@webiny/api-apw 5.34.8 → 5.35.0-beta.1

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 (216) hide show
  1. package/ApwChangeRequestNotification.js +0 -10
  2. package/ApwChangeRequestNotification.js.map +1 -1
  3. package/ApwCommentNotification.js +0 -10
  4. package/ApwCommentNotification.js.map +1 -1
  5. package/ApwContentReviewNotification.js +0 -10
  6. package/ApwContentReviewNotification.js.map +1 -1
  7. package/ApwContentUrlPlugin.js +0 -10
  8. package/ApwContentUrlPlugin.js.map +1 -1
  9. package/ContentApwSettingsPlugin.js +0 -5
  10. package/ContentApwSettingsPlugin.js.map +1 -1
  11. package/crud/createChangeRequestMethods.js +4 -11
  12. package/crud/createChangeRequestMethods.js.map +1 -1
  13. package/crud/createCommentMethods.js +4 -12
  14. package/crud/createCommentMethods.js.map +1 -1
  15. package/crud/createContentReviewMethods.js +20 -84
  16. package/crud/createContentReviewMethods.js.map +1 -1
  17. package/crud/createReviewerMethods.js +4 -12
  18. package/crud/createReviewerMethods.js.map +1 -1
  19. package/crud/createWorkflowMethods.js +4 -17
  20. package/crud/createWorkflowMethods.js.map +1 -1
  21. package/crud/index.js +0 -25
  22. package/crud/index.js.map +1 -1
  23. package/crud/utils.js +0 -28
  24. package/crud/utils.js.map +1 -1
  25. package/index.d.ts +1 -2
  26. package/index.js +1 -15
  27. package/index.js.map +1 -1
  28. package/package.json +34 -34
  29. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +0 -15
  30. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  31. package/plugins/cms/apwEntryPlugins.js +0 -8
  32. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  33. package/plugins/cms/index.js +0 -13
  34. package/plugins/cms/index.js.map +1 -1
  35. package/plugins/cms/linkContentReviewToEntry.js +0 -17
  36. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  37. package/plugins/cms/linkWorkflowToEntry.js +2 -31
  38. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  39. package/plugins/cms/notifications/changeRequestNotification.js +0 -4
  40. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
  41. package/plugins/cms/notifications/commentNotification.js +0 -4
  42. package/plugins/cms/notifications/commentNotification.js.map +1 -1
  43. package/plugins/cms/notifications/contentReviewNotification.js +0 -4
  44. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
  45. package/plugins/cms/notifications/contentUrl.js +1 -8
  46. package/plugins/cms/notifications/contentUrl.js.map +1 -1
  47. package/plugins/cms/triggerContentReview.js +0 -14
  48. package/plugins/cms/triggerContentReview.js.map +1 -1
  49. package/plugins/cms/updateContentReviewStatus.js +0 -18
  50. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  51. package/plugins/cms/utils.js +2 -47
  52. package/plugins/cms/utils.js.map +1 -1
  53. package/plugins/context.d.ts +0 -1
  54. package/plugins/context.js +2 -47
  55. package/plugins/context.js.map +1 -1
  56. package/plugins/graphql/changeRequest.gql.js +3 -10
  57. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  58. package/plugins/graphql/comment.gql.js +3 -10
  59. package/plugins/graphql/comment.gql.js.map +1 -1
  60. package/plugins/graphql/contentReview.gql.js +6 -25
  61. package/plugins/graphql/contentReview.gql.js.map +1 -1
  62. package/plugins/graphql/reviewer.gql.js +3 -10
  63. package/plugins/graphql/reviewer.gql.js.map +1 -1
  64. package/plugins/graphql/workflow.gql.js +3 -10
  65. package/plugins/graphql/workflow.gql.js.map +1 -1
  66. package/plugins/graphql.js +3 -18
  67. package/plugins/graphql.js.map +1 -1
  68. package/plugins/hooks/createReviewerFromIdentity.js +2 -11
  69. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  70. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -9
  71. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  72. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -8
  73. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  74. package/plugins/hooks/index.js +0 -14
  75. package/plugins/hooks/index.js.map +1 -1
  76. package/plugins/hooks/initializeContentReviewSteps.js +2 -18
  77. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  78. package/plugins/hooks/initializeNotifications.js +0 -5
  79. package/plugins/hooks/initializeNotifications.js.map +1 -1
  80. package/plugins/hooks/listContentReviews.js +0 -12
  81. package/plugins/hooks/listContentReviews.js.map +1 -1
  82. package/plugins/hooks/notifications/appUrl.js +0 -4
  83. package/plugins/hooks/notifications/appUrl.js.map +1 -1
  84. package/plugins/hooks/notifications/changeRequestAfterCreate.js +3 -36
  85. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  86. package/plugins/hooks/notifications/changeRequestUrl.js +0 -4
  87. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
  88. package/plugins/hooks/notifications/commentAfterCreate.js +3 -38
  89. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  90. package/plugins/hooks/notifications/commentUrl.js +0 -4
  91. package/plugins/hooks/notifications/commentUrl.js.map +1 -1
  92. package/plugins/hooks/notifications/contentReviewAfterCreate.js +4 -32
  93. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  94. package/plugins/hooks/notifications/contentReviewUrl.js +0 -4
  95. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
  96. package/plugins/hooks/notifications/contentUrl.js +0 -5
  97. package/plugins/hooks/notifications/contentUrl.js.map +1 -1
  98. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +0 -4
  99. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
  100. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +0 -4
  101. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
  102. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +0 -4
  103. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
  104. package/plugins/hooks/notifications/reviewers.js +15 -21
  105. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  106. package/plugins/hooks/notifications/sendChangeRequestNotification.js +0 -11
  107. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
  108. package/plugins/hooks/notifications/sendCommentNotification.js +0 -11
  109. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
  110. package/plugins/hooks/notifications/sendContentReviewNotification.js +0 -11
  111. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
  112. package/plugins/hooks/updatePendingChangeRequests.js +0 -8
  113. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  114. package/plugins/hooks/updateTotalComments.js +0 -9
  115. package/plugins/hooks/updateTotalComments.js.map +1 -1
  116. package/plugins/hooks/validateChangeRequest.js +0 -16
  117. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  118. package/plugins/hooks/validateComment.js +1 -12
  119. package/plugins/hooks/validateComment.js.map +1 -1
  120. package/plugins/hooks/validateContentReview.js +0 -6
  121. package/plugins/hooks/validateContentReview.js.map +1 -1
  122. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -15
  123. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  124. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  125. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  126. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  127. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  128. package/plugins/pageBuilder/index.js +0 -11
  129. package/plugins/pageBuilder/index.js.map +1 -1
  130. package/plugins/pageBuilder/linkContentReviewToPage.js +0 -16
  131. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  132. package/plugins/pageBuilder/linkWorkflowToPage.js +1 -31
  133. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  134. package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -4
  135. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
  136. package/plugins/pageBuilder/notifications/commentNotification.js +0 -4
  137. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
  138. package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -4
  139. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
  140. package/plugins/pageBuilder/notifications/contentUrl.js +1 -7
  141. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
  142. package/plugins/pageBuilder/triggerContentReview.js +0 -11
  143. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  144. package/plugins/pageBuilder/updateContentReviewStatus.js +0 -12
  145. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  146. package/plugins/pageBuilder/utils.js +1 -35
  147. package/plugins/pageBuilder/utils.js.map +1 -1
  148. package/plugins/utils.js +0 -43
  149. package/plugins/utils.js.map +1 -1
  150. package/scheduler/createScheduleActionMethods.js +1 -20
  151. package/scheduler/createScheduleActionMethods.js.map +1 -1
  152. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  153. package/scheduler/handlers/executeAction/index.js +9 -40
  154. package/scheduler/handlers/executeAction/index.js.map +1 -1
  155. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +0 -7
  156. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  157. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -23
  158. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  159. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +4 -28
  160. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  161. package/scheduler/handlers/executeAction/security.js +0 -11
  162. package/scheduler/handlers/executeAction/security.js.map +1 -1
  163. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  164. package/scheduler/handlers/scheduleAction/index.js +5 -25
  165. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  166. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -23
  167. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  168. package/scheduler/handlers/utils.d.ts +1 -2
  169. package/scheduler/handlers/utils.js +3 -41
  170. package/scheduler/handlers/utils.js.map +1 -1
  171. package/scheduler/index.js +0 -3
  172. package/scheduler/index.js.map +1 -1
  173. package/scheduler/types.d.ts +2 -20
  174. package/scheduler/types.js +0 -11
  175. package/scheduler/types.js.map +1 -1
  176. package/storageOperations/changeRequestStorageOperations.js +20 -39
  177. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  178. package/storageOperations/commentStorageOperations.js +23 -44
  179. package/storageOperations/commentStorageOperations.js.map +1 -1
  180. package/storageOperations/contentReviewStorageOperations.js +20 -37
  181. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  182. package/storageOperations/index.js +0 -14
  183. package/storageOperations/index.js.map +1 -1
  184. package/storageOperations/models/changeRequest.model.js +0 -9
  185. package/storageOperations/models/changeRequest.model.js.map +1 -1
  186. package/storageOperations/models/comment.model.js +0 -8
  187. package/storageOperations/models/comment.model.js.map +1 -1
  188. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
  189. package/storageOperations/models/contentModelPluginFactory.js +3 -11
  190. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  191. package/storageOperations/models/contentReview.model.js +0 -26
  192. package/storageOperations/models/contentReview.model.js.map +1 -1
  193. package/storageOperations/models/index.js +2 -28
  194. package/storageOperations/models/index.js.map +1 -1
  195. package/storageOperations/models/reviewer.model.js +0 -8
  196. package/storageOperations/models/reviewer.model.js.map +1 -1
  197. package/storageOperations/models/utils.js +0 -4
  198. package/storageOperations/models/utils.js.map +1 -1
  199. package/storageOperations/models/workflow.model.js +0 -23
  200. package/storageOperations/models/workflow.model.js.map +1 -1
  201. package/storageOperations/reviewerStorageOperations.js +23 -45
  202. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  203. package/storageOperations/workflowStorageOperations.js +20 -39
  204. package/storageOperations/workflowStorageOperations.js.map +1 -1
  205. package/types.d.ts +6 -5
  206. package/types.js +0 -14
  207. package/types.js.map +1 -1
  208. package/utils/contentApwSettingsPlugin.js +0 -6
  209. package/utils/contentApwSettingsPlugin.js.map +1 -1
  210. package/utils/errors.js +0 -17
  211. package/utils/errors.js.map +1 -1
  212. package/utils/fieldResolver.js +2 -12
  213. package/utils/fieldResolver.js.map +1 -1
  214. package/utils/resolve.d.ts +1 -1
  215. package/utils/resolve.js +0 -3
  216. package/utils/resolve.js.map +1 -1
