@webiny/api-apw 0.0.0-unstable.1e66d121db → 0.0.0-unstable.611c5af35e

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 (239) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +30 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +30 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +30 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +30 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +0 -5
  14. package/ContentApwSettingsPlugin.js.map +1 -1
  15. package/crud/createChangeRequestMethods.js +4 -11
  16. package/crud/createChangeRequestMethods.js.map +1 -1
  17. package/crud/createCommentMethods.js +4 -12
  18. package/crud/createCommentMethods.js.map +1 -1
  19. package/crud/createContentReviewMethods.js +32 -86
  20. package/crud/createContentReviewMethods.js.map +1 -1
  21. package/crud/createReviewerMethods.js +4 -12
  22. package/crud/createReviewerMethods.js.map +1 -1
  23. package/crud/createWorkflowMethods.js +4 -17
  24. package/crud/createWorkflowMethods.js.map +1 -1
  25. package/crud/index.js +0 -25
  26. package/crud/index.js.map +1 -1
  27. package/crud/utils.js +0 -28
  28. package/crud/utils.js.map +1 -1
  29. package/index.d.ts +3 -3
  30. package/index.js +5 -13
  31. package/index.js.map +1 -1
  32. package/package.json +35 -35
  33. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +0 -15
  34. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  35. package/plugins/cms/apwEntryPlugins.js +0 -8
  36. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  37. package/plugins/cms/index.js +5 -10
  38. package/plugins/cms/index.js.map +1 -1
  39. package/plugins/cms/linkContentReviewToEntry.js +0 -17
  40. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  41. package/plugins/cms/linkWorkflowToEntry.js +2 -31
  42. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  43. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  44. package/plugins/cms/notifications/changeRequestNotification.js +31 -0
  45. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  46. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  47. package/plugins/cms/notifications/commentNotification.js +31 -0
  48. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  49. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  50. package/plugins/cms/notifications/contentReviewNotification.js +31 -0
  51. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  52. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  53. package/plugins/cms/notifications/contentUrl.js +53 -0
  54. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  55. package/plugins/cms/triggerContentReview.js +0 -14
  56. package/plugins/cms/triggerContentReview.js.map +1 -1
  57. package/plugins/cms/updateContentReviewStatus.js +0 -18
  58. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  59. package/plugins/cms/utils.js +2 -47
  60. package/plugins/cms/utils.js.map +1 -1
  61. package/plugins/context.js +0 -31
  62. package/plugins/context.js.map +1 -1
  63. package/plugins/graphql/changeRequest.gql.js +1 -8
  64. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  65. package/plugins/graphql/comment.gql.js +1 -8
  66. package/plugins/graphql/comment.gql.js.map +1 -1
  67. package/plugins/graphql/contentReview.gql.js +1 -20
  68. package/plugins/graphql/contentReview.gql.js.map +1 -1
  69. package/plugins/graphql/reviewer.gql.js +3 -8
  70. package/plugins/graphql/reviewer.gql.js.map +1 -1
  71. package/plugins/graphql/workflow.gql.js +1 -8
  72. package/plugins/graphql/workflow.gql.js.map +1 -1
  73. package/plugins/graphql.js +1 -16
  74. package/plugins/graphql.js.map +1 -1
  75. package/plugins/hooks/createReviewerFromIdentity.js +26 -15
  76. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  77. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -9
  78. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  79. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -8
  80. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  81. package/plugins/hooks/index.js +2 -13
  82. package/plugins/hooks/index.js.map +1 -1
  83. package/plugins/hooks/initializeContentReviewSteps.js +2 -15
  84. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  85. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  86. package/plugins/hooks/initializeNotifications.js +15 -0
  87. package/plugins/hooks/initializeNotifications.js.map +1 -0
  88. package/plugins/hooks/listContentReviews.d.ts +1 -1
  89. package/plugins/hooks/listContentReviews.js +9 -33
  90. package/plugins/hooks/listContentReviews.js.map +1 -1
  91. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  92. package/plugins/hooks/notifications/appUrl.js +18 -0
  93. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  94. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  95. package/plugins/hooks/notifications/changeRequestAfterCreate.js +116 -0
  96. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  97. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  98. package/plugins/hooks/notifications/changeRequestUrl.js +27 -0
  99. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  100. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  101. package/plugins/hooks/notifications/commentAfterCreate.js +127 -0
  102. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  103. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  104. package/plugins/hooks/notifications/commentUrl.js +27 -0
  105. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  106. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  107. package/plugins/hooks/notifications/contentReviewAfterCreate.js +99 -0
  108. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  109. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  110. package/plugins/hooks/notifications/contentReviewUrl.js +26 -0
  111. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  112. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  113. package/plugins/hooks/notifications/contentUrl.js +24 -0
  114. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  115. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  116. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +21 -0
  117. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  118. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  119. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +21 -0
  120. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  121. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  122. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +21 -0
  123. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  124. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  125. package/plugins/hooks/notifications/reviewers.js +44 -0
  126. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  127. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  128. package/plugins/hooks/notifications/sendChangeRequestNotification.js +41 -0
  129. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  130. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  131. package/plugins/hooks/notifications/sendCommentNotification.js +41 -0
  132. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  133. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  134. package/plugins/hooks/notifications/sendContentReviewNotification.js +41 -0
  135. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  136. package/plugins/hooks/updatePendingChangeRequests.js +0 -8
  137. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  138. package/plugins/hooks/updateTotalComments.js +0 -9
  139. package/plugins/hooks/updateTotalComments.js.map +1 -1
  140. package/plugins/hooks/validateChangeRequest.js +25 -16
  141. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  142. package/plugins/hooks/validateComment.js +11 -12
  143. package/plugins/hooks/validateComment.js.map +1 -1
  144. package/plugins/hooks/validateContentReview.js +0 -6
  145. package/plugins/hooks/validateContentReview.js.map +1 -1
  146. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -15
  147. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  148. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  149. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  150. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  151. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  152. package/plugins/pageBuilder/index.js +5 -8
  153. package/plugins/pageBuilder/index.js.map +1 -1
  154. package/plugins/pageBuilder/linkContentReviewToPage.js +0 -16
  155. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  156. package/plugins/pageBuilder/linkWorkflowToPage.js +1 -31
  157. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  158. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  159. package/plugins/pageBuilder/notifications/changeRequestNotification.js +31 -0
  160. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  161. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  162. package/plugins/pageBuilder/notifications/commentNotification.js +31 -0
  163. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  164. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  165. package/plugins/pageBuilder/notifications/contentReviewNotification.js +31 -0
  166. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  167. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  168. package/plugins/pageBuilder/notifications/contentUrl.js +47 -0
  169. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  170. package/plugins/pageBuilder/triggerContentReview.js +0 -11
  171. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  172. package/plugins/pageBuilder/updateContentReviewStatus.js +0 -12
  173. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  174. package/plugins/pageBuilder/utils.js +1 -35
  175. package/plugins/pageBuilder/utils.js.map +1 -1
  176. package/plugins/utils.d.ts +0 -1
  177. package/plugins/utils.js +1 -50
  178. package/plugins/utils.js.map +1 -1
  179. package/scheduler/createScheduleActionMethods.js +1 -20
  180. package/scheduler/createScheduleActionMethods.js.map +1 -1
  181. package/scheduler/handlers/executeAction/index.js +9 -33
  182. package/scheduler/handlers/executeAction/index.js.map +1 -1
  183. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +0 -5
  184. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  185. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +0 -21
  186. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  187. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +4 -27
  188. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  189. package/scheduler/handlers/executeAction/security.js +0 -11
  190. package/scheduler/handlers/executeAction/security.js.map +1 -1
  191. package/scheduler/handlers/scheduleAction/index.js +5 -25
  192. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  193. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -23
  194. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  195. package/scheduler/handlers/utils.js +3 -40
  196. package/scheduler/handlers/utils.js.map +1 -1
  197. package/scheduler/index.js +0 -3
  198. package/scheduler/index.js.map +1 -1
  199. package/scheduler/types.js +0 -6
  200. package/scheduler/types.js.map +1 -1
  201. package/storageOperations/changeRequestStorageOperations.js +0 -19
  202. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  203. package/storageOperations/commentStorageOperations.js +0 -21
  204. package/storageOperations/commentStorageOperations.js.map +1 -1
  205. package/storageOperations/contentReviewStorageOperations.js +0 -17
  206. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  207. package/storageOperations/index.js +0 -14
  208. package/storageOperations/index.js.map +1 -1
  209. package/storageOperations/models/changeRequest.model.js +0 -9
  210. package/storageOperations/models/changeRequest.model.js.map +1 -1
  211. package/storageOperations/models/comment.model.js +0 -8
  212. package/storageOperations/models/comment.model.js.map +1 -1
  213. package/storageOperations/models/contentModelPluginFactory.js +0 -5
  214. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  215. package/storageOperations/models/contentReview.model.js +0 -26
  216. package/storageOperations/models/contentReview.model.js.map +1 -1
  217. package/storageOperations/models/index.js +2 -24
  218. package/storageOperations/models/index.js.map +1 -1
  219. package/storageOperations/models/reviewer.model.js +17 -9
  220. package/storageOperations/models/reviewer.model.js.map +1 -1
  221. package/storageOperations/models/utils.js +0 -4
  222. package/storageOperations/models/utils.js.map +1 -1
  223. package/storageOperations/models/workflow.model.js +0 -23
  224. package/storageOperations/models/workflow.model.js.map +1 -1
  225. package/storageOperations/reviewerStorageOperations.js +11 -20
  226. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  227. package/storageOperations/workflowStorageOperations.js +0 -19
  228. package/storageOperations/workflowStorageOperations.js.map +1 -1
  229. package/types.d.ts +21 -9
  230. package/types.js +0 -14
  231. package/types.js.map +1 -1
  232. package/utils/contentApwSettingsPlugin.js +0 -6
  233. package/utils/contentApwSettingsPlugin.js.map +1 -1
  234. package/utils/errors.js +0 -17
  235. package/utils/errors.js.map +1 -1
  236. package/utils/fieldResolver.js +2 -12
  237. package/utils/fieldResolver.js.map +1 -1
  238. package/utils/resolve.js +0 -3
  239. package/utils/resolve.js.map +1 -1
