@webiny/api-apw 0.0.0-unstable.5e7233243f → 0.0.0-unstable.6e5425ee89

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 (240) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +30 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +30 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +30 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +30 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +1 -6
  14. package/ContentApwSettingsPlugin.js.map +1 -1
  15. package/crud/createChangeRequestMethods.js +21 -25
  16. package/crud/createChangeRequestMethods.js.map +1 -1
  17. package/crud/createCommentMethods.js +21 -26
  18. package/crud/createCommentMethods.js.map +1 -1
  19. package/crud/createContentReviewMethods.js +71 -125
  20. package/crud/createContentReviewMethods.js.map +1 -1
  21. package/crud/createReviewerMethods.js +21 -26
  22. package/crud/createReviewerMethods.js.map +1 -1
  23. package/crud/createWorkflowMethods.d.ts +1 -1
  24. package/crud/createWorkflowMethods.js +37 -28
  25. package/crud/createWorkflowMethods.js.map +1 -1
  26. package/crud/index.js +3 -32
  27. package/crud/index.js.map +1 -1
  28. package/crud/utils.js +4 -36
  29. package/crud/utils.js.map +1 -1
  30. package/index.d.ts +3 -3
  31. package/index.js +7 -13
  32. package/index.js.map +1 -1
  33. package/package.json +38 -37
  34. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +1 -16
  35. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  36. package/plugins/cms/apwEntryPlugins.js +4 -16
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  38. package/plugins/cms/index.js +5 -10
  39. package/plugins/cms/index.js.map +1 -1
  40. package/plugins/cms/linkContentReviewToEntry.js +4 -21
  41. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  42. package/plugins/cms/linkWorkflowToEntry.js +7 -36
  43. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  44. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  45. package/plugins/cms/notifications/changeRequestNotification.js +31 -0
  46. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  47. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  48. package/plugins/cms/notifications/commentNotification.js +31 -0
  49. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  50. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  51. package/plugins/cms/notifications/contentReviewNotification.js +31 -0
  52. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  53. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  54. package/plugins/cms/notifications/contentUrl.js +53 -0
  55. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  56. package/plugins/cms/triggerContentReview.js +3 -17
  57. package/plugins/cms/triggerContentReview.js.map +1 -1
  58. package/plugins/cms/updateContentReviewStatus.js +10 -32
  59. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  60. package/plugins/cms/utils.js +6 -55
  61. package/plugins/cms/utils.js.map +1 -1
  62. package/plugins/context.js +1 -32
  63. package/plugins/context.js.map +1 -1
  64. package/plugins/graphql/changeRequest.gql.js +2 -9
  65. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  66. package/plugins/graphql/comment.gql.js +2 -9
  67. package/plugins/graphql/comment.gql.js.map +1 -1
  68. package/plugins/graphql/contentReview.gql.js +5 -24
  69. package/plugins/graphql/contentReview.gql.js.map +1 -1
  70. package/plugins/graphql/reviewer.gql.js +4 -9
  71. package/plugins/graphql/reviewer.gql.js.map +1 -1
  72. package/plugins/graphql/workflow.gql.js +2 -9
  73. package/plugins/graphql/workflow.gql.js.map +1 -1
  74. package/plugins/graphql.js +2 -17
  75. package/plugins/graphql.js.map +1 -1
  76. package/plugins/hooks/createReviewerFromIdentity.js +26 -15
  77. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  78. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +2 -10
  79. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  80. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +2 -9
  81. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  82. package/plugins/hooks/index.js +4 -12
  83. package/plugins/hooks/index.js.map +1 -1
  84. package/plugins/hooks/initializeContentReviewSteps.js +7 -23
  85. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  86. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  87. package/plugins/hooks/initializeNotifications.js +15 -0
  88. package/plugins/hooks/initializeNotifications.js.map +1 -0
  89. package/plugins/hooks/listContentReviews.d.ts +10 -0
  90. package/plugins/hooks/listContentReviews.js +56 -0
  91. package/plugins/hooks/listContentReviews.js.map +1 -0
  92. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  93. package/plugins/hooks/notifications/appUrl.js +18 -0
  94. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  95. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  96. package/plugins/hooks/notifications/changeRequestAfterCreate.js +116 -0
  97. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  98. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  99. package/plugins/hooks/notifications/changeRequestUrl.js +27 -0
  100. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  101. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  102. package/plugins/hooks/notifications/commentAfterCreate.js +127 -0
  103. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  104. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  105. package/plugins/hooks/notifications/commentUrl.js +27 -0
  106. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  107. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  108. package/plugins/hooks/notifications/contentReviewAfterCreate.js +99 -0
  109. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  110. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  111. package/plugins/hooks/notifications/contentReviewUrl.js +26 -0
  112. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  113. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  114. package/plugins/hooks/notifications/contentUrl.js +24 -0
  115. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  116. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  117. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +21 -0
  118. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  119. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  120. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +21 -0
  121. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  122. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  123. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +21 -0
  124. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  125. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  126. package/plugins/hooks/notifications/reviewers.js +44 -0
  127. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  128. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  129. package/plugins/hooks/notifications/sendChangeRequestNotification.js +41 -0
  130. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  131. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  132. package/plugins/hooks/notifications/sendCommentNotification.js +41 -0
  133. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  134. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  135. package/plugins/hooks/notifications/sendContentReviewNotification.js +41 -0
  136. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  137. package/plugins/hooks/updatePendingChangeRequests.js +7 -19
  138. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  139. package/plugins/hooks/updateTotalComments.js +14 -27
  140. package/plugins/hooks/updateTotalComments.js.map +1 -1
  141. package/plugins/hooks/validateChangeRequest.js +27 -18
  142. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  143. package/plugins/hooks/validateComment.js +13 -14
  144. package/plugins/hooks/validateComment.js.map +1 -1
  145. package/plugins/hooks/validateContentReview.js +2 -8
  146. package/plugins/hooks/validateContentReview.js.map +1 -1
  147. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +1 -16
  148. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  149. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  150. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  151. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  152. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  153. package/plugins/pageBuilder/index.js +5 -8
  154. package/plugins/pageBuilder/index.js.map +1 -1
  155. package/plugins/pageBuilder/linkContentReviewToPage.js +38 -42
  156. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  157. package/plugins/pageBuilder/linkWorkflowToPage.js +14 -32
  158. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  159. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  160. package/plugins/pageBuilder/notifications/changeRequestNotification.js +31 -0
  161. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  162. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  163. package/plugins/pageBuilder/notifications/commentNotification.js +31 -0
  164. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  165. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  166. package/plugins/pageBuilder/notifications/contentReviewNotification.js +31 -0
  167. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  168. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  169. package/plugins/pageBuilder/notifications/contentUrl.js +47 -0
  170. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  171. package/plugins/pageBuilder/triggerContentReview.js +3 -14
  172. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  173. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -26
  174. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  175. package/plugins/pageBuilder/utils.js +2 -36
  176. package/plugins/pageBuilder/utils.js.map +1 -1
  177. package/plugins/utils.d.ts +1 -1
  178. package/plugins/utils.js +4 -57
  179. package/plugins/utils.js.map +1 -1
  180. package/scheduler/createScheduleActionMethods.js +17 -33
  181. package/scheduler/createScheduleActionMethods.js.map +1 -1
  182. package/scheduler/handlers/executeAction/index.js +9 -33
  183. package/scheduler/handlers/executeAction/index.js.map +1 -1
  184. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +1 -6
  185. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  186. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -22
  187. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  188. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +5 -28
  189. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  190. package/scheduler/handlers/executeAction/security.js +0 -11
  191. package/scheduler/handlers/executeAction/security.js.map +1 -1
  192. package/scheduler/handlers/scheduleAction/index.js +13 -34
  193. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  194. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +7 -32
  195. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  196. package/scheduler/handlers/utils.js +4 -41
  197. package/scheduler/handlers/utils.js.map +1 -1
  198. package/scheduler/index.js +0 -3
  199. package/scheduler/index.js.map +1 -1
  200. package/scheduler/types.js +0 -6
  201. package/scheduler/types.js.map +1 -1
  202. package/storageOperations/changeRequestStorageOperations.js +5 -28
  203. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  204. package/storageOperations/commentStorageOperations.js +4 -29
  205. package/storageOperations/commentStorageOperations.js.map +1 -1
  206. package/storageOperations/contentReviewStorageOperations.js +5 -26
  207. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  208. package/storageOperations/index.js +5 -23
  209. package/storageOperations/index.js.map +1 -1
  210. package/storageOperations/models/changeRequest.model.js +0 -9
  211. package/storageOperations/models/changeRequest.model.js.map +1 -1
  212. package/storageOperations/models/comment.model.js +0 -8
  213. package/storageOperations/models/comment.model.js.map +1 -1
  214. package/storageOperations/models/contentModelPluginFactory.js +3 -12
  215. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  216. package/storageOperations/models/contentReview.model.js +6 -31
  217. package/storageOperations/models/contentReview.model.js.map +1 -1
  218. package/storageOperations/models/index.js +3 -25
  219. package/storageOperations/models/index.js.map +1 -1
  220. package/storageOperations/models/reviewer.model.js +17 -9
  221. package/storageOperations/models/reviewer.model.js.map +1 -1
  222. package/storageOperations/models/utils.js +3 -6
  223. package/storageOperations/models/utils.js.map +1 -1
  224. package/storageOperations/models/workflow.model.js +0 -23
  225. package/storageOperations/models/workflow.model.js.map +1 -1
  226. package/storageOperations/reviewerStorageOperations.js +16 -29
  227. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  228. package/storageOperations/workflowStorageOperations.js +6 -31
  229. package/storageOperations/workflowStorageOperations.js.map +1 -1
  230. package/types.d.ts +99 -84
  231. package/types.js +0 -14
  232. package/types.js.map +1 -1
  233. package/utils/contentApwSettingsPlugin.js +0 -6
  234. package/utils/contentApwSettingsPlugin.js.map +1 -1
  235. package/utils/errors.js +1 -18
  236. package/utils/errors.js.map +1 -1
  237. package/utils/fieldResolver.js +5 -21
  238. package/utils/fieldResolver.js.map +1 -1
  239. package/utils/resolve.js +0 -3
  240. package/utils/resolve.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["createReviewerFromIdentity","security","apw","onAfterLogin","subscribe","identity","reviewer","list","where","identityId","id","limit","e","message","create","displayName","type","update"],"sources":["createReviewerFromIdentity.ts"],"sourcesContent":["import { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const createReviewerFromIdentity = ({ security, apw }: LifeCycleHookCallbackParams) => {\n /**\n * Replicate identity in \"AdvancedPublishingWorkflow\" system after login.\n */\n security.onAfterLogin.subscribe(async ({ identity }) => {\n let reviewer;\n try {\n [[reviewer]] = await apw.reviewer.list({\n where: { identityId: identity.id },\n limit: 1\n });\n } catch (e) {\n if (e.message === \"index_not_found_exception\") {\n // Do nothing\n } else {\n throw e;\n }\n }\n /**\n * Create a reviewer if it doesn't exist already.\n */\n if (!reviewer) {\n await apw.reviewer.create({\n identityId: identity.id,\n displayName: identity.displayName,\n type: identity.type\n });\n return;\n }\n /**\n * If \"displayName\" doesn't match it means it has been updated in the identity,\n * therefore, we need to update it on reviewer as well keep them in sync.\n */\n if (reviewer.displayName !== identity.displayName) {\n await apw.reviewer.update(reviewer.id, {\n identityId: reviewer.identityId,\n type: reviewer.type,\n displayName: identity.displayName\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,0BAA0B,GAAG,CAAC;EAAEC,QAAF;EAAYC;AAAZ,CAAD,KAAoD;EAC1F;AACJ;AACA;EACID,QAAQ,CAACE,YAAT,CAAsBC,SAAtB,CAAgC,OAAO;IAAEC;EAAF,CAAP,KAAwB;IACpD,IAAIC,QAAJ;;IACA,IAAI;MACA,CAAC,CAACA,QAAD,CAAD,IAAe,MAAMJ,GAAG,CAACI,QAAJ,CAAaC,IAAb,CAAkB;QACnCC,KAAK,EAAE;UAAEC,UAAU,EAAEJ,QAAQ,CAACK;QAAvB,CAD4B;QAEnCC,KAAK,EAAE;MAF4B,CAAlB,CAArB;IAIH,CALD,CAKE,OAAOC,CAAP,EAAU;MACR,IAAIA,CAAC,CAACC,OAAF,KAAc,2BAAlB,EAA+C,CAC3C;MACH,CAFD,MAEO;QACH,MAAMD,CAAN;MACH;IACJ;IACD;AACR;AACA;;;IACQ,IAAI,CAACN,QAAL,EAAe;MACX,MAAMJ,GAAG,CAACI,QAAJ,CAAaQ,MAAb,CAAoB;QACtBL,UAAU,EAAEJ,QAAQ,CAACK,EADC;QAEtBK,WAAW,EAAEV,QAAQ,CAACU,WAFA;QAGtBC,IAAI,EAAEX,QAAQ,CAACW;MAHO,CAApB,CAAN;MAKA;IACH;IACD;AACR;AACA;AACA;;;IACQ,IAAIV,QAAQ,CAACS,WAAT,KAAyBV,QAAQ,CAACU,WAAtC,EAAmD;MAC/C,MAAMb,GAAG,CAACI,QAAJ,CAAaW,MAAb,CAAoBX,QAAQ,CAACI,EAA7B,EAAiC;QACnCD,UAAU,EAAEH,QAAQ,CAACG,UADc;QAEnCO,IAAI,EAAEV,QAAQ,CAACU,IAFoB;QAGnCD,WAAW,EAAEV,QAAQ,CAACU;MAHa,CAAjC,CAAN;IAKH;EACJ,CApCD;AAqCH,CAzCM"}
