@webiny/api-apw 0.0.0-unstable.de38392959 → 0.0.0-unstable.e0bfc55d5a

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 (253) hide show
  1. package/ApwChangeRequestNotification.d.ts +1 -1
  2. package/ApwChangeRequestNotification.js.map +1 -1
  3. package/ApwCommentNotification.d.ts +1 -1
  4. package/ApwCommentNotification.js.map +1 -1
  5. package/ApwContentReviewNotification.d.ts +1 -1
  6. package/ApwContentReviewNotification.js.map +1 -1
  7. package/ApwContentUrlPlugin.d.ts +1 -1
  8. package/ApwContentUrlPlugin.js.map +1 -1
  9. package/ContentApwSettingsPlugin.d.ts +1 -1
  10. package/ContentApwSettingsPlugin.js.map +1 -1
  11. package/crud/createChangeRequestMethods.d.ts +1 -1
  12. package/crud/createChangeRequestMethods.js.map +1 -1
  13. package/crud/createCommentMethods.d.ts +1 -1
  14. package/crud/createCommentMethods.js.map +1 -1
  15. package/crud/createContentReviewMethods.d.ts +2 -2
  16. package/crud/createContentReviewMethods.js +1 -2
  17. package/crud/createContentReviewMethods.js.map +1 -1
  18. package/crud/createReviewerMethods.d.ts +1 -1
  19. package/crud/createReviewerMethods.js.map +1 -1
  20. package/crud/createWorkflowMethods.d.ts +1 -1
  21. package/crud/createWorkflowMethods.js.map +1 -1
  22. package/crud/index.d.ts +1 -1
  23. package/crud/index.js.map +1 -1
  24. package/crud/utils.d.ts +2 -2
  25. package/crud/utils.js +1 -2
  26. package/crud/utils.js.map +1 -1
  27. package/index.d.ts +2 -2
  28. package/index.js +4 -5
  29. package/index.js.map +1 -1
  30. package/package.json +32 -43
  31. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +1 -1
  32. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  33. package/plugins/cms/apwEntryPlugins.d.ts +2 -2
  34. package/plugins/cms/apwEntryPlugins.js +10 -1
  35. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  36. package/plugins/cms/index.d.ts +4 -4
  37. package/plugins/cms/index.js.map +1 -1
  38. package/plugins/cms/linkContentReviewToEntry.d.ts +2 -2
  39. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  40. package/plugins/cms/linkWorkflowToEntry.d.ts +2 -2
  41. package/plugins/cms/linkWorkflowToEntry.js +1 -1
  42. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  43. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
  44. package/plugins/cms/notifications/commentNotification.js.map +1 -1
  45. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
  46. package/plugins/cms/notifications/contentUrl.js.map +1 -1
  47. package/plugins/cms/triggerContentReview.d.ts +2 -2
  48. package/plugins/cms/triggerContentReview.js.map +1 -1
  49. package/plugins/cms/updateContentReviewStatus.d.ts +3 -3
  50. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  51. package/plugins/cms/utils.d.ts +2 -2
  52. package/plugins/cms/utils.js +1 -3
  53. package/plugins/cms/utils.js.map +1 -1
  54. package/plugins/context.d.ts +3 -3
  55. package/plugins/context.js +3 -14
  56. package/plugins/context.js.map +1 -1
  57. package/plugins/graphql/changeRequest.gql.d.ts +1 -1
  58. package/plugins/graphql/changeRequest.gql.js +1 -2
  59. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  60. package/plugins/graphql/comment.gql.d.ts +1 -1
  61. package/plugins/graphql/comment.gql.js +1 -2
  62. package/plugins/graphql/comment.gql.js.map +1 -1
  63. package/plugins/graphql/contentReview.gql.d.ts +1 -1
  64. package/plugins/graphql/contentReview.gql.js +1 -2
  65. package/plugins/graphql/contentReview.gql.js.map +1 -1
  66. package/plugins/graphql/reviewer.gql.d.ts +1 -1
  67. package/plugins/graphql/reviewer.gql.js +1 -2
  68. package/plugins/graphql/reviewer.gql.js.map +1 -1
  69. package/plugins/graphql/utils.js +2 -4
  70. package/plugins/graphql/utils.js.map +1 -1
  71. package/plugins/graphql/workflow.gql.d.ts +1 -1
  72. package/plugins/graphql/workflow.gql.js +1 -2
  73. package/plugins/graphql/workflow.gql.js.map +1 -1
  74. package/plugins/graphql.d.ts +1 -1
  75. package/plugins/graphql.js.map +1 -1
  76. package/plugins/hooks/createReviewerFromIdentity.d.ts +1 -1
  77. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  78. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +1 -1
  79. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  80. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +1 -1
  81. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  82. package/plugins/hooks/index.d.ts +1 -1
  83. package/plugins/hooks/index.js.map +1 -1
  84. package/plugins/hooks/initializeContentReviewSteps.d.ts +1 -1
  85. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  86. package/plugins/hooks/initializeNotifications.d.ts +1 -1
  87. package/plugins/hooks/initializeNotifications.js.map +1 -1
  88. package/plugins/hooks/listContentReviews.d.ts +3 -3
  89. package/plugins/hooks/listContentReviews.js.map +1 -1
  90. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +1 -1
  91. package/plugins/hooks/notifications/changeRequestAfterCreate.js +2 -2
  92. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  93. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
  94. package/plugins/hooks/notifications/commentAfterCreate.d.ts +1 -1
  95. package/plugins/hooks/notifications/commentAfterCreate.js +2 -2
  96. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  97. package/plugins/hooks/notifications/commentUrl.js.map +1 -1
  98. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +1 -1
  99. package/plugins/hooks/notifications/contentReviewAfterCreate.js +2 -2
  100. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  101. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
  102. package/plugins/hooks/notifications/contentUrl.d.ts +2 -2
  103. package/plugins/hooks/notifications/contentUrl.js.map +1 -1
  104. package/plugins/hooks/notifications/getAppUrl.d.ts +2 -0
  105. package/plugins/hooks/notifications/getAppUrl.js +19 -0
  106. package/plugins/hooks/notifications/getAppUrl.js.map +1 -0
  107. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +1 -1
  108. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
  109. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +1 -1
  110. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
  111. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +1 -1
  112. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
  113. package/plugins/hooks/notifications/reviewers.d.ts +1 -1
  114. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  115. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +1 -1
  116. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
  117. package/plugins/hooks/notifications/sendCommentNotification.d.ts +1 -1
  118. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
  119. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +1 -1
  120. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
  121. package/plugins/hooks/updatePendingChangeRequests.d.ts +1 -1
  122. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  123. package/plugins/hooks/updateTotalComments.d.ts +1 -1
  124. package/plugins/hooks/updateTotalComments.js.map +1 -1
  125. package/plugins/hooks/validateChangeRequest.d.ts +1 -1
  126. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  127. package/plugins/hooks/validateComment.d.ts +1 -1
  128. package/plugins/hooks/validateComment.js.map +1 -1
  129. package/plugins/hooks/validateContentReview.d.ts +1 -1
  130. package/plugins/hooks/validateContentReview.js.map +1 -1
  131. package/plugins/utils.d.ts +6 -5
  132. package/plugins/utils.js +6 -5
  133. package/plugins/utils.js.map +1 -1
  134. package/scheduler/createScheduleActionMethods.d.ts +1 -1
  135. package/scheduler/createScheduleActionMethods.js +63 -38
  136. package/scheduler/createScheduleActionMethods.js.map +1 -1
  137. package/scheduler/handlers/executeAction/index.d.ts +2 -2
  138. package/scheduler/handlers/executeAction/index.js +0 -1
  139. package/scheduler/handlers/executeAction/index.js.map +1 -1
  140. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  141. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -1
  142. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  143. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +3 -2
  144. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  145. package/scheduler/handlers/executeAction/security.d.ts +2 -2
  146. package/scheduler/handlers/executeAction/security.js.map +1 -1
  147. package/scheduler/handlers/scheduleAction/index.d.ts +2 -2
  148. package/scheduler/handlers/scheduleAction/index.js +1 -3
  149. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  150. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +3 -3
  151. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  152. package/scheduler/handlers/utils.d.ts +1 -1
  153. package/scheduler/handlers/utils.js +15 -7
  154. package/scheduler/handlers/utils.js.map +1 -1
  155. package/scheduler/index.d.ts +1 -1
  156. package/scheduler/index.js.map +1 -1
  157. package/scheduler/types.d.ts +11 -11
  158. package/scheduler/types.js +3 -6
  159. package/scheduler/types.js.map +1 -1
  160. package/storageOperations/changeRequestStorageOperations.d.ts +2 -2
  161. package/storageOperations/changeRequestStorageOperations.js +13 -25
  162. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  163. package/storageOperations/commentStorageOperations.d.ts +3 -3
  164. package/storageOperations/commentStorageOperations.js +15 -28
  165. package/storageOperations/commentStorageOperations.js.map +1 -1
  166. package/storageOperations/contentReviewStorageOperations.d.ts +3 -3
  167. package/storageOperations/contentReviewStorageOperations.js +14 -27
  168. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  169. package/storageOperations/index.d.ts +3 -3
  170. package/storageOperations/index.js.map +1 -1
  171. package/storageOperations/models/changeRequest.model.d.ts +1 -1
  172. package/storageOperations/models/changeRequest.model.js +5 -6
  173. package/storageOperations/models/changeRequest.model.js.map +1 -1
  174. package/storageOperations/models/comment.model.d.ts +1 -1
  175. package/storageOperations/models/comment.model.js +5 -6
  176. package/storageOperations/models/comment.model.js.map +1 -1
  177. package/storageOperations/models/contentReview.model.d.ts +1 -1
  178. package/storageOperations/models/contentReview.model.js +5 -6
  179. package/storageOperations/models/contentReview.model.js.map +1 -1
  180. package/storageOperations/models/index.d.ts +1 -1
  181. package/storageOperations/models/index.js +5 -5
  182. package/storageOperations/models/index.js.map +1 -1
  183. package/storageOperations/models/reviewer.model.d.ts +1 -1
  184. package/storageOperations/models/reviewer.model.js +5 -6
  185. package/storageOperations/models/reviewer.model.js.map +1 -1
  186. package/storageOperations/models/utils.d.ts +2 -2
  187. package/storageOperations/models/utils.js.map +1 -1
  188. package/storageOperations/models/workflow.model.d.ts +2 -2
  189. package/storageOperations/models/workflow.model.js +5 -6
  190. package/storageOperations/models/workflow.model.js.map +1 -1
  191. package/storageOperations/reviewerStorageOperations.d.ts +3 -3
  192. package/storageOperations/reviewerStorageOperations.js +14 -27
  193. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  194. package/storageOperations/types.d.ts +2 -2
  195. package/storageOperations/types.js.map +1 -1
  196. package/storageOperations/workflowStorageOperations.d.ts +2 -2
  197. package/storageOperations/workflowStorageOperations.js +11 -24
  198. package/storageOperations/workflowStorageOperations.js.map +1 -1
  199. package/types.d.ts +31 -48
  200. package/types.js +6 -12
  201. package/types.js.map +1 -1
  202. package/utils/contentApwSettingsPlugin.d.ts +2 -2
  203. package/utils/contentApwSettingsPlugin.js.map +1 -1
  204. package/utils/errors.js.map +1 -1
  205. package/utils/fieldResolver.d.ts +2 -2
  206. package/utils/fieldResolver.js.map +1 -1
  207. package/utils/pickEntryFieldValues.d.ts +1 -1
  208. package/utils/pickEntryFieldValues.js +1 -2
  209. package/utils/pickEntryFieldValues.js.map +1 -1
  210. package/utils/resolve.d.ts +1 -1
  211. package/utils/resolve.js.map +1 -1
  212. package/plugins/hooks/notifications/appUrl.d.ts +0 -2
  213. package/plugins/hooks/notifications/appUrl.js +0 -20
  214. package/plugins/hooks/notifications/appUrl.js.map +0 -1
  215. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +0 -9
  216. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -36
  217. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +0 -1
  218. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +0 -3
  219. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -28
  220. package/plugins/pageBuilder/apwContentPagePlugins.js.map +0 -1
  221. package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +0 -3
  222. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +0 -22
  223. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +0 -1
  224. package/plugins/pageBuilder/index.d.ts +0 -11
  225. package/plugins/pageBuilder/index.js +0 -44
  226. package/plugins/pageBuilder/index.js.map +0 -1
  227. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +0 -8
  228. package/plugins/pageBuilder/linkContentReviewToPage.js +0 -93
  229. package/plugins/pageBuilder/linkContentReviewToPage.js.map +0 -1
  230. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +0 -8
  231. package/plugins/pageBuilder/linkWorkflowToPage.js +0 -166
  232. package/plugins/pageBuilder/linkWorkflowToPage.js.map +0 -1
  233. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +0 -1
  234. package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -33
  235. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +0 -1
  236. package/plugins/pageBuilder/notifications/commentNotification.d.ts +0 -1
  237. package/plugins/pageBuilder/notifications/commentNotification.js +0 -33
  238. package/plugins/pageBuilder/notifications/commentNotification.js.map +0 -1
  239. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +0 -1
  240. package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -33
  241. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +0 -1
  242. package/plugins/pageBuilder/notifications/contentUrl.d.ts +0 -1
  243. package/plugins/pageBuilder/notifications/contentUrl.js +0 -49
  244. package/plugins/pageBuilder/notifications/contentUrl.js.map +0 -1
  245. package/plugins/pageBuilder/triggerContentReview.d.ts +0 -8
  246. package/plugins/pageBuilder/triggerContentReview.js +0 -41
  247. package/plugins/pageBuilder/triggerContentReview.js.map +0 -1
  248. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +0 -10
  249. package/plugins/pageBuilder/updateContentReviewStatus.js +0 -72
  250. package/plugins/pageBuilder/updateContentReviewStatus.js.map +0 -1
  251. package/plugins/pageBuilder/utils.d.ts +0 -22
  252. package/plugins/pageBuilder/utils.js +0 -152
  253. package/plugins/pageBuilder/utils.js.map +0 -1