package/plugins/utils.js CHANGED
@@ -1,50 +1,32 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.workflowByPrecedenceDesc = exports.workflowByCreatedOnDesc = exports.updateContentReviewStep = exports.updateContentReview = exports.safelyGetContentReview = exports.isInstallationPending = exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getNanoid = exports.getContentReviewStepInitialStatus = exports.extractContentReviewIdAndStep = void 0;
9
-
7
+ exports.workflowByPrecedenceDesc = exports.workflowByCreatedOnDesc = exports.updateContentReviewStep = exports.updateContentReview = exports.safelyGetContentReview = exports.isInstallationPending = exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getContentReviewStepInitialStatus = exports.extractContentReviewIdAndStep = void 0;
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _get = _interopRequireDefault(require("lodash/get"));
13
-
14
- var _nanoid = require("nanoid");
15
-
16
10
  var _types = require("../types");
17
-
18
- const ALPHANUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
19
- const getNanoid = (0, _nanoid.customAlphabet)(ALPHANUMERIC, 10);
20
- exports.getNanoid = getNanoid;
21
-
22
11
  const hasReviewer = async params => {
23
12
  const {
24
13
  getReviewer,
25
14
  identity,
26
15
  step
27
16
  } = params;
28
-
29
17
  for (const stepReviewer of step.reviewers) {
30
18
  const entry = await getReviewer(stepReviewer.id);
31
-
32
19
  if (entry.identityId === identity.id) {
33
20
  return true;
34
21
  }
35
22
  }
36
-
37
23
  return false;
38
24
  };