1
+ {"version":3,"names":["createReviewerFromIdentity","security","apw","onAfterLogin","subscribe","identity","reviewer","list","where","identityId","id","limit","e","message","email","create","displayName","type","ex","console","log","JSON","stringify","update"],"sources":["createReviewerFromIdentity.ts"],"sourcesContent":["import { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const createReviewerFromIdentity = ({ security, apw }: LifeCycleHookCallbackParams) => {\n /**\n * Replicate identity in \"AdvancedPublishingWorkflow\" system after login.\n */\n security.onAfterLogin.subscribe(async ({ identity }) => {\n let reviewer;\n try {\n [[reviewer]] = await apw.reviewer.list({\n where: { identityId: identity.id },\n limit: 1\n });\n } catch (e) {\n if (e.message === \"index_not_found_exception\") {\n // Do nothing\n } else {\n throw e;\n }\n }\n const email = (identity as any).email || null;\n /**\n * Create a reviewer if it doesn't exist already.\n */\n if (!reviewer) {\n try {\n await apw.reviewer.create({\n identityId: identity.id,\n displayName: identity.displayName,\n type: identity.type,\n email\n });\n } catch (ex) {\n console.log(\n `There was an error while creating reviewer with identity: ${identity.id}`\n );\n console.log(JSON.stringify(ex));\n throw ex;\n }\n return;\n }\n /**\n * If \"displayName\" doesn't match it means it has been updated in the identity,\n * therefore, we need to update it on reviewer as well keep them in sync.\n */\n const update = reviewer.displayName !== identity.displayName || reviewer.email !== email;\n if (!update) {\n return;\n }\n try {\n await apw.reviewer.update(reviewer.id, {\n identityId: reviewer.identityId,\n type: reviewer.type,\n displayName: identity.displayName,\n email\n });\n } catch (ex) {\n console.log(`There was an error while updating reviewer: ${reviewer.id}`);\n console.log(JSON.stringify(ex));\n throw ex;\n }\n });\n};\n"],"mappings":";;;;;;AAEO,MAAMA,0BAA0B,GAAG,CAAC;EAAEC,QAAQ;EAAEC;AAAiC,CAAC,KAAK;EAC1F;AACJ;AACA;EACID,QAAQ,CAACE,YAAY,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAS,CAAC,KAAK;IACpD,IAAIC,QAAQ;IACZ,IAAI;MACA,CAAC,CAACA,QAAQ,CAAC,CAAC,GAAG,MAAMJ,GAAG,CAACI,QAAQ,CAACC,IAAI,CAAC;QACnCC,KAAK,EAAE;UAAEC,UAAU,EAAEJ,QAAQ,CAACK;QAAG,CAAC;QAClCC,KAAK,EAAE;MACX,CAAC,CAAC;IACN,CAAC,CAAC,OAAOC,CAAC,EAAE;MACR,IAAIA,CAAC,CAACC,OAAO,KAAK,2BAA2B,EAAE;QAC3C;MAAA,CACH,MAAM;QACH,MAAMD,CAAC;MACX;IACJ;IACA,MAAME,KAAK,GAAIT,QAAQ,CAASS,KAAK,IAAI,IAAI;IAC7C;AACR;AACA;IACQ,IAAI,CAACR,QAAQ,EAAE;MACX,IAAI;QACA,MAAMJ,GAAG,CAACI,QAAQ,CAACS,MAAM,CAAC;UACtBN,UAAU,EAAEJ,QAAQ,CAACK,EAAE;UACvBM,WAAW,EAAEX,QAAQ,CAACW,WAAW;UACjCC,IAAI,EAAEZ,QAAQ,CAACY,IAAI;UACnBH;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOI,EAAE,EAAE;QACTC,OAAO,CAACC,GAAG,CACN,6DAA4Df,QAAQ,CAACK,EAAG,EAAC,CAC7E;QACDS,OAAO,CAACC,GAAG,CAACC,IAAI,CAACC,SAAS,CAACJ,EAAE,CAAC,CAAC;QAC/B,MAAMA,EAAE;MACZ;MACA;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAMK,MAAM,GAAGjB,QAAQ,CAACU,WAAW,KAAKX,QAAQ,CAACW,WAAW,IAAIV,QAAQ,CAACQ,KAAK,KAAKA,KAAK;IACxF,IAAI,CAACS,MAAM,EAAE;MACT;IACJ;IACA,IAAI;MACA,MAAMrB,GAAG,CAACI,QAAQ,CAACiB,MAAM,CAACjB,QAAQ,CAACI,EAAE,EAAE;QACnCD,UAAU,EAAEH,QAAQ,CAACG,UAAU;QAC/BQ,IAAI,EAAEX,QAAQ,CAACW,IAAI;QACnBD,WAAW,EAAEX,QAAQ,CAACW,WAAW;QACjCF;MACJ,CAAC,CAAC;IACN,CAAC,CAAC,OAAOI,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAE,+CAA8Cd,QAAQ,CAACI,EAAG,EAAC,CAAC;MACzES,OAAO,CAACC,GAAG,CAACC,IAAI,CAACC,SAAS,CAACJ,EAAE,CAAC,CAAC;MAC/B,MAAMA,EAAE;IACZ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.deleteChangeRequestsWithContentReview = void 0;
7
-
8
7
  const deleteChangeRequestsWithContentReview = ({
9
8
  apw
10
9
  }) => {
11
- apw.contentReview.onAfterContentReviewDelete.subscribe(async ({
10
+ apw.contentReview.onContentReviewAfterDelete.subscribe(async ({
12
11
  contentReview
13
12
  }) => {
14
13
  /**
@@ -18,7 +17,6 @@ const deleteChangeRequestsWithContentReview = ({
18
17
  /**
19
18
  * For each step get associated change requests and delete them.
20
19
  */
21
-
22
20
  for (let i = 0; i < steps.length; i++) {
23
21
  const {
24
22
  id: stepId
@@ -29,13 +27,11 @@ const deleteChangeRequestsWithContentReview = ({
29
27
  /**
30
28
  * Paginate through change requests.
31
29
  */
32
-
33
30
  while (meta.totalCount > 0) {
34
31
  let changeRequests = [];
35
32
  /**
36
33
  * Get all change requests.
37
34
  */
38
-
39
35
  try {
40
36
  [changeRequests, meta] = await apw.changeRequest.list({
41
37
  where: {
@@ -44,18 +40,15 @@ const deleteChangeRequestsWithContentReview = ({
44
40
  });
45
41
  } catch (e) {
46
42
  meta.totalCount = 0;
47
-
48
43
  if (e.message !== "index_not_found_exception") {
49
44
  throw e;
50
45
  }
51
-
52
46
  console.log(e);
53
47
  }
48
+
54
49
  /**
55
50
  * Delete change requests one by one.
56
51
  */
57
-
58
-
59
52
  for (const changeRequest of changeRequests) {
60
53
  await apw.changeRequest.delete(changeRequest.id);
61
54
  }
@@ -63,5 +56,4 @@ const deleteChangeRequestsWithContentReview = ({
63
56
  }
64
57
  });
65
58
  };
66
-
67
59
  exports.deleteChangeRequestsWithContentReview = deleteChangeRequestsWithContentReview;
@@ -1 +1 @@
1
- {"version":3,"names":["deleteChangeRequestsWithContentReview","apw","contentReview","onAfterContentReviewDelete","subscribe","steps","i","length","id","stepId","meta","totalCount","changeRequests","changeRequest","list","where","step","e","message","console","log","delete"],"sources":["deleteChangeRequestsAfterContentReview.ts"],"sourcesContent":["import { ApwChangeRequest, LifeCycleHookCallbackParams, ListMeta } from \"~/types\";\n\nexport const deleteChangeRequestsWithContentReview = ({\n apw\n}: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onAfterContentReviewDelete.subscribe(async ({ contentReview }) => {\n /**\n * Also delete all associated \"changeRequest\" when a \"contentReview\" is deleted.\n */\n const steps = contentReview.steps;\n /**\n * For each step get associated change requests and delete them.\n */\n for (let i = 0; i < steps.length; i++) {\n const { id: stepId } = steps[i];\n\n let meta: Pick<ListMeta, \"totalCount\"> = {\n totalCount: 1\n };\n /**\n * Paginate through change requests.\n */\n while (meta.totalCount > 0) {\n let changeRequests: ApwChangeRequest[] = [];\n /**\n * Get all change requests.\n */\n try {\n [changeRequests, meta] = await apw.changeRequest.list({\n where: {\n step: `${contentReview.id}#${stepId}`\n }\n });\n } catch (e) {\n meta.totalCount = 0;\n if (e.message !== \"index_not_found_exception\") {\n throw e;\n }\n console.log(e);\n }\n\n /**\n * Delete change requests one by one.\n */\n for (const changeRequest of changeRequests) {\n await apw.changeRequest.delete(changeRequest.id);\n }\n }\n }\n });\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,qCAAqC,GAAG,CAAC;EAClDC;AADkD,CAAD,KAEL;EAC5CA,GAAG,CAACC,aAAJ,CAAkBC,0BAAlB,CAA6CC,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF;AACR;AACA;IACQ,MAAMG,KAAK,GAAGH,aAAa,CAACG,KAA5B;IACA;AACR;AACA;;IACQ,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,KAAK,CAACE,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;MACnC,MAAM;QAAEE,EAAE,EAAEC;MAAN,IAAiBJ,KAAK,CAACC,CAAD,CAA5B;MAEA,IAAII,IAAkC,GAAG;QACrCC,UAAU,EAAE;MADyB,CAAzC;MAGA;AACZ;AACA;;MACY,OAAOD,IAAI,CAACC,UAAL,GAAkB,CAAzB,EAA4B;QACxB,IAAIC,cAAkC,GAAG,EAAzC;QACA;AAChB;AACA;;QACgB,IAAI;UACA,CAACA,cAAD,EAAiBF,IAAjB,IAAyB,MAAMT,GAAG,CAACY,aAAJ,CAAkBC,IAAlB,CAAuB;YAClDC,KAAK,EAAE;cACHC,IAAI,EAAG,GAAEd,aAAa,CAACM,EAAG,IAAGC,MAAO;YADjC;UAD2C,CAAvB,CAA/B;QAKH,CAND,CAME,OAAOQ,CAAP,EAAU;UACRP,IAAI,CAACC,UAAL,GAAkB,CAAlB;;UACA,IAAIM,CAAC,CAACC,OAAF,KAAc,2BAAlB,EAA+C;YAC3C,MAAMD,CAAN;UACH;;UACDE,OAAO,CAACC,GAAR,CAAYH,CAAZ;QACH;QAED;AAChB;AACA;;;QACgB,KAAK,MAAMJ,aAAX,IAA4BD,cAA5B,EAA4C;UACxC,MAAMX,GAAG,CAACY,aAAJ,CAAkBQ,MAAlB,CAAyBR,aAAa,CAACL,EAAvC,CAAN;QACH;MACJ;IACJ;EACJ,CA5CD;AA6CH,CAhDM"}
1
+ {"version":3,"names":["deleteChangeRequestsWithContentReview","apw","contentReview","onContentReviewAfterDelete","subscribe","steps","i","length","id","stepId","meta","totalCount","changeRequests","changeRequest","list","where","step","e","message","console","log","delete"],"sources":["deleteChangeRequestsAfterContentReview.ts"],"sourcesContent":["import { ApwChangeRequest, LifeCycleHookCallbackParams, ListMeta } from \"~/types\";\n\nexport const deleteChangeRequestsWithContentReview = ({\n apw\n}: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onContentReviewAfterDelete.subscribe(async ({ contentReview }) => {\n /**\n * Also delete all associated \"changeRequest\" when a \"contentReview\" is deleted.\n */\n const steps = contentReview.steps;\n /**\n * For each step get associated change requests and delete them.\n */\n for (let i = 0; i < steps.length; i++) {\n const { id: stepId } = steps[i];\n\n let meta: Pick<ListMeta, \"totalCount\"> = {\n totalCount: 1\n };\n /**\n * Paginate through change requests.\n */\n while (meta.totalCount > 0) {\n let changeRequests: ApwChangeRequest[] = [];\n /**\n * Get all change requests.\n */\n try {\n [changeRequests, meta] = await apw.changeRequest.list({\n where: {\n step: `${contentReview.id}#${stepId}`\n }\n });\n } catch (e) {\n meta.totalCount = 0;\n if (e.message !== \"index_not_found_exception\") {\n throw e;\n }\n console.log(e);\n }\n\n /**\n * Delete change requests one by one.\n */\n for (const changeRequest of changeRequests) {\n await apw.changeRequest.delete(changeRequest.id);\n }\n }\n }\n });\n};\n"],"mappings":";;;;;;AAEO,MAAMA,qCAAqC,GAAG,CAAC;EAClDC;AACsC,CAAC,KAAK;EAC5CA,GAAG,CAACC,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IAChF;AACR;AACA;IACQ,MAAMG,KAAK,GAAGH,aAAa,CAACG,KAAK;IACjC;AACR;AACA;IACQ,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,KAAK,CAACE,MAAM,EAAED,CAAC,EAAE,EAAE;MACnC,MAAM;QAAEE,EAAE,EAAEC;MAAO,CAAC,GAAGJ,KAAK,CAACC,CAAC,CAAC;MAE/B,IAAII,IAAkC,GAAG;QACrCC,UAAU,EAAE;MAChB,CAAC;MACD;AACZ;AACA;MACY,OAAOD,IAAI,CAACC,UAAU,GAAG,CAAC,EAAE;QACxB,IAAIC,cAAkC,GAAG,EAAE;QAC3C;AAChB;AACA;QACgB,IAAI;UACA,CAACA,cAAc,EAAEF,IAAI,CAAC,GAAG,MAAMT,GAAG,CAACY,aAAa,CAACC,IAAI,CAAC;YAClDC,KAAK,EAAE;cACHC,IAAI,EAAG,GAAEd,aAAa,CAACM,EAAG,IAAGC,MAAO;YACxC;UACJ,CAAC,CAAC;QACN,CAAC,CAAC,OAAOQ,CAAC,EAAE;UACRP,IAAI,CAACC,UAAU,GAAG,CAAC;UACnB,IAAIM,CAAC,CAACC,OAAO,KAAK,2BAA2B,EAAE;YAC3C,MAAMD,CAAC;UACX;UACAE,OAAO,CAACC,GAAG,CAACH,CAAC,CAAC;QAClB;;QAEA;AAChB;AACA;QACgB,KAAK,MAAMJ,aAAa,IAAID,cAAc,EAAE;UACxC,MAAMX,GAAG,CAACY,aAAa,CAACQ,MAAM,CAACR,aAAa,CAACL,EAAE,CAAC;QACpD;MACJ;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.deleteCommentsAfterChangeRequest = void 0;
7
-
8
7
  const deleteCommentsAfterChangeRequest = ({
9
8
  apw
10
9
  }) => {
11
- apw.changeRequest.onAfterChangeRequestDelete.subscribe(async ({
10
+ apw.changeRequest.onChangeRequestAfterDelete.subscribe(async ({
12
11
  changeRequest
13
12
  }) => {
14
13
  /**
@@ -20,13 +19,11 @@ const deleteCommentsAfterChangeRequest = ({
20
19
  /**
21
20
  * Paginate through comments.
22
21
  */
23
-
24
22
  while (meta.totalCount > 0) {
25
23
  let comments = [];
26
24
  /**
27
25
  * Get all comments.
28
26
  */
29
-
30
27
  try {
31
28
  [comments, meta] = await apw.comment.list({
32
29
  where: {
@@ -37,23 +34,19 @@ const deleteCommentsAfterChangeRequest = ({
37
34
  });
38
35
  } catch (e) {
39
36
  meta.totalCount = 0;
40
-
41
37
  if (e.message !== "index_not_found_exception") {
42
38
  throw e;
43
39
  }
44
-
45
40
  console.log(e);
46
41
  }
42
+
47
43
  /**
48
44
  * Delete comments one by one.
49
45
  */
50
-
51
-
52
46
  for (const comment of comments) {
53
47
  await apw.comment.delete(comment.id);
54
48
  }
55
49
  }
56
50
  });
57
51
  };
58
-
59
52
  exports.deleteCommentsAfterChangeRequest = deleteCommentsAfterChangeRequest;
@@ -1 +1 @@
1
- {"version":3,"names":["deleteCommentsAfterChangeRequest","apw","changeRequest","onAfterChangeRequestDelete","subscribe","meta","totalCount","comments","comment","list","where","id","e","message","console","log","delete"],"sources":["deleteCommentsAfterChangeRequest.ts"],"sourcesContent":["import { ApwComment, LifeCycleHookCallbackParams, ListMeta } from \"~/types\";\n\nexport const deleteCommentsAfterChangeRequest = ({\n apw\n}: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onAfterChangeRequestDelete.subscribe(async ({ changeRequest }) => {\n /**\n * Also delete all associated comments with \"changeRequest\".\n */\n let meta: Pick<ListMeta, \"totalCount\"> = {\n totalCount: 1\n };\n /**\n * Paginate through comments.\n */\n while (meta.totalCount > 0) {\n let comments: ApwComment[] = [];\n /**\n * Get all comments.\n */\n try {\n [comments, meta] = await apw.comment.list({\n where: {\n changeRequest: {\n id: changeRequest.id\n }\n }\n });\n } catch (e) {\n meta.totalCount = 0;\n if (e.message !== \"index_not_found_exception\") {\n throw e;\n }\n console.log(e);\n }\n\n /**\n * Delete comments one by one.\n */\n for (const comment of comments) {\n await apw.comment.delete(comment.id);\n }\n }\n });\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,gCAAgC,GAAG,CAAC;EAC7CC;AAD6C,CAAD,KAEA;EAC5CA,GAAG,CAACC,aAAJ,CAAkBC,0BAAlB,CAA6CC,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF;AACR;AACA;IACQ,IAAIG,IAAkC,GAAG;MACrCC,UAAU,EAAE;IADyB,CAAzC;IAGA;AACR;AACA;;IACQ,OAAOD,IAAI,CAACC,UAAL,GAAkB,CAAzB,EAA4B;MACxB,IAAIC,QAAsB,GAAG,EAA7B;MACA;AACZ;AACA;;MACY,IAAI;QACA,CAACA,QAAD,EAAWF,IAAX,IAAmB,MAAMJ,GAAG,CAACO,OAAJ,CAAYC,IAAZ,CAAiB;UACtCC,KAAK,EAAE;YACHR,aAAa,EAAE;cACXS,EAAE,EAAET,aAAa,CAACS;YADP;UADZ;QAD+B,CAAjB,CAAzB;MAOH,CARD,CAQE,OAAOC,CAAP,EAAU;QACRP,IAAI,CAACC,UAAL,GAAkB,CAAlB;;QACA,IAAIM,CAAC,CAACC,OAAF,KAAc,2BAAlB,EAA+C;UAC3C,MAAMD,CAAN;QACH;;QACDE,OAAO,CAACC,GAAR,CAAYH,CAAZ;MACH;MAED;AACZ;AACA;;;MACY,KAAK,MAAMJ,OAAX,IAAsBD,QAAtB,EAAgC;QAC5B,MAAMN,GAAG,CAACO,OAAJ,CAAYQ,MAAZ,CAAmBR,OAAO,CAACG,EAA3B,CAAN;MACH;IACJ;EACJ,CAtCD;AAuCH,CA1CM"}
1
+ {"version":3,"names":["deleteCommentsAfterChangeRequest","apw","changeRequest","onChangeRequestAfterDelete","subscribe","meta","totalCount","comments","comment","list","where","id","e","message","console","log","delete"],"sources":["deleteCommentsAfterChangeRequest.ts"],"sourcesContent":["import { ApwComment, LifeCycleHookCallbackParams, ListMeta } from \"~/types\";\n\nexport const deleteCommentsAfterChangeRequest = ({\n apw\n}: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onChangeRequestAfterDelete.subscribe(async ({ changeRequest }) => {\n /**\n * Also delete all associated comments with \"changeRequest\".\n */\n let meta: Pick<ListMeta, \"totalCount\"> = {\n totalCount: 1\n };\n /**\n * Paginate through comments.\n */\n while (meta.totalCount > 0) {\n let comments: ApwComment[] = [];\n /**\n * Get all comments.\n */\n try {\n [comments, meta] = await apw.comment.list({\n where: {\n changeRequest: {\n id: changeRequest.id\n }\n }\n });\n } catch (e) {\n meta.totalCount = 0;\n if (e.message !== \"index_not_found_exception\") {\n throw e;\n }\n console.log(e);\n }\n\n /**\n * Delete comments one by one.\n */\n for (const comment of comments) {\n await apw.comment.delete(comment.id);\n }\n }\n });\n};\n"],"mappings":";;;;;;AAEO,MAAMA,gCAAgC,GAAG,CAAC;EAC7CC;AACsC,CAAC,KAAK;EAC5CA,GAAG,CAACC,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IAChF;AACR;AACA;IACQ,IAAIG,IAAkC,GAAG;MACrCC,UAAU,EAAE;IAChB,CAAC;IACD;AACR;AACA;IACQ,OAAOD,IAAI,CAACC,UAAU,GAAG,CAAC,EAAE;MACxB,IAAIC,QAAsB,GAAG,EAAE;MAC/B;AACZ;AACA;MACY,IAAI;QACA,CAACA,QAAQ,EAAEF,IAAI,CAAC,GAAG,MAAMJ,GAAG,CAACO,OAAO,CAACC,IAAI,CAAC;UACtCC,KAAK,EAAE;YACHR,aAAa,EAAE;cACXS,EAAE,EAAET,aAAa,CAACS;YACtB;UACJ;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOC,CAAC,EAAE;QACRP,IAAI,CAACC,UAAU,GAAG,CAAC;QACnB,IAAIM,CAAC,CAACC,OAAO,KAAK,2BAA2B,EAAE;UAC3C,MAAMD,CAAC;QACX;QACAE,OAAO,CAACC,GAAG,CAACH,CAAC,CAAC;MAClB;;MAEA;AACZ;AACA;MACY,KAAK,MAAMJ,OAAO,IAAID,QAAQ,EAAE;QAC5B,MAAMN,GAAG,CAACO,OAAO,CAACQ,MAAM,CAACR,OAAO,CAACG,EAAE,CAAC;MACxC;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -4,27 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.attachApwHooks = void 0;
7
-
8
7
  var _api = require("@webiny/api");
9
-
10
8
  var _deleteCommentsAfterChangeRequest = require("./deleteCommentsAfterChangeRequest");
11
-
12
9
  var _deleteChangeRequestsAfterContentReview = require("./deleteChangeRequestsAfterContentReview");
13
-
14
10
  var _createReviewerFromIdentity = require("./createReviewerFromIdentity");
15
-
16
11
  var _initializeContentReviewSteps = require("./initializeContentReviewSteps");
17
-
18
12
  var _updatePendingChangeRequests = require("./updatePendingChangeRequests");
19
-
20
13
  var _updateTotalComments = require("./updateTotalComments");
21
-
22
14
  var _validateChangeRequest = require("./validateChangeRequest");
23
-
24
15
  var _validateContentReview = require("./validateContentReview");
25
-
26
16
  var _validateComment = require("./validateComment");
27
-
17
+ var _listContentReviews = require("./listContentReviews");
18
+ var _initializeNotifications = require("./initializeNotifications");
28
19
  const attachApwHooks = () =>
29
20
  /**
30
21
  * Hook into CMS events and execute business logic.
@@ -63,6 +54,7 @@ new _api.ContextPlugin(async context => {
63
54
  (0, _deleteChangeRequestsAfterContentReview.deleteChangeRequestsWithContentReview)({
64
55
  apw
65
56
  });
57
+ (0, _listContentReviews.listContentReviews)(context);
58
+ (0, _initializeNotifications.initializeNotifications)(context);
66
59
  });
67
-
68
60
  exports.attachApwHooks = attachApwHooks;
@@ -1 +1 @@
1
- {"version":3,"names":["attachApwHooks","ContextPlugin","context","security","apw","validateContentReview","validateChangeRequest","validateComment","createReviewerFromIdentity","initializeContentReviewSteps","updatePendingChangeRequestsCount","updateTotalCommentsCount","updateLatestCommentId","deleteCommentsAfterChangeRequest","deleteChangeRequestsWithContentReview"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { deleteCommentsAfterChangeRequest } from \"./deleteCommentsAfterChangeRequest\";\nimport { deleteChangeRequestsWithContentReview } from \"./deleteChangeRequestsAfterContentReview\";\nimport { createReviewerFromIdentity } from \"./createReviewerFromIdentity\";\nimport { initializeContentReviewSteps } from \"./initializeContentReviewSteps\";\nimport { updatePendingChangeRequestsCount } from \"./updatePendingChangeRequests\";\nimport { updateTotalCommentsCount, updateLatestCommentId } from \"./updateTotalComments\";\nimport { validateChangeRequest } from \"./validateChangeRequest\";\nimport { validateContentReview } from \"./validateContentReview\";\nimport { validateComment } from \"./validateComment\";\n\nexport const attachApwHooks = () =>\n /**\n * Hook into CMS events and execute business logic.\n */\n new ContextPlugin<ApwContext>(async context => {\n const { security, apw } = context;\n\n validateContentReview({ apw });\n\n validateChangeRequest({ apw });\n\n validateComment({ apw });\n\n createReviewerFromIdentity({ security, apw });\n\n initializeContentReviewSteps(context);\n\n updatePendingChangeRequestsCount({ apw });\n\n updateTotalCommentsCount({ apw });\n\n updateLatestCommentId({ apw });\n\n deleteCommentsAfterChangeRequest({ apw });\n\n deleteChangeRequestsWithContentReview({ apw });\n });\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,cAAc,GAAG;AAC1B;AACJ;AACA;AACI,IAAIC,kBAAJ,CAA8B,MAAMC,OAAN,IAAiB;EAC3C,MAAM;IAAEC,QAAF;IAAYC;EAAZ,IAAoBF,OAA1B;EAEA,IAAAG,4CAAA,EAAsB;IAAED;EAAF,CAAtB;EAEA,IAAAE,4CAAA,EAAsB;IAAEF;EAAF,CAAtB;EAEA,IAAAG,gCAAA,EAAgB;IAAEH;EAAF,CAAhB;EAEA,IAAAI,sDAAA,EAA2B;IAAEL,QAAF;IAAYC;EAAZ,CAA3B;EAEA,IAAAK,0DAAA,EAA6BP,OAA7B;EAEA,IAAAQ,6DAAA,EAAiC;IAAEN;EAAF,CAAjC;EAEA,IAAAO,6CAAA,EAAyB;IAAEP;EAAF,CAAzB;EAEA,IAAAQ,0CAAA,EAAsB;IAAER;EAAF,CAAtB;EAEA,IAAAS,kEAAA,EAAiC;IAAET;EAAF,CAAjC;EAEA,IAAAU,6EAAA,EAAsC;IAAEV;EAAF,CAAtC;AACH,CAtBD,CAJG"}
1
+ {"version":3,"names":["attachApwHooks","ContextPlugin","context","security","apw","validateContentReview","validateChangeRequest","validateComment","createReviewerFromIdentity","initializeContentReviewSteps","updatePendingChangeRequestsCount","updateTotalCommentsCount","updateLatestCommentId","deleteCommentsAfterChangeRequest","deleteChangeRequestsWithContentReview","listContentReviews","initializeNotifications"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { deleteCommentsAfterChangeRequest } from \"./deleteCommentsAfterChangeRequest\";\nimport { deleteChangeRequestsWithContentReview } from \"./deleteChangeRequestsAfterContentReview\";\nimport { createReviewerFromIdentity } from \"./createReviewerFromIdentity\";\nimport { initializeContentReviewSteps } from \"./initializeContentReviewSteps\";\nimport { updatePendingChangeRequestsCount } from \"./updatePendingChangeRequests\";\nimport { updateTotalCommentsCount, updateLatestCommentId } from \"./updateTotalComments\";\nimport { validateChangeRequest } from \"./validateChangeRequest\";\nimport { validateContentReview } from \"./validateContentReview\";\nimport { validateComment } from \"./validateComment\";\nimport { listContentReviews } from \"./listContentReviews\";\nimport { initializeNotifications } from \"./initializeNotifications\";\n\nexport const attachApwHooks = () =>\n /**\n * Hook into CMS events and execute business logic.\n */\n new ContextPlugin<ApwContext>(async context => {\n const { security, apw } = context;\n\n validateContentReview({ apw });\n\n validateChangeRequest({ apw });\n\n validateComment({ apw });\n\n createReviewerFromIdentity({ security, apw });\n\n initializeContentReviewSteps(context);\n\n updatePendingChangeRequestsCount({ apw });\n\n updateTotalCommentsCount({ apw });\n\n updateLatestCommentId({ apw });\n\n deleteCommentsAfterChangeRequest({ apw });\n\n deleteChangeRequestsWithContentReview({ apw });\n\n listContentReviews(context);\n\n initializeNotifications(context);\n });\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEO,MAAMA,cAAc,GAAG;AAC1B;AACJ;AACA;AACI,IAAIC,kBAAa,CAAa,MAAMC,OAAO,IAAI;EAC3C,MAAM;IAAEC,QAAQ;IAAEC;EAAI,CAAC,GAAGF,OAAO;EAEjC,IAAAG,4CAAqB,EAAC;IAAED;EAAI,CAAC,CAAC;EAE9B,IAAAE,4CAAqB,EAAC;IAAEF;EAAI,CAAC,CAAC;EAE9B,IAAAG,gCAAe,EAAC;IAAEH;EAAI,CAAC,CAAC;EAExB,IAAAI,sDAA0B,EAAC;IAAEL,QAAQ;IAAEC;EAAI,CAAC,CAAC;EAE7C,IAAAK,0DAA4B,EAACP,OAAO,CAAC;EAErC,IAAAQ,6DAAgC,EAAC;IAAEN;EAAI,CAAC,CAAC;EAEzC,IAAAO,6CAAwB,EAAC;IAAEP;EAAI,CAAC,CAAC;EAEjC,IAAAQ,0CAAqB,EAAC;IAAER;EAAI,CAAC,CAAC;EAE9B,IAAAS,kEAAgC,EAAC;IAAET;EAAI,CAAC,CAAC;EAEzC,IAAAU,6EAAqC,EAAC;IAAEV;EAAI,CAAC,CAAC;EAE9C,IAAAW,sCAAkB,EAACb,OAAO,CAAC;EAE3B,IAAAc,gDAAuB,EAACd,OAAO,CAAC;AACpC,CAAC,CAAC;AAAC"}
@@ -1,31 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.initializeContentReviewSteps = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _set = _interopRequireDefault(require("lodash/set"));
13
-
14
10
  var _utils = require("../utils");
15
-
16
11
  var _handlerGraphql = require("@webiny/handler-graphql");
17
-
18
12
  var _contentApwSettingsPlugin = require("../../utils/contentApwSettingsPlugin");
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
13
  const initializeContentReviewSteps = ({
25
14
  apw,
26
15
  plugins
27
16
  }) => {
28
- apw.contentReview.onBeforeContentReviewCreate.subscribe(async ({
17
+ apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({
29
18
  input
30
19
  }) => {
31
20
  const {
@@ -36,42 +25,39 @@ const initializeContentReviewSteps = ({
36
25
  /*
37
26
  * Let's set "title" field value.
38
27
  */
39
-
40
28
  const getContent = apw.getContentGetter(type);
41
29
  const content = await getContent(id, settings);
42
-
43
30
  if (!content) {
44
31
  throw new _handlerGraphql.NotFoundError(`Content "${type}" with id ${id} not found.`);
45
32
  }
46
-
47
33
  const {
48
34
  title
49
35
  } = content;
50
36
  input = (0, _set.default)(input, "title", title);
37
+
51
38
  /**
52
39
  * We need to find a plugin which can get a workflow ID for the given type of content.
53
40
  */
54
-
55
41
  const contentApwSettingsPlugin = (0, _contentApwSettingsPlugin.getContentApwSettingsPlugin)({
56
42
  plugins,
57
43
  type
58
44
  });
59
45
  const workflowId = contentApwSettingsPlugin.getWorkflowId(content);
46
+
60
47
  /**
61
48
  * Let's initialize the "ContentReview" steps.
62
49
  */
63
-
64
50
  if (!workflowId) {
65
51
  throw new _handlerGraphql.NotFoundError(`Unable to initiate a "Content review". No workflow found!`);
66
52
  }
67
-
53
+ input.workflowId = workflowId;
68
54
  const workflow = await apw.workflow.get(workflowId);
69
55
  const workflowSteps = workflow.steps;
70
56
  let previousStepStatus = undefined;
71
57
  const updatedSteps = workflow.steps.map((step, index) => {
72
58
  const status = (0, _utils.getContentReviewStepInitialStatus)(workflowSteps, index, previousStepStatus);
73
59
  previousStepStatus = status;
74
- return _objectSpread(_objectSpread({}, step), {}, {
60
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
75
61
  status,
76
62
  pendingChangeRequests: 0,
77
63
  totalComments: 0
@@ -81,9 +67,7 @@ const initializeContentReviewSteps = ({
81
67
  * TODO Figure our what does this actually do?
82
68
  * There is no steps property on CreateApwContentReviewParams
83
69
  */
84
-
85
70
  input = (0, _set.default)(input, "steps", updatedSteps);
86
71
  });
87
72
  };
88
-
89
73
  exports.initializeContentReviewSteps = initializeContentReviewSteps;
@@ -1 +1 @@
1
- {"version":3,"names":["initializeContentReviewSteps","apw","plugins","contentReview","onBeforeContentReviewCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport { ApwContentReviewStepStatus, ApwContext } from \"~/types\";\nimport { getContentReviewStepInitialStatus } from \"~/plugins/utils\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { getContentApwSettingsPlugin } from \"~/utils/contentApwSettingsPlugin\";\n\nexport const initializeContentReviewSteps = ({ apw, plugins }: ApwContext) => {\n apw.contentReview.onBeforeContentReviewCreate.subscribe(async ({ input }) => {\n const { type, id, settings } = input.content;\n /*\n * Let's set \"title\" field value.\n */\n const getContent = apw.getContentGetter(type);\n const content = await getContent(id, settings);\n if (!content) {\n throw new NotFoundError(`Content \"${type}\" with id ${id} not found.`);\n }\n\n const { title } = content;\n input = lodashSet(input, \"title\", title);\n\n /**\n * We need to find a plugin which can get a workflow ID for the given type of content.\n */\n const contentApwSettingsPlugin = getContentApwSettingsPlugin({\n plugins,\n type\n });\n\n const workflowId = contentApwSettingsPlugin.getWorkflowId(content);\n\n /**\n * Let's initialize the \"ContentReview\" steps.\n */\n if (!workflowId) {\n throw new NotFoundError(`Unable to initiate a \"Content review\". No workflow found!`);\n }\n\n const workflow = await apw.workflow.get(workflowId);\n const workflowSteps = workflow.steps;\n\n let previousStepStatus: ApwContentReviewStepStatus | undefined = undefined;\n const updatedSteps = workflow.steps.map((step, index) => {\n const status = getContentReviewStepInitialStatus(\n workflowSteps,\n index,\n previousStepStatus\n );\n previousStepStatus = status;\n return {\n ...step,\n status,\n pendingChangeRequests: 0,\n totalComments: 0\n };\n });\n /**\n * TODO Figure our what does this actually do?\n * There is no steps property on CreateApwContentReviewParams\n */\n input = lodashSet(input, \"steps\", updatedSteps);\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;;;;;AAEO,MAAMA,4BAA4B,GAAG,CAAC;EAAEC,GAAF;EAAOC;AAAP,CAAD,KAAkC;EAC1ED,GAAG,CAACE,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC,IAAF;MAAQC,EAAR;MAAYC;IAAZ,IAAyBH,KAAK,CAACI,OAArC;IACA;AACR;AACA;;IACQ,MAAMC,UAAU,GAAGV,GAAG,CAACW,gBAAJ,CAAqBL,IAArB,CAAnB;IACA,MAAMG,OAAO,GAAG,MAAMC,UAAU,CAACH,EAAD,EAAKC,QAAL,CAAhC;;IACA,IAAI,CAACC,OAAL,EAAc;MACV,MAAM,IAAIG,6BAAJ,CAAmB,YAAWN,IAAK,aAAYC,EAAG,aAAlD,CAAN;IACH;;IAED,MAAM;MAAEM;IAAF,IAAYJ,OAAlB;IACAJ,KAAK,GAAG,IAAAS,YAAA,EAAUT,KAAV,EAAiB,OAAjB,EAA0BQ,KAA1B,CAAR;IAEA;AACR;AACA;;IACQ,MAAME,wBAAwB,GAAG,IAAAC,qDAAA,EAA4B;MACzDf,OADyD;MAEzDK;IAFyD,CAA5B,CAAjC;IAKA,MAAMW,UAAU,GAAGF,wBAAwB,CAACG,aAAzB,CAAuCT,OAAvC,CAAnB;IAEA;AACR;AACA;;IACQ,IAAI,CAACQ,UAAL,EAAiB;MACb,MAAM,IAAIL,6BAAJ,CAAmB,2DAAnB,CAAN;IACH;;IAED,MAAMO,QAAQ,GAAG,MAAMnB,GAAG,CAACmB,QAAJ,CAAaC,GAAb,CAAiBH,UAAjB,CAAvB;IACA,MAAMI,aAAa,GAAGF,QAAQ,CAACG,KAA/B;IAEA,IAAIC,kBAA0D,GAAGC,SAAjE;IACA,MAAMC,YAAY,GAAGN,QAAQ,CAACG,KAAT,CAAeI,GAAf,CAAmB,CAACC,IAAD,EAAOC,KAAP,KAAiB;MACrD,MAAMC,MAAM,GAAG,IAAAC,wCAAA,EACXT,aADW,EAEXO,KAFW,EAGXL,kBAHW,CAAf;MAKAA,kBAAkB,GAAGM,MAArB;MACA,uCACOF,IADP;QAEIE,MAFJ;QAGIE,qBAAqB,EAAE,CAH3B;QAIIC,aAAa,EAAE;MAJnB;IAMH,CAboB,CAArB;IAcA;AACR;AACA;AACA;;IACQ3B,KAAK,GAAG,IAAAS,YAAA,EAAUT,KAAV,EAAiB,OAAjB,EAA0BoB,YAA1B,CAAR;EACH,CAtDD;AAuDH,CAxDM"}
1
+ {"version":3,"names":["initializeContentReviewSteps","apw","plugins","contentReview","onContentReviewBeforeCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport { ApwContentReviewStepStatus, ApwContext } from \"~/types\";\nimport { getContentReviewStepInitialStatus } from \"~/plugins/utils\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { getContentApwSettingsPlugin } from \"~/utils/contentApwSettingsPlugin\";\n\nexport const initializeContentReviewSteps = ({ apw, plugins }: ApwContext) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { type, id, settings } = input.content;\n /*\n * Let's set \"title\" field value.\n */\n const getContent = apw.getContentGetter(type);\n const content = await getContent(id, settings);\n if (!content) {\n throw new NotFoundError(`Content \"${type}\" with id ${id} not found.`);\n }\n\n const { title } = content;\n input = lodashSet(input, \"title\", title);\n\n /**\n * We need to find a plugin which can get a workflow ID for the given type of content.\n */\n const contentApwSettingsPlugin = getContentApwSettingsPlugin({\n plugins,\n type\n });\n\n const workflowId = contentApwSettingsPlugin.getWorkflowId(content);\n\n /**\n * Let's initialize the \"ContentReview\" steps.\n */\n if (!workflowId) {\n throw new NotFoundError(`Unable to initiate a \"Content review\". No workflow found!`);\n }\n\n input.workflowId = workflowId;\n\n const workflow = await apw.workflow.get(workflowId);\n const workflowSteps = workflow.steps;\n\n let previousStepStatus: ApwContentReviewStepStatus | undefined = undefined;\n const updatedSteps = workflow.steps.map((step, index) => {\n const status = getContentReviewStepInitialStatus(\n workflowSteps,\n index,\n previousStepStatus\n );\n previousStepStatus = status;\n return {\n ...step,\n status,\n pendingChangeRequests: 0,\n totalComments: 0\n };\n });\n /**\n * TODO Figure our what does this actually do?\n * There is no steps property on CreateApwContentReviewParams\n */\n input = lodashSet(input, \"steps\", updatedSteps);\n });\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AACA;AACA;AAEO,MAAMA,4BAA4B,GAAG,CAAC;EAAEC,GAAG;EAAEC;AAAoB,CAAC,KAAK;EAC1ED,GAAG,CAACE,aAAa,CAACC,2BAA2B,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACzE,MAAM;MAAEC,IAAI;MAAEC,EAAE;MAAEC;IAAS,CAAC,GAAGH,KAAK,CAACI,OAAO;IAC5C;AACR;AACA;IACQ,MAAMC,UAAU,GAAGV,GAAG,CAACW,gBAAgB,CAACL,IAAI,CAAC;IAC7C,MAAMG,OAAO,GAAG,MAAMC,UAAU,CAACH,EAAE,EAAEC,QAAQ,CAAC;IAC9C,IAAI,CAACC,OAAO,EAAE;MACV,MAAM,IAAIG,6BAAa,CAAE,YAAWN,IAAK,aAAYC,EAAG,aAAY,CAAC;IACzE;IAEA,MAAM;MAAEM;IAAM,CAAC,GAAGJ,OAAO;IACzBJ,KAAK,GAAG,IAAAS,YAAS,EAACT,KAAK,EAAE,OAAO,EAAEQ,KAAK,CAAC;;IAExC;AACR;AACA;IACQ,MAAME,wBAAwB,GAAG,IAAAC,qDAA2B,EAAC;MACzDf,OAAO;MACPK;IACJ,CAAC,CAAC;IAEF,MAAMW,UAAU,GAAGF,wBAAwB,CAACG,aAAa,CAACT,OAAO,CAAC;;IAElE;AACR;AACA;IACQ,IAAI,CAACQ,UAAU,EAAE;MACb,MAAM,IAAIL,6BAAa,CAAE,2DAA0D,CAAC;IACxF;IAEAP,KAAK,CAACY,UAAU,GAAGA,UAAU;IAE7B,MAAME,QAAQ,GAAG,MAAMnB,GAAG,CAACmB,QAAQ,CAACC,GAAG,CAACH,UAAU,CAAC;IACnD,MAAMI,aAAa,GAAGF,QAAQ,CAACG,KAAK;IAEpC,IAAIC,kBAA0D,GAAGC,SAAS;IAC1E,MAAMC,YAAY,GAAGN,QAAQ,CAACG,KAAK,CAACI,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAK;MACrD,MAAMC,MAAM,GAAG,IAAAC,wCAAiC,EAC5CT,aAAa,EACbO,KAAK,EACLL,kBAAkB,CACrB;MACDA,kBAAkB,GAAGM,MAAM;MAC3B,mEACOF,IAAI;QACPE,MAAM;QACNE,qBAAqB,EAAE,CAAC;QACxBC,aAAa,EAAE;MAAC;IAExB,CAAC,CAAC;IACF;AACR;AACA;AACA;IACQ3B,KAAK,GAAG,IAAAS,YAAS,EAACT,KAAK,EAAE,OAAO,EAAEoB,YAAY,CAAC;EACnD,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../types";
2
+ export declare const initializeNotifications: (context: ApwContext) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initializeNotifications = void 0;
7
+ var _contentReviewAfterCreate = require("./notifications/contentReviewAfterCreate");
8
+ var _commentAfterCreate = require("./notifications/commentAfterCreate");
9
+ var _changeRequestAfterCreate = require("./notifications/changeRequestAfterCreate");
10
+ const initializeNotifications = context => {
11
+ (0, _contentReviewAfterCreate.attachContentReviewAfterCreate)(context);
12
+ (0, _commentAfterCreate.attachCommentAfterCreate)(context);
13
+ (0, _changeRequestAfterCreate.attachChangeRequestAfterCreate)(context);
14
+ };
15
+ exports.initializeNotifications = initializeNotifications;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["initializeNotifications","context","attachContentReviewAfterCreate","attachCommentAfterCreate","attachChangeRequestAfterCreate"],"sources":["initializeNotifications.ts"],"sourcesContent":["import { ApwContext } from \"~/types\";\nimport { attachContentReviewAfterCreate } from \"./notifications/contentReviewAfterCreate\";\nimport { attachCommentAfterCreate } from \"./notifications/commentAfterCreate\";\nimport { attachChangeRequestAfterCreate } from \"./notifications/changeRequestAfterCreate\";\n\nexport const initializeNotifications = (context: ApwContext) => {\n attachContentReviewAfterCreate(context);\n attachCommentAfterCreate(context);\n attachChangeRequestAfterCreate(context);\n};\n"],"mappings":";;;;;;AACA;AACA;AACA;AAEO,MAAMA,uBAAuB,GAAIC,OAAmB,IAAK;EAC5D,IAAAC,wDAA8B,EAACD,OAAO,CAAC;EACvC,IAAAE,4CAAwB,EAACF,OAAO,CAAC;EACjC,IAAAG,wDAA8B,EAACH,OAAO,CAAC;AAC3C,CAAC;AAAC"}
@@ -0,0 +1,10 @@
1
+ import { AdvancedPublishingWorkflow } from "../../types";
2
+ import { HeadlessCms } from "@webiny/api-headless-cms/types";
3
+ import { Security } from "@webiny/api-security/types";
4
+ interface ListWorkflowsParams {
5
+ apw: AdvancedPublishingWorkflow;
6
+ cms: HeadlessCms;
7
+ security: Security;
8
+ }
9
+ export declare const listContentReviews: ({ apw, security }: ListWorkflowsParams) => void;
10
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.listContentReviews = void 0;
7
+ const listContentReviews = ({
8
+ apw,
9
+ security
10
+ }) => {
11
+ /**
12
+ * We need to hook into listing the content review entries.
13
+ * When listing content review entries, we need to check which ones current user can actually see.
14
+ */
15
+ apw.contentReview.onContentReviewBeforeList.subscribe(async ({
16
+ where
17
+ }) => {
18
+ /**
19
+ * If there is workflowId_in attached on where, we will not change it.
20
+ */
21
+ if (where.workflowId_in) {
22
+ return;
23
+ }
24
+ const identity = security.getIdentity();
25
+ if (!(identity !== null && identity !== void 0 && identity.id)) {
26
+ return;
27
+ }
28
+ /**
29
+ * Find all available workflows.
30
+ */
31
+ const [workflows] = await apw.workflow.list();
32
+ if (workflows.length === 0) {
33
+ return;
34
+ }
35
+ /**
36
+ * Find all workflows which user has access to.
37
+ * User access is buried quite deep in the workflow data, so we need to do some traversing.
38
+ */
39
+ const userWorkflows = workflows.filter(workflow => {
40
+ return workflow.steps.some(step => {
41
+ return step.reviewers.some(reviewer => {
42
+ return identity.id === reviewer.identityId;
43
+ });
44
+ });
45
+ });
46
+ if (userWorkflows.length === 0) {
47
+ return;
48
+ }
49
+ /**
50
+ * In the end, we need to attach the workflow filter by the entryId.
51
+ * Just in case we add versioning at some point...
52
+ */
53
+ where.workflowId_in = userWorkflows.map(workflow => workflow.id);
54
+ });
55
+ };
56
+ exports.listContentReviews = listContentReviews;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["listContentReviews","apw","security","contentReview","onContentReviewBeforeList","subscribe","where","workflowId_in","identity","getIdentity","id","workflows","workflow","list","length","userWorkflows","filter","steps","some","step","reviewers","reviewer","identityId","map"],"sources":["listContentReviews.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow } from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\n\ninterface ListWorkflowsParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\nexport const listContentReviews = ({ apw, security }: ListWorkflowsParams) => {\n /**\n * We need to hook into listing the content review entries.\n * When listing content review entries, we need to check which ones current user can actually see.\n */\n apw.contentReview.onContentReviewBeforeList.subscribe(async ({ where }) => {\n /**\n * If there is workflowId_in attached on where, we will not change it.\n */\n if (where.workflowId_in) {\n return;\n }\n const identity = security.getIdentity();\n if (!identity?.id) {\n return;\n }\n /**\n * Find all available workflows.\n */\n const [workflows] = await apw.workflow.list();\n if (workflows.length === 0) {\n return;\n }\n /**\n * Find all workflows which user has access to.\n * User access is buried quite deep in the workflow data, so we need to do some traversing.\n */\n const userWorkflows = workflows.filter(workflow => {\n return workflow.steps.some(step => {\n return step.reviewers.some(reviewer => {\n return identity.id === reviewer.identityId;\n });\n });\n });\n if (userWorkflows.length === 0) {\n return;\n }\n /**\n * In the end, we need to attach the workflow filter by the entryId.\n * Just in case we add versioning at some point...\n */\n where.workflowId_in = userWorkflows.map(workflow => workflow.id);\n });\n};\n"],"mappings":";;;;;;AASO,MAAMA,kBAAkB,GAAG,CAAC;EAAEC,GAAG;EAAEC;AAA8B,CAAC,KAAK;EAC1E;AACJ;AACA;AACA;EACID,GAAG,CAACE,aAAa,CAACC,yBAAyB,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACvE;AACR;AACA;IACQ,IAAIA,KAAK,CAACC,aAAa,EAAE;MACrB;IACJ;IACA,MAAMC,QAAQ,GAAGN,QAAQ,CAACO,WAAW,EAAE;IACvC,IAAI,EAACD,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEE,EAAE,GAAE;MACf;IACJ;IACA;AACR;AACA;IACQ,MAAM,CAACC,SAAS,CAAC,GAAG,MAAMV,GAAG,CAACW,QAAQ,CAACC,IAAI,EAAE;IAC7C,IAAIF,SAAS,CAACG,MAAM,KAAK,CAAC,EAAE;MACxB;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAMC,aAAa,GAAGJ,SAAS,CAACK,MAAM,CAACJ,QAAQ,IAAI;MAC/C,OAAOA,QAAQ,CAACK,KAAK,CAACC,IAAI,CAACC,IAAI,IAAI;QAC/B,OAAOA,IAAI,CAACC,SAAS,CAACF,IAAI,CAACG,QAAQ,IAAI;UACnC,OAAOb,QAAQ,CAACE,EAAE,KAAKW,QAAQ,CAACC,UAAU;QAC9C,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC,CAAC;IACF,IAAIP,aAAa,CAACD,MAAM,KAAK,CAAC,EAAE;MAC5B;IACJ;IACA;AACR;AACA;AACA;IACQR,KAAK,CAACC,aAAa,GAAGQ,aAAa,CAACQ,GAAG,CAACX,QAAQ,IAAIA,QAAQ,CAACF,EAAE,CAAC;EACpE,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const getAppUrl: (context: ApwContext) => Promise<import("@webiny/api-admin-settings/types").AdminSettings | null>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAppUrl = void 0;
7
+ const getAppUrl = async context => {
8
+ const tenant = context.tenancy.getCurrentTenant().id;
9
+ try {
10
+ return await context.settings.getSettings(tenant);
11
+ } catch (ex) {
12
+ if (ex.code !== "NOT_FOUND") {
13
+ throw ex;
14
+ }
15
+ }
16
+ return null;
17
+ };
18
+ exports.getAppUrl = getAppUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getAppUrl","context","tenant","tenancy","getCurrentTenant","id","settings","getSettings","ex","code"],"sources":["appUrl.ts"],"sourcesContent":["import { ApwContext } from \"~/types\";\n\nexport const getAppUrl = async (context: ApwContext) => {\n const tenant = context.tenancy.getCurrentTenant().id;\n try {\n return await context.settings.getSettings(tenant);\n } catch (ex) {\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n return null;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,SAAS,GAAG,MAAOC,OAAmB,IAAK;EACpD,MAAMC,MAAM,GAAGD,OAAO,CAACE,OAAO,CAACC,gBAAgB,EAAE,CAACC,EAAE;EACpD,IAAI;IACA,OAAO,MAAMJ,OAAO,CAACK,QAAQ,CAACC,WAAW,CAACL,MAAM,CAAC;EACrD,CAAC,CAAC,OAAOM,EAAE,EAAE;IACT,IAAIA,EAAE,CAACC,IAAI,KAAK,WAAW,EAAE;MACzB,MAAMD,EAAE;IACZ;EACJ;EACA,OAAO,IAAI;AACf,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachChangeRequestAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.attachChangeRequestAfterCreate = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _utils = require("../../utils");
10
+ var _contentUrl = require("./contentUrl");
11
+ var _sendChangeRequestNotification = require("./sendChangeRequestNotification");
12
+ var _reviewers = require("./reviewers");
13
+ var _changeRequestUrl = require("./changeRequestUrl");
14
+ var _appUrl = require("./appUrl");
15
+ const attachChangeRequestAfterCreate = context => {
16
+ context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({
17
+ changeRequest
18
+ }) => {
19
+ const execute = async () => {
20
+ const {
21
+ id: contentReviewId,
22
+ stepId
23
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
24
+ if (!stepId) {
25
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
26
+ step: changeRequest.step
27
+ });
28
+ }
29
+ const settings = await (0, _appUrl.getAppUrl)(context);
30
+ if (!settings) {
31
+ return;
32
+ }
33
+ /**
34
+ * We will check if we can create a comment url before we go digging further into the database.
35
+ */
36
+ const changeRequestUrl = (0, _changeRequestUrl.createChangeRequestUrl)({
37
+ baseUrl: settings.appUrl,
38
+ changeRequestId: changeRequest.id,
39
+ contentReviewId,
40
+ stepId
41
+ });
42
+ if (!changeRequestUrl) {
43
+ return;
44
+ }
45
+ /**
46
+ * Let's see if content review exists.
47
+ */
48
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
49
+ if (!contentReview) {
50
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
51
+ contentReviewId
52
+ });
53
+ }
54
+ /**
55
+ * We go and check the workflow.
56
+ */
57
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
58
+ if (!workflow) {
59
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
60
+ workflowId: contentReview.workflowId
61
+ });
62
+ }
63
+ const contentUrl = (0, _contentUrl.createContentUrl)({
64
+ plugins: context.plugins,
65
+ baseUrl: settings.appUrl,
66
+ contentReview,
67
+ workflow
68
+ });
69
+ if (!contentUrl) {
70
+ return;
71
+ }
72
+ const reviewers = await (0, _reviewers.fetchReviewers)({
73
+ context,
74
+ workflow,
75
+ exclude: [changeRequest.createdBy.id]
76
+ });
77
+ if (reviewers.length === 0) {
78
+ return;
79
+ }
80
+ try {
81
+ await (0, _sendChangeRequestNotification.sendChangeRequestNotification)({
82
+ context,
83
+ reviewers,
84
+ changeRequest,
85
+ contentReview,
86
+ workflow,
87
+ changeRequestUrl,
88
+ contentUrl
89
+ });
90
+ } catch (ex) {
91
+ throw new _error.default(`Could not send change request notifications.`, "CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT", {
92
+ workflowId: workflow.id,
93
+ changeRequestId: changeRequest.id,
94
+ contentReviewId,
95
+ changeRequestUrl,
96
+ contentUrl,
97
+ error: {
98
+ message: ex.message,
99
+ code: ex.code,
100
+ data: ex.data,
101
+ stack: ex.stack
102
+ }
103
+ });
104
+ }
105
+ };
106
+ try {
107
+ context.security.disableAuthorization();
108
+ await execute();
109
+ } catch (ex) {
110
+ throw ex;
111
+ } finally {
112
+ context.security.enableAuthorization();
113
+ }
114
+ });
115
+ };
116
+ exports.attachChangeRequestAfterCreate = attachChangeRequestAfterCreate;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["attachChangeRequestAfterCreate","context","apw","changeRequest","onChangeRequestAfterCreate","subscribe","execute","id","contentReviewId","stepId","extractContentReviewIdAndStep","step","WebinyError","settings","getAppUrl","changeRequestUrl","createChangeRequestUrl","baseUrl","appUrl","changeRequestId","contentReview","get","workflow","workflowId","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","length","sendChangeRequestNotification","ex","error","message","code","data","stack","security","disableAuthorization","enableAuthorization"],"sources":["changeRequestAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { sendChangeRequestNotification } from \"./sendChangeRequestNotification\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { createChangeRequestUrl } from \"./changeRequestUrl\";\nimport { getAppUrl } from \"~/plugins/hooks/notifications/appUrl\";\n\nexport const attachChangeRequestAfterCreate = (context: ApwContext): void => {\n context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({ changeRequest }) => {\n const execute = async () => {\n const { id: contentReviewId, stepId } = extractContentReviewIdAndStep(\n changeRequest.step\n );\n if (!stepId) {\n throw new WebinyError(\"Malformed changeRequest.step value.\", \"MALFORMED_VALUE\", {\n step: changeRequest.step\n });\n }\n\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n /**\n * We will check if we can create a comment url before we go digging further into the database.\n */\n const changeRequestUrl = createChangeRequestUrl({\n baseUrl: settings.appUrl,\n changeRequestId: changeRequest.id,\n contentReviewId,\n stepId\n });\n if (!changeRequestUrl) {\n return;\n }\n /**\n * Let's see if content review exists.\n */\n const contentReview = await context.apw.contentReview.get(contentReviewId);\n if (!contentReview) {\n throw new WebinyError(\n `There is no contentReview with id \"${contentReviewId}\".`,\n \"CONTENT_REVIEW_NOT_FOUND\",\n {\n contentReviewId\n }\n );\n }\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with workflowId \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [changeRequest.createdBy.id]\n });\n if (reviewers.length === 0) {\n return;\n }\n\n try {\n await sendChangeRequestNotification({\n context,\n reviewers,\n changeRequest,\n contentReview,\n workflow,\n changeRequestUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send change request notifications.`,\n \"CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT\",\n {\n workflowId: workflow.id,\n changeRequestId: changeRequest.id,\n contentReviewId,\n changeRequestUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n try {\n context.security.disableAuthorization();\n await execute();\n } catch (ex) {\n throw ex;\n } finally {\n context.security.enableAuthorization();\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEO,MAAMA,8BAA8B,GAAIC,OAAmB,IAAW;EACzEA,OAAO,CAACC,GAAG,CAACC,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IACxF,MAAMG,OAAO,GAAG,YAAY;MACxB,MAAM;QAAEC,EAAE,EAAEC,eAAe;QAAEC;MAAO,CAAC,GAAG,IAAAC,oCAA6B,EACjEP,aAAa,CAACQ,IAAI,CACrB;MACD,IAAI,CAACF,MAAM,EAAE;QACT,MAAM,IAAIG,cAAW,CAAC,qCAAqC,EAAE,iBAAiB,EAAE;UAC5ED,IAAI,EAAER,aAAa,CAACQ;QACxB,CAAC,CAAC;MACN;MAEA,MAAME,QAAQ,GAAG,MAAM,IAAAC,iBAAS,EAACb,OAAO,CAAC;MACzC,IAAI,CAACY,QAAQ,EAAE;QACX;MACJ;MACA;AACZ;AACA;MACY,MAAME,gBAAgB,GAAG,IAAAC,wCAAsB,EAAC;QAC5CC,OAAO,EAAEJ,QAAQ,CAACK,MAAM;QACxBC,eAAe,EAAEhB,aAAa,CAACI,EAAE;QACjCC,eAAe;QACfC;MACJ,CAAC,CAAC;MACF,IAAI,CAACM,gBAAgB,EAAE;QACnB;MACJ;MACA;AACZ;AACA;MACY,MAAMK,aAAa,GAAG,MAAMnB,OAAO,CAACC,GAAG,CAACkB,aAAa,CAACC,GAAG,CAACb,eAAe,CAAC;MAC1E,IAAI,CAACY,aAAa,EAAE;QAChB,MAAM,IAAIR,cAAW,CAChB,sCAAqCJ,eAAgB,IAAG,EACzD,0BAA0B,EAC1B;UACIA;QACJ,CAAC,CACJ;MACL;MACA;AACZ;AACA;MACY,MAAMc,QAAQ,GAAG,MAAMrB,OAAO,CAACC,GAAG,CAACoB,QAAQ,CAACD,GAAG,CAACD,aAAa,CAACG,UAAU,CAAC;MACzE,IAAI,CAACD,QAAQ,EAAE;QACX,MAAM,IAAIV,cAAW,CAChB,yCAAwCQ,aAAa,CAACG,UAAW,IAAG,EACrE,oBAAoB,EACpB;UACIA,UAAU,EAAEH,aAAa,CAACG;QAC9B,CAAC,CACJ;MACL;MAEA,MAAMC,UAAU,GAAG,IAAAC,4BAAgB,EAAC;QAChCC,OAAO,EAAEzB,OAAO,CAACyB,OAAO;QACxBT,OAAO,EAAEJ,QAAQ,CAACK,MAAM;QACxBE,aAAa;QACbE;MACJ,CAAC,CAAC;MACF,IAAI,CAACE,UAAU,EAAE;QACb;MACJ;MAEA,MAAMG,SAAS,GAAG,MAAM,IAAAC,yBAAc,EAAC;QACnC3B,OAAO;QACPqB,QAAQ;QACRO,OAAO,EAAE,CAAC1B,aAAa,CAAC2B,SAAS,CAACvB,EAAE;MACxC,CAAC,CAAC;MACF,IAAIoB,SAAS,CAACI,MAAM,KAAK,CAAC,EAAE;QACxB;MACJ;MAEA,IAAI;QACA,MAAM,IAAAC,4DAA6B,EAAC;UAChC/B,OAAO;UACP0B,SAAS;UACTxB,aAAa;UACbiB,aAAa;UACbE,QAAQ;UACRP,gBAAgB;UAChBS;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOS,EAAE,EAAE;QACT,MAAM,IAAIrB,cAAW,CAChB,8CAA6C,EAC9C,uCAAuC,EACvC;UACIW,UAAU,EAAED,QAAQ,CAACf,EAAE;UACvBY,eAAe,EAAEhB,aAAa,CAACI,EAAE;UACjCC,eAAe;UACfO,gBAAgB;UAChBS,UAAU;UACVU,KAAK,EAAE;YACHC,OAAO,EAAEF,EAAE,CAACE,OAAO;YACnBC,IAAI,EAAEH,EAAE,CAACG,IAAI;YACbC,IAAI,EAAEJ,EAAE,CAACI,IAAI;YACbC,KAAK,EAAEL,EAAE,CAACK;UACd;QACJ,CAAC,CACJ;MACL;IACJ,CAAC;IAED,IAAI;MACArC,OAAO,CAACsC,QAAQ,CAACC,oBAAoB,EAAE;MACvC,MAAMlC,OAAO,EAAE;IACnB,CAAC,CAAC,OAAO2B,EAAE,EAAE;MACT,MAAMA,EAAE;IACZ,CAAC,SAAS;MACNhC,OAAO,CAACsC,QAAQ,CAACE,mBAAmB,EAAE;IAC1C;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}