@@ -1,3 +1,3 @@
1
- import { LifeCycleHookCallbackParams } from "../../types";
1
+ import type { LifeCycleHookCallbackParams } from "../../types";
2
2
  export declare const updateTotalCommentsCount: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
3
3
  export declare const updateLatestCommentId: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","updateTotalCommentsCount","apw","comment","onCommentAfterDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onCommentAfterCreate","exports","updateLatestCommentId","latestCommentId","onCommentAfterUpdate","safelyGetContentReview","latestComment","list","where","changeRequest","sort"],"sources":["updateTotalComments.ts"],"sourcesContent":["import { LifeCycleHookCallbackParams } from \"~/types\";\nimport {\n extractContentReviewIdAndStep,\n safelyGetContentReview,\n updateContentReview,\n updateContentReviewStep\n} from \"../utils\";\n\nexport const updateTotalCommentsCount = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n const { step } = comment;\n /**\n * After a \"comment\" is deleted, decrement the \"totalComments\" count\n * in the corresponding step of the content review entry.\n */\n if (step) {\n const { id, stepId } = extractContentReviewIdAndStep(step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments - 1\n }))\n };\n }\n });\n }\n });\n\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, increment the \"totalComments\" count\n * of the corresponding step in the content review entry.\n */\n const { id, stepId } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments + 1\n }))\n };\n }\n });\n });\n};\n\nexport const updateLatestCommentId = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterUpdate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n const contentReview = await safelyGetContentReview({\n id,\n contentReviewMethods: apw.contentReview\n });\n\n if (contentReview && contentReview.latestCommentId === comment.id) {\n const [[latestComment]] = await apw.comment.list({\n where: { changeRequest: { id: comment.changeRequest } },\n sort: [\"createdOn_DESC\"]\n });\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: latestComment ? latestComment.id : null\n };\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAOO,MAAMC,wBAAwB,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EAC3FA,GAAG,CAACC,OAAO,CAACC,oBAAoB,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAQ,CAAC,KAAK;IAC9D,MAAM;MAAEG;IAAK,CAAC,GAAGH,OAAO;IACxB;AACR;AACA;AACA;IACQ,IAAIG,IAAI,EAAE;MACN,MAAM;QAAEC,EAAE;QAAEC;MAAO,CAAC,GAAG,IAAAC,oCAA6B,EAACH,IAAI,CAAC;MAE1D,MAAM,IAAAI,0BAAmB,EAAC;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aAAa;QACvCL,EAAE;QACFM,uBAAuB,EAAEC,IAAI,IAAI;UAC7B,OAAO;YACH,GAAGA,IAAI;YACPC,KAAK,EAAE,IAAAC,8BAAuB,EAACF,IAAI,CAACC,KAAK,EAAEP,MAAM,EAAEF,IAAI,KAAK;cACxD,GAAGA,IAAI;cACPW,aAAa,EAAEX,IAAI,CAACW,aAAa,GAAG;Y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jB,EAAE,GAAG;UACxD,CAAC;QACL;MACJ,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACY,OAAA,CAAAC,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_utils","require","updateTotalCommentsCount","apw","comment","onCommentAfterDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onCommentAfterCreate","exports","updateLatestCommentId","latestCommentId","onCommentAfterUpdate","safelyGetContentReview","latestComment","list","where","changeRequest","sort"],"sources":["updateTotalComments.ts"],"sourcesContent":["import type { LifeCycleHookCallbackParams } from \"~/types\";\nimport {\n extractContentReviewIdAndStep,\n safelyGetContentReview,\n updateContentReview,\n updateContentReviewStep\n} from \"../utils\";\n\nexport const updateTotalCommentsCount = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n const { step } = comment;\n /**\n * After a \"comment\" is deleted, decrement the \"totalComments\" count\n * in the corresponding step of the content review entry.\n */\n if (step) {\n const { id, stepId } = extractContentReviewIdAndStep(step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments - 1\n }))\n };\n }\n });\n }\n });\n\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, increment the \"totalComments\" count\n * of the corresponding step in the content review entry.\n */\n const { id, stepId } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments + 1\n }))\n };\n }\n });\n });\n};\n\nexport const updateLatestCommentId = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterUpdate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n const contentReview = await safelyGetContentReview({\n id,\n contentReviewMethods: apw.contentReview\n });\n\n if (contentReview && contentReview.latestCommentId === comment.id) {\n const [[latestComment]] = await apw.comment.list({\n where: { changeRequest: { id: comment.changeRequest } },\n sort: [\"createdOn_DESC\"]\n });\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: latestComment ? latestComment.id : null\n };\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAOO,MAAMC,wBAAwB,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EAC3FA,GAAG,CAACC,OAAO,CAACC,oBAAoB,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAQ,CAAC,KAAK;IAC9D,MAAM;MAAEG;IAAK,CAAC,GAAGH,OAAO;IACxB;AACR;AACA;AACA;IACQ,IAAIG,IAAI,EAAE;MACN,MAAM;QAAE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G,CAACC,OAAO,CAACsB,IAAI,CAAC;QAC7CC,KAAK,EAAE;UAAEC,aAAa,EAAE;YAAEpB,EAAE,EAAEJ,OAAO,CAACwB;UAAc;QAAE,CAAC;QACvDC,IAAI,EAAE,CAAC,gBAAgB;MAC3B,CAAC,CAAC;MAEF,MAAM,IAAAlB,0BAAmB,EAAC;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aAAa;QACvCL,EAAE;QACFM,uBAAuB,EAAED,aAAa,IAAI;UACtC,OAAO;YACH,GAAGA,aAAa;YAChBS,eAAe,EAAEG,aAAa,GAAGA,aAAa,CAACjB,EAAE,GAAG;UACxD,CAAC;QACL;MACJ,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACY,OAAA,CAAAC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import { LifeCycleHookCallbackParams } from "../../types";
1
+ import type { LifeCycleHookCallbackParams } from "../../types";
2
2
  export declare const validateChangeRequest: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_handlerGraphql","_utils","_utils2","validateChangeRequest","apw","changeRequest","onChangeRequestBeforeCreate","subscribe","input","step","id","revisionId","stepId","extractContentReviewIdAndStep","entryId","version","parseIdentifier","WebinyError","contentReview","undefined","get","ex","process","env","NODE_ENV","console","log","message","code","data","NotFoundError","steps","currentStep","find","signOffProvidedOn","exports"],"sources":["validateChangeRequest.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ApwContentReview, LifeCycleHookCallbackParams } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const validateChangeRequest = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onChangeRequestBeforeCreate.subscribe(async ({ input }) => {\n const { step } = input;\n /**\n * We need step to be in a particular format i.e. \"contentReviewId#version#stepId\"\n */\n const { id: revisionId, stepId } = extractContentReviewIdAndStep(step);\n\n const { id: entryId, version } = parseIdentifier(revisionId);\n if (!entryId || !version || !stepId) {\n throw new WebinyError(\n `The step property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_STEP\",\n {\n step\n }\n );\n }\n /**\n * Check whether a contentReview entry exists with provided id.\n */\n let contentReview: ApwContentReview | undefined = undefined;\n try {\n contentReview = await apw.contentReview.get(revisionId);\n } catch (ex) {\n /**\n * There is no need to output the log if this is the test environment.\n */\n if (process.env.NODE_ENV !== \"test\") {\n console.log({\n message: ex.message,\n code: ex.data,\n data: ex.data\n });\n }\n }\n if (!contentReview) {\n throw new NotFoundError(\n `Unable to found \"ContentReview\" with given id \"${revisionId}\"`\n );\n }\n /**\n * Don't allow \"change request\" creation once the sign-off has been provided.\n */\n const { steps } = contentReview;\n const currentStep = steps.find(step => step.id === stepId);\n\n if (currentStep && currentStep.signOffProvidedOn) {\n throw new WebinyError(\n `Please retract the sign-off before opening a new change request.`,\n \"SIGN_OFF_PROVIDED\",\n {\n step: currentStep,\n stepId: stepId\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEO,MAAMI,qBAAqB,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EACxFA,GAAG,CAACC,aAAa,CAACC,2BAA2B,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACzE,MAAM;MAAEC;IAAK,CAAC,GAAGD,KAAK;IACtB;AACR;AACA;IACQ,MAAM;MAAEE,EAAE,EAAEC,UAAU;MAAEC;IAAO,CAAC,GAAG,IAAAC,oCAA6B,EAACJ,IAAI,CAAC;IAEtE,MAAM;MAAEC,EAAE,EAAEI,OAAO;MAAEC;IAAQ,CAAC,GAAG,IAAAC,uBAAe,EAACL,UAAU,CAAC;IAC5D,IAAI,CAACG,OAAO,IAAI,CAACC,OAAO,IAAI,CAACH,MAAM,EAAE;MACjC,MAAM,IAAIK,cAAW,CAChB,uDAAsD,EACvD,+BAA+B,EAC/B;QACIR;MACJ,CACJ,CAAC;IACL;IACA;AACR;AACA;IACQ,IAAIS,aAA2C,GAAGC,SAAS;IAC3D,IAAI;MACAD,aAAa,GAAG,MAAMd,GAAG,CAACc,aAAa,CAACE,GAAG,CAACT,UAAU,CAAC;IAC3D,CAAC,CAAC,OAAOU,EAAE,EAAE;MACT;AACZ;AACA;MACY,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE;QACjCC,OAAO,CAACC,GAAG,CAAC;UACRC,OAAO,EAAEN,EAAE,CAACM,OAAO;UACnBC,IAAI,EAAEP,EAAE,CAACQ,IAAI;UACbA,IAAI,EAAER,EAAE,CAACQ;QACb,CAAC,CAAC;MACN;IACJ;IACA,IAAI,CAACX,aAAa,EAAE;MAChB,MAAM,IAAIY,6BAAa,CAClB,kDAAiDnB,UAAW,GACjE,CAAC;IACL;IACA;AACR;AACA;IACQ,MAAM;MAAEoB;IAAM,CAAC,GAAGb,aAAa;IAC/B,MAAMc,WAAW,GAAGD,KAAK,CAACE,IAAI,CAACxB,IAAI,IAAIA,IAAI,CAACC,EAAE,KAAKE,MAAM,CAAC;IAE1D,IAAIoB,WAAW,IAAIA,WAAW,CAACE,iBAAiB,EAAE;MAC9C,MAAM,IAAIjB,cAAW,CAChB,kEAAiE,EAClE,mBAAmB,EACnB;QACIR,IAAI,EAAEuB,WAAW;QACjBpB,MAAM,EAAEA;MACZ,CACJ,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAACuB,OAAA,CAAAhC,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_handlerGraphql","_utils","_utils2","validateChangeRequest","apw","changeRequest","onChangeRequestBeforeCreate","subscribe","input","step","id","revisionId","stepId","extractContentReviewIdAndStep","entryId","version","parseIdentifier","WebinyError","contentReview","undefined","get","ex","process","env","NODE_ENV","console","log","message","code","data","NotFoundError","steps","currentStep","find","signOffProvidedOn","exports"],"sources":["validateChangeRequest.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { ApwContentReview, LifeCycleHookCallbackParams } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const validateChangeRequest = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onChangeRequestBeforeCreate.subscribe(async ({ input }) => {\n const { step } = input;\n /**\n * We need step to be in a particular format i.e. \"contentReviewId#version#stepId\"\n */\n const { id: revisionId, stepId } = extractContentReviewIdAndStep(step);\n\n const { id: entryId, version } = parseIdentifier(revisionId);\n if (!entryId || !version || !stepId) {\n throw new WebinyError(\n `The step property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_STEP\",\n {\n step\n }\n );\n }\n /**\n * Check whether a contentReview entry exists with provided id.\n */\n let contentReview: ApwContentReview | undefined = undefined;\n try {\n contentReview = await apw.contentReview.get(revisionId);\n } catch (ex) {\n /**\n * There is no need to output the log if this is the test environment.\n */\n if (process.env.NODE_ENV !== \"test\") {\n console.log({\n message: ex.message,\n code: ex.data,\n data: ex.data\n });\n }\n }\n if (!contentReview) {\n throw new NotFoundError(\n `Unable to found \"ContentReview\" with given id \"${revisionId}\"`\n );\n }\n /**\n * Don't allow \"change request\" creation once the sign-off has been provided.\n */\n const { steps } = contentReview;\n const currentStep = steps.find(step => step.id === stepId);\n\n if (currentStep && currentStep.signOffProvidedOn) {\n throw new WebinyError(\n `Please retract the sign-off before opening a new change request.`,\n \"SIGN_OFF_PROVIDED\",\n {\n step: currentStep,\n stepId: stepId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B,UAAU,GAChE,CAAC;IACL;IACA;AACR;AACA;IACQ,MAAM;MAAEoB;IAAM,CAAC,GAAGb,aAAa;IAC/B,MAAMc,WAAW,GAAGD,KAAK,CAACE,IAAI,CAACxB,IAAI,IAAIA,IAAI,CAACC,EAAE,KAAKE,MAAM,CAAC;IAE1D,IAAIoB,WAAW,IAAIA,WAAW,CAACE,iBAAiB,EAAE;MAC9C,MAAM,IAAIjB,cAAW,CACjB,kEAAkE,EAClE,mBAAmB,EACnB;QACIR,IAAI,EAAEuB,WAAW;QACjBpB,MAAM,EAAEA;MACZ,CACJ,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAACuB,OAAA,CAAAhC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import { LifeCycleHookCallbackParams } from "../../types";
1
+ import type { LifeCycleHookCallbackParams } from "../../types";
2
2
  export declare const validateComment: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_utils","validateComment","apw","comment","onCommentBeforeCreate","subscribe","input","changeRequest","changeRequestId","result","parseIdentifier","WebinyError","ex","get","step","exports"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\nimport { parseIdentifier, ParseIdentifierResult } from \"@webiny/utils\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentBeforeCreate.subscribe(async ({ input }) => {\n const { changeRequest: changeRequestId } = input;\n /**\n * We need changeRequest to be in a particular format i.e. \"contentReviewUniqueId#version\"\n */\n let result: ParseIdentifierResult;\n try {\n result = parseIdentifier(changeRequestId);\n if (!result) {\n throw new WebinyError(\n \"Could not parse changeRequestId.\",\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n changeRequestId\n }\n );\n }\n } catch (ex) {\n throw new WebinyError(\n `The\"changeRequest\" property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n input\n }\n );\n }\n\n /**\n * Assign value for \"step\" field from \"changeRequest\".\n */\n const changeRequest = await apw.changeRequest.get(changeRequestId);\n if (!changeRequest) {\n return;\n }\n input.step = changeRequest.step;\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,eAAe,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EAClFA,GAAG,CAACC,OAAO,CAACC,qBAAqB,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAgB,CAAC,GAAGF,KAAK;IAChD;AACR;AACA;IACQ,IAAIG,MAA6B;IACjC,IAAI;MACAA,MAAM,GAAG,IAAAC,sBAAe,EAACF,eAAe,CAAC;MACzC,IAAI,CAACC,MAAM,EAAE;QACT,MAAM,IAAIE,cAAW,CACjB,kCAAkC,EAClC,6BAA6B,EAC7B;UACIH;QACJ,CACJ,CAAC;MACL;IACJ,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,MAAM,IAAID,cAAW,CAChB,iEAAgE,EACjE,6BAA6B,EAC7B;QACIL;MACJ,CACJ,CAAC;IACL;;IAEA;AACR;AACA;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAa,CAACM,GAAG,CAACL,eAAe,CAAC;IAClE,IAAI,CAACD,aAAa,EAAE;MAChB;IACJ;IACAD,KAAK,CAACQ,IAAI,GAAGP,aAAa,CAACO,IAAI;EACnC,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAd,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_utils","validateComment","apw","comment","onCommentBeforeCreate","subscribe","input","changeRequest","changeRequestId","result","parseIdentifier","WebinyError","ex","get","step","exports"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { LifeCycleHookCallbackParams } from \"~/types\";\nimport type { ParseIdentifierResult } from \"@webiny/utils\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentBeforeCreate.subscribe(async ({ input }) => {\n const { changeRequest: changeRequestId } = input;\n /**\n * We need changeRequest to be in a particular format i.e. \"contentReviewUniqueId#version\"\n */\n let result: ParseIdentifierResult;\n try {\n result = parseIdentifier(changeRequestId);\n if (!result) {\n throw new WebinyError(\n \"Could not parse changeRequestId.\",\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n changeRequestId\n }\n );\n }\n } catch (ex) {\n throw new WebinyError(\n `The\"changeRequest\" property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n input\n }\n );\n }\n\n /**\n * Assign value for \"step\" field from \"changeRequest\".\n */\n const changeRequest = await apw.changeRequest.get(changeRequestId);\n if (!changeRequest) {\n return;\n }\n input.step = changeRequest.step;\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,eAAe,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EAClFA,GAAG,CAACC,OAAO,CAACC,qBAAqB,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAgB,CAAC,GAAGF,KAAK;IAChD;AACR;AACA;IACQ,IAAIG,MAA6B;IACjC,IAAI;MACAA,MAAM,GAAG,IAAAC,sBAAe,EAACF,eAAe,CAAC;MACzC,IAAI,CAACC,MAAM,EAAE;QACT,MAAM,IAAIE,cAAW,CACjB,kCAAkC,EAClC,6BAA6B,EAC7B;UACIH;QACJ,CACJ,CAAC;MACL;IACJ,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,MAAM,IAAID,cAAW,CACjB,iEAAiE,EACjE,6BAA6B,EAC7B;QACIL;MACJ,CACJ,CAAC;IACL;;IAEA;AACR;AACA;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAa,CAACM,GAAG,CAACL,eAAe,CAAC;IAClE,IAAI,CAACD,aAAa,EAAE;MAChB;IACJ;IACAD,KAAK,CAACQ,IAAI,GAAGP,aAAa,CAACO,IAAI;EACnC,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAd,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import { LifeCycleHookCallbackParams } from "../../types";
1
+ import type { LifeCycleHookCallbackParams } from "../../types";
2
2
  export declare const validateContentReview: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","validateContentReview","apw","contentReview","onContentReviewBeforeCreate","subscribe","input","content","contentReviewId","isReviewRequired","WebinyError","exports"],"sources":["validateContentReview.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateContentReview = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { content } = input;\n /**\n * Check whether a contentReview already exists for provided content.\n */\n const { contentReviewId } = await apw.contentReview.isReviewRequired(content);\n if (contentReviewId) {\n throw new WebinyError(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n content\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGO,MAAMC,qBAAqB,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EACxFA,GAAG,CAACC,aAAa,CAACC,2BAA2B,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACzE,MAAM;MAAEC;IAAQ,CAAC,GAAGD,KAAK;IACzB;AACR;AACA;IACQ,MAAM;MAAEE;IAAgB,CAAC,GAAG,MAAMN,GAAG,CAACC,aAAa,CAACM,gBAAgB,CAACF,OAAO,CAAC;IAC7E,IAAIC,eAAe,EAAE;MACjB,MAAM,IAAIE,cAAW,CAChB,4DAA2D,EAC5D,sBAAsB,EACtB;QACIF,eAAe;QACfD;MACJ,CACJ,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAACI,OAAA,CAAAV,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","validateContentReview","apw","contentReview","onContentReviewBeforeCreate","subscribe","input","content","contentReviewId","isReviewRequired","WebinyError","exports"],"sources":["validateContentReview.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateContentReview = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { content } = input;\n /**\n * Check whether a contentReview already exists for provided content.\n */\n const { contentReviewId } = await apw.contentReview.isReviewRequired(content);\n if (contentReviewId) {\n throw new WebinyError(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n content\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGO,MAAMC,qBAAqB,GAAGA,CAAC;EAAEC;AAA8C,CAAC,KAAK;EACxFA,GAAG,CAACC,aAAa,CAACC,2BAA2B,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACzE,MAAM;MAAEC;IAAQ,CAAC,GAAGD,KAAK;IACzB;AACR;AACA;IACQ,MAAM;MAAEE;IAAgB,CAAC,GAAG,MAAMN,GAAG,CAACC,aAAa,CAACM,gBAAgB,CAACF,OAAO,CAAC;IAC7E,IAAIC,eAAe,EAAE;MACjB,MAAM,IAAIE,cAAW,CACjB,4DAA4D,EAC5D,sBAAsB,EACtB;QACIF,eAAe;QACfD;MACJ,CACJ,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAACI,OAAA,CAAAV,qBAAA,GAAAA,qBAAA","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;
@@ -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,11 +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 _get = _interopRequireDefault(require("lodash/get"));
9
7
  var _types = require("../types");
10
8
  const hasReviewer = async params => {
11
9
  const {
@@ -23,7 +21,10 @@ const hasReviewer = async params => {
23
21
  };
24
22
  exports.hasReviewer = hasReviewer;
25
23
  const getValue = (object, key) => {
26
- return (0, _get.default)(object, `values.${key}`);
24
+ if (!object.values) {
25
+ return undefined;
26
+ }
27
+ return object.values[key];
27
28
  };
28
29
  exports.getValue = getValue;
29
30
  const getContentReviewStepInitialStatus = (workflowSteps, index, previousStepStatus) => {
@@ -135,8 +136,8 @@ const workflowByPrecedenceDesc = (a, b) => {
135
136
  };
136
137
  exports.workflowByPrecedenceDesc = workflowByPrecedenceDesc;
137
138
  const workflowByCreatedOnDesc = (a, b) => {
138
- const createdOnA = (0, _get.default)(a, "createdOn");
139
- const createdOnB = (0, _get.default)(b, "createdOn");
139
+ const createdOnA = a.createdOn;
140
+ const createdOnB = b.createdOn;
140
141
  /**
141
142
  * In descending order of workflow createdOn i.e. the most recent one first.
142
143
  */
@@ -1 +1 @@
1
- {"version":3,"names":["_get","_interopRequireDefault","require","_types","hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","exports","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,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AA0BO,MAAME,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,OAAO,IAAAC,YAAG,EAACF,MAAM,EAAG,UAASC,GAAI,EAAC,CAAC;AACvC,CAAC;AAACH,OAAA,CAAAC,QAAA,GAAAA,QAAA;AAEK,MAAMI,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,MAA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jC,CAAC;AAEM,MAAMC,wBAAwB,GAAGA,CAACC,CAAc,EAAEC,CAAc,KAAK;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAK,CAACzC,IAAI,CAAC;EAChD,MAAM0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAK,CAACzC,IAAI,CAAC;EAChD;AACJ;AACA;EACI,OAAO0C,MAAM,GAAGF,MAAM;AAC1B,CAAC;AAACpD,OAAA,CAAAiD,wBAAA,GAAAA,wBAAA;AAEK,MAAMM,uBAAuB,GAAGA,CAACL,CAAc,EAAEC,CAAc,KAAK;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAG,EAAC8C,CAAC,EAAE,WAAW,CAAC;EACtC,MAAMO,UAAU,GAAG,IAAArD,YAAG,EAAC+C,CAAC,EAAE,WAAW,CAAC;EACtC;AACJ;AACA;EACI,OAAO,IAAIO,IAAI,CAACD,UAAU,CAAC,CAACE,OAAO,CAAC,CAAC,GAAG,IAAID,IAAI,CAACF,UAAU,CAAC,CAACG,OAAO,CAAC,CAAC;AAC1E,CAAC;AAAC3D,OAAA,CAAAuD,uBAAA,GAAAA,uBAAA"}
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,C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AAA,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;
@@ -1,44 +1,64 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.createScheduleActionMethods = createScheduleActionMethods;
7
- var _fields = require("@commodo/fields");
8
- var _validation = require("@webiny/validation");
9
8
  var _utils = require("@webiny/utils");
10
9
  var _types = require("./types");
11
- /**
12
- * Package @commodo/fields does not have types.
13
- */
14
- // @ts-expect-error
15
-
16
- const CreateDataModel = (0, _fields.withFields)(instance => {
17
- return {
18
- datetime: (0, _fields.string)({
19
- validation: _validation.validation.create(`required`)
20
- }),
21
- type: (0, _fields.string)({
22
- validation: _validation.validation.create(`required,in:${_types.ApwContentTypes.PAGE}:${_types.ApwContentTypes.CMS_ENTRY}`)
23
- }),
24
- action: (0, _fields.string)({
25
- validation: _validation.validation.create(`required,in:${_types.ApwScheduleActionTypes.PUBLISH}:${_types.ApwScheduleActionTypes.UNPUBLISH}`)
26
- }),
27
- entryId: (0, _fields.string)({
28
- validation: _validation.validation.create(`required`)
29
- }),
30
- modelId: (0, _fields.string)({
31
- validation: value => {
32
- if (instance.type !== _types.ApwContentTypes.CMS_ENTRY) {
33
- return true;
34
- } else if (!!value) {
35
- return true;
36
- }
37
- throw new Error(`There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`);
38
- }
39
- })
40
- };
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
+ };
41
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
+ });
42
62
  function createScheduleActionMethods({
43
63
  storageOperations,
44
64
  getIdentity,
@@ -72,10 +92,12 @@ function createScheduleActionMethods({
72
92
  });
73
93
  },
74
94
  async create(input) {
75
- const createDataModel = new CreateDataModel().populate(input);
76
- await createDataModel.validate();
95
+ const validation = createDataModelValidation.safeParse(input);
96
+ if (!validation.success) {
97
+ throw (0, _utils.createZodError)(validation.error);
98
+ }
99
+ const data = validation.data;
77
100
  const id = (0, _utils.mdbid)();
78
- const data = await createDataModel.toJSON();
79
101
  const currentDateTime = new Date();
80
102
  const currentIdentity = getIdentity();
81
103
  const scheduleAction = {
@@ -102,9 +124,12 @@ function createScheduleActionMethods({
102
124
  input
103
125
  });
104
126
  },
105
- async update(id, data) {
106
- const updateDataModel = new CreateDataModel().populate(data);
107
- 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;
108
133
  const original = await this.get(id);
109
134
  if (!original) {
110
135
  throw new Error("Not found!");
@@ -1 +1 @@
1
- {"version":3,"names":["_fields","require","_validation","_utils","_types","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","data","toJSON","currentDateTime","Date","currentIdentity","scheduleAction","createdOn","toISOString","modifiedOn","savedOn","createdBy","displayName","modifiedBy","savedBy","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-expect-error\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { mdbid } from \"@webiny/utils\";\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\n const data: ApwScheduleActionData = await createDataModel.toJSON();\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, 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,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAPA;AACA;AACA;AACA;;AAaA,MAAMI,eAAe,GAAG,IAAAC,kBAAU,EAAEC,QAAa,IAAK;EAClD,OAAO;IACHC,QAAQ,EAAE,IAAAC,cAAM,EAAC;MACbC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAE,UAAS;IAC5C,CAAC,CAAC;IACFC,IAAI,EAAE,IAAAH,cAAM,EAAC;MACTC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CACxB,eAAcE,sBAAe,CAACC,IAAK,IAAGD,sBAAe,CAACE,SAAU,EACrE;IACJ,CAAC,CAAC;IACFC,MAAM,EAAE,IAAAP,cAAM,EAAC;MACXC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CACxB,eAAcM,6BAAsB,CAACC,OAAQ,IAAGD,6BAAsB,CAACE,SAAU,EACtF;IACJ,CAAC,CAAC;IACFC,OAAO,EAAE,IAAAX,cAAM,EAAC;MACZC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAE,UAAS;IAC5C,CAAC,CAAC;IACFU,OAAO,EAAE,IAAAZ,cAAM,EAAC;MACZC,UAAU,EAAGY,KAAa,IAAK;QAC3B,IAAIf,QAAQ,CAACK,IAAI,KAAKC,sBAAe,CAACE,SAAS,EAAE;UAC7C,OAAO,IAAI;QACf,CAAC,MAAM,IAAI,CAAC,CAACO,KAAK,EAAE;UAChB,OAAO,IAAI;QACf;QACA,MAAM,IAAIC,KAAK,CACV,6CAA4CV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ACD,MAAMiC,cAAcA,CAAA,EAAG;MACnB,OAAO,MAAMrC,iBAAiB,CAACqC,cAAc,CAAC;QAAE3B,KAAK,EAAE;UAAE,GAAGN,kBAAkB,CAAC;QAAE;MAAE,CAAC,CAAC;IACzF,CAAC;IACD,MAAMkC,iBAAiBA,CAACN,IAAI,EAAE;MAC1B,OAAO,MAAMhC,iBAAiB,CAACsC,iBAAiB,CAAC;QAAEN;MAAK,CAAC,CAAC;IAC9D,CAAC;IACD,MAAMO,iBAAiBA,CAAA,EAAG;MACtB,OAAO,MAAMvC,iBAAiB,CAACuC,iBAAiB,CAAC;QAAE,GAAGnC,kBAAkB,CAAC;MAAE,CAAC,CAAC;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,CAAC;EACJC,QAAQ,EAAEF,YAAG,CAACG,MAAM,CAAC,CAAC;EACtBC,IAAI,EAAEJ,YAAG,CAACK,IAAI,CAAC,CAACC,sBAAe,CAACC,IAAI,EAAED,sBAAe,CAACE,SAAS,CAAC,CAAC;EACjEC,MAAM,EAAET,YAAG,CAACK,IAAI,CAAC,CAACK,6BAAsB,CAACC,OAAO,EAAED,6BAAsB,CAACE,SAAS,CA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,IAAI;MAEnD,MAAMsC,QAAQ,GAAG,MAAM,IAAI,CAAC1B,GAAG,CAACH,EAAE,CAAC;MAEnC,IAAI,CAAC6B,QAAQ,EAAE;QACX,MAAM,IAAIC,KAAK,CAAC,YAAY,CAAC;MACjC;MAEA,OAAO,MAAMpC,iBAAiB,CAACkC,MAAM,CAAC;QAAED,IAAI,EAAEE,QAAQ;QAAErB,KAAK,EAAEjB;MAAK,CAAC,CAAC;IAC1E,CAAC;IACD,MAAMwC,MAAMA,CAAC/B,EAAU,EAAE;MACrB,MAAMN,iBAAiB,CAACqC,MAAM,CAAC;QAAE/B,EAAE;QAAE,GAAGF,kBAAkB,CAAC;MAAE,CAAC,CAAC;MAE/D,OAAO,IAAI;IACf,CAAC;IACD,MAAMkC,cAAcA,CAAA,EAAG;MACnB,OAAO,MAAMtC,iBAAiB,CAACsC,cAAc,CAAC;QAAE5B,KAAK,EAAE;UAAE,GAAGN,kBAAkB,CAAC;QAAE;MAAE,CAAC,CAAC;IACzF,CAAC;IACD,MAAMmC,iBAAiBA,CAACN,IAAI,EAAE;MAC1B,OAAO,MAAMjC,iBAAiB,CAACuC,iBAAiB,CAAC;QAAEN;MAAK,CAAC,CAAC;IAC9D,CAAC;IACD,MAAMO,iBAAiBA,CAAA,EAAG;MACtB,OAAO,MAAMxC,iBAAiB,CAACwC,iBAAiB,CAAC;QAAE,GAAGpC,kBAAkB,CAAC;MAAE,CAAC,CAAC;IACjF;EACJ,CAAC;AACL","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { ApwScheduleActionStorageOperations } 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) => (ContextPlugin<import("@webiny/api/types").Context> | (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>)[];
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 {};
@@ -170,7 +170,6 @@ const createExecuteActionLambda = params => {
170
170
  }
171
171
  });
172
172
  };
173
-
174
173
  const executeActionHandlerPlugins = config => [new _api.ContextPlugin(async context => {
175
174
  context.plugins.register([new _PageBuilderGraphQL.PageBuilderGraphQL(), new _HeadlessCMSGraphQL.HeadlessCMSGraphQL()]);
176
175
  }), (0, _utils.basePlugins)(), createExecuteActionLambda(config)];
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","_api","_PageBuilderGraphQL","_HeadlessCMSGraphQL","_ApplicationGraphQL","_handlerAws","createExecuteActionLambda","params","storageOperations","createRawEventHandler","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","url","getUrl","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","delete","content","ex","message","code","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins","exports"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createRawEventHandler<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n console.log(`Invoking Lambda \"${name}\" with url \"${url}\".`);\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: url,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n /**\n *\n */\n await storageOperations.delete({\n locale,\n tenant,\n id: item.id\n });\n /**\n * Check for the response and log the error if any.\n */\n if (response?.body) {\n const error = response.body.data?.content?.error;\n if (!error) {\n console.log(\"Invoke successful.\");\n continue;\n }\n console.log(JSON.stringify({ error }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (ex) {\n console.error(\n \"[HANDLER_EXECUTE_ACTION] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAaA;AACA;AACA;AACA,MAAMM,yBAAyB,GAAIC,MAAqB,IAAK;EACzD,MAAM;IAAEC;EAAkB,CAAC,GAAGD,MAAM;EAEpC,OAAO,IAAAE,iCAAqB,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IACtE,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvB,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAO,CAACC,MAAM,CACpDC,sCAAkB,CAACC,IACvB,CAAC;IAED,IAAIJ,yBAAyB,CAACK,MAAM,KAAK,CAAC,EAAE;MACxCN,OAAO,CAACO,KAAK,CAAE,mEAAkE,CAAC;MAClF;IACJ;IAEA,MAAMC,6BAAiE,GAAG,CAAC,CAAC;IAE5E,MAAMC,2BAA2B,GAC7BC,IAA2B,IACC;MAC5B,MAAM;QAAEL;MAAK,CAAC,GAAGK,IAAI;MACrB,IAAIF,6BAA6B,CAACH,IAAI,CAAC,EAAE;QACrC,OAAOG,6BAA6B,CAACH,IAAI,CAAC;MAC9C;MACA,KAAK,MAAMM,MAAM,IAAIV,yBAAyB,EAAE;QAC5C,IAAI,CAACU,MAAM,CAACC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,CACL,CAAC;MACD;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAM0C,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMxD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAACqD,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,CAAC,CAAC,EAAE,IAAIC,sCAAkB,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,EAAC,CAAC,EACbjE,yBAAyB,CAAC4D,MAAM,CAAC,CACpC;AAACM,OAAA,CAAAP,2BAAA,GAAAA,2BAAA"}
1
+ {"version":3,"names":["_utils","require","_api","_PageBuilderGraphQL","_HeadlessCMSGraphQL","_ApplicationGraphQL","_handlerAws","createExecuteActionLambda","params","storageOperations","createRawEventHandler","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","url","getUrl","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","delete","content","ex","message","code","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins","exports"],"sources":["index.ts"],"sourcesContent":["import type { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createRawEventHandler<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n console.log(`Invoking Lambda \"${name}\" with url \"${url}\".`);\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: url,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n /**\n *\n */\n await storageOperations.delete({\n locale,\n tenant,\n id: item.id\n });\n /**\n * Check for the response and log the error if any.\n */\n if (response?.body) {\n const error = response.body.data?.content?.error;\n if (!error) {\n console.log(\"Invoke successful.\");\n continue;\n }\n console.log(JSON.stringify({ error }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (ex) {\n console.error(\n \"[HANDLER_EXECUTE_ACTION] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"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AW,EAAC,CAAC,EACbjE,yBAAyB,CAAC4D,MAAM,CAAC,CACpC;AAACM,OAAA,CAAAP,2BAAA,GAAAA,2BAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_Plugin","require","_types","_utils","ApplicationGraphQL","Plugin","type","exports"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport { ApwScheduleActionData, ApwSettings };\n\nexport interface ApplicationGraphQLGetUrlParams {\n tenant: string;\n locale: string;\n}\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract getUrl(params: ApplicationGraphQLGetUrlParams): string;\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAaO,MAAeG,kBAAkB,SAASC,cAAM,CAAC;EACpD,OAAgCC,IAAI,GAAW,kCAAkC;AASrF;AAACC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["_Plugin","require","_types","_utils","ApplicationGraphQL","Plugin","type","exports"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport { ApwScheduleActionData, ApwSettings };\n\nexport interface ApplicationGraphQLGetUrlParams {\n tenant: string;\n locale: string;\n}\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract getUrl(params: ApplicationGraphQLGetUrlParams): string;\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAaO,MAAeG,kBAAkB,SAASC,cAAM,CAAC;EACpD,OAAgCC,IAAI,GAAW,kCAAkC;AASrF;AAACC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -1,4 +1,5 @@
1
- import { ApplicationGraphQL, ApplicationGraphQLBody, ApwSettings, ApplicationGraphQLGetUrlParams, ApwScheduleActionData } from "./ApplicationGraphQL";
1
+ import type { ApplicationGraphQLBody, ApwSettings, ApplicationGraphQLGetUrlParams, ApwScheduleActionData } from "./ApplicationGraphQL";
2
+ import { ApplicationGraphQL } from "./ApplicationGraphQL";
2
3
  export declare class HeadlessCMSGraphQL extends ApplicationGraphQL {
3
4
  name: string;
4
5
  canUse(data: ApwScheduleActionData): boolean;
@@ -1 +1 @@
1
- {"version":3,"names":["_ApplicationGraphQL","require","_types","_error","_interopRequireDefault","_upperFirst","META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","name","canUse","data","type","ApwContentTypes","CMS_ENTRY","getUrl","locale","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId","exports"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwSettings,\n ApplicationGraphQLGetUrlParams,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n lastPublishedOn\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n lastPublishedOn\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.headlessCms\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getUrl({ locale }: ApplicationGraphQLGetUrlParams): string {\n return `/cms/manage/${locale}`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAD,sBAAA,CAAAH,OAAA;AAEA,MAAMK,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,qBAAqB,GAAIC,OAAe,IAAa;EACvD,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAACF,OAAO,CAAC;EAE1C,OAAQ;AACZ,6BAA6BC,cAAe;AAC5C,8BAA8BA,cAAe;AAC7C;AACA;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAAU;AACV,CAAC;AAED,MAAMK,uBAAuB,GAAIH,OAAe,IAAK;EACjD,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAACF,OAAO,CAAC;EAE1C,OAAQ;AACZ,+BAA+BC,cAAe;AAC9C,gCAAgCA,cAAe;AAC/C;AACA;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AAC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AACoB;MACnB;IACJ,CAAC;EACL;AACJ;AAACC,OAAA,CAAAzB,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["_ApplicationGraphQL","require","_types","_error","_interopRequireDefault","_upperFirst","META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","name","canUse","data","type","ApwContentTypes","CMS_ENTRY","getUrl","locale","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId","exports"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import type {\n ApplicationGraphQLBody,\n ApwSettings,\n ApplicationGraphQLGetUrlParams,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApplicationGraphQL } from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n lastPublishedOn\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n lastPublishedOn\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.headlessCms\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getUrl({ locale }: ApplicationGraphQLGetUrlParams): string {\n return `/cms/manage/${locale}`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAD,sBAAA,CAAAH,OAAA;AAEA,MAAMK,WAAW,GAAG;AACpB;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAG;AACpB;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,qBAAqB,GAAIC,OAAe,IAAa;EACvD,MAA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ACA,OAAO;MACHiB,KAAK,EAAE1B,qBAAqB,CAACS,IAAI,CAACR,OAAO,CAAC;MAC1C0B,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MACnB;IACJ,CAAC;EACL;EAEQL,gBAAgBA,CACpBf,IAA2B,EAC4B;IACvD,IAAI,CAACA,IAAI,CAACR,OAAO,EAAE;MACf,MAAM,IAAIwB,cAAW,CACjB,+CAA+C,EAC/C,uBAAuB,EACvB;QACIhB;MACJ,CACJ,CAAC;IACL;IACA,OAAO;MACHiB,KAAK,EAAEtB,uBAAuB,CAACK,IAAI,CAACR,OAAO,CAAC;MAC5C0B,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MACnB;IACJ,CAAC;EACL;AACJ;AAACC,OAAA,CAAAzB,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -1,5 +1,6 @@
1
- import { ApplicationGraphQL, ApplicationGraphQLBody, ApwScheduleActionData } from "./ApplicationGraphQL";
2
- import { ApwSettings } from "../../utils";
1
+ import type { ApplicationGraphQLBody, ApwScheduleActionData } from "./ApplicationGraphQL";
2
+ import { ApplicationGraphQL } from "./ApplicationGraphQL";
3
+ import type { ApwSettings } from "../../utils";
3
4
  export declare class PageBuilderGraphQL extends ApplicationGraphQL {
4
5
  name: string;
5
6
  canUse(data: ApwScheduleActionData): boolean;