@webiny/api-apw 0.0.0-unstable.8c4d9f045a → 0.0.0-unstable.97a151f74d

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 (207) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +40 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +40 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +40 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +40 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +1 -1
  14. package/crud/createChangeRequestMethods.js +21 -18
  15. package/crud/createChangeRequestMethods.js.map +1 -1
  16. package/crud/createCommentMethods.js +21 -18
  17. package/crud/createCommentMethods.js.map +1 -1
  18. package/crud/createContentReviewMethods.js +60 -50
  19. package/crud/createContentReviewMethods.js.map +1 -1
  20. package/crud/createReviewerMethods.js +21 -18
  21. package/crud/createReviewerMethods.js.map +1 -1
  22. package/crud/createWorkflowMethods.d.ts +1 -1
  23. package/crud/createWorkflowMethods.js +42 -20
  24. package/crud/createWorkflowMethods.js.map +1 -1
  25. package/crud/index.js +3 -7
  26. package/crud/index.js.map +1 -1
  27. package/crud/utils.js +4 -8
  28. package/crud/utils.js.map +1 -1
  29. package/index.d.ts +3 -3
  30. package/index.js +8 -4
  31. package/index.js.map +1 -1
  32. package/package.json +38 -37
  33. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +1 -1
  34. package/plugins/cms/apwEntryPlugins.js +4 -8
  35. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  36. package/plugins/cms/index.js +9 -1
  37. package/plugins/cms/index.js.map +1 -1
  38. package/plugins/cms/linkContentReviewToEntry.js +4 -4
  39. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  40. package/plugins/cms/linkWorkflowToEntry.js +5 -5
  41. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  42. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  43. package/plugins/cms/notifications/changeRequestNotification.js +35 -0
  44. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  45. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  46. package/plugins/cms/notifications/commentNotification.js +35 -0
  47. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  48. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  49. package/plugins/cms/notifications/contentReviewNotification.js +35 -0
  50. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  51. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  52. package/plugins/cms/notifications/contentUrl.js +60 -0
  53. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  54. package/plugins/cms/triggerContentReview.js +3 -3
  55. package/plugins/cms/triggerContentReview.js.map +1 -1
  56. package/plugins/cms/updateContentReviewStatus.js +10 -14
  57. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  58. package/plugins/cms/utils.js +4 -8
  59. package/plugins/cms/utils.js.map +1 -1
  60. package/plugins/context.js +1 -1
  61. package/plugins/graphql/changeRequest.gql.js +1 -1
  62. package/plugins/graphql/comment.gql.js +1 -1
  63. package/plugins/graphql/contentReview.gql.js +4 -4
  64. package/plugins/graphql/contentReview.gql.js.map +1 -1
  65. package/plugins/graphql/reviewer.gql.js +3 -1
  66. package/plugins/graphql/reviewer.gql.js.map +1 -1
  67. package/plugins/graphql/workflow.gql.js +1 -1
  68. package/plugins/graphql.js +1 -1
  69. package/plugins/hooks/createReviewerFromIdentity.js +28 -8
  70. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  71. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -1
  72. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  73. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -1
  74. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  75. package/plugins/hooks/index.js +6 -0
  76. package/plugins/hooks/index.js.map +1 -1
  77. package/plugins/hooks/initializeContentReviewSteps.js +5 -8
  78. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  79. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  80. package/plugins/hooks/initializeNotifications.js +20 -0
  81. package/plugins/hooks/initializeNotifications.js.map +1 -0
  82. package/plugins/hooks/listContentReviews.d.ts +10 -0
  83. package/plugins/hooks/listContentReviews.js +68 -0
  84. package/plugins/hooks/listContentReviews.js.map +1 -0
  85. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  86. package/plugins/hooks/notifications/appUrl.js +22 -0
  87. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  88. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  89. package/plugins/hooks/notifications/changeRequestAfterCreate.js +144 -0
  90. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  91. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  92. package/plugins/hooks/notifications/changeRequestUrl.js +31 -0
  93. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  94. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  95. package/plugins/hooks/notifications/commentAfterCreate.js +157 -0
  96. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  97. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  98. package/plugins/hooks/notifications/commentUrl.js +31 -0
  99. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  100. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  101. package/plugins/hooks/notifications/contentReviewAfterCreate.js +122 -0
  102. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  103. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  104. package/plugins/hooks/notifications/contentReviewUrl.js +30 -0
  105. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  106. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  107. package/plugins/hooks/notifications/contentUrl.js +29 -0
  108. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  109. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  110. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +25 -0
  111. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  112. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  113. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +25 -0
  114. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  115. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  116. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +25 -0
  117. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  118. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  119. package/plugins/hooks/notifications/reviewers.js +51 -0
  120. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  121. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  122. package/plugins/hooks/notifications/sendChangeRequestNotification.js +52 -0
  123. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  124. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  125. package/plugins/hooks/notifications/sendCommentNotification.js +52 -0
  126. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  127. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  128. package/plugins/hooks/notifications/sendContentReviewNotification.js +52 -0
  129. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  130. package/plugins/hooks/updatePendingChangeRequests.js +7 -11
  131. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  132. package/plugins/hooks/updateTotalComments.js +14 -18
  133. package/plugins/hooks/updateTotalComments.js.map +1 -1
  134. package/plugins/hooks/validateChangeRequest.js +30 -5
  135. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  136. package/plugins/hooks/validateComment.js +14 -4
  137. package/plugins/hooks/validateComment.js.map +1 -1
  138. package/plugins/hooks/validateContentReview.js +2 -2
  139. package/plugins/hooks/validateContentReview.js.map +1 -1
  140. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +1 -1
  141. package/plugins/pageBuilder/index.js +9 -1
  142. package/plugins/pageBuilder/index.js.map +1 -1
  143. package/plugins/pageBuilder/linkContentReviewToPage.js +41 -29
  144. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  145. package/plugins/pageBuilder/linkWorkflowToPage.js +18 -6
  146. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  147. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  148. package/plugins/pageBuilder/notifications/changeRequestNotification.js +35 -0
  149. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  150. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  151. package/plugins/pageBuilder/notifications/commentNotification.js +35 -0
  152. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  153. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  154. package/plugins/pageBuilder/notifications/contentReviewNotification.js +35 -0
  155. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  156. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  157. package/plugins/pageBuilder/notifications/contentUrl.js +53 -0
  158. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  159. package/plugins/pageBuilder/triggerContentReview.js +3 -3
  160. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  161. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -14
  162. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  163. package/plugins/pageBuilder/utils.js +1 -1
  164. package/plugins/pageBuilder/utils.js.map +1 -1
  165. package/plugins/utils.d.ts +1 -1
  166. package/plugins/utils.js +4 -14
  167. package/plugins/utils.js.map +1 -1
  168. package/scheduler/createScheduleActionMethods.js +17 -14
  169. package/scheduler/createScheduleActionMethods.js.map +1 -1
  170. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  171. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +1 -1
  172. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -1
  173. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +1 -1
  174. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  175. package/scheduler/handlers/scheduleAction/index.js +8 -9
  176. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  177. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +5 -9
  178. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  179. package/scheduler/handlers/utils.d.ts +1 -1
  180. package/scheduler/handlers/utils.js +1 -1
  181. package/storageOperations/changeRequestStorageOperations.js +5 -9
  182. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  183. package/storageOperations/commentStorageOperations.js +4 -8
  184. package/storageOperations/commentStorageOperations.js.map +1 -1
  185. package/storageOperations/contentReviewStorageOperations.js +5 -9
  186. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  187. package/storageOperations/index.js +5 -9
  188. package/storageOperations/index.js.map +1 -1
  189. package/storageOperations/models/contentModelPluginFactory.js +3 -7
  190. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  191. package/storageOperations/models/contentReview.model.js +6 -5
  192. package/storageOperations/models/contentReview.model.js.map +1 -1
  193. package/storageOperations/models/index.js +1 -1
  194. package/storageOperations/models/reviewer.model.js +18 -2
  195. package/storageOperations/models/reviewer.model.js.map +1 -1
  196. package/storageOperations/models/utils.js +3 -2
  197. package/storageOperations/models/utils.js.map +1 -1
  198. package/storageOperations/reviewerStorageOperations.js +18 -14
  199. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  200. package/storageOperations/workflowStorageOperations.js +8 -12
  201. package/storageOperations/workflowStorageOperations.js.map +1 -1
  202. package/types.d.ts +99 -84
  203. package/types.js.map +1 -1
  204. package/utils/errors.js +1 -1
  205. package/utils/fieldResolver.js +3 -9
  206. package/utils/fieldResolver.js.map +1 -1
  207. package/utils/resolve.d.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["updateTotalCommentsCount","apw","comment","onAfterCommentDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onAfterCommentCreate","updateLatestCommentId","latestCommentId","onAfterCommentUpdate","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.onAfterCommentDelete.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.onAfterCommentCreate.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.onAfterCommentCreate.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.onAfterCommentUpdate.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.onAfterCommentDelete.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;;;;;;AAOO,MAAMA,wBAAwB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAC3FA,GAAG,CAACC,OAA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d,KAAkCjB,OAAO,CAACI,EAA/D,EAAmE;MAC/D,MAAM,CAAC,CAACgB,aAAD,CAAD,IAAoB,MAAMrB,GAAG,CAACC,OAAJ,CAAYqB,IAAZ,CAAiB;QAC7CC,KAAK,EAAE;UAAEC,aAAa,EAAE;YAAEnB,EAAE,EAAEJ,OAAO,CAACuB;UAAd;QAAjB,CADsC;QAE7CC,IAAI,EAAE,CAAC,gBAAD;MAFuC,CAAjB,CAAhC;MAKA,MAAM,IAAAjB,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAED,aAAa,IAAI;UACtC,uCACOA,aADP;YAEIQ,eAAe,EAAEG,aAAa,GAAGA,aAAa,CAAChB,EAAjB,GAAsB;UAFxD;QAIH;MARqB,CAApB,CAAN;IAUH;EACJ,CA7BD;AA8BH,CArEM"}
