@webiny/api-apw 0.0.0-unstable.1e66d121db
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ContentApwSettingsPlugin.d.ts +10 -0
- package/ContentApwSettingsPlugin.js +17 -0
- package/ContentApwSettingsPlugin.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/crud/createChangeRequestMethods.d.ts +2 -0
- package/crud/createChangeRequestMethods.js +98 -0
- package/crud/createChangeRequestMethods.js.map +1 -0
- package/crud/createCommentMethods.d.ts +2 -0
- package/crud/createCommentMethods.js +99 -0
- package/crud/createCommentMethods.js.map +1 -0
- package/crud/createContentReviewMethods.d.ts +10 -0
- package/crud/createContentReviewMethods.js +552 -0
- package/crud/createContentReviewMethods.js.map +1 -0
- package/crud/createReviewerMethods.d.ts +2 -0
- package/crud/createReviewerMethods.js +99 -0
- package/crud/createReviewerMethods.js.map +1 -0
- package/crud/createWorkflowMethods.d.ts +2 -0
- package/crud/createWorkflowMethods.js +118 -0
- package/crud/createWorkflowMethods.js.map +1 -0
- package/crud/index.d.ts +2 -0
- package/crud/index.js +96 -0
- package/crud/index.js.map +1 -0
- package/crud/utils.d.ts +21 -0
- package/crud/utils.js +138 -0
- package/crud/utils.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +36 -0
- package/index.js.map +1 -0
- package/package.json +76 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +10 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +51 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -0
- package/plugins/cms/README.md +49 -0
- package/plugins/cms/apwEntryPlugins.d.ts +8 -0
- package/plugins/cms/apwEntryPlugins.js +46 -0
- package/plugins/cms/apwEntryPlugins.js.map +1 -0
- package/plugins/cms/index.d.ts +12 -0
- package/plugins/cms/index.js +37 -0
- package/plugins/cms/index.js.map +1 -0
- package/plugins/cms/linkContentReviewToEntry.d.ts +8 -0
- package/plugins/cms/linkContentReviewToEntry.js +108 -0
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -0
- package/plugins/cms/linkWorkflowToEntry.d.ts +8 -0
- package/plugins/cms/linkWorkflowToEntry.js +166 -0
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -0
- package/plugins/cms/triggerContentReview.d.ts +8 -0
- package/plugins/cms/triggerContentReview.js +59 -0
- package/plugins/cms/triggerContentReview.js.map +1 -0
- package/plugins/cms/updateContentReviewStatus.d.ts +10 -0
- package/plugins/cms/updateContentReviewStatus.js +97 -0
- package/plugins/cms/updateContentReviewStatus.js.map +1 -0
- package/plugins/cms/utils.d.ts +27 -0
- package/plugins/cms/utils.js +207 -0
- package/plugins/cms/utils.js.map +1 -0
- package/plugins/context.d.ts +5 -0
- package/plugins/context.js +146 -0
- package/plugins/context.js.map +1 -0
- package/plugins/graphql/changeRequest.gql.d.ts +4 -0
- package/plugins/graphql/changeRequest.gql.js +155 -0
- package/plugins/graphql/changeRequest.gql.js.map +1 -0
- package/plugins/graphql/comment.gql.d.ts +4 -0
- package/plugins/graphql/comment.gql.js +160 -0
- package/plugins/graphql/comment.gql.js.map +1 -0
- package/plugins/graphql/contentReview.gql.d.ts +4 -0
- package/plugins/graphql/contentReview.gql.js +382 -0
- package/plugins/graphql/contentReview.gql.js.map +1 -0
- package/plugins/graphql/reviewer.gql.d.ts +4 -0
- package/plugins/graphql/reviewer.gql.js +114 -0
- package/plugins/graphql/reviewer.gql.js.map +1 -0
- package/plugins/graphql/workflow.gql.d.ts +4 -0
- package/plugins/graphql/workflow.gql.js +205 -0
- package/plugins/graphql/workflow.gql.js.map +1 -0
- package/plugins/graphql.d.ts +4 -0
- package/plugins/graphql.js +95 -0
- package/plugins/graphql.js.map +1 -0
- package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
- package/plugins/hooks/createReviewerFromIdentity.js +62 -0
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +67 -0
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +59 -0
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -0
- package/plugins/hooks/index.d.ts +3 -0
- package/plugins/hooks/index.js +71 -0
- package/plugins/hooks/index.js.map +1 -0
- package/plugins/hooks/initializeContentReviewSteps.d.ts +2 -0
- package/plugins/hooks/initializeContentReviewSteps.js +86 -0
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -0
- package/plugins/hooks/listContentReviews.d.ts +10 -0
- package/plugins/hooks/listContentReviews.js +80 -0
- package/plugins/hooks/listContentReviews.js.map +1 -0
- package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
- package/plugins/hooks/updatePendingChangeRequests.js +94 -0
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -0
- package/plugins/hooks/updateTotalComments.d.ts +3 -0
- package/plugins/hooks/updateTotalComments.js +153 -0
- package/plugins/hooks/updateTotalComments.js.map +1 -0
- package/plugins/hooks/validateChangeRequest.d.ts +2 -0
- package/plugins/hooks/validateChangeRequest.js +64 -0
- package/plugins/hooks/validateChangeRequest.js.map +1 -0
- package/plugins/hooks/validateComment.d.ts +2 -0
- package/plugins/hooks/validateComment.js +47 -0
- package/plugins/hooks/validateComment.js.map +1 -0
- package/plugins/hooks/validateContentReview.d.ts +2 -0
- package/plugins/hooks/validateContentReview.js +38 -0
- package/plugins/hooks/validateContentReview.js.map +1 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +9 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +51 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -0
- package/plugins/pageBuilder/apwContentPagePlugins.d.ts +3 -0
- package/plugins/pageBuilder/apwContentPagePlugins.js +30 -0
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -0
- package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +3 -0
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +25 -0
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -0
- package/plugins/pageBuilder/index.d.ts +11 -0
- package/plugins/pageBuilder/index.js +45 -0
- package/plugins/pageBuilder/index.js.map +1 -0
- package/plugins/pageBuilder/linkContentReviewToPage.d.ts +8 -0
- package/plugins/pageBuilder/linkContentReviewToPage.js +105 -0
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -0
- package/plugins/pageBuilder/linkWorkflowToPage.d.ts +8 -0
- package/plugins/pageBuilder/linkWorkflowToPage.js +194 -0
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -0
- package/plugins/pageBuilder/triggerContentReview.d.ts +8 -0
- package/plugins/pageBuilder/triggerContentReview.js +50 -0
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -0
- package/plugins/pageBuilder/updateContentReviewStatus.d.ts +10 -0
- package/plugins/pageBuilder/updateContentReviewStatus.js +79 -0
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -0
- package/plugins/pageBuilder/utils.d.ts +22 -0
- package/plugins/pageBuilder/utils.js +184 -0
- package/plugins/pageBuilder/utils.js.map +1 -0
- package/plugins/utils.d.ts +36 -0
- package/plugins/utils.js +193 -0
- package/plugins/utils.js.map +1 -0
- package/scheduler/createScheduleActionMethods.d.ts +2 -0
- package/scheduler/createScheduleActionMethods.js +149 -0
- package/scheduler/createScheduleActionMethods.js.map +1 -0
- package/scheduler/handlers/executeAction/index.d.ts +13 -0
- package/scheduler/handlers/executeAction/index.js +172 -0
- package/scheduler/handlers/executeAction/index.js.map +1 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +13 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +17 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +11 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +126 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -0
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +11 -0
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +163 -0
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -0
- package/scheduler/handlers/executeAction/security.d.ts +4 -0
- package/scheduler/handlers/executeAction/security.js +68 -0
- package/scheduler/handlers/executeAction/security.js.map +1 -0
- package/scheduler/handlers/scheduleAction/index.d.ts +22 -0
- package/scheduler/handlers/scheduleAction/index.js +164 -0
- package/scheduler/handlers/scheduleAction/index.js.map +1 -0
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +24 -0
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +172 -0
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -0
- package/scheduler/handlers/utils.d.ts +33 -0
- package/scheduler/handlers/utils.js +168 -0
- package/scheduler/handlers/utils.js.map +1 -0
- package/scheduler/index.d.ts +2 -0
- package/scheduler/index.js +27 -0
- package/scheduler/index.js.map +1 -0
- package/scheduler/types.d.ts +171 -0
- package/scheduler/types.js +34 -0
- package/scheduler/types.js.map +1 -0
- package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
- package/storageOperations/changeRequestStorageOperations.js +122 -0
- package/storageOperations/changeRequestStorageOperations.js.map +1 -0
- package/storageOperations/commentStorageOperations.d.ts +3 -0
- package/storageOperations/commentStorageOperations.js +138 -0
- package/storageOperations/commentStorageOperations.js.map +1 -0
- package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
- package/storageOperations/contentReviewStorageOperations.js +93 -0
- package/storageOperations/contentReviewStorageOperations.js.map +1 -0
- package/storageOperations/index.d.ts +15 -0
- package/storageOperations/index.js +48 -0
- package/storageOperations/index.js.map +1 -0
- package/storageOperations/models/changeRequest.model.d.ts +3 -0
- package/storageOperations/models/changeRequest.model.js +59 -0
- package/storageOperations/models/changeRequest.model.js.map +1 -0
- package/storageOperations/models/comment.model.d.ts +7 -0
- package/storageOperations/models/comment.model.js +60 -0
- package/storageOperations/models/comment.model.js.map +1 -0
- package/storageOperations/models/contentModelPluginFactory.d.ts +15 -0
- package/storageOperations/models/contentModelPluginFactory.js +28 -0
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -0
- package/storageOperations/models/contentReview.model.d.ts +7 -0
- package/storageOperations/models/contentReview.model.js +258 -0
- package/storageOperations/models/contentReview.model.js.map +1 -0
- package/storageOperations/models/index.d.ts +2 -0
- package/storageOperations/models/index.js +115 -0
- package/storageOperations/models/index.js.map +1 -0
- package/storageOperations/models/reviewer.model.d.ts +3 -0
- package/storageOperations/models/reviewer.model.js +55 -0
- package/storageOperations/models/reviewer.model.js.map +1 -0
- package/storageOperations/models/utils.d.ts +3 -0
- package/storageOperations/models/utils.js +37 -0
- package/storageOperations/models/utils.js.map +1 -0
- package/storageOperations/models/workflow.model.d.ts +12 -0
- package/storageOperations/models/workflow.model.js +208 -0
- package/storageOperations/models/workflow.model.js.map +1 -0
- package/storageOperations/reviewerStorageOperations.d.ts +3 -0
- package/storageOperations/reviewerStorageOperations.js +89 -0
- package/storageOperations/reviewerStorageOperations.js.map +1 -0
- package/storageOperations/types.d.ts +34 -0
- package/storageOperations/types.js +5 -0
- package/storageOperations/types.js.map +1 -0
- package/storageOperations/workflowStorageOperations.d.ts +3 -0
- package/storageOperations/workflowStorageOperations.js +109 -0
- package/storageOperations/workflowStorageOperations.js.map +1 -0
- package/types.d.ts +740 -0
- package/types.js +69 -0
- package/types.js.map +1 -0
- package/utils/contentApwSettingsPlugin.d.ts +9 -0
- package/utils/contentApwSettingsPlugin.js +26 -0
- package/utils/contentApwSettingsPlugin.js.map +1 -0
- package/utils/errors.d.ts +16 -0
- package/utils/errors.js +75 -0
- package/utils/errors.js.map +1 -0
- package/utils/fieldResolver.d.ts +16 -0
- package/utils/fieldResolver.js +54 -0
- package/utils/fieldResolver.js.map +1 -0
- package/utils/resolve.d.ts +3 -0
- package/utils/resolve.js +18 -0
- package/utils/resolve.js.map +1 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.triggerContentReview = void 0;
|
9
|
+
|
10
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
11
|
+
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
+
|
14
|
+
var _types = require("../../types");
|
15
|
+
|
16
|
+
const triggerContentReview = params => {
|
17
|
+
const {
|
18
|
+
pageBuilder,
|
19
|
+
apw
|
20
|
+
} = params;
|
21
|
+
pageBuilder.onPageBeforePublish.subscribe(async ({
|
22
|
+
page
|
23
|
+
}) => {
|
24
|
+
const contentReviewId = (0, _get.default)(page, "settings.apw.contentReviewId");
|
25
|
+
|
26
|
+
if (contentReviewId) {
|
27
|
+
const contentReview = await apw.contentReview.get(contentReviewId);
|
28
|
+
|
29
|
+
if (contentReview.reviewStatus === _types.ApwContentReviewStatus.UNDER_REVIEW) {
|
30
|
+
throw new _error.default(`A peer review for this content has been already requested.`, "REVIEW_ALREADY_EXIST", {
|
31
|
+
contentReviewId,
|
32
|
+
page
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
const workflowId = (0, _get.default)(page, "settings.apw.workflowId");
|
40
|
+
|
41
|
+
if (workflowId) {
|
42
|
+
throw new _error.default("This content requires peer review approval before it can be published.", "REVIEW_REQUIRED", {
|
43
|
+
workflowId,
|
44
|
+
page
|
45
|
+
});
|
46
|
+
}
|
47
|
+
});
|
48
|
+
};
|
49
|
+
|
50
|
+
exports.triggerContentReview = triggerContentReview;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["triggerContentReview","params","pageBuilder","apw","onPageBeforePublish","subscribe","page","contentReviewId","get","contentReview","reviewStatus","ApwContentReviewStatus","UNDER_REVIEW","Error","workflowId"],"sources":["triggerContentReview.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport Error from \"@webiny/error\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n ApwOnPageBeforePublishTopicParams\n} from \"~/types\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface TriggerContentReviewParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const triggerContentReview = (params: TriggerContentReviewParams) => {\n const { pageBuilder, apw } = params;\n\n pageBuilder.onPageBeforePublish.subscribe<ApwOnPageBeforePublishTopicParams>(\n async ({ page }) => {\n const contentReviewId = get(page, \"settings.apw.contentReviewId\");\n if (contentReviewId) {\n const contentReview = await apw.contentReview.get(contentReviewId);\n\n if (contentReview.reviewStatus === ApwContentReviewStatus.UNDER_REVIEW) {\n throw new Error(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n page\n }\n );\n }\n return;\n }\n\n const workflowId = get(page, \"settings.apw.workflowId\");\n\n if (workflowId) {\n throw new Error(\n \"This content requires peer review approval before it can be published.\",\n \"REVIEW_REQUIRED\",\n {\n workflowId,\n page\n }\n );\n }\n }\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAYO,MAAMA,oBAAoB,GAAIC,MAAD,IAAwC;EACxE,MAAM;IAAEC,WAAF;IAAeC;EAAf,IAAuBF,MAA7B;EAEAC,WAAW,CAACE,mBAAZ,CAAgCC,SAAhC,CACI,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAChB,MAAMC,eAAe,GAAG,IAAAC,YAAA,EAAIF,IAAJ,EAAU,8BAAV,CAAxB;;IACA,IAAIC,eAAJ,EAAqB;MACjB,MAAME,aAAa,GAAG,MAAMN,GAAG,CAACM,aAAJ,CAAkBD,GAAlB,CAAsBD,eAAtB,CAA5B;;MAEA,IAAIE,aAAa,CAACC,YAAd,KAA+BC,6BAAA,CAAuBC,YAA1D,EAAwE;QACpE,MAAM,IAAIC,cAAJ,CACD,4DADC,EAEF,sBAFE,EAGF;UACIN,eADJ;UAEID;QAFJ,CAHE,CAAN;MAQH;;MACD;IACH;;IAED,MAAMQ,UAAU,GAAG,IAAAN,YAAA,EAAIF,IAAJ,EAAU,yBAAV,CAAnB;;IAEA,IAAIQ,UAAJ,EAAgB;MACZ,MAAM,IAAID,cAAJ,CACF,wEADE,EAEF,iBAFE,EAGF;QACIC,UADJ;QAEIR;MAFJ,CAHE,CAAN;IAQH;EACJ,CA/BL;AAiCH,CApCM"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { AdvancedPublishingWorkflow } from "../../types";
|
2
|
+
import { PageBuilderContextObject } from "@webiny/api-page-builder/graphql/types";
|
3
|
+
import { Security } from "@webiny/api-security/types";
|
4
|
+
interface UpdateContentReviewStatusParams {
|
5
|
+
apw: AdvancedPublishingWorkflow;
|
6
|
+
pageBuilder: PageBuilderContextObject;
|
7
|
+
security: Security;
|
8
|
+
}
|
9
|
+
export declare const updateContentReviewStatus: (params: UpdateContentReviewStatusParams) => void;
|
10
|
+
export {};
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.updateContentReviewStatus = void 0;
|
9
|
+
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
+
|
12
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
13
|
+
|
14
|
+
var _types = require("../../types");
|
15
|
+
|
16
|
+
var _utils = require("../../crud/utils");
|
17
|
+
|
18
|
+
const updateContentReviewStatus = params => {
|
19
|
+
const {
|
20
|
+
apw,
|
21
|
+
pageBuilder,
|
22
|
+
security
|
23
|
+
} = params;
|
24
|
+
pageBuilder.onPageAfterPublish.subscribe(async ({
|
25
|
+
page
|
26
|
+
}) => {
|
27
|
+
const contentReviewId = (0, _get.default)(page, "settings.apw.contentReviewId");
|
28
|
+
/**
|
29
|
+
* Bail out if there is no "content review" linked.
|
30
|
+
*/
|
31
|
+
|
32
|
+
if (!contentReviewId) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
|
36
|
+
const contentReview = await apw.contentReview.get(contentReviewId);
|
37
|
+
const identity = security.getIdentity();
|
38
|
+
/**
|
39
|
+
* If content review is "readyToBePublished set its status as "published" after page publish.
|
40
|
+
*/
|
41
|
+
|
42
|
+
if (contentReview.reviewStatus === _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {
|
43
|
+
await apw.contentReview.update(contentReviewId, {
|
44
|
+
reviewStatus: _types.ApwContentReviewStatus.PUBLISHED,
|
45
|
+
content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
|
46
|
+
publishedBy: identity.id
|
47
|
+
})
|
48
|
+
});
|
49
|
+
}
|
50
|
+
});
|
51
|
+
pageBuilder.onPageAfterUnpublish.subscribe(async ({
|
52
|
+
page
|
53
|
+
}) => {
|
54
|
+
const contentReviewId = (0, _get.default)(page, "settings.apw.contentReviewId");
|
55
|
+
/**
|
56
|
+
* Bail out if there is no "content review" linked.
|
57
|
+
*/
|
58
|
+
|
59
|
+
if (!contentReviewId) {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
|
63
|
+
const contentReview = await apw.contentReview.get(contentReviewId);
|
64
|
+
/**
|
65
|
+
* If content review is "published set its status as "readyToBePublished" after page unpublish.
|
66
|
+
*/
|
67
|
+
|
68
|
+
if (contentReview.reviewStatus === _types.ApwContentReviewStatus.PUBLISHED) {
|
69
|
+
await apw.contentReview.update(contentReviewId, {
|
70
|
+
reviewStatus: _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED,
|
71
|
+
content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
|
72
|
+
publishedBy: null
|
73
|
+
})
|
74
|
+
});
|
75
|
+
}
|
76
|
+
});
|
77
|
+
};
|
78
|
+
|
79
|
+
exports.updateContentReviewStatus = updateContentReviewStatus;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["updateContentReviewStatus","params","apw","pageBuilder","security","onPageAfterPublish","subscribe","page","contentReviewId","get","contentReview","identity","getIdentity","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onPageAfterUnpublish"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n ApwOnPageBeforePublishTopicParams\n} from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\nimport { Security } from \"@webiny/api-security/types\";\n\ninterface UpdateContentReviewStatusParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n security: Security;\n}\n\nexport const updateContentReviewStatus = (params: UpdateContentReviewStatusParams) => {\n const { apw, pageBuilder, security } = params;\n\n pageBuilder.onPageAfterPublish.subscribe<ApwOnPageBeforePublishTopicParams>(\n async ({ page }) => {\n const contentReviewId = get(page, \"settings.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 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 );\n pageBuilder.onPageAfterUnpublish.subscribe<ApwOnPageBeforePublishTopicParams>(\n async ({ page }) => {\n const contentReviewId = get(page, \"settings.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 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};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAKA;;AAUO,MAAMA,yBAAyB,GAAIC,MAAD,IAA6C;EAClF,MAAM;IAAEC,GAAF;IAAOC,WAAP;IAAoBC;EAApB,IAAiCH,MAAvC;EAEAE,WAAW,CAACE,kBAAZ,CAA+BC,SAA/B,CACI,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAChB,MAAMC,eAAe,GAAG,IAAAC,YAAA,EAAIF,IAAJ,EAAU,8BAAV,CAAxB;IACA;AACZ;AACA;;IACY,IAAI,CAACC,eAAL,EAAsB;MAClB;IACH;;IAED,MAAME,aAAa,GAAG,MAAMR,GAAG,CAACQ,aAAJ,CAAkBD,GAAlB,CAAsBD,eAAtB,CAA5B;IACA,MAAMG,QAAQ,GAAGP,QAAQ,CAACQ,WAAT,EAAjB;IACA;AACZ;AACA;;IACY,IAAIF,aAAa,CAACG,YAAd,KAA+BC,6BAAA,CAAuBC,qBAA1D,EAAiF;MAC7E,MAAMb,GAAG,CAACQ,aAAJ,CAAkBM,MAAlB,CAAyBR,eAAzB,EAA0C;QAC5CK,YAAY,EAAEC,6BAAA,CAAuBG,SADO;QAE5CC,OAAO,0FACAR,aAAa,CAACQ,OADd,GAEAC,mDAFA;UAGHC,WAAW,EAAET,QAAQ,CAACU;QAHnB;MAFqC,CAA1C,CAAN;IAQH;EACJ,CAzBL;EA2BAlB,WAAW,CAACmB,oBAAZ,CAAiChB,SAAjC,CACI,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAChB,MAAMC,eAAe,GAAG,IAAAC,YAAA,EAAIF,IAAJ,EAAU,8BAAV,CAAxB;IACA;AACZ;AACA;;IACY,IAAI,CAACC,eAAL,EAAsB;MAClB;IACH;;IAED,MAAME,aAAa,GAAG,MAAMR,GAAG,CAACQ,aAAJ,CAAkBD,GAAlB,CAAsBD,eAAtB,CAA5B;IACA;AACZ;AACA;;IAEY,IAAIE,aAAa,CAACG,YAAd,KAA+BC,6BAAA,CAAuBG,SAA1D,EAAqE;MACjE,MAAMf,GAAG,CAACQ,aAAJ,CAAkBM,MAAlB,CAAyBR,eAAzB,EAA0C;QAC5CK,YAAY,EAAEC,6BAAA,CAAuBC,qBADO;QAE5CG,OAAO,0FACAR,aAAa,CAACQ,OADd,GAEAC,mDAFA;UAGHC,WAAW,EAAE;QAHV;MAFqC,CAA1C,CAAN;IAQH;EACJ,CAzBL;AA2BH,CAzDM"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { ApwWorkflow, ApwWorkflowCrud, ApwWorkflowScope, PageWithWorkflow } from "../../types";
|
2
|
+
import { PageBuilderContextObject } from "@webiny/api-page-builder/graphql/types";
|
3
|
+
interface AssignWorkflowToPageParams {
|
4
|
+
listWorkflow: ApwWorkflowCrud["list"];
|
5
|
+
page: PageWithWorkflow;
|
6
|
+
}
|
7
|
+
export declare const assignWorkflowToPage: ({ listWorkflow, page }: AssignWorkflowToPageParams) => Promise<void>;
|
8
|
+
export declare const hasPages: (workflow: ApwWorkflow) => Boolean;
|
9
|
+
export declare const shouldUpdatePages: (scope: ApwWorkflowScope, prevScope: ApwWorkflowScope) => Boolean;
|
10
|
+
interface GetUpdatePageOpsResult {
|
11
|
+
addedPages: string[];
|
12
|
+
removedPages: string[];
|
13
|
+
}
|
14
|
+
export declare const getPagesDiff: (currentPages: string[], prevPages: string[]) => GetUpdatePageOpsResult;
|
15
|
+
interface UpdatePageSettingsParams {
|
16
|
+
getPage: PageBuilderContextObject["getPage"];
|
17
|
+
updatePage: PageBuilderContextObject["updatePage"];
|
18
|
+
uniquePageId: string;
|
19
|
+
getNewSettings: (settings: PageWithWorkflow["settings"]) => PageWithWorkflow["settings"];
|
20
|
+
}
|
21
|
+
export declare const updatePageSettings: ({ getPage, updatePage, uniquePageId, getNewSettings }: UpdatePageSettingsParams) => Promise<void>;
|
22
|
+
export {};
|
@@ -0,0 +1,184 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.updatePageSettings = exports.shouldUpdatePages = exports.hasPages = exports.getPagesDiff = exports.assignWorkflowToPage = void 0;
|
9
|
+
|
10
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
11
|
+
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
+
|
14
|
+
var _types = require("../../types");
|
15
|
+
|
16
|
+
var _utils = require("../utils");
|
17
|
+
|
18
|
+
const isWorkflowApplicable = (page, workflow) => {
|
19
|
+
const application = workflow.app;
|
20
|
+
|
21
|
+
if (application !== _types.ApwWorkflowApplications.PB) {
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
const scopeType = workflow.scope.type;
|
26
|
+
|
27
|
+
if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
|
28
|
+
return true;
|
29
|
+
} else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
|
30
|
+
const categories = (0, _get.default)(workflow, "scope.data.categories");
|
31
|
+
|
32
|
+
if (Array.isArray(categories) && categories.includes(page.category)) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
|
36
|
+
const pages = (0, _get.default)(workflow, "scope.data.pages");
|
37
|
+
|
38
|
+
if (Array.isArray(pages) && pages.includes(page.pid)) {
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
|
45
|
+
throw new _error.default(`Unknown scope type "${scopeType}".`, "UNKNOWN_SCOPE_TYPE", {
|
46
|
+
workflow
|
47
|
+
});
|
48
|
+
};
|
49
|
+
|
50
|
+
const assignWorkflowToPage = async ({
|
51
|
+
listWorkflow,
|
52
|
+
page
|
53
|
+
}) => {
|
54
|
+
/**
|
55
|
+
* Lookup and assign "workflowId".
|
56
|
+
*/
|
57
|
+
try {
|
58
|
+
/*
|
59
|
+
* List all workflows for app pageBuilder
|
60
|
+
*/
|
61
|
+
const [entries] = await listWorkflow({
|
62
|
+
where: {
|
63
|
+
app: _types.ApwWorkflowApplications.PB
|
64
|
+
}
|
65
|
+
});
|
66
|
+
/*
|
67
|
+
* Re-order them based on workflow scope and pre-defined rule i.e.
|
68
|
+
* "specific" entry -> entry for a "category" -> "default".
|
69
|
+
* There can be more than one workflow with same "scope" and "app".
|
70
|
+
* Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
|
71
|
+
*/
|
72
|
+
|
73
|
+
const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
|
74
|
+
|
75
|
+
for (const workflow of sortedWorkflows) {
|
76
|
+
/**
|
77
|
+
* Assign the first applicable workflow to the page and exit.
|
78
|
+
*/
|
79
|
+
if (isWorkflowApplicable(page, workflow)) {
|
80
|
+
page.settings.apw = {
|
81
|
+
workflowId: workflow.id,
|
82
|
+
contentReviewId: null
|
83
|
+
};
|
84
|
+
break;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
} catch (ex) {
|
88
|
+
throw new _error.default(`Failed to assign workflow to page "${page.pid}".`, ex.code, ex.data);
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
exports.assignWorkflowToPage = assignWorkflowToPage;
|
93
|
+
|
94
|
+
const hasPages = workflow => {
|
95
|
+
const {
|
96
|
+
app,
|
97
|
+
scope
|
98
|
+
} = workflow;
|
99
|
+
return app === _types.ApwWorkflowApplications.PB && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.pages);
|
100
|
+
};
|
101
|
+
|
102
|
+
exports.hasPages = hasPages;
|
103
|
+
|
104
|
+
const shouldUpdatePages = (scope, prevScope) => {
|
105
|
+
/**
|
106
|
+
* Bail out early if the scope is not "CUSTOM" - at that point all pages should be updated.
|
107
|
+
*/
|
108
|
+
if (prevScope.type !== _types.WorkflowScopeTypes.CUSTOM) {
|
109
|
+
return true;
|
110
|
+
}
|
111
|
+
|
112
|
+
const prevScopePages = (0, _get.default)(prevScope, "data.pages");
|
113
|
+
const currentScopePages = (0, _get.default)(scope, "data.pages");
|
114
|
+
/**
|
115
|
+
* Bail out early if there were no pages assigned previously.
|
116
|
+
*/
|
117
|
+
|
118
|
+
if (prevScopePages.length === 0) {
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* Bail out early if number of pages has been changed.
|
123
|
+
*/
|
124
|
+
|
125
|
+
|
126
|
+
if (currentScopePages.length !== prevScopePages.length) {
|
127
|
+
return true;
|
128
|
+
}
|
129
|
+
/*
|
130
|
+
* Check whether previous scope has the exactly same pages as in the new scope.
|
131
|
+
*/
|
132
|
+
|
133
|
+
|
134
|
+
return !prevScopePages.every(pid => currentScopePages.includes(pid));
|
135
|
+
};
|
136
|
+
|
137
|
+
exports.shouldUpdatePages = shouldUpdatePages;
|
138
|
+
|
139
|
+
const getPagesDiff = (currentPages, prevPages) => {
|
140
|
+
const addedPages = currentPages.filter(id => !prevPages.includes(id));
|
141
|
+
const removedPages = prevPages.filter(id => !currentPages.includes(id));
|
142
|
+
return {
|
143
|
+
addedPages,
|
144
|
+
removedPages
|
145
|
+
};
|
146
|
+
};
|
147
|
+
|
148
|
+
exports.getPagesDiff = getPagesDiff;
|
149
|
+
|
150
|
+
const updatePageSettings = async ({
|
151
|
+
getPage,
|
152
|
+
updatePage,
|
153
|
+
uniquePageId,
|
154
|
+
getNewSettings
|
155
|
+
}) => {
|
156
|
+
try {
|
157
|
+
/**
|
158
|
+
* Currently, we only assign "workflow" to latest page.
|
159
|
+
*/
|
160
|
+
const page = await getPage(uniquePageId);
|
161
|
+
/**
|
162
|
+
* We can't update a page that is "locked".
|
163
|
+
*/
|
164
|
+
|
165
|
+
if (page.locked) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
/**
|
169
|
+
* There can be more than one workflow with same `scope` for same `app`. That is why;
|
170
|
+
* We'll update the workflow reference even though it already had one assign.
|
171
|
+
*/
|
172
|
+
|
173
|
+
|
174
|
+
await updatePage(page.id, {
|
175
|
+
settings: getNewSettings(page.settings)
|
176
|
+
});
|
177
|
+
} catch (e) {
|
178
|
+
if (e.code !== "NOT_FOUND") {
|
179
|
+
throw e;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
};
|
183
|
+
|
184
|
+
exports.updatePageSettings = updatePageSettings;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["isWorkflowApplicable","page","workflow","application","app","ApwWorkflowApplications","PB","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","categories","get","Array","isArray","includes","category","pages","pid","WebinyError","assignWorkflowToPage","listWorkflow","entries","where","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","settings","apw","workflowId","id","contentReviewId","ex","code","data","hasPages","shouldUpdatePages","prevScope","prevScopePages","currentScopePages","length","every","getPagesDiff","currentPages","prevPages","addedPages","filter","removedPages","updatePageSettings","getPage","updatePage","uniquePageId","getNewSettings","locked","e"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport WebinyError from \"@webiny/error\";\nimport {\n ApwWorkflow,\n ApwWorkflowApplications,\n ApwWorkflowCrud,\n ApwWorkflowScope,\n PageWithWorkflow,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\nconst isWorkflowApplicable = (page: PageWithWorkflow, workflow: ApwWorkflow) => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.PB) {\n return false;\n }\n\n const scopeType = workflow.scope.type;\n\n if (scopeType === WorkflowScopeTypes.DEFAULT) {\n return true;\n } else if (scopeType === WorkflowScopeTypes.CUSTOM) {\n const categories = get(workflow, \"scope.data.categories\");\n\n if (Array.isArray(categories) && categories.includes(page.category)) {\n return true;\n }\n\n const pages = get(workflow, \"scope.data.pages\");\n if (Array.isArray(pages) && pages.includes(page.pid)) {\n return true;\n }\n return false;\n }\n throw new WebinyError(`Unknown scope type \"${scopeType}\".`, \"UNKNOWN_SCOPE_TYPE\", {\n workflow\n });\n};\n\ninterface AssignWorkflowToPageParams {\n listWorkflow: ApwWorkflowCrud[\"list\"];\n page: PageWithWorkflow;\n}\n\nexport const assignWorkflowToPage = async ({ listWorkflow, page }: AssignWorkflowToPageParams) => {\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app pageBuilder\n */\n const [entries] = await listWorkflow({\n where: {\n app: ApwWorkflowApplications.PB\n }\n });\n\n /*\n * Re-order them based on workflow scope and pre-defined rule i.e.\n * \"specific\" entry -> entry for a \"category\" -> \"default\".\n * There can be more than one workflow with same \"scope\" and \"app\".\n * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.\n */\n const sortedWorkflows = entries\n .sort(workflowByPrecedenceDesc)\n .sort(workflowByCreatedOnDesc);\n\n for (const workflow of sortedWorkflows) {\n /**\n * Assign the first applicable workflow to the page and exit.\n */\n if (isWorkflowApplicable(page, workflow)) {\n page.settings.apw = {\n workflowId: workflow.id,\n contentReviewId: null\n };\n break;\n }\n }\n } catch (ex) {\n throw new WebinyError(`Failed to assign workflow to page \"${page.pid}\".`, ex.code, ex.data);\n }\n};\n\nexport const hasPages = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.PB &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.pages)\n );\n};\n\nexport const shouldUpdatePages = (\n scope: ApwWorkflowScope,\n prevScope: ApwWorkflowScope\n): Boolean => {\n /**\n * Bail out early if the scope is not \"CUSTOM\" - at that point all pages should be updated.\n */\n if (prevScope.type !== WorkflowScopeTypes.CUSTOM) {\n return true;\n }\n const prevScopePages: string[] = get(prevScope, \"data.pages\");\n const currentScopePages: string[] = get(scope, \"data.pages\");\n /**\n * Bail out early if there were no pages assigned previously.\n */\n if (prevScopePages.length === 0) {\n return true;\n }\n /**\n * Bail out early if number of pages has been changed.\n */\n if (currentScopePages.length !== prevScopePages.length) {\n return true;\n }\n /*\n * Check whether previous scope has the exactly same pages as in the new scope.\n */\n return !prevScopePages.every(pid => currentScopePages.includes(pid));\n};\n\ninterface GetUpdatePageOpsResult {\n addedPages: string[];\n removedPages: string[];\n}\n\nexport const getPagesDiff = (\n currentPages: string[],\n prevPages: string[]\n): GetUpdatePageOpsResult => {\n const addedPages = currentPages.filter(id => !prevPages.includes(id));\n const removedPages = prevPages.filter(id => !currentPages.includes(id));\n\n return {\n addedPages,\n removedPages\n };\n};\n\ninterface UpdatePageSettingsParams {\n getPage: PageBuilderContextObject[\"getPage\"];\n updatePage: PageBuilderContextObject[\"updatePage\"];\n uniquePageId: string;\n getNewSettings: (settings: PageWithWorkflow[\"settings\"]) => PageWithWorkflow[\"settings\"];\n}\n\nexport const updatePageSettings = async ({\n getPage,\n updatePage,\n uniquePageId,\n getNewSettings\n}: UpdatePageSettingsParams) => {\n try {\n /**\n * Currently, we only assign \"workflow\" to latest page.\n */\n const page = await getPage<PageWithWorkflow>(uniquePageId);\n /**\n * We can't update a page that is \"locked\".\n */\n if (page.locked) {\n return;\n }\n /**\n * There can be more than one workflow with same `scope` for same `app`. That is why;\n * We'll update the workflow reference even though it already had one assign.\n */\n await updatePage(page.id, {\n settings: getNewSettings(page.settings)\n });\n } catch (e) {\n if (e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAQA;;AAGA,MAAMA,oBAAoB,GAAG,CAACC,IAAD,EAAyBC,QAAzB,KAAmD;EAC5E,MAAMC,WAAW,GAAGD,QAAQ,CAACE,GAA7B;;EACA,IAAID,WAAW,KAAKE,8BAAA,CAAwBC,EAA5C,EAAgD;IAC5C,OAAO,KAAP;EACH;;EAED,MAAMC,SAAS,GAAGL,QAAQ,CAACM,KAAT,CAAeC,IAAjC;;EAEA,IAAIF,SAAS,KAAKG,yBAAA,CAAmBC,OAArC,EAA8C;IAC1C,OAAO,IAAP;EACH,CAFD,MAEO,IAAIJ,SAAS,KAAKG,yBAAA,CAAmBE,MAArC,EAA6C;IAChD,MAAMC,UAAU,GAAG,IAAAC,YAAA,EAAIZ,QAAJ,EAAc,uBAAd,CAAnB;;IAEA,IAAIa,KAAK,CAACC,OAAN,CAAcH,UAAd,KAA6BA,UAAU,CAACI,QAAX,CAAoBhB,IAAI,CAACiB,QAAzB,CAAjC,EAAqE;MACjE,OAAO,IAAP;IACH;;IAED,MAAMC,KAAK,GAAG,IAAAL,YAAA,EAAIZ,QAAJ,EAAc,kBAAd,CAAd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CAAP;AAIH,CAXM;;;;AAoBA,MAAMC,kBAAkB,GAAG,OAAO;EACrCC,OADqC;EAErCC,UAFqC;EAGrCC,YAHqC;EAIrCC;AAJqC,CAAP,KAKF;EAC5B,IAAI;IACA;AACR;AACA;IACQ,MAAMtD,IAAI,GAAG,MAAMmD,OAAO,CAAmBE,YAAnB,CAA1B;IACA;AACR;AACA;;IACQ,IAAIrD,IAAI,CAACuD,MAAT,EAAiB;MACb;IACH;IACD;AACR;AACA;AACA;;;IACQ,MAAMH,UAAU,CAACpD,IAAI,CAACgC,EAAN,EAAU;MACtBH,QAAQ,EAAEyB,cAAc,CAACtD,IAAI,CAAC6B,QAAN;IADF,CAAV,CAAhB;EAGH,CAlBD,CAkBE,OAAO2B,CAAP,EAAU;IACR,IAAIA,CAAC,CAACrB,IAAF,KAAW,WAAf,EAA4B;MACxB,MAAMqB,CAAN;IACH;EACJ;AACJ,CA7BM"}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
2
|
+
import { SecurityIdentity } from "@webiny/api-security/types";
|
3
|
+
import { ApwChangeRequest, ApwContentReview, ApwContentReviewCrud, ApwContentReviewStep, ApwContentReviewStepStatus, ApwContext, ApwReviewerCrud, ApwWorkflow, ApwWorkflowStep, ApwWorkflowStepTypes } from "../types";
|
4
|
+
export declare const getNanoid: (size?: number | undefined) => string;
|
5
|
+
export interface CreateModelFieldParams extends Omit<CmsModelField, "id" | "storageId" | "fieldId"> {
|
6
|
+
fieldId?: string;
|
7
|
+
parent: string;
|
8
|
+
}
|
9
|
+
export interface HasReviewersParams {
|
10
|
+
identity: SecurityIdentity;
|
11
|
+
step: ApwContentReviewStep;
|
12
|
+
getReviewer: ApwReviewerCrud["get"];
|
13
|
+
}
|
14
|
+
export declare const hasReviewer: (params: HasReviewersParams) => Promise<Boolean>;
|
15
|
+
export declare const getValue: (object: Record<string, any>, key: string) => any;
|
16
|
+
export declare const getContentReviewStepInitialStatus: (workflowSteps: ApwWorkflowStep[], index: number, previousStepStatus?: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
|
17
|
+
export declare const getNextStepStatus: (previousStepType: ApwWorkflowStepTypes, previousStepStatus: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
|
18
|
+
export interface ExtractContentReviewIdAndStepResult {
|
19
|
+
id: string;
|
20
|
+
stepId: string;
|
21
|
+
}
|
22
|
+
export declare const extractContentReviewIdAndStep: (step: ApwChangeRequest["step"]) => ExtractContentReviewIdAndStepResult;
|
23
|
+
declare type SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, "id" | "contentReviewMethods">;
|
24
|
+
export declare const safelyGetContentReview: ({ id, contentReviewMethods }: SafelyGetContentReviewParams) => Promise<ApwContentReview | null>;
|
25
|
+
export interface UpdateContentReviewParams {
|
26
|
+
id: string;
|
27
|
+
contentReviewMethods: ApwContentReviewCrud;
|
28
|
+
getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;
|
29
|
+
}
|
30
|
+
export declare const updateContentReview: ({ contentReviewMethods, id, getNewContentReviewData }: UpdateContentReviewParams) => Promise<void>;
|
31
|
+
export declare const updateContentReviewStep: (steps: ApwContentReviewStep[], stepId: string, updater: (step: ApwContentReviewStep) => ApwContentReviewStep) => ApwContentReviewStep[];
|
32
|
+
declare type CheckInstallationParams = Pick<ApwContext, "tenancy" | "i18n">;
|
33
|
+
export declare const isInstallationPending: ({ tenancy, i18n }: CheckInstallationParams) => boolean;
|
34
|
+
export declare const workflowByPrecedenceDesc: (a: ApwWorkflow, b: ApwWorkflow) => number;
|
35
|
+
export declare const workflowByCreatedOnDesc: (a: ApwWorkflow, b: ApwWorkflow) => number;
|
36
|
+
export {};
|
package/plugins/utils.js
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.workflowByPrecedenceDesc = exports.workflowByCreatedOnDesc = exports.updateContentReviewStep = exports.updateContentReview = exports.safelyGetContentReview = exports.isInstallationPending = exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getNanoid = exports.getContentReviewStepInitialStatus = exports.extractContentReviewIdAndStep = void 0;
|
9
|
+
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
+
|
12
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
13
|
+
|
14
|
+
var _nanoid = require("nanoid");
|
15
|
+
|
16
|
+
var _types = require("../types");
|
17
|
+
|
18
|
+
const ALPHANUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
19
|
+
const getNanoid = (0, _nanoid.customAlphabet)(ALPHANUMERIC, 10);
|
20
|
+
exports.getNanoid = getNanoid;
|
21
|
+
|
22
|
+
const hasReviewer = async params => {
|
23
|
+
const {
|
24
|
+
getReviewer,
|
25
|
+
identity,
|
26
|
+
step
|
27
|
+
} = params;
|
28
|
+
|
29
|
+
for (const stepReviewer of step.reviewers) {
|
30
|
+
const entry = await getReviewer(stepReviewer.id);
|
31
|
+
|
32
|
+
if (entry.identityId === identity.id) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return false;
|
38
|
+
};
|
39
|
+
|
40
|
+
exports.hasReviewer = hasReviewer;
|
41
|
+
|
42
|
+
const getValue = (object, key) => {
|
43
|
+
return (0, _get.default)(object, `values.${key}`);
|
44
|
+
};
|
45
|
+
|
46
|
+
exports.getValue = getValue;
|
47
|
+
|
48
|
+
const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
|
49
|
+
/**
|
50
|
+
* Always set first step 'active' by default.
|
51
|
+
*/
|
52
|
+
if (index === 0) {
|
53
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
54
|
+
}
|
55
|
+
|
56
|
+
const previousStep = workflowSteps[index - 1];
|
57
|
+
|
58
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStep.type !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
59
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
60
|
+
}
|
61
|
+
|
62
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
63
|
+
};
|
64
|
+
|
65
|
+
exports.getContentReviewStepInitialStatus = getContentReviewStepInitialStatus;
|
66
|
+
|
67
|
+
const getNextStepStatus = (previousStepType, previousStepStatus) => {
|
68
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.DONE) {
|
69
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
70
|
+
}
|
71
|
+
|
72
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStepType !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
73
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
74
|
+
}
|
75
|
+
|
76
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
77
|
+
};
|
78
|
+
|
79
|
+
exports.getNextStepStatus = getNextStepStatus;
|
80
|
+
|
81
|
+
const extractContentReviewIdAndStep = step => {
|
82
|
+
/*
|
83
|
+
* Get associated content review entry.
|
84
|
+
*/
|
85
|
+
const [entryId, version, stepId] = step.split("#");
|
86
|
+
const revisionId = `${entryId}#${version}`;
|
87
|
+
return {
|
88
|
+
id: revisionId,
|
89
|
+
stepId
|
90
|
+
};
|
91
|
+
};
|
92
|
+
|
93
|
+
exports.extractContentReviewIdAndStep = extractContentReviewIdAndStep;
|
94
|
+
|
95
|
+
const safelyGetContentReview = async ({
|
96
|
+
id,
|
97
|
+
contentReviewMethods
|
98
|
+
}) => {
|
99
|
+
let contentReviewEntry = null;
|
100
|
+
|
101
|
+
try {
|
102
|
+
contentReviewEntry = await contentReviewMethods.get(id);
|
103
|
+
} catch (e) {
|
104
|
+
if (e.message !== "index_not_found_exception" && e.code !== "NOT_FOUND") {
|
105
|
+
throw e;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
return contentReviewEntry;
|
110
|
+
};
|
111
|
+
|
112
|
+
exports.safelyGetContentReview = safelyGetContentReview;
|
113
|
+
|
114
|
+
const updateContentReview = async ({
|
115
|
+
contentReviewMethods,
|
116
|
+
id,
|
117
|
+
getNewContentReviewData
|
118
|
+
}) => {
|
119
|
+
const contentReviewEntry = await safelyGetContentReview({
|
120
|
+
id,
|
121
|
+
contentReviewMethods
|
122
|
+
});
|
123
|
+
|
124
|
+
if (contentReviewEntry) {
|
125
|
+
const newContentReviewData = getNewContentReviewData(contentReviewEntry);
|
126
|
+
/**
|
127
|
+
* Update content review entry.
|
128
|
+
*/
|
129
|
+
|
130
|
+
await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);
|
131
|
+
}
|
132
|
+
};
|
133
|
+
|
134
|
+
exports.updateContentReview = updateContentReview;
|
135
|
+
|
136
|
+
const updateContentReviewStep = (steps, stepId, updater) => {
|
137
|
+
return steps.map(step => {
|
138
|
+
if (step.id === stepId) {
|
139
|
+
return (0, _objectSpread2.default)({}, updater(step));
|
140
|
+
}
|
141
|
+
|
142
|
+
return step;
|
143
|
+
});
|
144
|
+
};
|
145
|
+
|
146
|
+
exports.updateContentReviewStep = updateContentReviewStep;
|
147
|
+
|
148
|
+
const isInstallationPending = ({
|
149
|
+
tenancy,
|
150
|
+
i18n
|
151
|
+
}) => {
|
152
|
+
/**
|
153
|
+
* In case of a fresh webiny project "tenant" and "locale" won't be there until
|
154
|
+
* installation is completed. So, we need to skip "APW" creation till then.
|
155
|
+
*/
|
156
|
+
const tenant = tenancy.getCurrentTenant();
|
157
|
+
|
158
|
+
if (!tenant) {
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
return !i18n.getContentLocale();
|
163
|
+
};
|
164
|
+
|
165
|
+
exports.isInstallationPending = isInstallationPending;
|
166
|
+
const WORKFLOW_PRECEDENCE = {
|
167
|
+
[_types.WorkflowScopeTypes.DEFAULT]: 0,
|
168
|
+
[_types.WorkflowScopeTypes.CUSTOM]: 1
|
169
|
+
};
|
170
|
+
|
171
|
+
const workflowByPrecedenceDesc = (a, b) => {
|
172
|
+
const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];
|
173
|
+
const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];
|
174
|
+
/**
|
175
|
+
* In descending order of workflow precedence.
|
176
|
+
*/
|
177
|
+
|
178
|
+
return scoreB - scoreA;
|
179
|
+
};
|
180
|
+
|
181
|
+
exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
|
182
|
+
|
183
|
+
const workflowByCreatedOnDesc = (a, b) => {
|
184
|
+
const createdOnA = (0, _get.default)(a, "createdOn");
|
185
|
+
const createdOnB = (0, _get.default)(b, "createdOn");
|
186
|
+
/**
|
187
|
+
* In descending order of workflow createdOn i.e. the most recent one first.
|
188
|
+
*/
|
189
|
+
|
190
|
+
return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
|
191
|
+
};
|
192
|
+
|
193
|
+
exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["ALPHANUMERIC","getNanoid","customAlphabet","hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { customAlphabet } from \"nanoid\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nconst ALPHANUMERIC = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\nexport const getNanoid = customAlphabet(ALPHANUMERIC, 10);\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AAcA,MAAMA,YAAY,GAAG,gEAArB;AACO,MAAMC,SAAS,GAAG,IAAAC,sBAAA,EAAeF,YAAf,EAA6B,EAA7B,CAAlB;;;AAcA,MAAMG,WAAW,GAAG,MAAOC,MAAP,IAAwD;EAC/E,MAAM;IAAEC,WAAF;IAAeC,QAAf;IAAyBC;EAAzB,IAAkCH,MAAxC;;EACA,KAAK,MAAMI,YAAX,IA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