39
-
40
25
  exports.hasReviewer = hasReviewer;
41
-
42
26
  const getValue = (object, key) => {
43
27
  return (0, _get.default)(object, `values.${key}`);
44
28
  };
45
-
46
29
  exports.getValue = getValue;
47
-
48
30
  const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
49
31
  /**
50
32
  * Always set first step 'active' by default.
@@ -52,32 +34,23 @@ const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepSta
52
34
  if (index === 0) {
53
35
  return _types.ApwContentReviewStepStatus.ACTIVE;
54
36
  }
55
-
56
37
  const previousStep = workflowSteps[index - 1];
57
-
58
38
  if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStep.type !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
59
39
  return _types.ApwContentReviewStepStatus.ACTIVE;
60
40
  }
61
-
62
41
  return _types.ApwContentReviewStepStatus.INACTIVE;
63
42
  };
64
-
65
43
  exports.getContentReviewStepInitialStatus = getContentReviewStepInitialStatus;
66
-
67
44
  const getNextStepStatus = (previousStepType, previousStepStatus) => {
68
45
  if (previousStepStatus === _types.ApwContentReviewStepStatus.DONE) {
69
46
  return _types.ApwContentReviewStepStatus.ACTIVE;
70
47
  }
71
-
72
48
  if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStepType !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
73
49
  return _types.ApwContentReviewStepStatus.ACTIVE;
74
50
  }
75
-
76
51
  return _types.ApwContentReviewStepStatus.INACTIVE;
77
52
  };
78
-
79
53
  exports.getNextStepStatus = getNextStepStatus;
80
-
81
54
  const extractContentReviewIdAndStep = step => {
82
55
  /*
83
56
  * Get associated content review entry.
@@ -89,15 +62,12 @@ const extractContentReviewIdAndStep = step => {
89
62
  stepId
90
63
  };
91
64
  };
92
-
93
65
  exports.extractContentReviewIdAndStep = extractContentReviewIdAndStep;
94
-
95
66
  const safelyGetContentReview = async ({
96
67
  id,
97
68
  contentReviewMethods
98
69
  }) => {
99
70
  let contentReviewEntry = null;
100
-
101
71
  try {
102
72
  contentReviewEntry = await contentReviewMethods.get(id);
103
73
  } catch (e) {
@@ -105,12 +75,9 @@ const safelyGetContentReview = async ({
105
75
  throw e;
106
76
  }
107
77
  }
108
-
109
78
  return contentReviewEntry;
110
79
  };
111
-
112
80
  exports.safelyGetContentReview = safelyGetContentReview;
113
-
114
81
  const updateContentReview = async ({
115
82
  contentReviewMethods,
116
83
  id,
@@ -120,31 +87,24 @@ const updateContentReview = async ({
120
87
  id,
121
88
  contentReviewMethods
122
89
  });
123
-
124
90
  if (contentReviewEntry) {
125
91
  const newContentReviewData = getNewContentReviewData(contentReviewEntry);
126
92
  /**
127
93
  * Update content review entry.
128
94
  */
129
-
130
95
  await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);
131
96
  }
132
97
  };
133
-
134
98
  exports.updateContentReview = updateContentReview;
135
-
136
99
  const updateContentReviewStep = (steps, stepId, updater) => {
137
100
  return steps.map(step => {
138
101
  if (step.id === stepId) {
139
102
  return (0, _objectSpread2.default)({}, updater(step));
140
103
  }
141
-
142
104
  return step;
143
105
  });
144
106
  };
145
-
146
107
  exports.updateContentReviewStep = updateContentReviewStep;
