@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.
Files changed (316) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +40 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +40 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +40 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +40 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.d.ts +10 -0
  14. package/ContentApwSettingsPlugin.js +17 -0
  15. package/ContentApwSettingsPlugin.js.map +1 -0
  16. package/LICENSE +21 -0
  17. package/README.md +34 -0
  18. package/crud/createChangeRequestMethods.d.ts +2 -0
  19. package/crud/createChangeRequestMethods.js +98 -0
  20. package/crud/createChangeRequestMethods.js.map +1 -0
  21. package/crud/createCommentMethods.d.ts +2 -0
  22. package/crud/createCommentMethods.js +99 -0
  23. package/crud/createCommentMethods.js.map +1 -0
  24. package/crud/createContentReviewMethods.d.ts +10 -0
  25. package/crud/createContentReviewMethods.js +562 -0
  26. package/crud/createContentReviewMethods.js.map +1 -0
  27. package/crud/createReviewerMethods.d.ts +2 -0
  28. package/crud/createReviewerMethods.js +99 -0
  29. package/crud/createReviewerMethods.js.map +1 -0
  30. package/crud/createWorkflowMethods.d.ts +2 -0
  31. package/crud/createWorkflowMethods.js +118 -0
  32. package/crud/createWorkflowMethods.js.map +1 -0
  33. package/crud/index.d.ts +2 -0
  34. package/crud/index.js +96 -0
  35. package/crud/index.js.map +1 -0
  36. package/crud/utils.d.ts +21 -0
  37. package/crud/utils.js +138 -0
  38. package/crud/utils.js.map +1 -0
  39. package/index.d.ts +4 -0
  40. package/index.js +38 -0
  41. package/index.js.map +1 -0
  42. package/package.json +76 -0
  43. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +10 -0
  44. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +51 -0
  45. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -0
  46. package/plugins/cms/README.md +49 -0
  47. package/plugins/cms/apwEntryPlugins.d.ts +8 -0
  48. package/plugins/cms/apwEntryPlugins.js +46 -0
  49. package/plugins/cms/apwEntryPlugins.js.map +1 -0
  50. package/plugins/cms/index.d.ts +12 -0
  51. package/plugins/cms/index.js +45 -0
  52. package/plugins/cms/index.js.map +1 -0
  53. package/plugins/cms/linkContentReviewToEntry.d.ts +8 -0
  54. package/plugins/cms/linkContentReviewToEntry.js +108 -0
  55. package/plugins/cms/linkContentReviewToEntry.js.map +1 -0
  56. package/plugins/cms/linkWorkflowToEntry.d.ts +8 -0
  57. package/plugins/cms/linkWorkflowToEntry.js +166 -0
  58. package/plugins/cms/linkWorkflowToEntry.js.map +1 -0
  59. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  60. package/plugins/cms/notifications/changeRequestNotification.js +35 -0
  61. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  62. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  63. package/plugins/cms/notifications/commentNotification.js +35 -0
  64. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  65. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  66. package/plugins/cms/notifications/contentReviewNotification.js +35 -0
  67. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  68. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  69. package/plugins/cms/notifications/contentUrl.js +60 -0
  70. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  71. package/plugins/cms/triggerContentReview.d.ts +8 -0
  72. package/plugins/cms/triggerContentReview.js +59 -0
  73. package/plugins/cms/triggerContentReview.js.map +1 -0
  74. package/plugins/cms/updateContentReviewStatus.d.ts +10 -0
  75. package/plugins/cms/updateContentReviewStatus.js +97 -0
  76. package/plugins/cms/updateContentReviewStatus.js.map +1 -0
  77. package/plugins/cms/utils.d.ts +27 -0
  78. package/plugins/cms/utils.js +207 -0
  79. package/plugins/cms/utils.js.map +1 -0
  80. package/plugins/context.d.ts +5 -0
  81. package/plugins/context.js +146 -0
  82. package/plugins/context.js.map +1 -0
  83. package/plugins/graphql/changeRequest.gql.d.ts +4 -0
  84. package/plugins/graphql/changeRequest.gql.js +155 -0
  85. package/plugins/graphql/changeRequest.gql.js.map +1 -0
  86. package/plugins/graphql/comment.gql.d.ts +4 -0
  87. package/plugins/graphql/comment.gql.js +160 -0
  88. package/plugins/graphql/comment.gql.js.map +1 -0
  89. package/plugins/graphql/contentReview.gql.d.ts +4 -0
  90. package/plugins/graphql/contentReview.gql.js +382 -0
  91. package/plugins/graphql/contentReview.gql.js.map +1 -0
  92. package/plugins/graphql/reviewer.gql.d.ts +4 -0
  93. package/plugins/graphql/reviewer.gql.js +116 -0
  94. package/plugins/graphql/reviewer.gql.js.map +1 -0
  95. package/plugins/graphql/workflow.gql.d.ts +4 -0
  96. package/plugins/graphql/workflow.gql.js +205 -0
  97. package/plugins/graphql/workflow.gql.js.map +1 -0
  98. package/plugins/graphql.d.ts +4 -0
  99. package/plugins/graphql.js +95 -0
  100. package/plugins/graphql.js.map +1 -0
  101. package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
  102. package/plugins/hooks/createReviewerFromIdentity.js +82 -0
  103. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -0
  104. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
  105. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +67 -0
  106. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -0
  107. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
  108. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +59 -0
  109. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -0
  110. package/plugins/hooks/index.d.ts +3 -0
  111. package/plugins/hooks/index.js +74 -0
  112. package/plugins/hooks/index.js.map +1 -0
  113. package/plugins/hooks/initializeContentReviewSteps.d.ts +2 -0
  114. package/plugins/hooks/initializeContentReviewSteps.js +86 -0
  115. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -0
  116. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  117. package/plugins/hooks/initializeNotifications.js +20 -0
  118. package/plugins/hooks/initializeNotifications.js.map +1 -0
  119. package/plugins/hooks/listContentReviews.d.ts +10 -0
  120. package/plugins/hooks/listContentReviews.js +68 -0
  121. package/plugins/hooks/listContentReviews.js.map +1 -0
  122. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  123. package/plugins/hooks/notifications/appUrl.js +22 -0
  124. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  125. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  126. package/plugins/hooks/notifications/changeRequestAfterCreate.js +144 -0
  127. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  128. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  129. package/plugins/hooks/notifications/changeRequestUrl.js +31 -0
  130. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  131. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  132. package/plugins/hooks/notifications/commentAfterCreate.js +157 -0
  133. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  134. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  135. package/plugins/hooks/notifications/commentUrl.js +31 -0
  136. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  137. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  138. package/plugins/hooks/notifications/contentReviewAfterCreate.js +122 -0
  139. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  140. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  141. package/plugins/hooks/notifications/contentReviewUrl.js +30 -0
  142. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  143. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  144. package/plugins/hooks/notifications/contentUrl.js +29 -0
  145. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  146. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  147. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +25 -0
  148. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  149. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  150. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +25 -0
  151. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  152. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  153. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +25 -0
  154. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  155. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  156. package/plugins/hooks/notifications/reviewers.js +51 -0
  157. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  158. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  159. package/plugins/hooks/notifications/sendChangeRequestNotification.js +52 -0
  160. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  161. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  162. package/plugins/hooks/notifications/sendCommentNotification.js +52 -0
  163. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  164. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  165. package/plugins/hooks/notifications/sendContentReviewNotification.js +52 -0
  166. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  167. package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
  168. package/plugins/hooks/updatePendingChangeRequests.js +94 -0
  169. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -0
  170. package/plugins/hooks/updateTotalComments.d.ts +3 -0
  171. package/plugins/hooks/updateTotalComments.js +153 -0
  172. package/plugins/hooks/updateTotalComments.js.map +1 -0
  173. package/plugins/hooks/validateChangeRequest.d.ts +2 -0
  174. package/plugins/hooks/validateChangeRequest.js +89 -0
  175. package/plugins/hooks/validateChangeRequest.js.map +1 -0
  176. package/plugins/hooks/validateComment.d.ts +2 -0
  177. package/plugins/hooks/validateComment.js +57 -0
  178. package/plugins/hooks/validateComment.js.map +1 -0
  179. package/plugins/hooks/validateContentReview.d.ts +2 -0
  180. package/plugins/hooks/validateContentReview.js +38 -0
  181. package/plugins/hooks/validateContentReview.js.map +1 -0
  182. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +9 -0
  183. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +51 -0
  184. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -0
  185. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +3 -0
  186. package/plugins/pageBuilder/apwContentPagePlugins.js +30 -0
  187. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -0
  188. package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +3 -0
  189. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +25 -0
  190. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -0
  191. package/plugins/pageBuilder/index.d.ts +11 -0
  192. package/plugins/pageBuilder/index.js +53 -0
  193. package/plugins/pageBuilder/index.js.map +1 -0
  194. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +8 -0
  195. package/plugins/pageBuilder/linkContentReviewToPage.js +105 -0
  196. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -0
  197. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +8 -0
  198. package/plugins/pageBuilder/linkWorkflowToPage.js +194 -0
  199. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -0
  200. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  201. package/plugins/pageBuilder/notifications/changeRequestNotification.js +35 -0
  202. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  203. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  204. package/plugins/pageBuilder/notifications/commentNotification.js +35 -0
  205. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  206. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  207. package/plugins/pageBuilder/notifications/contentReviewNotification.js +35 -0
  208. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  209. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  210. package/plugins/pageBuilder/notifications/contentUrl.js +53 -0
  211. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  212. package/plugins/pageBuilder/triggerContentReview.d.ts +8 -0
  213. package/plugins/pageBuilder/triggerContentReview.js +50 -0
  214. package/plugins/pageBuilder/triggerContentReview.js.map +1 -0
  215. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +10 -0
  216. package/plugins/pageBuilder/updateContentReviewStatus.js +79 -0
  217. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -0
  218. package/plugins/pageBuilder/utils.d.ts +22 -0
  219. package/plugins/pageBuilder/utils.js +184 -0
  220. package/plugins/pageBuilder/utils.js.map +1 -0
  221. package/plugins/utils.d.ts +35 -0
  222. package/plugins/utils.js +187 -0
  223. package/plugins/utils.js.map +1 -0
  224. package/scheduler/createScheduleActionMethods.d.ts +2 -0
  225. package/scheduler/createScheduleActionMethods.js +149 -0
  226. package/scheduler/createScheduleActionMethods.js.map +1 -0
  227. package/scheduler/handlers/executeAction/index.d.ts +13 -0
  228. package/scheduler/handlers/executeAction/index.js +172 -0
  229. package/scheduler/handlers/executeAction/index.js.map +1 -0
  230. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +13 -0
  231. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +17 -0
  232. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -0
  233. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +11 -0
  234. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +126 -0
  235. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -0
  236. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +11 -0
  237. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +163 -0
  238. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -0
  239. package/scheduler/handlers/executeAction/security.d.ts +4 -0
  240. package/scheduler/handlers/executeAction/security.js +68 -0
  241. package/scheduler/handlers/executeAction/security.js.map +1 -0
  242. package/scheduler/handlers/scheduleAction/index.d.ts +22 -0
  243. package/scheduler/handlers/scheduleAction/index.js +164 -0
  244. package/scheduler/handlers/scheduleAction/index.js.map +1 -0
  245. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +24 -0
  246. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +172 -0
  247. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -0
  248. package/scheduler/handlers/utils.d.ts +33 -0
  249. package/scheduler/handlers/utils.js +168 -0
  250. package/scheduler/handlers/utils.js.map +1 -0
  251. package/scheduler/index.d.ts +2 -0
  252. package/scheduler/index.js +27 -0
  253. package/scheduler/index.js.map +1 -0
  254. package/scheduler/types.d.ts +171 -0
  255. package/scheduler/types.js +34 -0
  256. package/scheduler/types.js.map +1 -0
  257. package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
  258. package/storageOperations/changeRequestStorageOperations.js +122 -0
  259. package/storageOperations/changeRequestStorageOperations.js.map +1 -0
  260. package/storageOperations/commentStorageOperations.d.ts +3 -0
  261. package/storageOperations/commentStorageOperations.js +138 -0
  262. package/storageOperations/commentStorageOperations.js.map +1 -0
  263. package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
  264. package/storageOperations/contentReviewStorageOperations.js +93 -0
  265. package/storageOperations/contentReviewStorageOperations.js.map +1 -0
  266. package/storageOperations/index.d.ts +15 -0
  267. package/storageOperations/index.js +48 -0
  268. package/storageOperations/index.js.map +1 -0
  269. package/storageOperations/models/changeRequest.model.d.ts +3 -0
  270. package/storageOperations/models/changeRequest.model.js +59 -0
  271. package/storageOperations/models/changeRequest.model.js.map +1 -0
  272. package/storageOperations/models/comment.model.d.ts +7 -0
  273. package/storageOperations/models/comment.model.js +60 -0
  274. package/storageOperations/models/comment.model.js.map +1 -0
  275. package/storageOperations/models/contentModelPluginFactory.d.ts +15 -0
  276. package/storageOperations/models/contentModelPluginFactory.js +28 -0
  277. package/storageOperations/models/contentModelPluginFactory.js.map +1 -0
  278. package/storageOperations/models/contentReview.model.d.ts +7 -0
  279. package/storageOperations/models/contentReview.model.js +258 -0
  280. package/storageOperations/models/contentReview.model.js.map +1 -0
  281. package/storageOperations/models/index.d.ts +2 -0
  282. package/storageOperations/models/index.js +115 -0
  283. package/storageOperations/models/index.js.map +1 -0
  284. package/storageOperations/models/reviewer.model.d.ts +3 -0
  285. package/storageOperations/models/reviewer.model.js +71 -0
  286. package/storageOperations/models/reviewer.model.js.map +1 -0
  287. package/storageOperations/models/utils.d.ts +3 -0
  288. package/storageOperations/models/utils.js +37 -0
  289. package/storageOperations/models/utils.js.map +1 -0
  290. package/storageOperations/models/workflow.model.d.ts +12 -0
  291. package/storageOperations/models/workflow.model.js +208 -0
  292. package/storageOperations/models/workflow.model.js.map +1 -0
  293. package/storageOperations/reviewerStorageOperations.d.ts +3 -0
  294. package/storageOperations/reviewerStorageOperations.js +97 -0
  295. package/storageOperations/reviewerStorageOperations.js.map +1 -0
  296. package/storageOperations/types.d.ts +34 -0
  297. package/storageOperations/types.js +5 -0
  298. package/storageOperations/types.js.map +1 -0
  299. package/storageOperations/workflowStorageOperations.d.ts +3 -0
  300. package/storageOperations/workflowStorageOperations.js +111 -0
  301. package/storageOperations/workflowStorageOperations.js.map +1 -0
  302. package/types.d.ts +752 -0
  303. package/types.js +69 -0
  304. package/types.js.map +1 -0
  305. package/utils/contentApwSettingsPlugin.d.ts +9 -0
  306. package/utils/contentApwSettingsPlugin.js +26 -0
  307. package/utils/contentApwSettingsPlugin.js.map +1 -0
  308. package/utils/errors.d.ts +16 -0
  309. package/utils/errors.js +75 -0
  310. package/utils/errors.js.map +1 -0
  311. package/utils/fieldResolver.d.ts +16 -0
  312. package/utils/fieldResolver.js +54 -0
  313. package/utils/fieldResolver.js.map +1 -0
  314. package/utils/resolve.d.ts +3 -0
  315. package/utils/resolve.js +18 -0
  316. package/utils/resolve.js.map +1 -0
