@webiny/api-apw 0.0.0-unstable.e3f4727c56 → 0.0.0-unstable.e53eceafb5

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 (310) hide show
  1. package/ApwChangeRequestNotification.d.ts +1 -1
  2. package/ApwChangeRequestNotification.js +4 -6
  3. package/ApwChangeRequestNotification.js.map +1 -1
  4. package/ApwCommentNotification.d.ts +1 -1
  5. package/ApwCommentNotification.js +4 -6
  6. package/ApwCommentNotification.js.map +1 -1
  7. package/ApwContentReviewNotification.d.ts +1 -1
  8. package/ApwContentReviewNotification.js +4 -6
  9. package/ApwContentReviewNotification.js.map +1 -1
  10. package/ApwContentUrlPlugin.d.ts +1 -1
  11. package/ApwContentUrlPlugin.js +4 -6
  12. package/ApwContentUrlPlugin.js.map +1 -1
  13. package/ContentApwSettingsPlugin.d.ts +1 -1
  14. package/ContentApwSettingsPlugin.js +5 -4
  15. package/ContentApwSettingsPlugin.js.map +1 -1
  16. package/README.md +3 -3
  17. package/crud/createChangeRequestMethods.d.ts +1 -1
  18. package/crud/createChangeRequestMethods.js +3 -1
  19. package/crud/createChangeRequestMethods.js.map +1 -1
  20. package/crud/createCommentMethods.d.ts +1 -1
  21. package/crud/createCommentMethods.js +3 -1
  22. package/crud/createCommentMethods.js.map +1 -1
  23. package/crud/createContentReviewMethods.d.ts +2 -2
  24. package/crud/createContentReviewMethods.js +57 -32
  25. package/crud/createContentReviewMethods.js.map +1 -1
  26. package/crud/createReviewerMethods.d.ts +1 -1
  27. package/crud/createReviewerMethods.js +3 -1
  28. package/crud/createReviewerMethods.js.map +1 -1
  29. package/crud/createWorkflowMethods.d.ts +1 -1
  30. package/crud/createWorkflowMethods.js +3 -1
  31. package/crud/createWorkflowMethods.js.map +1 -1
  32. package/crud/index.d.ts +1 -1
  33. package/crud/index.js +6 -5
  34. package/crud/index.js.map +1 -1
  35. package/crud/utils.d.ts +2 -2
  36. package/crud/utils.js +8 -8
  37. package/crud/utils.js.map +1 -1
  38. package/index.d.ts +2 -2
  39. package/index.js +4 -3
  40. package/index.js.map +1 -1
  41. package/package.json +32 -50
  42. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +1 -1
  43. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +5 -5
  44. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  45. package/plugins/cms/apwEntryPlugins.d.ts +2 -2
  46. package/plugins/cms/apwEntryPlugins.js +19 -7
  47. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  48. package/plugins/cms/index.d.ts +4 -4
  49. package/plugins/cms/index.js +3 -1
  50. package/plugins/cms/index.js.map +1 -1
  51. package/plugins/cms/linkContentReviewToEntry.d.ts +2 -2
  52. package/plugins/cms/linkContentReviewToEntry.js +5 -4
  53. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  54. package/plugins/cms/linkWorkflowToEntry.d.ts +2 -2
  55. package/plugins/cms/linkWorkflowToEntry.js +17 -16
  56. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  57. package/plugins/cms/notifications/changeRequestNotification.js +3 -1
  58. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
  59. package/plugins/cms/notifications/commentNotification.js +3 -1
  60. package/plugins/cms/notifications/commentNotification.js.map +1 -1
  61. package/plugins/cms/notifications/contentReviewNotification.js +3 -1
  62. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
  63. package/plugins/cms/notifications/contentUrl.js +3 -1
  64. package/plugins/cms/notifications/contentUrl.js.map +1 -1
  65. package/plugins/cms/triggerContentReview.d.ts +2 -2
  66. package/plugins/cms/triggerContentReview.js +6 -5
  67. package/plugins/cms/triggerContentReview.js.map +1 -1
  68. package/plugins/cms/updateContentReviewStatus.d.ts +3 -3
  69. package/plugins/cms/updateContentReviewStatus.js +15 -13
  70. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  71. package/plugins/cms/utils.d.ts +5 -4
  72. package/plugins/cms/utils.js +19 -13
  73. package/plugins/cms/utils.js.map +1 -1
  74. package/plugins/context.d.ts +2 -2
  75. package/plugins/context.js +3 -1
  76. package/plugins/context.js.map +1 -1
  77. package/plugins/graphql/changeRequest.gql.d.ts +1 -1
  78. package/plugins/graphql/changeRequest.gql.js +16 -13
  79. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  80. package/plugins/graphql/comment.gql.d.ts +1 -1
  81. package/plugins/graphql/comment.gql.js +41 -36
  82. package/plugins/graphql/comment.gql.js.map +1 -1
  83. package/plugins/graphql/contentReview.gql.d.ts +1 -1
  84. package/plugins/graphql/contentReview.gql.js +26 -17
  85. package/plugins/graphql/contentReview.gql.js.map +1 -1
  86. package/plugins/graphql/reviewer.gql.d.ts +1 -1
  87. package/plugins/graphql/reviewer.gql.js +15 -13
  88. package/plugins/graphql/reviewer.gql.js.map +1 -1
  89. package/plugins/graphql/utils.d.ts +2 -0
  90. package/plugins/graphql/utils.js +10 -0
  91. package/plugins/graphql/utils.js.map +1 -0
  92. package/plugins/graphql/workflow.gql.d.ts +1 -1
  93. package/plugins/graphql/workflow.gql.js +15 -13
  94. package/plugins/graphql/workflow.gql.js.map +1 -1
  95. package/plugins/graphql.d.ts +1 -1
  96. package/plugins/graphql.js +4 -2
  97. package/plugins/graphql.js.map +1 -1
  98. package/plugins/hooks/createReviewerFromIdentity.d.ts +1 -1
  99. package/plugins/hooks/createReviewerFromIdentity.js +4 -2
  100. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  101. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +1 -1
  102. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +3 -1
  103. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  104. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +1 -1
  105. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +3 -1
  106. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  107. package/plugins/hooks/index.d.ts +1 -1
  108. package/plugins/hooks/index.js +3 -1
  109. package/plugins/hooks/index.js.map +1 -1
  110. package/plugins/hooks/initializeContentReviewSteps.d.ts +1 -1
  111. package/plugins/hooks/initializeContentReviewSteps.js +6 -4
  112. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  113. package/plugins/hooks/initializeNotifications.d.ts +1 -1
  114. package/plugins/hooks/initializeNotifications.js +3 -1
  115. package/plugins/hooks/initializeNotifications.js.map +1 -1
  116. package/plugins/hooks/listContentReviews.d.ts +3 -3
  117. package/plugins/hooks/listContentReviews.js +4 -2
  118. package/plugins/hooks/listContentReviews.js.map +1 -1
  119. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +1 -1
  120. package/plugins/hooks/notifications/changeRequestAfterCreate.js +8 -11
  121. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  122. package/plugins/hooks/notifications/changeRequestUrl.js +3 -1
  123. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
  124. package/plugins/hooks/notifications/commentAfterCreate.d.ts +1 -1
  125. package/plugins/hooks/notifications/commentAfterCreate.js +8 -11
  126. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  127. package/plugins/hooks/notifications/commentUrl.js +3 -1
  128. package/plugins/hooks/notifications/commentUrl.js.map +1 -1
  129. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +1 -1
  130. package/plugins/hooks/notifications/contentReviewAfterCreate.js +9 -12
  131. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  132. package/plugins/hooks/notifications/contentReviewUrl.js +3 -1
  133. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
  134. package/plugins/hooks/notifications/contentUrl.d.ts +2 -2
  135. package/plugins/hooks/notifications/contentUrl.js +3 -1
  136. package/plugins/hooks/notifications/contentUrl.js.map +1 -1
  137. package/plugins/hooks/notifications/getAppUrl.d.ts +2 -0
  138. package/plugins/hooks/notifications/getAppUrl.js +19 -0
  139. package/plugins/hooks/notifications/getAppUrl.js.map +1 -0
  140. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +1 -1
  141. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +3 -1
  142. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
  143. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +1 -1
  144. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +3 -1
  145. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
  146. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +1 -1
  147. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +3 -1
  148. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
  149. package/plugins/hooks/notifications/reviewers.d.ts +1 -1
  150. package/plugins/hooks/notifications/reviewers.js +18 -15
  151. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  152. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +1 -1
  153. package/plugins/hooks/notifications/sendChangeRequestNotification.js +3 -1
  154. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
  155. package/plugins/hooks/notifications/sendCommentNotification.d.ts +1 -1
  156. package/plugins/hooks/notifications/sendCommentNotification.js +3 -1
  157. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
  158. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +1 -1
  159. package/plugins/hooks/notifications/sendContentReviewNotification.js +3 -1
  160. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
  161. package/plugins/hooks/updatePendingChangeRequests.d.ts +1 -1
  162. package/plugins/hooks/updatePendingChangeRequests.js +8 -6
  163. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  164. package/plugins/hooks/updateTotalComments.d.ts +1 -1
  165. package/plugins/hooks/updateTotalComments.js +22 -15
  166. package/plugins/hooks/updateTotalComments.js.map +1 -1
  167. package/plugins/hooks/validateChangeRequest.d.ts +1 -1
  168. package/plugins/hooks/validateChangeRequest.js +3 -1
  169. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  170. package/plugins/hooks/validateComment.d.ts +1 -1
  171. package/plugins/hooks/validateComment.js +3 -1
  172. package/plugins/hooks/validateComment.js.map +1 -1
  173. package/plugins/hooks/validateContentReview.d.ts +1 -1
  174. package/plugins/hooks/validateContentReview.js +3 -1
  175. package/plugins/hooks/validateContentReview.js.map +1 -1
  176. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +2 -1
  177. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +5 -5
  178. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  179. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +1 -1
  180. package/plugins/pageBuilder/apwContentPagePlugins.js +3 -1
  181. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  182. package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +1 -1
  183. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +3 -1
  184. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  185. package/plugins/pageBuilder/index.d.ts +4 -4
  186. package/plugins/pageBuilder/index.js +3 -1
  187. package/plugins/pageBuilder/index.js.map +1 -1
  188. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +2 -2
  189. package/plugins/pageBuilder/linkContentReviewToPage.js +16 -12
  190. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  191. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +2 -2
  192. package/plugins/pageBuilder/linkWorkflowToPage.js +13 -12
  193. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  194. package/plugins/pageBuilder/notifications/changeRequestNotification.js +3 -1
  195. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
  196. package/plugins/pageBuilder/notifications/commentNotification.js +3 -1
  197. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
  198. package/plugins/pageBuilder/notifications/contentReviewNotification.js +3 -1
  199. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
  200. package/plugins/pageBuilder/notifications/contentUrl.js +3 -1
  201. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
  202. package/plugins/pageBuilder/triggerContentReview.d.ts +2 -2
  203. package/plugins/pageBuilder/triggerContentReview.js +5 -4
  204. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  205. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +3 -3
  206. package/plugins/pageBuilder/updateContentReviewStatus.js +13 -10
  207. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  208. package/plugins/pageBuilder/utils.d.ts +4 -4
  209. package/plugins/pageBuilder/utils.js +7 -6
  210. package/plugins/pageBuilder/utils.js.map +1 -1
  211. package/plugins/utils.d.ts +7 -6
  212. package/plugins/utils.js +12 -8
  213. package/plugins/utils.js.map +1 -1
  214. package/scheduler/createScheduleActionMethods.d.ts +1 -1
  215. package/scheduler/createScheduleActionMethods.js +105 -66
  216. package/scheduler/createScheduleActionMethods.js.map +1 -1
  217. package/scheduler/handlers/executeAction/index.d.ts +2 -2
  218. package/scheduler/handlers/executeAction/index.js +30 -9
  219. package/scheduler/handlers/executeAction/index.js.map +1 -1
  220. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +5 -4
  221. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  222. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -1
  223. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +6 -7
  224. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  225. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +3 -2
  226. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +4 -7
  227. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  228. package/scheduler/handlers/executeAction/security.d.ts +2 -2
  229. package/scheduler/handlers/executeAction/security.js +3 -1
  230. package/scheduler/handlers/executeAction/security.js.map +1 -1
  231. package/scheduler/handlers/scheduleAction/index.d.ts +2 -2
  232. package/scheduler/handlers/scheduleAction/index.js +20 -15
  233. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  234. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +3 -3
  235. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +19 -14
  236. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  237. package/scheduler/handlers/utils.d.ts +2 -3
  238. package/scheduler/handlers/utils.js +20 -13
  239. package/scheduler/handlers/utils.js.map +1 -1
  240. package/scheduler/index.d.ts +1 -1
  241. package/scheduler/index.js +3 -1
  242. package/scheduler/index.js.map +1 -1
  243. package/scheduler/types.d.ts +20 -36
  244. package/scheduler/types.js +11 -17
  245. package/scheduler/types.js.map +1 -1
  246. package/storageOperations/changeRequestStorageOperations.d.ts +2 -2
  247. package/storageOperations/changeRequestStorageOperations.js +44 -23
  248. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  249. package/storageOperations/commentStorageOperations.d.ts +3 -3
  250. package/storageOperations/commentStorageOperations.js +17 -24
  251. package/storageOperations/commentStorageOperations.js.map +1 -1
  252. package/storageOperations/contentReviewStorageOperations.d.ts +3 -3
  253. package/storageOperations/contentReviewStorageOperations.js +20 -25
  254. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  255. package/storageOperations/index.d.ts +3 -9
  256. package/storageOperations/index.js +11 -16
  257. package/storageOperations/index.js.map +1 -1
  258. package/storageOperations/models/changeRequest.model.d.ts +1 -2
  259. package/storageOperations/models/changeRequest.model.js +10 -11
  260. package/storageOperations/models/changeRequest.model.js.map +1 -1
  261. package/storageOperations/models/comment.model.d.ts +1 -2
  262. package/storageOperations/models/comment.model.js +10 -11
  263. package/storageOperations/models/comment.model.js.map +1 -1
  264. package/storageOperations/models/contentReview.model.d.ts +1 -2
  265. package/storageOperations/models/contentReview.model.js +16 -15
  266. package/storageOperations/models/contentReview.model.js.map +1 -1
  267. package/storageOperations/models/index.d.ts +1 -1
  268. package/storageOperations/models/index.js +11 -31
  269. package/storageOperations/models/index.js.map +1 -1
  270. package/storageOperations/models/reviewer.model.d.ts +1 -2
  271. package/storageOperations/models/reviewer.model.js +11 -12
  272. package/storageOperations/models/reviewer.model.js.map +1 -1
  273. package/storageOperations/models/utils.d.ts +2 -2
  274. package/storageOperations/models/utils.js +3 -1
  275. package/storageOperations/models/utils.js.map +1 -1
  276. package/storageOperations/models/workflow.model.d.ts +2 -3
  277. package/storageOperations/models/workflow.model.js +22 -23
  278. package/storageOperations/models/workflow.model.js.map +1 -1
  279. package/storageOperations/reviewerStorageOperations.d.ts +3 -3
  280. package/storageOperations/reviewerStorageOperations.js +24 -34
  281. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  282. package/storageOperations/types.d.ts +2 -2
  283. package/storageOperations/types.js +3 -1
  284. package/storageOperations/types.js.map +1 -1
  285. package/storageOperations/workflowStorageOperations.d.ts +2 -2
  286. package/storageOperations/workflowStorageOperations.js +25 -28
  287. package/storageOperations/workflowStorageOperations.js.map +1 -1
  288. package/types.d.ts +54 -53
  289. package/types.js +121 -29
  290. package/types.js.map +1 -1
  291. package/utils/contentApwSettingsPlugin.d.ts +2 -2
  292. package/utils/contentApwSettingsPlugin.js +3 -1
  293. package/utils/contentApwSettingsPlugin.js.map +1 -1
  294. package/utils/errors.js +3 -1
  295. package/utils/errors.js.map +1 -1
  296. package/utils/fieldResolver.d.ts +2 -2
  297. package/utils/fieldResolver.js +7 -7
  298. package/utils/fieldResolver.js.map +1 -1
  299. package/utils/pickEntryFieldValues.d.ts +3 -0
  300. package/utils/pickEntryFieldValues.js +30 -0
  301. package/utils/pickEntryFieldValues.js.map +1 -0
  302. package/utils/resolve.d.ts +1 -1
  303. package/utils/resolve.js +3 -1
  304. package/utils/resolve.js.map +1 -1
  305. package/plugins/hooks/notifications/appUrl.d.ts +0 -2
  306. package/plugins/hooks/notifications/appUrl.js +0 -18
  307. package/plugins/hooks/notifications/appUrl.js.map +0 -1
  308. package/storageOperations/models/contentModelPluginFactory.d.ts +0 -8
  309. package/storageOperations/models/contentModelPluginFactory.js +0 -19
  310. package/storageOperations/models/contentModelPluginFactory.js.map +0 -1