147
-
148
108
  const isInstallationPending = ({
149
109
  tenancy,
150
110
  i18n
@@ -154,40 +114,31 @@ const isInstallationPending = ({
154
114
  * installation is completed. So, we need to skip "APW" creation till then.
155
115
  */
156
116
  const tenant = tenancy.getCurrentTenant();
157
-
158
117
  if (!tenant) {
159
118
  return true;
160
119
  }
161
-
162
120
  return !i18n.getContentLocale();
163
121
  };
164
-
165
122
  exports.isInstallationPending = isInstallationPending;
166
123
  const WORKFLOW_PRECEDENCE = {
167
124
  [_types.WorkflowScopeTypes.DEFAULT]: 0,
168
125
  [_types.WorkflowScopeTypes.CUSTOM]: 1
169
126
  };
170
-
171
127
  const workflowByPrecedenceDesc = (a, b) => {
172
128
  const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];
173
129
  const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];
174
130
  /**
175
131
  * In descending order of workflow precedence.
176
132
  */
177
-
178
133
  return scoreB - scoreA;
179
134
  };
180
-
181
135
  exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
182
-
183
136
  const workflowByCreatedOnDesc = (a, b) => {
184
137
  const createdOnA = (0, _get.default)(a, "createdOn");
185
138
  const createdOnB = (0, _get.default)(b, "createdOn");
186
139
  /**
187
140
  * In descending order of workflow createdOn i.e. the most recent one first.
188
141
  */
189
-
190
142
  return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
191
143
  };
192
-
193
144
  exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
@@ -1 +1 @@
1
- {"version":3,"names":["ALPHANUMERIC","getNanoid","customAlphabet","hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { customAlphabet } from \"nanoid\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nconst ALPHANUMERIC = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\nexport const getNanoid = customAlphabet(ALPHANUMERIC, 10);\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AAcA,MAAMA,YAAY,GAAG,gEAArB;AACO,MAAMC,SAAS,GAAG,IAAAC,sBAAA,EAAeF,YAAf,EAA6B,EAA7B,CAAlB;;;AAcA,MAAMG,WAAW,GAAG,MAAOC,MAAP,IAAwD;EAC/E,MAAM;IAAEC,WAAF;IAAeC,QAAf;IAAyBC;EAAzB,IAAkCH,MAAxC;;EACA,KAAK,MAAMI,YAAX,IAA2BD,IAAI,CAACE,SAAhC,EAA2C;IACvC,MAAMC,KAAK,GAAG,MAAML,WAAW,CAACG,YAAY,CAACG,EAAd,CAA/B;;IAEA,IAAID,KAAK,CAACE,UAAN,KAAqBN,QAAQ,CAACK,EAAlC,EAAsC;MAClC,OAAO,IAAP;IACH;EACJ;;EAED,OAAO,KAAP;AACH,CAXM;;;;AAaA,MAAME,QAAQ,GAAG,CAACC,MAAD,EAA8BC,GAA9B,KAA8C;EAClE,OAAO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ACD,IAAI,CAACG,gBAAL,EAAR;AACH,CAXM;;;AAaP,MAAMC,mBAAmB,GAAG;EACxB,CAACC,yBAAA,CAAmBC,OAApB,GAA8B,CADN;EAExB,CAACD,yBAAA,CAAmBE,MAApB,GAA6B;AAFL,CAA5B;;AAKO,MAAMC,wBAAwB,GAAG,CAACC,CAAD,EAAiBC,CAAjB,KAAoC;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAF,CAAQzC,IAAT,CAAlC;EACA,MAAM0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAF,CAAQzC,IAAT,CAAlC;EACA;AACJ;AACA;;EACI,OAAO0C,MAAM,GAAGF,MAAhB;AACH,CAPM;;;;AASA,MAAMG,uBAAuB,GAAG,CAACL,CAAD,EAAiBC,CAAjB,KAAoC;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAA,EAAI8C,CAAJ,EAAO,WAAP,CAAnB;EACA,MAAMO,UAAU,GAAG,IAAArD,YAAA,EAAI+C,CAAJ,EAAO,WAAP,CAAnB;EACA;AACJ;AACA;;EACI,OAAO,IAAIO,IAAJ,CAASD,UAAT,EAAqBE,OAArB,KAAiC,IAAID,IAAJ,CAASF,UAAT,EAAqBG,OAArB,EAAxC;AACH,CAPM"}
1
+ {"version":3,"names":["hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;AAAA;AAGA;AA0BO,MAAMA,WAAW,GAAG,MAAOC,MAA0B,IAAuB;EAC/E,MAAM;IAAEC,WAAW;IAAEC,QAAQ;IAAEC;EAAK,CAAC,GAAGH,MAAM;EAC9C,KAAK,MAAMI,YAAY,IAAID,IAAI,CAACE,SAAS,EAAE;IACvC,MAAMC,KAAK,GAAG,MAAML,WAAW,CAACG,YAAY,CAACG,EAAE,CAAC;IAEhD,IAAID,KAAK,CAACE,UAAU,KAAKN,QAAQ,CAACK,EAAE,EAAE;MAClC,OAAO,IAAI;IACf;EACJ;EAEA,OAAO,KAAK;AAChB,CAAC;AAAC;AAEK,MAAME,QAAQ,GAAG,CAACC,MAA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AEA,OAAO,CAACD,IAAI,CAACG,gBAAgB,EAAE;AACnC,CAAC;AAAC;AAEF,MAAMC,mBAAmB,GAAG;EACxB,CAACC,yBAAkB,CAACC,OAAO,GAAG,CAAC;EAC/B,CAACD,yBAAkB,CAACE,MAAM,GAAG;AACjC,CAAC;AAEM,MAAMC,wBAAwB,GAAG,CAACC,CAAc,EAAEC,CAAc,KAAK;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAK,CAACzC,IAAI,CAAC;EAChD,MAAM0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAK,CAACzC,IAAI,CAAC;EAChD;AACJ;AACA;EACI,OAAO0C,MAAM,GAAGF,MAAM;AAC1B,CAAC;AAAC;AAEK,MAAMG,uBAAuB,GAAG,CAACL,CAAc,EAAEC,CAAc,KAAK;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAG,EAAC8C,CAAC,EAAE,WAAW,CAAC;EACtC,MAAMO,UAAU,GAAG,IAAArD,YAAG,EAAC+C,CAAC,EAAE,WAAW,CAAC;EACtC;AACJ;AACA;EACI,OAAO,IAAIO,IAAI,CAACD,UAAU,CAAC,CAACE,OAAO,EAAE,GAAG,IAAID,IAAI,CAACF,UAAU,CAAC,CAACG,OAAO,EAAE;AAC1E,CAAC;AAAC"}
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createScheduleActionMethods = createScheduleActionMethods;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _mdbid = _interopRequireDefault(require("mdbid"));
13
-
14
10
  var _fields = require("@commodo/fields");
15
-
16
11
  var _validation = require("@webiny/validation");
17
-
18
12
  var _types = require("./types");
19
-
20
13
  /**
21
14
  * Package mdbid does not have types.
22
15
  */
@@ -26,6 +19,7 @@ var _types = require("./types");
26
19
  * Package @commodo/fields does not have types.
27
20
  */
28
21
  // @ts-ignore
22
+
29
23
  const CreateDataModel = (0, _fields.withFields)(instance => {
30
24
  return {
31
25
  datetime: (0, _fields.string)({
@@ -47,13 +41,11 @@ const CreateDataModel = (0, _fields.withFields)(instance => {
47
41
  } else if (!!value) {
48
42
  return true;
49
43
  }
50
-
51
44
  throw new Error(`There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`);
52
45
  }
53
46
  })
54
47
  };
55
48
  })();
56
-
57
49
  function createScheduleActionMethods({
58
50
  storageOperations,
59
51
  getIdentity,
@@ -68,7 +60,6 @@ function createScheduleActionMethods({
68
60
  locale
69
61
  };
70
62
  };
71
-
72
63
  return {
73
64
  async get(id) {
74
65
  return storageOperations.get({
@@ -77,13 +68,11 @@ function createScheduleActionMethods({
77
68
  }, getTenantAndLocale())
78
69
  });
79
70
  },
80
-
81
71
  async list(params) {
82
72
  return storageOperations.list((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
83
73
  where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.where), getTenantAndLocale())
84
74
  }));
85
75
  },
86
-
87
76
  async create(input) {
88
77
  const createDataModel = new CreateDataModel().populate(input);
89
78
  await createDataModel.validate();
@@ -106,44 +95,36 @@ function createScheduleActionMethods({
106
95
  input
107
96
  });
108
97
  },
109
-
110
98
  async update(id, data) {
111
99
  const updateDataModel = new CreateDataModel().populate(data);
112
100
  await updateDataModel.validate();
113
101
  const original = await this.get(id);
114
-
115
102
  if (!original) {
116
103
  throw new Error("Not found!");
117
104
  }
118
-
119
105
  return await storageOperations.update({
120
106
  item: original,
121
107
  input: data
122
108
  });
123
109
  },
124
-
125
110
  async delete(id) {
126
111
  await storageOperations.delete((0, _objectSpread2.default)({
127
112
  id
128
113
  }, getTenantAndLocale()));
129
114
  return true;
130
115
  },
131
-
132
116
  async getCurrentTask() {
133
117
  return await storageOperations.getCurrentTask({
134
118
  where: (0, _objectSpread2.default)({}, getTenantAndLocale())
135
119
  });
136
120
  },
137
-
138
121
  async updateCurrentTask(item) {
139
122
  return await storageOperations.updateCurrentTask({
140
123
  item
141
124
  });
142
125
  },
143
-
144
126
  async deleteCurrentTask() {
145
127
  return await storageOperations.deleteCurrentTask((0, _objectSpread2.default)({}, getTenantAndLocale()));
146
128
  }
147
-
148
129
  };
149
130
  }
@@ -1 +1 @@
1
- {"version":3,"names":["CreateDataModel","withFields","instance","datetime","string","validation","create","type","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","value","Error","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","input","createDataModel","populate","validate","mdbid","identity","data","toJSON","scheduleAction","createdOn","Date","toISOString","savedOn","createdBy","displayName","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport {\n ApwContentTypes,\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n ApwScheduleActionTypes,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\n\nconst CreateDataModel = withFields((instance: any) => {\n return {\n datetime: string({\n validation: validation.create(`required`)\n }),\n type: string({\n validation: validation.create(\n `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`\n )\n }),\n action: string({\n validation: validation.create(\n `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`\n )\n }),\n entryId: string({\n validation: validation.create(`required`)\n }),\n modelId: string({\n validation: (value: string) => {\n if (instance.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!value) {\n return true;\n }\n throw new Error(\n `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\n );\n }\n })\n };\n})();\n\ninterface GetTenantAndLocaleResult {\n tenant: string;\n locale: string;\n}\n\nexport function createScheduleActionMethods({\n storageOperations,\n getIdentity,\n getTenant,\n getLocale\n}: CreateScheduleActionParams): ApwScheduleActionCrud {\n const getTenantAndLocale = (): GetTenantAndLocaleResult => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n return {\n tenant,\n locale\n };\n };\n return {\n async get(id) {\n return storageOperations.get({\n where: {\n id,\n ...getTenantAndLocale()\n }\n });\n },\n async list(params) {\n return storageOperations.list({\n ...params,\n where: {\n ...params.where,\n ...getTenantAndLocale()\n }\n });\n },\n async create(input) {\n const createDataModel = new CreateDataModel().populate(input);\n\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = getIdentity();\n\n const data: ApwScheduleActionData = await createDataModel.toJSON();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, data) {\n const updateDataModel = new CreateDataModel().populate(data);\n\n await updateDataModel.validate();\n\n const original = await this.get(id);\n\n if (!original) {\n throw new Error(\"Not found!\");\n }\n\n return await storageOperations.update({ item: original, input: data });\n },\n async delete(id: string) {\n await storageOperations.delete({ id, ...getTenantAndLocale() });\n\n return true;\n },\n async getCurrentTask() {\n return await storageOperations.getCurrentTask({ where: { ...getTenantAndLocale() } });\n },\n async updateCurrentTask(item) {\n return await storageOperations.updateCurrentTask({ item });\n },\n async deleteCurrentTask() {\n return await storageOperations.deleteCurrentTask({ ...getTenantAndLocale() });\n }\n };\n}\n"],"mappings":";;;;;;;;;;;AAIA;;AAKA;;AACA;;AACA;;A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AjB,EAAuB;MACnB,MAAMW,eAAe,GAAG,IAAIlD,eAAJ,GAAsBmC,QAAtB,CAA+BI,IAA/B,CAAxB;MAEA,MAAMW,eAAe,CAACd,QAAhB,EAAN;MAEA,MAAMe,QAAQ,GAAG,MAAM,KAAKtB,GAAL,CAASH,EAAT,CAAvB;;MAEA,IAAI,CAACyB,QAAL,EAAe;QACX,MAAM,IAAIjC,KAAJ,CAAU,YAAV,CAAN;MACH;;MAED,OAAO,MAAME,iBAAiB,CAAC6B,MAAlB,CAAyB;QAAED,IAAI,EAAEG,QAAR;QAAkBlB,KAAK,EAAEM;MAAzB,CAAzB,CAAb;IACH,CA1DE;;IA2DH,MAAMa,MAAN,CAAa1B,EAAb,EAAyB;MACrB,MAAMN,iBAAiB,CAACgC,MAAlB;QAA2B1B;MAA3B,GAAkCF,kBAAkB,EAApD,EAAN;MAEA,OAAO,IAAP;IACH,CA/DE;;IAgEH,MAAM6B,cAAN,GAAuB;MACnB,OAAO,MAAMjC,iBAAiB,CAACiC,cAAlB,CAAiC;QAAEvB,KAAK,kCAAON,kBAAkB,EAAzB;MAAP,CAAjC,CAAb;IACH,CAlEE;;IAmEH,MAAM8B,iBAAN,CAAwBN,IAAxB,EAA8B;MAC1B,OAAO,MAAM5B,iBAAiB,CAACkC,iBAAlB,CAAoC;QAAEN;MAAF,CAApC,CAAb;IACH,CArEE;;IAsEH,MAAMO,iBAAN,GAA0B;MACtB,OAAO,MAAMnC,iBAAiB,CAACmC,iBAAlB,iCAAyC/B,kBAAkB,EAA3D,EAAb;IACH;;EAxEE,CAAP;AA0EH"}
1
+ {"version":3,"names":["CreateDataModel","withFields","instance","datetime","string","validation","create","type","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","value","Error","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","input","createDataModel","populate","validate","mdbid","identity","data","toJSON","scheduleAction","createdOn","Date","toISOString","savedOn","createdBy","displayName","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport {\n ApwContentTypes,\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n ApwScheduleActionTypes,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\n\nconst CreateDataModel = withFields((instance: any) => {\n return {\n datetime: string({\n validation: validation.create(`required`)\n }),\n type: string({\n validation: validation.create(\n `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`\n )\n }),\n action: string({\n validation: validation.create(\n `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`\n )\n }),\n entryId: string({\n validation: validation.create(`required`)\n }),\n modelId: string({\n validation: (value: string) => {\n if (instance.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!value) {\n return true;\n }\n throw new Error(\n `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\n );\n }\n })\n };\n})();\n\ninterface GetTenantAndLocaleResult {\n tenant: string;\n locale: string;\n}\n\nexport function createScheduleActionMethods({\n storageOperations,\n getIdentity,\n getTenant,\n getLocale\n}: CreateScheduleActionParams): ApwScheduleActionCrud {\n const getTenantAndLocale = (): GetTenantAndLocaleResult => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n return {\n tenant,\n locale\n };\n };\n return {\n async get(id) {\n return storageOperations.get({\n where: {\n id,\n ...getTenantAndLocale()\n }\n });\n },\n async list(params) {\n return storageOperations.list({\n ...params,\n where: {\n ...params.where,\n ...getTenantAndLocale()\n }\n });\n },\n async create(input) {\n const createDataModel = new CreateDataModel().populate(input);\n\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = getIdentity();\n\n const data: ApwScheduleActionData = await createDataModel.toJSON();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, data) {\n const updateDataModel = new CreateDataModel().populate(data);\n\n await updateDataModel.validate();\n\n const original = await this.get(id);\n\n if (!original) {\n throw new Error(\"Not found!\");\n }\n\n return await storageOperations.update({ item: original, input: data });\n },\n async delete(id: string) {\n await storageOperations.delete({ id, ...getTenantAndLocale() });\n\n return true;\n },\n async getCurrentTask() {\n return await storageOperations.getCurrentTask({ where: { ...getTenantAndLocale() } });\n },\n async updateCurrentTask(item) {\n return await storageOperations.updateCurrentTask({ item });\n },\n async deleteCurrentTask() {\n return await storageOperations.deleteCurrentTask({ ...getTenantAndLocale() });\n }\n };\n}\n"],"mappings":";;;;;;;;AAIA;AAKA;AACA;AACA;AAXA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAYA,MAAMA,eAAe,GAAG,IAAAC,kBAAU,EAAEC,QAAa,IAAK;EAClD,OAAO;IACHC,QAAQ,EAAE,IAAAC,cAAM,EAAC;MACbC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAE,UAAS;IAC5C,CAAC,CAAC;IACFC,IAAI,EAAE,IAAAH,cAAM,EAAC;MACTC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CACxB,eAAcE,sBAAe,CAACC,IAAK,IAAGD,sBAAe,CAACE,SAAU,EAAC;IAE1E,CAAC,CAAC;IACFC,MAAM,EAAE,IAAAP,cAAM,EAAC;MACXC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CACxB,eAAcM,6BAAsB,CAACC,OAAQ,IAAGD,6BAAsB,CAACE,SAAU,EAAC;IAE3F,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MjC,iBAAiB,CAACiC,cAAc,CAAC;QAAEvB,KAAK,kCAAON,kBAAkB,EAAE;MAAG,CAAC,CAAC;IACzF,CAAC;IACD,MAAM8B,iBAAiB,CAACN,IAAI,EAAE;MAC1B,OAAO,MAAM5B,iBAAiB,CAACkC,iBAAiB,CAAC;QAAEN;MAAK,CAAC,CAAC;IAC9D,CAAC;IACD,MAAMO,iBAAiB,GAAG;MACtB,OAAO,MAAMnC,iBAAiB,CAACmC,iBAAiB,iCAAM/B,kBAAkB,EAAE,EAAG;IACjF;EACJ,CAAC;AACL"}
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.executeActionHandlerPlugins = void 0;
7
-
8
7
  var _utils = require("../utils");
9
-
10
8
  var _api = require("@webiny/api");
11
-
12
9
  var _PageBuilderGraphQL = require("./plugins/PageBuilderGraphQL");
13
-
14
10
  var _HeadlessCMSGraphQL = require("./plugins/HeadlessCMSGraphQL");
15
-
16
11
  var _ApplicationGraphQL = require("./plugins/ApplicationGraphQL");
17
-
18
12
  var _handler = require("@webiny/handler");
19
-
20
13
  /**
21
14
  * Handler that execute the provided action(s) for the schedule action workflow.
22
15
  */
@@ -30,35 +23,27 @@ const createExecuteActionLambda = params => {
30
23
  }) => {
31
24
  const log = console.log;
32
25
  const applicationGraphQLPlugins = context.plugins.byType(_ApplicationGraphQL.ApplicationGraphQL.type);
33
-
34
26
  if (applicationGraphQLPlugins.length === 0) {
35
27
  console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);
36
28
  return;
37
29
  }
