Skip to content

Commit

Permalink
Merge branch 'main' of github.com:storyblok/field-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
demetriusfeijoo committed Dec 26, 2024
2 parents a604c61 + 749d767 commit 280f6fc
Show file tree
Hide file tree
Showing 22 changed files with 241 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
"contributions": [
"code"
]
},
{
"login": "ECJ222",
"name": "ECJ",
"avatar_url": "https://avatars.githubusercontent.com/u/39567763?v=4",
"profile": "https://github.com/ECJ222",
"contributions": [
"code"
]
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish CLI to NPM

on:
release:
types: [created]
types: [published]

jobs:
publish-npm:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish library to NPM

on:
release:
types: [created]
types: [published]

jobs:
publish-npm:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ For more details, please refer to the [documentation](https://www.storyblok.com/
</tr>
<tr>
<td align="center" valign="top" width="16.66%"><a href="https://links.dawntraoz.com/"><img src="https://avatars.githubusercontent.com/u/36744484?v=4?s=100" width="100px;" alt="Alba Silvente Fuentes"/><br /><sub><b>Alba Silvente Fuentes</b></sub></a><br /><a href="#code-Dawntraoz" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/ECJ222"><img src="https://avatars.githubusercontent.com/u/39567763?v=4?s=100" width="100px;" alt="ECJ"/><br /><sub><b>ECJ</b></sub></a><br /><a href="#code-ECJ222" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://www.storyblok.com/"
},
"private": true,
"license": "UNLICENSED",
"license": "MIT",
"workspaces": [
"packages/*",
"packages/cli/templates/*",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@storyblok/field-plugin-cli",
"version": "1.4.0",
"version": "1.5.1",
"license": "MIT",
"type": "module",
"bin": {
"field-plugin": "./bin.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"deploy": "npm run build && npx @storyblok/field-plugin-cli@latest deploy"
},
"dependencies": {
"@storyblok/field-plugin": "1.3.0"
"@storyblok/field-plugin": "1.4.2"
},
"devDependencies": {
"vite": "5.4.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy": "npm run build && npx @storyblok/field-plugin-cli@latest deploy"
},
"dependencies": {
"@storyblok/field-plugin": "1.3.0",
"@storyblok/field-plugin": "1.4.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy": "npm run build && npx @storyblok/field-plugin-cli@latest deploy"
},
"dependencies": {
"@storyblok/field-plugin": "1.3.0",
"@storyblok/field-plugin": "1.4.2",
"vue": "^2.7.14"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"deploy": "npm run build && npx @storyblok/field-plugin-cli@latest deploy"
},
"dependencies": {
"@storyblok/field-plugin": "1.3.0",
"@storyblok/field-plugin": "1.4.2",
"vue": "^3.2.47"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/field-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "@storyblok/field-plugin",
"version": "1.4.0",
"version": "1.4.2",
"description": "SDK for creating Field Plugins for Storyblok.",
"license": "MIT",
"sideEffects": false,
"files": [
"dist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type FieldPluginData<Content> = {
content: Content
options: Record<string, string>
spaceId: number | undefined
userId: number | undefined
interfaceLang: string
storyLang: string
story: StoryData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('createPluginActions', () => {
interfaceLanguage: 'en',
model: randomString,
spaceId: null,
userId: undefined,
blockId: undefined,
releases: [],
releaseId: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('handlePluginMessage', () => {
interfaceLanguage: 'en',
model: 123,
spaceId: 1234,
userId: 2345,
story: { content: {} },
schema: { options: [], field_type: 'avh', translatable: false },
storyId: 1344,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const pluginStateFromStateChangeMessage = <Content>(
return {
interfaceLang: message.interfaceLanguage,
spaceId: message.spaceId ?? undefined,
userId: message.userId ?? undefined,
story: message.story ?? undefined,
storyId: message.storyId ?? undefined,
storyLang: message.language === '' ? 'default' : message.language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const stub: LoadedMessage = {
action: 'loaded',
uid: '-preview',
spaceId: null,
userId: undefined,
model: undefined,
isModalOpen: false,
token: null,
Expand All @@ -18,7 +19,7 @@ const stub: LoadedMessage = {
releaseId: undefined,
}

describe('StateChangedMessage', () => {
describe('LoadedMessage', () => {
it('should validate', () => {
expect(isLoadedMessage(stub)).toEqual(true)
})
Expand Down Expand Up @@ -128,4 +129,38 @@ describe('StateChangedMessage', () => {
).toEqual(true)
})
})
describe('The "userId" property', () => {
it('is a number', () => {
expect(
isLoadedMessage({
...stub,
userId: 123,
}),
).toEqual(true)
})
it('is undefined', () => {
expect(
isLoadedMessage({
...stub,
userId: undefined,
}),
).toEqual(true)
})
it('is not null', () => {
expect(
isLoadedMessage({
...stub,
userId: null,
}),
).toEqual(false)
})
it('is not a string', () => {
expect(
isLoadedMessage({
...stub,
userId: '123',
}),
).toEqual(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type LoadedMessage = MessageToPlugin<'loaded'> & {
language: string
interfaceLanguage: string
spaceId: number | null
userId: number | undefined
story: StoryData
storyId: number | undefined
blockId: string | undefined
Expand All @@ -33,6 +34,8 @@ export const isLoadedMessage = (data: unknown): data is LoadedMessage =>
typeof data.language === 'string' &&
hasKey(data, 'schema') &&
isFieldPluginSchema(data.schema) &&
hasKey(data, 'userId') &&
(typeof data.userId === 'number' || typeof data.userId === 'undefined') &&
hasKey(data, 'story') &&
isStoryData(data.story) &&
hasKey(data, 'isModalOpen') &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { isStateMessage, StateChangedMessage } from './StateChangedMessage'
import { FieldPluginSchema } from './FieldPluginSchema'

const stub: StateChangedMessage = {
action: 'state-changed',
uid: '-preview',
spaceId: null,
userId: undefined,
model: undefined,
isModalOpen: false,
token: null,
storyId: undefined,
blockId: undefined,
story: { content: {} },
language: '',
interfaceLanguage: 'en',
schema: { options: [], field_type: 'blah', translatable: false },
releases: [],
releaseId: undefined,
}

describe('StateChangedMessage', () => {
it('should validate', () => {
expect(isStateMessage(stub)).toEqual(true)
})
describe('The "action" property', () => {
it('equals "loaded"', () => {
expect(
isStateMessage({
...stub,
action: 'anotherString',
}),
).toEqual(false)
})
})
describe('the "uid" property', () => {
it('is a string', () => {
expect(
isStateMessage({
...stub,
uid: 'anything',
}),
).toEqual(true)
})
it('is not undefined', () => {
expect(
isStateMessage({
...stub,
uid: undefined,
}),
).toEqual(false)
})
it('is not null', () => {
expect(
isStateMessage({
...stub,
uid: null,
}),
).toEqual(false)
})
it('is not a number', () => {
expect(
isStateMessage({
...stub,
uid: 123,
}),
).toEqual(false)
})
})

describe('the "language" property', () => {
it('is a string', () => {
expect(
isStateMessage({
...stub,
language: 'anything',
}),
).toEqual(true)
})
it('is not undefined', () => {
expect(
isStateMessage({
...stub,
language: undefined,
}),
).toEqual(false)
})
it('is not null', () => {
expect(
isStateMessage({
...stub,
language: null,
}),
).toEqual(false)
})
it('is not a number', () => {
expect(
isStateMessage({
...stub,
language: 123,
}),
).toEqual(false)
})
})
describe('The "schema" property', () => {
it('is required', () => {
expect(
isStateMessage({
...stub,
schema: undefined,
}),
).toEqual(false)
})
it('must be a schema', () => {
expect(
isStateMessage({
...stub,
schema: {
field_type: 'my-field',
options: [
{
name: 'a',
value: 'ab',
},
],
translatable: false,
} as FieldPluginSchema,
}),
).toEqual(true)
})
})
describe('The "userId" property', () => {
it('is a number', () => {
expect(
isStateMessage({
...stub,
userId: 123,
}),
).toEqual(true)
})
it('is undefined', () => {
expect(
isStateMessage({
...stub,
userId: undefined,
}),
).toEqual(true)
})
it('is not null', () => {
expect(
isStateMessage({
...stub,
userId: null,
}),
).toEqual(false)
})
it('is not a string', () => {
expect(
isStateMessage({
...stub,
userId: '123',
}),
).toEqual(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type StateChangedMessage = MessageToPlugin<'state-changed'> & {
language: string
interfaceLanguage: string
spaceId: number | null
userId: number | undefined
story: StoryData
storyId: number | undefined
blockId: string | undefined
Expand All @@ -33,6 +34,8 @@ export const isStateMessage = (data: unknown): data is StateChangedMessage =>
typeof data.language === 'string' &&
hasKey(data, 'schema') &&
isFieldPluginSchema(data.schema) &&
hasKey(data, 'userId') &&
(typeof data.userId === 'number' || typeof data.userId === 'undefined') &&
hasKey(data, 'story') &&
isStoryData(data.story) &&
hasKey(data, 'isModalOpen') &&
Expand Down
Loading

0 comments on commit 280f6fc

Please sign in to comment.