@webiny/api-apw 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d
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 +1 -1
- package/ApwChangeRequestNotification.js +3 -15
- package/ApwChangeRequestNotification.js.map +1 -1
- package/ApwCommentNotification.d.ts +1 -1
- package/ApwCommentNotification.js +3 -15
- package/ApwCommentNotification.js.map +1 -1
- package/ApwContentReviewNotification.d.ts +1 -1
- package/ApwContentReviewNotification.js +3 -15
- package/ApwContentReviewNotification.js.map +1 -1
- package/ApwContentUrlPlugin.d.ts +1 -1
- package/ApwContentUrlPlugin.js +3 -15
- package/ApwContentUrlPlugin.js.map +1 -1
- package/ContentApwSettingsPlugin.d.ts +1 -1
- package/ContentApwSettingsPlugin.js +5 -9
- package/ContentApwSettingsPlugin.js.map +1 -1
- package/README.md +3 -3
- package/crud/createChangeRequestMethods.d.ts +1 -1
- package/crud/createChangeRequestMethods.js +7 -12
- package/crud/createChangeRequestMethods.js.map +1 -1
- package/crud/createCommentMethods.d.ts +1 -1
- package/crud/createCommentMethods.js +7 -13
- package/crud/createCommentMethods.js.map +1 -1
- package/crud/createContentReviewMethods.d.ts +2 -2
- package/crud/createContentReviewMethods.js +76 -115
- package/crud/createContentReviewMethods.js.map +1 -1
- package/crud/createReviewerMethods.d.ts +1 -1
- package/crud/createReviewerMethods.js +7 -13
- package/crud/createReviewerMethods.js.map +1 -1
- package/crud/createWorkflowMethods.d.ts +1 -1
- package/crud/createWorkflowMethods.js +7 -18
- package/crud/createWorkflowMethods.js.map +1 -1
- package/crud/index.d.ts +1 -1
- package/crud/index.js +5 -29
- package/crud/index.js.map +1 -1
- package/crud/utils.d.ts +2 -2
- package/crud/utils.js +7 -35
- package/crud/utils.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +6 -19
- package/index.js.map +1 -1
- package/package.json +32 -50
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +1 -1
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +4 -19
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/cms/apwEntryPlugins.d.ts +2 -2
- package/plugins/cms/apwEntryPlugins.js +18 -14
- package/plugins/cms/apwEntryPlugins.js.map +1 -1
- package/plugins/cms/index.d.ts +4 -4
- package/plugins/cms/index.js +2 -13
- package/plugins/cms/index.js.map +1 -1
- package/plugins/cms/linkContentReviewToEntry.d.ts +2 -2
- package/plugins/cms/linkContentReviewToEntry.js +4 -20
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
- package/plugins/cms/linkWorkflowToEntry.d.ts +2 -2
- package/plugins/cms/linkWorkflowToEntry.js +18 -46
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
- package/plugins/cms/notifications/changeRequestNotification.js +2 -4
- package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/cms/notifications/commentNotification.js +2 -4
- package/plugins/cms/notifications/commentNotification.js.map +1 -1
- package/plugins/cms/notifications/contentReviewNotification.js +2 -4
- package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/cms/notifications/contentUrl.js +3 -8
- package/plugins/cms/notifications/contentUrl.js.map +1 -1
- package/plugins/cms/triggerContentReview.d.ts +2 -2
- package/plugins/cms/triggerContentReview.js +5 -18
- package/plugins/cms/triggerContentReview.js.map +1 -1
- package/plugins/cms/updateContentReviewStatus.d.ts +3 -3
- package/plugins/cms/updateContentReviewStatus.js +14 -30
- package/plugins/cms/updateContentReviewStatus.js.map +1 -1
- package/plugins/cms/utils.d.ts +5 -4
- package/plugins/cms/utils.js +20 -59
- package/plugins/cms/utils.js.map +1 -1
- package/plugins/context.d.ts +3 -4
- package/plugins/context.js +4 -58
- package/plugins/context.js.map +1 -1
- package/plugins/graphql/changeRequest.gql.d.ts +1 -1
- package/plugins/graphql/changeRequest.gql.js +16 -20
- package/plugins/graphql/changeRequest.gql.js.map +1 -1
- package/plugins/graphql/comment.gql.d.ts +1 -1
- package/plugins/graphql/comment.gql.js +41 -43
- package/plugins/graphql/comment.gql.js.map +1 -1
- package/plugins/graphql/contentReview.gql.d.ts +1 -1
- package/plugins/graphql/contentReview.gql.js +25 -35
- package/plugins/graphql/contentReview.gql.js.map +1 -1
- package/plugins/graphql/reviewer.gql.d.ts +1 -1
- package/plugins/graphql/reviewer.gql.js +15 -20
- package/plugins/graphql/reviewer.gql.js.map +1 -1
- package/plugins/graphql/utils.d.ts +2 -0
- package/plugins/graphql/utils.js +10 -0
- package/plugins/graphql/utils.js.map +1 -0
- package/plugins/graphql/workflow.gql.d.ts +1 -1
- package/plugins/graphql/workflow.gql.js +15 -20
- package/plugins/graphql/workflow.gql.js.map +1 -1
- package/plugins/graphql.d.ts +1 -1
- package/plugins/graphql.js +5 -18
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/createReviewerFromIdentity.d.ts +1 -1
- package/plugins/hooks/createReviewerFromIdentity.js +5 -12
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +3 -9
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +3 -8
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
- package/plugins/hooks/index.d.ts +1 -1
- package/plugins/hooks/index.js +2 -14
- package/plugins/hooks/index.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.d.ts +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +15 -20
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/plugins/hooks/initializeNotifications.d.ts +1 -1
- package/plugins/hooks/initializeNotifications.js +2 -5
- package/plugins/hooks/initializeNotifications.js.map +1 -1
- package/plugins/hooks/listContentReviews.d.ts +3 -3
- package/plugins/hooks/listContentReviews.js +3 -13
- package/plugins/hooks/listContentReviews.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +1 -1
- package/plugins/hooks/notifications/changeRequestAfterCreate.js +7 -38
- package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestUrl.js +2 -4
- package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
- package/plugins/hooks/notifications/commentAfterCreate.d.ts +1 -1
- package/plugins/hooks/notifications/commentAfterCreate.js +7 -40
- package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/commentUrl.js +2 -4
- package/plugins/hooks/notifications/commentUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +1 -1
- package/plugins/hooks/notifications/contentReviewAfterCreate.js +9 -35
- package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewUrl.js +2 -4
- package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentUrl.d.ts +2 -2
- package/plugins/hooks/notifications/contentUrl.js +2 -5
- package/plugins/hooks/notifications/contentUrl.js.map +1 -1
- package/plugins/hooks/notifications/getAppUrl.d.ts +2 -0
- package/plugins/hooks/notifications/getAppUrl.js +19 -0
- package/plugins/hooks/notifications/getAppUrl.js.map +1 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +1 -1
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +2 -4
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +1 -1
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +2 -4
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +1 -1
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +2 -4
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/reviewers.d.ts +1 -1
- package/plugins/hooks/notifications/reviewers.js +17 -21
- package/plugins/hooks/notifications/reviewers.js.map +1 -1
- package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +1 -1
- package/plugins/hooks/notifications/sendChangeRequestNotification.js +2 -11
- package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendCommentNotification.d.ts +1 -1
- package/plugins/hooks/notifications/sendCommentNotification.js +2 -11
- package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +1 -1
- package/plugins/hooks/notifications/sendContentReviewNotification.js +2 -11
- package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
- package/plugins/hooks/updatePendingChangeRequests.d.ts +1 -1
- package/plugins/hooks/updatePendingChangeRequests.js +7 -13
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
- package/plugins/hooks/updateTotalComments.d.ts +1 -1
- package/plugins/hooks/updateTotalComments.js +21 -23
- package/plugins/hooks/updateTotalComments.js.map +1 -1
- package/plugins/hooks/validateChangeRequest.d.ts +1 -1
- package/plugins/hooks/validateChangeRequest.js +2 -16
- package/plugins/hooks/validateChangeRequest.js.map +1 -1
- package/plugins/hooks/validateComment.d.ts +1 -1
- package/plugins/hooks/validateComment.js +3 -12
- package/plugins/hooks/validateComment.js.map +1 -1
- package/plugins/hooks/validateContentReview.d.ts +1 -1
- package/plugins/hooks/validateContentReview.js +2 -6
- package/plugins/hooks/validateContentReview.js.map +1 -1
- package/plugins/utils.d.ts +7 -6
- package/plugins/utils.js +11 -50
- package/plugins/utils.js.map +1 -1
- package/scheduler/createScheduleActionMethods.d.ts +1 -1
- package/scheduler/createScheduleActionMethods.js +105 -85
- package/scheduler/createScheduleActionMethods.js.map +1 -1
- package/scheduler/handlers/executeAction/index.d.ts +2 -2
- package/scheduler/handlers/executeAction/index.js +47 -41
- 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 +3 -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 +4 -3
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +10 -92
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/security.d.ts +2 -2
- package/scheduler/handlers/executeAction/security.js +2 -11
- package/scheduler/handlers/executeAction/security.js.map +1 -1
- package/scheduler/handlers/scheduleAction/index.d.ts +2 -2
- package/scheduler/handlers/scheduleAction/index.js +23 -38
- package/scheduler/handlers/scheduleAction/index.js.map +1 -1
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +3 -3
- 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 +22 -53
- package/scheduler/handlers/utils.js.map +1 -1
- package/scheduler/index.d.ts +1 -1
- package/scheduler/index.js +2 -3
- package/scheduler/index.js.map +1 -1
- package/scheduler/types.d.ts +20 -36
- package/scheduler/types.js +11 -23
- package/scheduler/types.js.map +1 -1
- package/storageOperations/changeRequestStorageOperations.d.ts +2 -2
- package/storageOperations/changeRequestStorageOperations.js +43 -41
- package/storageOperations/changeRequestStorageOperations.js.map +1 -1
- package/storageOperations/commentStorageOperations.d.ts +3 -3
- package/storageOperations/commentStorageOperations.js +16 -44
- package/storageOperations/commentStorageOperations.js.map +1 -1
- package/storageOperations/contentReviewStorageOperations.d.ts +3 -3
- package/storageOperations/contentReviewStorageOperations.js +19 -41
- package/storageOperations/contentReviewStorageOperations.js.map +1 -1
- package/storageOperations/index.d.ts +3 -9
- 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 +9 -19
- package/storageOperations/models/changeRequest.model.js.map +1 -1
- package/storageOperations/models/comment.model.d.ts +1 -2
- package/storageOperations/models/comment.model.js +9 -18
- package/storageOperations/models/comment.model.js.map +1 -1
- package/storageOperations/models/contentReview.model.d.ts +1 -2
- package/storageOperations/models/contentReview.model.js +16 -41
- package/storageOperations/models/contentReview.model.js.map +1 -1
- package/storageOperations/models/index.d.ts +1 -1
- package/storageOperations/models/index.js +11 -55
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/models/reviewer.model.d.ts +1 -2
- package/storageOperations/models/reviewer.model.js +10 -19
- package/storageOperations/models/reviewer.model.js.map +1 -1
- package/storageOperations/models/utils.d.ts +2 -2
- package/storageOperations/models/utils.js +2 -4
- package/storageOperations/models/utils.js.map +1 -1
- package/storageOperations/models/workflow.model.d.ts +2 -3
- package/storageOperations/models/workflow.model.js +22 -46
- package/storageOperations/models/workflow.model.js.map +1 -1
- package/storageOperations/reviewerStorageOperations.d.ts +3 -3
- package/storageOperations/reviewerStorageOperations.js +23 -50
- package/storageOperations/reviewerStorageOperations.js.map +1 -1
- package/storageOperations/types.d.ts +2 -2
- package/storageOperations/types.js +3 -1
- package/storageOperations/types.js.map +1 -1
- package/storageOperations/workflowStorageOperations.d.ts +2 -2
- package/storageOperations/workflowStorageOperations.js +24 -44
- package/storageOperations/workflowStorageOperations.js.map +1 -1
- package/types.d.ts +49 -64
- package/types.js +121 -43
- package/types.js.map +1 -1
- package/utils/contentApwSettingsPlugin.d.ts +2 -2
- 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.d.ts +2 -2
- package/utils/fieldResolver.js +8 -18
- package/utils/fieldResolver.js.map +1 -1
- package/utils/pickEntryFieldValues.d.ts +3 -0
- package/utils/pickEntryFieldValues.js +30 -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/plugins/hooks/notifications/appUrl.d.ts +0 -2
- package/plugins/hooks/notifications/appUrl.js +0 -22
- package/plugins/hooks/notifications/appUrl.js.map +0 -1
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +0 -9
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -51
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +0 -1
- package/plugins/pageBuilder/apwContentPagePlugins.d.ts +0 -3
- package/plugins/pageBuilder/apwContentPagePlugins.js +0 -30
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +0 -1
- package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +0 -3
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +0 -25
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +0 -1
- package/plugins/pageBuilder/index.d.ts +0 -11
- package/plugins/pageBuilder/index.js +0 -53
- package/plugins/pageBuilder/index.js.map +0 -1
- package/plugins/pageBuilder/linkContentReviewToPage.d.ts +0 -8
- package/plugins/pageBuilder/linkContentReviewToPage.js +0 -105
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +0 -1
- package/plugins/pageBuilder/linkWorkflowToPage.d.ts +0 -8
- package/plugins/pageBuilder/linkWorkflowToPage.js +0 -194
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +0 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +0 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -35
- package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +0 -1
- package/plugins/pageBuilder/notifications/commentNotification.d.ts +0 -1
- package/plugins/pageBuilder/notifications/commentNotification.js +0 -35
- package/plugins/pageBuilder/notifications/commentNotification.js.map +0 -1
- package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +0 -1
- package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -35
- package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +0 -1
- package/plugins/pageBuilder/notifications/contentUrl.d.ts +0 -1
- package/plugins/pageBuilder/notifications/contentUrl.js +0 -53
- package/plugins/pageBuilder/notifications/contentUrl.js.map +0 -1
- package/plugins/pageBuilder/triggerContentReview.d.ts +0 -8
- package/plugins/pageBuilder/triggerContentReview.js +0 -50
- package/plugins/pageBuilder/triggerContentReview.js.map +0 -1
- package/plugins/pageBuilder/updateContentReviewStatus.d.ts +0 -10
- package/plugins/pageBuilder/updateContentReviewStatus.js +0 -79
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +0 -1
- package/plugins/pageBuilder/utils.d.ts +0 -22
- package/plugins/pageBuilder/utils.js +0 -184
- package/plugins/pageBuilder/utils.js.map +0 -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 type {\n AdvancedPublishingWorkflow,\n OnCmsEntryAfterPublishTopicParams,\n OnCmsEntryAfterUnpublishTopicParams\n} from \"~/types\";\nimport { ApwContentReviewStatus } from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport type { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport type { 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 }\n );\n};\n"],"mappings":";;;;;;AAKA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,OAAA,GAAAF,OAAA;AAQO,MAAMG,yBAAyB,GAAIC,MAAuC,IAAK;EAClF,MAAM;IAAEC,GAAG;IAAEC,GAAG;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAErCE,GAAG,CAACE,mBAAmB,CAACC,SAAS,CAC7B,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IACxB,IAAI,IAAAC,4BAAoB,EAACD,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAME,eAAe,GAAGH,KAAK,CAACI,IAAI,EAAET,GAAG,EAAEQ,eAAe;IACxD;AACZ;AACA;IACY,IAAI,CAACA,eAAe,EAAE;MAClB;IACJ;IAEA,MAAME,aAAa,GAAG,MAAMV,GAAG,CAACU,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;IAClE,MAAMI,QAAQ,GAAGV,QAAQ,CAACW,WAAW,CAAC,CAAC;IACvC;AACZ;AACA;IACY,IAAIH,aAAa,CAACI,YAAY,KAAKC,6BAAsB,CAACC,qBAAqB,EAAE;MAC7E;IACJ;IACA,MAAMhB,GAAG,CAACU,aAAa,CAACO,MAAM,CAACT,eAAe,EAAE;MAC5CM,YAAY,EAAEC,6BAAsB,CAACG,SAAS;MAC9CC,OAAO,EAAE;QACL,GAAGT,aAAa,CAACS,OAAO;QACxB,GAAGC,mDAA4C;QAC/CC,WAAW,EAAET,QAAQ,CAACU;MAC1B;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;EACDrB,GAAG,CAACsB,qBAAqB,CAACnB,SAAS,CAC/B,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IACxB,IAAI,IAAAC,4BAAoB,EAACD,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAME,eAAe,GAAGH,KAAK,CAACI,IAAI,EAAET,GAAG,EAAEQ,eAAe;IACxD;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","ignoreList":[]}
|
package/plugins/cms/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { CmsEntry, CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
|
2
|
-
import { AdvancedPublishingWorkflow, ApwWorkflow } from "../../types";
|
1
|
+
import type { CmsEntry, CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
|
2
|
+
import type { AdvancedPublishingWorkflow, ApwWorkflow } from "../../types";
|
3
3
|
export declare const fetchModel: (cms: HeadlessCms, id: string, settings?: {
|
4
4
|
modelId?: string;
|
5
5
|
} | null) => Promise<CmsModel>;
|
@@ -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,43 +74,30 @@ 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,
|
@@ -146,7 +106,6 @@ const assignWorkflowToEntry = async params => {
|
|
146
106
|
/**
|
147
107
|
* Lookup and assign "workflowId".
|
148
108
|
*/
|
149
|
-
|
150
109
|
try {
|
151
110
|
/*
|
152
111
|
* List all workflows for app cms
|
@@ -156,40 +115,37 @@ const assignWorkflowToEntry = async params => {
|
|
156
115
|
app: _types.ApwWorkflowApplications.CMS
|
157
116
|
}
|
158
117
|
});
|
159
|
-
|
118
|
+
|
160
119
|
/*
|
161
120
|
* Re-order them based on workflow scope and pre-defined rule i.e.
|
162
121
|
* "specific" entry -> entry for a "category" -> "default".
|
163
122
|
* There can be more than one workflow with same "scope" and "app".
|
164
123
|
* Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
|
165
124
|
*/
|
166
|
-
|
167
125
|
const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
|
126
|
+
|
168
127
|
/**
|
169
128
|
* Assign the first applicable workflow to the page and exit.
|
170
129
|
*/
|
171
|
-
|
172
130
|
for (const workflow of sortedWorkflows) {
|
173
131
|
if (isWorkflowApplicable(entry, workflow) === false) {
|
174
132
|
console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);
|
175
133
|
continue;
|
176
134
|
}
|
177
|
-
|
178
|
-
|
135
|
+
entry.meta = {
|
136
|
+
...(entry.meta || {}),
|
179
137
|
apw: {
|
180
138
|
workflowId: workflow.id,
|
181
139
|
contentReviewId: null
|
182
140
|
}
|
183
|
-
}
|
141
|
+
};
|
184
142
|
return;
|
185
143
|
}
|
186
144
|
} catch (ex) {
|
187
145
|
throw new _error.default(`Failed to assign workflow to CMS entry "${entry.id}".`, ex.code, ex.data);
|
188
146
|
}
|
189
147
|
};
|
190
|
-
|
191
148
|
exports.assignWorkflowToEntry = assignWorkflowToEntry;
|
192
|
-
|
193
149
|
const hasEntries = workflow => {
|
194
150
|
const {
|
195
151
|
app,
|
@@ -197,11 +153,16 @@ const hasEntries = workflow => {
|
|
197
153
|
} = workflow;
|
198
154
|
return app === _types.ApwWorkflowApplications.CMS && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.entries);
|
199
155
|
};
|
200
|
-
|
201
156
|
exports.hasEntries = hasEntries;
|
202
|
-
|
203
|
-
|
157
|
+
const isApwDisabledOnModel = model => {
|
158
|
+
/**
|
159
|
+
* We should not run APW on private models as well.
|
160
|
+
*/
|
161
|
+
if (model.isPrivate) {
|
162
|
+
return true;
|
163
|
+
}
|
204
164
|
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
165
|
};
|
166
|
+
exports.isApwDisabledOnModel = isApwDisabledOnModel;
|
206
167
|
|
207
|
-
|
168
|
+
//# 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,IAAIC,cAAJ,CAAgB,mBAAhB,EAAqC,gBAArC,EAAuD;MACzDF;IADyD,CAAvD,CAAN;EAGH;;EACD,MAAMG,OAAO,GAAGF,QAAQ,CAACE,OAAzB;;EACA,IAAI,CAACA,OAAL,EAAc;IACV,MAAM,IAAID,cAAJ,CAAgB,8BAAhB,EAAgD,gBAAhD,EAAkE;MACpEF,EADoE;MAEpEC;IAFoE,CAAlE,CAAN;EAIH;;EACD,MAAMG,KAAK,GAAG,MAAML,GAAG,CAACM,QAAJ,CAAaF,OAAb,CAApB;;EACA,IAAIC,KAAJ,EAAW;IACP,OAAOA,KAAP;EACH;;EACD,MAAM,IAAIF,cAAJ,CAAgB,4CAAhB,EAA8D,kBAA9D,EAAkF;IACpFF,EADoF;IAEpFC;EAFoF,CAAlF,CAAN;AAIH,CAzBM;;;;AA2BA,MAAMK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V,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","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","console","log","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 type { CmsEntry, CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport type { AdvancedPublishingWorkflow, ApwWorkflow } from \"~/types\";\nimport { ApwWorkflowApplications, WorkflowScopeTypes } 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}\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}\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}\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 /*\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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,5 +1,4 @@
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
2
|
-
import { ApwContext } from "../types";
|
3
|
-
import { CreateApwContextParams } from "../scheduler/types";
|
4
|
-
export declare const
|
5
|
-
export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
2
|
+
import type { ApwContext } from "../types";
|
3
|
+
import type { CreateApwContextParams } from "../scheduler/types";
|
4
|
+
export declare const createApwContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
package/plugins/context.js
CHANGED
@@ -1,36 +1,19 @@
|
|
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.
|
9
|
-
|
7
|
+
exports.createApwContext = 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
|
-
var _pageBuilder = require("./pageBuilder");
|
19
|
-
|
20
12
|
var _storageOperations = require("../storageOperations");
|
21
|
-
|
22
13
|
var _scheduler = require("../scheduler");
|
23
|
-
|
24
14
|
var _security = require("../scheduler/handlers/executeAction/security");
|
25
|
-
|
26
15
|
var _utils = require("./utils");
|
27
|
-
|
28
|
-
var _extendPbPageSettingsSchema = require("./pageBuilder/extendPbPageSettingsSchema");
|
29
|
-
|
30
|
-
var _apwContentPagePlugins = require("./pageBuilder/apwContentPagePlugins");
|
31
|
-
|
32
16
|
var _cms = require("./cms");
|
33
|
-
|
34
17
|
const setupApwContext = params => new _api.ContextPlugin(async context => {
|
35
18
|
const {
|
36
19
|
tenancy,
|
@@ -38,34 +21,26 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
38
21
|
i18n,
|
39
22
|
handlerClient
|
40
23
|
} = context;
|
41
|
-
|
42
24
|
if ((0, _utils.isInstallationPending)({
|
43
25
|
tenancy,
|
44
26
|
i18n
|
45
27
|
})) {
|
46
28
|
return;
|
47
29
|
}
|
48
|
-
|
49
30
|
const getLocale = () => {
|
50
31
|
const locale = i18n.getContentLocale();
|
51
|
-
|
52
32
|
if (!locale) {
|
53
33
|
throw new _error.default("Missing content locale in api-apw/plugins/context.ts", "LOCALE_ERROR");
|
54
34
|
}
|
55
|
-
|
56
35
|
return locale;
|
57
36
|
};
|
58
|
-
|
59
37
|
const getTenant = () => {
|
60
38
|
return tenancy.getCurrentTenant();
|
61
39
|
};
|
62
|
-
|
63
40
|
const getPermission = async name => {
|
64
41
|
return security.getPermission(name);
|
65
42
|
};
|
66
|
-
|
67
43
|
const getIdentity = () => security.getIdentity();
|
68
|
-
|
69
44
|
const scheduler = (0, _scheduler.createScheduler)({
|
70
45
|
getLocale,
|
71
46
|
getIdentity,
|
@@ -83,7 +58,6 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
83
58
|
* TODO: We need to figure out a way to pass "cms" from outside (e.g. apps/api/graphql)
|
84
59
|
*/
|
85
60
|
cms: context.cms,
|
86
|
-
|
87
61
|
/**
|
88
62
|
* TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
|
89
63
|
*/
|
@@ -95,52 +69,24 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
95
69
|
plugins: context.plugins
|
96
70
|
});
|
97
71
|
});
|
98
|
-
|
99
|
-
const setupApwPageBuilder = () => {
|
100
|
-
return new _api.ContextPlugin(async context => {
|
101
|
-
(0, _pageBuilder.apwPageBuilderHooks)(context);
|
102
|
-
});
|
103
|
-
};
|
104
|
-
|
105
72
|
const setupApwHeadlessCms = () => {
|
106
73
|
return new _api.ContextPlugin(async context => {
|
107
74
|
(0, _cms.apwCmsHooks)(context);
|
108
75
|
});
|
109
76
|
};
|
110
|
-
|
111
|
-
const createApwPageBuilderContext = params => {
|
112
|
-
return new _api.ContextPlugin(async context => {
|
113
|
-
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
114
|
-
return;
|
115
|
-
} else if ((0, _utils.isInstallationPending)(context)) {
|
116
|
-
return;
|
117
|
-
}
|
118
|
-
|
119
|
-
await setupApwContext(params).apply(context);
|
120
|
-
await setupApwPageBuilder().apply(context);
|
121
|
-
await setupApwHeadlessCms().apply(context);
|
122
|
-
await (0, _apwContentPagePlugins.apwContentPagePlugins)().apply(context);
|
123
|
-
await (0, _hooks.attachApwHooks)().apply(context);
|
124
|
-
await (0, _security.createCustomAuth)(params).apply(context);
|
125
|
-
context.plugins.register((0, _extendPbPageSettingsSchema.extendPbPageSettingsSchema)());
|
126
|
-
});
|
127
|
-
};
|
128
|
-
|
129
|
-
exports.createApwPageBuilderContext = createApwPageBuilderContext;
|
130
|
-
|
131
|
-
const createApwHeadlessCmsContext = params => {
|
77
|
+
const createApwContext = params => {
|
132
78
|
return new _api.ContextPlugin(async context => {
|
133
79
|
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
134
80
|
return;
|
135
81
|
} else if ((0, _utils.isInstallationPending)(context)) {
|
136
82
|
return;
|
137
83
|
}
|
138
|
-
|
139
84
|
await setupApwContext(params).apply(context);
|
140
85
|
await setupApwHeadlessCms().apply(context);
|
141
86
|
await (0, _hooks.attachApwHooks)().apply(context);
|
142
87
|
await (0, _security.createCustomAuth)(params).apply(context);
|
143
88
|
});
|
144
89
|
};
|
90
|
+
exports.createApwContext = createApwContext;
|
145
91
|
|
146
|
-
|
92
|
+
//# 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","
|
1
|
+
{"version":3,"names":["_hooks","require","_error","_interopRequireDefault","_api","_crud","_storageOperations","_scheduler","_security","_utils","_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","setupApwHeadlessCms","apwCmsHooks","createApwContext","wcp","canUseFeature","apply","attachApwHooks","createCustomAuth","exports"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport type { SecurityPermission } from \"@webiny/api-security/types\";\nimport type { Tenant } from \"@webiny/api-tenancy/types\";\nimport type { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport type { 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 setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwContext = (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 setupApwHeadlessCms().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\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,kBAAA,GAAAL,OAAA;AAIA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,IAAA,GAAAT,OAAA;AAGA,MAAMU,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,CA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