38
-
39
30
  const applicationGraphQLPluginCache = {};
40
-
41
31
  const getApplicationGraphQLPlugin = data => {
42
32
  const {
43
33
  type
44
34
  } = data;
45
-
46
35
  if (applicationGraphQLPluginCache[type]) {
47
36
  return applicationGraphQLPluginCache[type];
48
37
  }
49
-
50
38
  for (const plugin of applicationGraphQLPlugins) {
51
39
  if (!plugin.canUse(data)) {
52
40
  continue;
53
41
  }
54
-
55
42
  applicationGraphQLPluginCache[type] = plugin;
56
43
  return plugin;
57
44
  }
58
-
59
45
  return null;
60
46
  };
61
-
62
47
  try {
63
48
  const apwSettings = await (0, _utils.getApwSettings)();
64
49
  const {
@@ -69,16 +54,14 @@ const createExecuteActionLambda = params => {
69
54
  /**
70
55
  * If there is no datetime we bail out early.
71
56
  */
72
-
73
57
  if (!datetime || typeof datetime !== "string") {
74
58
  log(`Bailing out!!`);
75
59
  return;
76
60
  }
61
+
77
62
  /**
78
63
  * Get tasks from the DB by datetime.
79
64
  */
80
-
81
-
82
65
  const [items] = await storageOperations.list({
83
66
  where: {
84
67
  tenant,
@@ -88,28 +71,23 @@ const createExecuteActionLambda = params => {
88
71
  sort: ["datetime_ASC"],
89
72
  limit: 1000
90
73
  });
74
+
91
75
  /**
92
76
  * Execute all actions.
93
77
  */
94
-
95
78
  if (!items || items.length === 0) {
96
79
  return;
97
80
  }
98
-
99
81
  log(`Found ${items.length} actions.`);
100
-
101
82
  for (const item of items) {
102
83
  log(`Performing mutation "${item.data.action}" on "${item.data.type}" at "${item.data.datetime}"`);
103
84
  const plugin = getApplicationGraphQLPlugin(item.data);
104
-
105
85
  if (!plugin) {
106
86
  console.error(`There is no plugin to determine GraphQL endpoint and mutations for type "${item.data.type}".`);
107
87
  console.log(JSON.stringify(item));
108
88
  continue;
109
89
  }
110
-
111
90
  const name = plugin.getArn(apwSettings);
112
-
113
91
  if (!name) {
114
92
  console.error(`There is no FunctionName found for type "${item.data.type}".`);
115
93
  console.log(JSON.stringify({
@@ -118,16 +96,14 @@ const createExecuteActionLambda = params => {
118
96
  }));
119
97
  continue;
120
98
  }
121
-
122
99
  const body = plugin.getGraphQLBody(item.data);
123
-
124
100
  if (!body) {
125
101
  console.error(`There is no GraphQL body defined, in the Plugin, for type "${item.data.type}".`);
126
102
  console.log(JSON.stringify(item));
127
103
  continue;
128
- } // Perform the actual action call.
129
-
104
+ }
130
105
 
106
+ // Perform the actual action call.
131
107
  const response = await context.handlerClient.invoke({
132
108
  name,
133
109
  payload: {
@@ -147,20 +123,21 @@ const createExecuteActionLambda = params => {
147
123
  },
148
124
  await: true
149
125
  });
150
-
151
126
  if (response !== null && response !== void 0 && response.body) {
152
127
  console.log(JSON.stringify({
153
128
  body: response.body
154
129
  }, null, 2));
155
130
  continue;
156
131
  }
157
-
158
132
  console.log(JSON.stringify({
159
133
  response
160
- }, null, 2)); // TODO: Maybe update the status like error in original item in DB.
134
+ }, null, 2));
135
+
136
+ // TODO: Maybe update the status like error in original item in DB.
161
137
  }
162
138
  } catch (e) {
163
- log("[HANDLER_EXECUTE_ACTION] Error => ", e); // TODO: Maybe update the status like error in original item in DB.
139
+ log("[HANDLER_EXECUTE_ACTION] Error => ", e);
140
+ // TODO: Maybe update the status like error in original item in DB.
164
141
  }
165
142
  });