1
+ {"version":3,"names":["updateTotalCommentsCount","apw","comment","onCommentAfterDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onCommentAfterCreate","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;;AAOO,MAAMA,wBAAwB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAC3FA,GAAG,CAACC,OAAJ,CAAYC,oBAAZ,CAAiCC,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D,MAAM;MAAEG;IAAF,IAAWH,OAAjB;IACA;AACR;AACA;AACA;;IACQ,IAAIG,IAAJ,EAAU;MACN,MAAM;QAAEC,EAAF;QAAMC;MAAN,IAAiB,IAAAC,oCAAA,EAA8BH,IAA9B,CAAvB;MAEA,MAAM,IAAAI,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAEC,IAAI,IAAI;UAC7B,mEACOA,IADP;YAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAAI,CAACC,KAA7B,EAAoCP,MAApC,EAA4CF,IAAI,gEAChDA,IADgD;cAEnDW,aAAa,EAAEX,IAAI,CAACW,aAAL,GAAqB;YAFe,EAAhD;UAFX;QAOH;MAXqB,CAApB,CAAN;IAaH;EACJ,CAvBD;EAyBAf,GAAG,CAACC,OAAJ,CAAYe,oBAAZ,CAAiCb,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D;AACR;AACA;AACA;IACQ,MAAM;MAAEI,EAAF;MAAMC;IAAN,IAAiB,IAAAC,oCAAA,EAA8BN,OAAO,CAACG,IAAtC,CAAvB;IAEA,MAAM,IAAAI,0BAAA,EAAoB;MACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;MAEtBL,EAFsB;MAGtBM,uBAAuB,EAAEC,IAAI,IAAI;QAC7B,mEACOA,IADP;UAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAA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AS,IAAAE,oCAAA,EAA8BN,OAAO,CAACG,IAAtC,CAAf;IAEA,MAAMM,aAAa,GAAG,MAAM,IAAAU,6BAAA,EAAuB;MAC/Cf,EAD+C;MAE/CI,oBAAoB,EAAET,GAAG,CAACU;IAFqB,CAAvB,CAA5B;;IAKA,IAAIA,aAAa,IAAIA,aAAa,CAACQ,eAAd,KAAkCjB,OAAO,CAACI,EAA/D,EAAmE;MAC/D,MAAM,CAAC,CAACgB,aAAD,CAAD,IAAoB,MAAMrB,GAAG,CAACC,OAAJ,CAAYqB,IAAZ,CAAiB;QAC7CC,KAAK,EAAE;UAAEC,aAAa,EAAE;YAAEnB,EAAE,EAAEJ,OAAO,CAACuB;UAAd;QAAjB,CADsC;QAE7CC,IAAI,EAAE,CAAC,gBAAD;MAFuC,CAAjB,CAAhC;MAKA,MAAM,IAAAjB,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAED,aAAa,IAAI;UACtC,mEACOA,aADP;YAEIQ,eAAe,EAAEG,aAAa,GAAGA,aAAa,CAAChB,EAAjB,GAAsB;UAFxD;QAIH;MARqB,CAApB,CAAN;IAUH;EACJ,CA7BD;AA8BH,CArEM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,10 +11,14 @@ var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
12
  var _handlerGraphql = require("@webiny/handler-graphql");
13
13
 
14
+ var _utils = require("../utils");
15
+
16
+ var _utils2 = require("@webiny/utils");
17
+
14
18
  const validateChangeRequest = ({
15
19
  apw
16
20
  }) => {
17
- apw.changeRequest.onBeforeChangeRequestCreate.subscribe(async ({
21
+ apw.changeRequest.onChangeRequestBeforeCreate.subscribe(async ({
18
22
  input
19
23
  }) => {
20
24
  const {
@@ -24,7 +28,14 @@ const validateChangeRequest = ({
24
28
  * We need step to be in a particular format i.e. "contentReviewId#version#stepId"
25
29
  */
26
30
 
27
- const [entryId, version, stepId] = step.split("#");
31
+ const {
32
+ id: revisionId,
33
+ stepId
34
+ } = (0, _utils.extractContentReviewIdAndStep)(step);
35
+ const {
36
+ id: entryId,
37
+ version
38
+ } = (0, _utils2.parseIdentifier)(revisionId);
28
39
 
29
40
  if (!entryId || !version || !stepId) {
30
41
  throw new _error.default(`The step property in input is not properly formatted.`, "MALFORMED_CHANGE_REQUEST_STEP", {
@@ -36,8 +47,22 @@ const validateChangeRequest = ({
36
47
  */
37
48
 
38
49
 
39
- const revisionId = `${entryId}#${version}`;
40
- const contentReview = await apw.contentReview.get(revisionId);
50
+ let contentReview = undefined;
51
+
52
+ try {
53
+ contentReview = await apw.contentReview.get(revisionId);
54
+ } catch (ex) {
55
+ /**
56
+ * There is no need to output the log if this is the test environment.
57
+ */
58
+ if (process.env.NODE_ENV !== "test") {
59
+ console.log({
60
+ message: ex.message,
61
+ code: ex.data,
62
+ data: ex.data
63
+ });
64
+ }
65
+ }
41
66
 
42
67
  if (!contentReview) {
43
68
  throw new _handlerGraphql.NotFoundError(`Unable to found "ContentReview" with given id "${revisionId}"`);
@@ -1 +1 @@
1
- {"version":3,"names":["validateChangeRequest","apw","changeRequest","onBeforeChangeRequestCreate","subscribe","input","step","entryId","version","stepId","split","WebinyError","revisionId","contentReview","get","NotFoundError","steps","currentStep","find","id","signOffProvidedOn"],"sources":["validateChangeRequest.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateChangeRequest = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onBeforeChangeRequestCreate.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 [entryId, version, stepId] = step.split(\"#\");\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 const revisionId = `${entryId}#${version}`;\n\n const contentReview = await apw.contentReview.get(revisionId);\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;;AACA;;AAGO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAWD,KAAjB;IACA;AACR;AACA;;IACQ,MAAM,CAACE,OAAD,EAAUC,OAAV,EAAmBC,MAAnB,IAA6BH,IAAI,CAACI,KAAL,CAAW,GAAX,CAAnC;;IACA,IAAI,CAACH,OAAD,IAAY,CAACC,OAAb,IAAwB,CAACC,MAA7B,EAAqC;MACjC,MAAM,IAAIE,cAAJ,CACD,uDADC,EAEF,+BAFE,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;IACD;AACR;AACA;;;IACQ,MAAMM,UAAU,GAAI,GAAEL,OAAQ,IAAGC,OAAQ,EAAzC;IAEA,MAAMK,aAAa,GAAG,MAAMZ,GAAG,CAACY,aAAJ,CAAkBC,GAAlB,CAAsBF,UAAtB,CAA5B;;IACA,IAAI,CAACC,aAAL,EAAoB;MAChB,MAAM,IAAIE,6BAAJ,CACD,kDAAiDH,UAAW,GAD3D,CAAN;IAGH;IACD;AACR;AACA;;;IACQ,MAAM;MAAEI;IAAF,IAAYH,aAAlB;IACA,MAAMI,WAAW,GAAGD,KAAK,CAACE,IAAN,CAAWZ,IAAI,IAAIA,IAAI,CAACa,EAAL,KAAYV,MAA/B,CAApB;;IAEA,IAAIQ,WAAW,IAAIA,WAAW,CAACG,iBAA/B,EAAkD;MAC9C,MAAM,IAAIT,cAAJ,CACD,kEADC,EAEF,mBAFE,EAGF;QACIL,IAAI,EAAEW,WADV;QAEIR,MAAM,EAAEA;MAFZ,CAHE,CAAN;IAQH;EACJ,CA1CD;AA2CH,CA5CM"}
1
+ {"version":3,"names":["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"],"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;;AACA;;AAEA;;AACA;;AAEO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAWD,KAAjB;IACA;AACR;AACA;;IACQ,MAAM;MAAEE,EAAE,EAAEC,UAAN;MAAkBC;IAAlB,IAA6B,IAAAC,oCAAA,EAA8BJ,IAA9B,CAAnC;IAEA,MAAM;MAAEC,EAAE,EAAEI,OAAN;MAAeC;IAAf,IAA2B,IAAAC,uBAAA,EAAgBL,UAAhB,CAAjC;;IACA,IAAI,CAACG,OAAD,IAAY,CAACC,OAAb,IAAwB,CAACH,MAA7B,EAAqC;MACjC,MAAM,IAAIK,cAAJ,CACD,uDADC,EAEF,+BAFE,EAGF;QACIR;MADJ,CAHE,CAAN;IAOH;IACD;AACR;AACA;;;IACQ,IAAIS,aAA2C,GAAGC,SAAlD;;IACA,IAAI;MACAD,aAAa,GAAG,MAAMd,GAAG,CAACc,aAAJ,CAAkBE,GAAlB,CAAsBT,UAAtB,CAAtB;IACH,CAFD,CAEE,OAAOU,EAAP,EAAW;MACT;AACZ;AACA;MACY,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC;QACjCC,OAAO,CAACC,GAAR,CAAY;UACRC,OAAO,EAAEN,EAAE,CAACM,OADJ;UAERC,IAAI,EAAEP,EAAE,CAACQ,IAFD;UAGRA,IAAI,EAAER,EAAE,CAACQ;QAHD,CAAZ;MAKH;IACJ;;IACD,IAAI,CAACX,aAAL,EAAoB;MAChB,MAAM,IAAIY,6BAAJ,CACD,kDAAiDnB,UAAW,GAD3D,CAAN;IAGH;IACD;AACR;AACA;;;IACQ,MAAM;MAAEoB;IAAF,IAAYb,aAAlB;IACA,MAAMc,WAAW,GAAGD,KAAK,CAACE,IAAN,CAAWxB,IAAI,IAAIA,IAAI,CAACC,EAAL,KAAYE,MAA/B,CAApB;;IAEA,IAAIoB,WAAW,IAAIA,WAAW,CAACE,iBAA/B,EAAkD;MAC9C,MAAM,IAAIjB,cAAJ,CACD,kEADC,EAEF,mBAFE,EAGF;QACIR,IAAI,EAAEuB,WADV;QAEIpB,MAAM,EAAEA;MAFZ,CAHE,CAAN;IAQH;EACJ,CAxDD;AAyDH,CA1DM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -9,10 +9,12 @@ exports.validateComment = void 0;
9
9
 
10
10
  var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
+ var _utils = require("@webiny/utils");
13
+
12
14
  const validateComment = ({
13
15
  apw
14
16
  }) => {
15
- apw.comment.onBeforeCommentCreate.subscribe(async ({
17
+ apw.comment.onCommentBeforeCreate.subscribe(async ({
16
18
  input
17
19
  }) => {
18
20
  const {
@@ -22,9 +24,17 @@ const validateComment = ({
22
24
  * We need changeRequest to be in a particular format i.e. "contentReviewUniqueId#version"
23
25
  */
24
26
 
25
- const [entryId, version] = changeRequestId.split("#");
27
+ let result;
28
+
29
+ try {
30
+ result = (0, _utils.parseIdentifier)(changeRequestId);
26
31
 
27
- if (!entryId || !version) {
32
+ if (!result) {
33
+ throw new _error.default("Could not parse changeRequestId.", "MALFORMED_CHANGE_REQUEST_ID", {
34
+ changeRequestId
35
+ });
36
+ }
37
+ } catch (ex) {
28
38
  throw new _error.default(`The"changeRequest" property in input is not properly formatted.`, "MALFORMED_CHANGE_REQUEST_ID", {
29
39
  input
30
40
  });
@@ -1 +1 @@
1
- {"version":3,"names":["validateComment","apw","comment","onBeforeCommentCreate","subscribe","input","changeRequest","changeRequestId","entryId","version","split","WebinyError","get","step"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onBeforeCommentCreate.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 const [entryId, version] = changeRequestId.split(\"#\");\n if (!entryId || !version) {\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;;AAGO,MAAMA,eAAe,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAClFA,GAAG,CAACC,OAAJ,CAAYC,qBAAZ,CAAkCC,SAAlC,CAA4C,OAAO;IAAEC;EAAF,CAAP,KAAqB;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAjB,IAAqCF,KAA3C;IACA;AACR;AACA;;IACQ,MAAM,CAACG,OAAD,EAAUC,OAAV,IAAqBF,eAAe,CAACG,KAAhB,CAAsB,GAAtB,CAA3B;;IACA,IAAI,CAACF,OAAD,IAAY,CAACC,OAAjB,EAA0B;MACtB,MAAM,IAAIE,cAAJ,CACD,iEADC,EAEF,6BAFE,EAGF;QACIN;MADJ,CAHE,CAAN;IAOH;IAED;AACR;AACA;;;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAJ,CAAkBM,GAAlB,CAAsBL,eAAtB,CAA5B;;IACA,IAAI,CAACD,aAAL,EAAoB;MAChB;IACH;;IACDD,KAAK,CAACQ,IAAN,GAAaP,aAAa,CAACO,IAA3B;EACH,CAxBD;AAyBH,CA1BM"}
1
+ {"version":3,"names":["validateComment","apw","comment","onCommentBeforeCreate","subscribe","input","changeRequest","changeRequestId","result","parseIdentifier","WebinyError","ex","get","step"],"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;;AAEA;;AAEO,MAAMA,eAAe,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAClFA,GAAG,CAACC,OAAJ,CAAYC,qBAAZ,CAAkCC,SAAlC,CAA4C,OAAO;IAAEC;EAAF,CAAP,KAAqB;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAjB,IAAqCF,KAA3C;IACA;AACR;AACA;;IACQ,IAAIG,MAAJ;;IACA,IAAI;MACAA,MAAM,GAAG,IAAAC,sBAAA,EAAgBF,eAAhB,CAAT;;MACA,IAAI,CAACC,MAAL,EAAa;QACT,MAAM,IAAIE,cAAJ,CACF,kCADE,EAEF,6BAFE,EAGF;UACIH;QADJ,CAHE,CAAN;MAOH;IACJ,CAXD,CAWE,OAAOI,EAAP,EAAW;MACT,MAAM,IAAID,cAAJ,CACD,iEADC,EAEF,6BAFE,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;IAED;AACR;AACA;;;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAJ,CAAkBM,GAAlB,CAAsBL,eAAtB,CAA5B;;IACA,IAAI,CAACD,aAAL,EAAoB;MAChB;IACH;;IACDD,KAAK,CAACQ,IAAN,GAAaP,aAAa,CAACO,IAA3B;EACH,CAnCD;AAoCH,CArCM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -12,7 +12,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
12
12
  const validateContentReview = ({
13
13
  apw
14
14
  }) => {
15
- apw.contentReview.onBeforeContentReviewCreate.subscribe(async ({
15
+ apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({
16
16
  input
17
17
  }) => {
18
18
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["validateContentReview","apw","contentReview","onBeforeContentReviewCreate","subscribe","input","content","contentReviewId","isReviewRequired","WebinyError"],"sources":["validateContentReview.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateContentReview = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onBeforeContentReviewCreate.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;;AAGO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAcD,KAApB;IACA;AACR;AACA;;IACQ,MAAM;MAAEE;IAAF,IAAsB,MAAMN,GAAG,CAACC,aAAJ,CAAkBM,gBAAlB,CAAmCF,OAAnC,CAAlC;;IACA,IAAIC,eAAJ,EAAqB;MACjB,MAAM,IAAIE,cAAJ,CACD,4DADC,EAEF,sBAFE,EAGF;QACIF,eADJ;QAEID;MAFJ,CAHE,CAAN;IAQH;EACJ,CAhBD;AAiBH,CAlBM"}
1
+ {"version":3,"names":["validateContentReview","apw","contentReview","onContentReviewBeforeCreate","subscribe","input","content","contentReviewId","isReviewRequired","WebinyError"],"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;;AAGO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAcD,KAApB;IACA;AACR;AACA;;IACQ,MAAM;MAAEE;IAAF,IAAsB,MAAMN,GAAG,CAACC,aAAJ,CAAkBM,gBAAlB,CAAmCF,OAAnC,CAAlC;;IACA,IAAIC,eAAJ,EAAqB;MACjB,MAAM,IAAIE,cAAJ,CACD,4DADC,EAEF,sBAFE,EAGF;QACIF,eADJ;QAEID;MAFJ,CAHE,CAAN;IAQH;EACJ,CAhBD;AAiBH,CAlBM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -15,6 +15,14 @@ var _linkWorkflowToPage = require("./linkWorkflowToPage");
15
15
 
16
16
  var _PageApwSettingsGetterPlugin = require("./PageApwSettingsGetterPlugin");
17
17
 
18
+ var _commentNotification = require("./notifications/commentNotification");
19
+
20
+ var _contentUrl = require("./notifications/contentUrl");
21
+
22
+ var _changeRequestNotification = require("./notifications/changeRequestNotification");
23
+
24
+ var _contentReviewNotification = require("./notifications/contentReviewNotification");
25
+
18
26
  const apwPageBuilderHooks = params => {
19
27
  const {
20
28
  pageBuilder,
@@ -22,7 +30,7 @@ const apwPageBuilderHooks = params => {
22
30
  security,
23
31
  plugins
24
32
  } = params;
25
- plugins.register(new _PageApwSettingsGetterPlugin.PageApwSettingsGetterPlugin());
33
+ plugins.register([new _PageApwSettingsGetterPlugin.PageApwSettingsGetterPlugin(), (0, _commentNotification.createCommentNotification)(), (0, _changeRequestNotification.createChangeRequestNotification)(), (0, _contentUrl.createContentUrlPlugin)(), (0, _contentReviewNotification.createContentReviewNotification)()]);
26
34
  (0, _triggerContentReview.triggerContentReview)({
27
35
  apw,
28
36
  pageBuilder
@@ -1 +1 @@
1
- {"version":3,"names":["apwPageBuilderHooks","params","pageBuilder","apw","security","plugins","register","PageApwSettingsGetterPlugin","triggerContentReview","linkContentReviewToPage","updateContentReviewStatus","linkWorkflowToPage"],"sources":["index.ts"],"sourcesContent":["import { Security } from \"@webiny/api-security/types\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\nimport { AdvancedPublishingWorkflow } from \"~/types\";\nimport { triggerContentReview } from \"./triggerContentReview\";\nimport { linkContentReviewToPage } from \"./linkContentReviewToPage\";\nimport { updateContentReviewStatus } from \"./updateContentReviewStatus\";\nimport { linkWorkflowToPage } from \"./linkWorkflowToPage\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { PageApwSettingsGetterPlugin } from \"~/plugins/pageBuilder/PageApwSettingsGetterPlugin\";\n\nexport interface ApwPageBuilderPluginsParams {\n pageBuilder: PageBuilderContextObject;\n apw: AdvancedPublishingWorkflow;\n security: Security;\n plugins: PluginsContainer;\n}\n\nexport const apwPageBuilderHooks = (params: ApwPageBuilderPluginsParams) => {\n const { pageBuilder, apw, security, plugins } = params;\n\n plugins.register(new PageApwSettingsGetterPlugin());\n\n triggerContentReview({\n apw,\n pageBuilder\n });\n linkContentReviewToPage({\n apw,\n pageBuilder\n });\n updateContentReviewStatus({\n apw,\n pageBuilder,\n security\n });\n linkWorkflowToPage({\n apw,\n pageBuilder\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAEA;;AASO,MAAMA,mBAAmB,GAAIC,MAAD,IAAyC;EACxE,MAAM;IAAEC,WAAF;IAAeC,GAAf;IAAoBC,QAApB;IAA8BC;EAA9B,IAA0CJ,MAAhD;EAEAI,OAAO,CAACC,QAAR,CAAiB,IAAIC,wDAAJ,EAAjB;EAEA,IAAAC,0CAAA,EAAqB;IACjBL,GADiB;IAEjBD;EAFiB,CAArB;EAIA,IAAAO,gDAAA,EAAwB;IACpBN,GADoB;IAEpBD;EAFoB,CAAxB;EAIA,IAAAQ,oDAAA,EAA0B;IACtBP,GADsB;IAEtBD,WAFsB;IAGtBE;EAHsB,CAA1B;EAKA,IAAAO,sCAAA,EAAmB;IACfR,GADe;IAEfD;EAFe,CAAnB;AAIH,CAtBM"}
1
+ {"version":3,"names":["apwPageBuilderHooks","params","pageBuilder","apw","security","plugins","register","PageApwSettingsGetterPlugin","createCommentNotification","createChangeRequestNotification","createContentUrlPlugin","createContentReviewNotification","triggerContentReview","linkContentReviewToPage","updateContentReviewStatus","linkWorkflowToPage"],"sources":["index.ts"],"sourcesContent":["import { Security } from \"@webiny/api-security/types\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\nimport { AdvancedPublishingWorkflow } from \"~/types\";\nimport { triggerContentReview } from \"./triggerContentReview\";\nimport { linkContentReviewToPage } from \"./linkContentReviewToPage\";\nimport { updateContentReviewStatus } from \"./updateContentReviewStatus\";\nimport { linkWorkflowToPage } from \"./linkWorkflowToPage\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { PageApwSettingsGetterPlugin } from \"~/plugins/pageBuilder/PageApwSettingsGetterPlugin\";\nimport { createCommentNotification } from \"./notifications/commentNotification\";\nimport { createContentUrlPlugin } from \"./notifications/contentUrl\";\nimport { createChangeRequestNotification } from \"./notifications/changeRequestNotification\";\nimport { createContentReviewNotification } from \"./notifications/contentReviewNotification\";\n\nexport interface ApwPageBuilderPluginsParams {\n pageBuilder: PageBuilderContextObject;\n apw: AdvancedPublishingWorkflow;\n security: Security;\n plugins: PluginsContainer;\n}\n\nexport const apwPageBuilderHooks = (params: ApwPageBuilderPluginsParams) => {\n const { pageBuilder, apw, security, plugins } = params;\n\n plugins.register([\n new PageApwSettingsGetterPlugin(),\n createCommentNotification(),\n createChangeRequestNotification(),\n createContentUrlPlugin(),\n createContentReviewNotification()\n ]);\n\n triggerContentReview({\n apw,\n pageBuilder\n });\n linkContentReviewToPage({\n apw,\n pageBuilder\n });\n updateContentReviewStatus({\n apw,\n pageBuilder,\n security\n });\n linkWorkflowToPage({\n apw,\n pageBuilder\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AASO,MAAMA,mBAAmB,GAAIC,MAAD,IAAyC;EACxE,MAAM;IAAEC,WAAF;IAAeC,GAAf;IAAoBC,QAApB;IAA8BC;EAA9B,IAA0CJ,MAAhD;EAEAI,OAAO,CAACC,QAAR,CAAiB,CACb,IAAIC,wDAAJ,EADa,EAEb,IAAAC,8CAAA,GAFa,EAGb,IAAAC,0DAAA,GAHa,EAIb,IAAAC,kCAAA,GAJa,EAKb,IAAAC,0DAAA,GALa,CAAjB;EAQA,IAAAC,0CAAA,EAAqB;IACjBT,GADiB;IAEjBD;EAFiB,CAArB;EAIA,IAAAW,gDAAA,EAAwB;IACpBV,GADoB;IAEpBD;EAFoB,CAAxB;EAIA,IAAAY,oDAAA,EAA0B;IACtBX,GADsB;IAEtBD,WAFsB;IAGtBE;EAHsB,CAA1B;EAKA,IAAAW,sCAAA,EAAmB;IACfZ,GADe;IAEfD;EAFe,CAAnB;AAIH,CA5BM"}
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.linkContentReviewToPage = void 0;
9
9
 
10
- var _set = _interopRequireDefault(require("lodash/set"));
11
-
12
- var _get = _interopRequireDefault(require("lodash/get"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
11
 
14
12
  var _error = _interopRequireDefault(require("@webiny/error"));
15
13
 
@@ -22,46 +20,60 @@ const linkContentReviewToPage = params => {
22
20
  apw,
23
21
  pageBuilder
24
22
  } = params;
25
- apw.contentReview.onAfterContentReviewCreate.subscribe(async ({
23
+ apw.contentReview.onContentReviewAfterCreate.subscribe(async ({
26
24
  contentReview
27
25
  }) => {
28
26
  const {
29
27
  content
30
28
  } = contentReview;
31
29
 
32
- if (content.type === _types.ApwContentTypes.PAGE) {
33
- await (0, _utils.updatePageSettings)({
34
- getPage: pageBuilder.getPage,
35
- updatePage: pageBuilder.updatePage,
36
- uniquePageId: content.id,
37
- getNewSettings: settings => {
38
- return (0, _set.default)(settings, "apw.contentReviewId", contentReview.id);
39
- }
40
- });
30
+ if (content.type !== _types.ApwContentTypes.PAGE) {
31
+ return;
41
32
  }
33
+
34
+ await (0, _utils.updatePageSettings)({
35
+ getPage: pageBuilder.getPage,
36
+ updatePage: pageBuilder.updatePage,
37
+ uniquePageId: content.id,
38
+ getNewSettings: settings => {
39
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
40
+ apw: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings.apw || {}), {}, {
41
+ contentReviewId: contentReview.id
42
+ })
43
+ });
44
+ }
45
+ });
42
46
  });
43
- apw.contentReview.onAfterContentReviewDelete.subscribe(async ({
47
+ apw.contentReview.onContentReviewAfterDelete.subscribe(async ({
44
48
  contentReview
45
49
  }) => {
46
50
  const {
47
51
  content
48
52
  } = contentReview;
49
53
 
50
- if (content.type === _types.ApwContentTypes.PAGE) {
51
- await (0, _utils.updatePageSettings)({
52
- getPage: pageBuilder.getPage,
53
- updatePage: pageBuilder.updatePage,
54
- uniquePageId: content.id,
55
- getNewSettings: settings => {
56
- return (0, _set.default)(settings, "apw.contentReviewId", null);
57
- }
58
- });
54
+ if (content.type !== _types.ApwContentTypes.PAGE) {
55
+ return;
59
56
  }
57
+
58
+ await (0, _utils.updatePageSettings)({
59
+ getPage: pageBuilder.getPage,
60
+ updatePage: pageBuilder.updatePage,
61
+ uniquePageId: content.id,
62
+ getNewSettings: settings => {
63
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
64
+ apw: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings.apw || {}), {}, {
65
+ contentReviewId: null
66
+ })
67
+ });
68
+ }
69
+ });
60
70
  });
61
- pageBuilder.onBeforePageDelete.subscribe(async ({
71
+ pageBuilder.onPageBeforeDelete.subscribe(async ({
62
72
  page
63
73
  }) => {
64
- const contentReviewId = (0, _get.default)(page, "settings.apw.contentReviewId");
74
+ var _page$settings, _page$settings$apw;
75
+
76
+ const contentReviewId = (_page$settings = page.settings) === null || _page$settings === void 0 ? void 0 : (_page$settings$apw = _page$settings.apw) === null || _page$settings$apw === void 0 ? void 0 : _page$settings$apw.contentReviewId;
65
77
 
66
78
  if (!contentReviewId) {
67
79
  return;
@@ -71,13 +83,13 @@ const linkContentReviewToPage = params => {
71
83
 
72
84
  try {
73
85
  contentReview = await apw.contentReview.get(contentReviewId);
74
- } catch (e) {
86
+ } catch (ex) {
75
87
  /**
76
88
  * We're handling the case whereby "contentReviewId" is still linked to page;
77
89
  * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.
78
90
  */
79
- if (e.code !== "NOT_FOUND") {
80
- throw e;
91
+ if (ex.code !== "NOT_FOUND") {
92
+ throw ex;
81
93
  }
82
94
  }
83
95
 
@@ -1 +1 @@
1
- {"version":3,"names":["linkContentReviewToPage","params","apw","pageBuilder","contentReview","onAfterContentReviewCreate","subscribe","content","type","ApwContentTypes","PAGE","updatePageSettings","getPage","updatePage","uniquePageId","id","getNewSettings","settings","set","onAfterContentReviewDelete","onBeforePageDelete","page","contentReviewId","get","e","code","Error"],"sources":["linkContentReviewToPage.ts"],"sourcesContent":["import set from \"lodash/set\";\nimport get from \"lodash/get\";\nimport Error from \"@webiny/error\";\nimport { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { updatePageSettings } from \"./utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface LinkContentReviewToPageParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const linkContentReviewToPage = (params: LinkContentReviewToPageParams) => {\n const { apw, pageBuilder } = params;\n\n apw.contentReview.onAfterContentReviewCreate.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type === ApwContentTypes.PAGE) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return set(settings, \"apw.contentReviewId\", contentReview.id);\n }\n });\n }\n });\n\n apw.contentReview.onAfterContentReviewDelete.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type === ApwContentTypes.PAGE) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return set(settings, \"apw.contentReviewId\", null);\n }\n });\n }\n });\n\n pageBuilder.onBeforePageDelete.subscribe(async ({ page }) => {\n const contentReviewId = get(page, \"settings.apw.contentReviewId\");\n if (!contentReviewId) {\n return;\n }\n\n let contentReview;\n try {\n contentReview = await apw.contentReview.get(contentReviewId);\n } catch (e) {\n /**\n * We're handling the case whereby \"contentReviewId\" is still linked to page;\n * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.\n */\n if (e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n if (contentReview) {\n throw new Error(\n `Cannot delete the page because a peer review has been requested. Please delete the review first.`,\n \"CANNOT_DELETE_RE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AAW,CAACiB,kBAAZ,CAA+Bd,SAA/B,CAAyC,OAAO;IAAEe;EAAF,CAAP,KAAoB;IACzD,MAAMC,eAAe,GAAG,IAAAC,YAAA,EAAIF,IAAJ,EAAU,8BAAV,CAAxB;;IACA,IAAI,CAACC,eAAL,EAAsB;MAClB;IACH;;IAED,IAAIlB,aAAJ;;IACA,IAAI;MACAA,aAAa,GAAG,MAAMF,GAAG,CAACE,aAAJ,CAAkBmB,GAAlB,CAAsBD,eAAtB,CAAtB;IACH,CAFD,CAEE,OAAOE,CAAP,EAAU;MACR;AACZ;AACA;AACA;MACY,IAAIA,CAAC,CAACC,IAAF,KAAW,WAAf,EAA4B;QACxB,MAAMD,CAAN;MACH;IACJ;;IAED,IAAIpB,aAAJ,EAAmB;MACf,MAAM,IAAIsB,cAAJ,CACD,kGADC,EAEF,4BAFE,EAGF;QACIJ,eADJ;QAEID;MAFJ,CAHE,CAAN;IAQH;EACJ,CA7BD;AA8BH,CA/DM"}
1
+ {"version":3,"names":["linkContentReviewToPage","params","apw","pageBuilder","contentReview","onContentReviewAfterCreate","subscribe","content","type","ApwContentTypes","PAGE","updatePageSettings","getPage","updatePage","uniquePageId","id","getNewSettings","settings","contentReviewId","onContentReviewAfterDelete","onPageBeforeDelete","page","get","ex","code","Error"],"sources":["linkContentReviewToPage.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { updatePageSettings } from \"./utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface LinkContentReviewToPageParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const linkContentReviewToPage = (params: LinkContentReviewToPageParams) => {\n const { apw, pageBuilder } = params;\n\n apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type !== ApwContentTypes.PAGE) {\n return;\n }\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return {\n ...settings,\n apw: {\n ...(settings.apw || {}),\n contentReviewId: contentReview.id\n }\n };\n }\n });\n });\n\n apw.contentReview.onContentReviewAfterDelete.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type !== ApwContentTypes.PAGE) {\n return;\n }\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return {\n ...settings,\n apw: {\n ...(settings.apw || {}),\n contentReviewId: null\n }\n };\n }\n });\n });\n\n pageBuilder.onPageBeforeDelete.subscribe(async ({ page }) => {\n const contentReviewId = page.settings?.apw?.contentReviewId;\n if (!contentReviewId) {\n return;\n }\n\n let contentReview;\n try {\n contentReview = await apw.contentReview.get(contentReviewId);\n } catch (ex) {\n /**\n * We're handling the case whereby \"contentReviewId\" is still linked to page;\n * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.\n */\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n\n if (contentReview) {\n throw new Error(\n `Cannot delete the page because a peer review has been requested. Please delete the review first.`,\n \"CANNOT_DELETE_REVIEW_EXIST\",\n {\n contentReviewId,\n page\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAuBF,MAA7B;EAEAC,GAAG,CAACE,aAAJ,CAAkBC,0BAAlB,CAA6CC,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF,MAAM;MAAEG;IAAF,IAAcH,aAApB;;IAEA,IAAIG,OAAO,CAACC,IAAR,KAAiBC,sBAAA,CAAgBC,IAArC,EAA2C;MACvC;IACH;;IACD,MAAM,IAAAC,yBAAA,EAAmB;MACrBC,OAAO,EAAET,WAAW,C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IAAIA,EAAE,CAACC,IAAH,KAAY,WAAhB,EAA6B;QACzB,MAAMD,EAAN;MACH;IACJ;;IAED,IAAInB,aAAJ,EAAmB;MACf,MAAM,IAAIqB,cAAJ,CACD,kGADC,EAEF,4BAFE,EAGF;QACIP,eADJ;QAEIG;MAFJ,CAHE,CAAN;IAQH;EACJ,CA7BD;AA8BH,CA7EM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,6 +11,8 @@ var _get = _interopRequireDefault(require("lodash/get"));
11
11
 
12
12
  var _set = _interopRequireDefault(require("lodash/set"));
13
13
 
14
+ var _types = require("../../types");
15
+
14
16
  var _utils = require("./utils");
15
17
 
16
18
  const linkWorkflowToPage = params => {
@@ -18,7 +20,7 @@ const linkWorkflowToPage = params => {
18
20
  apw,
19
21
  pageBuilder
20
22
  } = params;
21
- pageBuilder.onBeforePageCreate.subscribe(async ({
23
+ pageBuilder.onPageBeforeCreate.subscribe(async ({
22
24
  page
23
25
  }) => {
24
26
  await (0, _utils.assignWorkflowToPage)({
@@ -26,7 +28,7 @@ const linkWorkflowToPage = params => {
26
28
  page
27
29
  });
28
30
  });
29
- pageBuilder.onBeforePageCreateFrom.subscribe(async params => {
31
+ pageBuilder.onPageBeforeCreateFrom.subscribe(async params => {
30
32
  const {
31
33
  page,
32
34
  original
@@ -62,7 +64,7 @@ const linkWorkflowToPage = params => {
62
64
  page
63
65
  });
64
66
  });
65
- pageBuilder.onBeforePageUpdate.subscribe(async params => {
67
+ pageBuilder.onPageBeforeUpdate.subscribe(async params => {
66
68
  const {
67
69
  page,
68
70
  original
@@ -98,16 +100,21 @@ const linkWorkflowToPage = params => {
98
100
  * Link created workflow to associated pages.
99
101
  */
100
102
 
101
- apw.workflow.onAfterWorkflowCreate.subscribe(async ({
103
+ apw.workflow.onWorkflowAfterCreate.subscribe(async ({
102
104
  workflow
103
105
  }) => {
104
106
  const {
105
107
  scope
106
108
  } = workflow;
109
+
110
+ if (workflow.app !== _types.ApwWorkflowApplications.PB) {
111
+ return;
112
+ }
107
113
  /**
108
114
  * If the workflow has pages in it's scope, we'll link that workflow for each of those pages.
109
115
  */
110
116
 
117
+
111
118
  if ((0, _utils.hasPages)(workflow) === false) {
112
119
  return;
113
120
  }
@@ -129,13 +136,18 @@ const linkWorkflowToPage = params => {
129
136
  * Link updated workflow to associated pages.
130
137
  */
131
138
 
132
- apw.workflow.onAfterWorkflowUpdate.subscribe(async ({
139
+ apw.workflow.onWorkflowAfterUpdate.subscribe(async ({
133
140
  workflow,
134
141
  original
135
142
  }) => {
136
143
  const {
137
144
  scope
138
145
  } = workflow;
146
+
147
+ if (workflow.app !== _types.ApwWorkflowApplications.PB) {
148
+ return;
149
+ }
150
+
139
151
  const {
140
152
  scope: prevScope
141
153
  } = original;
@@ -1 +1 @@
1
- {"version":3,"names":["linkWorkflowToPage","params","apw","pageBuilder","onBeforePageCreate","subscribe","page","assignWorkflowToPage","listWorkflow","workflow","list","onBeforePageCreateFrom","original","previousContentReviewId","get","settings","contentReviewId","previousWorkflowId","onBeforePageUpdate","prevApwWorkflowId","currentApwWorkflowId","linkedContentReviewId","prevTitle","newTitle","contentReview","update","title","onAfterWorkflowCreate","scope","hasPages","pages","pid","updatePageSettings","getPage","updatePage","uniquePageId","getNewSettings","set","id","onAfterWorkflowUpdate","prevScope","shouldUpdatePages","previousPages","currentPages","removedPages","addedPages","getPagesDiff"],"sources":["linkWorkflowToPage.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport set from \"lodash/set\";\nimport {\n ApwOnBeforePageCreateTopicParams,\n ApwOnBeforePageCreateFromTopicParams,\n ApwOnBeforePageUpdateTopicParams,\n AdvancedPublishingWorkflow\n} from \"~/types\";\nimport {\n getPagesDiff,\n hasPages,\n updatePageSettings,\n shouldUpdatePages,\n assignWorkflowToPage\n} from \"./utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface LinkWorkflowToPageParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {\n const { apw, pageBuilder } = params;\n\n pageBuilder.onBeforePageCreate.subscribe<ApwOnBeforePageCreateTopicParams>(async ({ page }) => {\n await assignWorkflowToPage({ listWorkflow: apw.workflow.list, page });\n });\n pageBuilder.onBeforePageCreateFrom.subscribe<ApwOnBeforePageCreateFromTopicParams>(\n async params => {\n const { page, original } = params;\n /**\n * If the previous revision(original) already had the \"contentReviewId\",\n * we need to unlink it so that new \"contentReview\" can be request for the new revision.\n */\n const previousContentReviewId = get(original, \"settings.apw.contentReviewId\");\n if (previousContentReviewId) {\n page.settings.apw.contentReviewId = null;\n }\n\n /**\n * If the previous revision(original) already had the \"workflowId\",\n * we don't need to do anything we'll just let it be copied over.\n */\n const previousWorkflowId = get(original, \"settings.apw.workflowId\");\n if (previousWorkflowId) {\n return;\n }\n /**\n * Lookup and assign \"workflowId\".\n */\n await assignWorkflowToPage({ listWorkflow: apw.workflow.list, page });\n }\n );\n pageBuilder.onBeforePageUpdate.subscribe<ApwOnBeforePageUpdateTopicParams>(async params => {\n const { page, original } = params;\n const prevApwWorkflowId = get(original, \"settings.apw\");\n const currentApwWorkflowId = get(page, \"settings.apw\");\n /**\n * Make sure the apw property doesn't get lost between updates.\n * It can happen because we run modal validation in \"onBeforePageUpdate\" event,\n * which doesn't have the \"apw\" property.\n */\n if (prevApwWorkflowId && !currentApwWorkflowId) {\n page.settings.apw = original.settings.apw;\n }\n /*\n * If there is a linked \"contentReview\" for this page and the page \"title\" has changed.\n * Let's update the \"title\" field in \"contentReview\".\n */\n const linkedContentReviewId = get(page, \"settings.apw.contentReviewId\");\n const prevTitle = get(original, \"title\");\n const newTitle = get(page, \"title\");\n\n if (linkedContentReviewId && prevTitle !== newTitle) {\n await apw.contentReview.update(linkedContentReviewId, { title: newTitle });\n }\n });\n /**\n * Link created workflow to associated pages.\n */\n apw.workflow.onAfterWorkflowCreate.subscribe(async ({ workflow }) => {\n const { scope } = workflow;\n /**\n * If the workflow has pages in it's scope, we'll link that workflow for each of those pages.\n */\n if (hasPages(workflow) === false) {\n return;\n }\n const pages = get(scope, \"data.pages\");\n\n for (const pid of pages) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: pid,\n getNewSettings: settings => {\n return set(settings, \"apw.workflowId\", workflow.id);\n }\n });\n }\n });\n /**\n * Link updated workflow to associated pages.\n */\n apw.workflow.onAfterWorkflowUpdate.subscribe(async ({ workflow, original }) => {\n const { scope } = workflow;\n const { scope: prevScope } = original;\n /**\n * If the workflow has pages in it's scope and there is a change in that page list,\n * we'll update the workflow link for corresponding pages.\n */\n if (hasPages(workflow) === false || shouldUpdatePages(scope, prevScope) === false) {\n return;\n }\n\n const previousPages = get(prevScope, \"data.pages\", []);\n const currentPages = get(scope, \"data.pages\", []);\n\n const { removedPages, addedPages } = getPagesDiff(currentPages, previousPages);\n for (const pid of addedPages) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: pid,\n getNewSettings: settings => {\n return set(settings, \"apw.workflowId\", workflow.id);\n }\n });\n }\n for (const pid of removedPages) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: pid,\n getNewSettings: settings => {\n return set(settings, \"apw.workflowId\", null);\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAOA;;AAcO,MAAMA,kBAAkB,GAAIC,MAAD,IAAsC;EACpE,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAuBF,MAA7B;EAEAE,WAAW,CAACC,kBAAZ,CAA+BC,SAA/B,CAA2E,OAAO;IAAEC;EAA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{"version":3,"names":["linkWorkflowToPage","params","apw","pageBuilder","onPageBeforeCreate","subscribe","page","assignWorkflowToPage","listWorkflow","workflow","list","onPageBeforeCreateFrom","original","previousContentReviewId","get","settings","contentReviewId","previousWorkflowId","onPageBeforeUpdate","prevApwWorkflowId","currentApwWorkflowId","linkedContentReviewId","prevTitle","newTitle","contentReview","update","title","onWorkflowAfterCreate","scope","app","ApwWorkflowApplications","PB","hasPages","pages","pid","updatePageSettings","getPage","updatePage","uniquePageId","getNewSettings","set","id","onWorkflowAfterUpdate","prevScope","shouldUpdatePages","previousPages","currentPages","removedPages","addedPages","getPagesDiff"],"sources":["linkWorkflowToPage.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport set from \"lodash/set\";\nimport {\n ApwWorkflowApplications,\n ApwOnPageBeforeCreateTopicParams,\n ApwOnPageBeforeCreateFromTopicParams,\n ApwOnPageBeforeUpdateTopicParams,\n AdvancedPublishingWorkflow\n} from \"~/types\";\nimport {\n getPagesDiff,\n hasPages,\n updatePageSettings,\n shouldUpdatePages,\n assignWorkflowToPage\n} from \"./utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface LinkWorkflowToPageParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const linkWorkflowToPage = (params: LinkWorkflowToPageParams) => {\n const { apw, pageBuilder } = params;\n\n pageBuilder.onPageBeforeCreate.subscribe<ApwOnPageBeforeCreateTopicParams>(async ({ page }) => {\n await assignWorkflowToPage({ listWorkflow: apw.workflow.list, page });\n });\n pageBuilder.onPageBeforeCreateFrom.subscribe<ApwOnPageBeforeCreateFromTopicParams>(\n async params => {\n const { page, original } = params;\n /**\n * If the previous revision(original) already had the \"contentReviewId\",\n * we need to unlink it so that new \"contentReview\" can be request for the new revision.\n */\n const previousContentReviewId = get(original, \"settings.apw.contentReviewId\");\n if (previousContentReviewId) {\n page.settings.apw.contentReviewId = null;\n }\n\n /**\n * If the previous revision(original) already had the \"workflowId\",\n * we don't need to do anything we'll just let it be copied over.\n */\n const previousWorkflowId = get(original, \"settings.apw.workflowId\");\n if (previousWorkflowId) {\n return;\n }\n /**\n * Lookup and assign \"workflowId\".\n */\n await assignWorkflowToPage({ listWorkflow: apw.workflow.list, page });\n }\n );\n pageBuilder.onPageBeforeUpdate.subscribe<ApwOnPageBeforeUpdateTopicParams>(async params => {\n const { page, original } = params;\n const prevApwWorkflowId = get(original, \"settings.apw\");\n const currentApwWorkflowId = get(page, \"settings.apw\");\n /**\n * Make sure the apw property doesn't get lost between updates.\n * It can happen because we run modal validation in \"onBeforePageUpdate\" event,\n * which doesn't have the \"apw\" property.\n */\n if (prevApwWorkflowId && !currentApwWorkflowId) {\n page.settings.apw = original.settings.apw;\n }\n /*\n * If there is a linked \"contentReview\" for this page and the page \"title\" has changed.\n * Let's update the \"title\" field in \"contentReview\".\n */\n const linkedContentReviewId = get(page, \"settings.apw.contentReviewId\");\n const prevTitle = get(original, \"title\");\n const newTitle = get(page, \"title\");\n\n if (linkedContentReviewId && prevTitle !== newTitle) {\n await apw.contentReview.update(linkedContentReviewId, { title: newTitle });\n }\n });\n /**\n * Link created workflow to associated pages.\n */\n apw.workflow.onWorkflowAfterCreate.subscribe(async ({ workflow }) => {\n const { scope } = workflow;\n if (workflow.app !== ApwWorkflowApplications.PB) {\n return;\n }\n /**\n * If the workflow has pages in it's scope, we'll link that workflow for each of those pages.\n */\n if (hasPages(workflow) === false) {\n return;\n }\n const pages = get(scope, \"data.pages\") as unknown as string[];\n\n for (const pid of pages) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: pid,\n getNewSettings: settings => {\n return set(settings, \"apw.workflowId\", workflow.id);\n }\n });\n }\n });\n /**\n * Link updated workflow to associated pages.\n */\n apw.workflow.onWorkflowAfterUpdate.subscribe(async ({ workflow, original }) => {\n const { scope } = workflow;\n if (workflow.app !== ApwWorkflowApplications.PB) {\n return;\n }\n const { scope: prevScope } = original;\n /**\n * If the workflow has pages in it's scope and there is a change in that page list,\n * we'll update the workflow link for corresponding pages.\n */\n if (hasPages(workflow) === false || shouldUpdatePages(scope, prevScope) === false) {\n return;\n }\n\n const previousPages = get(prevScope, \"data.pages\", []);\n const currentPages = get(scope, \"data.pages\", []);\n\n const { removedPages, addedPages } = getPagesDiff(currentPages, previousPages);\n for (const pid of addedPages) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: pid,\n getNewSettings: settings => {\n return set(settings, \"apw.workflowId\", workflow.id);\n }\n });\n }\n for (const pid of removedPages) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: pid,\n getNewSettings: settings => {\n return set(settings, \"apw.workflowId\", null);\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAOA;;AAcO,MAAMA,kBAAkB,GAAIC,MAAD,IAAsC;EACpE,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAuBF,MAA7B;EAEAE,WAAW,CAACC,kBAAZ,CAA+BC,SAA/B,CAA2E,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAC3F,MAAM,IAAAC,2BAAA,EAAqB;MAAEC,YAAY,EAAEN,GAAG,CAACO,QAAJ,CAAaC,IAA7B;MAAmCJ;IAAnC,CAArB,CAAN;EACH,CAFD;EAGAH,WAAW,CAACQ,sBAAZ,CAAmCN,SAAnC,CACI,MAAMJ,MAAN,IAAgB;IACZ,MAAM;MAAEK,IAAF;MAAQM;IAAR,IAAqBX,MAA3B;IACA;AACZ;AACA;AACA;;IACY,MAAMY,uBAAuB,GAAG,IAAAC,YAAA,EAAIF,QAAJ,EAAc,8BAAd,CAAhC;;IACA,IAAIC,uBAAJ,EAA6B;MACzBP,IAAI,CAACS,QAAL,CAAcb,GAAd,CAAkBc,eAAlB,GAAoC,IAApC;IACH;IAED;AACZ;AACA;AACA;;;IACY,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IACA,MAAMG,YAAY,GAAG,IAAAhC,YAAA,EAAIc,KAAJ,EAAW,YAAX,EAAyB,EAAzB,CAArB;IAEA,MAAM;MAAEmB,YAAF;MAAgBC;IAAhB,IAA+B,IAAAC,mBAAA,EAAaH,YAAb,EAA2BD,aAA3B,CAArC;;IACA,KAAK,MAAMX,GAAX,IAAkBc,UAAlB,EAA8B;MAC1B,MAAM,IAAAb,yBAAA,EAAmB;QACrBC,OAAO,EAAEjC,WAAW,CAACiC,OADA;QAErBC,UAAU,EAAElC,WAAW,CAACkC,UAFH;QAGrBC,YAAY,EAAEJ,GAHO;QAIrBK,cAAc,EAAExB,QAAQ,IAAI;UACxB,OAAO,IAAAyB,YAAA,EAAIzB,QAAJ,EAAc,gBAAd,EAAgCN,QAAQ,CAACgC,EAAzC,CAAP;QACH;MANoB,CAAnB,CAAN;IAQH;;IACD,KAAK,MAAMP,GAAX,IAAkBa,YAAlB,EAAgC;MAC5B,MAAM,IAAAZ,yBAAA,EAAmB;QACrBC,OAAO,EAAEjC,WAAW,CAACiC,OADA;QAErBC,UAAU,EAAElC,WAAW,CAACkC,UAFH;QAGrBC,YAAY,EAAEJ,GAHO;QAIrBK,cAAc,EAAExB,QAAQ,IAAI;UACxB,OAAO,IAAAyB,YAAA,EAAIzB,QAAJ,EAAc,gBAAd,EAAgC,IAAhC,CAAP;QACH;MANoB,CAAnB,CAAN;IAQH;EACJ,CAtCD;AAuCH,CA7HM"}
@@ -0,0 +1 @@
1
+ export declare const createChangeRequestNotification: () => import("../../../ApwChangeRequestNotification").ApwChangeRequestNotification;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createChangeRequestNotification = void 0;
7
+
8
+ var _types = require("../../../types");
9
+
10
+ var _ApwChangeRequestNotification = require("../../../ApwChangeRequestNotification");
11
+
12
+ const createChangeRequestNotification = () => {
13
+ const plugin = (0, _ApwChangeRequestNotification.createApwChangeRequestNotification)(_types.ApwContentTypes.PAGE, params => {
14
+ const {
15
+ changeRequestUrl,
16
+ contentUrl
17
+ } = params;
18
+ return {
19
+ text: `
20
+ Hi,<br /><br />
21
+
22
+ You have received a <a href="${changeRequestUrl}">change request</a>, for <a href="${contentUrl}">this</a> page.<br /><br />
23
+
24
+ Here are the full URLs:<br /><br />
25
+
26
+ Change Request: ${changeRequestUrl}<br />
27
+ Page: ${contentUrl}
28
+ `
29
+ };
30
+ });
31
+ plugin.name = `${plugin.type}.${_types.ApwContentTypes.PAGE}.default`;
32
+ return plugin;
33
+ };
34
+
35
+ exports.createChangeRequestNotification = createChangeRequestNotification;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createChangeRequestNotification","plugin","createApwChangeRequestNotification","ApwContentTypes","PAGE","params","changeRequestUrl","contentUrl","text","name","type"],"sources":["changeRequestNotification.ts"],"sourcesContent":["import { ApwContentTypes } from \"~/types\";\nimport { createApwChangeRequestNotification } from \"~/ApwChangeRequestNotification\";\n\nexport const createChangeRequestNotification = () => {\n const plugin = createApwChangeRequestNotification(ApwContentTypes.PAGE, params => {\n const { changeRequestUrl, contentUrl } = params;\n return {\n text: `\n Hi,<br /><br />\n \n You have received a <a href=\"${changeRequestUrl}\">change request</a>, for <a href=\"${contentUrl}\">this</a> page.<br /><br />\n \n Here are the full URLs:<br /><br />\n \n Change Request: ${changeRequestUrl}<br />\n Page: ${contentUrl}\n `\n };\n });\n\n plugin.name = `${plugin.type}.${ApwContentTypes.PAGE}.default`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,+BAA+B,GAAG,MAAM;EACjD,MAAMC,MAAM,GAAG,IAAAC,gEAAA,EAAmCC,sBAAA,CAAgBC,IAAnD,EAAyDC,MAAM,IAAI;IAC9E,MAAM;MAAEC,gBAAF;MAAoBC;IAApB,IAAmCF,MAAzC;IACA,OAAO;MACHG,IAAI,EAAG;AACnB;AACA;AACA,+CAA+CF,gBAAiB,sCAAqCC,UAAW;AAChH;AACA;AACA;AACA,kCAAkCD,gBAAiB;AACnD,wBAAwBC,UAAW;AACnC;IAVe,CAAP;EAYH,CAdc,CAAf;EAgBAN,MAAM,CAACQ,IAAP,GAAe,GAAER,MAAM,CAACS,IAAK,IAAGP,sBAAA,CAAgBC,IAAK,UAArD;EAEA,OAAOH,MAAP;AACH,CApBM"}
@@ -0,0 +1 @@
1
+ export declare const createCommentNotification: () => import("../../../ApwCommentNotification").ApwCommentNotification;