@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,126 @@
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.HeadlessCMSGraphQL = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _ApplicationGraphQL = require("./ApplicationGraphQL");
13
+
14
+ var _types = require("../../../types");
15
+
16
+ var _error = _interopRequireDefault(require("@webiny/error"));
17
+
18
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
19
+
20
+ const META_FIELDS = `
21
+ title
22
+ publishedOn
23
+ version
24
+ locked
25
+ status
26
+ `;
27
+ const ERROR_FIELD = `
28
+ {
29
+ code
30
+ data
31
+ message
32
+ }
33
+ `;
34
+
35
+ const createPublishMutation = modelId => {
36
+ const ucFirstModelId = (0, _upperFirst.default)(modelId);
37
+ return `
38
+ mutation CmsPublish${ucFirstModelId}($revision: ID!) {
39
+ content: publish${ucFirstModelId}(revision: $revision) {
40
+ data {
41
+ id
42
+ meta {
43
+ ${META_FIELDS}
44
+ }
45
+ }
46
+ error ${ERROR_FIELD}
47
+ }
48
+ }`;
49
+ };
50
+
51
+ const createUnpublishMutation = modelId => {
52
+ const ucFirstModelId = (0, _upperFirst.default)(modelId);
53
+ return `
54
+ mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {
55
+ content: unpublish${ucFirstModelId}(revision: $revision) {
56
+ data {
57
+ id
58
+ meta {
59
+ ${META_FIELDS}
60
+ }
61
+ }
62
+ error ${ERROR_FIELD}
63
+ }
64
+ }`;
65
+ };
66
+
67
+ class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
68
+ constructor(...args) {
69
+ super(...args);
70
+ (0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.pageBuilder");
71
+ }
72
+
73
+ canUse(data) {
74
+ return data.type === _types.ApwContentTypes.CMS_ENTRY;
75
+ }
76
+
77
+ getArn(settings) {
78
+ return settings.cmsGraphqlFunctionArn;
79
+ }
80
+
81
+ getGraphQLBody(data) {
82
+ switch (data.action) {
83
+ case _types.ApwScheduleActionTypes.PUBLISH:
84
+ return this.getPublishBody(data);
85
+
86
+ case _types.ApwScheduleActionTypes.UNPUBLISH:
87
+ return this.getUnpublishBody(data);
88
+
89
+ default:
90
+ return null;
91
+ }
92
+ }
93
+
94
+ getPublishBody(data) {
95
+ if (!data.modelId) {
96
+ throw new _error.default("Missing model ID in the schedule action data.", "SCHEDULE_ACTION_ERROR", {
97
+ data
98
+ });
99
+ }
100
+
101
+ return {
102
+ query: createPublishMutation(data.modelId),
103
+ variables: {
104
+ revision: data.entryId
105
+ }
106
+ };
107
+ }
108
+
109
+ getUnpublishBody(data) {
110
+ if (!data.modelId) {
111
+ throw new _error.default("Missing model ID in the schedule action data.", "SCHEDULE_ACTION_ERROR", {
112
+ data
113
+ });
114
+ }
115
+
116
+ return {
117
+ query: createUnpublishMutation(data.modelId),
118
+ variables: {
119
+ revision: data.entryId
120
+ }
121
+ };
122
+ }
123
+
124
+ }
125
+
126
+ exports.HeadlessCMSGraphQL = HeadlessCMSGraphQL;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getArn","settings","cmsGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import { ApplicationGraphQL, ApplicationGraphQLBody } from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionData, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n publishedOn\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.cmsGraphqlFunctionArn;\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 if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAEA,MAAMA,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CANA;;AAQA,MAAMC,qBAAqB,GAAIC,OAAD,IAA6B;EACvD,MAAMC,cAAc,GAAG,IAAAC,mBAAA,EAAWF,OAAX,CAAvB;EAEA,OAAQ;AACZ,6BAA6BC,cAAe;AAC5C,8BAA8BA,cAAe;AAC7C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAXI;AAYH,CAfD;;AAiBA,MAAMK,uBAAuB,GAAIH,OAAD,IAAqB;EACjD,MAAMC,cAAc,GAAG,IAAAC,mBAAA,EAAWF,OAAX,CAAvB;EAEA,OAAQ;AACZ,+BAA+BC,c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Q,EAAEjB,IAAI,CAACkB;MADR;IAFR,CAAP;EAMH;;AA5DsD"}
@@ -0,0 +1,11 @@
1
+ import { ApplicationGraphQL, ApplicationGraphQLBody } from "./ApplicationGraphQL";
2
+ import { ApwScheduleActionData } from "../../../types";
3
+ import { ApwSettings } from "../../utils";
4
+ export declare class PageBuilderGraphQL extends ApplicationGraphQL {
5
+ name: string;
6
+ canUse(data: ApwScheduleActionData): boolean;
7
+ getArn(settings: ApwSettings): string;
8
+ getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;
9
+ private getPublishBody;
10
+ private getUnpublishBody;
11
+ }
@@ -0,0 +1,163 @@
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.PageBuilderGraphQL = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _ApplicationGraphQL = require("./ApplicationGraphQL");
13
+
14
+ var _types = require("../../../types");
15
+
16
+ const PB_PAGE_DATA_FIELD =
17
+ /* GraphQL */
18
+ `
19
+ {
20
+ 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
+ }
81
+ `;
82
+ const ERROR_FIELD =
83
+ /* GraphQL */
84
+ `
85
+ {
86
+ code
87
+ data
88
+ message
89
+ }
90
+ `;
91
+ const PUBLISH_MUTATION =
92
+ /* GraphQL */
93
+ `
94
+ mutation PublishPage($id: ID!) {
95
+ pageBuilder {
96
+ publishPage(id: $id) {
97
+ data ${PB_PAGE_DATA_FIELD}
98
+ error ${ERROR_FIELD}
99
+ }
100
+ }
101
+ }
102
+ `;
103
+ const UNPUBLISH_MUTATION =
104
+ /* GraphQL */
105
+ `
106
+ mutation UnpublishPage($id: ID!) {
107
+ pageBuilder {
108
+ unpublishPage(id: $id) {
109
+ data ${PB_PAGE_DATA_FIELD}
110
+ error ${ERROR_FIELD}
111
+ }
112
+ }
113
+ }
114
+ `;
115
+
116
+ class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
117
+ constructor(...args) {
118
+ super(...args);
119
+ (0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.pageBuilder");
120
+ }
121
+
122
+ canUse(data) {
123
+ return data.type === _types.ApwContentTypes.PAGE;
124
+ }
125
+
126
+ getArn(settings) {
127
+ return settings.mainGraphqlFunctionArn;
128
+ }
129
+
130
+ getGraphQLBody(data) {
131
+ switch (data.action) {
132
+ case _types.ApwScheduleActionTypes.PUBLISH:
133
+ return this.getPublishBody(data);
134
+
135
+ case _types.ApwScheduleActionTypes.UNPUBLISH:
136
+ return this.getUnpublishBody(data);
137
+
138
+ default:
139
+ return null;
140
+ }
141
+ }
142
+
143
+ getPublishBody(data) {
144
+ return {
145
+ query: PUBLISH_MUTATION,
146
+ variables: {
147
+ id: data.entryId
148
+ }
149
+ };
150
+ }
151
+
152
+ getUnpublishBody(data) {
153
+ return {
154
+ query: UNPUBLISH_MUTATION,
155
+ variables: {
156
+ id: data.entryId
157
+ }
158
+ };
159
+ }
160
+
161
+ }
162
+
163
+ exports.PageBuilderGraphQL = PageBuilderGraphQL;
@@ -0,0 +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 { ApplicationGraphQL, ApplicationGraphQLBody } from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionData, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst PB_PAGE_DATA_FIELD = /* GraphQL */ `\n {\n id\n pid\n editor\n category {\n slug\n }\n version\n title\n path\n url\n content\n savedOn\n status\n locked\n publishedOn\n locked\n revisions {\n id\n status\n locked\n version\n }\n settings {\n general {\n snippet\n tags\n layout\n image {\n id\n src\n }\n }\n social {\n meta {\n property\n content\n }\n title\n description\n image {\n id\n src\n }\n }\n seo {\n title\n description\n meta {\n name\n content\n }\n }\n }\n createdFrom\n createdOn\n createdBy {\n id\n displayName\n type\n }\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 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;;AACA;;AAGA,MAAMA,kBAAkB;AAAG;AAAe;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CA/DA;AAiEA,MAAMC,WAAW;AAAG;AAAe;AACnC;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,gBAAgB;AAAG;AAAe;AACxC;AACA;AACA;AACA,uBAAuBF,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CATA;AAWA,MAAME,kBAAkB;AAAG;AAAe;AAC1C;AACA;AACA;AACA,uBAAuBH,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CATA;;AAeO,MAAMG,kBAAN,SAAiCC,sCAAjC,CAAoD;EAAA;IAAA;IAAA,4CAChC,8CADgC;EAAA;;EAGvCC,MAAM,CAACC,IAAD,EAAuC;IACzD,OAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAA,CAAgBC,IAArC;EACH;;EAEeC,MAAM,CAACC,QAAD,EAAgC;IAClD,OAAOA,QAAQ,CAACC,sBAAhB;EACH;;EAEeC,cAAc,CAACP,IAAD,EAA6D;IACvF,QAAQA,IAAI,CAACQ,MAAb;MACI,KAAKC,6BAAA,CAAuBC,OAA5B;QACI,OAAO,KAAKC,cAAL,CAAoBX,IAApB,CAAP;;MACJ,KAAKS,6BAAA,CAAuBG,SAA5B;QACI,OAAO,KAAKC,gBAAL,CAAsBb,IAAtB,CAAP;;MACJ;QACI,OAAO,IAAP;IANR;EAQH;;EAEOW,cAAc,CAClBX,IADkB,EAEqC;IACvD,OAAO;MACHc,KAAK,EAAEnB,gBADJ;MAEHoB,SAAS,EAAE;QACPC,EAAE,EAAEhB,IAAI,CAACiB;MADF;IAFR,CAAP;EAMH;;EAEOJ,gBAAgB,CACpBb,IADoB,EAEmC;IACvD,OAAO;MACHc,KAAK,EAAElB,kBADJ;MAEHmB,SAAS,EAAE;QACPC,EAAE,EAAEhB,IAAI,CAACiB;MADF;IAFR,CAAP;EAMH;;AA1CsD"}
@@ -0,0 +1,4 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { CreateApwContextParams } from "../../types";
3
+ import { ApwContext } from "../../../types";
4
+ export declare const createCustomAuth: ({ storageOperations }: CreateApwContextParams) => ContextPlugin<ApwContext>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCustomAuth = void 0;
7
+
8
+ var _api = require("@webiny/api");
9
+
10
+ var _utils = require("../utils");
11
+
12
+ const createCustomAuth = ({
13
+ storageOperations
14
+ }) => {
15
+ return new _api.ContextPlugin(({
16
+ security
17
+ }) => {
18
+ let hasApwToken = false;
19
+ security.addAuthenticator(async token => {
20
+ if (!token.startsWith(_utils.TOKEN_PREFIX)) {
21
+ return null;
22
+ }
23
+
24
+ const {
25
+ id,
26
+ tenant,
27
+ locale
28
+ } = (0, _utils.decodeToken)(token);
29
+ /**
30
+ * No point in going further if any piece of information is missing.
31
+ */
32
+
33
+ if (!id || !tenant || !locale) {
34
+ return null;
35
+ }
36
+ /**
37
+ * We must verify that action we are trying to execute actually exists.
38
+ */
39
+
40
+
41
+ const item = await storageOperations.get({
42
+ where: {
43
+ id,
44
+ tenant,
45
+ locale
46
+ }
47
+ });
48
+
49
+ if (!item) {
50
+ return null;
51
+ }
52
+
53
+ hasApwToken = true;
54
+ return item.createdBy;
55
+ });
56
+ security.addAuthorizer(async () => {
57
+ if (!hasApwToken) {
58
+ return null;
59
+ }
60
+
61
+ return [{
62
+ name: "*"
63
+ }];
64
+ });
65
+ });
66
+ };
67
+
68
+ exports.createCustomAuth = createCustomAuth;
@@ -0,0 +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":";;;;;;;AAAA;;AAEA;;AAGO,MAAMA,gBAAgB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAmD;EAC/E,OAAO,IAAIC,kBAAJ,CAA8B,CAAC;IAAEC;EAAF,CAAD,KAAkB;IACnD,IAAIC,WAAW,GAAG,KAAlB;IAEAD,QAAQ,CAACE,gBAAT,CAA0B,MAAMC,KAAN,IAAe;MACrC,IAAI,CAACA,KAAK,CAACC,UAAN,CAAiBC,mBAAjB,CAAL,EAAqC;QACjC,OAAO,IAAP;MACH;;MAED,MAAM;QAAEC,EAAF;QAAMC,MAAN;QAAcC;MAAd,IAAyB,IAAAC,kBAAA,EAAYN,KAAZ,CAA/B;MACA;AACZ;AACA;;MACY,IAAI,CAACG,EAAD,IAAO,CAACC,MAAR,IAAkB,CAACC,MAAvB,EAA+B;QAC3B,OAAO,IAAP;MACH;MACD;AACZ;AACA;;;MACY,MAAME,IAAI,GAAG,MAAMZ,iBAAiB,CAACa,GAAlB,CAAsB;QACrCC,KAAK,EAAE;UACHN,EADG;UAEHC,MAFG;UAGHC;QAHG;MAD8B,CAAtB,CAAnB;;MAQA,IAAI,CAACE,IAAL,EAAW;QACP,OAAO,IAAP;MACH;;MAEDT,WAAW,GAAG,IAAd;MAEA,OAAOS,IAAI,CAACG,SAAZ;IACH,CA9BD;IAgCAb,QAAQ,CAACc,aAAT,CAAuB,YAAY;MAC/B,IAAI,CAACb,WAAL,EAAkB;QACd,OAAO,IAAP;MACH;;MACD,OAAO,CAAC;QAAEc,IAAI,EAAE;MAAR,CAAD,CAAP;IACH,CALD;EAMH,CAzCM,CAAP;AA0CH,CA3CM"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * This logic/file should be moved somewhere else as it is relying on AWS specific stuff.
3
+ */
4
+ import { ApwScheduleActionStorageOperations } from "../../types";
5
+ export declare enum InvocationTypes {
6
+ SCHEDULED = "scheduled"
7
+ }
8
+ export interface HandlerArgs {
9
+ datetime: string;
10
+ tenant: string;
11
+ locale: string;
12
+ invocationType?: InvocationTypes;
13
+ futureDatetime?: string;
14
+ }
15
+ export interface Configuration {
16
+ cwClient: any;
17
+ storageOperations: ApwScheduleActionStorageOperations;
18
+ handlers: {
19
+ executeAction: string;
20
+ };
21
+ }
22
+ export declare const scheduleActionHandlerPlugins: (config: Configuration) => ((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>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any>)[];
@@ -0,0 +1,164 @@
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.scheduleActionHandlerPlugins = exports.InvocationTypes = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _utils = require("../utils");
13
+
14
+ var _scheduleAction = require("./scheduleAction.utils");
15
+
16
+ var _handlerAws = require("@webiny/handler-aws");
17
+
18
+ /**
19
+ * This logic/file should be moved somewhere else as it is relying on AWS specific stuff.
20
+ */
21
+ let InvocationTypes;
22
+ exports.InvocationTypes = InvocationTypes;
23
+
24
+ (function (InvocationTypes) {
25
+ InvocationTypes["SCHEDULED"] = "scheduled";
26
+ })(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
27
+
28
+ const log = console.log;
29
+ /**
30
+ * Handler that creates a cloudwatch event rule for the schedule action workflow.
31
+ */
32
+
33
+ const createScheduleActionLambda = params => {
34
+ const {
35
+ cwClient: cloudWatchEventClient,
36
+ storageOperations,
37
+ handlers
38
+ } = params;
39
+ return (0, _handlerAws.createRawEventHandler)(async ({
40
+ payload,
41
+ context,
42
+ lambdaContext: eventContext
43
+ }) => {
44
+ try {
45
+ const {
46
+ locale,
47
+ tenant,
48
+ invocationType
49
+ } = payload;
50
+ /**
51
+ * If invocationType is "scheduled", execute the action.
52
+ */
53
+
54
+ if (invocationType === InvocationTypes.SCHEDULED) {
55
+ await (0, _scheduleAction.executeTask)({
56
+ args: payload,
57
+ lambdaName: handlers.executeAction,
58
+ handlerClient: context.handlerClient,
59
+ storageOperations
60
+ });
61
+ }
62
+ /**
63
+ * Get current scheduled task from the DB.
64
+ */
65
+
66
+
67
+ const currentTask = await storageOperations.getCurrentTask({
68
+ where: {
69
+ tenant,
70
+ locale
71
+ }
72
+ });
73
+ /**
74
+ * Get next task from the DB.
75
+ */
76
+
77
+ const [[nextItem]] = await storageOperations.list({
78
+ where: {
79
+ tenant,
80
+ locale
81
+ },
82
+ sort: ["datetime_ASC"],
83
+ limit: 1
84
+ });
85
+
86
+ if (!nextItem) {
87
+ log(`No item found.`);
88
+ return;
89
+ }
90
+
91
+ const nextTaskDatetime = nextItem.data.datetime;
92
+ const currentTaskDatetime = currentTask && currentTask.data.datetime;
93
+
94
+ if ((0, _utils.isDateTimeInNextCentury)(nextTaskDatetime)) {
95
+ log(`Already processed the task.`);
96
+ return;
97
+ }
98
+
99
+ if (!(0, _scheduleAction.shouldScheduleTask)(nextTaskDatetime, currentTaskDatetime)) {
100
+ log(`Already scheduled the task.`);
101
+ return;
102
+ }
103
+
104
+ const futureDatetime = (0, _utils.moveDateTimeToNextCentury)(nextItem.data.datetime);
105
+ /**
106
+ * Update "datetime" to a future date to mark it as scheduled.
107
+ */
108
+
109
+ log(`Update task's datetime to `, futureDatetime);
110
+ await storageOperations.update({
111
+ item: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, nextItem), {}, {
112
+ data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, nextItem.data), {}, {
113
+ datetime: futureDatetime
114
+ })
115
+ }),
116
+ input: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, nextItem.data), {}, {
117
+ datetime: futureDatetime
118
+ })
119
+ });
120
+ /**
121
+ * Restore "datetime" of current task so that it can be schedule in next cycle.
122
+ */
123
+
124
+ if (currentTaskDatetime && (0, _utils.shouldRestoreDatetime)({
125
+ invocationType,
126
+ datetime: currentTaskDatetime
127
+ })) {
128
+ await (0, _scheduleAction.restoreDateTime)({
129
+ tenant,
130
+ locale,
131
+ task: currentTask,
132
+ storageOperations
133
+ });
134
+ }
135
+ /**
136
+ * Schedule Lambda
137
+ */
138
+
139
+
140
+ log(`Schedule Lambda Execution...`);
141
+ await (0, _scheduleAction.scheduleLambdaExecution)({
142
+ cloudWatchEventClient,
143
+ invokedFunctionArn: eventContext.invokedFunctionArn,
144
+ datetime: nextItem.data.datetime,
145
+ futureDatetime: futureDatetime,
146
+ tenant,
147
+ locale
148
+ });
149
+ /**
150
+ * Update current task.
151
+ */
152
+
153
+ await storageOperations.updateCurrentTask({
154
+ item: nextItem
155
+ });
156
+ } catch (ex) {
157
+ log("[HANDLER_CREATE_RULE] Error => ", ex); // TODO: Handler error. Maybe save it into DB.
158
+ }
159
+ });
160
+ };
161
+
162
+ const scheduleActionHandlerPlugins = config => [(0, _utils.basePlugins)(), createScheduleActionLambda(config)];
163
+
164
+ exports.scheduleActionHandlerPlugins = scheduleActionHandlerPlugins;
@@ -0,0 +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 log(\"[HANDLER_CREATE_RULE] Error => \", ex);\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":";;;;;;;;;;;AAIA;;AAMA;;AAMA;;AAhBA;AACA;AACA;IAgBYA,e;;;WAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e;;AAoBZ,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;AAEA;AACA;AACA;;AACA,MAAME,0BAA0B,GAAIC,MAAD,IAA2B;EAC1D,MAAM;IAAEC,QAAQ,EAAEC,qBAAZ;IAAmCC,iBAAnC;IAAsDC;EAAtD,IAAmEJ,MAAzE;EAEA,O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B,CACnE,IAAAC,kBAAA,GADmE,EAEnE/C,0BAA0B,CAAC8C,MAAD,CAFyC,CAAhE"}
@@ -0,0 +1,24 @@
1
+ import { ApwScheduleAction } from "../../types";
2
+ import { HandlerArgs, Configuration } from "./index";
3
+ import { ClientContext } from "@webiny/handler-client/types";
4
+ interface ScheduleLambdaExecutionParams extends Omit<HandlerArgs, "invocationType"> {
5
+ cloudWatchEventClient: any;
6
+ invokedFunctionArn: string;
7
+ }
8
+ /**
9
+ * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;
10
+ * in case of scheduling becoming the most frequently used feature.
11
+ * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/
12
+ */
13
+ export declare function scheduleLambdaExecution({ cloudWatchEventClient, invokedFunctionArn, datetime, futureDatetime, tenant, locale }: ScheduleLambdaExecutionParams): Promise<void>;
14
+ export declare const shouldScheduleTask: (nextTaskDatetime: string, currentTaskDatetime: string | null) => boolean;
15
+ interface RestoreDateTimeParams extends Pick<Configuration, "storageOperations">, Pick<HandlerArgs, "tenant" | "locale"> {
16
+ task: ApwScheduleAction;
17
+ }
18
+ export declare const restoreDateTime: ({ locale, tenant, task: currentTask, storageOperations }: RestoreDateTimeParams) => Promise<void>;
19
+ interface ExecuteTaskParams extends Pick<ClientContext, "handlerClient">, Pick<Configuration, "storageOperations"> {
20
+ args: HandlerArgs;
21
+ lambdaName: string;
22
+ }
23
+ export declare const executeTask: ({ args, lambdaName, handlerClient, storageOperations }: ExecuteTaskParams) => Promise<void>;
24
+ export {};