@webiny/api-apw 0.0.0-unstable.5e7233243f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ContentApwSettingsPlugin.d.ts +10 -0
- package/ContentApwSettingsPlugin.js +17 -0
- package/ContentApwSettingsPlugin.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/crud/createChangeRequestMethods.d.ts +2 -0
- package/crud/createChangeRequestMethods.js +95 -0
- package/crud/createChangeRequestMethods.js.map +1 -0
- package/crud/createCommentMethods.d.ts +2 -0
- package/crud/createCommentMethods.js +96 -0
- package/crud/createCommentMethods.js.map +1 -0
- package/crud/createContentReviewMethods.d.ts +10 -0
- package/crud/createContentReviewMethods.js +552 -0
- package/crud/createContentReviewMethods.js.map +1 -0
- package/crud/createReviewerMethods.d.ts +2 -0
- package/crud/createReviewerMethods.js +96 -0
- package/crud/createReviewerMethods.js.map +1 -0
- package/crud/createWorkflowMethods.d.ts +2 -0
- package/crud/createWorkflowMethods.js +96 -0
- package/crud/createWorkflowMethods.js.map +1 -0
- package/crud/index.d.ts +2 -0
- package/crud/index.js +100 -0
- package/crud/index.js.map +1 -0
- package/crud/utils.d.ts +21 -0
- package/crud/utils.js +142 -0
- package/crud/utils.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +34 -0
- package/index.js.map +1 -0
- package/package.json +75 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +10 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +51 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -0
- package/plugins/cms/README.md +49 -0
- package/plugins/cms/apwEntryPlugins.d.ts +8 -0
- package/plugins/cms/apwEntryPlugins.js +50 -0
- package/plugins/cms/apwEntryPlugins.js.map +1 -0
- package/plugins/cms/index.d.ts +12 -0
- package/plugins/cms/index.js +37 -0
- package/plugins/cms/index.js.map +1 -0
- package/plugins/cms/linkContentReviewToEntry.d.ts +8 -0
- package/plugins/cms/linkContentReviewToEntry.js +108 -0
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -0
- package/plugins/cms/linkWorkflowToEntry.d.ts +8 -0
- package/plugins/cms/linkWorkflowToEntry.js +166 -0
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -0
- package/plugins/cms/triggerContentReview.d.ts +8 -0
- package/plugins/cms/triggerContentReview.js +59 -0
- package/plugins/cms/triggerContentReview.js.map +1 -0
- package/plugins/cms/updateContentReviewStatus.d.ts +10 -0
- package/plugins/cms/updateContentReviewStatus.js +101 -0
- package/plugins/cms/updateContentReviewStatus.js.map +1 -0
- package/plugins/cms/utils.d.ts +27 -0
- package/plugins/cms/utils.js +211 -0
- package/plugins/cms/utils.js.map +1 -0
- package/plugins/context.d.ts +5 -0
- package/plugins/context.js +146 -0
- package/plugins/context.js.map +1 -0
- package/plugins/graphql/changeRequest.gql.d.ts +4 -0
- package/plugins/graphql/changeRequest.gql.js +155 -0
- package/plugins/graphql/changeRequest.gql.js.map +1 -0
- package/plugins/graphql/comment.gql.d.ts +4 -0
- package/plugins/graphql/comment.gql.js +160 -0
- package/plugins/graphql/comment.gql.js.map +1 -0
- package/plugins/graphql/contentReview.gql.d.ts +4 -0
- package/plugins/graphql/contentReview.gql.js +382 -0
- package/plugins/graphql/contentReview.gql.js.map +1 -0
- package/plugins/graphql/reviewer.gql.d.ts +4 -0
- package/plugins/graphql/reviewer.gql.js +114 -0
- package/plugins/graphql/reviewer.gql.js.map +1 -0
- package/plugins/graphql/workflow.gql.d.ts +4 -0
- package/plugins/graphql/workflow.gql.js +205 -0
- package/plugins/graphql/workflow.gql.js.map +1 -0
- package/plugins/graphql.d.ts +4 -0
- package/plugins/graphql.js +95 -0
- package/plugins/graphql.js.map +1 -0
- package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
- package/plugins/hooks/createReviewerFromIdentity.js +62 -0
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +67 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +59 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -0
- package/plugins/hooks/index.d.ts +3 -0
- package/plugins/hooks/index.js +68 -0
- package/plugins/hooks/index.js.map +1 -0
- package/plugins/hooks/initializeContentReviewSteps.d.ts +2 -0
- package/plugins/hooks/initializeContentReviewSteps.js +89 -0
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -0
- package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
- package/plugins/hooks/updatePendingChangeRequests.js +98 -0
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -0
- package/plugins/hooks/updateTotalComments.d.ts +3 -0
- package/plugins/hooks/updateTotalComments.js +157 -0
- package/plugins/hooks/updateTotalComments.js.map +1 -0
- package/plugins/hooks/validateChangeRequest.d.ts +2 -0
- package/plugins/hooks/validateChangeRequest.js +64 -0
- package/plugins/hooks/validateChangeRequest.js.map +1 -0
- package/plugins/hooks/validateComment.d.ts +2 -0
- package/plugins/hooks/validateComment.js +47 -0
- package/plugins/hooks/validateComment.js.map +1 -0
- package/plugins/hooks/validateContentReview.d.ts +2 -0
- package/plugins/hooks/validateContentReview.js +38 -0
- package/plugins/hooks/validateContentReview.js.map +1 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +9 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +51 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -0
- package/plugins/pageBuilder/apwContentPagePlugins.d.ts +3 -0
- package/plugins/pageBuilder/apwContentPagePlugins.js +30 -0
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -0
- package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +3 -0
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +25 -0
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -0
- package/plugins/pageBuilder/index.d.ts +11 -0
- package/plugins/pageBuilder/index.js +45 -0
- package/plugins/pageBuilder/index.js.map +1 -0
- package/plugins/pageBuilder/linkContentReviewToPage.d.ts +8 -0
- package/plugins/pageBuilder/linkContentReviewToPage.js +93 -0
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -0
- package/plugins/pageBuilder/linkWorkflowToPage.d.ts +8 -0
- package/plugins/pageBuilder/linkWorkflowToPage.js +182 -0
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -0
- package/plugins/pageBuilder/triggerContentReview.d.ts +8 -0
- package/plugins/pageBuilder/triggerContentReview.js +50 -0
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -0
- package/plugins/pageBuilder/updateContentReviewStatus.d.ts +10 -0
- package/plugins/pageBuilder/updateContentReviewStatus.js +83 -0
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -0
- package/plugins/pageBuilder/utils.d.ts +22 -0
- package/plugins/pageBuilder/utils.js +184 -0
- package/plugins/pageBuilder/utils.js.map +1 -0
- package/plugins/utils.d.ts +35 -0
- package/plugins/utils.js +197 -0
- package/plugins/utils.js.map +1 -0
- package/scheduler/createScheduleActionMethods.d.ts +2 -0
- package/scheduler/createScheduleActionMethods.js +146 -0
- package/scheduler/createScheduleActionMethods.js.map +1 -0
- package/scheduler/handlers/executeAction/index.d.ts +13 -0
- package/scheduler/handlers/executeAction/index.js +172 -0
- package/scheduler/handlers/executeAction/index.js.map +1 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +13 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +17 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +11 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +126 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -0
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +11 -0
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +163 -0
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -0
- package/scheduler/handlers/executeAction/security.d.ts +4 -0
- package/scheduler/handlers/executeAction/security.js +68 -0
- package/scheduler/handlers/executeAction/security.js.map +1 -0
- package/scheduler/handlers/scheduleAction/index.d.ts +22 -0
- package/scheduler/handlers/scheduleAction/index.js +165 -0
- package/scheduler/handlers/scheduleAction/index.js.map +1 -0
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +24 -0
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +176 -0
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -0
- package/scheduler/handlers/utils.d.ts +33 -0
- package/scheduler/handlers/utils.js +168 -0
- package/scheduler/handlers/utils.js.map +1 -0
- package/scheduler/index.d.ts +2 -0
- package/scheduler/index.js +27 -0
- package/scheduler/index.js.map +1 -0
- package/scheduler/types.d.ts +171 -0
- package/scheduler/types.js +34 -0
- package/scheduler/types.js.map +1 -0
- package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
- package/storageOperations/changeRequestStorageOperations.js +126 -0
- package/storageOperations/changeRequestStorageOperations.js.map +1 -0
- package/storageOperations/commentStorageOperations.d.ts +3 -0
- package/storageOperations/commentStorageOperations.js +142 -0
- package/storageOperations/commentStorageOperations.js.map +1 -0
- package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
- package/storageOperations/contentReviewStorageOperations.js +97 -0
- package/storageOperations/contentReviewStorageOperations.js.map +1 -0
- package/storageOperations/index.d.ts +15 -0
- package/storageOperations/index.js +52 -0
- package/storageOperations/index.js.map +1 -0
- package/storageOperations/models/changeRequest.model.d.ts +3 -0
- package/storageOperations/models/changeRequest.model.js +59 -0
- package/storageOperations/models/changeRequest.model.js.map +1 -0
- package/storageOperations/models/comment.model.d.ts +7 -0
- package/storageOperations/models/comment.model.js +60 -0
- package/storageOperations/models/comment.model.js.map +1 -0
- package/storageOperations/models/contentModelPluginFactory.d.ts +15 -0
- package/storageOperations/models/contentModelPluginFactory.js +32 -0
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -0
- package/storageOperations/models/contentReview.model.d.ts +7 -0
- package/storageOperations/models/contentReview.model.js +257 -0
- package/storageOperations/models/contentReview.model.js.map +1 -0
- package/storageOperations/models/index.d.ts +2 -0
- package/storageOperations/models/index.js +115 -0
- package/storageOperations/models/index.js.map +1 -0
- package/storageOperations/models/reviewer.model.d.ts +3 -0
- package/storageOperations/models/reviewer.model.js +55 -0
- package/storageOperations/models/reviewer.model.js.map +1 -0
- package/storageOperations/models/utils.d.ts +3 -0
- package/storageOperations/models/utils.js +36 -0
- package/storageOperations/models/utils.js.map +1 -0
- package/storageOperations/models/workflow.model.d.ts +12 -0
- package/storageOperations/models/workflow.model.js +208 -0
- package/storageOperations/models/workflow.model.js.map +1 -0
- package/storageOperations/reviewerStorageOperations.d.ts +3 -0
- package/storageOperations/reviewerStorageOperations.js +93 -0
- package/storageOperations/reviewerStorageOperations.js.map +1 -0
- package/storageOperations/types.d.ts +34 -0
- package/storageOperations/types.js +5 -0
- package/storageOperations/types.js.map +1 -0
- package/storageOperations/workflowStorageOperations.d.ts +3 -0
- package/storageOperations/workflowStorageOperations.js +115 -0
- package/storageOperations/workflowStorageOperations.js.map +1 -0
- package/types.d.ts +737 -0
- package/types.js +69 -0
- package/types.js.map +1 -0
- package/utils/contentApwSettingsPlugin.d.ts +9 -0
- package/utils/contentApwSettingsPlugin.js +26 -0
- package/utils/contentApwSettingsPlugin.js.map +1 -0
- package/utils/errors.d.ts +16 -0
- package/utils/errors.js +75 -0
- package/utils/errors.js.map +1 -0
- package/utils/fieldResolver.d.ts +16 -0
- package/utils/fieldResolver.js +60 -0
- package/utils/fieldResolver.js.map +1 -0
- package/utils/resolve.d.ts +3 -0
- package/utils/resolve.js +18 -0
- package/utils/resolve.js.map +1 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
import { ApwWorkflow, ApwWorkflowCrud, ApwWorkflowScope, PageWithWorkflow } from "../../types";
|
2
|
+
import { PageBuilderContextObject } from "@webiny/api-page-builder/graphql/types";
|
3
|
+
interface AssignWorkflowToPageParams {
|
4
|
+
listWorkflow: ApwWorkflowCrud["list"];
|
5
|
+
page: PageWithWorkflow;
|
6
|
+
}
|
7
|
+
export declare const assignWorkflowToPage: ({ listWorkflow, page }: AssignWorkflowToPageParams) => Promise<void>;
|
8
|
+
export declare const hasPages: (workflow: ApwWorkflow) => Boolean;
|
9
|
+
export declare const shouldUpdatePages: (scope: ApwWorkflowScope, prevScope: ApwWorkflowScope) => Boolean;
|
10
|
+
interface GetUpdatePageOpsResult {
|
11
|
+
addedPages: string[];
|
12
|
+
removedPages: string[];
|
13
|
+
}
|
14
|
+
export declare const getPagesDiff: (currentPages: string[], prevPages: string[]) => GetUpdatePageOpsResult;
|
15
|
+
interface UpdatePageSettingsParams {
|
16
|
+
getPage: PageBuilderContextObject["getPage"];
|
17
|
+
updatePage: PageBuilderContextObject["updatePage"];
|
18
|
+
uniquePageId: string;
|
19
|
+
getNewSettings: (settings: PageWithWorkflow["settings"]) => PageWithWorkflow["settings"];
|
20
|
+
}
|
21
|
+
export declare const updatePageSettings: ({ getPage, updatePage, uniquePageId, getNewSettings }: UpdatePageSettingsParams) => Promise<void>;
|
22
|
+
export {};
|
@@ -0,0 +1,184 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.updatePageSettings = exports.shouldUpdatePages = exports.hasPages = exports.getPagesDiff = exports.assignWorkflowToPage = void 0;
|
9
|
+
|
10
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
11
|
+
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
+
|
14
|
+
var _types = require("../../types");
|
15
|
+
|
16
|
+
var _utils = require("../utils");
|
17
|
+
|
18
|
+
const isWorkflowApplicable = (page, workflow) => {
|
19
|
+
const application = workflow.app;
|
20
|
+
|
21
|
+
if (application !== _types.ApwWorkflowApplications.PB) {
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
const scopeType = workflow.scope.type;
|
26
|
+
|
27
|
+
if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
|
28
|
+
return true;
|
29
|
+
} else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
|
30
|
+
const categories = (0, _get.default)(workflow, "scope.data.categories");
|
31
|
+
|
32
|
+
if (Array.isArray(categories) && categories.includes(page.category)) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
|
36
|
+
const pages = (0, _get.default)(workflow, "scope.data.pages");
|
37
|
+
|
38
|
+
if (Array.isArray(pages) && pages.includes(page.pid)) {
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
|
45
|
+
throw new _error.default(`Unknown scope type "${scopeType}".`, "UNKNOWN_SCOPE_TYPE", {
|
46
|
+
workflow
|
47
|
+
});
|
48
|
+
};
|
49
|
+
|
50
|
+
const assignWorkflowToPage = async ({
|
51
|
+
listWorkflow,
|
52
|
+
page
|
53
|
+
}) => {
|
54
|
+
/**
|
55
|
+
* Lookup and assign "workflowId".
|
56
|
+
*/
|
57
|
+
try {
|
58
|
+
/*
|
59
|
+
* List all workflows for app pageBuilder
|
60
|
+
*/
|
61
|
+
const [entries] = await listWorkflow({
|
62
|
+
where: {
|
63
|
+
app: _types.ApwWorkflowApplications.PB
|
64
|
+
}
|
65
|
+
});
|
66
|
+
/*
|
67
|
+
* Re-order them based on workflow scope and pre-defined rule i.e.
|
68
|
+
* "specific" entry -> entry for a "category" -> "default".
|
69
|
+
* There can be more than one workflow with same "scope" and "app".
|
70
|
+
* Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
|
71
|
+
*/
|
72
|
+
|
73
|
+
const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
|
74
|
+
|
75
|
+
for (const workflow of sortedWorkflows) {
|
76
|
+
/**
|
77
|
+
* Assign the first applicable workflow to the page and exit.
|
78
|
+
*/
|
79
|
+
if (isWorkflowApplicable(page, workflow)) {
|
80
|
+
page.settings.apw = {
|
81
|
+
workflowId: workflow.id,
|
82
|
+
contentReviewId: null
|
83
|
+
};
|
84
|
+
break;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
} catch (ex) {
|
88
|
+
throw new _error.default(`Failed to assign workflow to page "${page.pid}".`, ex.code, ex.data);
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
exports.assignWorkflowToPage = assignWorkflowToPage;
|
93
|
+
|
94
|
+
const hasPages = workflow => {
|
95
|
+
const {
|
96
|
+
app,
|
97
|
+
scope
|
98
|
+
} = workflow;
|
99
|
+
return app === _types.ApwWorkflowApplications.PB && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.pages);
|
100
|
+
};
|
101
|
+
|
102
|
+
exports.hasPages = hasPages;
|
103
|
+
|
104
|
+
const shouldUpdatePages = (scope, prevScope) => {
|
105
|
+
/**
|
106
|
+
* Bail out early if the scope is not "CUSTOM" - at that point all pages should be updated.
|
107
|
+
*/
|
108
|
+
if (prevScope.type !== _types.WorkflowScopeTypes.CUSTOM) {
|
109
|
+
return true;
|
110
|
+
}
|
111
|
+
|
112
|
+
const prevScopePages = (0, _get.default)(prevScope, "data.pages");
|
113
|
+
const currentScopePages = (0, _get.default)(scope, "data.pages");
|
114
|
+
/**
|
115
|
+
* Bail out early if there were no pages assigned previously.
|
116
|
+
*/
|
117
|
+
|
118
|
+
if (prevScopePages.length === 0) {
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* Bail out early if number of pages has been changed.
|
123
|
+
*/
|
124
|
+
|
125
|
+
|
126
|
+
if (currentScopePages.length !== prevScopePages.length) {
|
127
|
+
return true;
|
128
|
+
}
|
129
|
+
/*
|
130
|
+
* Check whether previous scope has the exactly same pages as in the new scope.
|
131
|
+
*/
|
132
|
+
|
133
|
+
|
134
|
+
return !prevScopePages.every(pid => currentScopePages.includes(pid));
|
135
|
+
};
|
136
|
+
|
137
|
+
exports.shouldUpdatePages = shouldUpdatePages;
|
138
|
+
|
139
|
+
const getPagesDiff = (currentPages, prevPages) => {
|
140
|
+
const addedPages = currentPages.filter(id => !prevPages.includes(id));
|
141
|
+
const removedPages = prevPages.filter(id => !currentPages.includes(id));
|
142
|
+
return {
|
143
|
+
addedPages,
|
144
|
+
removedPages
|
145
|
+
};
|
146
|
+
};
|
147
|
+
|
148
|
+
exports.getPagesDiff = getPagesDiff;
|
149
|
+
|
150
|
+
const updatePageSettings = async ({
|
151
|
+
getPage,
|
152
|
+
updatePage,
|
153
|
+
uniquePageId,
|
154
|
+
getNewSettings
|
155
|
+
}) => {
|
156
|
+
try {
|
157
|
+
/**
|
158
|
+
* Currently, we only assign "workflow" to latest page.
|
159
|
+
*/
|
160
|
+
const page = await getPage(uniquePageId);
|
161
|
+
/**
|
162
|
+
* We can't update a page that is "locked".
|
163
|
+
*/
|
164
|
+
|
165
|
+
if (page.locked) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
/**
|
169
|
+
* There can be more than one workflow with same `scope` for same `app`. That is why;
|
170
|
+
* We'll update the workflow reference even though it already had one assign.
|
171
|
+
*/
|
172
|
+
|
173
|
+
|
174
|
+
await updatePage(page.id, {
|
175
|
+
settings: getNewSettings(page.settings)
|
176
|
+
});
|
177
|
+
} catch (e) {
|
178
|
+
if (e.code !== "NOT_FOUND") {
|
179
|
+
throw e;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
};
|
183
|
+
|
184
|
+
exports.updatePageSettings = updatePageSettings;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["isWorkflowApplicable","page","workflow","application","app","ApwWorkflowApplications","PB","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","categories","get","Array","isArray","includes","category","pages","pid","WebinyError","assignWorkflowToPage","listWorkflow","entries","where","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","settings","apw","workflowId","id","contentReviewId","ex","code","data","hasPages","shouldUpdatePages","prevScope","prevScopePages","currentScopePages","length","every","getPagesDiff","currentPages","prevPages","addedPages","filter","removedPages","updatePageSettings","getPage","updatePage","uniquePageId","getNewSettings","locked","e"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport WebinyError from \"@webiny/error\";\nimport {\n ApwWorkflow,\n ApwWorkflowApplications,\n ApwWorkflowCrud,\n ApwWorkflowScope,\n PageWithWorkflow,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\nconst isWorkflowApplicable = (page: PageWithWorkflow, workflow: ApwWorkflow) => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.PB) {\n return false;\n }\n\n const scopeType = workflow.scope.type;\n\n if (scopeType === WorkflowScopeTypes.DEFAULT) {\n return true;\n } else if (scopeType === WorkflowScopeTypes.CUSTOM) {\n const categories = get(workflow, \"scope.data.categories\");\n\n if (Array.isArray(categories) && categories.includes(page.category)) {\n return true;\n }\n\n const pages = get(workflow, \"scope.data.pages\");\n if (Array.isArray(pages) && pages.includes(page.pid)) {\n return true;\n }\n return false;\n }\n throw new WebinyError(`Unknown scope type \"${scopeType}\".`, \"UNKNOWN_SCOPE_TYPE\", {\n workflow\n });\n};\n\ninterface AssignWorkflowToPageParams {\n listWorkflow: ApwWorkflowCrud[\"list\"];\n page: PageWithWorkflow;\n}\n\nexport const assignWorkflowToPage = async ({ listWorkflow, page }: AssignWorkflowToPageParams) => {\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app pageBuilder\n */\n const [entries] = await listWorkflow({\n where: {\n app: ApwWorkflowApplications.PB\n }\n });\n\n /*\n * Re-order them based on workflow scope and pre-defined rule i.e.\n * \"specific\" entry -> entry for a \"category\" -> \"default\".\n * There can be more than one workflow with same \"scope\" and \"app\".\n * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.\n */\n const sortedWorkflows = entries\n .sort(workflowByPrecedenceDesc)\n .sort(workflowByCreatedOnDesc);\n\n for (const workflow of sortedWorkflows) {\n /**\n * Assign the first applicable workflow to the page and exit.\n */\n if (isWorkflowApplicable(page, workflow)) {\n page.settings.apw = {\n workflowId: workflow.id,\n contentReviewId: null\n };\n break;\n }\n }\n } catch (ex) {\n throw new WebinyError(`Failed to assign workflow to page \"${page.pid}\".`, ex.code, ex.data);\n }\n};\n\nexport const hasPages = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.PB &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.pages)\n );\n};\n\nexport const shouldUpdatePages = (\n scope: ApwWorkflowScope,\n prevScope: ApwWorkflowScope\n): Boolean => {\n /**\n * Bail out early if the scope is not \"CUSTOM\" - at that point all pages should be updated.\n */\n if (prevScope.type !== WorkflowScopeTypes.CUSTOM) {\n return true;\n }\n const prevScopePages: string[] = get(prevScope, \"data.pages\");\n const currentScopePages: string[] = get(scope, \"data.pages\");\n /**\n * Bail out early if there were no pages assigned previously.\n */\n if (prevScopePages.length === 0) {\n return true;\n }\n /**\n * Bail out early if number of pages has been changed.\n */\n if (currentScopePages.length !== prevScopePages.length) {\n return true;\n }\n /*\n * Check whether previous scope has the exactly same pages as in the new scope.\n */\n return !prevScopePages.every(pid => currentScopePages.includes(pid));\n};\n\ninterface GetUpdatePageOpsResult {\n addedPages: string[];\n removedPages: string[];\n}\n\nexport const getPagesDiff = (\n currentPages: string[],\n prevPages: string[]\n): GetUpdatePageOpsResult => {\n const addedPages = currentPages.filter(id => !prevPages.includes(id));\n const removedPages = prevPages.filter(id => !currentPages.includes(id));\n\n return {\n addedPages,\n removedPages\n };\n};\n\ninterface UpdatePageSettingsParams {\n getPage: PageBuilderContextObject[\"getPage\"];\n updatePage: PageBuilderContextObject[\"updatePage\"];\n uniquePageId: string;\n getNewSettings: (settings: PageWithWorkflow[\"settings\"]) => PageWithWorkflow[\"settings\"];\n}\n\nexport const updatePageSettings = async ({\n getPage,\n updatePage,\n uniquePageId,\n getNewSettings\n}: UpdatePageSettingsParams) => {\n try {\n /**\n * Currently, we only assign \"workflow\" to latest page.\n */\n const page = await getPage<PageWithWorkflow>(uniquePageId);\n /**\n * We can't update a page that is \"locked\".\n */\n if (page.locked) {\n return;\n }\n /**\n * There can be more than one workflow with same `scope` for same `app`. That is why;\n * We'll update the workflow reference even though it already had one assign.\n */\n await updatePage(page.id, {\n settings: getNewSettings(page.settings)\n });\n } catch (e) {\n if (e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAQA;;AAGA,MAAMA,oBAAoB,GAAG,CAACC,IAAD,EAAyBC,QAAzB,KAAmD;EAC5E,MAAMC,WAAW,GAAGD,QAAQ,CAACE,GAA7B;;EACA,IAAID,WAAW,KAAKE,8BAAA,CAAwBC,EAA5C,EAAgD;IAC5C,OAAO,KAAP;EACH;;EAED,MAAMC,SAAS,GAAGL,QAAQ,CAACM,KAAT,CAAeC,IAAjC;;EAEA,IAAIF,SAAS,KAAKG,yBAAA,CAAmBC,OAArC,EAA8C;IAC1C,OAAO,IAAP;EACH,CAFD,MAEO,IAAIJ,SAAS,KAAKG,yBAAA,CAAmBE,MAArC,EAA6C;IAChD,MAAMC,UAAU,GAAG,IAAAC,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AY,CAACG,MAAb,CAAoBhB,EAAE,IAAI,CAACc,SAAS,CAAC9B,QAAV,CAAmBgB,EAAnB,CAA3B,CAAnB;EACA,MAAMiB,YAAY,GAAGH,SAAS,CAACE,MAAV,CAAiBhB,EAAE,IAAI,CAACa,YAAY,CAAC7B,QAAb,CAAsBgB,EAAtB,CAAxB,CAArB;EAEA,OAAO;IACHe,UADG;IAEHE;EAFG,CAAP;AAIH,CAXM;;;;AAoBA,MAAMC,kBAAkB,GAAG,OAAO;EACrCC,OADqC;EAErCC,UAFqC;EAGrCC,YAHqC;EAIrCC;AAJqC,CAAP,KAKF;EAC5B,IAAI;IACA;AACR;AACA;IACQ,MAAMtD,IAAI,GAAG,MAAMmD,OAAO,CAAmBE,YAAnB,CAA1B;IACA;AACR;AACA;;IACQ,IAAIrD,IAAI,CAACuD,MAAT,EAAiB;MACb;IACH;IACD;AACR;AACA;AACA;;;IACQ,MAAMH,UAAU,CAACpD,IAAI,CAACgC,EAAN,EAAU;MACtBH,QAAQ,EAAEyB,cAAc,CAACtD,IAAI,CAAC6B,QAAN;IADF,CAAV,CAAhB;EAGH,CAlBD,CAkBE,OAAO2B,CAAP,EAAU;IACR,IAAIA,CAAC,CAACrB,IAAF,KAAW,WAAf,EAA4B;MACxB,MAAMqB,CAAN;IACH;EACJ;AACJ,CA7BM"}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
2
|
+
import { SecurityIdentity } from "@webiny/api-security/types";
|
3
|
+
import { ApwChangeRequest, ApwContentReview, ApwContentReviewCrud, ApwContentReviewStep, ApwContentReviewStepStatus, ApwContext, ApwReviewerCrud, ApwWorkflow, ApwWorkflowStep, ApwWorkflowStepTypes } from "../types";
|
4
|
+
export declare const getNanoid: (size?: number | undefined) => string;
|
5
|
+
export interface CreateModelFieldParams extends Omit<CmsModelField, "id" | "storageId" | "fieldId"> {
|
6
|
+
parent: string;
|
7
|
+
}
|
8
|
+
export interface HasReviewersParams {
|
9
|
+
identity: SecurityIdentity;
|
10
|
+
step: ApwContentReviewStep;
|
11
|
+
getReviewer: ApwReviewerCrud["get"];
|
12
|
+
}
|
13
|
+
export declare const hasReviewer: (params: HasReviewersParams) => Promise<Boolean>;
|
14
|
+
export declare const getValue: (object: Record<string, any>, key: string) => any;
|
15
|
+
export declare const getContentReviewStepInitialStatus: (workflowSteps: ApwWorkflowStep[], index: number, previousStepStatus?: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
|
16
|
+
export declare const getNextStepStatus: (previousStepType: ApwWorkflowStepTypes, previousStepStatus: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
|
17
|
+
export interface ExtractContentReviewIdAndStepResult {
|
18
|
+
id: string;
|
19
|
+
stepId: string;
|
20
|
+
}
|
21
|
+
export declare const extractContentReviewIdAndStep: (step: ApwChangeRequest["step"]) => ExtractContentReviewIdAndStepResult;
|
22
|
+
declare type SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, "id" | "contentReviewMethods">;
|
23
|
+
export declare const safelyGetContentReview: ({ id, contentReviewMethods }: SafelyGetContentReviewParams) => Promise<ApwContentReview | null>;
|
24
|
+
export interface UpdateContentReviewParams {
|
25
|
+
id: string;
|
26
|
+
contentReviewMethods: ApwContentReviewCrud;
|
27
|
+
getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;
|
28
|
+
}
|
29
|
+
export declare const updateContentReview: ({ contentReviewMethods, id, getNewContentReviewData }: UpdateContentReviewParams) => Promise<void>;
|
30
|
+
export declare const updateContentReviewStep: (steps: ApwContentReviewStep[], stepId: string, updater: (step: ApwContentReviewStep) => ApwContentReviewStep) => ApwContentReviewStep[];
|
31
|
+
declare type CheckInstallationParams = Pick<ApwContext, "tenancy" | "i18n">;
|
32
|
+
export declare const isInstallationPending: ({ tenancy, i18n }: CheckInstallationParams) => boolean;
|
33
|
+
export declare const workflowByPrecedenceDesc: (a: ApwWorkflow, b: ApwWorkflow) => number;
|
34
|
+
export declare const workflowByCreatedOnDesc: (a: ApwWorkflow, b: ApwWorkflow) => number;
|
35
|
+
export {};
|
package/plugins/utils.js
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.workflowByPrecedenceDesc = exports.workflowByCreatedOnDesc = exports.updateContentReviewStep = exports.updateContentReview = exports.safelyGetContentReview = exports.isInstallationPending = exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getNanoid = exports.getContentReviewStepInitialStatus = exports.extractContentReviewIdAndStep = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
13
|
+
|
14
|
+
var _nanoid = require("nanoid");
|
15
|
+
|
16
|
+
var _types = require("../types");
|
17
|
+
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
19
|
+
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
21
|
+
|
22
|
+
const ALPHANUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
23
|
+
const getNanoid = (0, _nanoid.customAlphabet)(ALPHANUMERIC, 10);
|
24
|
+
exports.getNanoid = getNanoid;
|
25
|
+
|
26
|
+
const hasReviewer = async params => {
|
27
|
+
const {
|
28
|
+
getReviewer,
|
29
|
+
identity,
|
30
|
+
step
|
31
|
+
} = params;
|
32
|
+
|
33
|
+
for (const stepReviewer of step.reviewers) {
|
34
|
+
const entry = await getReviewer(stepReviewer.id);
|
35
|
+
|
36
|
+
if (entry.identityId === identity.id) {
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
return false;
|
42
|
+
};
|
43
|
+
|
44
|
+
exports.hasReviewer = hasReviewer;
|
45
|
+
|
46
|
+
const getValue = (object, key) => {
|
47
|
+
return (0, _get.default)(object, `values.${key}`);
|
48
|
+
};
|
49
|
+
|
50
|
+
exports.getValue = getValue;
|
51
|
+
|
52
|
+
const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
|
53
|
+
/**
|
54
|
+
* Always set first step 'active' by default.
|
55
|
+
*/
|
56
|
+
if (index === 0) {
|
57
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
58
|
+
}
|
59
|
+
|
60
|
+
const previousStep = workflowSteps[index - 1];
|
61
|
+
|
62
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStep.type !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
63
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
64
|
+
}
|
65
|
+
|
66
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
67
|
+
};
|
68
|
+
|
69
|
+
exports.getContentReviewStepInitialStatus = getContentReviewStepInitialStatus;
|
70
|
+
|
71
|
+
const getNextStepStatus = (previousStepType, previousStepStatus) => {
|
72
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.DONE) {
|
73
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStepType !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
77
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
78
|
+
}
|
79
|
+
|
80
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
81
|
+
};
|
82
|
+
|
83
|
+
exports.getNextStepStatus = getNextStepStatus;
|
84
|
+
|
85
|
+
const extractContentReviewIdAndStep = step => {
|
86
|
+
/*
|
87
|
+
* Get associated content review entry.
|
88
|
+
*/
|
89
|
+
const [entryId, version, stepId] = step.split("#");
|
90
|
+
const revisionId = `${entryId}#${version}`;
|
91
|
+
return {
|
92
|
+
id: revisionId,
|
93
|
+
stepId
|
94
|
+
};
|
95
|
+
};
|
96
|
+
|
97
|
+
exports.extractContentReviewIdAndStep = extractContentReviewIdAndStep;
|
98
|
+
|
99
|
+
const safelyGetContentReview = async ({
|
100
|
+
id,
|
101
|
+
contentReviewMethods
|
102
|
+
}) => {
|
103
|
+
let contentReviewEntry = null;
|
104
|
+
|
105
|
+
try {
|
106
|
+
contentReviewEntry = await contentReviewMethods.get(id);
|
107
|
+
} catch (e) {
|
108
|
+
if (e.message !== "index_not_found_exception" && e.code !== "NOT_FOUND") {
|
109
|
+
throw e;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
return contentReviewEntry;
|
114
|
+
};
|
115
|
+
|
116
|
+
exports.safelyGetContentReview = safelyGetContentReview;
|
117
|
+
|
118
|
+
const updateContentReview = async ({
|
119
|
+
contentReviewMethods,
|
120
|
+
id,
|
121
|
+
getNewContentReviewData
|
122
|
+
}) => {
|
123
|
+
const contentReviewEntry = await safelyGetContentReview({
|
124
|
+
id,
|
125
|
+
contentReviewMethods
|
126
|
+
});
|
127
|
+
|
128
|
+
if (contentReviewEntry) {
|
129
|
+
const newContentReviewData = getNewContentReviewData(contentReviewEntry);
|
130
|
+
/**
|
131
|
+
* Update content review entry.
|
132
|
+
*/
|
133
|
+
|
134
|
+
await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
exports.updateContentReview = updateContentReview;
|
139
|
+
|
140
|
+
const updateContentReviewStep = (steps, stepId, updater) => {
|
141
|
+
return steps.map(step => {
|
142
|
+
if (step.id === stepId) {
|
143
|
+
return _objectSpread({}, updater(step));
|
144
|
+
}
|
145
|
+
|
146
|
+
return step;
|
147
|
+
});
|
148
|
+
};
|
149
|
+
|
150
|
+
exports.updateContentReviewStep = updateContentReviewStep;
|
151
|
+
|
152
|
+
const isInstallationPending = ({
|
153
|
+
tenancy,
|
154
|
+
i18n
|
155
|
+
}) => {
|
156
|
+
/**
|
157
|
+
* In case of a fresh webiny project "tenant" and "locale" won't be there until
|
158
|
+
* installation is completed. So, we need to skip "APW" creation till then.
|
159
|
+
*/
|
160
|
+
const tenant = tenancy.getCurrentTenant();
|
161
|
+
|
162
|
+
if (!tenant) {
|
163
|
+
return true;
|
164
|
+
}
|
165
|
+
|
166
|
+
return !i18n.getContentLocale();
|
167
|
+
};
|
168
|
+
|
169
|
+
exports.isInstallationPending = isInstallationPending;
|
170
|
+
const WORKFLOW_PRECEDENCE = {
|
171
|
+
[_types.WorkflowScopeTypes.DEFAULT]: 0,
|
172
|
+
[_types.WorkflowScopeTypes.CUSTOM]: 1
|
173
|
+
};
|
174
|
+
|
175
|
+
const workflowByPrecedenceDesc = (a, b) => {
|
176
|
+
const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];
|
177
|
+
const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];
|
178
|
+
/**
|
179
|
+
* In descending order of workflow precedence.
|
180
|
+
*/
|
181
|
+
|
182
|
+
return scoreB - scoreA;
|
183
|
+
};
|
184
|
+
|
185
|
+
exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
|
186
|
+
|
187
|
+
const workflowByCreatedOnDesc = (a, b) => {
|
188
|
+
const createdOnA = (0, _get.default)(a, "createdOn");
|
189
|
+
const createdOnB = (0, _get.default)(b, "createdOn");
|
190
|
+
/**
|
191
|
+
* In descending order of workflow createdOn i.e. the most recent one first.
|
192
|
+
*/
|
193
|
+
|
194
|
+
return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
|
195
|
+
};
|
196
|
+
|
197
|
+
exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["ALPHANUMERIC","getNanoid","customAlphabet","hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { customAlphabet } from \"nanoid\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nconst ALPHANUMERIC = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\nexport const getNanoid = customAlphabet(ALPHANUMERIC, 10);\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;;;;;AAcA,MAAMA,YAAY,GAAG,gEAArB;AACO,MAAMC,SAAS,GAAG,IAAAC,sBAAA,EAAeF,YAAf,EAA6B,EAA7B,CAAlB;;;AAaA,MAAMG,WAAW,GAAG,MAAOC,MAAP,IAAwD;EAC/E,MAAM;IAAEC,WAAF;IAAeC,QAAf;IAAyBC;EAAzB,IAAkCH,MAAxC;;EACA,KAAK,MAAMI,YAAX,IAA2BD,IAAI,CAACE,SAAhC,EAA2C;IACvC,MAAMC,KAAK,GAAG,MAAML,WAAW,CAACG,YAAY,CAACG,EAAd,CAA/B;;IAEA,IAAID,KAAK,CAACE,UAAN,KAAqBN,QAAQ,CAACK,EAAlC,EAAsC;MAClC,OAAO,IAAP;IACH;EACJ;;EAED,OAAO,KAAP;AACH,CAXM;;;;AAaA,MAAME,QAAQ,GAAG,CAACC,MAAD,EAA8BC,GAA9B,KAA8C;EAClE,OAAO,IAAAC,YAAA,EAAIF,MAAJ,EAAa,UAASC,GAAI,EAA1B,CAAP;AACH,CAFM;;;;AAIA,MAAME,iCAAiC,GAAG,CAC7CC,aAD6C,EAE7CC,KAF6C,EAG7CC,kBAH6C,KAIhB;EAC7B;AACJ;AACA;EACI,IAAID,KAAK,KAAK,CAAd,EAAiB;IACb,OAAOE,iCAAA,C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C;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAF,CAAQzC,IAAT,CAAlC;EACA,MAAM0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAF,CAAQzC,IAAT,CAAlC;EACA;AACJ;AACA;;EACI,OAAO0C,MAAM,GAAGF,MAAhB;AACH,CAPM;;;;AASA,MAAMG,uBAAuB,GAAG,CAACL,CAAD,EAAiBC,CAAjB,KAAoC;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAA,EAAI8C,CAAJ,EAAO,WAAP,CAAnB;EACA,MAAMO,UAAU,GAAG,IAAArD,YAAA,EAAI+C,CAAJ,EAAO,WAAP,CAAnB;EACA;AACJ;AACA;;EACI,OAAO,IAAIO,IAAJ,CAASD,UAAT,EAAqBE,OAArB,KAAiC,IAAID,IAAJ,CAASF,UAAT,EAAqBG,OAArB,EAAxC;AACH,CAPM"}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createScheduleActionMethods = createScheduleActionMethods;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _mdbid = _interopRequireDefault(require("mdbid"));
|
13
|
+
|
14
|
+
var _fields = require("@commodo/fields");
|
15
|
+
|
16
|
+
var _validation = require("@webiny/validation");
|
17
|
+
|
18
|
+
var _types = require("./types");
|
19
|
+
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
21
|
+
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
23
|
+
|
24
|
+
const CreateDataModel = (0, _fields.withFields)(instance => {
|
25
|
+
return {
|
26
|
+
datetime: (0, _fields.string)({
|
27
|
+
validation: _validation.validation.create(`required`)
|
28
|
+
}),
|
29
|
+
type: (0, _fields.string)({
|
30
|
+
validation: _validation.validation.create(`required,in:${_types.ApwContentTypes.PAGE}:${_types.ApwContentTypes.CMS_ENTRY}`)
|
31
|
+
}),
|
32
|
+
action: (0, _fields.string)({
|
33
|
+
validation: _validation.validation.create(`required,in:${_types.ApwScheduleActionTypes.PUBLISH}:${_types.ApwScheduleActionTypes.UNPUBLISH}`)
|
34
|
+
}),
|
35
|
+
entryId: (0, _fields.string)({
|
36
|
+
validation: _validation.validation.create(`required`)
|
37
|
+
}),
|
38
|
+
modelId: (0, _fields.string)({
|
39
|
+
validation: value => {
|
40
|
+
if (instance.type !== _types.ApwContentTypes.CMS_ENTRY) {
|
41
|
+
return true;
|
42
|
+
} else if (!!value) {
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
|
46
|
+
throw new Error(`There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`);
|
47
|
+
}
|
48
|
+
})
|
49
|
+
};
|
50
|
+
})();
|
51
|
+
|
52
|
+
function createScheduleActionMethods({
|
53
|
+
storageOperations,
|
54
|
+
getIdentity,
|
55
|
+
getTenant,
|
56
|
+
getLocale
|
57
|
+
}) {
|
58
|
+
const getTenantAndLocale = () => {
|
59
|
+
const tenant = getTenant().id;
|
60
|
+
const locale = getLocale().code;
|
61
|
+
return {
|
62
|
+
tenant,
|
63
|
+
locale
|
64
|
+
};
|
65
|
+
};
|
66
|
+
|
67
|
+
return {
|
68
|
+
async get(id) {
|
69
|
+
return storageOperations.get({
|
70
|
+
where: _objectSpread({
|
71
|
+
id
|
72
|
+
}, getTenantAndLocale())
|
73
|
+
});
|
74
|
+
},
|
75
|
+
|
76
|
+
async list(params) {
|
77
|
+
return storageOperations.list(_objectSpread(_objectSpread({}, params), {}, {
|
78
|
+
where: _objectSpread(_objectSpread({}, params.where), getTenantAndLocale())
|
79
|
+
}));
|
80
|
+
},
|
81
|
+
|
82
|
+
async create(input) {
|
83
|
+
const createDataModel = new CreateDataModel().populate(input);
|
84
|
+
await createDataModel.validate();
|
85
|
+
const id = (0, _mdbid.default)();
|
86
|
+
const identity = getIdentity();
|
87
|
+
const data = await createDataModel.toJSON();
|
88
|
+
|
89
|
+
const scheduleAction = _objectSpread(_objectSpread({}, getTenantAndLocale()), {}, {
|
90
|
+
data,
|
91
|
+
id,
|
92
|
+
createdOn: new Date().toISOString(),
|
93
|
+
savedOn: new Date().toISOString(),
|
94
|
+
createdBy: {
|
95
|
+
id: identity.id,
|
96
|
+
type: identity.type,
|
97
|
+
displayName: identity.displayName
|
98
|
+
}
|
99
|
+
});
|
100
|
+
|
101
|
+
return await storageOperations.create({
|
102
|
+
item: scheduleAction,
|
103
|
+
input
|
104
|
+
});
|
105
|
+
},
|
106
|
+
|
107
|
+
async update(id, data) {
|
108
|
+
const updateDataModel = new CreateDataModel().populate(data);
|
109
|
+
await updateDataModel.validate();
|
110
|
+
const original = await this.get(id);
|
111
|
+
|
112
|
+
if (!original) {
|
113
|
+
throw new Error("Not found!");
|
114
|
+
}
|
115
|
+
|
116
|
+
return await storageOperations.update({
|
117
|
+
item: original,
|
118
|
+
input: data
|
119
|
+
});
|
120
|
+
},
|
121
|
+
|
122
|
+
async delete(id) {
|
123
|
+
await storageOperations.delete(_objectSpread({
|
124
|
+
id
|
125
|
+
}, getTenantAndLocale()));
|
126
|
+
return true;
|
127
|
+
},
|
128
|
+
|
129
|
+
async getCurrentTask() {
|
130
|
+
return await storageOperations.getCurrentTask({
|
131
|
+
where: _objectSpread({}, getTenantAndLocale())
|
132
|
+
});
|
133
|
+
},
|
134
|
+
|
135
|
+
async updateCurrentTask(item) {
|
136
|
+
return await storageOperations.updateCurrentTask({
|
137
|
+
item
|
138
|
+
});
|
139
|
+
},
|
140
|
+
|
141
|
+
async deleteCurrentTask() {
|
142
|
+
return await storageOperations.deleteCurrentTask(_objectSpread({}, getTenantAndLocale()));
|
143
|
+
}
|
144
|
+
|
145
|
+
};
|
146
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["CreateDataModel","withFields","instance","datetime","string","validation","create","type","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","value","Error","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","input","createDataModel","populate","validate","mdbid","identity","data","toJSON","scheduleAction","createdOn","Date","toISOString","savedOn","createdBy","displayName","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport {\n ApwContentTypes,\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n ApwScheduleActionTypes,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\n\nconst CreateDataModel = withFields((instance: any) => {\n return {\n datetime: string({\n validation: validation.create(`required`)\n }),\n type: string({\n validation: validation.create(\n `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`\n )\n }),\n action: string({\n validation: validation.create(\n `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`\n )\n }),\n entryId: string({\n validation: validation.create(`required`)\n }),\n modelId: string({\n validation: (value: string) => {\n if (instance.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!value) {\n return true;\n }\n throw new Error(\n `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\n );\n }\n })\n };\n})();\n\ninterface GetTenantAndLocaleResult {\n tenant: string;\n locale: string;\n}\n\nexport function createScheduleActionMethods({\n storageOperations,\n getIdentity,\n getTenant,\n getLocale\n}: CreateScheduleActionParams): ApwScheduleActionCrud {\n const getTenantAndLocale = (): GetTenantAndLocaleResult => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n return {\n tenant,\n locale\n };\n };\n return {\n async get(id) {\n return storageOperations.get({\n where: {\n id,\n ...getTenantAndLocale()\n }\n });\n },\n async list(params) {\n return storageOperations.list({\n ...params,\n where: {\n ...params.where,\n ...getTenantAndLocale()\n }\n });\n },\n async create(input) {\n const createDataModel = new CreateDataModel().populate(input);\n\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = getIdentity();\n\n const data: ApwScheduleActionData = await createDataModel.toJSON();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, data) {\n const updateDataModel = new CreateDataModel().populate(data);\n\n await updateDataModel.validate();\n\n const original = await this.get(id);\n\n if (!original) {\n throw new Error(\"Not found!\");\n }\n\n return await storageOperations.update({ item: original, input: data });\n },\n async delete(id: string) {\n await storageOperations.delete({ id, ...getTenantAndLocale() });\n\n return true;\n },\n async getCurrentTask() {\n return await storageOperations.getCurrentTask({ where: { ...getTenantAndLocale() } });\n },\n async updateCurrentTask(item) {\n return await storageOperations.updateCurrentTask({ item });\n },\n async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MAFkC,CAAzB,CAAb;IAIH,CA7CE;;IA8CH,MAAMgB,MAAN,CAAavB,EAAb,EAAiBa,IAAjB,EAAuB;MACnB,MAAMW,eAAe,GAAG,IAAIlD,eAAJ,GAAsBmC,QAAtB,CAA+BI,IAA/B,CAAxB;MAEA,MAAMW,eAAe,CAACd,QAAhB,EAAN;MAEA,MAAMe,QAAQ,GAAG,MAAM,KAAKtB,GAAL,CAASH,EAAT,CAAvB;;MAEA,IAAI,CAACyB,QAAL,EAAe;QACX,MAAM,IAAIjC,KAAJ,CAAU,YAAV,CAAN;MACH;;MAED,OAAO,MAAME,iBAAiB,CAAC6B,MAAlB,CAAyB;QAAED,IAAI,EAAEG,QAAR;QAAkBlB,KAAK,EAAEM;MAAzB,CAAzB,CAAb;IACH,CA1DE;;IA2DH,MAAMa,MAAN,CAAa1B,EAAb,EAAyB;MACrB,MAAMN,iBAAiB,CAACgC,MAAlB;QAA2B1B;MAA3B,GAAkCF,kBAAkB,EAApD,EAAN;MAEA,OAAO,IAAP;IACH,CA/DE;;IAgEH,MAAM6B,cAAN,GAAuB;MACnB,OAAO,MAAMjC,iBAAiB,CAACiC,cAAlB,CAAiC;QAAEvB,KAAK,oBAAON,kBAAkB,EAAzB;MAAP,CAAjC,CAAb;IACH,CAlEE;;IAmEH,MAAM8B,iBAAN,CAAwBN,IAAxB,EAA8B;MAC1B,OAAO,MAAM5B,iBAAiB,CAACkC,iBAAlB,CAAoC;QAAEN;MAAF,CAApC,CAAb;IACH,CArEE;;IAsEH,MAAMO,iBAAN,GAA0B;MACtB,OAAO,MAAMnC,iBAAiB,CAACmC,iBAAlB,mBAAyC/B,kBAAkB,EAA3D,EAAb;IACH;;EAxEE,CAAP;AA0EH"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ApwScheduleActionStorageOperations } from "../../types";
|
2
|
+
import { ContextPlugin } from "@webiny/api";
|
3
|
+
export interface HandlerArgs {
|
4
|
+
datetime: string;
|
5
|
+
tenant: string;
|
6
|
+
locale: string;
|
7
|
+
futureDatetime?: string;
|
8
|
+
}
|
9
|
+
interface Configuration {
|
10
|
+
storageOperations: ApwScheduleActionStorageOperations;
|
11
|
+
}
|
12
|
+
export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler").EventPlugin<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
|
13
|
+
export {};
|