@webiny/api-apw 0.0.0-unstable.1e66d121db → 0.0.0-unstable.2696f9d9e8
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/ApwChangeRequestNotification.d.ts +27 -0
- package/ApwChangeRequestNotification.js +28 -0
- package/ApwChangeRequestNotification.js.map +1 -0
- package/ApwCommentNotification.d.ts +27 -0
- package/ApwCommentNotification.js +28 -0
- package/ApwCommentNotification.js.map +1 -0
- package/ApwContentReviewNotification.d.ts +26 -0
- package/ApwContentReviewNotification.js +28 -0
- package/ApwContentReviewNotification.js.map +1 -0
- package/ApwContentUrlPlugin.d.ts +19 -0
- package/ApwContentUrlPlugin.js +28 -0
- package/ApwContentUrlPlugin.js.map +1 -0
- package/ContentApwSettingsPlugin.js +5 -9
- package/ContentApwSettingsPlugin.js.map +1 -1
- package/README.md +3 -3
- package/crud/createChangeRequestMethods.js +7 -12
- package/crud/createChangeRequestMethods.js.map +1 -1
- package/crud/createCommentMethods.js +7 -13
- package/crud/createCommentMethods.js.map +1 -1
- package/crud/createContentReviewMethods.js +83 -111
- package/crud/createContentReviewMethods.js.map +1 -1
- package/crud/createReviewerMethods.js +7 -13
- package/crud/createReviewerMethods.js.map +1 -1
- package/crud/createWorkflowMethods.js +7 -18
- package/crud/createWorkflowMethods.js.map +1 -1
- package/crud/index.js +5 -29
- package/crud/index.js.map +1 -1
- package/crud/utils.js +6 -33
- package/crud/utils.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +6 -16
- package/index.js.map +1 -1
- package/package.json +40 -47
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +4 -19
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/cms/apwEntryPlugins.js +8 -13
- package/plugins/cms/apwEntryPlugins.js.map +1 -1
- package/plugins/cms/index.js +7 -10
- package/plugins/cms/index.js.map +1 -1
- package/plugins/cms/linkContentReviewToEntry.js +4 -20
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
- package/plugins/cms/linkWorkflowToEntry.js +17 -45
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
- package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
- package/plugins/cms/notifications/changeRequestNotification.js +33 -0
- package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
- package/plugins/cms/notifications/commentNotification.d.ts +1 -0
- package/plugins/cms/notifications/commentNotification.js +33 -0
- package/plugins/cms/notifications/commentNotification.js.map +1 -0
- package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
- package/plugins/cms/notifications/contentReviewNotification.js +33 -0
- package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
- package/plugins/cms/notifications/contentUrl.d.ts +8 -0
- package/plugins/cms/notifications/contentUrl.js +55 -0
- package/plugins/cms/notifications/contentUrl.js.map +1 -0
- package/plugins/cms/triggerContentReview.js +5 -18
- package/plugins/cms/triggerContentReview.js.map +1 -1
- package/plugins/cms/updateContentReviewStatus.js +14 -30
- package/plugins/cms/updateContentReviewStatus.js.map +1 -1
- package/plugins/cms/utils.d.ts +3 -2
- package/plugins/cms/utils.js +23 -60
- package/plugins/cms/utils.js.map +1 -1
- package/plugins/context.d.ts +0 -1
- package/plugins/context.js +2 -45
- package/plugins/context.js.map +1 -1
- package/plugins/graphql/changeRequest.gql.js +16 -19
- package/plugins/graphql/changeRequest.gql.js.map +1 -1
- package/plugins/graphql/comment.gql.js +41 -42
- package/plugins/graphql/comment.gql.js.map +1 -1
- package/plugins/graphql/contentReview.gql.js +25 -34
- package/plugins/graphql/contentReview.gql.js.map +1 -1
- package/plugins/graphql/reviewer.gql.js +17 -19
- package/plugins/graphql/reviewer.gql.js.map +1 -1
- package/plugins/graphql/utils.d.ts +2 -0
- package/plugins/graphql/utils.js +12 -0
- package/plugins/graphql/utils.js.map +1 -0
- package/plugins/graphql/workflow.gql.js +15 -19
- package/plugins/graphql/workflow.gql.js.map +1 -1
- package/plugins/graphql.js +5 -18
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/createReviewerFromIdentity.js +28 -15
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +3 -9
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +3 -8
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
- package/plugins/hooks/index.js +4 -13
- package/plugins/hooks/index.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +15 -20
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/plugins/hooks/initializeNotifications.d.ts +2 -0
- package/plugins/hooks/initializeNotifications.js +17 -0
- package/plugins/hooks/initializeNotifications.js.map +1 -0
- package/plugins/hooks/listContentReviews.d.ts +1 -1
- package/plugins/hooks/listContentReviews.js +11 -33
- package/plugins/hooks/listContentReviews.js.map +1 -1
- package/plugins/hooks/notifications/appUrl.d.ts +2 -0
- package/plugins/hooks/notifications/appUrl.js +20 -0
- package/plugins/hooks/notifications/appUrl.js.map +1 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.js +113 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
- package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
- package/plugins/hooks/notifications/changeRequestUrl.js +29 -0
- package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
- package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
- package/plugins/hooks/notifications/commentAfterCreate.js +124 -0
- package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
- package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
- package/plugins/hooks/notifications/commentUrl.js +29 -0
- package/plugins/hooks/notifications/commentUrl.js.map +1 -0
- package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
- package/plugins/hooks/notifications/contentReviewAfterCreate.js +96 -0
- package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
- package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
- package/plugins/hooks/notifications/contentReviewUrl.js +28 -0
- package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
- package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
- package/plugins/hooks/notifications/contentUrl.js +26 -0
- package/plugins/hooks/notifications/contentUrl.js.map +1 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +23 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +23 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +23 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
- package/plugins/hooks/notifications/reviewers.d.ts +15 -0
- package/plugins/hooks/notifications/reviewers.js +47 -0
- package/plugins/hooks/notifications/reviewers.js.map +1 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.js +43 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
- package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
- package/plugins/hooks/notifications/sendCommentNotification.js +43 -0
- package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.js +43 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
- package/plugins/hooks/updatePendingChangeRequests.js +7 -13
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
- package/plugins/hooks/updateTotalComments.js +21 -23
- package/plugins/hooks/updateTotalComments.js.map +1 -1
- package/plugins/hooks/validateChangeRequest.js +27 -16
- package/plugins/hooks/validateChangeRequest.js.map +1 -1
- package/plugins/hooks/validateComment.js +13 -12
- package/plugins/hooks/validateComment.js.map +1 -1
- package/plugins/hooks/validateContentReview.js +2 -6
- package/plugins/hooks/validateContentReview.js.map +1 -1
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +4 -19
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/pageBuilder/apwContentPagePlugins.js +2 -4
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +3 -6
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
- package/plugins/pageBuilder/index.js +7 -8
- package/plugins/pageBuilder/index.js.map +1 -1
- package/plugins/pageBuilder/linkContentReviewToPage.js +15 -27
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
- package/plugins/pageBuilder/linkWorkflowToPage.js +3 -31
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +33 -0
- package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
- package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/commentNotification.js +33 -0
- package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.js +33 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
- package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
- package/plugins/pageBuilder/notifications/contentUrl.js +49 -0
- package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
- package/plugins/pageBuilder/triggerContentReview.js +2 -11
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
- package/plugins/pageBuilder/updateContentReviewStatus.js +10 -17
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
- package/plugins/pageBuilder/utils.d.ts +2 -2
- package/plugins/pageBuilder/utils.js +3 -35
- package/plugins/pageBuilder/utils.js.map +1 -1
- package/plugins/utils.d.ts +1 -2
- package/plugins/utils.js +6 -52
- package/plugins/utils.js.map +1 -1
- package/scheduler/createScheduleActionMethods.js +45 -50
- package/scheduler/createScheduleActionMethods.js.map +1 -1
- package/scheduler/handlers/executeAction/index.d.ts +1 -1
- package/scheduler/handlers/executeAction/index.js +47 -40
- package/scheduler/handlers/executeAction/index.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +19 -9
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +11 -28
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +10 -92
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/security.js +2 -11
- package/scheduler/handlers/executeAction/security.js.map +1 -1
- package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
- package/scheduler/handlers/scheduleAction/index.js +24 -37
- package/scheduler/handlers/scheduleAction/index.js.map +1 -1
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +20 -36
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
- package/scheduler/handlers/utils.d.ts +2 -4
- package/scheduler/handlers/utils.js +8 -47
- package/scheduler/handlers/utils.js.map +1 -1
- package/scheduler/index.js +2 -3
- package/scheduler/index.js.map +1 -1
- package/scheduler/types.d.ts +12 -28
- package/scheduler/types.js +13 -22
- package/scheduler/types.js.map +1 -1
- package/storageOperations/changeRequestStorageOperations.js +59 -45
- package/storageOperations/changeRequestStorageOperations.js.map +1 -1
- package/storageOperations/commentStorageOperations.js +35 -50
- package/storageOperations/commentStorageOperations.js.map +1 -1
- package/storageOperations/contentReviewStorageOperations.d.ts +1 -1
- package/storageOperations/contentReviewStorageOperations.js +34 -43
- package/storageOperations/contentReviewStorageOperations.js.map +1 -1
- package/storageOperations/index.d.ts +1 -7
- package/storageOperations/index.js +10 -29
- package/storageOperations/index.js.map +1 -1
- package/storageOperations/models/changeRequest.model.d.ts +1 -2
- package/storageOperations/models/changeRequest.model.js +6 -15
- package/storageOperations/models/changeRequest.model.js.map +1 -1
- package/storageOperations/models/comment.model.d.ts +1 -2
- package/storageOperations/models/comment.model.js +6 -14
- package/storageOperations/models/comment.model.js.map +1 -1
- package/storageOperations/models/contentReview.model.d.ts +1 -2
- package/storageOperations/models/contentReview.model.js +13 -37
- package/storageOperations/models/contentReview.model.js.map +1 -1
- package/storageOperations/models/index.js +6 -50
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/models/reviewer.model.d.ts +1 -2
- package/storageOperations/models/reviewer.model.js +22 -14
- package/storageOperations/models/reviewer.model.js.map +1 -1
- package/storageOperations/models/utils.js +2 -4
- package/storageOperations/models/utils.js.map +1 -1
- package/storageOperations/models/workflow.model.d.ts +1 -2
- package/storageOperations/models/workflow.model.js +19 -42
- package/storageOperations/models/workflow.model.js.map +1 -1
- package/storageOperations/reviewerStorageOperations.d.ts +1 -1
- package/storageOperations/reviewerStorageOperations.js +34 -40
- package/storageOperations/reviewerStorageOperations.js.map +1 -1
- package/storageOperations/types.js +3 -1
- package/storageOperations/workflowStorageOperations.js +40 -47
- package/storageOperations/workflowStorageOperations.js.map +1 -1
- package/types.d.ts +39 -25
- package/types.js +126 -42
- package/types.js.map +1 -1
- package/utils/contentApwSettingsPlugin.js +2 -6
- package/utils/contentApwSettingsPlugin.js.map +1 -1
- package/utils/errors.js +2 -17
- package/utils/errors.js.map +1 -1
- package/utils/fieldResolver.js +8 -18
- package/utils/fieldResolver.js.map +1 -1
- package/utils/pickEntryFieldValues.d.ts +3 -0
- package/utils/pickEntryFieldValues.js +31 -0
- package/utils/pickEntryFieldValues.js.map +1 -0
- package/utils/resolve.d.ts +1 -1
- package/utils/resolve.js +2 -3
- package/utils/resolve.js.map +1 -1
- package/storageOperations/models/contentModelPluginFactory.d.ts +0 -15
- package/storageOperations/models/contentModelPluginFactory.js +0 -28
- package/storageOperations/models/contentModelPluginFactory.js.map +0 -1
@@ -1,20 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
6
4
|
value: true
|
7
5
|
});
|
8
6
|
exports.updateContentReviewStatus = void 0;
|
9
|
-
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
-
|
12
7
|
var _types = require("../../types");
|
13
|
-
|
14
8
|
var _utils = require("../../crud/utils");
|
15
|
-
|
16
9
|
var _utils2 = require("./utils");
|
17
|
-
|
18
10
|
const updateContentReviewStatus = params => {
|
19
11
|
const {
|
20
12
|
apw,
|
@@ -25,57 +17,47 @@ const updateContentReviewStatus = params => {
|
|
25
17
|
entry,
|
26
18
|
model
|
27
19
|
}) => {
|
28
|
-
|
29
|
-
|
30
|
-
if ((0, _utils2.isAwpModel)(model)) {
|
20
|
+
if ((0, _utils2.isApwDisabledOnModel)(model)) {
|
31
21
|
return;
|
32
22
|
}
|
33
|
-
|
34
|
-
const contentReviewId = (_entry$meta = entry.meta) === null || _entry$meta === void 0 ? void 0 : (_entry$meta$apw = _entry$meta.apw) === null || _entry$meta$apw === void 0 ? void 0 : _entry$meta$apw.contentReviewId;
|
23
|
+
const contentReviewId = entry.meta?.apw?.contentReviewId;
|
35
24
|
/**
|
36
25
|
* Bail out if there is no "content review" linked.
|
37
26
|
*/
|
38
|
-
|
39
27
|
if (!contentReviewId) {
|
40
28
|
return;
|
41
29
|
}
|
42
|
-
|
43
30
|
const contentReview = await apw.contentReview.get(contentReviewId);
|
44
31
|
const identity = security.getIdentity();
|
45
32
|
/**
|
46
33
|
* If content review is "readyToBePublished set its status as "published" after page publish.
|
47
34
|
*/
|
48
|
-
|
49
35
|
if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {
|
50
36
|
return;
|
51
37
|
}
|
52
|
-
|
53
38
|
await apw.contentReview.update(contentReviewId, {
|
54
39
|
reviewStatus: _types.ApwContentReviewStatus.PUBLISHED,
|
55
|
-
content:
|
40
|
+
content: {
|
41
|
+
...contentReview.content,
|
42
|
+
..._utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,
|
56
43
|
publishedBy: identity.id
|
57
|
-
}
|
44
|
+
}
|
58
45
|
});
|
59
46
|
});
|
60
47
|
cms.onEntryAfterUnpublish.subscribe(async ({
|
61
48
|
entry,
|
62
49
|
model
|
63
50
|
}) => {
|
64
|
-
|
65
|
-
|
66
|
-
if ((0, _utils2.isAwpModel)(model)) {
|
51
|
+
if ((0, _utils2.isApwDisabledOnModel)(model)) {
|
67
52
|
return;
|
68
53
|
}
|
69
|
-
|
70
|
-
const contentReviewId = (_entry$meta2 = entry.meta) === null || _entry$meta2 === void 0 ? void 0 : (_entry$meta2$apw = _entry$meta2.apw) === null || _entry$meta2$apw === void 0 ? void 0 : _entry$meta2$apw.contentReviewId;
|
54
|
+
const contentReviewId = entry.meta?.apw?.contentReviewId;
|
71
55
|
/**
|
72
56
|
* Bail out if there is no "content review" linked.
|
73
57
|
*/
|
74
|
-
|
75
58
|
if (!contentReviewId) {
|
76
59
|
return;
|
77
60
|
}
|
78
|
-
|
79
61
|
const contentReview = await apw.contentReview.get(contentReviewId);
|
80
62
|
/**
|
81
63
|
* If content review is "published set its status as "readyToBePublished" after page unpublish.
|
@@ -84,14 +66,16 @@ const updateContentReviewStatus = params => {
|
|
84
66
|
if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.PUBLISHED) {
|
85
67
|
return;
|
86
68
|
}
|
87
|
-
|
88
69
|
await apw.contentReview.update(contentReviewId, {
|
89
70
|
reviewStatus: _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED,
|
90
|
-
content:
|
71
|
+
content: {
|
72
|
+
...contentReview.content,
|
73
|
+
..._utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,
|
91
74
|
publishedBy: null
|
92
|
-
}
|
75
|
+
}
|
93
76
|
});
|
94
77
|
});
|
95
78
|
};
|
79
|
+
exports.updateContentReviewStatus = updateContentReviewStatus;
|
96
80
|
|
97
|
-
|
81
|
+
//# sourceMappingURL=updateContentReviewStatus.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","
|
1
|
+
{"version":3,"names":["_types","require","_utils","_utils2","updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","isApwDisabledOnModel","contentReviewId","meta","contentReview","get","identity","getIdentity","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onEntryAfterUnpublish","exports"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryAfterPublishTopicParams,\n OnCmsEntryAfterUnpublishTopicParams\n} from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\nimport { isApwDisabledOnModel } from \"~/plugins/cms/utils\";\n\ninterface UpdateContentReviewStatusParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\n\nexport const updateContentReviewStatus = (params: UpdateContentReviewStatusParams) => {\n const { apw, cms, security } = params;\n\n cms.onEntryAfterPublish.subscribe<OnCmsEntryAfterPublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n /**\n * Bail out if there is no \"content review\" linked.\n */\n if (!contentReviewId) {\n return;\n }\n\n const contentReview = await apw.contentReview.get(contentReviewId);\n const identity = security.getIdentity();\n /**\n * If content review is \"readyToBePublished set its status as \"published\" after page publish.\n */\n if (contentReview.reviewStatus !== ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n reviewStatus: ApwContentReviewStatus.PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: identity.id\n }\n });\n }\n );\n cms.onEntryAfterUnpublish.subscribe<OnCmsEntryAfterUnpublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n /**\n * Bail out if there is no \"content review\" linked.\n */\n if (!contentReviewId) {\n return;\n }\n\n const contentReview = await apw.contentReview.get(contentReviewId);\n /**\n * If content review is \"published set its status as \"readyToBePublished\" after page unpublish.\n */\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n reviewStatus: ApwContentReviewStatus.READY_TO_BE_PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: null\n }\n });\n }\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ACxD;AACZ;AACA;IACY,IAAI,CAACA,eAAe,EAAE;MAClB;IACJ;IAEA,MAAME,aAAa,GAAG,MAAMV,GAAG,CAACU,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;IAClE;AACZ;AACA;;IAEY,IAAIE,aAAa,CAACI,YAAY,KAAKC,6BAAsB,CAACG,SAAS,EAAE;MACjE;IACJ;IACA,MAAMlB,GAAG,CAACU,aAAa,CAACO,MAAM,CAACT,eAAe,EAAE;MAC5CM,YAAY,EAAEC,6BAAsB,CAACC,qBAAqB;MAC1DG,OAAO,EAAE;QACL,GAAGT,aAAa,CAACS,OAAO;QACxB,GAAGC,mDAA4C;QAC/CC,WAAW,EAAE;MACjB;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAACG,OAAA,CAAA1B,yBAAA,GAAAA,yBAAA"}
|
package/plugins/cms/utils.d.ts
CHANGED
@@ -20,8 +20,9 @@ export declare const updateEntryMeta: (params: UpdateEntryMetaParams) => Promise
|
|
20
20
|
interface AssignWorkflowToEntryParams {
|
21
21
|
apw: AdvancedPublishingWorkflow;
|
22
22
|
entry: CmsEntry;
|
23
|
+
model: CmsModel;
|
23
24
|
}
|
24
25
|
export declare const assignWorkflowToEntry: (params: AssignWorkflowToEntryParams) => Promise<void>;
|
25
|
-
export declare const hasEntries: (workflow: ApwWorkflow) =>
|
26
|
-
export declare const
|
26
|
+
export declare const hasEntries: (workflow: ApwWorkflow) => boolean;
|
27
|
+
export declare const isApwDisabledOnModel: (model: Pick<CmsModel, "modelId" | "isPrivate">) => boolean;
|
27
28
|
export {};
|
package/plugins/cms/utils.js
CHANGED
@@ -1,92 +1,65 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
|
-
exports.updateEntryMeta = exports.
|
9
|
-
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
-
|
7
|
+
exports.updateEntryMeta = exports.isApwDisabledOnModel = exports.hasEntries = exports.getLatestEntryRevision = exports.getEntryTitle = exports.fetchModel = exports.assignWorkflowToEntry = void 0;
|
12
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
-
|
14
9
|
var _types = require("../../types");
|
15
|
-
|
16
10
|
var _utils = require("../utils");
|
17
|
-
|
18
11
|
var _changeRequest = require("../../storageOperations/models/changeRequest.model");
|
19
|
-
|
20
12
|
var _comment = require("../../storageOperations/models/comment.model");
|
21
|
-
|
22
13
|
var _contentReview = require("../../storageOperations/models/contentReview.model");
|
23
|
-
|
24
14
|
var _reviewer = require("../../storageOperations/models/reviewer.model");
|
25
|
-
|
26
15
|
var _workflow = require("../../storageOperations/models/workflow.model");
|
27
|
-
|
28
16
|
const fetchModel = async (cms, id, settings) => {
|
29
17
|
if (!settings) {
|
30
18
|
throw new _error.default("Missing settings.", "SETTINGS_ERROR", {
|
31
19
|
id
|
32
20
|
});
|
33
21
|
}
|
34
|
-
|
35
22
|
const modelId = settings.modelId;
|
36
|
-
|
37
23
|
if (!modelId) {
|
38
24
|
throw new _error.default("Missing modelId in settings.", "MODEL_ID_ERROR", {
|
39
25
|
id,
|
40
26
|
settings
|
41
27
|
});
|
42
28
|
}
|
43
|
-
|
44
29
|
const model = await cms.getModel(modelId);
|
45
|
-
|
46
30
|
if (model) {
|
47
31
|
return model;
|
48
32
|
}
|
49
|
-
|
50
33
|
throw new _error.default("There is no requested model in the system.", "MODEL_NOT_EXISTS", {
|
51
34
|
id,
|
52
35
|
settings
|
53
36
|
});
|
54
37
|
};
|
55
|
-
|
56
38
|
exports.fetchModel = fetchModel;
|
57
|
-
|
58
39
|
const getEntryTitle = (model, entry) => {
|
59
40
|
const titleFieldId = model.titleFieldId;
|
60
|
-
|
61
41
|
if (!titleFieldId || !entry.values[titleFieldId]) {
|
62
42
|
return entry.id;
|
63
43
|
}
|
64
|
-
|
65
44
|
return entry.values[titleFieldId];
|
66
45
|
};
|
67
|
-
|
68
46
|
exports.getEntryTitle = getEntryTitle;
|
69
|
-
|
70
47
|
const getLatestEntryRevision = async params => {
|
71
48
|
const {
|
72
49
|
cms,
|
73
50
|
model,
|
74
51
|
entryId
|
75
52
|
} = params;
|
76
|
-
const
|
77
|
-
const item = items.shift();
|
78
|
-
|
53
|
+
const [item] = await cms.getLatestEntriesByIds(model, [entryId]);
|
79
54
|
if (!item) {
|
80
55
|
throw new _error.default("There is no entry with given ID.", "ENTRY_NOT_FOUND", {
|
81
|
-
entryId
|
56
|
+
entryId,
|
57
|
+
model: model.modelId
|
82
58
|
});
|
83
59
|
}
|
84
|
-
|
85
60
|
return item;
|
86
61
|
};
|
87
|
-
|
88
62
|
exports.getLatestEntryRevision = getLatestEntryRevision;
|
89
|
-
|
90
63
|
const updateEntryMeta = async params => {
|
91
64
|
const {
|
92
65
|
entryId,
|
@@ -101,52 +74,39 @@ const updateEntryMeta = async params => {
|
|
101
74
|
});
|
102
75
|
await cms.updateEntry(model, entry.id, {}, meta);
|
103
76
|
};
|
104
|
-
|
105
77
|
exports.updateEntryMeta = updateEntryMeta;
|
106
|
-
|
107
78
|
const isWorkflowApplicable = (entry, workflow) => {
|
108
79
|
const application = workflow.app;
|
109
|
-
|
110
80
|
if (application !== _types.ApwWorkflowApplications.CMS) {
|
111
81
|
return false;
|
112
82
|
}
|
113
|
-
|
114
83
|
const scopeType = workflow.scope.type;
|
115
|
-
|
116
84
|
if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
|
117
85
|
return true;
|
118
86
|
} else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
|
119
|
-
|
120
|
-
|
121
|
-
const models = (_workflow$scope$data = workflow.scope.data) === null || _workflow$scope$data === void 0 ? void 0 : _workflow$scope$data.models;
|
122
|
-
|
87
|
+
const models = workflow.scope.data?.models;
|
123
88
|
if (Array.isArray(models) && models.includes(entry.modelId)) {
|
124
89
|
return true;
|
125
90
|
}
|
126
|
-
|
127
|
-
const entries = ((_workflow$scope$data2 = workflow.scope.data) === null || _workflow$scope$data2 === void 0 ? void 0 : _workflow$scope$data2.entries) || [];
|
128
|
-
|
91
|
+
const entries = workflow.scope.data?.entries || [];
|
129
92
|
if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {
|
130
93
|
return true;
|
131
94
|
}
|
132
|
-
|
133
95
|
return false;
|
134
96
|
}
|
135
|
-
|
136
97
|
throw new _error.default(`Unknown scope type "${scopeType}".`, "UNKNOWN_SCOPE_TYPE", {
|
137
98
|
workflow
|
138
99
|
});
|
139
100
|
};
|
140
|
-
|
141
101
|
const assignWorkflowToEntry = async params => {
|
142
102
|
const {
|
143
103
|
apw,
|
144
|
-
entry
|
104
|
+
entry,
|
105
|
+
model
|
145
106
|
} = params;
|
146
107
|
/**
|
147
108
|
* Lookup and assign "workflowId".
|
148
109
|
*/
|
149
|
-
|
150
110
|
try {
|
151
111
|
/*
|
152
112
|
* List all workflows for app cms
|
@@ -156,40 +116,38 @@ const assignWorkflowToEntry = async params => {
|
|
156
116
|
app: _types.ApwWorkflowApplications.CMS
|
157
117
|
}
|
158
118
|
});
|
159
|
-
console.log(`Found ${entries.length}
|
119
|
+
console.log(`Found ${entries.length} workflow(s) for model ${model.modelId}.`);
|
120
|
+
|
160
121
|
/*
|
161
122
|
* Re-order them based on workflow scope and pre-defined rule i.e.
|
162
123
|
* "specific" entry -> entry for a "category" -> "default".
|
163
124
|
* There can be more than one workflow with same "scope" and "app".
|
164
125
|
* Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
|
165
126
|
*/
|
166
|
-
|
167
127
|
const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
|
128
|
+
|
168
129
|
/**
|
169
130
|
* Assign the first applicable workflow to the page and exit.
|
170
131
|
*/
|
171
|
-
|
172
132
|
for (const workflow of sortedWorkflows) {
|
173
133
|
if (isWorkflowApplicable(entry, workflow) === false) {
|
174
134
|
console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);
|
175
135
|
continue;
|
176
136
|
}
|
177
|
-
|
178
|
-
|
137
|
+
entry.meta = {
|
138
|
+
...(entry.meta || {}),
|
179
139
|
apw: {
|
180
140
|
workflowId: workflow.id,
|
181
141
|
contentReviewId: null
|
182
142
|
}
|
183
|
-
}
|
143
|
+
};
|
184
144
|
return;
|
185
145
|
}
|
186
146
|
} catch (ex) {
|
187
147
|
throw new _error.default(`Failed to assign workflow to CMS entry "${entry.id}".`, ex.code, ex.data);
|
188
148
|
}
|
189
149
|
};
|
190
|
-
|
191
150
|
exports.assignWorkflowToEntry = assignWorkflowToEntry;
|
192
|
-
|
193
151
|
const hasEntries = workflow => {
|
194
152
|
const {
|
195
153
|
app,
|
@@ -197,11 +155,16 @@ const hasEntries = workflow => {
|
|
197
155
|
} = workflow;
|
198
156
|
return app === _types.ApwWorkflowApplications.CMS && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.entries);
|
199
157
|
};
|
200
|
-
|
201
158
|
exports.hasEntries = hasEntries;
|
202
|
-
|
203
|
-
|
159
|
+
const isApwDisabledOnModel = model => {
|
160
|
+
/**
|
161
|
+
* We should not run APW on private models as well.
|
162
|
+
*/
|
163
|
+
if (model.isPrivate) {
|
164
|
+
return true;
|
165
|
+
}
|
204
166
|
return [_changeRequest.CHANGE_REQUEST_MODEL_ID, _comment.COMMENT_MODEL_ID, _contentReview.CONTENT_REVIEW_MODEL_ID, _reviewer.REVIEWER_MODEL_ID, _workflow.WORKFLOW_MODEL_ID].includes(model.modelId);
|
205
167
|
};
|
168
|
+
exports.isApwDisabledOnModel = isApwDisabledOnModel;
|
206
169
|
|
207
|
-
|
170
|
+
//# sourceMappingURL=utils.js.map
|
package/plugins/cms/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["fetchModel","cms","id","settings","WebinyError","modelId","model","getModel","getEntryTitle","entry","titleFieldId","values","getLatestEntryRevision","params","entryId","items","getLatestEntriesByIds","item","shift","updateEntryMeta","meta","updateEntry","isWorkflowApplicable","workflow","application","app","ApwWorkflowApplications","CMS","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","models","data","Array","isArray","includes","entries","some","value","assignWorkflowToEntry","apw","list","where","console","log","length","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","workflowId","contentReviewId","ex","code","hasEntries","isAwpModel","CHANGE_REQUEST_MODEL_ID","COMMENT_MODEL_ID","CONTENT_REVIEW_MODEL_ID","REVIEWER_MODEL_ID","WORKFLOW_MODEL_ID"],"sources":["utils.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport {\n AdvancedPublishingWorkflow,\n ApwWorkflow,\n ApwWorkflowApplications,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { CHANGE_REQUEST_MODEL_ID } from \"~/storageOperations/models/changeRequest.model\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\nimport { REVIEWER_MODEL_ID } from \"~/storageOperations/models/reviewer.model\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\nexport const fetchModel = async (\n cms: HeadlessCms,\n id: string,\n settings?: { modelId?: string } | null\n): Promise<CmsModel> => {\n if (!settings) {\n throw new WebinyError(\"Missing settings.\", \"SETTINGS_ERROR\", {\n id\n });\n }\n const modelId = settings.modelId;\n if (!modelId) {\n throw new WebinyError(\"Missing modelId in settings.\", \"MODEL_ID_ERROR\", {\n id,\n settings\n });\n }\n const model = await cms.getModel(modelId);\n if (model) {\n return model;\n }\n throw new WebinyError(\"There is no requested model in the system.\", \"MODEL_NOT_EXISTS\", {\n id,\n settings\n });\n};\n\nexport const getEntryTitle = (model: CmsModel, entry: CmsEntry): string => {\n const titleFieldId = model.titleFieldId;\n if (!titleFieldId || !entry.values[titleFieldId]) {\n return entry.id;\n }\n return entry.values[titleFieldId];\n};\n\ninterface GetLatestEntryRevisionParams {\n cms: HeadlessCms;\n model: CmsModel;\n entryId: string;\n}\nexport const getLatestEntryRevision = async (\n params: GetLatestEntryRevisionParams\n): Promise<CmsEntry> => {\n const { cms, model, entryId } = params;\n const items = await cms.getLatestEntriesByIds(model, [entryId]);\n\n const item = items.shift();\n if (!item) {\n throw new WebinyError(\"There is no entry with given ID.\", \"ENTRY_NOT_FOUND\", {\n entryId\n });\n }\n return item;\n};\n\ninterface UpdateEntryMetaParams {\n meta: Record<string, any>;\n entryId: string;\n cms: HeadlessCms;\n model: CmsModel;\n}\nexport const updateEntryMeta = async (params: UpdateEntryMetaParams): Promise<void> => {\n const { entryId, cms, model, meta } = params;\n\n const entry = await getLatestEntryRevision({\n cms,\n model,\n entryId\n });\n\n await cms.updateEntry(model, entry.id, {}, meta);\n};\n\nconst isWorkflowApplicable = (entry: CmsEntry, workflow: ApwWorkflow): boolean => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.CMS) {\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 models = workflow.scope.data?.models;\n\n if (Array.isArray(models) && models.includes(entry.modelId)) {\n return true;\n }\n\n const entries = workflow.scope.data?.entries || [];\n if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {\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 AssignWorkflowToEntryParams {\n apw: AdvancedPublishingWorkflow;\n entry: CmsEntry;\n}\nexport const assignWorkflowToEntry = async (params: AssignWorkflowToEntryParams): Promise<void> => {\n const { apw, entry } = params;\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app cms\n */\n const [entries] = await apw.workflow.list({\n where: {\n app: ApwWorkflowApplications.CMS\n }\n });\n\n console.log(`Found ${entries.length} workflows.`);\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 /**\n * Assign the first applicable workflow to the page and exit.\n */\n for (const workflow of sortedWorkflows) {\n if (isWorkflowApplicable(entry, workflow) === false) {\n console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);\n continue;\n }\n entry.meta = {\n ...(entry.meta || {}),\n apw: {\n workflowId: workflow.id,\n contentReviewId: null\n }\n };\n return;\n }\n } catch (ex) {\n throw new WebinyError(\n `Failed to assign workflow to CMS entry \"${entry.id}\".`,\n ex.code,\n ex.data\n );\n }\n};\n\nexport const hasEntries = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.CMS &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.entries)\n );\n};\n\nexport const isAwpModel = (model: CmsModel): boolean => {\n return [\n CHANGE_REQUEST_MODEL_ID,\n COMMENT_MODEL_ID,\n CONTENT_REVIEW_MODEL_ID,\n REVIEWER_MODEL_ID,\n WORKFLOW_MODEL_ID\n ].includes(model.modelId);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,UAAU,GAAG,OACtBC,GADsB,EAEtBC,EAFsB,EAGtBC,QAHsB,KAIF;EACpB,IAAI,CAACA,QAAL,EAAe;IACX,MAAM,IAAI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FD,EAAE,CAACpB,IAHD,CAAN;EAKH;AACJ,CAnDM;;;;AAqDA,MAAMsB,UAAU,GAAIlC,QAAD,IAAoC;EAC1D,MAAM;IAAEE,GAAF;IAAOI;EAAP,IAAiBN,QAAvB;EACA,OACIE,GAAG,KAAKC,8BAAA,CAAwBC,GAAhC,IACAE,KAAK,CAACC,IAAN,KAAeC,yBAAA,CAAmBE,MADlC,IAEAJ,KAAK,CAACM,IAFN,IAGAC,KAAK,CAACC,OAAN,CAAcR,KAAK,CAACM,IAAN,CAAWI,OAAzB,CAJJ;AAMH,CARM;;;;AAUA,MAAMmB,UAAU,GAAIpD,KAAD,IAA8B;EACpD,OAAO,CACHqD,sCADG,EAEHC,yBAFG,EAGHC,sCAHG,EAIHC,2BAJG,EAKHC,2BALG,EAMLzB,QANK,CAMIhC,KAAK,CAACD,OANV,CAAP;AAOH,CARM"}
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_types","_utils","_changeRequest","_comment","_contentReview","_reviewer","_workflow","fetchModel","cms","id","settings","WebinyError","modelId","model","getModel","exports","getEntryTitle","entry","titleFieldId","values","getLatestEntryRevision","params","entryId","item","getLatestEntriesByIds","updateEntryMeta","meta","updateEntry","isWorkflowApplicable","workflow","application","app","ApwWorkflowApplications","CMS","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","models","data","Array","isArray","includes","entries","some","value","assignWorkflowToEntry","apw","list","where","console","log","length","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","workflowId","contentReviewId","ex","code","hasEntries","isApwDisabledOnModel","isPrivate","CHANGE_REQUEST_MODEL_ID","COMMENT_MODEL_ID","CONTENT_REVIEW_MODEL_ID","REVIEWER_MODEL_ID","WORKFLOW_MODEL_ID"],"sources":["utils.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport {\n AdvancedPublishingWorkflow,\n ApwWorkflow,\n ApwWorkflowApplications,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { CHANGE_REQUEST_MODEL_ID } from \"~/storageOperations/models/changeRequest.model\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\nimport { REVIEWER_MODEL_ID } from \"~/storageOperations/models/reviewer.model\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\nexport const fetchModel = async (\n cms: HeadlessCms,\n id: string,\n settings?: { modelId?: string } | null\n): Promise<CmsModel> => {\n if (!settings) {\n throw new WebinyError(\"Missing settings.\", \"SETTINGS_ERROR\", {\n id\n });\n }\n const modelId = settings.modelId;\n if (!modelId) {\n throw new WebinyError(\"Missing modelId in settings.\", \"MODEL_ID_ERROR\", {\n id,\n settings\n });\n }\n const model = await cms.getModel(modelId);\n if (model) {\n return model;\n }\n throw new WebinyError(\"There is no requested model in the system.\", \"MODEL_NOT_EXISTS\", {\n id,\n settings\n });\n};\n\nexport const getEntryTitle = (model: CmsModel, entry: CmsEntry): string => {\n const titleFieldId = model.titleFieldId;\n if (!titleFieldId || !entry.values[titleFieldId]) {\n return entry.id;\n }\n return entry.values[titleFieldId];\n};\n\ninterface GetLatestEntryRevisionParams {\n cms: HeadlessCms;\n model: CmsModel;\n entryId: string;\n}\nexport const getLatestEntryRevision = async (\n params: GetLatestEntryRevisionParams\n): Promise<CmsEntry> => {\n const { cms, model, entryId } = params;\n const [item] = await cms.getLatestEntriesByIds(model, [entryId]);\n\n if (!item) {\n throw new WebinyError(\"There is no entry with given ID.\", \"ENTRY_NOT_FOUND\", {\n entryId,\n model: model.modelId\n });\n }\n return item;\n};\n\ninterface UpdateEntryMetaParams {\n meta: Record<string, any>;\n entryId: string;\n cms: HeadlessCms;\n model: CmsModel;\n}\nexport const updateEntryMeta = async (params: UpdateEntryMetaParams): Promise<void> => {\n const { entryId, cms, model, meta } = params;\n\n const entry = await getLatestEntryRevision({\n cms,\n model,\n entryId\n });\n\n await cms.updateEntry(model, entry.id, {}, meta);\n};\n\nconst isWorkflowApplicable = (entry: CmsEntry, workflow: ApwWorkflow): boolean => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.CMS) {\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 models = workflow.scope.data?.models;\n\n if (Array.isArray(models) && models.includes(entry.modelId)) {\n return true;\n }\n\n const entries = workflow.scope.data?.entries || [];\n if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {\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 AssignWorkflowToEntryParams {\n apw: AdvancedPublishingWorkflow;\n entry: CmsEntry;\n model: CmsModel;\n}\nexport const assignWorkflowToEntry = async (params: AssignWorkflowToEntryParams): Promise<void> => {\n const { apw, entry, model } = params;\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app cms\n */\n const [entries] = await apw.workflow.list({\n where: {\n app: ApwWorkflowApplications.CMS\n }\n });\n\n console.log(`Found ${entries.length} workflow(s) for model ${model.modelId}.`);\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 /**\n * Assign the first applicable workflow to the page and exit.\n */\n for (const workflow of sortedWorkflows) {\n if (isWorkflowApplicable(entry, workflow) === false) {\n console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);\n continue;\n }\n entry.meta = {\n ...(entry.meta || {}),\n apw: {\n workflowId: workflow.id,\n contentReviewId: null\n }\n };\n return;\n }\n } catch (ex) {\n throw new WebinyError(\n `Failed to assign workflow to CMS entry \"${entry.id}\".`,\n ex.code,\n ex.data\n );\n }\n};\n\nexport const hasEntries = (workflow: ApwWorkflow): boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.CMS &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.entries)\n );\n};\n\nexport const isApwDisabledOnModel = (model: Pick<CmsModel, \"modelId\" | \"isPrivate\">): boolean => {\n /**\n * We should not run APW on private models as well.\n */\n if (model.isPrivate) {\n return true;\n }\n return [\n CHANGE_REQUEST_MODEL_ID,\n COMMENT_MODEL_ID,\n CONTENT_REVIEW_MODEL_ID,\n REVIEWER_MODEL_ID,\n WORKFLOW_MODEL_ID\n ].includes(model.modelId);\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAEO,MAAMQ,UAAU,GAAG,MAAAA,CACtBC,GAAgB,EAChBC,EAAU,EACVC,QAAsC,KAClB;EACpB,IAAI,CAACA,QAAQ,EAAE;IACX,MAAM,IAAIC,cAAW,CAAC,mBAAmB,EAAE,gBAAgB,EAAE;MACzDF;IACJ,CAAC,CAAC;EACN;EACA,MAAMG,OAAO,GAAGF,QAAQ,CAACE,OAAO;EAChC,IAAI,CAACA,OAAO,EAAE;IACV,MAAM,IAAID,cAAW,CAAC,8BAA8B,EAAE,gBAAgB,EAAE;MACpEF,EAAE;MACFC;IACJ,CA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,IAAc;EAC1D,MAAM;IAAEE,GAAG;IAAEI;EAAM,CAAC,GAAGN,QAAQ;EAC/B,OACIE,GAAG,KAAKC,8BAAuB,CAACC,GAAG,IACnCE,KAAK,CAACC,IAAI,KAAKC,yBAAkB,CAACE,MAAM,IACxCJ,KAAK,CAACM,IAAI,IACVC,KAAK,CAACC,OAAO,CAACR,KAAK,CAACM,IAAI,CAACI,OAAO,CAAC;AAEzC,CAAC;AAAC9B,OAAA,CAAAgD,UAAA,GAAAA,UAAA;AAEK,MAAMC,oBAAoB,GAAInD,KAA8C,IAAc;EAC7F;AACJ;AACA;EACI,IAAIA,KAAK,CAACoD,SAAS,EAAE;IACjB,OAAO,IAAI;EACf;EACA,OAAO,CACHC,sCAAuB,EACvBC,yBAAgB,EAChBC,sCAAuB,EACvBC,2BAAiB,EACjBC,2BAAiB,CACpB,CAAC1B,QAAQ,CAAC/B,KAAK,CAACD,OAAO,CAAC;AAC7B,CAAC;AAACG,OAAA,CAAAiD,oBAAA,GAAAA,oBAAA"}
|
package/plugins/context.d.ts
CHANGED
@@ -2,4 +2,3 @@ import { ContextPlugin } from "@webiny/api";
|
|
2
2
|
import { ApwContext } from "../types";
|
3
3
|
import { CreateApwContextParams } from "../scheduler/types";
|
4
4
|
export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
5
|
-
export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
package/plugins/context.js
CHANGED
@@ -1,36 +1,22 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
|
-
exports.createApwPageBuilderContext =
|
9
|
-
|
7
|
+
exports.createApwPageBuilderContext = void 0;
|
10
8
|
var _hooks = require("./hooks");
|
11
|
-
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
-
|
14
10
|
var _api = require("@webiny/api");
|
15
|
-
|
16
11
|
var _crud = require("../crud");
|
17
|
-
|
18
12
|
var _pageBuilder = require("./pageBuilder");
|
19
|
-
|
20
13
|
var _storageOperations = require("../storageOperations");
|
21
|
-
|
22
14
|
var _scheduler = require("../scheduler");
|
23
|
-
|
24
15
|
var _security = require("../scheduler/handlers/executeAction/security");
|
25
|
-
|
26
16
|
var _utils = require("./utils");
|
27
|
-
|
28
17
|
var _extendPbPageSettingsSchema = require("./pageBuilder/extendPbPageSettingsSchema");
|
29
|
-
|
30
18
|
var _apwContentPagePlugins = require("./pageBuilder/apwContentPagePlugins");
|
31
|
-
|
32
19
|
var _cms = require("./cms");
|
33
|
-
|
34
20
|
const setupApwContext = params => new _api.ContextPlugin(async context => {
|
35
21
|
const {
|
36
22
|
tenancy,
|
@@ -38,34 +24,26 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
38
24
|
i18n,
|
39
25
|
handlerClient
|
40
26
|
} = context;
|
41
|
-
|
42
27
|
if ((0, _utils.isInstallationPending)({
|
43
28
|
tenancy,
|
44
29
|
i18n
|
45
30
|
})) {
|
46
31
|
return;
|
47
32
|
}
|
48
|
-
|
49
33
|
const getLocale = () => {
|
50
34
|
const locale = i18n.getContentLocale();
|
51
|
-
|
52
35
|
if (!locale) {
|
53
36
|
throw new _error.default("Missing content locale in api-apw/plugins/context.ts", "LOCALE_ERROR");
|
54
37
|
}
|
55
|
-
|
56
38
|
return locale;
|
57
39
|
};
|
58
|
-
|
59
40
|
const getTenant = () => {
|
60
41
|
return tenancy.getCurrentTenant();
|
61
42
|
};
|
62
|
-
|
63
43
|
const getPermission = async name => {
|
64
44
|
return security.getPermission(name);
|
65
45
|
};
|
66
|
-
|
67
46
|
const getIdentity = () => security.getIdentity();
|
68
|
-
|
69
47
|
const scheduler = (0, _scheduler.createScheduler)({
|
70
48
|
getLocale,
|
71
49
|
getIdentity,
|
@@ -83,7 +61,6 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
83
61
|
* TODO: We need to figure out a way to pass "cms" from outside (e.g. apps/api/graphql)
|
84
62
|
*/
|
85
63
|
cms: context.cms,
|
86
|
-
|
87
64
|
/**
|
88
65
|
* TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
|
89
66
|
*/
|
@@ -95,19 +72,16 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
95
72
|
plugins: context.plugins
|
96
73
|
});
|
97
74
|
});
|
98
|
-
|
99
75
|
const setupApwPageBuilder = () => {
|
100
76
|
return new _api.ContextPlugin(async context => {
|
101
77
|
(0, _pageBuilder.apwPageBuilderHooks)(context);
|
102
78
|
});
|
103
79
|
};
|
104
|
-
|
105
80
|
const setupApwHeadlessCms = () => {
|
106
81
|
return new _api.ContextPlugin(async context => {
|
107
82
|
(0, _cms.apwCmsHooks)(context);
|
108
83
|
});
|
109
84
|
};
|
110
|
-
|
111
85
|
const createApwPageBuilderContext = params => {
|
112
86
|
return new _api.ContextPlugin(async context => {
|
113
87
|
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
@@ -115,7 +89,6 @@ const createApwPageBuilderContext = params => {
|
|
115
89
|
} else if ((0, _utils.isInstallationPending)(context)) {
|
116
90
|
return;
|
117
91
|
}
|
118
|
-
|
119
92
|
await setupApwContext(params).apply(context);
|
120
93
|
await setupApwPageBuilder().apply(context);
|
121
94
|
await setupApwHeadlessCms().apply(context);
|
@@ -125,22 +98,6 @@ const createApwPageBuilderContext = params => {
|
|
125
98
|
context.plugins.register((0, _extendPbPageSettingsSchema.extendPbPageSettingsSchema)());
|
126
99
|
});
|
127
100
|
};
|
128
|
-
|
129
101
|
exports.createApwPageBuilderContext = createApwPageBuilderContext;
|
130
102
|
|
131
|
-
|
132
|
-
return new _api.ContextPlugin(async context => {
|
133
|
-
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
134
|
-
return;
|
135
|
-
} else if ((0, _utils.isInstallationPending)(context)) {
|
136
|
-
return;
|
137
|
-
}
|
138
|
-
|
139
|
-
await setupApwContext(params).apply(context);
|
140
|
-
await setupApwHeadlessCms().apply(context);
|
141
|
-
await (0, _hooks.attachApwHooks)().apply(context);
|
142
|
-
await (0, _security.createCustomAuth)(params).apply(context);
|
143
|
-
});
|
144
|
-
};
|
145
|
-
|
146
|
-
exports.createApwHeadlessCmsContext = createApwHeadlessCmsContext;
|
103
|
+
//# sourceMappingURL=context.js.map
|
package/plugins/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema","
|
1
|
+
{"version":3,"names":["_hooks","require","_error","_interopRequireDefault","_api","_crud","_pageBuilder","_storageOperations","_scheduler","_security","_utils","_extendPbPageSettingsSchema","_apwContentPagePlugins","_cms","setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema","exports"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { apwPageBuilderHooks } from \"./pageBuilder\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { extendPbPageSettingsSchema } from \"~/plugins/pageBuilder/extendPbPageSettingsSchema\";\nimport { apwContentPagePlugins } from \"~/plugins/pageBuilder/apwContentPagePlugins\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst setupApwContext = (params: CreateApwContextParams) =>\n new ContextPlugin<ApwContext>(async context => {\n const { tenancy, security, i18n, handlerClient } = context;\n\n if (isInstallationPending({ tenancy, i18n })) {\n return;\n }\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getPermission = async (name: string): Promise<SecurityPermission | null> => {\n return security.getPermission(name);\n };\n const getIdentity = () => security.getIdentity();\n\n const scheduler = createScheduler({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: params.storageOperations\n });\n\n context.apw = createApw({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: createStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context,\n security\n }),\n scheduler,\n handlerClient,\n plugins: context.plugins\n });\n });\n\nconst setupApwPageBuilder = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwPageBuilderHooks(context);\n });\n};\n\nconst setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwPageBuilder().apply(context);\n await setupApwHeadlessCms().apply(context);\n await apwContentPagePlugins().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n\n context.plugins.register(extendPbPageSettingsSchema());\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,kBAAA,GAAAN,OAAA;AAIA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,2BAAA,GAAAV,OAAA;AACA,IAAAW,sBAAA,GAAAX,OAAA;AACA,IAAAY,IAAA,GAAAZ,OAAA;AAGA,MAAMa,eAAe,GAAIC,MAA8B,IACnD,IAAIC,kBAAa,CAAa,MAAMC,OAAO,IAAI;EAC3C,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC,IAAI;IAAEC;EAAc,CAAC,GAAGJ,OAAO;EAE1D,IAAI,IAAAK,4BAAqB,EAAC;IAAEJ,OAAO;IAAEE;EAAK,CAAC,CAAC,EAAE;IAC1C;EACJ;EAEA,MAAMG,SAAS,GAAGA,CAAA,KAAkB;IAChC,MAAMC,MAAM,GAAGJ,IAAI,CAACK,gBAAgB,CAAC,CAAC;IACtC,IAAI,CAACD,MAAM,EAAE;MACT,MAAM,IAA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