@webiny/api-apw 0.0.0-unstable.8c4d9f045a → 0.0.0-unstable.8feaff8c32
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 +30 -0
- package/ApwChangeRequestNotification.js.map +1 -0
- package/ApwCommentNotification.d.ts +27 -0
- package/ApwCommentNotification.js +30 -0
- package/ApwCommentNotification.js.map +1 -0
- package/ApwContentReviewNotification.d.ts +26 -0
- package/ApwContentReviewNotification.js +30 -0
- package/ApwContentReviewNotification.js.map +1 -0
- package/ApwContentUrlPlugin.d.ts +19 -0
- package/ApwContentUrlPlugin.js +30 -0
- package/ApwContentUrlPlugin.js.map +1 -0
- package/ContentApwSettingsPlugin.js +1 -6
- package/ContentApwSettingsPlugin.js.map +1 -1
- package/crud/createChangeRequestMethods.js +21 -25
- package/crud/createChangeRequestMethods.js.map +1 -1
- package/crud/createCommentMethods.js +21 -26
- package/crud/createCommentMethods.js.map +1 -1
- package/crud/createContentReviewMethods.js +89 -128
- package/crud/createContentReviewMethods.js.map +1 -1
- package/crud/createReviewerMethods.js +21 -26
- package/crud/createReviewerMethods.js.map +1 -1
- package/crud/createWorkflowMethods.d.ts +1 -1
- package/crud/createWorkflowMethods.js +37 -28
- package/crud/createWorkflowMethods.js.map +1 -1
- package/crud/index.js +3 -32
- package/crud/index.js.map +1 -1
- package/crud/utils.js +4 -36
- package/crud/utils.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +6 -16
- package/index.js.map +1 -1
- package/package.json +40 -46
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +1 -16
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/cms/apwEntryPlugins.js +4 -16
- package/plugins/cms/apwEntryPlugins.js.map +1 -1
- package/plugins/cms/index.js +5 -10
- package/plugins/cms/index.js.map +1 -1
- package/plugins/cms/linkContentReviewToEntry.js +6 -23
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
- package/plugins/cms/linkWorkflowToEntry.js +14 -43
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
- package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
- package/plugins/cms/notifications/changeRequestNotification.js +31 -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 +31 -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 +31 -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 +53 -0
- package/plugins/cms/notifications/contentUrl.js.map +1 -0
- package/plugins/cms/triggerContentReview.js +6 -20
- package/plugins/cms/triggerContentReview.js.map +1 -1
- package/plugins/cms/updateContentReviewStatus.js +14 -36
- package/plugins/cms/updateContentReviewStatus.js.map +1 -1
- package/plugins/cms/utils.js +6 -55
- package/plugins/cms/utils.js.map +1 -1
- package/plugins/context.d.ts +0 -1
- package/plugins/context.js +3 -48
- package/plugins/context.js.map +1 -1
- package/plugins/graphql/changeRequest.gql.js +4 -11
- package/plugins/graphql/changeRequest.gql.js.map +1 -1
- package/plugins/graphql/comment.gql.js +4 -11
- package/plugins/graphql/comment.gql.js.map +1 -1
- package/plugins/graphql/contentReview.gql.js +10 -29
- package/plugins/graphql/contentReview.gql.js.map +1 -1
- package/plugins/graphql/reviewer.gql.js +6 -11
- package/plugins/graphql/reviewer.gql.js.map +1 -1
- package/plugins/graphql/workflow.gql.js +4 -11
- package/plugins/graphql/workflow.gql.js.map +1 -1
- package/plugins/graphql.js +4 -19
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/createReviewerFromIdentity.js +26 -15
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +2 -10
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +2 -9
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
- package/plugins/hooks/index.js +4 -12
- package/plugins/hooks/index.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +15 -25
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/plugins/hooks/initializeNotifications.d.ts +2 -0
- package/plugins/hooks/initializeNotifications.js +15 -0
- package/plugins/hooks/initializeNotifications.js.map +1 -0
- package/plugins/hooks/listContentReviews.d.ts +10 -0
- package/plugins/hooks/listContentReviews.js +56 -0
- package/plugins/hooks/listContentReviews.js.map +1 -0
- package/plugins/hooks/notifications/appUrl.d.ts +2 -0
- package/plugins/hooks/notifications/appUrl.js +18 -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 +111 -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 +27 -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 +122 -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 +27 -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 +94 -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 +26 -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 +24 -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 +21 -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 +21 -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 +21 -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 +45 -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 +41 -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 +41 -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 +41 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
- package/plugins/hooks/updatePendingChangeRequests.js +7 -19
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
- package/plugins/hooks/updateTotalComments.js +14 -27
- package/plugins/hooks/updateTotalComments.js.map +1 -1
- package/plugins/hooks/validateChangeRequest.js +27 -18
- package/plugins/hooks/validateChangeRequest.js.map +1 -1
- package/plugins/hooks/validateComment.js +13 -14
- package/plugins/hooks/validateComment.js.map +1 -1
- package/plugins/hooks/validateContentReview.js +2 -8
- package/plugins/hooks/validateContentReview.js.map +1 -1
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +1 -16
- 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 +5 -8
- package/plugins/pageBuilder/index.js.map +1 -1
- package/plugins/pageBuilder/linkContentReviewToPage.js +38 -42
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
- package/plugins/pageBuilder/linkWorkflowToPage.js +14 -32
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +31 -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 +31 -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 +31 -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 +47 -0
- package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
- package/plugins/pageBuilder/triggerContentReview.js +3 -14
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
- package/plugins/pageBuilder/updateContentReviewStatus.js +10 -26
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
- package/plugins/pageBuilder/utils.js +2 -36
- package/plugins/pageBuilder/utils.js.map +1 -1
- package/plugins/utils.d.ts +1 -1
- package/plugins/utils.js +4 -57
- package/plugins/utils.js.map +1 -1
- package/scheduler/createScheduleActionMethods.js +15 -36
- package/scheduler/createScheduleActionMethods.js.map +1 -1
- package/scheduler/handlers/executeAction/index.d.ts +1 -1
- package/scheduler/handlers/executeAction/index.js +45 -39
- package/scheduler/handlers/executeAction/index.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +15 -6
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +8 -24
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +8 -87
- 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.js +21 -38
- package/scheduler/handlers/scheduleAction/index.js.map +1 -1
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +9 -32
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
- package/scheduler/handlers/utils.d.ts +0 -1
- package/scheduler/handlers/utils.js +4 -42
- 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 +12 -23
- package/scheduler/types.js.map +1 -1
- package/storageOperations/changeRequestStorageOperations.js +22 -45
- package/storageOperations/changeRequestStorageOperations.js.map +1 -1
- package/storageOperations/commentStorageOperations.js +25 -50
- package/storageOperations/commentStorageOperations.js.map +1 -1
- package/storageOperations/contentReviewStorageOperations.js +22 -43
- package/storageOperations/contentReviewStorageOperations.js.map +1 -1
- package/storageOperations/index.js +5 -23
- 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 +5 -17
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
- package/storageOperations/models/contentReview.model.js +6 -31
- package/storageOperations/models/contentReview.model.js.map +1 -1
- package/storageOperations/models/index.js +3 -29
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/models/reviewer.model.js +17 -9
- package/storageOperations/models/reviewer.model.js.map +1 -1
- package/storageOperations/models/utils.js +3 -6
- 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 +22 -40
- package/storageOperations/reviewerStorageOperations.js.map +1 -1
- package/storageOperations/workflowStorageOperations.js +25 -48
- package/storageOperations/workflowStorageOperations.js.map +1 -1
- package/types.d.ts +104 -88
- package/types.js +124 -42
- package/types.js.map +1 -1
- package/utils/contentApwSettingsPlugin.js +0 -6
- package/utils/contentApwSettingsPlugin.js.map +1 -1
- package/utils/errors.js +1 -18
- package/utils/errors.js.map +1 -1
- package/utils/fieldResolver.js +5 -21
- package/utils/fieldResolver.js.map +1 -1
- package/utils/resolve.js +0 -3
- package/utils/resolve.js.map +1 -1
@@ -1,96 +1,26 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.PageBuilderGraphQL = void 0;
|
9
|
-
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
12
9
|
var _ApplicationGraphQL = require("./ApplicationGraphQL");
|
13
|
-
|
14
10
|
var _types = require("../../../types");
|
15
|
-
|
16
|
-
const PB_PAGE_DATA_FIELD =
|
17
|
-
/* GraphQL */
|
18
|
-
`
|
11
|
+
const PB_PAGE_DATA_FIELD = /* GraphQL */`
|
19
12
|
{
|
20
13
|
id
|
21
|
-
pid
|
22
|
-
editor
|
23
|
-
category {
|
24
|
-
slug
|
25
|
-
}
|
26
|
-
version
|
27
|
-
title
|
28
|
-
path
|
29
|
-
url
|
30
|
-
content
|
31
|
-
savedOn
|
32
|
-
status
|
33
|
-
locked
|
34
|
-
publishedOn
|
35
|
-
locked
|
36
|
-
revisions {
|
37
|
-
id
|
38
|
-
status
|
39
|
-
locked
|
40
|
-
version
|
41
|
-
}
|
42
|
-
settings {
|
43
|
-
general {
|
44
|
-
snippet
|
45
|
-
tags
|
46
|
-
layout
|
47
|
-
image {
|
48
|
-
id
|
49
|
-
src
|
50
|
-
}
|
51
|
-
}
|
52
|
-
social {
|
53
|
-
meta {
|
54
|
-
property
|
55
|
-
content
|
56
|
-
}
|
57
|
-
title
|
58
|
-
description
|
59
|
-
image {
|
60
|
-
id
|
61
|
-
src
|
62
|
-
}
|
63
|
-
}
|
64
|
-
seo {
|
65
|
-
title
|
66
|
-
description
|
67
|
-
meta {
|
68
|
-
name
|
69
|
-
content
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
createdFrom
|
74
|
-
createdOn
|
75
|
-
createdBy {
|
76
|
-
id
|
77
|
-
displayName
|
78
|
-
type
|
79
|
-
}
|
80
14
|
}
|
81
15
|
`;
|
82
|
-
const ERROR_FIELD =
|
83
|
-
/* GraphQL */
|
84
|
-
`
|
16
|
+
const ERROR_FIELD = /* GraphQL */`
|
85
17
|
{
|
86
18
|
code
|
87
19
|
data
|
88
20
|
message
|
89
21
|
}
|
90
22
|
`;
|
91
|
-
const PUBLISH_MUTATION =
|
92
|
-
/* GraphQL */
|
93
|
-
`
|
23
|
+
const PUBLISH_MUTATION = /* GraphQL */`
|
94
24
|
mutation PublishPage($id: ID!) {
|
95
25
|
pageBuilder {
|
96
26
|
publishPage(id: $id) {
|
@@ -100,9 +30,7 @@ const PUBLISH_MUTATION =
|
|
100
30
|
}
|
101
31
|
}
|
102
32
|
`;
|
103
|
-
const UNPUBLISH_MUTATION =
|
104
|
-
/* GraphQL */
|
105
|
-
`
|
33
|
+
const UNPUBLISH_MUTATION = /* GraphQL */`
|
106
34
|
mutation UnpublishPage($id: ID!) {
|
107
35
|
pageBuilder {
|
108
36
|
unpublishPage(id: $id) {
|
@@ -112,34 +40,30 @@ const UNPUBLISH_MUTATION =
|
|
112
40
|
}
|
113
41
|
}
|
114
42
|
`;
|
115
|
-
|
116
43
|
class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
117
44
|
constructor(...args) {
|
118
45
|
super(...args);
|
119
46
|
(0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.pageBuilder");
|
120
47
|
}
|
121
|
-
|
122
48
|
canUse(data) {
|
123
49
|
return data.type === _types.ApwContentTypes.PAGE;
|
124
50
|
}
|
125
|
-
|
51
|
+
getUrl() {
|
52
|
+
return `/graphql`;
|
53
|
+
}
|
126
54
|
getArn(settings) {
|
127
55
|
return settings.mainGraphqlFunctionArn;
|
128
56
|
}
|
129
|
-
|
130
57
|
getGraphQLBody(data) {
|
131
58
|
switch (data.action) {
|
132
59
|
case _types.ApwScheduleActionTypes.PUBLISH:
|
133
60
|
return this.getPublishBody(data);
|
134
|
-
|
135
61
|
case _types.ApwScheduleActionTypes.UNPUBLISH:
|
136
62
|
return this.getUnpublishBody(data);
|
137
|
-
|
138
63
|
default:
|
139
64
|
return null;
|
140
65
|
}
|
141
66
|
}
|
142
|
-
|
143
67
|
getPublishBody(data) {
|
144
68
|
return {
|
145
69
|
query: PUBLISH_MUTATION,
|
@@ -148,7 +72,6 @@ class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
|
148
72
|
}
|
149
73
|
};
|
150
74
|
}
|
151
|
-
|
152
75
|
getUnpublishBody(data) {
|
153
76
|
return {
|
154
77
|
query: UNPUBLISH_MUTATION,
|
@@ -157,7 +80,5 @@ class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
|
157
80
|
}
|
158
81
|
};
|
159
82
|
}
|
160
|
-
|
161
83
|
}
|
162
|
-
|
163
84
|
exports.PageBuilderGraphQL = PageBuilderGraphQL;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["PB_PAGE_DATA_FIELD","ERROR_FIELD","PUBLISH_MUTATION","UNPUBLISH_MUTATION","PageBuilderGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","PAGE","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","query","variables","id","entryId"],"sources":["PageBuilderGraphQL.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"names":["_ApplicationGraphQL","require","_types","PB_PAGE_DATA_FIELD","ERROR_FIELD","PUBLISH_MUTATION","UNPUBLISH_MUTATION","PageBuilderGraphQL","ApplicationGraphQL","constructor","args","_defineProperty2","default","canUse","data","type","ApwContentTypes","PAGE","getUrl","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","query","variables","id","entryId","exports"],"sources":["PageBuilderGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst PB_PAGE_DATA_FIELD = /* GraphQL */ `\n {\n id\n }\n`;\n\nconst ERROR_FIELD = /* GraphQL */ `\n {\n code\n data\n message\n }\n`;\n\nconst PUBLISH_MUTATION = /* GraphQL */ `\n mutation PublishPage($id: ID!) {\n pageBuilder {\n publishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\nconst UNPUBLISH_MUTATION = /* GraphQL */ `\n mutation UnpublishPage($id: ID!) {\n pageBuilder {\n unpublishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\ninterface ApplicationGraphQLBodyVariables {\n id: string;\n}\n\nexport class PageBuilderGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.PAGE;\n }\n\n public override getUrl(): string {\n return `/graphql`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: PUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: UNPUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AAGA,MAAME,kBAAkB,GAAG,aAAe;AAC1C;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAG,aAAe;AACnC;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,gBAAgB,GAAG,aAAe;AACxC;AACA;AACA;AACA,uBAAuBF,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CAAC;AAED,MAAME,kBAAkB,GAAG,aAAe;AAC1C;AACA;AACA;AACA,uBAAuBH,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CAAC;AAMM,MAAMG,kBAAkB,SAASC,sCAAkB,CAAC;EAAAC,YAAA,GAAAC,IAAA;IAAA,SAAAA,IAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,gBAChC,8CAA8C;EAAA;EAErDC,MAAMA,CAACC,IAA2B,EAAW;IACzD,OAAOA,IAAI,CAACC,IAAI,KAAKC,sBAAe,CAACC,IAAI;EAC7C;EAEgBC,MAAMA,CAAA,EAAW;IAC7B,OAAQ,UAAS;EACrB;EAEgBC,MAAMA,CAACC,QAAqB,EAAU;IAClD,OAAOA,QAAQ,CAACC,sBAAsB;EAC1C;EAEgBC,cAAcA,CAACR,IAA2B,EAAiC;IACvF,QAAQA,IAAI,CAACS,MAAM;MACf,KAAKC,6BAAsB,CAACC,OAAO;QAC/B,OAAO,IAAI,CAACC,cAAc,CAACZ,IAAI,CAAC;MACpC,KAAKU,6BAAsB,CAACG,SAAS;QACjC,OAAO,IAAI,CAACC,gBAAgB,CAACd,IAAI,CAAC;MACtC;QACI,OAAO,IAAI;IACnB;EACJ;EAEQY,cAAcA,CAClBZ,IAA2B,EAC4B;IACvD,OAAO;MACHe,KAAK,EAAExB,gBAAgB;MACvByB,SAAS,EAAE;QACPC,EAAE,EAAEjB,IAAI,CAACkB;MACb;IACJ,CAAC;EACL;EAEQJ,gBAAgBA,CACpBd,IAA2B,EAC4B;IACvD,OAAO;MACHe,KAAK,EAAEvB,kBAAkB;MACzBwB,SAAS,EAAE;QACPC,EAAE,EAAEjB,IAAI,CAACkB;MACb;IACJ,CAAC;EACL;AACJ;AAACC,OAAA,CAAA1B,kBAAA,GAAAA,kBAAA"}
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createCustomAuth = void 0;
|
7
|
-
|
8
7
|
var _api = require("@webiny/api");
|
9
|
-
|
10
8
|
var _utils = require("../utils");
|
11
|
-
|
12
9
|
const createCustomAuth = ({
|
13
10
|
storageOperations
|
14
11
|
}) => {
|
@@ -20,7 +17,6 @@ const createCustomAuth = ({
|
|
20
17
|
if (!token.startsWith(_utils.TOKEN_PREFIX)) {
|
21
18
|
return null;
|
22
19
|
}
|
23
|
-
|
24
20
|
const {
|
25
21
|
id,
|
26
22
|
tenant,
|
@@ -29,15 +25,12 @@ const createCustomAuth = ({
|
|
29
25
|
/**
|
30
26
|
* No point in going further if any piece of information is missing.
|
31
27
|
*/
|
32
|
-
|
33
28
|
if (!id || !tenant || !locale) {
|
34
29
|
return null;
|
35
30
|
}
|
36
31
|
/**
|
37
32
|
* We must verify that action we are trying to execute actually exists.
|
38
33
|
*/
|
39
|
-
|
40
|
-
|
41
34
|
const item = await storageOperations.get({
|
42
35
|
where: {
|
43
36
|
id,
|
@@ -45,11 +38,9 @@ const createCustomAuth = ({
|
|
45
38
|
locale
|
46
39
|
}
|
47
40
|
});
|
48
|
-
|
49
41
|
if (!item) {
|
50
42
|
return null;
|
51
43
|
}
|
52
|
-
|
53
44
|
hasApwToken = true;
|
54
45
|
return item.createdBy;
|
55
46
|
});
|
@@ -57,12 +48,10 @@ const createCustomAuth = ({
|
|
57
48
|
if (!hasApwToken) {
|
58
49
|
return null;
|
59
50
|
}
|
60
|
-
|
61
51
|
return [{
|
62
52
|
name: "*"
|
63
53
|
}];
|
64
54
|
});
|
65
55
|
});
|
66
56
|
};
|
67
|
-
|
68
57
|
exports.createCustomAuth = createCustomAuth;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createCustomAuth","storageOperations","ContextPlugin","security","hasApwToken","addAuthenticator","token","startsWith","TOKEN_PREFIX","id","tenant","locale","decodeToken","item","get","where","createdBy","addAuthorizer","name"],"sources":["security.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { decodeToken, TOKEN_PREFIX } from \"~/scheduler/handlers/utils\";\nimport { ApwContext } from \"~/types\";\n\nexport const createCustomAuth = ({ storageOperations }: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(({ security }) => {\n let hasApwToken = false;\n\n security.addAuthenticator(async token => {\n if (!token.startsWith(TOKEN_PREFIX)) {\n return null;\n }\n\n const { id, tenant, locale } = decodeToken(token);\n /**\n * No point in going further if any piece of information is missing.\n */\n if (!id || !tenant || !locale) {\n return null;\n }\n /**\n * We must verify that action we are trying to execute actually exists.\n */\n const item = await storageOperations.get({\n where: {\n id,\n tenant,\n locale\n }\n });\n\n if (!item) {\n return null;\n }\n\n hasApwToken = true;\n\n return item.createdBy;\n });\n\n security.addAuthorizer(async () => {\n if (!hasApwToken) {\n return null;\n }\n return [{ name: \"*\" }];\n });\n });\n};\n"],"mappings":"
|
1
|
+
{"version":3,"names":["_api","require","_utils","createCustomAuth","storageOperations","ContextPlugin","security","hasApwToken","addAuthenticator","token","startsWith","TOKEN_PREFIX","id","tenant","locale","decodeToken","item","get","where","createdBy","addAuthorizer","name","exports"],"sources":["security.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { decodeToken, TOKEN_PREFIX } from \"~/scheduler/handlers/utils\";\nimport { ApwContext } from \"~/types\";\n\nexport const createCustomAuth = ({ storageOperations }: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(({ security }) => {\n let hasApwToken = false;\n\n security.addAuthenticator(async token => {\n if (!token.startsWith(TOKEN_PREFIX)) {\n return null;\n }\n\n const { id, tenant, locale } = decodeToken(token);\n /**\n * No point in going further if any piece of information is missing.\n */\n if (!id || !tenant || !locale) {\n return null;\n }\n /**\n * We must verify that action we are trying to execute actually exists.\n */\n const item = await storageOperations.get({\n where: {\n id,\n tenant,\n locale\n }\n });\n\n if (!item) {\n return null;\n }\n\n hasApwToken = true;\n\n return item.createdBy;\n });\n\n security.addAuthorizer(async () => {\n if (!hasApwToken) {\n return null;\n }\n return [{ name: \"*\" }];\n });\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAGO,MAAME,gBAAgB,GAAGA,CAAC;EAAEC;AAA0C,CAAC,KAAK;EAC/E,OAAO,IAAIC,kBAAa,CAAa,CAAC;IAAEC;EAAS,CAAC,KAAK;IACnD,IAAIC,WAAW,GAAG,KAAK;IAEvBD,QAAQ,CAACE,gBAAgB,CAAC,MAAMC,KAAK,IAAI;MACrC,IAAI,CAACA,KAAK,CAACC,UAAU,CAACC,mBAAY,CAAC,EAAE;QACjC,OAAO,IAAI;MACf;MAEA,MAAM;QAAEC,EAAE;QAAEC,MAAM;QAAEC;MAAO,CAAC,GAAG,IAAAC,kBAAW,EAACN,KAAK,CAAC;MACjD;AACZ;AACA;MACY,IAAI,CAACG,EAAE,IAAI,CAACC,MAAM,IAAI,CAACC,MAAM,EAAE;QAC3B,OAAO,IAAI;MACf;MACA;AACZ;AACA;MACY,MAAME,IAAI,GAAG,MAAMZ,iBAAiB,CAACa,GAAG,CAAC;QACrCC,KAAK,EAAE;UACHN,EAAE;UACFC,MAAM;UACNC;QACJ;MACJ,CAAC,CAAC;MAEF,IAAI,CAACE,IAAI,EAAE;QACP,OAAO,IAAI;MACf;MAEAT,WAAW,GAAG,IAAI;MAElB,OAAOS,IAAI,CAACG,SAAS;IACzB,CAAC,CAAC;IAEFb,QAAQ,CAACc,aAAa,CAAC,YAAY;MAC/B,IAAI,CAACb,WAAW,EAAE;QACd,OAAO,IAAI;MACf;MACA,OAAO,CAAC;QAAEc,IAAI,EAAE;MAAI,CAAC,CAAC;IAC1B,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAnB,gBAAA,GAAAA,gBAAA"}
|
@@ -1,36 +1,27 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.scheduleActionHandlerPlugins = exports.InvocationTypes = void 0;
|
9
|
-
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
12
9
|
var _utils = require("../utils");
|
13
|
-
|
14
10
|
var _scheduleAction = require("./scheduleAction.utils");
|
15
|
-
|
16
11
|
var _handlerAws = require("@webiny/handler-aws");
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
let InvocationTypes;
|
23
|
-
exports.InvocationTypes = InvocationTypes;
|
24
|
-
|
25
|
-
(function (InvocationTypes) {
|
12
|
+
/**
|
13
|
+
* This logic/file should be moved somewhere else as it is relying on AWS specific stuff.
|
14
|
+
*/
|
15
|
+
let InvocationTypes = /*#__PURE__*/function (InvocationTypes) {
|
26
16
|
InvocationTypes["SCHEDULED"] = "scheduled";
|
27
|
-
|
28
|
-
|
17
|
+
return InvocationTypes;
|
18
|
+
}({});
|
19
|
+
exports.InvocationTypes = InvocationTypes;
|
29
20
|
const log = console.log;
|
21
|
+
|
30
22
|
/**
|
31
23
|
* Handler that creates a cloudwatch event rule for the schedule action workflow.
|
32
24
|
*/
|
33
|
-
|
34
25
|
const createScheduleActionLambda = params => {
|
35
26
|
const {
|
36
27
|
cwClient: cloudWatchEventClient,
|
@@ -51,7 +42,6 @@ const createScheduleActionLambda = params => {
|
|
51
42
|
/**
|
52
43
|
* If invocationType is "scheduled", execute the action.
|
53
44
|
*/
|
54
|
-
|
55
45
|
if (invocationType === InvocationTypes.SCHEDULED) {
|
56
46
|
await (0, _scheduleAction.executeTask)({
|
57
47
|
args: payload,
|
@@ -60,21 +50,20 @@ const createScheduleActionLambda = params => {
|
|
60
50
|
storageOperations
|
61
51
|
});
|
62
52
|
}
|
53
|
+
|
63
54
|
/**
|
64
55
|
* Get current scheduled task from the DB.
|
65
56
|
*/
|
66
|
-
|
67
|
-
|
68
57
|
const currentTask = await storageOperations.getCurrentTask({
|
69
58
|
where: {
|
70
59
|
tenant,
|
71
60
|
locale
|
72
61
|
}
|
73
62
|
});
|
63
|
+
|
74
64
|
/**
|
75
65
|
* Get next task from the DB.
|
76
66
|
*/
|
77
|
-
|
78
67
|
const [[nextItem]] = await storageOperations.list({
|
79
68
|
where: {
|
80
69
|
tenant,
|
@@ -83,45 +72,38 @@ const createScheduleActionLambda = params => {
|
|
83
72
|
sort: ["datetime_ASC"],
|
84
73
|
limit: 1
|
85
74
|
});
|
86
|
-
|
87
75
|
if (!nextItem) {
|
88
76
|
log(`No item found.`);
|
89
77
|
return;
|
90
78
|
}
|
91
|
-
|
92
79
|
const nextTaskDatetime = nextItem.data.datetime;
|
93
80
|
const currentTaskDatetime = currentTask && currentTask.data.datetime;
|
94
|
-
|
95
81
|
if ((0, _utils.isDateTimeInNextCentury)(nextTaskDatetime)) {
|
96
82
|
log(`Already processed the task.`);
|
97
83
|
return;
|
98
84
|
}
|
99
|
-
|
100
85
|
if (!(0, _scheduleAction.shouldScheduleTask)(nextTaskDatetime, currentTaskDatetime)) {
|
101
86
|
log(`Already scheduled the task.`);
|
102
87
|
return;
|
103
88
|
}
|
104
|
-
|
105
89
|
const futureDatetime = (0, _utils.moveDateTimeToNextCentury)(nextItem.data.datetime);
|
106
90
|
/**
|
107
91
|
* Update "datetime" to a future date to mark it as scheduled.
|
108
92
|
*/
|
109
|
-
|
110
93
|
log(`Update task's datetime to `, futureDatetime);
|
111
94
|
await storageOperations.update({
|
112
|
-
item:
|
113
|
-
data:
|
95
|
+
item: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, nextItem), {}, {
|
96
|
+
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, nextItem.data), {}, {
|
114
97
|
datetime: futureDatetime
|
115
98
|
})
|
116
99
|
}),
|
117
|
-
input:
|
100
|
+
input: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, nextItem.data), {}, {
|
118
101
|
datetime: futureDatetime
|
119
102
|
})
|
120
103
|
});
|
121
104
|
/**
|
122
105
|
* Restore "datetime" of current task so that it can be schedule in next cycle.
|
123
106
|
*/
|
124
|
-
|
125
107
|
if (currentTaskDatetime && (0, _utils.shouldRestoreDatetime)({
|
126
108
|
invocationType,
|
127
109
|
datetime: currentTaskDatetime
|
@@ -136,8 +118,6 @@ const createScheduleActionLambda = params => {
|
|
136
118
|
/**
|
137
119
|
* Schedule Lambda
|
138
120
|
*/
|
139
|
-
|
140
|
-
|
141
121
|
log(`Schedule Lambda Execution...`);
|
142
122
|
await (0, _scheduleAction.scheduleLambdaExecution)({
|
143
123
|
cloudWatchEventClient,
|
@@ -150,16 +130,19 @@ const createScheduleActionLambda = params => {
|
|
150
130
|
/**
|
151
131
|
* Update current task.
|
152
132
|
*/
|
153
|
-
|
154
133
|
await storageOperations.updateCurrentTask({
|
155
134
|
item: nextItem
|
156
135
|
});
|
157
136
|
} catch (ex) {
|
158
|
-
|
137
|
+
console.error("[HANDLER_CREATE_RULE] => ", JSON.stringify({
|
138
|
+
message: ex.message,
|
139
|
+
code: ex.code,
|
140
|
+
data: ex.data
|
141
|
+
}));
|
142
|
+
// TODO: Handler error. Maybe save it into DB.
|
159
143
|
}
|
160
144
|
});
|
161
145
|
};
|
162
146
|
|
163
147
|
const scheduleActionHandlerPlugins = config => [(0, _utils.basePlugins)(), createScheduleActionLambda(config)];
|
164
|
-
|
165
148
|
exports.scheduleActionHandlerPlugins = scheduleActionHandlerPlugins;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["InvocationTypes","log","console","createScheduleActionLambda","params","cwClient","cloudWatchEventClient","storageOperations","handlers","createRawEventHandler","payload","context","lambdaContext","eventContext","locale","tenant","invocationType","SCHEDULED","executeTask","args","lambdaName","executeAction","handlerClient","currentTask","getCurrentTask","where","nextItem","list","sort","limit","nextTaskDatetime","data","datetime","currentTaskDatetime","isDateTimeInNextCentury","shouldScheduleTask","futureDatetime","moveDateTimeToNextCentury","update","item","input","shouldRestoreDatetime","restoreDateTime","task","scheduleLambdaExecution","invokedFunctionArn","updateCurrentTask","ex","scheduleActionHandlerPlugins","config","basePlugins"],"sources":["index.ts"],"sourcesContent":["/**\n * This logic/file should be moved somewhere else as it is relying on AWS specific stuff.\n */\nimport { ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport {\n isDateTimeInNextCentury,\n moveDateTimeToNextCentury,\n shouldRestoreDatetime,\n basePlugins\n} from \"~/scheduler/handlers/utils\";\nimport {\n executeTask,\n shouldScheduleTask,\n restoreDateTime,\n scheduleLambdaExecution\n} from \"./scheduleAction.utils\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n invocationType?: InvocationTypes;\n futureDatetime?: string;\n}\n\nexport interface Configuration {\n cwClient: any;\n storageOperations: ApwScheduleActionStorageOperations;\n handlers: {\n executeAction: string;\n };\n}\n\nconst log = console.log;\n\n/**\n * Handler that creates a cloudwatch event rule for the schedule action workflow.\n */\nconst createScheduleActionLambda = (params: Configuration) => {\n const { cwClient: cloudWatchEventClient, storageOperations, handlers } = params;\n\n return createRawEventHandler<HandlerArgs>(\n async ({ payload, context, lambdaContext: eventContext }) => {\n try {\n const { locale, tenant, invocationType } = payload;\n /**\n * If invocationType is \"scheduled\", execute the action.\n */\n if (invocationType === InvocationTypes.SCHEDULED) {\n await executeTask({\n args: payload,\n lambdaName: handlers.executeAction,\n handlerClient: context.handlerClient,\n storageOperations\n });\n }\n\n /**\n * Get current scheduled task from the DB.\n */\n const currentTask = await storageOperations.getCurrentTask({\n where: {\n tenant,\n locale\n }\n });\n\n /**\n * Get next task from the DB.\n */\n const [[nextItem]] = await storageOperations.list({\n where: {\n tenant,\n locale\n },\n sort: [\"datetime_ASC\"],\n limit: 1\n });\n\n if (!nextItem) {\n log(`No item found.`);\n return;\n }\n\n const nextTaskDatetime = nextItem.data.datetime;\n const currentTaskDatetime = currentTask && currentTask.data.datetime;\n\n if (isDateTimeInNextCentury(nextTaskDatetime)) {\n log(`Already processed the task.`);\n return;\n }\n\n if (!shouldScheduleTask(nextTaskDatetime, currentTaskDatetime)) {\n log(`Already scheduled the task.`);\n return;\n }\n\n const futureDatetime = moveDateTimeToNextCentury(nextItem.data.datetime);\n /**\n * Update \"datetime\" to a future date to mark it as scheduled.\n */\n log(`Update task's datetime to `, futureDatetime);\n await storageOperations.update({\n item: {\n ...nextItem,\n data: { ...nextItem.data, datetime: futureDatetime }\n },\n input: { ...nextItem.data, datetime: futureDatetime }\n });\n /**\n * Restore \"datetime\" of current task so that it can be schedule in next cycle.\n */\n if (\n currentTaskDatetime &&\n shouldRestoreDatetime({\n invocationType,\n datetime: currentTaskDatetime\n })\n ) {\n await restoreDateTime({\n tenant,\n locale,\n task: currentTask,\n storageOperations\n });\n }\n /**\n * Schedule Lambda\n */\n log(`Schedule Lambda Execution...`);\n await scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn: eventContext.invokedFunctionArn,\n datetime: nextItem.data.datetime,\n futureDatetime: futureDatetime,\n tenant,\n locale\n });\n /**\n * Update current task.\n */\n await storageOperations.updateCurrentTask({ item: nextItem });\n } catch (ex) {\n
|
1
|
+
{"version":3,"names":["_utils","require","_scheduleAction","_handlerAws","InvocationTypes","exports","log","console","createScheduleActionLambda","params","cwClient","cloudWatchEventClient","storageOperations","handlers","createRawEventHandler","payload","context","lambdaContext","eventContext","locale","tenant","invocationType","SCHEDULED","executeTask","args","lambdaName","executeAction","handlerClient","currentTask","getCurrentTask","where","nextItem","list","sort","limit","nextTaskDatetime","data","datetime","currentTaskDatetime","isDateTimeInNextCentury","shouldScheduleTask","futureDatetime","moveDateTimeToNextCentury","update","item","_objectSpread2","default","input","shouldRestoreDatetime","restoreDateTime","task","scheduleLambdaExecution","invokedFunctionArn","updateCurrentTask","ex","error","JSON","stringify","message","code","scheduleActionHandlerPlugins","config","basePlugins"],"sources":["index.ts"],"sourcesContent":["/**\n * This logic/file should be moved somewhere else as it is relying on AWS specific stuff.\n */\nimport { ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport {\n isDateTimeInNextCentury,\n moveDateTimeToNextCentury,\n shouldRestoreDatetime,\n basePlugins\n} from \"~/scheduler/handlers/utils\";\nimport {\n executeTask,\n shouldScheduleTask,\n restoreDateTime,\n scheduleLambdaExecution\n} from \"./scheduleAction.utils\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n invocationType?: InvocationTypes;\n futureDatetime?: string;\n}\n\nexport interface Configuration {\n cwClient: any;\n storageOperations: ApwScheduleActionStorageOperations;\n handlers: {\n executeAction: string;\n };\n}\n\nconst log = console.log;\n\n/**\n * Handler that creates a cloudwatch event rule for the schedule action workflow.\n */\nconst createScheduleActionLambda = (params: Configuration) => {\n const { cwClient: cloudWatchEventClient, storageOperations, handlers } = params;\n\n return createRawEventHandler<HandlerArgs>(\n async ({ payload, context, lambdaContext: eventContext }) => {\n try {\n const { locale, tenant, invocationType } = payload;\n /**\n * If invocationType is \"scheduled\", execute the action.\n */\n if (invocationType === InvocationTypes.SCHEDULED) {\n await executeTask({\n args: payload,\n lambdaName: handlers.executeAction,\n handlerClient: context.handlerClient,\n storageOperations\n });\n }\n\n /**\n * Get current scheduled task from the DB.\n */\n const currentTask = await storageOperations.getCurrentTask({\n where: {\n tenant,\n locale\n }\n });\n\n /**\n * Get next task from the DB.\n */\n const [[nextItem]] = await storageOperations.list({\n where: {\n tenant,\n locale\n },\n sort: [\"datetime_ASC\"],\n limit: 1\n });\n\n if (!nextItem) {\n log(`No item found.`);\n return;\n }\n\n const nextTaskDatetime = nextItem.data.datetime;\n const currentTaskDatetime = currentTask && currentTask.data.datetime;\n\n if (isDateTimeInNextCentury(nextTaskDatetime)) {\n log(`Already processed the task.`);\n return;\n }\n\n if (!shouldScheduleTask(nextTaskDatetime, currentTaskDatetime)) {\n log(`Already scheduled the task.`);\n return;\n }\n\n const futureDatetime = moveDateTimeToNextCentury(nextItem.data.datetime);\n /**\n * Update \"datetime\" to a future date to mark it as scheduled.\n */\n log(`Update task's datetime to `, futureDatetime);\n await storageOperations.update({\n item: {\n ...nextItem,\n data: { ...nextItem.data, datetime: futureDatetime }\n },\n input: { ...nextItem.data, datetime: futureDatetime }\n });\n /**\n * Restore \"datetime\" of current task so that it can be schedule in next cycle.\n */\n if (\n currentTaskDatetime &&\n shouldRestoreDatetime({\n invocationType,\n datetime: currentTaskDatetime\n })\n ) {\n await restoreDateTime({\n tenant,\n locale,\n task: currentTask,\n storageOperations\n });\n }\n /**\n * Schedule Lambda\n */\n log(`Schedule Lambda Execution...`);\n await scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn: eventContext.invokedFunctionArn,\n datetime: nextItem.data.datetime,\n futureDatetime: futureDatetime,\n tenant,\n locale\n });\n /**\n * Update current task.\n */\n await storageOperations.updateCurrentTask({ item: nextItem });\n } catch (ex) {\n console.error(\n \"[HANDLER_CREATE_RULE] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\n // TODO: Handler error. Maybe save it into DB.\n }\n }\n );\n};\n\nexport const scheduleActionHandlerPlugins = (config: Configuration) => [\n basePlugins(),\n createScheduleActionLambda(config)\n];\n"],"mappings":"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"}
|
@@ -1,28 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.restoreDateTime = exports.executeTask = void 0;
|
9
8
|
exports.scheduleLambdaExecution = scheduleLambdaExecution;
|
10
9
|
exports.shouldScheduleTask = void 0;
|
11
|
-
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
-
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
14
11
|
var _utils = require("../utils");
|
15
|
-
|
16
12
|
var _index = require("./index");
|
17
|
-
|
18
13
|
var _clientCloudwatchEvents = require("@aws-sdk/client-cloudwatch-events");
|
19
|
-
|
20
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
21
|
-
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
23
|
-
|
24
14
|
const log = console.log;
|
25
|
-
|
26
15
|
/**
|
27
16
|
* Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;
|
28
17
|
* in case of scheduling becoming the most frequently used feature.
|
@@ -43,7 +32,6 @@ async function scheduleLambdaExecution({
|
|
43
32
|
/**
|
44
33
|
* Remove the target
|
45
34
|
*/
|
46
|
-
|
47
35
|
const removeTargetsCommand = new _clientCloudwatchEvents.RemoveTargetsCommand({
|
48
36
|
Rule: eventRuleName,
|
49
37
|
Ids: [eventTargetId]
|
@@ -52,7 +40,6 @@ async function scheduleLambdaExecution({
|
|
52
40
|
/**
|
53
41
|
* Log error.
|
54
42
|
*/
|
55
|
-
|
56
43
|
if (typeof removeTargetsResponse.FailedEntryCount === "number" && removeTargetsResponse.FailedEntryCount !== 0) {
|
57
44
|
console.info("Failed in removing the targets!");
|
58
45
|
console.info(removeTargetsResponse.FailedEntries);
|
@@ -60,18 +47,16 @@ async function scheduleLambdaExecution({
|
|
60
47
|
/**
|
61
48
|
* Delete the Rule
|
62
49
|
*/
|
63
|
-
|
64
|
-
|
65
50
|
const deleteRuleCommand = new _clientCloudwatchEvents.DeleteRuleCommand({
|
66
51
|
Name: eventRuleName
|
67
52
|
});
|
68
53
|
await cloudWatchEventClient.send(deleteRuleCommand);
|
54
|
+
|
69
55
|
/**
|
70
56
|
* Create a new one.
|
71
57
|
* Min H D M DW Y
|
72
58
|
* 20 10 10 03 * 2022
|
73
59
|
*/
|
74
|
-
|
75
60
|
const cronExpression = (0, _utils.dateTimeToCronExpression)(datetime);
|
76
61
|
const ruleParams = {
|
77
62
|
Name: eventRuleName,
|
@@ -83,7 +68,6 @@ async function scheduleLambdaExecution({
|
|
83
68
|
/**
|
84
69
|
* Add lambda as target for the rule.
|
85
70
|
*/
|
86
|
-
|
87
71
|
await cloudWatchEventClient.send(new _clientCloudwatchEvents.PutTargetsCommand({
|
88
72
|
Rule: eventRuleName,
|
89
73
|
Targets: [{
|
@@ -99,13 +83,10 @@ async function scheduleLambdaExecution({
|
|
99
83
|
}]
|
100
84
|
}));
|
101
85
|
}
|
102
|
-
|
103
86
|
const shouldScheduleTask = (nextTaskDatetime, currentTaskDatetime) => {
|
104
87
|
return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;
|
105
88
|
};
|
106
|
-
|
107
89
|
exports.shouldScheduleTask = shouldScheduleTask;
|
108
|
-
|
109
90
|
const restoreDateTime = async ({
|
110
91
|
locale,
|
111
92
|
tenant,
|
@@ -120,24 +101,21 @@ const restoreDateTime = async ({
|
|
120
101
|
id: currentTask.id
|
121
102
|
}
|
122
103
|
});
|
123
|
-
|
124
104
|
if (item) {
|
125
105
|
const newDateTime = (0, _utils.moveDateTimeToCurrentCentury)(item.data.datetime);
|
126
106
|
await storageOperations.update({
|
127
|
-
item:
|
128
|
-
data:
|
107
|
+
item: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
108
|
+
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item.data), {}, {
|
129
109
|
datetime: newDateTime
|
130
110
|
})
|
131
111
|
}),
|
132
|
-
input:
|
112
|
+
input: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item.data), {}, {
|
133
113
|
datetime: newDateTime
|
134
114
|
})
|
135
115
|
});
|
136
116
|
}
|
137
117
|
};
|
138
|
-
|
139
118
|
exports.restoreDateTime = restoreDateTime;
|
140
|
-
|
141
119
|
const executeTask = async ({
|
142
120
|
args,
|
143
121
|
lambdaName,
|
@@ -145,7 +123,6 @@ const executeTask = async ({
|
|
145
123
|
storageOperations
|
146
124
|
}) => {
|
147
125
|
log(`Executing task at: `, new Date().toISOString());
|
148
|
-
|
149
126
|
if (typeof handlerClient.invoke === "function") {
|
150
127
|
await handlerClient.invoke({
|
151
128
|
name: lambdaName,
|
@@ -157,12 +134,13 @@ const executeTask = async ({
|
|
157
134
|
},
|
158
135
|
await: false
|
159
136
|
});
|
137
|
+
} else {
|
138
|
+
console.log(`context.handlerClient.invoke is not a function!`);
|
160
139
|
}
|
140
|
+
|
161
141
|
/**
|
162
142
|
* Delete current schedule Task. So that, we can schedule a new one later.
|
163
143
|
*/
|
164
|
-
|
165
|
-
|
166
144
|
try {
|
167
145
|
await storageOperations.deleteCurrentTask({
|
168
146
|
tenant: args.tenant,
|
@@ -172,5 +150,4 @@ const executeTask = async ({
|
|
172
150
|
console.error(e);
|
173
151
|
}
|
174
152
|
};
|
175
|
-
|
176
153
|
exports.executeTask = executeTask;
|