@webiny/api-apw 0.0.0-ee-vpcs.549378cf03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ApwChangeRequestNotification.d.ts +27 -0
- package/ApwChangeRequestNotification.js +40 -0
- package/ApwChangeRequestNotification.js.map +1 -0
- package/ApwCommentNotification.d.ts +27 -0
- package/ApwCommentNotification.js +40 -0
- package/ApwCommentNotification.js.map +1 -0
- package/ApwContentReviewNotification.d.ts +26 -0
- package/ApwContentReviewNotification.js +40 -0
- package/ApwContentReviewNotification.js.map +1 -0
- package/ApwContentUrlPlugin.d.ts +19 -0
- package/ApwContentUrlPlugin.js +40 -0
- package/ApwContentUrlPlugin.js.map +1 -0
- 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 +562 -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 +38 -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 +45 -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/notifications/changeRequestNotification.d.ts +1 -0
- package/plugins/cms/notifications/changeRequestNotification.js +35 -0
- package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
- package/plugins/cms/notifications/commentNotification.d.ts +1 -0
- package/plugins/cms/notifications/commentNotification.js +35 -0
- package/plugins/cms/notifications/commentNotification.js.map +1 -0
- package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
- package/plugins/cms/notifications/contentReviewNotification.js +35 -0
- package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
- package/plugins/cms/notifications/contentUrl.d.ts +8 -0
- package/plugins/cms/notifications/contentUrl.js +60 -0
- package/plugins/cms/notifications/contentUrl.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 +116 -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 +82 -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 +74 -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/initializeNotifications.d.ts +2 -0
- package/plugins/hooks/initializeNotifications.js +20 -0
- package/plugins/hooks/initializeNotifications.js.map +1 -0
- package/plugins/hooks/listContentReviews.d.ts +10 -0
- package/plugins/hooks/listContentReviews.js +68 -0
- package/plugins/hooks/listContentReviews.js.map +1 -0
- package/plugins/hooks/notifications/appUrl.d.ts +2 -0
- package/plugins/hooks/notifications/appUrl.js +22 -0
- package/plugins/hooks/notifications/appUrl.js.map +1 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.js +144 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
- package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
- package/plugins/hooks/notifications/changeRequestUrl.js +31 -0
- package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
- package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
- package/plugins/hooks/notifications/commentAfterCreate.js +157 -0
- package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
- package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
- package/plugins/hooks/notifications/commentUrl.js +31 -0
- package/plugins/hooks/notifications/commentUrl.js.map +1 -0
- package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
- package/plugins/hooks/notifications/contentReviewAfterCreate.js +122 -0
- package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
- package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
- package/plugins/hooks/notifications/contentReviewUrl.js +30 -0
- package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
- package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
- package/plugins/hooks/notifications/contentUrl.js +29 -0
- package/plugins/hooks/notifications/contentUrl.js.map +1 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +25 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +25 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +25 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
- package/plugins/hooks/notifications/reviewers.d.ts +15 -0
- package/plugins/hooks/notifications/reviewers.js +51 -0
- package/plugins/hooks/notifications/reviewers.js.map +1 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.js +52 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
- package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
- package/plugins/hooks/notifications/sendCommentNotification.js +52 -0
- package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.js +52 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.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 +89 -0
- package/plugins/hooks/validateChangeRequest.js.map +1 -0
- package/plugins/hooks/validateComment.d.ts +2 -0
- package/plugins/hooks/validateComment.js +57 -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 +53 -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/notifications/changeRequestNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +35 -0
- package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
- package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/commentNotification.js +35 -0
- package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.js +35 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
- package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
- package/plugins/pageBuilder/notifications/contentUrl.js +53 -0
- package/plugins/pageBuilder/notifications/contentUrl.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 +35 -0
- package/plugins/utils.js +187 -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 +71 -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 +97 -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 +111 -0
- package/storageOperations/workflowStorageOperations.js.map +1 -0
- package/types.d.ts +752 -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
package/plugins/utils.js
ADDED
@@ -0,0 +1,187 @@
|
|
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.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 _types = require("../types");
|
15
|
+
|
16
|
+
const hasReviewer = async params => {
|
17
|
+
const {
|
18
|
+
getReviewer,
|
19
|
+
identity,
|
20
|
+
step
|
21
|
+
} = params;
|
22
|
+
|
23
|
+
for (const stepReviewer of step.reviewers) {
|
24
|
+
const entry = await getReviewer(stepReviewer.id);
|
25
|
+
|
26
|
+
if (entry.identityId === identity.id) {
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
return false;
|
32
|
+
};
|
33
|
+
|
34
|
+
exports.hasReviewer = hasReviewer;
|
35
|
+
|
36
|
+
const getValue = (object, key) => {
|
37
|
+
return (0, _get.default)(object, `values.${key}`);
|
38
|
+
};
|
39
|
+
|
40
|
+
exports.getValue = getValue;
|
41
|
+
|
42
|
+
const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
|
43
|
+
/**
|
44
|
+
* Always set first step 'active' by default.
|
45
|
+
*/
|
46
|
+
if (index === 0) {
|
47
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
48
|
+
}
|
49
|
+
|
50
|
+
const previousStep = workflowSteps[index - 1];
|
51
|
+
|
52
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStep.type !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
53
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
54
|
+
}
|
55
|
+
|
56
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
57
|
+
};
|
58
|
+
|
59
|
+
exports.getContentReviewStepInitialStatus = getContentReviewStepInitialStatus;
|
60
|
+
|
61
|
+
const getNextStepStatus = (previousStepType, previousStepStatus) => {
|
62
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.DONE) {
|
63
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
64
|
+
}
|
65
|
+
|
66
|
+
if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStepType !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
|
67
|
+
return _types.ApwContentReviewStepStatus.ACTIVE;
|
68
|
+
}
|
69
|
+
|
70
|
+
return _types.ApwContentReviewStepStatus.INACTIVE;
|
71
|
+
};
|
72
|
+
|
73
|
+
exports.getNextStepStatus = getNextStepStatus;
|
74
|
+
|
75
|
+
const extractContentReviewIdAndStep = step => {
|
76
|
+
/*
|
77
|
+
* Get associated content review entry.
|
78
|
+
*/
|
79
|
+
const [entryId, version, stepId] = step.split("#");
|
80
|
+
const revisionId = `${entryId}#${version}`;
|
81
|
+
return {
|
82
|
+
id: revisionId,
|
83
|
+
stepId
|
84
|
+
};
|
85
|
+
};
|
86
|
+
|
87
|
+
exports.extractContentReviewIdAndStep = extractContentReviewIdAndStep;
|
88
|
+
|
89
|
+
const safelyGetContentReview = async ({
|
90
|
+
id,
|
91
|
+
contentReviewMethods
|
92
|
+
}) => {
|
93
|
+
let contentReviewEntry = null;
|
94
|
+
|
95
|
+
try {
|
96
|
+
contentReviewEntry = await contentReviewMethods.get(id);
|
97
|
+
} catch (e) {
|
98
|
+
if (e.message !== "index_not_found_exception" && e.code !== "NOT_FOUND") {
|
99
|
+
throw e;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
return contentReviewEntry;
|
104
|
+
};
|
105
|
+
|
106
|
+
exports.safelyGetContentReview = safelyGetContentReview;
|
107
|
+
|
108
|
+
const updateContentReview = async ({
|
109
|
+
contentReviewMethods,
|
110
|
+
id,
|
111
|
+
getNewContentReviewData
|
112
|
+
}) => {
|
113
|
+
const contentReviewEntry = await safelyGetContentReview({
|
114
|
+
id,
|
115
|
+
contentReviewMethods
|
116
|
+
});
|
117
|
+
|
118
|
+
if (contentReviewEntry) {
|
119
|
+
const newContentReviewData = getNewContentReviewData(contentReviewEntry);
|
120
|
+
/**
|
121
|
+
* Update content review entry.
|
122
|
+
*/
|
123
|
+
|
124
|
+
await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
exports.updateContentReview = updateContentReview;
|
129
|
+
|
130
|
+
const updateContentReviewStep = (steps, stepId, updater) => {
|
131
|
+
return steps.map(step => {
|
132
|
+
if (step.id === stepId) {
|
133
|
+
return (0, _objectSpread2.default)({}, updater(step));
|
134
|
+
}
|
135
|
+
|
136
|
+
return step;
|
137
|
+
});
|
138
|
+
};
|
139
|
+
|
140
|
+
exports.updateContentReviewStep = updateContentReviewStep;
|
141
|
+
|
142
|
+
const isInstallationPending = ({
|
143
|
+
tenancy,
|
144
|
+
i18n
|
145
|
+
}) => {
|
146
|
+
/**
|
147
|
+
* In case of a fresh webiny project "tenant" and "locale" won't be there until
|
148
|
+
* installation is completed. So, we need to skip "APW" creation till then.
|
149
|
+
*/
|
150
|
+
const tenant = tenancy.getCurrentTenant();
|
151
|
+
|
152
|
+
if (!tenant) {
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
|
156
|
+
return !i18n.getContentLocale();
|
157
|
+
};
|
158
|
+
|
159
|
+
exports.isInstallationPending = isInstallationPending;
|
160
|
+
const WORKFLOW_PRECEDENCE = {
|
161
|
+
[_types.WorkflowScopeTypes.DEFAULT]: 0,
|
162
|
+
[_types.WorkflowScopeTypes.CUSTOM]: 1
|
163
|
+
};
|
164
|
+
|
165
|
+
const workflowByPrecedenceDesc = (a, b) => {
|
166
|
+
const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];
|
167
|
+
const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];
|
168
|
+
/**
|
169
|
+
* In descending order of workflow precedence.
|
170
|
+
*/
|
171
|
+
|
172
|
+
return scoreB - scoreA;
|
173
|
+
};
|
174
|
+
|
175
|
+
exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
|
176
|
+
|
177
|
+
const workflowByCreatedOnDesc = (a, b) => {
|
178
|
+
const createdOnA = (0, _get.default)(a, "createdOn");
|
179
|
+
const createdOnB = (0, _get.default)(b, "createdOn");
|
180
|
+
/**
|
181
|
+
* In descending order of workflow createdOn i.e. the most recent one first.
|
182
|
+
*/
|
183
|
+
|
184
|
+
return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
|
185
|
+
};
|
186
|
+
|
187
|
+
exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["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 { 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\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;;AAGA;;AA0BO,MAAMA,WAAW,GAAG,MAAOC,MAAP,IAAwD;EAC/E,MAAM;IAAEC,WAAF;IAAeC,QAAf;IAAyBC;EAAzB,IAAkCH,MAAxC;;EACA,KAAK,MAAMI,YAAX,IAA2BD,IAAI,CAACE,SAAhC,EAA2C;IACvC,MAAMC,KAAK,GAAG,MAAML,WAAW,CAACG,YAAY,CAACG,EAAd,CAA/B;;IAEA,IAAID,KAAK,CAACE,UAAN,KAAqBN,QAAQ,CAACK,EAAlC,EAAsC;MAClC,OAAO,IAAP;IACH;EACJ;;EAED,OAAO,KAAP;AACH,CAXM;;;;AAaA,MAAME,QAAQ,GAAG,CAACC,MAAD,EAA8BC,GAA9B,KAA8C;EAClE,OAAO,IAAAC,YAAA,EAAIF,MAAJ,EAAa,UAASC,GAAI,EAA1B,CAAP;AACH,CAFM;;;;AAIA,MAAME,iCAAiC,GAAG,CAC7CC,aAD6C,EAE7CC,KAF6C,EAG7CC,kBAH6C,KAIhB;EAC7B;AACJ;AACA;EACI,IAAID,KAAK,KAAK,CAAd,EAAiB;IACb,OAAOE,iCAAA,CAA2BC,MAAlC;EACH;;EAED,MAAMC,YAAY,GAAGL,aAAa,CAACC,KAAK,GAAG,CAAT,CAAlC;;EACA,IAC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M0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAF,CAAQzC,IAAT,CAAlC;EACA;AACJ;AACA;;EACI,OAAO0C,MAAM,GAAGF,MAAhB;AACH,CAPM;;;;AASA,MAAMG,uBAAuB,GAAG,CAACL,CAAD,EAAiBC,CAAjB,KAAoC;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAA,EAAI8C,CAAJ,EAAO,WAAP,CAAnB;EACA,MAAMO,UAAU,GAAG,IAAArD,YAAA,EAAI+C,CAAJ,EAAO,WAAP,CAAnB;EACA;AACJ;AACA;;EACI,OAAO,IAAIO,IAAJ,CAASD,UAAT,EAAqBE,OAArB,KAAiC,IAAID,IAAJ,CAASF,UAAT,EAAqBG,OAArB,EAAxC;AACH,CAPM"}
|
@@ -0,0 +1,149 @@
|
|
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.createScheduleActionMethods = createScheduleActionMethods;
|
9
|
+
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
+
|
12
|
+
var _mdbid = _interopRequireDefault(require("mdbid"));
|
13
|
+
|
14
|
+
var _fields = require("@commodo/fields");
|
15
|
+
|
16
|
+
var _validation = require("@webiny/validation");
|
17
|
+
|
18
|
+
var _types = require("./types");
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Package mdbid does not have types.
|
22
|
+
*/
|
23
|
+
// @ts-ignore
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Package @commodo/fields does not have types.
|
27
|
+
*/
|
28
|
+
// @ts-ignore
|
29
|
+
const CreateDataModel = (0, _fields.withFields)(instance => {
|
30
|
+
return {
|
31
|
+
datetime: (0, _fields.string)({
|
32
|
+
validation: _validation.validation.create(`required`)
|
33
|
+
}),
|
34
|
+
type: (0, _fields.string)({
|
35
|
+
validation: _validation.validation.create(`required,in:${_types.ApwContentTypes.PAGE}:${_types.ApwContentTypes.CMS_ENTRY}`)
|
36
|
+
}),
|
37
|
+
action: (0, _fields.string)({
|
38
|
+
validation: _validation.validation.create(`required,in:${_types.ApwScheduleActionTypes.PUBLISH}:${_types.ApwScheduleActionTypes.UNPUBLISH}`)
|
39
|
+
}),
|
40
|
+
entryId: (0, _fields.string)({
|
41
|
+
validation: _validation.validation.create(`required`)
|
42
|
+
}),
|
43
|
+
modelId: (0, _fields.string)({
|
44
|
+
validation: value => {
|
45
|
+
if (instance.type !== _types.ApwContentTypes.CMS_ENTRY) {
|
46
|
+
return true;
|
47
|
+
} else if (!!value) {
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
|
51
|
+
throw new Error(`There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`);
|
52
|
+
}
|
53
|
+
})
|
54
|
+
};
|
55
|
+
})();
|
56
|
+
|
57
|
+
function createScheduleActionMethods({
|
58
|
+
storageOperations,
|
59
|
+
getIdentity,
|
60
|
+
getTenant,
|
61
|
+
getLocale
|
62
|
+
}) {
|
63
|
+
const getTenantAndLocale = () => {
|
64
|
+
const tenant = getTenant().id;
|
65
|
+
const locale = getLocale().code;
|
66
|
+
return {
|
67
|
+
tenant,
|
68
|
+
locale
|
69
|
+
};
|
70
|
+
};
|
71
|
+
|
72
|
+
return {
|
73
|
+
async get(id) {
|
74
|
+
return storageOperations.get({
|
75
|
+
where: (0, _objectSpread2.default)({
|
76
|
+
id
|
77
|
+
}, getTenantAndLocale())
|
78
|
+
});
|
79
|
+
},
|
80
|
+
|
81
|
+
async list(params) {
|
82
|
+
return storageOperations.list((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
83
|
+
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.where), getTenantAndLocale())
|
84
|
+
}));
|
85
|
+
},
|
86
|
+
|
87
|
+
async create(input) {
|
88
|
+
const createDataModel = new CreateDataModel().populate(input);
|
89
|
+
await createDataModel.validate();
|
90
|
+
const id = (0, _mdbid.default)();
|
91
|
+
const identity = getIdentity();
|
92
|
+
const data = await createDataModel.toJSON();
|
93
|
+
const scheduleAction = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getTenantAndLocale()), {}, {
|
94
|
+
data,
|
95
|
+
id,
|
96
|
+
createdOn: new Date().toISOString(),
|
97
|
+
savedOn: new Date().toISOString(),
|
98
|
+
createdBy: {
|
99
|
+
id: identity.id,
|
100
|
+
type: identity.type,
|
101
|
+
displayName: identity.displayName
|
102
|
+
}
|
103
|
+
});
|
104
|
+
return await storageOperations.create({
|
105
|
+
item: scheduleAction,
|
106
|
+
input
|
107
|
+
});
|
108
|
+
},
|
109
|
+
|
110
|
+
async update(id, data) {
|
111
|
+
const updateDataModel = new CreateDataModel().populate(data);
|
112
|
+
await updateDataModel.validate();
|
113
|
+
const original = await this.get(id);
|
114
|
+
|
115
|
+
if (!original) {
|
116
|
+
throw new Error("Not found!");
|
117
|
+
}
|
118
|
+
|
119
|
+
return await storageOperations.update({
|
120
|
+
item: original,
|
121
|
+
input: data
|
122
|
+
});
|
123
|
+
},
|
124
|
+
|
125
|
+
async delete(id) {
|
126
|
+
await storageOperations.delete((0, _objectSpread2.default)({
|
127
|
+
id
|
128
|
+
}, getTenantAndLocale()));
|
129
|
+
return true;
|
130
|
+
},
|
131
|
+
|
132
|
+
async getCurrentTask() {
|
133
|
+
return await storageOperations.getCurrentTask({
|
134
|
+
where: (0, _objectSpread2.default)({}, getTenantAndLocale())
|
135
|
+
});
|
136
|
+
},
|
137
|
+
|
138
|
+
async updateCurrentTask(item) {
|
139
|
+
return await storageOperations.updateCurrentTask({
|
140
|
+
item
|
141
|
+
});
|
142
|
+
},
|
143
|
+
|
144
|
+
async deleteCurrentTask() {
|
145
|
+
return await storageOperations.deleteCurrentTask((0, _objectSpread2.default)({}, getTenantAndLocale()));
|
146
|
+
}
|
147
|
+
|
148
|
+
};
|
149
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["CreateDataModel","withFields","instance","datetime","string","validation","create","type","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","value","Error","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","input","createDataModel","populate","validate","mdbid","identity","data","toJSON","scheduleAction","createdOn","Date","toISOString","savedOn","createdBy","displayName","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport {\n ApwContentTypes,\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n ApwScheduleActionTypes,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\n\nconst CreateDataModel = withFields((instance: any) => {\n return {\n datetime: string({\n validation: validation.create(`required`)\n }),\n type: string({\n validation: validation.create(\n `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`\n )\n }),\n action: string({\n validation: validation.create(\n `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`\n )\n }),\n entryId: string({\n validation: validation.create(`required`)\n }),\n modelId: string({\n validation: (value: string) => {\n if (instance.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!value) {\n return true;\n }\n throw new Error(\n `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\n );\n }\n })\n };\n})();\n\ninterface GetTenantAndLocaleResult {\n tenant: string;\n locale: string;\n}\n\nexport function createScheduleActionMethods({\n storageOperations,\n getIdentity,\n getTenant,\n getLocale\n}: CreateScheduleActionParams): ApwScheduleActionCrud {\n const getTenantAndLocale = (): GetTenantAndLocaleResult => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n return {\n tenant,\n locale\n };\n };\n return {\n async get(id) {\n return storageOperations.get({\n where: {\n id,\n ...getTenantAndLocale()\n }\n });\n },\n async list(params) {\n return storageOperations.list({\n ...params,\n where: {\n ...params.where,\n ...getTenantAndLocale()\n }\n });\n },\n async create(input) {\n const createDataModel = new CreateDataModel().populate(input);\n\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = getIdentity();\n\n const data: ApwScheduleActionData = await createDataModel.toJSON();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, data) {\n const updateDataModel = new CreateDataModel().populate(data);\n\n await updateDataModel.validate();\n\n const original = await this.get(id);\n\n if (!original) {\n throw new Error(\"Not found!\");\n }\n\n return await storageOperations.update({ item: original, input: data });\n },\n async delete(id: string) {\n await storageOperations.delete({ id, ...getTenantAndLocale() });\n\n return true;\n },\n async getCurrentTask() {\n return await storageOperations.getCurrentTask({ where: { ...getTenantAndLocale() } });\n },\n async updateCurrentTask(item) {\n return await storageOperations.updateCurrentTask({ item });\n },\n async deleteCurrentTask() {\n return await storageOperations.deleteCurrentTask({ ...getTenantAndLocale() });\n }\n };\n}\n"],"mappings":";;;;;;;;;;;AAIA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAYA,MAAMA,eAAe,GAAG,IAAAC,kBAAA,EAAYC,QAAD,IAAmB;EAClD,OAAO;IACHC,QAAQ,EAAE,IAAAC,cAAA,EAAO;MACbC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAmB,UAAnB;IADC,CAAP,CADP;IAIHC,IAAI,EAAE,I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AAIjC,KAAJ,CAAU,YAAV,CAAN;MACH;;MAED,OAAO,MAAME,iBAAiB,CAAC6B,MAAlB,CAAyB;QAAED,IAAI,EAAEG,QAAR;QAAkBlB,KAAK,EAAEM;MAAzB,CAAzB,CAAb;IACH,CA1DE;;IA2DH,MAAMa,MAAN,CAAa1B,EAAb,EAAyB;MACrB,MAAMN,iBAAiB,CAACgC,MAAlB;QAA2B1B;MAA3B,GAAkCF,kBAAkB,EAApD,EAAN;MAEA,OAAO,IAAP;IACH,CA/DE;;IAgEH,MAAM6B,cAAN,GAAuB;MACnB,OAAO,MAAMjC,iBAAiB,CAACiC,cAAlB,CAAiC;QAAEvB,KAAK,kCAAON,kBAAkB,EAAzB;MAAP,CAAjC,CAAb;IACH,CAlEE;;IAmEH,MAAM8B,iBAAN,CAAwBN,IAAxB,EAA8B;MAC1B,OAAO,MAAM5B,iBAAiB,CAACkC,iBAAlB,CAAoC;QAAEN;MAAF,CAApC,CAAb;IACH,CArEE;;IAsEH,MAAMO,iBAAN,GAA0B;MACtB,OAAO,MAAMnC,iBAAiB,CAACmC,iBAAlB,iCAAyC/B,kBAAkB,EAA3D,EAAb;IACH;;EAxEE,CAAP;AA0EH"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ApwScheduleActionStorageOperations } from "../../types";
|
2
|
+
import { ContextPlugin } from "@webiny/api";
|
3
|
+
export interface HandlerArgs {
|
4
|
+
datetime: string;
|
5
|
+
tenant: string;
|
6
|
+
locale: string;
|
7
|
+
futureDatetime?: string;
|
8
|
+
}
|
9
|
+
interface Configuration {
|
10
|
+
storageOperations: ApwScheduleActionStorageOperations;
|
11
|
+
}
|
12
|
+
export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler").EventPlugin<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
|
13
|
+
export {};
|
@@ -0,0 +1,172 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.executeActionHandlerPlugins = void 0;
|
7
|
+
|
8
|
+
var _utils = require("../utils");
|
9
|
+
|
10
|
+
var _api = require("@webiny/api");
|
11
|
+
|
12
|
+
var _PageBuilderGraphQL = require("./plugins/PageBuilderGraphQL");
|
13
|
+
|
14
|
+
var _HeadlessCMSGraphQL = require("./plugins/HeadlessCMSGraphQL");
|
15
|
+
|
16
|
+
var _ApplicationGraphQL = require("./plugins/ApplicationGraphQL");
|
17
|
+
|
18
|
+
var _handler = require("@webiny/handler");
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Handler that execute the provided action(s) for the schedule action workflow.
|
22
|
+
*/
|
23
|
+
const createExecuteActionLambda = params => {
|
24
|
+
const {
|
25
|
+
storageOperations
|
26
|
+
} = params;
|
27
|
+
return (0, _handler.createEvent)(async ({
|
28
|
+
payload,
|
29
|
+
context
|
30
|
+
}) => {
|
31
|
+
const log = console.log;
|
32
|
+
const applicationGraphQLPlugins = context.plugins.byType(_ApplicationGraphQL.ApplicationGraphQL.type);
|
33
|
+
|
34
|
+
if (applicationGraphQLPlugins.length === 0) {
|
35
|
+
console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
const applicationGraphQLPluginCache = {};
|
40
|
+
|
41
|
+
const getApplicationGraphQLPlugin = data => {
|
42
|
+
const {
|
43
|
+
type
|
44
|
+
} = data;
|
45
|
+
|
46
|
+
if (applicationGraphQLPluginCache[type]) {
|
47
|
+
return applicationGraphQLPluginCache[type];
|
48
|
+
}
|
49
|
+
|
50
|
+
for (const plugin of applicationGraphQLPlugins) {
|
51
|
+
if (!plugin.canUse(data)) {
|
52
|
+
continue;
|
53
|
+
}
|
54
|
+
|
55
|
+
applicationGraphQLPluginCache[type] = plugin;
|
56
|
+
return plugin;
|
57
|
+
}
|
58
|
+
|
59
|
+
return null;
|
60
|
+
};
|
61
|
+
|
62
|
+
try {
|
63
|
+
const apwSettings = await (0, _utils.getApwSettings)();
|
64
|
+
const {
|
65
|
+
futureDatetime: datetime,
|
66
|
+
locale,
|
67
|
+
tenant
|
68
|
+
} = payload;
|
69
|
+
/**
|
70
|
+
* If there is no datetime we bail out early.
|
71
|
+
*/
|
72
|
+
|
73
|
+
if (!datetime || typeof datetime !== "string") {
|
74
|
+
log(`Bailing out!!`);
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* Get tasks from the DB by datetime.
|
79
|
+
*/
|
80
|
+
|
81
|
+
|
82
|
+
const [items] = await storageOperations.list({
|
83
|
+
where: {
|
84
|
+
tenant,
|
85
|
+
locale,
|
86
|
+
datetime_startsWith: (0, _utils.getIsoStringTillMinutes)(datetime)
|
87
|
+
},
|
88
|
+
sort: ["datetime_ASC"],
|
89
|
+
limit: 1000
|
90
|
+
});
|
91
|
+
/**
|
92
|
+
* Execute all actions.
|
93
|
+
*/
|
94
|
+
|
95
|
+
if (!items || items.length === 0) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
|
99
|
+
log(`Found ${items.length} actions.`);
|
100
|
+
|
101
|
+
for (const item of items) {
|
102
|
+
log(`Performing mutation "${item.data.action}" on "${item.data.type}" at "${item.data.datetime}"`);
|
103
|
+
const plugin = getApplicationGraphQLPlugin(item.data);
|
104
|
+
|
105
|
+
if (!plugin) {
|
106
|
+
console.error(`There is no plugin to determine GraphQL endpoint and mutations for type "${item.data.type}".`);
|
107
|
+
console.log(JSON.stringify(item));
|
108
|
+
continue;
|
109
|
+
}
|
110
|
+
|
111
|
+
const name = plugin.getArn(apwSettings);
|
112
|
+
|
113
|
+
if (!name) {
|
114
|
+
console.error(`There is no FunctionName found for type "${item.data.type}".`);
|
115
|
+
console.log(JSON.stringify({
|
116
|
+
item,
|
117
|
+
settings: apwSettings
|
118
|
+
}));
|
119
|
+
continue;
|
120
|
+
}
|
121
|
+
|
122
|
+
const body = plugin.getGraphQLBody(item.data);
|
123
|
+
|
124
|
+
if (!body) {
|
125
|
+
console.error(`There is no GraphQL body defined, in the Plugin, for type "${item.data.type}".`);
|
126
|
+
console.log(JSON.stringify(item));
|
127
|
+
continue;
|
128
|
+
} // Perform the actual action call.
|
129
|
+
|
130
|
+
|
131
|
+
const response = await context.handlerClient.invoke({
|
132
|
+
name,
|
133
|
+
payload: {
|
134
|
+
httpMethod: "POST",
|
135
|
+
path: `/cms/manage/${locale}`,
|
136
|
+
headers: {
|
137
|
+
["content-type"]: "application/json",
|
138
|
+
Authorization: (0, _utils.encodeToken)({
|
139
|
+
id: item.id,
|
140
|
+
locale: item.locale,
|
141
|
+
tenant: item.tenant
|
142
|
+
}),
|
143
|
+
["x-tenant"]: tenant,
|
144
|
+
["x-i18n-locale"]: `default:${locale};content:${locale};`
|
145
|
+
},
|
146
|
+
body: JSON.stringify(body)
|
147
|
+
},
|
148
|
+
await: true
|
149
|
+
});
|
150
|
+
|
151
|
+
if (response !== null && response !== void 0 && response.body) {
|
152
|
+
console.log(JSON.stringify({
|
153
|
+
body: response.body
|
154
|
+
}, null, 2));
|
155
|
+
continue;
|
156
|
+
}
|
157
|
+
|
158
|
+
console.log(JSON.stringify({
|
159
|
+
response
|
160
|
+
}, null, 2)); // TODO: Maybe update the status like error in original item in DB.
|
161
|
+
}
|
162
|
+
} catch (e) {
|
163
|
+
log("[HANDLER_EXECUTE_ACTION] Error => ", e); // TODO: Maybe update the status like error in original item in DB.
|
164
|
+
}
|
165
|
+
});
|
166
|
+
};
|
167
|
+
|
168
|
+
const executeActionHandlerPlugins = config => [new _api.ContextPlugin(async context => {
|
169
|
+
context.plugins.register([new _PageBuilderGraphQL.PageBuilderGraphQL(), new _HeadlessCMSGraphQL.HeadlessCMSGraphQL()]);
|
170
|
+
}), (0, _utils.basePlugins)(), createExecuteActionLambda(config)];
|
171
|
+
|
172
|
+
exports.executeActionHandlerPlugins = executeActionHandlerPlugins;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: `/cms/manage/${locale}`,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAD,IAA2B;EACzD,MAAM;IAAEC;EAAF,IAAwBD,MAA9B;EAEA,OAAO,IAAAE,oBAAA,EAAyB,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IAC5D,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;IAEA,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAR,CAAgBC,MAAhB,CAC9BC,sCAAA,CAAmBC,IADW,CAAlC;;IAIA,IAAIJ,yBAAyB,CAACK,MAA1B,KAAqC,CAAzC,EAA4C;MACxCN,OAAO,CAACO,KAAR,CAAe,mEAAf;MACA;IACH;;IAED,MAAMC,6BAAiE,GAAG,EAA1E;;IAEA,MAAMC,2BAA2B,GAC7BC,IADgC,IAEJ;MAC5B,MAAM;QAAEL;MAAF,IAAWK,IAAjB;;MACA,IAAIF,6BAA6B,CAACH,IAAD,CAAjC,EAAyC;QACrC,OAAOG,6BAA6B,CAACH,IAAD,CAApC;MACH;;MACD,KAAK,MAAMM,MAAX,IAAqBV,yB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I,EAAEL,IAAI,CAACC,SAAL,CAAeI,IAAf;UAbD,CAFuC;UAiBhDW,KAAK,EAAE;QAjByC,CAA7B,CAAvB;;QAmBA,IAAIT,QAAJ,aAAIA,QAAJ,eAAIA,QAAQ,CAAEF,IAAd,EAAoB;UAChBjC,OAAO,CAACD,GAAR,CAAY6B,IAAI,CAACC,SAAL,CAAe;YAAEI,IAAI,EAAEE,QAAQ,CAACF;UAAjB,CAAf,EAAwC,IAAxC,EAA8C,CAA9C,CAAZ;UACA;QACH;;QACDjC,OAAO,CAACD,GAAR,CAAY6B,IAAI,CAACC,SAAL,CAAe;UAAEM;QAAF,CAAf,EAA6B,IAA7B,EAAmC,CAAnC,CAAZ,EA5DsB,CA8DtB;MACH;IACJ,CAhGD,CAgGE,OAAOU,CAAP,EAAU;MACR9C,GAAG,CAAC,oCAAD,EAAuC8C,CAAvC,CAAH,CADQ,CAER;IACH;EACJ,CAnIM,CAAP;AAoIH,CAvID;;AAyIO,MAAMC,2BAA2B,GAAIC,MAAD,IAA2B,CAClE,IAAIC,kBAAJ,CAAkB,MAAMlD,OAAN,IAAiB;EAC/BA,OAAO,CAACI,OAAR,CAAgB+C,QAAhB,CAAyB,CAAC,IAAIC,sCAAJ,EAAD,EAA2B,IAAIC,sCAAJ,EAA3B,CAAzB;AACH,CAFD,CADkE,EAIlE,IAAAC,kBAAA,GAJkE,EAKlE3D,yBAAyB,CAACsD,MAAD,CALyC,CAA/D"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
2
|
+
import { ApwScheduleActionData } from "../../../types";
|
3
|
+
import { ApwSettings } from "../../utils";
|
4
|
+
export interface ApplicationGraphQLBody<T = Record<string, any>> {
|
5
|
+
query: string;
|
6
|
+
variables: T;
|
7
|
+
}
|
8
|
+
export declare abstract class ApplicationGraphQL extends Plugin {
|
9
|
+
static readonly type: string;
|
10
|
+
abstract canUse(data: ApwScheduleActionData): boolean;
|
11
|
+
abstract getArn(settings: ApwSettings): string;
|
12
|
+
abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;
|
13
|
+
}
|
@@ -0,0 +1,17 @@
|
|
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.ApplicationGraphQL = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
13
|
+
|
14
|
+
class ApplicationGraphQL extends _Plugin.Plugin {}
|
15
|
+
|
16
|
+
exports.ApplicationGraphQL = ApplicationGraphQL;
|
17
|
+
(0, _defineProperty2.default)(ApplicationGraphQL, "type", "apw.scheduler.applicationGraphQL");
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAeA,kBAAf,SAA0CC,cAA1C,CAAiD;;;8BAAlCD,kB,UAC6B,kC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ApplicationGraphQL, ApplicationGraphQLBody } from "./ApplicationGraphQL";
|
2
|
+
import { ApwScheduleActionData } from "../../../types";
|
3
|
+
import { ApwSettings } from "../../utils";
|
4
|
+
export declare class HeadlessCMSGraphQL extends ApplicationGraphQL {
|
5
|
+
name: string;
|
6
|
+
canUse(data: ApwScheduleActionData): boolean;
|
7
|
+
getArn(settings: ApwSettings): string;
|
8
|
+
getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;
|
9
|
+
private getPublishBody;
|
10
|
+
private getUnpublishBody;
|
11
|
+
}
|