@webiny/api-apw 5.33.5-beta.0 → 5.34.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) 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/plugins/ApplicationGraphQL.js +1 -1
  171. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -1
  172. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +1 -1
  173. package/scheduler/handlers/scheduleAction/index.js +8 -9
  174. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  175. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +5 -9
  176. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  177. package/scheduler/handlers/utils.js +1 -1
  178. package/storageOperations/changeRequestStorageOperations.js +5 -9
  179. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  180. package/storageOperations/commentStorageOperations.js +4 -8
  181. package/storageOperations/commentStorageOperations.js.map +1 -1
  182. package/storageOperations/contentReviewStorageOperations.js +5 -9
  183. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  184. package/storageOperations/index.js +5 -9
  185. package/storageOperations/index.js.map +1 -1
  186. package/storageOperations/models/contentModelPluginFactory.js +3 -7
  187. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  188. package/storageOperations/models/contentReview.model.js +6 -5
  189. package/storageOperations/models/contentReview.model.js.map +1 -1
  190. package/storageOperations/models/index.js +1 -1
  191. package/storageOperations/models/reviewer.model.js +18 -2
  192. package/storageOperations/models/reviewer.model.js.map +1 -1
  193. package/storageOperations/models/utils.js +3 -2
  194. package/storageOperations/models/utils.js.map +1 -1
  195. package/storageOperations/reviewerStorageOperations.js +18 -14
  196. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  197. package/storageOperations/workflowStorageOperations.js +8 -12
  198. package/storageOperations/workflowStorageOperations.js.map +1 -1
  199. package/types.d.ts +99 -84
  200. package/types.js.map +1 -1
  201. package/utils/errors.js +1 -1
  202. package/utils/fieldResolver.js +3 -9
  203. package/utils/fieldResolver.js.map +1 -1
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.attachChangeRequestAfterCreate = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _utils = require("../../utils");
13
+
14
+ var _contentUrl = require("./contentUrl");
15
+
16
+ var _sendChangeRequestNotification = require("./sendChangeRequestNotification");
17
+
18
+ var _reviewers = require("./reviewers");
19
+
20
+ var _changeRequestUrl = require("./changeRequestUrl");
21
+
22
+ var _appUrl = require("./appUrl");
23
+
24
+ const attachChangeRequestAfterCreate = context => {
25
+ context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({
26
+ changeRequest
27
+ }) => {
28
+ const execute = async () => {
29
+ const {
30
+ id: contentReviewId,
31
+ stepId
32
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
33
+
34
+ if (!stepId) {
35
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
36
+ step: changeRequest.step
37
+ });
38
+ }
39
+
40
+ const settings = await (0, _appUrl.getAppUrl)(context);
41
+
42
+ if (!settings) {
43
+ return;
44
+ }
45
+ /**
46
+ * We will check if we can create a comment url before we go digging further into the database.
47
+ */
48
+
49
+
50
+ const changeRequestUrl = (0, _changeRequestUrl.createChangeRequestUrl)({
51
+ baseUrl: settings.appUrl,
52
+ changeRequestId: changeRequest.id,
53
+ contentReviewId,
54
+ stepId
55
+ });
56
+
57
+ if (!changeRequestUrl) {
58
+ return;
59
+ }
60
+ /**
61
+ * Let's see if content review exists.
62
+ */
63
+
64
+
65
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
66
+
67
+ if (!contentReview) {
68
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
69
+ contentReviewId
70
+ });
71
+ }
72
+ /**
73
+ * We go and check the workflow.
74
+ */
75
+
76
+
77
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
78
+
79
+ if (!workflow) {
80
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
81
+ workflowId: contentReview.workflowId
82
+ });
83
+ }
84
+
85
+ const contentUrl = (0, _contentUrl.createContentUrl)({
86
+ plugins: context.plugins,
87
+ baseUrl: settings.appUrl,
88
+ contentReview,
89
+ workflow
90
+ });
91
+
92
+ if (!contentUrl) {
93
+ return;
94
+ }
95
+
96
+ const reviewers = await (0, _reviewers.fetchReviewers)({
97
+ context,
98
+ workflow,
99
+ exclude: [changeRequest.createdBy.id]
100
+ });
101
+
102
+ if (reviewers.length === 0) {
103
+ return;
104
+ }
105
+
106
+ try {
107
+ await (0, _sendChangeRequestNotification.sendChangeRequestNotification)({
108
+ context,
109
+ reviewers,
110
+ changeRequest,
111
+ contentReview,
112
+ workflow,
113
+ changeRequestUrl,
114
+ contentUrl
115
+ });
116
+ } catch (ex) {
117
+ throw new _error.default(`Could not send change request notifications.`, "CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT", {
118
+ workflowId: workflow.id,
119
+ changeRequestId: changeRequest.id,
120
+ contentReviewId,
121
+ changeRequestUrl,
122
+ contentUrl,
123
+ error: {
124
+ message: ex.message,
125
+ code: ex.code,
126
+ data: ex.data,
127
+ stack: ex.stack
128
+ }
129
+ });
130
+ }
131
+ };
132
+
133
+ try {
134
+ context.security.disableAuthorization();
135
+ await execute();
136
+ } catch (ex) {
137
+ throw ex;
138
+ } finally {
139
+ context.security.enableAuthorization();
140
+ }
141
+ });
142
+ };
143
+
144
+ 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,OAAD,IAA+B;EACzEA,OAAO,CAACC,GAAR,CAAYC,aAAZ,CAA0BC,0BAA1B,CAAqDC,SAArD,CAA+D,OAAO;IAAEF;EAAF,CAAP,KAA6B;IACxF,MAAMG,OAAO,GAAG,YAAY;MACxB,MAAM;QAAEC,EAAE,EAAEC,eAAN;QAAuBC;MAAvB,IAAkC,IAAAC,oCAAA,EACpCP,aAAa,CAACQ,IADsB,CAAxC;;MAGA,IAAI,CAACF,MAAL,EAAa;QACT,MAAM,IAAIG,cAAJ,CAAgB,qCAAhB,EAAuD,iBAAvD,EAA0E;UAC5ED,IAAI,EAAER,aAAa,CAACQ;QADwD,CAA1E,CAAN;MAGH;;MAED,MAAME,QAAQ,G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B,SAAd,CAAwBvB,EAAzB;MAH0B,CAAf,CAAxB;;MAKA,IAAIoB,SAAS,CAACI,MAAV,KAAqB,CAAzB,EAA4B;QACxB;MACH;;MAED,IAAI;QACA,MAAM,IAAAC,4DAAA,EAA8B;UAChC/B,OADgC;UAEhC0B,SAFgC;UAGhCxB,aAHgC;UAIhCiB,aAJgC;UAKhCE,QALgC;UAMhCP,gBANgC;UAOhCS;QAPgC,CAA9B,CAAN;MASH,CAVD,CAUE,OAAOS,EAAP,EAAW;QACT,MAAM,IAAIrB,cAAJ,CACD,8CADC,EAEF,uCAFE,EAGF;UACIW,UAAU,EAAED,QAAQ,CAACf,EADzB;UAEIY,eAAe,EAAEhB,aAAa,CAACI,EAFnC;UAGIC,eAHJ;UAIIO,gBAJJ;UAKIS,UALJ;UAMIU,KAAK,EAAE;YACHC,OAAO,EAAEF,EAAE,CAACE,OADT;YAEHC,IAAI,EAAEH,EAAE,CAACG,IAFN;YAGHC,IAAI,EAAEJ,EAAE,CAACI,IAHN;YAIHC,KAAK,EAAEL,EAAE,CAACK;UAJP;QANX,CAHE,CAAN;MAiBH;IACJ,CArGD;;IAuGA,IAAI;MACArC,OAAO,CAACsC,QAAR,CAAiBC,oBAAjB;MACA,MAAMlC,OAAO,EAAb;IACH,CAHD,CAGE,OAAO2B,EAAP,EAAW;MACT,MAAMA,EAAN;IACH,CALD,SAKU;MACNhC,OAAO,CAACsC,QAAR,CAAiBE,mBAAjB;IACH;EACJ,CAhHD;AAiHH,CAlHM"}
@@ -0,0 +1,8 @@
1
+ interface Params {
2
+ baseUrl?: string;
3
+ changeRequestId: string;
4
+ contentReviewId: string;
5
+ stepId: string;
6
+ }
7
+ export declare const createChangeRequestUrl: (params: Params) => string | null;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createChangeRequestUrl = void 0;
7
+
8
+ const createChangeRequestUrl = params => {
9
+ /**
10
+ * All variables must exist for URL to be created.
11
+ * We go through all vars and throw a log if it does not exist.
12
+ */
13
+ for (const key in params) {
14
+ if (!!key) {
15
+ continue;
16
+ }
17
+
18
+ console.log(`Missing variable "${key}", which we use to create a comment URL.`);
19
+ return null;
20
+ }
21
+
22
+ const {
23
+ baseUrl,
24
+ changeRequestId,
25
+ contentReviewId,
26
+ stepId
27
+ } = params;
28
+ return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;
29
+ };
30
+
31
+ exports.createChangeRequestUrl = createChangeRequestUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createChangeRequestUrl","params","key","console","log","baseUrl","changeRequestId","contentReviewId","stepId"],"sources":["changeRequestUrl.ts"],"sourcesContent":["interface Params {\n baseUrl?: string;\n changeRequestId: string;\n contentReviewId: string;\n stepId: string;\n}\nexport const createChangeRequestUrl = (params: Params) => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a comment URL.`);\n return null;\n }\n const { baseUrl, changeRequestId, contentReviewId, stepId } = params;\n\n return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;\n};\n"],"mappings":";;;;;;;AAMO,MAAMA,sBAAsB,GAAIC,MAAD,IAAoB;EACtD;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAX,IAAkBD,MAAlB,EAA0B;IACtB,IAAI,CAAC,CAACC,GAAN,EAAW;MACP;IACH;;IACDC,OAAO,CAACC,GAAR,CAAa,qBAAoBF,GAAI,0CAArC;IACA,OAAO,IAAP;EACH;;EACD,MAAM;IAAEG,OAAF;IAAWC,eAAX;IAA4BC,eAA5B;IAA6CC;EAA7C,IAAwDP,MAA9D;EAEA,OAAQ,GAAEI,OAAQ,wBAAuBE,eAAgB,IAAGC,MAAO,IAAGF,eAAgB,EAAtF;AACH,CAfM"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachCommentAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.attachCommentAfterCreate = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _utils = require("../../utils");
13
+
14
+ var _contentUrl = require("./contentUrl");
15
+
16
+ var _commentUrl = require("./commentUrl");
17
+
18
+ var _reviewers = require("./reviewers");
19
+
20
+ var _sendCommentNotification = require("./sendCommentNotification");
21
+
22
+ var _appUrl = require("./appUrl");
23
+
24
+ const attachCommentAfterCreate = context => {
25
+ context.apw.comment.onCommentAfterCreate.subscribe(async ({
26
+ comment
27
+ }) => {
28
+ const execute = async () => {
29
+ const changeRequest = await context.apw.changeRequest.get(comment.changeRequest);
30
+
31
+ if (!changeRequest) {
32
+ throw new _error.default("Missing change request.", "CHANGE_REQUEST_NOT_FOUND", {
33
+ changeRequest: comment.changeRequest,
34
+ comment: comment.id
35
+ });
36
+ }
37
+
38
+ const {
39
+ id: contentReviewId,
40
+ stepId
41
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
42
+
43
+ if (!stepId) {
44
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
45
+ step: changeRequest.step
46
+ });
47
+ }
48
+
49
+ const settings = await (0, _appUrl.getAppUrl)(context);
50
+
51
+ if (!settings) {
52
+ return;
53
+ }
54
+ /**
55
+ * We will check if we can create a comment url before we go digging further into the database.
56
+ */
57
+
58
+
59
+ const commentUrl = (0, _commentUrl.createCommentUrl)({
60
+ baseUrl: settings.appUrl,
61
+ changeRequestId: changeRequest.id,
62
+ contentReviewId,
63
+ stepId
64
+ });
65
+
66
+ if (!commentUrl) {
67
+ console.log("No comment url.");
68
+ return;
69
+ }
70
+ /**
71
+ * Let's see if content review exists.
72
+ */
73
+
74
+
75
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
76
+
77
+ if (!contentReview) {
78
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
79
+ contentReviewId
80
+ });
81
+ }
82
+ /**
83
+ * We go and check the workflow.
84
+ */
85
+
86
+
87
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
88
+
89
+ if (!workflow) {
90
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
91
+ workflowId: contentReview.workflowId
92
+ });
93
+ }
94
+
95
+ const contentUrl = (0, _contentUrl.createContentUrl)({
96
+ plugins: context.plugins,
97
+ baseUrl: settings.appUrl,
98
+ contentReview,
99
+ workflow
100
+ });
101
+
102
+ if (!contentUrl) {
103
+ console.log("No content url.");
104
+ return;
105
+ }
106
+
107
+ const reviewers = await (0, _reviewers.fetchReviewers)({
108
+ context,
109
+ workflow,
110
+ exclude: [comment.createdBy.id]
111
+ });
112
+
113
+ if (reviewers.length === 0) {
114
+ console.log("No reviewers to send the e-mail notification to.");
115
+ return;
116
+ }
117
+
118
+ try {
119
+ await (0, _sendCommentNotification.sendCommentNotification)({
120
+ context,
121
+ reviewers,
122
+ changeRequest,
123
+ contentReview,
124
+ workflow,
125
+ commentUrl,
126
+ contentUrl
127
+ });
128
+ } catch (ex) {
129
+ throw new _error.default(`Could not send comment notifications.`, "COMMENT_NOTIFICATIONS_NOT_SENT", {
130
+ commentId: comment.id,
131
+ workflowId: workflow.id,
132
+ changeRequestId: changeRequest.id,
133
+ contentReviewId,
134
+ commentUrl,
135
+ contentUrl,
136
+ error: {
137
+ message: ex.message,
138
+ code: ex.code,
139
+ data: ex.data,
140
+ stack: ex.stack
141
+ }
142
+ });
143
+ }
144
+ };
145
+
146
+ try {
147
+ context.security.disableAuthorization();
148
+ await execute();
149
+ } catch (ex) {
150
+ throw ex;
151
+ } finally {
152
+ context.security.enableAuthorization();
153
+ }
154
+ });
155
+ };
156
+
157
+ exports.attachCommentAfterCreate = attachCommentAfterCreate;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["attachCommentAfterCreate","context","apw","comment","onCommentAfterCreate","subscribe","execute","changeRequest","get","WebinyError","id","contentReviewId","stepId","extractContentReviewIdAndStep","step","settings","getAppUrl","commentUrl","createCommentUrl","baseUrl","appUrl","changeRequestId","console","log","contentReview","workflow","workflowId","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","length","sendCommentNotification","ex","commentId","error","message","code","data","stack","security","disableAuthorization","enableAuthorization"],"sources":["commentAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { createCommentUrl } from \"./commentUrl\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { sendCommentNotification } from \"./sendCommentNotification\";\nimport { getAppUrl } from \"~/plugins/hooks/notifications/appUrl\";\n\nexport const attachCommentAfterCreate = (context: ApwContext): void => {\n context.apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n const execute = async () => {\n const changeRequest = await context.apw.changeRequest.get(comment.changeRequest);\n if (!changeRequest) {\n throw new WebinyError(\"Missing change request.\", \"CHANGE_REQUEST_NOT_FOUND\", {\n changeRequest: comment.changeRequest,\n comment: comment.id\n });\n }\n\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 commentUrl = createCommentUrl({\n baseUrl: settings.appUrl,\n changeRequestId: changeRequest.id,\n contentReviewId,\n stepId\n });\n if (!commentUrl) {\n console.log(\"No comment url.\");\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 console.log(\"No content url.\");\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [comment.createdBy.id]\n });\n\n if (reviewers.length === 0) {\n console.log(\"No reviewers to send the e-mail notification to.\");\n return;\n }\n\n try {\n await sendCommentNotification({\n context,\n reviewers,\n changeRequest,\n contentReview,\n workflow,\n commentUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send comment notifications.`,\n \"COMMENT_NOTIFICATIONS_NOT_SENT\",\n {\n commentId: comment.id,\n workflowId: workflow.id,\n changeRequestId: changeRequest.id,\n contentReviewId,\n commentUrl,\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,wBAAwB,GAAIC,OAAD,IAA+B;EACnEA,OAAO,CAACC,GAAR,CAAYC,OAAZ,CAAoBC,oBAApB,CAAyCC,SAAzC,CAAmD,OAAO;IAAEF;EAAF,CAAP,KAAuB;IACtE,MAAMG,OAAO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KIM,UALJ;UAMIU,UANJ;UAOIW,KAAK,EAAE;YACHC,OAAO,EAAEH,EAAE,CAACG,OADT;YAEHC,IAAI,EAAEJ,EAAE,CAACI,IAFN;YAGHC,IAAI,EAAEL,EAAE,CAACK,IAHN;YAIHC,KAAK,EAAEN,EAAE,CAACM;UAJP;QAPX,CAHE,CAAN;MAkBH;IACJ,CAlHD;;IAoHA,IAAI;MACAzC,OAAO,CAAC0C,QAAR,CAAiBC,oBAAjB;MACA,MAAMtC,OAAO,EAAb;IACH,CAHD,CAGE,OAAO8B,EAAP,EAAW;MACT,MAAMA,EAAN;IACH,CALD,SAKU;MACNnC,OAAO,CAAC0C,QAAR,CAAiBE,mBAAjB;IACH;EACJ,CA7HD;AA8HH,CA/HM"}
@@ -0,0 +1,8 @@
1
+ interface CreateCommentUrlParams {
2
+ baseUrl?: string;
3
+ changeRequestId: string;
4
+ contentReviewId: string;
5
+ stepId: string;
6
+ }
7
+ export declare const createCommentUrl: (params: CreateCommentUrlParams) => string | null;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCommentUrl = void 0;
7
+
8
+ const createCommentUrl = params => {
9
+ /**
10
+ * All variables must exist for URL to be created.
11
+ * We go through all vars and throw a log if it does not exist.
12
+ */
13
+ for (const key in params) {
14
+ if (!!key) {
15
+ continue;
16
+ }
17
+
18
+ console.log(`Missing variable "${key}", which we use to create a comment URL.`);
19
+ return null;
20
+ }
21
+
22
+ const {
23
+ baseUrl,
24
+ changeRequestId,
25
+ contentReviewId,
26
+ stepId
27
+ } = params;
28
+ return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;
29
+ };
30
+
31
+ exports.createCommentUrl = createCommentUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createCommentUrl","params","key","console","log","baseUrl","changeRequestId","contentReviewId","stepId"],"sources":["commentUrl.ts"],"sourcesContent":["interface CreateCommentUrlParams {\n baseUrl?: string;\n changeRequestId: string;\n contentReviewId: string;\n stepId: string;\n}\nexport const createCommentUrl = (params: CreateCommentUrlParams): string | null => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a comment URL.`);\n return null;\n }\n const { baseUrl, changeRequestId, contentReviewId, stepId } = params;\n\n return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;\n};\n"],"mappings":";;;;;;;AAMO,MAAMA,gBAAgB,GAAIC,MAAD,IAAmD;EAC/E;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAX,IAAkBD,MAAlB,EAA0B;IACtB,IAAI,CAAC,CAACC,GAAN,EAAW;MACP;IACH;;IACDC,OAAO,CAACC,GAAR,CAAa,qBAAoBF,GAAI,0CAArC;IACA,OAAO,IAAP;EACH;;EACD,MAAM;IAAEG,OAAF;IAAWC,eAAX;IAA4BC,eAA5B;IAA6CC;EAA7C,IAAwDP,MAA9D;EAEA,OAAQ,GAAEI,OAAQ,wBAAuBE,eAAgB,IAAGC,MAAO,IAAGF,eAAgB,EAAtF;AACH,CAfM"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachContentReviewAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.attachContentReviewAfterCreate = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _appUrl = require("./appUrl");
13
+
14
+ var _contentReviewUrl = require("./contentReviewUrl");
15
+
16
+ var _contentUrl = require("./contentUrl");
17
+
18
+ var _reviewers = require("./reviewers");
19
+
20
+ var _sendContentReviewNotification = require("./sendContentReviewNotification");
21
+
22
+ const attachContentReviewAfterCreate = context => {
23
+ context.apw.contentReview.onContentReviewAfterCreate.subscribe(async ({
24
+ contentReview
25
+ }) => {
26
+ const execute = async () => {
27
+ if (contentReview.steps.length === 0) {
28
+ return;
29
+ }
30
+
31
+ const [step] = contentReview.steps;
32
+
33
+ if (!(step !== null && step !== void 0 && step.id)) {
34
+ return;
35
+ }
36
+
37
+ const settings = await (0, _appUrl.getAppUrl)(context);
38
+
39
+ if (!settings) {
40
+ return;
41
+ }
42
+
43
+ const contentReviewUrl = (0, _contentReviewUrl.createContentReviewUrl)({
44
+ baseUrl: settings.appUrl,
45
+ contentReviewId: contentReview.id,
46
+ stepId: step.id
47
+ });
48
+
49
+ if (!contentReviewUrl) {
50
+ return;
51
+ }
52
+ /**
53
+ * We go and check the workflow.
54
+ */
55
+
56
+
57
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
58
+
59
+ if (!workflow) {
60
+ throw new _error.default(`There is no workflow with Id "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
61
+ workflowId: contentReview.workflowId
62
+ });
63
+ }
64
+
65
+ const contentUrl = (0, _contentUrl.createContentUrl)({
66
+ plugins: context.plugins,
67
+ baseUrl: settings.appUrl,
68
+ contentReview,
69
+ workflow
70
+ });
71
+
72
+ if (!contentUrl) {
73
+ return;
74
+ }
75
+
76
+ const reviewers = await (0, _reviewers.fetchReviewers)({
77
+ context,
78
+ workflow,
79
+ exclude: [contentReview.createdBy.id]
80
+ });
81
+
82
+ if (reviewers.length === 0) {
83
+ return;
84
+ }
85
+
86
+ try {
87
+ await (0, _sendContentReviewNotification.sendContentReviewNotification)({
88
+ context,
89
+ reviewers,
90
+ contentReview,
91
+ workflow,
92
+ contentReviewUrl,
93
+ contentUrl
94
+ });
95
+ } catch (ex) {
96
+ throw new _error.default(`Could not send content review notifications.`, "CONTENT_REVIEW_NOTIFICATIONS_NOT_SENT", {
97
+ workflowId: workflow.id,
98
+ contentReviewId: contentReview.id,
99
+ contentReviewUrl,
100
+ contentUrl,
101
+ error: {
102
+ message: ex.message,
103
+ code: ex.code,
104
+ data: ex.data,
105
+ stack: ex.stack
106
+ }
107
+ });
108
+ }
109
+ };
110
+
111
+ try {
112
+ context.security.disableAuthorization();
113
+ await execute();
114
+ } catch (ex) {
115
+ throw ex;
116
+ } finally {
117
+ context.security.enableAuthorization();
118
+ }
119
+ });
120
+ };
121
+
122
+ exports.attachContentReviewAfterCreate = attachContentReviewAfterCreate;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["attachContentReviewAfterCreate","context","apw","contentReview","onContentReviewAfterCreate","subscribe","execute","steps","length","step","id","settings","getAppUrl","contentReviewUrl","createContentReviewUrl","baseUrl","appUrl","contentReviewId","stepId","workflow","get","workflowId","WebinyError","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","sendContentReviewNotification","ex","error","message","code","data","stack","security","disableAuthorization","enableAuthorization"],"sources":["contentReviewAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { getAppUrl } from \"./appUrl\";\nimport { createContentReviewUrl } from \"./contentReviewUrl\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { sendContentReviewNotification } from \"./sendContentReviewNotification\";\n\nexport const attachContentReviewAfterCreate = (context: ApwContext): void => {\n context.apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const execute = async () => {\n if (contentReview.steps.length === 0) {\n return;\n }\n const [step] = contentReview.steps;\n if (!step?.id) {\n return;\n }\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n\n const contentReviewUrl = createContentReviewUrl({\n baseUrl: settings.appUrl,\n contentReviewId: contentReview.id,\n stepId: step.id\n });\n if (!contentReviewUrl) {\n return;\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 Id \"${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: [contentReview.createdBy.id]\n });\n if (reviewers.length === 0) {\n return;\n }\n\n try {\n await sendContentReviewNotification({\n context,\n reviewers,\n contentReview,\n workflow,\n contentReviewUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send content review notifications.`,\n \"CONTENT_REVIEW_NOTIFICATIONS_NOT_SENT\",\n {\n workflowId: workflow.id,\n contentReviewId: contentReview.id,\n contentReviewUrl,\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;;AAEO,MAAMA,8BAA8B,GAAIC,OAAD,IAA+B;EACzEA,OAAO,CAACC,GAAR,CAAYC,aAAZ,CAA0BC,0BAA1B,CAAqDC,SAArD,CAA+D,OAAO;IAAEF;EAAF,CAAP,KAA6B;IACxF,MAAMG,OAAO,GAAG,YAAY;MACxB,IAAIH,aAAa,CAACI,KAAd,CAAoBC,MAApB,KAA+B,CAAnC,EAAsC;QAClC;MACH;;MACD,MAAM,CAACC,IAAD,IAASN,aAAa,CAACI,KAA7B;;MACA,IAAI,EAACE,IAAD,aAACA,IAAD,eAACA,IAAI,CAAEC,EAAP,CAAJ,EAAe;QACX;MACH;;MACD,MAAMC,QAAQ,GAAG,MAAM,IAAAC,iBAAA,EAAUX,OAAV,CAAvB;;MACA,IAAI,CAACU,QAAL,EAAe;QACX;MACH;;MAED,MAAME,gBAAgB,GAAG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AAQ,CAACT,EADzB;UAEIO,eAAe,EAAEd,aAAa,CAACO,EAFnC;UAGIG,gBAHJ;UAIIU,UAJJ;UAKIS,KAAK,EAAE;YACHC,OAAO,EAAEF,EAAE,CAACE,OADT;YAEHC,IAAI,EAAEH,EAAE,CAACG,IAFN;YAGHC,IAAI,EAAEJ,EAAE,CAACI,IAHN;YAIHC,KAAK,EAAEL,EAAE,CAACK;UAJP;QALX,CAHE,CAAN;MAgBH;IACJ,CAlFD;;IAoFA,IAAI;MACAnC,OAAO,CAACoC,QAAR,CAAiBC,oBAAjB;MACA,MAAMhC,OAAO,EAAb;IACH,CAHD,CAGE,OAAOyB,EAAP,EAAW;MACT,MAAMA,EAAN;IACH,CALD,SAKU;MACN9B,OAAO,CAACoC,QAAR,CAAiBE,mBAAjB;IACH;EACJ,CA7FD;AA8FH,CA/FM"}
@@ -0,0 +1,7 @@
1
+ interface Params {
2
+ baseUrl?: string;
3
+ contentReviewId: string;
4
+ stepId: string;
5
+ }
6
+ export declare const createContentReviewUrl: (params: Params) => string | null;
7
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createContentReviewUrl = void 0;
7
+
8
+ const createContentReviewUrl = params => {
9
+ /**
10
+ * All variables must exist for URL to be created.
11
+ * We go through all vars and throw a log if it does not exist.
12
+ */
13
+ for (const key in params) {
14
+ if (!!key) {
15
+ continue;
16
+ }
17
+
18
+ console.log(`Missing variable "${key}", which we use to create a comment URL.`);
19
+ return null;
20
+ }
21
+
22
+ const {
23
+ baseUrl,
24
+ contentReviewId,
25
+ stepId
26
+ } = params;
27
+ return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}`;
28
+ };
29
+
30
+ exports.createContentReviewUrl = createContentReviewUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContentReviewUrl","params","key","console","log","baseUrl","contentReviewId","stepId"],"sources":["contentReviewUrl.ts"],"sourcesContent":["interface Params {\n baseUrl?: string;\n contentReviewId: string;\n stepId: string;\n}\nexport const createContentReviewUrl = (params: Params) => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a comment URL.`);\n return null;\n }\n const { baseUrl, contentReviewId, stepId } = params;\n\n return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}`;\n};\n"],"mappings":";;;;;;;AAKO,MAAMA,sBAAsB,GAAIC,MAAD,IAAoB;EACtD;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAX,IAAkBD,MAAlB,EAA0B;IACtB,IAAI,CAAC,CAACC,GAAN,EAAW;MACP;IACH;;IACDC,OAAO,CAACC,GAAR,CAAa,qBAAoBF,GAAI,0CAArC;IACA,OAAO,IAAP;EACH;;EACD,MAAM;IAAEG,OAAF;IAAWC,eAAX;IAA4BC;EAA5B,IAAuCN,MAA7C;EAEA,OAAQ,GAAEI,OAAQ,wBAAuBC,eAAgB,IAAGC,MAAO,EAAnE;AACH,CAfM"}
@@ -0,0 +1,7 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { ApwContentUrlPluginCbParams } from "../../../ApwContentUrlPlugin";
3
+ interface Params extends ApwContentUrlPluginCbParams {
4
+ plugins: PluginsContainer;
5
+ }
6
+ export declare const createContentUrl: (params: Params) => string | null;
7
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createContentUrl = void 0;
7
+
8
+ var _ApwContentUrlPlugin = require("../../../ApwContentUrlPlugin");
9
+
10
+ const createContentUrl = params => {
11
+ const {
12
+ plugins,
13
+ contentReview
14
+ } = params;
15
+ const {
16
+ type: contentType
17
+ } = contentReview.content;
18
+ const [contentUrlPlugin] = plugins.byType(_ApwContentUrlPlugin.ApwContentUrlPlugin.type).filter(plugin => {
19
+ return plugin.canUse(contentType);
20
+ }).reverse();
21
+
22
+ if (!contentUrlPlugin) {
23
+ return null;
24
+ }
25
+
26
+ return contentUrlPlugin.create(params);
27
+ };
28
+
29
+ exports.createContentUrl = createContentUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContentUrl","params","plugins","contentReview","type","contentType","content","contentUrlPlugin","byType","ApwContentUrlPlugin","filter","plugin","canUse","reverse","create"],"sources":["contentUrl.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { ApwContentUrlPlugin, ApwContentUrlPluginCbParams } from \"~/ApwContentUrlPlugin\";\n\ninterface Params extends ApwContentUrlPluginCbParams {\n plugins: PluginsContainer;\n}\n\nexport const createContentUrl = (params: Params): string | null => {\n const { plugins, contentReview } = params;\n\n const { type: contentType } = contentReview.content;\n\n const [contentUrlPlugin] = plugins\n .byType<ApwContentUrlPlugin>(ApwContentUrlPlugin.type)\n .filter(plugin => {\n return plugin.canUse(contentType);\n })\n .reverse();\n if (!contentUrlPlugin) {\n return null;\n }\n\n return contentUrlPlugin.create(params);\n};\n"],"mappings":";;;;;;;AACA;;AAMO,MAAMA,gBAAgB,GAAIC,MAAD,IAAmC;EAC/D,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAA6BF,MAAnC;EAEA,MAAM;IAAEG,IAAI,EAAEC;EAAR,IAAwBF,aAAa,CAACG,OAA5C;EAEA,MAAM,CAACC,gBAAD,IAAqBL,OAAO,CAC7BM,MADsB,CACMC,wCAAA,CAAoBL,IAD1B,EAEtBM,MAFsB,CAEfC,MAAM,IAAI;IACd,OAAOA,MAAM,CAACC,MAAP,CAAcP,WAAd,CAAP;EACH,CAJsB,EAKtBQ,OALsB,EAA3B;;EAMA,IAAI,CAACN,gBAAL,EAAuB;IACnB,OAAO,IAAP;EACH;;EAED,OAAOA,gBAAgB,CAACO,MAAjB,CAAwBb,MAAxB,CAAP;AACH,CAhBM"}