@@ -1,52 +1,37 @@
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.updatePageSettings = exports.shouldUpdatePages = exports.hasPages = exports.getPagesDiff = exports.assignWorkflowToPage = void 0;
9
-
10
8
  var _get = _interopRequireDefault(require("lodash/get"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _types = require("../../types");
15
-
16
11
  var _utils = require("../utils");
17
-
18
12
  const isWorkflowApplicable = (page, workflow) => {
19
13
  const application = workflow.app;
20
-
21
14
  if (application !== _types.ApwWorkflowApplications.PB) {
22
15
  return false;
23
16
  }
24
-
25
17
  const scopeType = workflow.scope.type;
26
-
27
18
  if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
28
19
  return true;
29
20
  } else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
30
21
  const categories = (0, _get.default)(workflow, "scope.data.categories");
31
-
32
22
  if (Array.isArray(categories) && categories.includes(page.category)) {
33
23
  return true;
34
24
  }
35
-
36
25
  const pages = (0, _get.default)(workflow, "scope.data.pages");
37
-
38
26
  if (Array.isArray(pages) && pages.includes(page.pid)) {
39
27
  return true;
40
28
  }
41
-
42
29
  return false;
43
30
  }
44
-
45
31
  throw new _error.default(`Unknown scope type "${scopeType}".`, "UNKNOWN_SCOPE_TYPE", {
46
32
  workflow
47
33
  });
48
34
  };