@@ -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,IAAsB,EAAEC,QAAqB,KAAK;EAC5E,MAAMC,WAAW,GAAGD,QAAQ,CAACE,GAAG;EAChC,IAAID,WAAW,KAAKE,8BAAuB,CAACC,EAAE,EAAE;IAC5C,OAAO,KAAK;EAChB;EAEA,MAAMC,SAAS,GAAGL,QAAQ,CAACM,KAAK,CAACC,IAAI;EAErC,IAAIF,SAAS,K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,CAAC;AAAC;AAOK,MAAMyB,YAAY,GAAG,CACxBC,YAAsB,EACtBC,SAAmB,KACM;EACzB,MAAMC,UAAU,GAAGF,YAAY,CAACG,MAAM,CAAChB,EAAE,IAAI,CAACc,SAAS,CAAC9B,QAAQ,CAACgB,EAAE,CAAC,CAAC;EACrE,MAAMiB,YAAY,GAAGH,SAAS,CAACE,MAAM,CAAChB,EAAE,IAAI,CAACa,YAAY,CAAC7B,QAAQ,CAACgB,EAAE,CAAC,CAAC;EAEvE,OAAO;IACHe,UAAU;IACVE;EACJ,CAAC;AACL,CAAC;AAAC;AASK,MAAMC,kBAAkB,GAAG,OAAO;EACrCC,OAAO;EACPC,UAAU;EACVC,YAAY;EACZC;AACsB,CAAC,KAAK;EAC5B,IAAI;IACA;AACR;AACA;IACQ,MAAMtD,IAAI,GAAG,MAAMmD,OAAO,CAAmBE,YAAY,CAAC;IAC1D;AACR;AACA;IACQ,IAAIrD,IAAI,CAACuD,MAAM,EAAE;MACb;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAMH,UAAU,CAACpD,IAAI,CAACgC,EAAE,EAAE;MACtBH,QAAQ,EAAEyB,cAAc,CAACtD,IAAI,CAAC6B,QAAQ;IAC1C,CAAC,CAAC;EACN,CAAC,CAAC,OAAO2B,CAAC,EAAE;IACR,IAAIA,CAAC,CAACrB,IAAI,KAAK,WAAW,EAAE;MACxB,MAAMqB,CAAC;IACX;EACJ;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_types","_utils","isWorkflowApplicable","page","workflow","application","app","ApwWorkflowApplications","PB","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","categories","data","Array","isArray","includes","category","pages","pid","WebinyError","assignWorkflowToPage","listWorkflow","entries","where","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","settings","apw","workflowId","id","contentReviewId","ex","code","exports","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 WebinyError from \"@webiny/error\";\nimport type { ApwWorkflow, ApwWorkflowCrud, ApwWorkflowScope, PageWithWorkflow } from \"~/types\";\nimport { ApwWorkflowApplications, WorkflowScopeTypes } from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport type { 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 = workflow.scope.data?.categories;\n\n if (Array.isArray(categories) && categories.includes(page.category)) {\n return true;\n }\n\n const pages = 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 = prevScope.data.pages || [];\n const currentScopePages = scope.data.pages || [];\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAGA,MAAMG,oBAAoB,GAAGA,CAACC,IAAsB,EAAEC,QAAqB,KAAK;EAC5E,MAAMC,WAAW,GAAGD,QAAQ,CAACE,GAAG;EAChC,IAAID,WAAW,KAAKE,8BAAuB,CAACC,EAAE,EAAE;IAC5C,OAAO,KAAK;EAChB;EAEA,MAAMC,SAAS,GAAGL,QAAQ,CAACM,KAAK,CAACC,IAAI;EAErC,IAAIF,SAAS,KAAKG,yBAAkB,CAACC,OAAO,EAAE;IAC1C,OAAO,IAAI;EACf,CAAC,MAAM,IAAIJ,SAAS,KAAKG,yBAAkB,CAACE,MAAM,EAAE;IAChD,MAAMC,UAAU,GAAGX,QAAQ,CAACM,KAAK,CAACM,IAAI,EAAED,UAAU;IAElD,IAAIE,KAAK,CAACC,OAAO,CAACH,UAAU,CAAC,IAAIA,UAAU,CAACI,QAAQ,CAAChB,IAAI,CAACiB,QAAQ,CAAC,EAAE;MACjE,OAAO,IAAI;IACf;IAEA,MAAMC,KAAK,GAAGjB,QAAQ,CAACM,KAAK,CAACM,IAAI,EAAEK,KAAK;IACxC,IAAIJ,KAAK,CAACC,OAAO,CAACG,KAAK,CAAC,IAAIA,KAAK,CAACF,QAAQ,CAAChB,IAAI,CAACmB,GAAG,CAAC,EAAE;MAClD,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kB,GAAG,MAAAA,CAAO;EACrCC,OAAO;EACPC,UAAU;EACVC,YAAY;EACZC;AACsB,CAAC,KAAK;EAC5B,IAAI;IACA;AACR;AACA;IACQ,MAAMtD,IAAI,GAAG,MAAMmD,OAAO,CAAmBE,YAAY,CAAC;IAC1D;AACR;AACA;IACQ,IAAIrD,IAAI,CAACuD,MAAM,EAAE;MACb;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAMH,UAAU,CAACpD,IAAI,CAACgC,EAAE,EAAE;MACtBH,QAAQ,EAAEyB,cAAc,CAACtD,IAAI,CAAC6B,QAAQ;IAC1C,CAAC,CAAC;EACN,CAAC,CAAC,OAAO2B,CAAC,EAAE;IACR,IAAIA,CAAC,CAACrB,IAAI,KAAK,WAAW,EAAE;MACxB,MAAMqB,CAAC;IACX;EACJ;AACJ,CAAC;AAACpB,OAAA,CAAAc,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -1,6 +1,7 @@
1
- import { CmsModelField } from "@webiny/api-headless-cms/types";
2
- import { SecurityIdentity } from "@webiny/api-security/types";
3
- import { ApwChangeRequest, ApwContentReview, ApwContentReviewCrud, ApwContentReviewStep, ApwContentReviewStepStatus, ApwContext, ApwReviewerCrud, ApwWorkflow, ApwWorkflowStep, ApwWorkflowStepTypes } from "../types";
1
+ import type { CmsModelField } from "@webiny/api-headless-cms/types";
2
+ import type { SecurityIdentity } from "@webiny/api-security/types";
3
+ import type { ApwChangeRequest, ApwContentReview, ApwContentReviewCrud, ApwContentReviewStep, ApwContext, ApwReviewerCrud, ApwWorkflow, ApwWorkflowStep } from "../types";
4
+ import { ApwContentReviewStepStatus, ApwWorkflowStepTypes } from "../types";
4
5
  export interface CreateModelFieldParams extends Omit<CmsModelField, "id" | "storageId" | "fieldId"> {
5
6
  fieldId?: string;
6
7
  parent: string;
@@ -10,7 +11,7 @@ export interface HasReviewersParams {
10
11
  step: ApwContentReviewStep;
11
12
  getReviewer: ApwReviewerCrud["get"];
12
13
  }
13
- export declare const hasReviewer: (params: HasReviewersParams) => Promise<Boolean>;
14
+ export declare const hasReviewer: (params: HasReviewersParams) => Promise<boolean>;
14
15
  export declare const getValue: (object: Record<string, any>, key: string) => any;
15
16
  export declare const getContentReviewStepInitialStatus: (workflowSteps: ApwWorkflowStep[], index: number, previousStepStatus?: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
16
17
  export declare const getNextStepStatus: (previousStepType: ApwWorkflowStepTypes, previousStepStatus: ApwContentReviewStepStatus) => ApwContentReviewStepStatus;
@@ -19,7 +20,7 @@ export interface ExtractContentReviewIdAndStepResult {
19
20
  stepId: string;
20
21
  }
21
22
  export declare const extractContentReviewIdAndStep: (step: ApwChangeRequest["step"]) => ExtractContentReviewIdAndStepResult;
22
- declare type SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, "id" | "contentReviewMethods">;
23
+ type SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, "id" | "contentReviewMethods">;
23
24
  export declare const safelyGetContentReview: ({ id, contentReviewMethods }: SafelyGetContentReviewParams) => Promise<ApwContentReview | null>;
24
25
  export interface UpdateContentReviewParams {
25
26
  id: string;
@@ -28,7 +29,7 @@ export interface UpdateContentReviewParams {
28
29
  }
29
30
  export declare const updateContentReview: ({ contentReviewMethods, id, getNewContentReviewData }: UpdateContentReviewParams) => Promise<void>;
30
31
  export declare const updateContentReviewStep: (steps: ApwContentReviewStep[], stepId: string, updater: (step: ApwContentReviewStep) => ApwContentReviewStep) => ApwContentReviewStep[];
31
- declare type CheckInstallationParams = Pick<ApwContext, "tenancy" | "i18n">;
32
+ type CheckInstallationParams = Pick<ApwContext, "tenancy" | "i18n">;
32
33
  export declare const isInstallationPending: ({ tenancy, i18n }: CheckInstallationParams) => boolean;
33
34
  export declare const workflowByPrecedenceDesc: (a: ApwWorkflow, b: ApwWorkflow) => number;
34
35
  export declare const workflowByCreatedOnDesc: (a: ApwWorkflow, b: ApwWorkflow) => number;
package/plugins/utils.js CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.workflowByPrecedenceDesc = exports.workflowByCreatedOnDesc = exports.updateContentReviewStep = exports.updateContentReview = exports.safelyGetContentReview = exports.isInstallationPending = exports.hasReviewer = exports.getValue = exports.getNextStepStatus = exports.getContentReviewStepInitialStatus = exports.extractContentReviewIdAndStep = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _get = _interopRequireDefault(require("lodash/get"));
10
7
  var _types = require("../types");
11
8
  const hasReviewer = async params => {
12
9
  const {
@@ -24,7 +21,10 @@ const hasReviewer = async params => {
24
21
  };
25
22
  exports.hasReviewer = hasReviewer;
26
23
  const getValue = (object, key) => {
27
- return (0, _get.default)(object, `values.${key}`);
24
+ if (!object.values) {
25
+ return undefined;
26
+ }
27
+ return object.values[key];
28
28
  };
29
29
  exports.getValue = getValue;
30
30
  const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
@@ -99,7 +99,9 @@ exports.updateContentReview = updateContentReview;
99
99
  const updateContentReviewStep = (steps, stepId, updater) => {
100
100
  return steps.map(step => {
101
101
  if (step.id === stepId) {
102
- return (0, _objectSpread2.default)({}, updater(step));
102
+ return {
103
+ ...updater(step)
104
+ };
103
105
  }
104
106
  return step;
105
107
  });
@@ -134,11 +136,13 @@ const workflowByPrecedenceDesc = (a, b) => {
134
136
  };
135
137
  exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
136
138
  const workflowByCreatedOnDesc = (a, b) => {
137
- const createdOnA = (0, _get.default)(a, "createdOn");
138
- const createdOnB = (0, _get.default)(b, "createdOn");
139
+ const createdOnA = a.createdOn;
140
+ const createdOnB = b.createdOn;
139
141
  /**
140
142
  * In descending order of workflow createdOn i.e. the most recent one first.
141
143
  */
142
144
  return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();
143
145
  };
144
- exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
146
+ exports.workflowByCreatedOnDesc = workflowByCreatedOnDesc;
147
+
148
+ //# sourceMappingURL=utils.js.map
@@ -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,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,MAA2B,EAAEC,GAAW,KAAK;EAClE,OAAO,IAAAC,YAAG,EAACF,MAAM,EAAG,UAASC,GAAI,EAAC,CAAC;AACvC,CAAC;AAAC;AAEK,MAAME,iCAAiC,GAAG,CAC7CC,aAAgC,EAChCC,KAAa,EACbC,kBAA+C,KAClB;EAC7B;AACJ;AACA;EACI,IAAID,KAAK,KAAK,CAAC,EAAE;IACb,OAAOE,iCAA0B,CAACC,MAAM;EAC5C;EAEA,MAAMC,YAAY,GAAGL,aAAa,CAACC,KAAK,GAAG,CAAC,CAAC;EAC7C,IACIC,kBAAkB,KAAKC,iCAA0B,CAACC,MAAM,IACxDC,YAAY,CAACC,IAAI,KAAKC,2BAAoB,CAACC,kBAAkB,EAC/D;IACE,OAAOL,iCAA0B,CAACC,MAAM;EAC5C;EAEA,OAAOD,iCAA0B,CAACM,QAAQ;AAC9C,CAAC;AAAC;AAEK,MAAMC,iBAAiB,GAAG,CAC7BC,gBAAsC,EACtCT,kBAA8C,KACjB;EAC7B,IAAIA,kBAAkB,KAAKC,iCAA0B,CAACS,IA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,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
+ {"version":3,"names":["_types","require","hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","exports","getValue","object","key","values","undefined","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","get","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","createdOn","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport type {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep\n} from \"~/types\";\nimport { ApwContentReviewStepStatus, ApwWorkflowStepTypes, WorkflowScopeTypes } 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 if (!object.values) {\n return undefined;\n }\n return 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 = a.createdOn;\n const createdOnB = 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":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAcO,MAAMC,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;AAACE,OAAA,CAAAV,WAAA,GAAAA,WAAA;AAEK,MAAMW,QAAQ,GAAGA,CAACC,MAA2B,EAAEC,GAAW,KAAK;EAClE,IAAI,CAACD,MAAM,CAACE,MAAM,EAAE;IAChB,OAAOC,SAAS;EACpB;EACA,OAAOH,MAAM,CAACE,MAAM,CAACD,GAAG,CAAC;AAC7B,CAAC;AAACH,OAAA,CAAAC,QAAA,GAAAA,QAAA;AAEK,MAAMK,iCAAiC,GAAGA,CAC7CC,aAAgC,EAChCC,KAAa,EACbC,kBAA+C,KAClB;EAC7B;AACJ;AACA;EACI,IAAID,KAAK,KAAK,CAAC,EAAE;IACb,OAAOE,iCAA0B,CAACC,MAAM;EAC5C;EAEA,MAAMC,YAAY,GAAGL,aAAa,CAACC,KAAK,GAAG,CAAC,CAAC;EAC7C,IACIC,kBAAkB,KAAKC,iCAA0B,CAACC,MAAM,IACxDC,YAAY,CAACC,IAAI,KAAKC,2BAAoB,CAACC,kBAAkB,EAC/D;IACE,OAAOL,iCAA0B,CAACC,MA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AG;AACjC,CAAC;AAEM,MAAMC,wBAAwB,GAAGA,CAACC,CAAc,EAAEC,CAAc,KAAK;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAK,CAAC1C,IAAI,CAAC;EAChD,MAAM2C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAK,CAAC1C,IAAI,CAAC;EAChD;AACJ;AACA;EACI,OAAO2C,MAAM,GAAGF,MAAM;AAC1B,CAAC;AAACtD,OAAA,CAAAmD,wBAAA,GAAAA,wBAAA;AAEK,MAAMM,uBAAuB,GAAGA,CAACL,CAAc,EAAEC,CAAc,KAAK;EACvE,MAAMK,UAAU,GAAGN,CAAC,CAACO,SAAS;EAC9B,MAAMC,UAAU,GAAGP,CAAC,CAACM,SAAS;EAC9B;AACJ;AACA;EACI,OAAO,IAAIE,IAAI,CAACD,UAAU,CAAC,CAACE,OAAO,CAAC,CAAC,GAAG,IAAID,IAAI,CAACH,UAAU,CAAC,CAACI,OAAO,CAAC,CAAC;AAC1E,CAAC;AAAC9D,OAAA,CAAAyD,uBAAA,GAAAA,uBAAA","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import { ApwScheduleActionCrud, CreateScheduleActionParams } from "./types";
1
+ import type { ApwScheduleActionCrud, CreateScheduleActionParams } from "./types";
2
2
  export declare function createScheduleActionMethods({ storageOperations, getIdentity, getTenant, getLocale }: CreateScheduleActionParams): ApwScheduleActionCrud;
@@ -5,47 +5,60 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createScheduleActionMethods = createScheduleActionMethods;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _mdbid = _interopRequireDefault(require("mdbid"));
10
- var _fields = require("@commodo/fields");
11
- var _validation = require("@webiny/validation");
8
+ var _utils = require("@webiny/utils");
12
9
  var _types = require("./types");
13
- /**
14
- * Package mdbid does not have types.
15
- */
16
- // @ts-ignore
17
-
18
- /**
19
- * Package @commodo/fields does not have types.
20
- */
21
- // @ts-ignore
22
-
23
- const CreateDataModel = (0, _fields.withFields)(instance => {
24
- return {
25
- datetime: (0, _fields.string)({
26
- validation: _validation.validation.create(`required`)
27
- }),
28
- type: (0, _fields.string)({
29
- validation: _validation.validation.create(`required,in:${_types.ApwContentTypes.PAGE}:${_types.ApwContentTypes.CMS_ENTRY}`)
30
- }),
31
- action: (0, _fields.string)({
32
- validation: _validation.validation.create(`required,in:${_types.ApwScheduleActionTypes.PUBLISH}:${_types.ApwScheduleActionTypes.UNPUBLISH}`)
33
- }),
34
- entryId: (0, _fields.string)({
35
- validation: _validation.validation.create(`required`)
36
- }),
37
- modelId: (0, _fields.string)({
38
- validation: value => {
39
- if (instance.type !== _types.ApwContentTypes.CMS_ENTRY) {
40
- return true;
41
- } else if (!!value) {
42
- return true;
43
- }
44
- throw new Error(`There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`);
45
- }
46
- })
47
- };
10
+ var _zod = _interopRequireDefault(require("zod"));
11
+ /*
12
+ const CreateDataModel = withFields((instance: any) => {
13
+ return {
14
+ datetime: string({
15
+ validation: validation.create(`required`)
16
+ }),
17
+ type: string({
18
+ validation: validation.create(
19
+ `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`
20
+ )
21
+ }),
22
+ action: string({
23
+ validation: validation.create(
24
+ `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`
25
+ )
26
+ }),
27
+ entryId: string({
28
+ validation: validation.create(`required`)
29
+ }),
30
+ modelId: string({
31
+ validation: (value: string) => {
32
+ if (instance.type !== ApwContentTypes.CMS_ENTRY) {
33
+ return true;
34
+ } else if (!!value) {
35
+ return true;
36
+ }
37
+ throw new Error(
38
+ `There is no modelId defined when type is "${ApwContentTypes.CMS_ENTRY}"`
39
+ );
40
+ }
41
+ })
42
+ };
48
43
  })();
44
+ */
45
+
46
+ const createDataModelValidation = _zod.default.object({
47
+ datetime: _zod.default.string(),
48
+ type: _zod.default.enum([_types.ApwContentTypes.PAGE, _types.ApwContentTypes.CMS_ENTRY]),
49
+ action: _zod.default.enum([_types.ApwScheduleActionTypes.PUBLISH, _types.ApwScheduleActionTypes.UNPUBLISH]),
50
+ entryId: _zod.default.string(),
51
+ modelId: _zod.default.string().optional()
52
+ }).refine(data => {
53
+ if (data.type !== _types.ApwContentTypes.CMS_ENTRY) {
54
+ return true;
55
+ } else if (!!data.modelId) {
56
+ return true;
57
+ }
58
+ return false;
59
+ }, {
60
+ message: `There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`
61
+ });
49
62
  function createScheduleActionMethods({
50
63
  storageOperations,
51
64
  getIdentity,
@@ -63,41 +76,60 @@ function createScheduleActionMethods({
63
76
  return {
64
77
  async get(id) {
65
78
  return storageOperations.get({
66
- where: (0, _objectSpread2.default)({
67
- id
68
- }, getTenantAndLocale())
79
+ where: {
80
+ id,
81
+ ...getTenantAndLocale()
82
+ }
69
83
  });
70
84
  },
71
85
  async list(params) {
72
- return storageOperations.list((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
73
- where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.where), getTenantAndLocale())
74
- }));
86
+ return storageOperations.list({
87
+ ...params,
88
+ where: {
89
+ ...params.where,
90
+ ...getTenantAndLocale()
91
+ }
92
+ });
75
93
  },
76
94
  async create(input) {
77
- const createDataModel = new CreateDataModel().populate(input);
78
- await createDataModel.validate();
79
- const id = (0, _mdbid.default)();
80
- const identity = getIdentity();
81
- const data = await createDataModel.toJSON();
82
- const scheduleAction = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getTenantAndLocale()), {}, {
95
+ const validation = createDataModelValidation.safeParse(input);
96
+ if (!validation.success) {
97
+ throw (0, _utils.createZodError)(validation.error);
98
+ }
99
+ const data = validation.data;
100
+ const id = (0, _utils.mdbid)();
101
+ const currentDateTime = new Date();
102
+ const currentIdentity = getIdentity();
103
+ const scheduleAction = {
104
+ ...getTenantAndLocale(),
83
105
  data,
84
106
  id,
85
- createdOn: new Date().toISOString(),
86
- savedOn: new Date().toISOString(),
107
+ createdOn: currentDateTime.toISOString(),
108
+ modifiedOn: null,
109
+ savedOn: currentDateTime.toISOString(),
87
110
  createdBy: {
88
- id: identity.id,
89
- type: identity.type,
90
- displayName: identity.displayName
111
+ id: currentIdentity.id,
112
+ type: currentIdentity.type,
113
+ displayName: currentIdentity.displayName
114
+ },
115
+ modifiedBy: null,
116
+ savedBy: {
117
+ id: currentIdentity.id,
118
+ type: currentIdentity.type,
119
+ displayName: currentIdentity.displayName
91
120
  }
92
- });
121
+ };
93
122
  return await storageOperations.create({
94
123
  item: scheduleAction,
95
124
  input
96
125
  });
97
126
  },
98
- async update(id, data) {
99
- const updateDataModel = new CreateDataModel().populate(data);
100
- await updateDataModel.validate();
127
+ async update(id, input) {
128
+ const validation = createDataModelValidation.safeParse(input);
129
+ if (!validation.success) {
130
+ throw (0, _utils.createZodError)(validation.error);
131
+ }
132
+ const data = validation.data;
101
133
  const original = await this.get(id);
102
134
  if (!original) {
103
135
  throw new Error("Not found!");
@@ -108,14 +140,17 @@ function createScheduleActionMethods({
108
140
  });
109
141
  },
110
142
  async delete(id) {
111
- await storageOperations.delete((0, _objectSpread2.default)({
112
- id
113
- }, getTenantAndLocale()));
143
+ await storageOperations.delete({
144
+ id,
145
+ ...getTenantAndLocale()
146
+ });
114
147
  return true;
115
148
  },
116
149
  async getCurrentTask() {
117
150
  return await storageOperations.getCurrentTask({
118
- where: (0, _objectSpread2.default)({}, getTenantAndLocale())
151
+ where: {
152
+ ...getTenantAndLocale()
153
+ }
119
154
  });
120
155
  },
121
156
  async updateCurrentTask(item) {
@@ -124,7 +159,11 @@ function createScheduleActionMethods({
124
159
  });
125
160
  },
126
161
  async deleteCurrentTask() {
127
- return await storageOperations.deleteCurrentTask((0, _objectSpread2.default)({}, getTenantAndLocale()));
162
+ return await storageOperations.deleteCurrentTask({
163
+ ...getTenantAndLocale()
164
+ });
128
165
  }
129
166
  };
130
- }
167
+ }
168
+
169
+ //# sourceMappingURL=createScheduleActionMethods.js.map
@@ -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,kBAAU,EAAEC,QAAa,IAAK;EAClD,OAAO;IACHC,QAAQ,EAAE,IAAAC,cAAM,EAAC;MACbC,UAAU,EAAEA,sBA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X,MAAM,IAAIjC,KAAK,CAAC,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"}
1
+ {"version":3,"names":["_utils","require","_types","_zod","_interopRequireDefault","createDataModelValidation","zod","object","datetime","string","type","enum","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","optional","refine","data","message","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","create","input","validation","safeParse","success","createZodError","error","mdbid","currentDateTime","Date","currentIdentity","scheduleAction","createdOn","toISOString","modifiedOn","savedOn","createdBy","displayName","modifiedBy","savedBy","item","update","original","Error","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["import { createZodError, mdbid } from \"@webiny/utils\";\nimport type {\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport zod from \"zod\";\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*/\n\nconst createDataModelValidation = zod\n .object({\n datetime: zod.string(),\n type: zod.enum([ApwContentTypes.PAGE, ApwContentTypes.CMS_ENTRY]),\n action: zod.enum([ApwScheduleActionTypes.PUBLISH, ApwScheduleActionTypes.UNPUBLISH]),\n entryId: zod.string(),\n modelId: zod.string().optional()\n })\n .refine(\n data => {\n if (data.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!data.modelId) {\n return true;\n }\n return false;\n },\n {\n message: `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\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 validation = createDataModelValidation.safeParse(input);\n if (!validation.success) {\n throw createZodError(validation.error);\n }\n const data: ApwScheduleActionData = validation.data;\n\n const id = mdbid();\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: currentDateTime.toISOString(),\n modifiedOn: null,\n savedOn: currentDateTime.toISOString(),\n createdBy: {\n id: currentIdentity.id,\n type: currentIdentity.type,\n displayName: currentIdentity.displayName\n },\n modifiedBy: null,\n savedBy: {\n id: currentIdentity.id,\n type: currentIdentity.type,\n displayName: currentIdentity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, input) {\n const validation = createDataModelValidation.safeParse(input);\n if (!validation.success) {\n throw createZodError(validation.error);\n }\n const data: ApwScheduleActionData = validation.data;\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":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMI,yBAAyB,GAAGC,YAAG,CAChCC,MAAM,C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from "../../types";
1
+ import type { ApwScheduleActionStorageOperations } from "../../types";
2
2
  import { ContextPlugin } from "@webiny/api";
3
3
  export interface HandlerArgs {
4
4
  datetime: string;
@@ -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/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").EventPlugin<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<any, any>[][] | 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 {};
@@ -9,7 +9,7 @@ var _api = require("@webiny/api");
9
9
  var _PageBuilderGraphQL = require("./plugins/PageBuilderGraphQL");
10
10
  var _HeadlessCMSGraphQL = require("./plugins/HeadlessCMSGraphQL");
11
11
  var _ApplicationGraphQL = require("./plugins/ApplicationGraphQL");
12
- var _handler = require("@webiny/handler");
12
+ var _handlerAws = require("@webiny/handler-aws");
13
13
  /**
14
14
  * Handler that execute the provided action(s) for the schedule action workflow.
15
15
  */
@@ -17,7 +17,7 @@ const createExecuteActionLambda = params => {
17
17
  const {
18
18
  storageOperations
19
19
  } = params;
20
- return (0, _handler.createEvent)(async ({
20
+ return (0, _handlerAws.createRawEventHandler)(async ({
21
21
  payload,
22
22
  context
23
23
  }) => {
@@ -111,7 +111,7 @@ const createExecuteActionLambda = params => {
111
111
  console.log(JSON.stringify(item));
112
112
  continue;
113
113
  }
114
-
114
+ console.log(`Invoking Lambda "${name}" with url "${url}".`);
115
115
  // Perform the actual action call.
116
116
  const response = await context.handlerClient.invoke({
117
117
  name,
@@ -132,9 +132,25 @@ const createExecuteActionLambda = params => {
132
132
  },
133
133
  await: true
134
134
  });
135
- if (response !== null && response !== void 0 && response.body) {
135
+ /**
136
+ *
137
+ */
138
+ await storageOperations.delete({
139
+ locale,
140
+ tenant,
141
+ id: item.id
142
+ });
143
+ /**
144
+ * Check for the response and log the error if any.
145
+ */
146
+ if (response?.body) {
147
+ const error = response.body.data?.content?.error;
148
+ if (!error) {
149
+ console.log("Invoke successful.");
150
+ continue;
151
+ }
136
152
  console.log(JSON.stringify({
137
- body: response.body
153
+ error
138
154
  }, null, 2));
139
155
  continue;
140
156
  }
@@ -144,14 +160,19 @@ const createExecuteActionLambda = params => {
144
160
 
145
161
  // TODO: Maybe update the status like error in original item in DB.
146
162
  }
147
- } catch (e) {
148
- log("[HANDLER_EXECUTE_ACTION] Error => ", e);
163
+ } catch (ex) {
164
+ console.error("[HANDLER_EXECUTE_ACTION] => ", JSON.stringify({
165
+ message: ex.message,
166
+ code: ex.code,
167
+ data: ex.data
168
+ }));
149
169
  // TODO: Maybe update the status like error in original item in DB.
150
170
  }
151
171
  });
152
172
  };
153
-
154
173
  const executeActionHandlerPlugins = config => [new _api.ContextPlugin(async context => {
155
174
  context.plugins.register([new _PageBuilderGraphQL.PageBuilderGraphQL(), new _HeadlessCMSGraphQL.HeadlessCMSGraphQL()]);
156
175
  }), (0, _utils.basePlugins)(), createExecuteActionLambda(config)];
157
- exports.executeActionHandlerPlugins = executeActionHandlerPlugins;
176
+ exports.executeActionHandlerPlugins = executeActionHandlerPlugins;
177
+
178
+ //# sourceMappingURL=index.js.map