Skip to content

Commit 43b095b

Browse files
committed
feat(api-website-builder-workflows): workflows (#4777)
1 parent 428c73b commit 43b095b

File tree

29 files changed

+442
-15
lines changed

29 files changed

+442
-15
lines changed

packages/api-headless-cms-workflows/src/state/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Context } from "~/types.js";
22
import { getModelIdFromAppName } from "~/utils/appName.js";
33
import { getStateValues } from "~/utils/state.js";
44
import type { IWorkflowState } from "@webiny/api-workflows";
5-
import type { ICmsEntryState } from "@webiny/api-headless-cms/types/index.js";
5+
import type { IEntryState } from "@webiny/api-headless-cms/types/index.js";
66

77
interface IParams {
88
context: Context;
@@ -11,7 +11,7 @@ interface IParams {
1111
export const attachStateLifecycleEvents = ({ context }: IParams) => {
1212
const updateEntry = async (
1313
state: IWorkflowState,
14-
values: ICmsEntryState | undefined
14+
values: IEntryState | undefined
1515
): Promise<void> => {
1616
const modelId = getModelIdFromAppName(state.app);
1717
if (!modelId) {

packages/api-headless-cms-workflows/src/utils/state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { ICmsEntryState } from "@webiny/api-headless-cms/types/index.js";
1+
import type { IEntryState } from "@webiny/api-headless-cms/types/index.js";
22
import type { IWorkflowStateModel } from "@webiny/api-workflows/context/abstractions/WorkflowState.js";
33

4-
export const getStateValues = (state: IWorkflowStateModel): ICmsEntryState | undefined => {
4+
export const getStateValues = (state: IWorkflowStateModel): IEntryState | undefined => {
55
const activeStep = state.getActiveStep();
66
if (!activeStep) {
77
return undefined;

packages/api-headless-cms/src/crud/contentEntry/entryDataFactories/state.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import type { CmsEntry, ICmsEntryState } from "~/types/index.js";
1+
import type { CmsEntry, IEntryState } from "~/types/index.js";
22

33
interface IInputWithPossibleState {
4-
state: Partial<ICmsEntryState> | null;
4+
state: Partial<IEntryState> | null;
55
}
66
interface IParams {
77
input: Partial<IInputWithPossibleState>;
88
original?: CmsEntry | null;
99
}
1010

11-
export const getState = ({ input, original }: IParams): ICmsEntryState | undefined => {
11+
export const getState = ({ input, original }: IParams): IEntryState | undefined => {
1212
if (
1313
!input?.state?.stepId ||
1414
!input.state.state ||

packages/api-headless-cms/src/graphql/schema/baseSchema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,17 @@ const createSchema = (plugins: PluginsContainer): IGraphQLSchemaPlugin<CmsContex
140140
}
141141
142142
type CmsEntryState {
143+
workflowId: String
143144
stepId: ID
144145
stepName: String
145146
state: CmsEntryStateType
146147
}
147148
148149
input ListWhereInputCmsEntryState {
150+
workflowId: String
149151
stepId: ID
150152
state: CmsEntryStateType
153+
stepName: String
151154
}
152155
`,
153156
resolvers: {}

packages/api-headless-cms/src/types/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ export interface ICmsEntryLocation {
467467
folderId?: string | null;
468468
}
469469

470-
export interface ICmsEntryState {
470+
export interface IEntryState {
471471
state: string;
472472
workflowId: string;
473473
stepId: string;
@@ -686,7 +686,7 @@ export interface CmsEntry<T = CmsEntryValues> {
686686
*/
687687
binOriginalFolderId?: string | null;
688688

689-
state?: ICmsEntryState;
689+
state?: IEntryState;
690690
}
691691

692692
export interface CmsStorageEntry extends CmsEntry {
@@ -1471,7 +1471,7 @@ export type CreateCmsEntryInput<TValues = CmsEntryValues> = TValues & {
14711471
folderId?: string | null;
14721472
};
14731473

1474-
state?: Partial<ICmsEntryState>;
1474+
state?: Partial<IEntryState>;
14751475
};
14761476

14771477
export interface CreateCmsEntryOptionsInput {
@@ -1511,7 +1511,7 @@ export interface CreateFromCmsEntryInput {
15111511
firstPublishedBy?: CmsIdentity;
15121512
lastPublishedBy?: CmsIdentity;
15131513

1514-
state?: Partial<ICmsEntryState>;
1514+
state?: Partial<IEntryState>;
15151515

15161516
[key: string]: any;
15171517
}
@@ -1565,7 +1565,7 @@ export type UpdateCmsEntryInput<TValues = CmsEntryValues> = TValues & {
15651565
folderId?: string | null;
15661566
};
15671567

1568-
state?: Partial<ICmsEntryState>;
1568+
state?: Partial<IEntryState>;
15691569
};
15701570

15711571
export interface UpdateCmsEntryOptionsInput {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = require("@webiny/build-tools").createBabelConfigForNode({
2+
path: __dirname
3+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Webiny
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@webiny/api-website-builder-workflows",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"main": "index.js",
6+
"description": "Headless CMS Workflows",
7+
"keywords": [
8+
"api-website-builder-workflows:base"
9+
],
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/webiny/webiny-js.git",
13+
"directory": "packages/api-website-builder-workflows"
14+
},
15+
"license": "MIT",
16+
"dependencies": {
17+
"@webiny/api-website-builder": "0.0.0",
18+
"@webiny/api-workflows": "0.0.0",
19+
"@webiny/error": "0.0.0",
20+
"@webiny/handler": "0.0.0",
21+
"@webiny/handler-graphql": "0.0.0"
22+
},
23+
"devDependencies": {
24+
"@webiny/build-tools": "0.0.0",
25+
"@webiny/plugins": "0.0.0",
26+
"@webiny/project-utils": "0.0.0",
27+
"@webiny/testing": "0.0.0",
28+
"typescript": "5.9.3",
29+
"vitest": "^3.2.4"
30+
},
31+
"publishConfig": {
32+
"access": "public",
33+
"directory": "dist"
34+
}
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const WB_PAGE_APP = "wb.page";
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2+
import type { Context } from "~/types.js";
3+
4+
export const createWebsiteBuilderPageGraphQLExtension = () => {
5+
return new GraphQLSchemaPlugin<Context>({
6+
isApplicable: context => {
7+
if (!context.wcp.canUseWorkflows()) {
8+
return false;
9+
} else if (!context.workflows) {
10+
return false;
11+
} else if (!context.websiteBuilder) {
12+
return false;
13+
}
14+
return true;
15+
},
16+
typeDefs: /* GraphQL */ `
17+
# CmsEntryStateType
18+
enum WbPageStateType {
19+
pending
20+
inReview
21+
rejected
22+
approved
23+
}
24+
25+
# CmsEntryState
26+
type WbPageState {
27+
workflowId: String
28+
stepId: ID
29+
stepName: String
30+
state: WbPageStateType
31+
}
32+
33+
extend type WbPage {
34+
state: WbPageState
35+
}
36+
37+
input ListWhereInputWbPageState {
38+
workflowId: String
39+
stepId: ID
40+
state: CmsEntryStateType
41+
stepName: String
42+
}
43+
44+
extend input WbPagesListWhereInput {
45+
state: ListWhereInputWbPageState
46+
}
47+
`
48+
});
49+
};

0 commit comments

Comments
 (0)