166
143
  };
@@ -168,5 +145,4 @@ const createExecuteActionLambda = params => {
168
145
  const executeActionHandlerPlugins = config => [new _api.ContextPlugin(async context => {
169
146
  context.plugins.register([new _PageBuilderGraphQL.PageBuilderGraphQL(), new _HeadlessCMSGraphQL.HeadlessCMSGraphQL()]);
170
147
  }), (0, _utils.basePlugins)(), createExecuteActionLambda(config)];
171
-
172
148
  exports.executeActionHandlerPlugins = executeActionHandlerPlugins;
@@ -1 +1 @@
1
- {"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: `/cms/manage/${locale}`,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAaA;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EACJ,CAnIM,CAAP;AAoIH,CAvID;;AAyIO,MAAMC,2BAA2B,GAAIC,MAAD,IAA2B,CAClE,IAAIC,kBAAJ,CAAkB,MAAMlD,OAAN,IAAiB;EAC/BA,OAAO,CAACI,OAAR,CAAgB+C,QAAhB,CAAyB,CAAC,IAAIC,sCAAJ,EAAD,EAA2B,IAAIC,sCAAJ,EAA3B,CAAzB;AACH,CAFD,CADkE,EAIlE,IAAAC,kBAAA,GAJkE,EAKlE3D,yBAAyB,CAACsD,MAAD,CALyC,CAA/D"}
1
+ {"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: `/cms/manage/${locale}`,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAqB,IAAK;EACzD,MAAM;IAAEC;EAAkB,CAAC,GAAGD,MAAM;EAEpC,OAAO,IAAAE,oBAAW,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5D,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvB,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAO,CAACC,MAAM,CACpDC,sCAAkB,CAACC,IAAI,CAC1B;IAED,IAAIJ,yBAAyB,CAACK,MAAM,KAAK,CAAC,EAAE;MACxCN,OAAO,CAACO,KAAK,CAAE,mEAAkE,CAAC;MAClF;IACJ;IAEA,MAAMC,6BAAiE,GAAG,CAAC,CAAC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X1B,MAAM,EAAES,IAAI,CAACT,MAAM;gBACnBC,MAAM,EAAEQ,IAAI,CAACR;cACjB,CAAC,CAAC;cACF,CAAC,UAAU,GAAGA,MAAM;cACpB,CAAC,eAAe,GAAI,WAAUD,MAAO,YAAWA,MAAO;YAC3D,CAAC;YACDgB,IAAI,EAAEL,IAAI,CAACC,SAAS,CAACI,IAAI;UAC7B,CAAC;UACDW,KAAK,EAAE;QACX,CAAC,CAAC;QACF,IAAIT,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEF,IAAI,EAAE;UAChBjC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;YAAEI,IAAI,EAAEE,QAAQ,CAACF;UAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;UAC7D;QACJ;QACAjC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;UAAEM;QAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;;QAElD;MACJ;IACJ,CAAC,CAAC,OAAOU,CAAC,EAAE;MACR9C,GAAG,CAAC,oCAAoC,EAAE8C,CAAC,CAAC;MAC5C;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAMC,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMlD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAAC+C,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACb3D,yBAAyB,CAACsD,MAAM,CAAC,CACpC;AAAC"}
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.ApplicationGraphQL = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
10
  class ApplicationGraphQL extends _Plugin.Plugin {}
15
-
16
11
  exports.ApplicationGraphQL = ApplicationGraphQL;
17
12
  (0, _defineProperty2.default)(ApplicationGraphQL, "type", "apw.scheduler.applicationGraphQL");
@@ -1 +1 @@
1
- {"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAeA,kBAAf,SAA0CC,cAA1C,CAAiD;;;8BAAlCD,kB,UAC6B,kC"}
1
+ {"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;AAAA;AASO,MAAeA,kBAAkB,SAASC,cAAM,CAAC;AAQvD;AAAA,8BARqBD,kBAAkB,UACW,kCAAkC"}