@webiny/api-apw 5.34.8 → 5.35.0-beta.1
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.js +0 -10
- package/ApwChangeRequestNotification.js.map +1 -1
- package/ApwCommentNotification.js +0 -10
- package/ApwCommentNotification.js.map +1 -1
- package/ApwContentReviewNotification.js +0 -10
- package/ApwContentReviewNotification.js.map +1 -1
- package/ApwContentUrlPlugin.js +0 -10
- package/ApwContentUrlPlugin.js.map +1 -1
- package/ContentApwSettingsPlugin.js +0 -5
- package/ContentApwSettingsPlugin.js.map +1 -1
- package/crud/createChangeRequestMethods.js +4 -11
- package/crud/createChangeRequestMethods.js.map +1 -1
- package/crud/createCommentMethods.js +4 -12
- package/crud/createCommentMethods.js.map +1 -1
- package/crud/createContentReviewMethods.js +20 -84
- package/crud/createContentReviewMethods.js.map +1 -1
- package/crud/createReviewerMethods.js +4 -12
- package/crud/createReviewerMethods.js.map +1 -1
- package/crud/createWorkflowMethods.js +4 -17
- package/crud/createWorkflowMethods.js.map +1 -1
- package/crud/index.js +0 -25
- package/crud/index.js.map +1 -1
- package/crud/utils.js +0 -28
- package/crud/utils.js.map +1 -1
- package/index.d.ts +1 -2
- package/index.js +1 -15
- package/index.js.map +1 -1
- package/package.json +34 -34
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +0 -15
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/cms/apwEntryPlugins.js +0 -8
- package/plugins/cms/apwEntryPlugins.js.map +1 -1
- package/plugins/cms/index.js +0 -13
- package/plugins/cms/index.js.map +1 -1
- package/plugins/cms/linkContentReviewToEntry.js +0 -17
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
- package/plugins/cms/linkWorkflowToEntry.js +2 -31
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
- package/plugins/cms/notifications/changeRequestNotification.js +0 -4
- package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/cms/notifications/commentNotification.js +0 -4
- package/plugins/cms/notifications/commentNotification.js.map +1 -1
- package/plugins/cms/notifications/contentReviewNotification.js +0 -4
- package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/cms/notifications/contentUrl.js +1 -8
- package/plugins/cms/notifications/contentUrl.js.map +1 -1
- package/plugins/cms/triggerContentReview.js +0 -14
- package/plugins/cms/triggerContentReview.js.map +1 -1
- package/plugins/cms/updateContentReviewStatus.js +0 -18
- package/plugins/cms/updateContentReviewStatus.js.map +1 -1
- package/plugins/cms/utils.js +2 -47
- package/plugins/cms/utils.js.map +1 -1
- package/plugins/context.d.ts +0 -1
- package/plugins/context.js +2 -47
- package/plugins/context.js.map +1 -1
- package/plugins/graphql/changeRequest.gql.js +3 -10
- package/plugins/graphql/changeRequest.gql.js.map +1 -1
- package/plugins/graphql/comment.gql.js +3 -10
- package/plugins/graphql/comment.gql.js.map +1 -1
- package/plugins/graphql/contentReview.gql.js +6 -25
- package/plugins/graphql/contentReview.gql.js.map +1 -1
- package/plugins/graphql/reviewer.gql.js +3 -10
- package/plugins/graphql/reviewer.gql.js.map +1 -1
- package/plugins/graphql/workflow.gql.js +3 -10
- package/plugins/graphql/workflow.gql.js.map +1 -1
- package/plugins/graphql.js +3 -18
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/createReviewerFromIdentity.js +2 -11
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -9
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -8
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
- package/plugins/hooks/index.js +0 -14
- package/plugins/hooks/index.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +2 -18
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/plugins/hooks/initializeNotifications.js +0 -5
- package/plugins/hooks/initializeNotifications.js.map +1 -1
- package/plugins/hooks/listContentReviews.js +0 -12
- package/plugins/hooks/listContentReviews.js.map +1 -1
- package/plugins/hooks/notifications/appUrl.js +0 -4
- package/plugins/hooks/notifications/appUrl.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestAfterCreate.js +3 -36
- package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestUrl.js +0 -4
- package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
- package/plugins/hooks/notifications/commentAfterCreate.js +3 -38
- package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/commentUrl.js +0 -4
- package/plugins/hooks/notifications/commentUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewAfterCreate.js +4 -32
- package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewUrl.js +0 -4
- package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentUrl.js +0 -5
- package/plugins/hooks/notifications/contentUrl.js.map +1 -1
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +0 -4
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +0 -4
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +0 -4
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/reviewers.js +15 -21
- package/plugins/hooks/notifications/reviewers.js.map +1 -1
- package/plugins/hooks/notifications/sendChangeRequestNotification.js +0 -11
- package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendCommentNotification.js +0 -11
- package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendContentReviewNotification.js +0 -11
- package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
- package/plugins/hooks/updatePendingChangeRequests.js +0 -8
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
- package/plugins/hooks/updateTotalComments.js +0 -9
- package/plugins/hooks/updateTotalComments.js.map +1 -1
- package/plugins/hooks/validateChangeRequest.js +0 -16
- package/plugins/hooks/validateChangeRequest.js.map +1 -1
- package/plugins/hooks/validateComment.js +1 -12
- package/plugins/hooks/validateComment.js.map +1 -1
- package/plugins/hooks/validateContentReview.js +0 -6
- package/plugins/hooks/validateContentReview.js.map +1 -1
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -15
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
- package/plugins/pageBuilder/index.js +0 -11
- package/plugins/pageBuilder/index.js.map +1 -1
- package/plugins/pageBuilder/linkContentReviewToPage.js +0 -16
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
- package/plugins/pageBuilder/linkWorkflowToPage.js +1 -31
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -4
- package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/commentNotification.js +0 -4
- package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -4
- package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/contentUrl.js +1 -7
- package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
- package/plugins/pageBuilder/triggerContentReview.js +0 -11
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
- package/plugins/pageBuilder/updateContentReviewStatus.js +0 -12
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
- package/plugins/pageBuilder/utils.js +1 -35
- package/plugins/pageBuilder/utils.js.map +1 -1
- package/plugins/utils.js +0 -43
- package/plugins/utils.js.map +1 -1
- package/scheduler/createScheduleActionMethods.js +1 -20
- package/scheduler/createScheduleActionMethods.js.map +1 -1
- package/scheduler/handlers/executeAction/index.d.ts +1 -1
- package/scheduler/handlers/executeAction/index.js +9 -40
- package/scheduler/handlers/executeAction/index.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +0 -7
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -23
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +4 -28
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/security.js +0 -11
- package/scheduler/handlers/executeAction/security.js.map +1 -1
- package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
- package/scheduler/handlers/scheduleAction/index.js +5 -25
- package/scheduler/handlers/scheduleAction/index.js.map +1 -1
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -23
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
- package/scheduler/handlers/utils.d.ts +1 -2
- package/scheduler/handlers/utils.js +3 -41
- package/scheduler/handlers/utils.js.map +1 -1
- package/scheduler/index.js +0 -3
- package/scheduler/index.js.map +1 -1
- package/scheduler/types.d.ts +2 -20
- package/scheduler/types.js +0 -11
- package/scheduler/types.js.map +1 -1
- package/storageOperations/changeRequestStorageOperations.js +20 -39
- package/storageOperations/changeRequestStorageOperations.js.map +1 -1
- package/storageOperations/commentStorageOperations.js +23 -44
- package/storageOperations/commentStorageOperations.js.map +1 -1
- package/storageOperations/contentReviewStorageOperations.js +20 -37
- package/storageOperations/contentReviewStorageOperations.js.map +1 -1
- package/storageOperations/index.js +0 -14
- package/storageOperations/index.js.map +1 -1
- package/storageOperations/models/changeRequest.model.js +0 -9
- package/storageOperations/models/changeRequest.model.js.map +1 -1
- package/storageOperations/models/comment.model.js +0 -8
- package/storageOperations/models/comment.model.js.map +1 -1
- package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
- package/storageOperations/models/contentModelPluginFactory.js +3 -11
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
- package/storageOperations/models/contentReview.model.js +0 -26
- package/storageOperations/models/contentReview.model.js.map +1 -1
- package/storageOperations/models/index.js +2 -28
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/models/reviewer.model.js +0 -8
- package/storageOperations/models/reviewer.model.js.map +1 -1
- package/storageOperations/models/utils.js +0 -4
- package/storageOperations/models/utils.js.map +1 -1
- package/storageOperations/models/workflow.model.js +0 -23
- package/storageOperations/models/workflow.model.js.map +1 -1
- package/storageOperations/reviewerStorageOperations.js +23 -45
- package/storageOperations/reviewerStorageOperations.js.map +1 -1
- package/storageOperations/workflowStorageOperations.js +20 -39
- package/storageOperations/workflowStorageOperations.js.map +1 -1
- package/types.d.ts +6 -5
- package/types.js +0 -14
- package/types.js.map +1 -1
- package/utils/contentApwSettingsPlugin.js +0 -6
- package/utils/contentApwSettingsPlugin.js.map +1 -1
- package/utils/errors.js +0 -17
- package/utils/errors.js.map +1 -1
- package/utils/fieldResolver.js +2 -12
- package/utils/fieldResolver.js.map +1 -1
- package/utils/resolve.d.ts +1 -1
- package/utils/resolve.js +0 -3
- package/utils/resolve.js.map +1 -1
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createContentUrlPlugin = exports.createContentEntryUrl = void 0;
|
7
|
-
|
8
7
|
var _ApwContentUrlPlugin = require("../../../ApwContentUrlPlugin");
|
9
|
-
|
10
8
|
var _types = require("../../../types");
|
11
|
-
|
12
9
|
/**
|
13
10
|
* In this file we create a plugin which in turn creates a content entry url when requested by the code which sends notifications.
|
14
11
|
* Due to multiple content types for the APW, everything needs to be pluginable.
|
15
12
|
*/
|
13
|
+
|
16
14
|
const createContentEntryUrl = params => {
|
17
15
|
/**
|
18
16
|
* All variables must exist for URL to be created.
|
@@ -22,11 +20,9 @@ const createContentEntryUrl = params => {
|
|
22
20
|
if (!!key) {
|
23
21
|
continue;
|
24
22
|
}
|
25
|
-
|
26
23
|
console.log(`Missing variable "${key}", which we use to create a content entry URL.`);
|
27
24
|
return null;
|
28
25
|
}
|
29
|
-
|
30
26
|
const {
|
31
27
|
baseUrl,
|
32
28
|
modelId,
|
@@ -34,9 +30,7 @@ const createContentEntryUrl = params => {
|
|
34
30
|
} = params;
|
35
31
|
return `${baseUrl}/cms/content-entries/${modelId}?id=${id}`;
|
36
32
|
};
|
37
|
-
|
38
33
|
exports.createContentEntryUrl = createContentEntryUrl;
|
39
|
-
|
40
34
|
const createContentUrlPlugin = () => {
|
41
35
|
return (0, _ApwContentUrlPlugin.createApwContentUrlPlugin)(_types.ApwContentTypes.CMS_ENTRY, params => {
|
42
36
|
const {
|
@@ -56,5 +50,4 @@ const createContentUrlPlugin = () => {
|
|
56
50
|
});
|
57
51
|
});
|
58
52
|
};
|
59
|
-
|
60
53
|
exports.createContentUrlPlugin = createContentUrlPlugin;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createContentEntryUrl","params","key","console","log","baseUrl","modelId","id","createContentUrlPlugin","createApwContentUrlPlugin","ApwContentTypes","CMS_ENTRY","contentReview","content","settings"],"sources":["contentUrl.ts"],"sourcesContent":["/**\n * In this file we create a plugin which in turn creates a content entry url when requested by the code which sends notifications.\n * Due to multiple content types for the APW, everything needs to be pluginable.\n */\nimport { createApwContentUrlPlugin } from \"~/ApwContentUrlPlugin\";\nimport { ApwContentTypes } from \"~/types\";\n\ninterface CreateContentEntryUrlParams {\n baseUrl?: string;\n modelId?: string;\n id: string;\n}\nexport const createContentEntryUrl = (params: CreateContentEntryUrlParams): string | null => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a content entry URL.`);\n return null;\n }\n const { baseUrl, modelId, id } = params;\n return `${baseUrl}/cms/content-entries/${modelId}?id=${id}`;\n};\n\nexport const createContentUrlPlugin = () => {\n return createApwContentUrlPlugin(ApwContentTypes.CMS_ENTRY, params => {\n const { baseUrl, contentReview } = params;\n const { id } = contentReview.content;\n const { modelId } = contentReview.content.settings;\n return createContentEntryUrl({\n baseUrl,\n modelId,\n id\n });\n });\n};\n"],"mappings":"
|
1
|
+
{"version":3,"names":["createContentEntryUrl","params","key","console","log","baseUrl","modelId","id","createContentUrlPlugin","createApwContentUrlPlugin","ApwContentTypes","CMS_ENTRY","contentReview","content","settings"],"sources":["contentUrl.ts"],"sourcesContent":["/**\n * In this file we create a plugin which in turn creates a content entry url when requested by the code which sends notifications.\n * Due to multiple content types for the APW, everything needs to be pluginable.\n */\nimport { createApwContentUrlPlugin } from \"~/ApwContentUrlPlugin\";\nimport { ApwContentTypes } from \"~/types\";\n\ninterface CreateContentEntryUrlParams {\n baseUrl?: string;\n modelId?: string;\n id: string;\n}\nexport const createContentEntryUrl = (params: CreateContentEntryUrlParams): string | null => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a content entry URL.`);\n return null;\n }\n const { baseUrl, modelId, id } = params;\n return `${baseUrl}/cms/content-entries/${modelId}?id=${id}`;\n};\n\nexport const createContentUrlPlugin = () => {\n return createApwContentUrlPlugin(ApwContentTypes.CMS_ENTRY, params => {\n const { baseUrl, contentReview } = params;\n const { id } = contentReview.content;\n const { modelId } = contentReview.content.settings;\n return createContentEntryUrl({\n baseUrl,\n modelId,\n id\n });\n });\n};\n"],"mappings":";;;;;;AAIA;AACA;AALA;AACA;AACA;AACA;;AASO,MAAMA,qBAAqB,GAAIC,MAAmC,IAAoB;EACzF;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAG,IAAID,MAAM,EAAE;IACtB,IAAI,CAAC,CAACC,GAAG,EAAE;MACP;IACJ;IACAC,OAAO,CAACC,GAAG,CAAE,qBAAoBF,GAAI,gDAA+C,CAAC;IACrF,OAAO,IAAI;EACf;EACA,MAAM;IAAEG,OAAO;IAAEC,OAAO;IAAEC;EAAG,CAAC,GAAGN,MAAM;EACvC,OAAQ,GAAEI,OAAQ,wBAAuBC,OAAQ,OAAMC,EAAG,EAAC;AAC/D,CAAC;AAAC;AAEK,MAAMC,sBAAsB,GAAG,MAAM;EACxC,OAAO,IAAAC,8CAAyB,EAACC,sBAAe,CAACC,SAAS,EAAEV,MAAM,IAAI;IAClE,MAAM;MAAEI,OAAO;MAAEO;IAAc,CAAC,GAAGX,MAAM;IACzC,MAAM;MAAEM;IAAG,CAAC,GAAGK,aAAa,CAACC,OAAO;IACpC,MAAM;MAAEP;IAAQ,CAAC,GAAGM,aAAa,CAACC,OAAO,CAACC,QAAQ;IAClD,OAAOd,qBAAqB,CAAC;MACzBK,OAAO;MACPC,OAAO;MACPC;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
|
@@ -1,18 +1,13 @@
|
|
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
7
|
exports.triggerContentReview = void 0;
|
9
|
-
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
11
|
-
|
12
9
|
var _types = require("../../types");
|
13
|
-
|
14
10
|
var _utils = require("./utils");
|
15
|
-
|
16
11
|
const triggerContentReview = params => {
|
17
12
|
const {
|
18
13
|
cms,
|
@@ -23,37 +18,28 @@ const triggerContentReview = params => {
|
|
23
18
|
model
|
24
19
|
}) => {
|
25
20
|
var _entry$meta, _entry$meta$apw, _entry$meta2, _entry$meta2$apw;
|
26
|
-
|
27
21
|
if ((0, _utils.isAwpModel)(model)) {
|
28
22
|
return;
|
29
23
|
}
|
30
|
-
|
31
24
|
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;
|
32
|
-
|
33
25
|
if (contentReviewId) {
|
34
26
|
const contentReview = await apw.contentReview.get(contentReviewId);
|
35
|
-
|
36
27
|
if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.UNDER_REVIEW) {
|
37
28
|
return;
|
38
29
|
}
|
39
|
-
|
40
30
|
throw new _error.default(`A peer review for this content has been already requested.`, "REVIEW_ALREADY_EXIST", {
|
41
31
|
contentReviewId,
|
42
32
|
entry
|
43
33
|
});
|
44
34
|
}
|
45
|
-
|
46
35
|
const workflowId = (_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.workflowId;
|
47
|
-
|
48
36
|
if (!workflowId) {
|
49
37
|
return;
|
50
38
|
}
|
51
|
-
|
52
39
|
throw new _error.default("This content requires peer review approval before it can be published.", "REVIEW_REQUIRED", {
|
53
40
|
workflowId,
|
54
41
|
entry
|
55
42
|
});
|
56
43
|
});
|
57
44
|
};
|
58
|
-
|
59
45
|
exports.triggerContentReview = triggerContentReview;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["triggerContentReview","params","cms","apw","onEntryBeforePublish","subscribe","entry","model","isAwpModel","contentReviewId","meta","contentReview","get","reviewStatus","ApwContentReviewStatus","UNDER_REVIEW","Error","workflowId"],"sources":["triggerContentReview.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryBeforePublishTopicParams\n} from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { isAwpModel } from \"~/plugins/cms/utils\";\n\ninterface TriggerContentReviewParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const triggerContentReview = (params: TriggerContentReviewParams) => {\n const { cms, apw } = params;\n\n cms.onEntryBeforePublish.subscribe<OnCmsEntryBeforePublishTopicParams>(\n async ({ entry, model }) => {\n if (isAwpModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n if (contentReviewId) {\n const contentReview = await apw.contentReview.get(contentReviewId);\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.UNDER_REVIEW) {\n return;\n }\n throw new Error(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n entry\n }\n );\n }\n\n const workflowId = entry.meta?.apw?.workflowId;\n\n if (!workflowId) {\n return;\n }\n throw new Error(\n \"This content requires peer review approval before it can be published.\",\n \"REVIEW_REQUIRED\",\n {\n workflowId,\n entry\n }\n );\n }\n );\n};\n"],"mappings":"
|
1
|
+
{"version":3,"names":["triggerContentReview","params","cms","apw","onEntryBeforePublish","subscribe","entry","model","isAwpModel","contentReviewId","meta","contentReview","get","reviewStatus","ApwContentReviewStatus","UNDER_REVIEW","Error","workflowId"],"sources":["triggerContentReview.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryBeforePublishTopicParams\n} from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { isAwpModel } from \"~/plugins/cms/utils\";\n\ninterface TriggerContentReviewParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const triggerContentReview = (params: TriggerContentReviewParams) => {\n const { cms, apw } = params;\n\n cms.onEntryBeforePublish.subscribe<OnCmsEntryBeforePublishTopicParams>(\n async ({ entry, model }) => {\n if (isAwpModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n if (contentReviewId) {\n const contentReview = await apw.contentReview.get(contentReviewId);\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.UNDER_REVIEW) {\n return;\n }\n throw new Error(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n entry\n }\n );\n }\n\n const workflowId = entry.meta?.apw?.workflowId;\n\n if (!workflowId) {\n return;\n }\n throw new Error(\n \"This content requires peer review approval before it can be published.\",\n \"REVIEW_REQUIRED\",\n {\n workflowId,\n entry\n }\n );\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAMA;AAMO,MAAMA,oBAAoB,GAAIC,MAAkC,IAAK;EACxE,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BC,GAAG,CAACE,oBAAoB,CAACC,SAAS,CAC9B,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IAAA;IACxB,IAAI,IAAAC,iBAAU,EAACD,KAAK,CAAC,EAAE;MACnB;IACJ;IACA,MAAME,eAAe,kBAAGH,KAAK,CAACI,IAAI,mEAAV,YAAYP,GAAG,oDAAf,gBAAiBM,eAAe;IACxD,IAAIA,eAAe,EAAE;MACjB,MAAME,aAAa,GAAG,MAAMR,GAAG,CAACQ,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;MAElE,IAAIE,aAAa,CAACE,YAAY,KAAKC,6BAAsB,CAACC,YAAY,EAAE;QACpE;MACJ;MACA,MAAM,IAAIC,cAAK,CACV,4DAA2D,EAC5D,sBAAsB,EACtB;QACIP,eAAe;QACfH;MACJ,CAAC,CACJ;IACL;IAEA,MAAMW,UAAU,mBAAGX,KAAK,CAACI,IAAI,qEAAV,aAAYP,GAAG,qDAAf,iBAAiBc,UAAU;IAE9C,IAAI,CAACA,UAAU,EAAE;MACb;IACJ;IACA,MAAM,IAAID,cAAK,CACX,wEAAwE,EACxE,iBAAiB,EACjB;MACIC,UAAU;MACVX;IACJ,CAAC,CACJ;EACL,CAAC,CACJ;AACL,CAAC;AAAC"}
|
@@ -1,20 +1,14 @@
|
|
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
7
|
exports.updateContentReviewStatus = void 0;
|
9
|
-
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
-
|
12
9
|
var _types = require("../../types");
|
13
|
-
|
14
10
|
var _utils = require("../../crud/utils");
|
15
|
-
|
16
11
|
var _utils2 = require("./utils");
|
17
|
-
|
18
12
|
const updateContentReviewStatus = params => {
|
19
13
|
const {
|
20
14
|
apw,
|
@@ -26,30 +20,24 @@ const updateContentReviewStatus = params => {
|
|
26
20
|
model
|
27
21
|
}) => {
|
28
22
|
var _entry$meta, _entry$meta$apw;
|
29
|
-
|
30
23
|
if ((0, _utils2.isAwpModel)(model)) {
|
31
24
|
return;
|
32
25
|
}
|
33
|
-
|
34
26
|
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;
|
35
27
|
/**
|
36
28
|
* Bail out if there is no "content review" linked.
|
37
29
|
*/
|
38
|
-
|
39
30
|
if (!contentReviewId) {
|
40
31
|
return;
|
41
32
|
}
|
42
|
-
|
43
33
|
const contentReview = await apw.contentReview.get(contentReviewId);
|
44
34
|
const identity = security.getIdentity();
|
45
35
|
/**
|
46
36
|
* If content review is "readyToBePublished set its status as "published" after page publish.
|
47
37
|
*/
|
48
|
-
|
49
38
|
if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {
|
50
39
|
return;
|
51
40
|
}
|
52
|
-
|
53
41
|
await apw.contentReview.update(contentReviewId, {
|
54
42
|
reviewStatus: _types.ApwContentReviewStatus.PUBLISHED,
|
55
43
|
content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
|
@@ -62,20 +50,16 @@ const updateContentReviewStatus = params => {
|
|
62
50
|
model
|
63
51
|
}) => {
|
64
52
|
var _entry$meta2, _entry$meta2$apw;
|
65
|
-
|
66
53
|
if ((0, _utils2.isAwpModel)(model)) {
|
67
54
|
return;
|
68
55
|
}
|
69
|
-
|
70
56
|
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;
|
71
57
|
/**
|
72
58
|
* Bail out if there is no "content review" linked.
|
73
59
|
*/
|
74
|
-
|
75
60
|
if (!contentReviewId) {
|
76
61
|
return;
|
77
62
|
}
|
78
|
-
|
79
63
|
const contentReview = await apw.contentReview.get(contentReviewId);
|
80
64
|
/**
|
81
65
|
* If content review is "published set its status as "readyToBePublished" after page unpublish.
|
@@ -84,7 +68,6 @@ const updateContentReviewStatus = params => {
|
|
84
68
|
if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.PUBLISHED) {
|
85
69
|
return;
|
86
70
|
}
|
87
|
-
|
88
71
|
await apw.contentReview.update(contentReviewId, {
|
89
72
|
reviewStatus: _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED,
|
90
73
|
content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
|
@@ -93,5 +76,4 @@ const updateContentReviewStatus = params => {
|
|
93
76
|
});
|
94
77
|
});
|
95
78
|
};
|
96
|
-
|
97
79
|
exports.updateContentReviewStatus = updateContentReviewStatus;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","isAwpModel","contentReviewId","meta","contentReview","get","identity","getIdentity","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onEntryAfterUnpublish"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryAfterPublishTopicParams,\n OnCmsEntryAfterUnpublishTopicParams\n} from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\nimport { isAwpModel } 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 (isAwpModel(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 (isAwpModel(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":"
|
1
|
+
{"version":3,"names":["updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","isAwpModel","contentReviewId","meta","contentReview","get","identity","getIdentity","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onEntryAfterUnpublish"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryAfterPublishTopicParams,\n OnCmsEntryAfterUnpublishTopicParams\n} from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\nimport { isAwpModel } 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 (isAwpModel(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 (isAwpModel(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":";;;;;;;;AAAA;AAMA;AAGA;AAQO,MAAMA,yBAAyB,GAAIC,MAAuC,IAAK;EAClF,MAAM;IAAEC,GAAG;IAAEC,GAAG;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAErCE,GAAG,CAACE,mBAAmB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AMlB,GAAG,CAACU,aAAa,CAACO,MAAM,CAACT,eAAe,EAAE;MAC5CM,YAAY,EAAEC,6BAAsB,CAACC,qBAAqB;MAC1DG,OAAO,0FACAT,aAAa,CAACS,OAAO,GACrBC,mDAA4C;QAC/CC,WAAW,EAAE;MAAI;IAEzB,CAAC,CAAC;EACN,CAAC,CACJ;AACL,CAAC;AAAC"}
|
package/plugins/cms/utils.js
CHANGED
@@ -1,72 +1,50 @@
|
|
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
7
|
exports.updateEntryMeta = exports.isAwpModel = exports.hasEntries = exports.getLatestEntryRevision = exports.getEntryTitle = exports.fetchModel = exports.assignWorkflowToEntry = void 0;
|
9
|
-
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
-
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
-
|
14
10
|
var _types = require("../../types");
|
15
|
-
|
16
11
|
var _utils = require("../utils");
|
17
|
-
|
18
12
|
var _changeRequest = require("../../storageOperations/models/changeRequest.model");
|
19
|
-
|
20
13
|
var _comment = require("../../storageOperations/models/comment.model");
|
21
|
-
|
22
14
|
var _contentReview = require("../../storageOperations/models/contentReview.model");
|
23
|
-
|
24
15
|
var _reviewer = require("../../storageOperations/models/reviewer.model");
|
25
|
-
|
26
16
|
var _workflow = require("../../storageOperations/models/workflow.model");
|
27
|
-
|
28
17
|
const fetchModel = async (cms, id, settings) => {
|
29
18
|
if (!settings) {
|
30
19
|
throw new _error.default("Missing settings.", "SETTINGS_ERROR", {
|
31
20
|
id
|
32
21
|
});
|
33
22
|
}
|
34
|
-
|
35
23
|
const modelId = settings.modelId;
|
36
|
-
|
37
24
|
if (!modelId) {
|
38
25
|
throw new _error.default("Missing modelId in settings.", "MODEL_ID_ERROR", {
|
39
26
|
id,
|
40
27
|
settings
|
41
28
|
});
|
42
29
|
}
|
43
|
-
|
44
30
|
const model = await cms.getModel(modelId);
|
45
|
-
|
46
31
|
if (model) {
|
47
32
|
return model;
|
48
33
|
}
|
49
|
-
|
50
34
|
throw new _error.default("There is no requested model in the system.", "MODEL_NOT_EXISTS", {
|
51
35
|
id,
|
52
36
|
settings
|
53
37
|
});
|
54
38
|
};
|
55
|
-
|
56
39
|
exports.fetchModel = fetchModel;
|
57
|
-
|
58
40
|
const getEntryTitle = (model, entry) => {
|
59
41
|
const titleFieldId = model.titleFieldId;
|
60
|
-
|
61
42
|
if (!titleFieldId || !entry.values[titleFieldId]) {
|
62
43
|
return entry.id;
|
63
44
|
}
|
64
|
-
|
65
45
|
return entry.values[titleFieldId];
|
66
46
|
};
|
67
|
-
|
68
47
|
exports.getEntryTitle = getEntryTitle;
|
69
|
-
|
70
48
|
const getLatestEntryRevision = async params => {
|
71
49
|
const {
|
72
50
|
cms,
|
@@ -75,18 +53,14 @@ const getLatestEntryRevision = async params => {
|
|
75
53
|
} = params;
|
76
54
|
const items = await cms.getLatestEntriesByIds(model, [entryId]);
|
77
55
|
const item = items.shift();
|
78
|
-
|
79
56
|
if (!item) {
|
80
57
|
throw new _error.default("There is no entry with given ID.", "ENTRY_NOT_FOUND", {
|
81
58
|
entryId
|
82
59
|
});
|
83
60
|
}
|
84
|
-
|
85
61
|
return item;
|
86
62
|
};
|
87
|
-
|
88
63
|
exports.getLatestEntryRevision = getLatestEntryRevision;
|
89
|
-
|
90
64
|
const updateEntryMeta = async params => {
|
91
65
|
const {
|
92
66
|
entryId,
|
@@ -101,43 +75,31 @@ const updateEntryMeta = async params => {
|
|
101
75
|
});
|
102
76
|
await cms.updateEntry(model, entry.id, {}, meta);
|
103
77
|
};
|
104
|
-
|
105
78
|
exports.updateEntryMeta = updateEntryMeta;
|
106
|
-
|
107
79
|
const isWorkflowApplicable = (entry, workflow) => {
|
108
80
|
const application = workflow.app;
|
109
|
-
|
110
81
|
if (application !== _types.ApwWorkflowApplications.CMS) {
|
111
82
|
return false;
|
112
83
|
}
|
113
|
-
|
114
84
|
const scopeType = workflow.scope.type;
|
115
|
-
|
116
85
|
if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
|
117
86
|
return true;
|
118
87
|
} else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
|
119
88
|
var _workflow$scope$data, _workflow$scope$data2;
|
120
|
-
|
121
89
|
const models = (_workflow$scope$data = workflow.scope.data) === null || _workflow$scope$data === void 0 ? void 0 : _workflow$scope$data.models;
|
122
|
-
|
123
90
|
if (Array.isArray(models) && models.includes(entry.modelId)) {
|
124
91
|
return true;
|
125
92
|
}
|
126
|
-
|
127
93
|
const entries = ((_workflow$scope$data2 = workflow.scope.data) === null || _workflow$scope$data2 === void 0 ? void 0 : _workflow$scope$data2.entries) || [];
|
128
|
-
|
129
94
|
if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {
|
130
95
|
return true;
|
131
96
|
}
|
132
|
-
|
133
97
|
return false;
|
134
98
|
}
|
135
|
-
|
136
99
|
throw new _error.default(`Unknown scope type "${scopeType}".`, "UNKNOWN_SCOPE_TYPE", {
|
137
100
|
workflow
|
138
101
|
});
|
139
102
|
};
|
140
|
-
|
141
103
|
const assignWorkflowToEntry = async params => {
|
142
104
|
const {
|
143
105
|
apw,
|
@@ -146,7 +108,6 @@ const assignWorkflowToEntry = async params => {
|
|
146
108
|
/**
|
147
109
|
* Lookup and assign "workflowId".
|
148
110
|
*/
|
149
|
-
|
150
111
|
try {
|
151
112
|
/*
|
152
113
|
* List all workflows for app cms
|
@@ -157,24 +118,23 @@ const assignWorkflowToEntry = async params => {
|
|
157
118
|
}
|
158
119
|
});
|
159
120
|
console.log(`Found ${entries.length} workflows.`);
|
121
|
+
|
160
122
|
/*
|
161
123
|
* Re-order them based on workflow scope and pre-defined rule i.e.
|
162
124
|
* "specific" entry -> entry for a "category" -> "default".
|
163
125
|
* There can be more than one workflow with same "scope" and "app".
|
164
126
|
* Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
|
165
127
|
*/
|
166
|
-
|
167
128
|
const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
|
129
|
+
|
168
130
|
/**
|
169
131
|
* Assign the first applicable workflow to the page and exit.
|
170
132
|
*/
|
171
|
-
|
172
133
|
for (const workflow of sortedWorkflows) {
|
173
134
|
if (isWorkflowApplicable(entry, workflow) === false) {
|
174
135
|
console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);
|
175
136
|
continue;
|
176
137
|
}
|
177
|
-
|
178
138
|
entry.meta = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry.meta || {}), {}, {
|
179
139
|
apw: {
|
180
140
|
workflowId: workflow.id,
|
@@ -187,9 +147,7 @@ const assignWorkflowToEntry = async params => {
|
|
187
147
|
throw new _error.default(`Failed to assign workflow to CMS entry "${entry.id}".`, ex.code, ex.data);
|
188
148
|
}
|
189
149
|
};
|
190
|
-
|
191
150
|
exports.assignWorkflowToEntry = assignWorkflowToEntry;
|
192
|
-
|
193
151
|
const hasEntries = workflow => {
|
194
152
|
const {
|
195
153
|
app,
|
@@ -197,11 +155,8 @@ const hasEntries = workflow => {
|
|
197
155
|
} = workflow;
|
198
156
|
return app === _types.ApwWorkflowApplications.CMS && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.entries);
|
199
157
|
};
|
200
|
-
|
201
158
|
exports.hasEntries = hasEntries;
|
202
|
-
|
203
159
|
const isAwpModel = model => {
|
204
160
|
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
161
|
};
|
206
|
-
|
207
162
|
exports.isAwpModel = isAwpModel;
|
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,EAE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InD,cAAJ,CACD,2CAA0CK,KAAK,CAACP,EAAG,IADlD,EAEFqD,EAAE,CAACC,IAFD,EAGFD,EAAE,CAACpB,IAHD,CAAN;EAKH;AACJ,CAnDM;;;;AAqDA,MAAMsB,UAAU,GAAIlC,QAAD,IAAoC;EAC1D,MAAM;IAAEE,GAAF;IAAOI;EAAP,IAAiBN,QAAvB;EACA,OACIE,GAAG,KAAKC,8BAAA,CAAwBC,GAAhC,IACAE,KAAK,CAACC,IAAN,KAAeC,yBAAA,CAAmBE,MADlC,IAEAJ,KAAK,CAACM,IAFN,IAGAC,KAAK,CAACC,OAAN,CAAcR,KAAK,CAACM,IAAN,CAAWI,OAAzB,CAJJ;AAMH,CARM;;;;AAUA,MAAMmB,UAAU,GAAIpD,KAAD,IAA8B;EACpD,OAAO,CACHqD,sCADG,EAEHC,yBAFG,EAGHC,sCAHG,EAIHC,2BAJG,EAKHC,2BALG,EAMLzB,QANK,CAMIhC,KAAK,CAACD,OANV,CAAP;AAOH,CARM"}
|
1
|
+
{"version":3,"names":["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,GAAgB,EAChBC,EAAU,EACVC,QAAsC,KAClB;EACpB,IAAI,CAACA,QAAQ,EAAE;IACX,MAAM,IAAIC,cAAW,CAAC,mBAAmB,EAAE,gBAAgB,EAAE;MACzDF;IACJ,CAAC,CAAC;EACN;EACA,MAAMG,OAAO,GAAGF,QAAQ,CAACE,OAAO;EAChC,IAAI,CAACA,OAAO,EAAE;IACV,MAAM,IAAID,cAAW,CAAC,8BAA8B,EAAE,gBAAgB,EAAE;MACpEF,EAAE;MACFC;IACJ,CAAC,CAAC;EACN;EACA,MAAMG,KAAK,GAAG,MAAML,GAAG,CAACM,QAAQ,CAACF,OAAO,CAAC;EACzC,IAAIC,KAAK,EAAE;IACP,OAAOA,KAAK;EAChB;EACA,MAAM,IAAIF,cAAW,CAAC,4CAA4C,EAAE,kBAAkB,EAAE;IACpFF,EAAE;IACFC;EACJ,CAAC,CAAC;AACN,CAAC;AAAC;AAEK,MAAMK,aAAa,GAAG,CAACF,KAAe,EAAEG,KAAe,KAAa;EACvE,MAAMC,YAAY,GAAGJ,KAAK,CAACI,Y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webiny/api";
|
|
2
2
|
import { ApwContext } from "../types";
|
3
3
|
import { CreateApwContextParams } from "../scheduler/types";
|
4
4
|
export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
5
|
-
export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
|
package/plugins/context.js
CHANGED
@@ -1,36 +1,22 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
|
-
exports.createApwPageBuilderContext =
|
9
|
-
|
7
|
+
exports.createApwPageBuilderContext = void 0;
|
10
8
|
var _hooks = require("./hooks");
|
11
|
-
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
-
|
14
10
|
var _api = require("@webiny/api");
|
15
|
-
|
16
11
|
var _crud = require("../crud");
|
17
|
-
|
18
12
|
var _pageBuilder = require("./pageBuilder");
|
19
|
-
|
20
13
|
var _storageOperations = require("../storageOperations");
|
21
|
-
|
22
14
|
var _scheduler = require("../scheduler");
|
23
|
-
|
24
15
|
var _security = require("../scheduler/handlers/executeAction/security");
|
25
|
-
|
26
16
|
var _utils = require("./utils");
|
27
|
-
|
28
17
|
var _extendPbPageSettingsSchema = require("./pageBuilder/extendPbPageSettingsSchema");
|
29
|
-
|
30
18
|
var _apwContentPagePlugins = require("./pageBuilder/apwContentPagePlugins");
|
31
|
-
|
32
19
|
var _cms = require("./cms");
|
33
|
-
|
34
20
|
const setupApwContext = params => new _api.ContextPlugin(async context => {
|
35
21
|
const {
|
36
22
|
tenancy,
|
@@ -38,34 +24,26 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
38
24
|
i18n,
|
39
25
|
handlerClient
|
40
26
|
} = context;
|
41
|
-
|
42
27
|
if ((0, _utils.isInstallationPending)({
|
43
28
|
tenancy,
|
44
29
|
i18n
|
45
30
|
})) {
|
46
31
|
return;
|
47
32
|
}
|
48
|
-
|
49
33
|
const getLocale = () => {
|
50
34
|
const locale = i18n.getContentLocale();
|
51
|
-
|
52
35
|
if (!locale) {
|
53
36
|
throw new _error.default("Missing content locale in api-apw/plugins/context.ts", "LOCALE_ERROR");
|
54
37
|
}
|
55
|
-
|
56
38
|
return locale;
|
57
39
|
};
|
58
|
-
|
59
40
|
const getTenant = () => {
|
60
41
|
return tenancy.getCurrentTenant();
|
61
42
|
};
|
62
|
-
|
63
43
|
const getPermission = async name => {
|
64
44
|
return security.getPermission(name);
|
65
45
|
};
|
66
|
-
|
67
46
|
const getIdentity = () => security.getIdentity();
|
68
|
-
|
69
47
|
const scheduler = (0, _scheduler.createScheduler)({
|
70
48
|
getLocale,
|
71
49
|
getIdentity,
|
@@ -83,7 +61,6 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
83
61
|
* TODO: We need to figure out a way to pass "cms" from outside (e.g. apps/api/graphql)
|
84
62
|
*/
|
85
63
|
cms: context.cms,
|
86
|
-
|
87
64
|
/**
|
88
65
|
* TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
|
89
66
|
*/
|
@@ -95,19 +72,16 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
|
|
95
72
|
plugins: context.plugins
|
96
73
|
});
|
97
74
|
});
|
98
|
-
|
99
75
|
const setupApwPageBuilder = () => {
|
100
76
|
return new _api.ContextPlugin(async context => {
|
101
77
|
(0, _pageBuilder.apwPageBuilderHooks)(context);
|
102
78
|
});
|
103
79
|
};
|
104
|
-
|
105
80
|
const setupApwHeadlessCms = () => {
|
106
81
|
return new _api.ContextPlugin(async context => {
|
107
82
|
(0, _cms.apwCmsHooks)(context);
|
108
83
|
});
|
109
84
|
};
|
110
|
-
|
111
85
|
const createApwPageBuilderContext = params => {
|
112
86
|
return new _api.ContextPlugin(async context => {
|
113
87
|
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
@@ -115,7 +89,6 @@ const createApwPageBuilderContext = params => {
|
|
115
89
|
} else if ((0, _utils.isInstallationPending)(context)) {
|
116
90
|
return;
|
117
91
|
}
|
118
|
-
|
119
92
|
await setupApwContext(params).apply(context);
|
120
93
|
await setupApwPageBuilder().apply(context);
|
121
94
|
await setupApwHeadlessCms().apply(context);
|
@@ -125,22 +98,4 @@ const createApwPageBuilderContext = params => {
|
|
125
98
|
context.plugins.register((0, _extendPbPageSettingsSchema.extendPbPageSettingsSchema)());
|
126
99
|
});
|
127
100
|
};
|
128
|
-
|
129
|
-
exports.createApwPageBuilderContext = createApwPageBuilderContext;
|
130
|
-
|
131
|
-
const createApwHeadlessCmsContext = params => {
|
132
|
-
return new _api.ContextPlugin(async context => {
|
133
|
-
if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
|
134
|
-
return;
|
135
|
-
} else if ((0, _utils.isInstallationPending)(context)) {
|
136
|
-
return;
|
137
|
-
}
|
138
|
-
|
139
|
-
await setupApwContext(params).apply(context);
|
140
|
-
await setupApwHeadlessCms().apply(context);
|
141
|
-
await (0, _hooks.attachApwHooks)().apply(context);
|
142
|
-
await (0, _security.createCustomAuth)(params).apply(context);
|
143
|
-
});
|
144
|
-
};
|
145
|
-
|
146
|
-
exports.createApwHeadlessCmsContext = createApwHeadlessCmsContext;
|
101
|
+
exports.createApwPageBuilderContext = createApwPageBuilderContext;
|