49
-
50
35
  const assignWorkflowToPage = async ({
51
36
  listWorkflow,
52
37
  page
@@ -63,15 +48,14 @@ const assignWorkflowToPage = async ({
63
48
  app: _types.ApwWorkflowApplications.PB
64
49
  }
65
50
  });
51
+
66
52
  /*
67
53
  * Re-order them based on workflow scope and pre-defined rule i.e.
68
54
  * "specific" entry -> entry for a "category" -> "default".
69
55
  * There can be more than one workflow with same "scope" and "app".
70
56
  * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
71
57
  */
72
-
73
58
  const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
74
-
75
59
  for (const workflow of sortedWorkflows) {
76
60
  /**
77
61
  * Assign the first applicable workflow to the page and exit.
@@ -88,9 +72,7 @@ const assignWorkflowToPage = async ({
88
72
  throw new _error.default(`Failed to assign workflow to page "${page.pid}".`, ex.code, ex.data);
89
73
  }
90
74
  };
91
-
92
75
  exports.assignWorkflowToPage = assignWorkflowToPage;
93
-
94
76
  const hasPages = workflow => {
95
77
  const {
96
78
  app,
@@ -98,9 +80,7 @@ const hasPages = workflow => {
98
80
  } = workflow;
99
81
  return app === _types.ApwWorkflowApplications.PB && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.pages);
100
82
  };
101
-
102
83
  exports.hasPages = hasPages;
103
-
104
84
  const shouldUpdatePages = (scope, prevScope) => {
105
85
  /**
106
86
  * Bail out early if the scope is not "CUSTOM" - at that point all pages should be updated.
@@ -108,34 +88,26 @@ const shouldUpdatePages = (scope, prevScope) => {
108
88
  if (prevScope.type !== _types.WorkflowScopeTypes.CUSTOM) {
109
89
  return true;
110
90
  }
111
-
112
91
  const prevScopePages = (0, _get.default)(prevScope, "data.pages");
113
92
  const currentScopePages = (0, _get.default)(scope, "data.pages");
114
93
  /**
115
94
  * Bail out early if there were no pages assigned previously.
116
95
  */
117
-
118
96
  if (prevScopePages.length === 0) {
119
97
  return true;
120
98
  }
121
99
  /**
122
100
  * Bail out early if number of pages has been changed.
123
101
  */
124
-
125
-
126
102
  if (currentScopePages.length !== prevScopePages.length) {
127
103
  return true;
128
104
  }
129
105
  /*
130
106
  * Check whether previous scope has the exactly same pages as in the new scope.
131
107
  */
132
-
133
-
134
108
  return !prevScopePages.every(pid => currentScopePages.includes(pid));
135
109
  };
136
-
137
110
  exports.shouldUpdatePages = shouldUpdatePages;
138
-
139
111
  const getPagesDiff = (currentPages, prevPages) => {
140
112
  const addedPages = currentPages.filter(id => !prevPages.includes(id));
141
113
  const removedPages = prevPages.filter(id => !currentPages.includes(id));
@@ -144,9 +116,7 @@ const getPagesDiff = (currentPages, prevPages) => {
144
116
  removedPages
145
117
  };
146
118
  };
147
-
148
119
  exports.getPagesDiff = getPagesDiff;
149
-
150
120
  const updatePageSettings = async ({
151
121
  getPage,
152
122
  updatePage,
@@ -161,7 +131,6 @@ const updatePageSettings = async ({
161
131
  /**
162
132
  * We can't update a page that is "locked".
163
133
  */
164
-
165
134
  if (page.locked) {
166
135
  return;
167
136
  }
@@ -169,8 +138,6 @@ const updatePageSettings = async ({
169
138
  * There can be more than one workflow with same `scope` for same `app`. That is why;
170
139
  * We'll update the workflow reference even though it already had one assign.
171
140
  */
172
-
173
-
174
141
  await updatePage(page.id, {
175
142
  settings: getNewSettings(page.settings)
176
143
  });
@@ -180,5 +147,4 @@ const updatePageSettings = async ({
180
147
  }
181
148
  }
182
149
  };
183
-
184
150
  exports.updatePageSettings = updatePageSettings;
@@ -1 +1 @@
1
- {"version":3,"names":["isWorkflowApplicable","page","workflow","application","app","ApwWorkflowApplications","PB","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","categories","get","Array","isArray","includes","category","pages","pid","WebinyError","assignWorkflowToPage","listWorkflow","entries","where","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","settings","apw","workflowId","id","contentReviewId","ex","code","data","hasPages","shouldUpdatePages","prevScope","prevScopePages","currentScopePages","length","every","getPagesDiff","currentPages","prevPages","addedPages","filter","removedPages","updatePageSettings","getPage","updatePage","uniquePageId","getNewSettings","locked","e"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport WebinyError from \"@webiny/error\";\nimport {\n ApwWorkflow,\n ApwWorkflowApplications,\n ApwWorkflowCrud,\n ApwWorkflowScope,\n PageWithWorkflow,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\nconst isWorkflowApplicable = (page: PageWithWorkflow, workflow: ApwWorkflow) => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.PB) {\n return false;\n }\n\n const scopeType = workflow.scope.type;\n\n if (scopeType === WorkflowScopeTypes.DEFAULT) {\n return true;\n } else if (scopeType === WorkflowScopeTypes.CUSTOM) {\n const categories = get(workflow, \"scope.data.categories\");\n\n if (Array.isArray(categories) && categories.includes(page.category)) {\n return true;\n }\n\n const pages = get(workflow, \"scope.data.pages\");\n if (Array.isArray(pages) && pages.includes(page.pid)) {\n return true;\n }\n return false;\n }\n throw new WebinyError(`Unknown scope type \"${scopeType}\".`, \"UNKNOWN_SCOPE_TYPE\", {\n workflow\n });\n};\n\ninterface AssignWorkflowToPageParams {\n listWorkflow: ApwWorkflowCrud[\"list\"];\n page: PageWithWorkflow;\n}\n\nexport const assignWorkflowToPage = async ({ listWorkflow, page }: AssignWorkflowToPageParams) => {\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app pageBuilder\n */\n const [entries] = await listWorkflow({\n where: {\n app: ApwWorkflowApplications.PB\n }\n });\n\n /*\n * Re-order them based on workflow scope and pre-defined rule i.e.\n * \"specific\" entry -> entry for a \"category\" -> \"default\".\n * There can be more than one workflow with same \"scope\" and \"app\".\n * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.\n */\n const sortedWorkflows = entries\n .sort(workflowByPrecedenceDesc)\n .sort(workflowByCreatedOnDesc);\n\n for (const workflow of sortedWorkflows) {\n /**\n * Assign the first applicable workflow to the page and exit.\n */\n if (isWorkflowApplicable(page, workflow)) {\n page.settings.apw = {\n workflowId: workflow.id,\n contentReviewId: null\n };\n break;\n }\n }\n } catch (ex) {\n throw new WebinyError(`Failed to assign workflow to page \"${page.pid}\".`, ex.code, ex.data);\n }\n};\n\nexport const hasPages = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.PB &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.pages)\n );\n};\n\nexport const shouldUpdatePages = (\n scope: ApwWorkflowScope,\n prevScope: ApwWorkflowScope\n): Boolean => {\n /**\n * Bail out early if the scope is not \"CUSTOM\" - at that point all pages should be updated.\n */\n if (prevScope.type !== WorkflowScopeTypes.CUSTOM) {\n return true;\n }\n const prevScopePages: string[] = get(prevScope, \"data.pages\") as unknown as string[];\n const currentScopePages: string[] = get(scope, \"data.pages\") as unknown as string[];\n /**\n * Bail out early if there were no pages assigned previously.\n */\n if (prevScopePages.length === 0) {\n return true;\n }\n /**\n * Bail out early if number of pages has been changed.\n */\n if (currentScopePages.length !== prevScopePages.length) {\n return true;\n }\n /*\n * Check whether previous scope has the exactly same pages as in the new scope.\n */\n return !prevScopePages.every(pid => currentScopePages.includes(pid));\n};\n\ninterface GetUpdatePageOpsResult {\n addedPages: string[];\n removedPages: string[];\n}\n\nexport const getPagesDiff = (\n currentPages: string[],\n prevPages: string[]\n): GetUpdatePageOpsResult => {\n const addedPages = currentPages.filter(id => !prevPages.includes(id));\n const removedPages = prevPages.filter(id => !currentPages.includes(id));\n\n return {\n addedPages,\n removedPages\n };\n};\n\ninterface UpdatePageSettingsParams {\n getPage: PageBuilderContextObject[\"getPage\"];\n updatePage: PageBuilderContextObject[\"updatePage\"];\n uniquePageId: string;\n getNewSettings: (settings: PageWithWorkflow[\"settings\"]) => PageWithWorkflow[\"settings\"];\n}\n\nexport const updatePageSettings = async ({\n getPage,\n updatePage,\n uniquePageId,\n getNewSettings\n}: UpdatePageSettingsParams) => {\n try {\n /**\n * Currently, we only assign \"workflow\" to latest page.\n */\n const page = await getPage<PageWithWorkflow>(uniquePageId);\n /**\n * We can't update a page that is \"locked\".\n */\n if (page.locked) {\n return;\n }\n /**\n * There can be more than one workflow with same `scope` for same `app`. That is why;\n * We'll update the workflow reference even though it already had one assign.\n */\n await updatePage(page.id, {\n settings: getNewSettings(page.settings)\n });\n } catch (e) {\n if (e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAQA;;AAGA,MAAMA,oBAAoB,GAAG,CAACC,IAAD,EAAyBC,QAAzB,KAAmD;EAC5E,MAAMC,WAAW,GAAGD,QAAQ,CAACE,GAA7B;;EACA,IAAID,WAAW,KAAKE,8BAAA,CAAwBC,EAA5C,EAAgD;IAC5C,OAAO,KAAP;EACH;;EAED,MAAMC,SAAS,GAAGL,QAAQ,CAACM,KAAT,CAAeC,IAAjC;;EAEA,IAAIF,SAAS,KAAKG,yBAAA,CAAmBC,OAArC,EAA8C;IAC1C,OAAO,IAAP;EACH,CAFD,MAEO,IAAIJ,SAAS,KAAKG,yBAAA,CAAmBE,MAArC,EAA6C;IAChD,MAAMC,UAAU,GAAG,IAAAC,YAAA,EAAIZ,QAAJ,EAAc,uBAAd,CAAnB;;IAEA,IAAIa,KAAK,CAACC,OAAN,CAAcH,UAAd,KAA6BA,UAAU,CAACI,QAAX,CAAoBhB,IAAI,CAACiB,QAAzB,CAAjC,EAAqE;MACjE,OAAO,IAAP;IACH;;IAED,MAAMC,KAAK,GAAG,IAAAL,YAAA,EAAIZ,QAAJ,EAAc,kBAAd,CAAd;;IACA,IAAIa,KAAK,CAACC,OAAN,CAAcG,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AkB,GAAG,OAAO;EACrCC,OADqC;EAErCC,UAFqC;EAGrCC,YAHqC;EAIrCC;AAJqC,CAAP,KAKF;EAC5B,IAAI;IACA;AACR;AACA;IACQ,MAAMtD,IAAI,GAAG,MAAMmD,OAAO,CAAmBE,YAAnB,CAA1B;IACA;AACR;AACA;;IACQ,IAAIrD,IAAI,CAACuD,MAAT,EAAiB;MACb;IACH;IACD;AACR;AACA;AACA;;;IACQ,MAAMH,UAAU,CAACpD,IAAI,CAACgC,EAAN,EAAU;MACtBH,QAAQ,EAAEyB,cAAc,CAACtD,IAAI,CAAC6B,QAAN;IADF,CAAV,CAAhB;EAGH,CAlBD,CAkBE,OAAO2B,CAAP,EAAU;IACR,IAAIA,CAAC,CAACrB,IAAF,KAAW,WAAf,EAA4B;MACxB,MAAMqB,CAAN;IACH;EACJ;AACJ,CA7BM"}
1
+ {"version":3,"names":["isWorkflowApplicable","page","workflow","application","app","ApwWorkflowApplications","PB","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","categories","get","Array","isArray","includes","category","pages","pid","WebinyError","assignWorkflowToPage","listWorkflow","entries","where","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","settings","apw","workflowId","id","contentReviewId","ex","code","data","hasPages","shouldUpdatePages","prevScope","prevScopePages","currentScopePages","length","every","getPagesDiff","currentPages","prevPages","addedPages","filter","removedPages","updatePageSettings","getPage","updatePage","uniquePageId","getNewSettings","locked","e"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport WebinyError from \"@webiny/error\";\nimport {\n ApwWorkflow,\n ApwWorkflowApplications,\n ApwWorkflowCrud,\n ApwWorkflowScope,\n PageWithWorkflow,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\nconst isWorkflowApplicable = (page: PageWithWorkflow, workflow: ApwWorkflow) => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.PB) {\n return false;\n }\n\n const scopeType = workflow.scope.type;\n\n if (scopeType === WorkflowScopeTypes.DEFAULT) {\n return true;\n } else if (scopeType === WorkflowScopeTypes.CUSTOM) {\n const categories = get(workflow, \"scope.data.categories\");\n\n if (Array.isArray(categories) && categories.includes(page.category)) {\n return true;\n }\n\n const pages = get(workflow, \"scope.data.pages\");\n if (Array.isArray(pages) && pages.includes(page.pid)) {\n return true;\n }\n return false;\n }\n throw new WebinyError(`Unknown scope type \"${scopeType}\".`, \"UNKNOWN_SCOPE_TYPE\", {\n workflow\n });\n};\n\ninterface AssignWorkflowToPageParams {\n listWorkflow: ApwWorkflowCrud[\"list\"];\n page: PageWithWorkflow;\n}\n\nexport const assignWorkflowToPage = async ({ listWorkflow, page }: AssignWorkflowToPageParams) => {\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app pageBuilder\n */\n const [entries] = await listWorkflow({\n where: {\n app: ApwWorkflowApplications.PB\n }\n });\n\n /*\n * Re-order them based on workflow scope and pre-defined rule i.e.\n * \"specific\" entry -> entry for a \"category\" -> \"default\".\n * There can be more than one workflow with same \"scope\" and \"app\".\n * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.\n */\n const sortedWorkflows = entries\n .sort(workflowByPrecedenceDesc)\n .sort(workflowByCreatedOnDesc);\n\n for (const workflow of sortedWorkflows) {\n /**\n * Assign the first applicable workflow to the page and exit.\n */\n if (isWorkflowApplicable(page, workflow)) {\n page.settings.apw = {\n workflowId: workflow.id,\n contentReviewId: null\n };\n break;\n }\n }\n } catch (ex) {\n throw new WebinyError(`Failed to assign workflow to page \"${page.pid}\".`, ex.code, ex.data);\n }\n};\n\nexport const hasPages = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.PB &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.pages)\n );\n};\n\nexport const shouldUpdatePages = (\n scope: ApwWorkflowScope,\n prevScope: ApwWorkflowScope\n): Boolean => {\n /**\n * Bail out early if the scope is not \"CUSTOM\" - at that point all pages should be updated.\n */\n if (prevScope.type !== WorkflowScopeTypes.CUSTOM) {\n return true;\n }\n const prevScopePages: string[] = get(prevScope, \"data.pages\") as unknown as string[];\n const currentScopePages: string[] = get(scope, \"data.pages\") as unknown as string[];\n /**\n * Bail out early if there were no pages assigned previously.\n */\n if (prevScopePages.length === 0) {\n return true;\n }\n /**\n * Bail out early if number of pages has been changed.\n */\n if (currentScopePages.length !== prevScopePages.length) {\n return true;\n }\n /*\n * Check whether previous scope has the exactly same pages as in the new scope.\n */\n return !prevScopePages.every(pid => currentScopePages.includes(pid));\n};\n\ninterface GetUpdatePageOpsResult {\n addedPages: string[];\n removedPages: string[];\n}\n\nexport const getPagesDiff = (\n currentPages: string[],\n prevPages: string[]\n): GetUpdatePageOpsResult => {\n const addedPages = currentPages.filter(id => !prevPages.includes(id));\n const removedPages = prevPages.filter(id => !currentPages.includes(id));\n\n return {\n addedPages,\n removedPages\n };\n};\n\ninterface UpdatePageSettingsParams {\n getPage: PageBuilderContextObject[\"getPage\"];\n updatePage: PageBuilderContextObject[\"updatePage\"];\n uniquePageId: string;\n getNewSettings: (settings: PageWithWorkflow[\"settings\"]) => PageWithWorkflow[\"settings\"];\n}\n\nexport const updatePageSettings = async ({\n getPage,\n updatePage,\n uniquePageId,\n getNewSettings\n}: UpdatePageSettingsParams) => {\n try {\n /**\n * Currently, we only assign \"workflow\" to latest page.\n */\n const page = await getPage<PageWithWorkflow>(uniquePageId);\n /**\n * We can't update a page that is \"locked\".\n */\n if (page.locked) {\n return;\n }\n /**\n * There can be more than one workflow with same `scope` for same `app`. That is why;\n * We'll update the workflow reference even though it already had one assign.\n */\n await updatePage(page.id, {\n settings: getNewSettings(page.settings)\n });\n } catch (e) {\n if (e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n};\n"],"mappings":";;;;;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
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.workflowByPrecedenceDesc = exports.workflowByCreatedOnDesc = exports.updateContentReviewStep = exports.updateContentReview = exports.safelyGetContentReview = exports.isInstallationPending = exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getContentReviewStepInitialStatus = exports.extractContentReviewIdAndStep = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _get = _interopRequireDefault(require("lodash/get"));
13
-
14
10
  var _types = require("../types");
15
-
16
11
  const hasReviewer = async params => {
17
12
  const {
18
13
  getReviewer,
19
14
  identity,
20
15
  step
21
16
  } = params;
22
-
23
17
  for (const stepReviewer of step.reviewers) {
24
18
  const entry = await getReviewer(stepReviewer.id);
25
-
26
19
  if (entry.identityId === identity.id) {
27
20
  return true;
28
21
  }
29
22
  }
30
-
31
23
  return false;
32
24
  };
33
-
34
25
  exports.hasReviewer = hasReviewer;
35
-
36
26
  const getValue = (object, key) => {
37
27
  return (0, _get.default)(object, `values.${key}`);
38
28
  };
39
-
40
29
  exports.getValue = getValue;
41
-
42
30
  const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
43
31
  /**
44
32
  * Always set first step 'active' by default.
@@ -46,32 +34,23 @@ const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepSta
46
34
  if (index === 0) {
47
35
  return _types.ApwContentReviewStepStatus.ACTIVE;
48
36
  }
49
-
50
37
  const previousStep = workflowSteps[index - 1];
51
-
52
38
  if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStep.type !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
53
39
  return _types.ApwContentReviewStepStatus.ACTIVE;
54
40
  }
55
-
56
41
  return _types.ApwContentReviewStepStatus.INACTIVE;
57
42
  };
58
-
59
43
  exports.getContentReviewStepInitialStatus = getContentReviewStepInitialStatus;
60
-
61
44
  const getNextStepStatus = (previousStepType, previousStepStatus) => {
62
45
  if (previousStepStatus === _types.ApwContentReviewStepStatus.DONE) {
63
46
  return _types.ApwContentReviewStepStatus.ACTIVE;
64
47
  }
65
-
66
48
  if (previousStepStatus === _types.ApwContentReviewStepStatus.ACTIVE && previousStepType !== _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
67
49
  return _types.ApwContentReviewStepStatus.ACTIVE;
68
50
  }
69
-
70
51
  return _types.ApwContentReviewStepStatus.INACTIVE;
71
52
  };
72
-
73
53
  exports.getNextStepStatus = getNextStepStatus;
74
-
75
54
  const extractContentReviewIdAndStep = step => {
76
55
  /*
77
56
  * Get associated content review entry.
@@ -83,15 +62,12 @@ const extractContentReviewIdAndStep = step => {
83
62
  stepId
84
63
  };
85
64
  };
86
-
87
65
  exports.extractContentReviewIdAndStep = extractContentReviewIdAndStep;
88
-
89
66
  const safelyGetContentReview = async ({
90
67
  id,
91
68
  contentReviewMethods
92
69
  }) => {
93
70
  let contentReviewEntry = null;
94
-
95
71
  try {
96
72
  contentReviewEntry = await contentReviewMethods.get(id);
97
73
  } catch (e) {
@@ -99,12 +75,9 @@ const safelyGetContentReview = async ({
99
75
  throw e;
100
76
  }
101
77
  }
102
-
103
78
  return contentReviewEntry;
104
79
  };
105
-
106
80
  exports.safelyGetContentReview = safelyGetContentReview;
107
-
108
81
  const updateContentReview = async ({
109
82
  contentReviewMethods,
110
83
  id,
@@ -114,31 +87,24 @@ const updateContentReview = async ({
114
87
  id,
115
88
  contentReviewMethods
116
89
  });
117
-
118
90
  if (contentReviewEntry) {
119
91
  const newContentReviewData = getNewContentReviewData(contentReviewEntry);
120
92
  /**
121
93
  * Update content review entry.
122
94
  */
123
-
124
95
  await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);
125
96
  }
126
97
  };
127
-
128
98
  exports.updateContentReview = updateContentReview;
129
-
130
99
  const updateContentReviewStep = (steps, stepId, updater) => {
131
100
  return steps.map(step => {
132
101
  if (step.id === stepId) {
133
102
  return (0, _objectSpread2.default)({}, updater(step));
134
103
  }
135
-
136
104
  return step;
137
105
  });
138
106
  };
139
-
140
107
  exports.updateContentReviewStep = updateContentReviewStep;
141
-
142
108
  const isInstallationPending = ({
143
109
  tenancy,
144
110
  i18n
@@ -148,40 +114,31 @@ const isInstallationPending = ({
148
114
  * installation is completed. So, we need to skip "APW" creation till then.
149
115
  */
150
116
  const tenant = tenancy.getCurrentTenant();
151
-
152
117
  if (!tenant) {
153
118
  return true;
154
119
  }
155
-
156
120
  return !i18n.getContentLocale();
157
121
  };
158
-
159
122
  exports.isInstallationPending = isInstallationPending;
160
123
  const WORKFLOW_PRECEDENCE = {
161
124
  [_types.WorkflowScopeTypes.DEFAULT]: 0,
162
125
  [_types.WorkflowScopeTypes.CUSTOM]: 1
163
126
  };
164
-
165
127
  const workflowByPrecedenceDesc = (a, b) => {
166
128
  const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];
167
129
  const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];
168
130
  /**
169
131
  * In descending order of workflow precedence.
170
132
  */
171
-
172
133
  return scoreB - scoreA;
173
134
  };
174
-
175
135
  exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
176
-
177
136
  const workflowByCreatedOnDesc = (a, b) => {
178
137
  const createdOnA = (0, _get.default)(a, "createdOn");
179
138
  const createdOnB = (0, _get.default)(b, "createdOn");
180
139
  /**
181
140
  * In descending order of workflow createdOn i.e. the most recent one first.
182
141
  */
183
-
184
142
  return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
185
143
  };
186
-
187
144
  exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
@@ -1 +1 @@
1
- {"version":3,"names":["hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAGA;;AA0BO,MAAMA,WAAW,GAAG,MAAOC,MAAP,IAAwD;EAC/E,MAAM;IAAEC,WAAF;IAAeC,QAAf;IAAyBC;EAAzB,IAAkCH,M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KAAYuB,MAAhB,EAAwB;MACpB,uCACOe,OAAO,CAAC1C,IAAD,CADd;IAGH;;IACD,OAAOA,IAAP;EACH,CAPM,CAAP;AAQH,CAbM;;;;AAiBA,MAAM4C,qBAAqB,GAAG,CAAC;EAAEC,OAAF;EAAWC;AAAX,CAAD,KAAyD;EAC1F;AACJ;AACA;AACA;EACI,MAAMC,MAAM,GAAGF,OAAO,CAACG,gBAAR,EAAf;;EACA,IAAI,CAACD,MAAL,EAAa;IACT,OAAO,IAAP;EACH;;EAED,OAAO,CAACD,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;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ers/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;;AAXA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAYA,MAAMA,eAAe,GAAG,IAAAC,kBAAA,EAAYC,QAAD,IAAmB;EAClD,OAAO;IACHC,QAAQ,EAAE,IAAAC,cAAA,EAAO;MACbC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAmB,UAAnB;IADC,CAAP,CADP;IAIHC,IAAI,EAAE,IAAAH,cAAA,EAAO;MACTC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CACP,eAAcE,sBAAA,CAAgBC,IAAK,IAAGD,sBAAA,CAAgBE,SAAU,EADzD;IADH,CAAP,CAJH;IASHC,MAAM,EAAE,IAAAP,cAAA,EAAO;MACXC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CACP,eAAcM,6BAAA,CAAuBC,OAAQ,IAAGD,6BAAA,CAAuBE,SAAU,EAD1E;IADD,CAAP,CATL;IAcHC,OAAO,EAAE,IAAAX,cAAA,EAAO;MACZC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAmB,UAAnB;IADA,CAAP,CAdN;IAiBHU,OAAO,EAAE,IAAAZ,cAAA,EAAO;MACZC,UAAU,EAAGY,KAAD,IAAmB;QAC3B,IAAIf,QAAQ,CAACK,IAAT,KAAkBC,sBAAA,CAAgBE,SAAtC,EAAiD;UAC7C,OAAO,IAAP;QACH,CAFD,MAEO,IAAI,CAAC,CAACO,KAAN,EAAa;UAChB,OAAO,IAAP;QACH;;QACD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C,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,UA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AAC,YAAY,CAAC;MACjC;MAEA,OAAO,MAAME,iBAAiB,CAAC6B,MAAM,CAAC;QAAED,IAAI,EAAEG,QAAQ;QAAElB,KAAK,EAAEM;MAAK,CAAC,CAAC;IAC1E,CAAC;IACD,MAAMa,MAAM,CAAC1B,EAAU,EAAE;MACrB,MAAMN,iBAAiB,CAACgC,MAAM;QAAG1B;MAAE,GAAKF,kBAAkB,EAAE,EAAG;MAE/D,OAAO,IAAI;IACf,CAAC;IACD,MAAM6B,cAAc,GAAG;MACnB,OAAO,MAAMjC,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"}
@@ -9,5 +9,5 @@ export interface HandlerArgs {
9
9
  interface Configuration {
10
10
  storageOperations: ApwScheduleActionStorageOperations;
11
11
  }
12
- export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
12
+ export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
13
13
  export {};