@@ -0,0 +1,172 @@
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.restoreDateTime = exports.executeTask = void 0;
9
+ exports.scheduleLambdaExecution = scheduleLambdaExecution;
10
+ exports.shouldScheduleTask = void 0;
11
+
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+
14
+ var _utils = require("../utils");
15
+
16
+ var _index = require("./index");
17
+
18
+ var _clientCloudwatchEvents = require("@aws-sdk/client-cloudwatch-events");
19
+
20
+ const log = console.log;
21
+
22
+ /**
23
+ * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;
24
+ * in case of scheduling becoming the most frequently used feature.
25
+ * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/
26
+ */
27
+ async function scheduleLambdaExecution({
28
+ cloudWatchEventClient,
29
+ invokedFunctionArn,
30
+ datetime,
31
+ futureDatetime,
32
+ tenant,
33
+ locale
34
+ }) {
35
+ const {
36
+ eventTargetId,
37
+ eventRuleName
38
+ } = await (0, _utils.getApwSettings)();
39
+ /**
40
+ * Remove the target
41
+ */
42
+
43
+ const removeTargetsCommand = new _clientCloudwatchEvents.RemoveTargetsCommand({
44
+ Rule: eventRuleName,
45
+ Ids: [eventTargetId]
46
+ });
47
+ const removeTargetsResponse = await cloudWatchEventClient.send(removeTargetsCommand);
48
+ /**
49
+ * Log error.
50
+ */
51
+
52
+ if (typeof removeTargetsResponse.FailedEntryCount === "number" && removeTargetsResponse.FailedEntryCount !== 0) {
53
+ console.info("Failed in removing the targets!");
54
+ console.info(removeTargetsResponse.FailedEntries);
55
+ }
56
+ /**
57
+ * Delete the Rule
58
+ */
59
+
60
+
61
+ const deleteRuleCommand = new _clientCloudwatchEvents.DeleteRuleCommand({
62
+ Name: eventRuleName
63
+ });
64
+ await cloudWatchEventClient.send(deleteRuleCommand);
65
+ /**
66
+ * Create a new one.
67
+ * Min H D M DW Y
68
+ * 20 10 10 03 * 2022
69
+ */
70
+
71
+ const cronExpression = (0, _utils.dateTimeToCronExpression)(datetime);
72
+ const ruleParams = {
73
+ Name: eventRuleName,
74
+ ScheduleExpression: `cron(${cronExpression})`,
75
+ State: "ENABLED",
76
+ Description: `Enable us to schedule an action in publishing workflow at a particular datetime`
77
+ };
78
+ await cloudWatchEventClient.send(new _clientCloudwatchEvents.PutRuleCommand(ruleParams));
79
+ /**
80
+ * Add lambda as target for the rule.
81
+ */
82
+
83
+ await cloudWatchEventClient.send(new _clientCloudwatchEvents.PutTargetsCommand({
84
+ Rule: eventRuleName,
85
+ Targets: [{
86
+ Arn: invokedFunctionArn,
87
+ Id: eventTargetId,
88
+ Input: JSON.stringify({
89
+ datetime: datetime,
90
+ tenant: tenant,
91
+ locale: locale,
92
+ invocationType: _index.InvocationTypes.SCHEDULED,
93
+ futureDatetime: futureDatetime
94
+ })
95
+ }]
96
+ }));
97
+ }
98
+
99
+ const shouldScheduleTask = (nextTaskDatetime, currentTaskDatetime) => {
100
+ return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;
101
+ };
102
+
103
+ exports.shouldScheduleTask = shouldScheduleTask;
104
+
105
+ const restoreDateTime = async ({
106
+ locale,
107
+ tenant,
108
+ task: currentTask,
109
+ storageOperations
110
+ }) => {
111
+ log(`Mark task "${currentTask.id}" as undone by restoring original "datetime".`);
112
+ const item = await storageOperations.get({
113
+ where: {
114
+ tenant,
115
+ locale,
116
+ id: currentTask.id
117
+ }
118
+ });
119
+
120
+ if (item) {
121
+ const newDateTime = (0, _utils.moveDateTimeToCurrentCentury)(item.data.datetime);
122
+ await storageOperations.update({
123
+ item: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
124
+ data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item.data), {}, {
125
+ datetime: newDateTime
126
+ })
127
+ }),
128
+ input: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item.data), {}, {
129
+ datetime: newDateTime
130
+ })
131
+ });
132
+ }
133
+ };
134
+
135
+ exports.restoreDateTime = restoreDateTime;
136
+
137
+ const executeTask = async ({
138
+ args,
139
+ lambdaName,
140
+ handlerClient,
141
+ storageOperations
142
+ }) => {
143
+ log(`Executing task at: `, new Date().toISOString());
144
+
145
+ if (typeof handlerClient.invoke === "function") {
146
+ await handlerClient.invoke({
147
+ name: lambdaName,
148
+ payload: {
149
+ futureDatetime: args.futureDatetime,
150
+ datetime: args.datetime,
151
+ tenant: args.tenant,
152
+ locale: args.locale
153
+ },
154
+ await: false
155
+ });
156
+ }
157
+ /**
158
+ * Delete current schedule Task. So that, we can schedule a new one later.
159
+ */
160
+
161
+
162
+ try {
163
+ await storageOperations.deleteCurrentTask({
164
+ tenant: args.tenant,
165
+ locale: args.locale
166
+ });
167
+ } catch (e) {
168
+ console.error(e);
169
+ }
170
+ };
171
+
172
+ exports.executeTask = executeTask;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["log","console","scheduleLambdaExecution","cloudWatchEventClient","invokedFunctionArn","datetime","futureDatetime","tenant","locale","eventTargetId","eventRuleName","getApwSettings","removeTargetsCommand","RemoveTargetsCommand","Rule","Ids","removeTargetsResponse","send","FailedEntryCount","info","FailedEntries","deleteRuleCommand","DeleteRuleCommand","Name","cronExpression","dateTimeToCronExpression","ruleParams","ScheduleExpression","State","Description","PutRuleCommand","PutTargetsCommand","Targets","Arn","Id","Input","JSON","stringify","invocationType","InvocationTypes","SCHEDULED","shouldScheduleTask","nextTaskDatetime","currentTaskDatetime","restoreDateTime","task","currentTask","storageOperations","id","item","get","where","newDateTime","moveDateTimeToCurrentCentury","data","update","input","executeTask","args","lambdaName","handlerClient","Date","toISOString","invoke","name","payload","await","deleteCurrentTask","e","error"],"sources":["scheduleAction.utils.ts"],"sourcesContent":["import { dateTimeToCronExpression, moveDateTimeToCurrentCentury } from \"~/scheduler/handlers/utils\";\nimport { ApwScheduleAction } from \"~/scheduler/types\";\nimport {\n HandlerArgs,\n InvocationTypes,\n Configuration\n} from \"~/scheduler/handlers/scheduleAction/index\";\nimport {\n DeleteRuleCommand,\n RemoveTargetsCommand,\n PutTargetsCommand,\n PutRuleCommand\n} from \"@aws-sdk/client-cloudwatch-events\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst log = console.log;\n\ninterface ScheduleLambdaExecutionParams extends Omit<HandlerArgs, \"invocationType\"> {\n cloudWatchEventClient: any;\n invokedFunctionArn: string;\n}\n\n/**\n * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;\n * in case of scheduling becoming the most frequently used feature.\n * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/\n */\nexport async function scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn,\n datetime,\n futureDatetime,\n tenant,\n locale\n}: ScheduleLambdaExecutionParams) {\n const { eventTargetId, eventRuleName } = await getApwSettings();\n /**\n * Remove the target\n */\n const removeTargetsCommand = new RemoveTargetsCommand({\n Rule: eventRuleName,\n Ids: [eventTargetId]\n });\n const removeTargetsResponse = await cloudWatchEventClient.send(removeTargetsCommand);\n /**\n * Log error.\n */\n if (\n typeof removeTargetsResponse.FailedEntryCount === \"number\" &&\n removeTargetsResponse.FailedEntryCount !== 0\n ) {\n console.info(\"Failed in removing the targets!\");\n console.info(removeTargetsResponse.FailedEntries);\n }\n /**\n * Delete the Rule\n */\n const deleteRuleCommand = new DeleteRuleCommand({\n Name: eventRuleName\n });\n await cloudWatchEventClient.send(deleteRuleCommand);\n\n /**\n * Create a new one.\n * Min H D M DW Y\n * 20 10 10 03 * 2022\n */\n const cronExpression = dateTimeToCronExpression(datetime);\n\n const ruleParams = {\n Name: eventRuleName,\n ScheduleExpression: `cron(${cronExpression})`,\n State: \"ENABLED\",\n Description: `Enable us to schedule an action in publishing workflow at a particular datetime`\n };\n\n await cloudWatchEventClient.send(new PutRuleCommand(ruleParams));\n /**\n * Add lambda as target for the rule.\n */\n await cloudWatchEventClient.send(\n new PutTargetsCommand({\n Rule: eventRuleName,\n Targets: [\n {\n Arn: invokedFunctionArn,\n Id: eventTargetId,\n Input: JSON.stringify({\n datetime: datetime,\n tenant: tenant,\n locale: locale,\n invocationType: InvocationTypes.SCHEDULED,\n futureDatetime: futureDatetime\n } as HandlerArgs)\n }\n ]\n })\n );\n}\n\nexport const shouldScheduleTask = (\n nextTaskDatetime: string,\n currentTaskDatetime: string | null\n): boolean => {\n return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;\n};\n\ninterface RestoreDateTimeParams\n extends Pick<Configuration, \"storageOperations\">,\n Pick<HandlerArgs, \"tenant\" | \"locale\"> {\n task: ApwScheduleAction;\n}\n\nexport const restoreDateTime = async ({\n locale,\n tenant,\n task: currentTask,\n storageOperations\n}: RestoreDateTimeParams): Promise<void> => {\n log(`Mark task \"${currentTask.id}\" as undone by restoring original \"datetime\".`);\n const item = await storageOperations.get({\n where: {\n tenant,\n locale,\n id: currentTask.id\n }\n });\n if (item) {\n const newDateTime = moveDateTimeToCurrentCentury(item.data.datetime);\n await storageOperations.update({\n item: {\n ...item,\n data: { ...item.data, datetime: newDateTime }\n },\n input: { ...item.data, datetime: newDateTime }\n });\n }\n};\n\ninterface ExecuteTaskParams\n extends Pick<ClientContext, \"handlerClient\">,\n Pick<Configuration, \"storageOperations\"> {\n args: HandlerArgs;\n lambdaName: string;\n}\n\nexport const executeTask = async ({\n args,\n lambdaName,\n handlerClient,\n storageOperations\n}: ExecuteTaskParams): Promise<void> => {\n log(`Executing task at: `, new Date().toISOString());\n\n if (typeof handlerClient.invoke === \"function\") {\n await handlerClient.invoke({\n name: lambdaName,\n payload: {\n futureDatetime: args.futureDatetime,\n datetime: args.datetime,\n tenant: args.tenant,\n locale: args.locale\n },\n await: false\n });\n }\n\n /**\n * Delete current schedule Task. So that, we can schedule a new one later.\n */\n try {\n await storageOperations.deleteCurrentTask({\n tenant: args.tenant,\n locale: args.locale\n });\n } catch (e) {\n console.error(e);\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AAKA;;AASA,MAAMA,GAAG,GAAGC,OAAO,CAACD,GAApB;;AAOA;AACA;AACA;AACA;AACA;AACO,eAAeE,uBAAf,CAAuC;EAC1CC,qBAD0C;EAE1CC,kBAF0C;EAG1CC,QAH0C;EAI1CC,cAJ0C;EAK1CC,MAL0C;EAM1CC;AAN0C,CAAvC,EAO2B;EAC9B,MAAM;IAAEC,aAAF;IAAiBC;EAAjB,IAAmC,MAAM,IAAAC,qBAAA,GAA/C;EACA;AACJ;AACA;;EACI,MAAMC,oBAAoB,GAAG,IAAIC,4CAAJ,CAAyB;IAClDC,IAAI,EAAEJ,aAD4C;IAElDK,GAAG,EAAE,CAACN,aAAD;EAF6C,CAAzB,CAA7B;EAIA,MAAMO,qBAAqB,GAAG,MAAMb,qBAAqB,CAACc,IAAtB,CAA2BL,oBAA3B,CAApC;EACA;AACJ;AACA;;EACI,IACI,OAAOI,qBAAqB,CAACE,gBAA7B,KAAkD,QAAlD,IACAF,qBAAqB,CAACE,gBAA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AArB,CAAN;EAUH;EAED;AACJ;AACA;;;EACI,IAAI;IACA,MAAMnB,iBAAiB,CAACoB,iBAAlB,CAAoC;MACtC5D,MAAM,EAAEmD,IAAI,CAACnD,MADyB;MAEtCC,MAAM,EAAEkD,IAAI,CAAClD;IAFyB,CAApC,CAAN;EAIH,CALD,CAKE,OAAO4D,CAAP,EAAU;IACRnE,OAAO,CAACoE,KAAR,CAAcD,CAAd;EACH;AACJ,CAhCM"}
@@ -0,0 +1,33 @@
1
+ import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
+ import { InvocationTypes } from "../types";
3
+ export declare const getIsoStringTillMinutes: (datetime: string) => string;
4
+ export declare const dateTimeToCronExpression: (datetime: string) => string;
5
+ export declare const moveDateTimeToNextCentury: (datetime: string) => string;
6
+ export declare const moveDateTimeToCurrentCentury: (datetime: string) => string;
7
+ export declare const isDateTimeInNextCentury: (datetime: string) => boolean;
8
+ interface ShouldRestoreDatetimeParams {
9
+ invocationType?: InvocationTypes;
10
+ datetime: string;
11
+ }
12
+ export declare const shouldRestoreDatetime: ({ invocationType, datetime }: ShouldRestoreDatetimeParams) => boolean;
13
+ interface EncodeTokenParams {
14
+ id: string;
15
+ tenant: string;
16
+ locale: string;
17
+ }
18
+ export declare const encodeToken: ({ id, tenant, locale }: EncodeTokenParams) => string;
19
+ export declare const TOKEN_PREFIX = "apw-";
20
+ export declare const decodeToken: (token: string) => Partial<EncodeTokenParams>;
21
+ export declare const documentClient: DocumentClient;
22
+ export declare const basePlugins: () => (import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[];
23
+ /**
24
+ * Get APW settings record from DDB.
25
+ */
26
+ export interface ApwSettings {
27
+ mainGraphqlFunctionArn: string;
28
+ cmsGraphqlFunctionArn: string;
29
+ eventRuleName: string;
30
+ eventTargetId: string;
31
+ }
32
+ export declare const getApwSettings: () => Promise<ApwSettings>;
33
+ export {};
@@ -0,0 +1,168 @@
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.shouldRestoreDatetime = exports.moveDateTimeToNextCentury = exports.moveDateTimeToCurrentCentury = exports.isDateTimeInNextCentury = exports.getIsoStringTillMinutes = exports.getApwSettings = exports.encodeToken = exports.documentClient = exports.decodeToken = exports.dateTimeToCronExpression = exports.basePlugins = exports.TOKEN_PREFIX = void 0;
9
+
10
+ var _dayjs = _interopRequireDefault(require("dayjs"));
11
+
12
+ var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
13
+
14
+ var _dynamodb = require("aws-sdk/clients/dynamodb");
15
+
16
+ var _handlerDb = _interopRequireDefault(require("@webiny/handler-db"));
17
+
18
+ var _dbDynamodb = require("@webiny/db-dynamodb");
19
+
20
+ var _plugins = _interopRequireDefault(require("@webiny/db-dynamodb/plugins"));
21
+
22
+ var _handlerLogs = _interopRequireDefault(require("@webiny/handler-logs"));
23
+
24
+ var _types = require("../types");
25
+
26
+ /**
27
+ * https://day.js.org/docs/en/plugin/utc
28
+ */
29
+ _dayjs.default.extend(_utc.default);
30
+
31
+ const TIME_SEPARATOR = ":";
32
+ const ELAPSED_CRON_EXPRESSION = "* * * * ? 2000";
33
+
34
+ const getIsoStringTillMinutes = datetime => {
35
+ /**
36
+ * Validate datetime.
37
+ */
38
+ if (isNaN(Date.parse(datetime))) {
39
+ return datetime;
40
+ } // input = "2022-03-08T05:41:13.230Z"
41
+ // output = "2022-03-08T05:41"
42
+
43
+
44
+ return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));
45
+ };
46
+
47
+ exports.getIsoStringTillMinutes = getIsoStringTillMinutes;
48
+
49
+ const dateTimeToCronExpression = datetime => {
50
+ if (!datetime) {
51
+ return ELAPSED_CRON_EXPRESSION;
52
+ }
53
+ /**
54
+ * You can't specify the Day-of-month and Day-of-week fields in the same cron expression.
55
+ * If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.
56
+ *
57
+ * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
58
+ */
59
+
60
+
61
+ const dayOfWeek = "?";
62
+ return _dayjs.default.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);
63
+ };
64
+
65
+ exports.dateTimeToCronExpression = dateTimeToCronExpression;
66
+
67
+ const moveDateTimeToNextCentury = datetime => {
68
+ return _dayjs.default.utc(datetime).add(100, "year").toISOString();
69
+ };
70
+
71
+ exports.moveDateTimeToNextCentury = moveDateTimeToNextCentury;
72
+
73
+ const moveDateTimeToCurrentCentury = datetime => {
74
+ return _dayjs.default.utc(datetime).subtract(100, "year").toISOString();
75
+ };
76
+
77
+ exports.moveDateTimeToCurrentCentury = moveDateTimeToCurrentCentury;
78
+
79
+ const isDateTimeInNextCentury = datetime => {
80
+ return _dayjs.default.utc(datetime).isAfter("2100-01-01", "year");
81
+ };
82
+
83
+ exports.isDateTimeInNextCentury = isDateTimeInNextCentury;
84
+
85
+ const shouldRestoreDatetime = ({
86
+ invocationType,
87
+ datetime
88
+ }) => {
89
+ /**
90
+ * "invocationType" will not be SCHEDULED when the lambda is called from Main GQL handler.
91
+ *
92
+ * Which means a new content is scheduled for "publish"/"unpublish" therefore, we need to restore the previously
93
+ * scheduled action if it has not been executed already.
94
+ */
95
+ const selfInvoked = invocationType === _types.InvocationTypes.SCHEDULED;
96
+
97
+ const today = _dayjs.default.utc();
98
+
99
+ const isExecutionPending = _dayjs.default.utc(datetime).isAfter(today);
100
+
101
+ return !selfInvoked && isExecutionPending;
102
+ };
103
+
104
+ exports.shouldRestoreDatetime = shouldRestoreDatetime;
105
+
106
+ const encodeToken = ({
107
+ id,
108
+ tenant,
109
+ locale
110
+ }) => {
111
+ return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;
112
+ };
113
+
114
+ exports.encodeToken = encodeToken;
115
+ const TOKEN_PREFIX = "apw-";
116
+ exports.TOKEN_PREFIX = TOKEN_PREFIX;
117
+
118
+ const decodeToken = token => {
119
+ const auth = token.slice(TOKEN_PREFIX.length);
120
+ const [id, tenant, locale] = auth.split("__");
121
+ return {
122
+ id,
123
+ tenant,
124
+ locale
125
+ };
126
+ };
127
+
128
+ exports.decodeToken = decodeToken;
129
+ const documentClient = new _dynamodb.DocumentClient({
130
+ convertEmptyValues: true,
131
+ region: process.env.AWS_REGION
132
+ });
133
+ exports.documentClient = documentClient;
134
+
135
+ const basePlugins = () => [(0, _plugins.default)(), (0, _handlerLogs.default)(), (0, _handlerDb.default)({
136
+ table: process.env.DB_TABLE,
137
+ driver: new _dbDynamodb.DynamoDbDriver({
138
+ documentClient
139
+ })
140
+ })];
141
+ /**
142
+ * Get APW settings record from DDB.
143
+ */
144
+
145
+
146
+ exports.basePlugins = basePlugins;
147
+
148
+ const getApwSettings = async () => {
149
+ const variant = process.env.STAGED_ROLLOUTS_VARIANT;
150
+ const params = {
151
+ TableName: process.env.DB_TABLE,
152
+ Key: {
153
+ PK: `APW#SETTINGS`,
154
+ SK: variant || "default"
155
+ }
156
+ };
157
+ const {
158
+ Item
159
+ } = await documentClient.get(params).promise();
160
+ return {
161
+ mainGraphqlFunctionArn: Item ? Item["mainGraphqlFunctionArn"] : "mainGraphqlFunctionArn",
162
+ cmsGraphqlFunctionArn: Item ? Item["cmsGraphqlFunctionArn"] : "cmsGraphqlFunctionArn",
163
+ eventRuleName: Item ? Item["eventRuleName"] : "eventRuleName",
164
+ eventTargetId: Item ? Item["eventTargetId"] : "eventTargetId"
165
+ };
166
+ };
167
+
168
+ exports.getApwSettings = getApwSettings;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","cmsGraphqlFunctionArn","eventRuleName","eventTargetId"],"sources":["utils.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport dbPlugins from \"@webiny/handler-db\";\nimport { DynamoDbDriver } from \"@webiny/db-dynamodb\";\nimport dynamoDbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport logsPlugins from \"@webiny/handler-logs\";\nimport { InvocationTypes } from \"~/scheduler/types\";\n\n/**\n * https://day.js.org/docs/en/plugin/utc\n */\ndayjs.extend(utc);\n\nconst TIME_SEPARATOR = \":\";\nconst ELAPSED_CRON_EXPRESSION = \"* * * * ? 2000\";\n\nexport const getIsoStringTillMinutes = (datetime: string): string => {\n /**\n * Validate datetime.\n */\n if (isNaN(Date.parse(datetime))) {\n return datetime;\n }\n // input = \"2022-03-08T05:41:13.230Z\"\n // output = \"2022-03-08T05:41\"\n return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));\n};\n\nexport const dateTimeToCronExpression = (datetime: string): string => {\n if (!datetime) {\n return ELAPSED_CRON_EXPRESSION;\n }\n /**\n * You can't specify the Day-of-month and Day-of-week fields in the same cron expression.\n * If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.\n *\n * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html\n */\n const dayOfWeek = \"?\";\n\n return dayjs.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);\n};\n\nexport const moveDateTimeToNextCentury = (datetime: string): string => {\n return dayjs.utc(datetime).add(100, \"year\").toISOString();\n};\n\nexport const moveDateTimeToCurrentCentury = (datetime: string): string => {\n return dayjs.utc(datetime).subtract(100, \"year\").toISOString();\n};\n\nexport const isDateTimeInNextCentury = (datetime: string): boolean => {\n return dayjs.utc(datetime).isAfter(\"2100-01-01\", \"year\");\n};\n\ninterface ShouldRestoreDatetimeParams {\n invocationType?: InvocationTypes;\n datetime: string;\n}\n\nexport const shouldRestoreDatetime = ({\n invocationType,\n datetime\n}: ShouldRestoreDatetimeParams): boolean => {\n /**\n * \"invocationType\" will not be SCHEDULED when the lambda is called from Main GQL handler.\n *\n * Which means a new content is scheduled for \"publish\"/\"unpublish\" therefore, we need to restore the previously\n * scheduled action if it has not been executed already.\n */\n const selfInvoked = invocationType === InvocationTypes.SCHEDULED;\n\n const today = dayjs.utc();\n const isExecutionPending = dayjs.utc(datetime).isAfter(today);\n\n return !selfInvoked && isExecutionPending;\n};\n\ninterface EncodeTokenParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport const encodeToken = ({ id, tenant, locale }: EncodeTokenParams) => {\n return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;\n};\n\nexport const TOKEN_PREFIX = \"apw-\";\n\nexport const decodeToken = (token: string): Partial<EncodeTokenParams> => {\n const auth = token.slice(TOKEN_PREFIX.length);\n const [id, tenant, locale] = auth.split(\"__\");\n\n return {\n id,\n tenant,\n locale\n };\n};\n\nexport const documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: process.env.AWS_REGION\n});\n\nexport const basePlugins = () => [\n dynamoDbPlugins(),\n logsPlugins(),\n dbPlugins({\n table: process.env.DB_TABLE,\n driver: new DynamoDbDriver({\n documentClient\n })\n })\n];\n\n/**\n * Get APW settings record from DDB.\n */\nexport interface ApwSettings {\n mainGraphqlFunctionArn: string;\n cmsGraphqlFunctionArn: string;\n eventRuleName: string;\n eventTargetId: string;\n}\n\nexport const getApwSettings = async (): Promise<ApwSettings> => {\n const variant = process.env.STAGED_ROLLOUTS_VARIANT;\n\n const params = {\n TableName: process.env.DB_TABLE as string,\n Key: {\n PK: `APW#SETTINGS`,\n SK: variant || \"default\"\n }\n };\n\n const { Item } = await documentClient.get(params).promise();\n\n return {\n mainGraphqlFunctionArn: Item ? Item[\"mainGraphqlFunctionArn\"] : \"mainGraphqlFunctionArn\",\n cmsGraphqlFunctionArn: Item ? Item[\"cmsGraphqlFunctionArn\"] : \"cmsGraphqlFunctionArn\",\n eventRuleName: Item ? Item[\"eventRuleName\"] : \"eventRuleName\",\n eventTargetId: Item ? Item[\"eventTargetId\"] : \"eventTargetId\"\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;AACA;AACA;AACAA,cAAA,CAAMC,MAAN,CAAaC,YAAb;;AAEA,MAAMC,cAAc,GAAG,GAAvB;AACA,MAAMC,uBAAuB,GAAG,gBAAhC;;AAEO,MAAMC,uBAAuB,GAAIC,QAAD,IAA8B;EACjE;AACJ;AACA;EACI,IAAIC,KAAK,CAACC,IAAI,CAACC,KAAL,CAAWH,QAAX,CAAD,CAAT,EAAiC;IAC7B,OAAOA,QAAP;EACH,CANgE,CAOjE;EACA;;;EACA,OAAOA,QAAQ,CAACI,KAAT,CAAe,CAAf,EAAkBJ,QAAQ,CAACK,WAAT,CAAqBR,cAArB,CAAlB,CAAP;AACH,CAVM;;;;AAYA,MAAMS,wBAAwB,GAAIN,QAAD,IAA8B;EAClE,IAAI,CAACA,QAAL,EAAe;IACX,OAAOF,uBAAP;EACH;EACD;AACJ;AACA;AACA;AACA;AACA;;;EACI,MAAMS,SAAS,GAAG,GAAlB;EAEA,OAAOb,cAAA,CAAME,GAAN,CAAUI,QAAV,EAAoBQ,MAApB,CAA4B,aAAYD,SAAU,QAAlD,CAAP;AACH,CAbM;;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@@ -0,0 +1,2 @@
1
+ import { ApwScheduleActionCrud, CreateScheduleActionParams } from "./types";
2
+ export declare const createScheduler: (params: CreateScheduleActionParams) => ApwScheduleActionCrud;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createScheduler = void 0;
7
+
8
+ var _createScheduleActionMethods = require("./createScheduleActionMethods");
9
+
10
+ const createScheduler = params => {
11
+ const {
12
+ getLocale,
13
+ getIdentity,
14
+ getTenant,
15
+ getPermission,
16
+ storageOperations
17
+ } = params;
18
+ return (0, _createScheduleActionMethods.createScheduleActionMethods)({
19
+ getLocale,
20
+ getIdentity,
21
+ getTenant,
22
+ getPermission,
23
+ storageOperations
24
+ });
25
+ };
26
+
27
+ exports.createScheduler = createScheduler;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createScheduler","params","getLocale","getIdentity","getTenant","getPermission","storageOperations","createScheduleActionMethods"],"sources":["index.ts"],"sourcesContent":["import { createScheduleActionMethods } from \"./createScheduleActionMethods\";\nimport { ApwScheduleActionCrud, CreateScheduleActionParams } from \"./types\";\n\nexport const createScheduler = (params: CreateScheduleActionParams): ApwScheduleActionCrud => {\n const { getLocale, getIdentity, getTenant, getPermission, storageOperations } = params;\n\n return createScheduleActionMethods({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations\n });\n};\n"],"mappings":";;;;;;;AAAA;;AAGO,MAAMA,eAAe,GAAIC,MAAD,IAA+D;EAC1F,MAAM;IAAEC,SAAF;IAAaC,WAAb;IAA0BC,SAA1B;IAAqCC,aAArC;IAAoDC;EAApD,IAA0EL,MAAhF;EAEA,OAAO,IAAAM,wDAAA,EAA4B;IAC/BL,SAD+B;IAE/BC,WAF+B;IAG/BC,SAH+B;IAI/BC,aAJ+B;IAK/BC;EAL+B,CAA5B,CAAP;AAOH,CAVM"}
@@ -0,0 +1,171 @@
1
+ import { Context } from "@webiny/api/types";
2
+ import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types";
3
+ import { I18NLocale, I18NContext } from "@webiny/api-i18n/types";
4
+ import { Tenant } from "@webiny/api-tenancy/types";
5
+ import { TenancyContext } from "@webiny/api-tenancy/types";
6
+ export interface ListWhere {
7
+ /**
8
+ * Fields.
9
+ */
10
+ id?: string;
11
+ id_in?: string[];
12
+ id_not?: string;
13
+ id_not_in?: string[];
14
+ /**
15
+ * Who created the entry?
16
+ */
17
+ createdBy?: string;
18
+ createdBy_not?: string;
19
+ createdBy_in?: string[];
20
+ createdBy_not_in?: string[];
21
+ /**
22
+ * By datetime field.
23
+ */
24
+ datetime_startsWith?: string;
25
+ }
26
+ export interface ListParams {
27
+ where: ListWhere;
28
+ sort?: ("datetime_ASC" | "datetime_DESC")[];
29
+ limit?: number;
30
+ after?: string;
31
+ }
32
+ /**
33
+ * A interface describing the reference to a user that created some data in the database.
34
+ *
35
+ * @category General
36
+ */
37
+ export interface CreatedBy {
38
+ /**
39
+ * ID if the user.
40
+ */
41
+ id: string;
42
+ /**
43
+ * Full name of the user.
44
+ */
45
+ displayName: string | null;
46
+ /**
47
+ * Type of the user (admin, user)
48
+ */
49
+ type: string;
50
+ }
51
+ export interface ListMeta {
52
+ /**
53
+ * A cursor for pagination.
54
+ */
55
+ cursor: string | null;
56
+ /**
57
+ * Is there more items to load?
58
+ */
59
+ hasMoreItems: boolean;
60
+ /**
61
+ * Total count of the items in the storage.
62
+ */
63
+ totalCount: number;
64
+ }
65
+ export declare enum ApwContentTypes {
66
+ PAGE = "page",
67
+ CMS_ENTRY = "cms_entry"
68
+ }
69
+ export interface BaseFields {
70
+ id: string;
71
+ createdOn: string;
72
+ savedOn?: string;
73
+ createdBy: CreatedBy;
74
+ tenant: string;
75
+ locale: string;
76
+ }
77
+ export interface ApwScheduleAction extends BaseFields {
78
+ data: ApwScheduleActionData;
79
+ }
80
+ export declare enum ApwScheduleActionTypes {
81
+ PUBLISH = "publish",
82
+ UNPUBLISH = "unpublish"
83
+ }
84
+ export interface ApwScheduleActionData {
85
+ action: ApwScheduleActionTypes;
86
+ type: ApwContentTypes;
87
+ datetime: string;
88
+ entryId: string;
89
+ /**
90
+ * We will add modelId to the data for now.
91
+ * TODO extract in separate package?
92
+ */
93
+ modelId?: string;
94
+ }
95
+ export declare enum InvocationTypes {
96
+ SCHEDULED = "scheduled"
97
+ }
98
+ interface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {
99
+ get(id: string): Promise<TEntry | null>;
100
+ create(data: TCreateEntryParams): Promise<TEntry>;
101
+ update(id: string, data: TUpdateEntryParams): Promise<TEntry>;
102
+ delete(id: string): Promise<Boolean>;
103
+ }
104
+ export interface ApwScheduleActionCrud extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {
105
+ list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;
106
+ getCurrentTask(): Promise<ApwScheduleAction | null>;
107
+ updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;
108
+ deleteCurrentTask(): Promise<Boolean>;
109
+ }
110
+ export interface ScheduleActionContext extends Context, I18NContext, TenancyContext {
111
+ scheduleAction: ApwScheduleActionCrud;
112
+ }
113
+ export interface CreateScheduleActionParams {
114
+ getLocale: () => I18NLocale;
115
+ getIdentity: () => SecurityIdentity;
116
+ getTenant: () => Tenant;
117
+ getPermission: (name: string) => Promise<SecurityPermission | null>;
118
+ storageOperations: ApwScheduleActionStorageOperations;
119
+ }
120
+ interface CreateApwScheduleActionParams {
121
+ item: ApwScheduleAction;
122
+ input: ApwScheduleActionData;
123
+ }
124
+ interface StorageOperationsGetParams {
125
+ where: {
126
+ id: string;
127
+ tenant: string;
128
+ locale: string;
129
+ };
130
+ }
131
+ interface StorageOperationsDeleteParams {
132
+ id: string;
133
+ tenant: string;
134
+ locale: string;
135
+ }
136
+ export interface ApwScheduleActionListParams extends ListParams {
137
+ where: ListWhere & {
138
+ tenant: string;
139
+ locale: string;
140
+ };
141
+ }
142
+ export declare type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;
143
+ export declare type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;
144
+ export declare type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;
145
+ export declare type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;
146
+ export interface StorageOperationsUpdateScheduleActionParams {
147
+ item: ApwScheduleAction;
148
+ input: ApwScheduleActionData;
149
+ }
150
+ export declare type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];
151
+ export interface StorageOperationsUpdateCurrentTaskParams {
152
+ item: ApwScheduleAction;
153
+ }
154
+ export interface StorageOperationsGetCurrentTaskParams {
155
+ where: Pick<StorageOperationsGetParams["where"], "tenant" | "locale">;
156
+ }
157
+ export declare type StorageOperationsDeleteCurrentTaskParams = Pick<StorageOperationsDeleteParams, "tenant" | "locale">;
158
+ export interface ApwScheduleActionStorageOperations {
159
+ get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;
160
+ list(params: StorageOperationsListScheduleActionsParams): Promise<StorageOperationsListScheduleActionsResponse>;
161
+ create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;
162
+ update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;
163
+ delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;
164
+ getCurrentTask(params: StorageOperationsGetCurrentTaskParams): Promise<ApwScheduleAction | null>;
165
+ updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;
166
+ deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;
167
+ }
168
+ export interface CreateApwContextParams {
169
+ storageOperations: ApwScheduleActionStorageOperations;
170
+ }
171
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTypes = void 0;
7
+
8
+ /**
9
+ * A interface describing the reference to a user that created some data in the database.
10
+ *
11
+ * @category General
12
+ */
13
+ let ApwContentTypes;
14
+ exports.ApwContentTypes = ApwContentTypes;
15
+
16
+ (function (ApwContentTypes) {
17
+ ApwContentTypes["PAGE"] = "page";
18
+ ApwContentTypes["CMS_ENTRY"] = "cms_entry";
19
+ })(ApwContentTypes || (exports.ApwContentTypes = ApwContentTypes = {}));
20
+
21
+ let ApwScheduleActionTypes;
22
+ exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
23
+
24
+ (function (ApwScheduleActionTypes) {
25
+ ApwScheduleActionTypes["PUBLISH"] = "publish";
26
+ ApwScheduleActionTypes["UNPUBLISH"] = "unpublish";
27
+ })(ApwScheduleActionTypes || (exports.ApwScheduleActionTypes = ApwScheduleActionTypes = {}));
28
+
29
+ let InvocationTypes;
30
+ exports.InvocationTypes = InvocationTypes;
31
+
32
+ (function (InvocationTypes) {
33
+ InvocationTypes["SCHEDULED"] = "scheduled";
34
+ })(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\n/**\n * A interface describing the reference to a user that created some data in the database.\n *\n * @category General\n */\nexport interface CreatedBy {\n /**\n * ID if the user.\n */\n id: string;\n /**\n * Full name of the user.\n */\n displayName: string | null;\n /**\n * Type of the user (admin, user)\n */\n type: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: CreatedBy;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;;AAkCA;AACA;AACA;AACA;AACA;IA+BYA,e;;;WAAAA,e;EAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e;;IAkBAC,sB;;;WAAAA,sB;EAAAA,sB;EAAAA,sB;GAAAA,sB,sCAAAA,sB;;IAiBAC,e;;;WAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e"}