@webiny/api-apw 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60e968001a

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 (206) 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 +2 -3
  30. package/index.js +8 -10
  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.d.ts +0 -1
  61. package/plugins/context.js +3 -20
  62. package/plugins/context.js.map +1 -1
  63. package/plugins/graphql/changeRequest.gql.js +1 -1
  64. package/plugins/graphql/comment.gql.js +1 -1
  65. package/plugins/graphql/contentReview.gql.js +4 -4
  66. package/plugins/graphql/contentReview.gql.js.map +1 -1
  67. package/plugins/graphql/reviewer.gql.js +3 -1
  68. package/plugins/graphql/reviewer.gql.js.map +1 -1
  69. package/plugins/graphql/workflow.gql.js +1 -1
  70. package/plugins/graphql.js +3 -3
  71. package/plugins/graphql.js.map +1 -1
  72. package/plugins/hooks/createReviewerFromIdentity.js +28 -8
  73. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  74. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -1
  75. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  76. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -1
  77. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  78. package/plugins/hooks/index.js +6 -0
  79. package/plugins/hooks/index.js.map +1 -1
  80. package/plugins/hooks/initializeContentReviewSteps.js +5 -8
  81. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  82. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  83. package/plugins/hooks/initializeNotifications.js +20 -0
  84. package/plugins/hooks/initializeNotifications.js.map +1 -0
  85. package/plugins/hooks/listContentReviews.d.ts +10 -0
  86. package/plugins/hooks/listContentReviews.js +68 -0
  87. package/plugins/hooks/listContentReviews.js.map +1 -0
  88. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  89. package/plugins/hooks/notifications/appUrl.js +22 -0
  90. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  91. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  92. package/plugins/hooks/notifications/changeRequestAfterCreate.js +144 -0
  93. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  94. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  95. package/plugins/hooks/notifications/changeRequestUrl.js +31 -0
  96. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  97. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  98. package/plugins/hooks/notifications/commentAfterCreate.js +157 -0
  99. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  100. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  101. package/plugins/hooks/notifications/commentUrl.js +31 -0
  102. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  103. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  104. package/plugins/hooks/notifications/contentReviewAfterCreate.js +122 -0
  105. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  106. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  107. package/plugins/hooks/notifications/contentReviewUrl.js +30 -0
  108. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  109. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  110. package/plugins/hooks/notifications/contentUrl.js +29 -0
  111. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  112. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  113. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +25 -0
  114. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  115. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  116. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +25 -0
  117. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  118. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  119. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +25 -0
  120. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  121. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  122. package/plugins/hooks/notifications/reviewers.js +51 -0
  123. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  124. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  125. package/plugins/hooks/notifications/sendChangeRequestNotification.js +52 -0
  126. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  127. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  128. package/plugins/hooks/notifications/sendCommentNotification.js +52 -0
  129. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  130. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  131. package/plugins/hooks/notifications/sendContentReviewNotification.js +52 -0
  132. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  133. package/plugins/hooks/updatePendingChangeRequests.js +7 -11
  134. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  135. package/plugins/hooks/updateTotalComments.js +14 -18
  136. package/plugins/hooks/updateTotalComments.js.map +1 -1
  137. package/plugins/hooks/validateChangeRequest.js +30 -5
  138. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  139. package/plugins/hooks/validateComment.js +14 -4
  140. package/plugins/hooks/validateComment.js.map +1 -1
  141. package/plugins/hooks/validateContentReview.js +2 -2
  142. package/plugins/hooks/validateContentReview.js.map +1 -1
  143. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +1 -1
  144. package/plugins/pageBuilder/index.js +9 -1
  145. package/plugins/pageBuilder/index.js.map +1 -1
  146. package/plugins/pageBuilder/linkContentReviewToPage.js +41 -29
  147. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  148. package/plugins/pageBuilder/linkWorkflowToPage.js +18 -6
  149. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  150. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  151. package/plugins/pageBuilder/notifications/changeRequestNotification.js +35 -0
  152. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  153. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  154. package/plugins/pageBuilder/notifications/commentNotification.js +35 -0
  155. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  156. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  157. package/plugins/pageBuilder/notifications/contentReviewNotification.js +35 -0
  158. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  159. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  160. package/plugins/pageBuilder/notifications/contentUrl.js +53 -0
  161. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  162. package/plugins/pageBuilder/triggerContentReview.js +3 -3
  163. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  164. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -14
  165. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  166. package/plugins/pageBuilder/utils.js +1 -1
  167. package/plugins/pageBuilder/utils.js.map +1 -1
  168. package/plugins/utils.d.ts +1 -1
  169. package/plugins/utils.js +4 -14
  170. package/plugins/utils.js.map +1 -1
  171. package/scheduler/createScheduleActionMethods.js +17 -14
  172. package/scheduler/createScheduleActionMethods.js.map +1 -1
  173. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +1 -1
  174. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -1
  175. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +1 -1
  176. package/scheduler/handlers/scheduleAction/index.js +8 -9
  177. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  178. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +5 -9
  179. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  180. package/scheduler/handlers/utils.js +1 -1
  181. package/storageOperations/changeRequestStorageOperations.js +5 -9
  182. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  183. package/storageOperations/commentStorageOperations.js +4 -8
  184. package/storageOperations/commentStorageOperations.js.map +1 -1
  185. package/storageOperations/contentReviewStorageOperations.js +5 -9
  186. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  187. package/storageOperations/index.js +5 -9
  188. package/storageOperations/index.js.map +1 -1
  189. package/storageOperations/models/contentModelPluginFactory.js +3 -7
  190. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  191. package/storageOperations/models/contentReview.model.js +6 -5
  192. package/storageOperations/models/contentReview.model.js.map +1 -1
  193. package/storageOperations/models/index.js +1 -1
  194. package/storageOperations/models/reviewer.model.js +18 -2
  195. package/storageOperations/models/reviewer.model.js.map +1 -1
  196. package/storageOperations/models/utils.js +3 -2
  197. package/storageOperations/models/utils.js.map +1 -1
  198. package/storageOperations/reviewerStorageOperations.js +18 -14
  199. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  200. package/storageOperations/workflowStorageOperations.js +8 -12
  201. package/storageOperations/workflowStorageOperations.js.map +1 -1
  202. package/types.d.ts +99 -84
  203. package/types.js.map +1 -1
  204. package/utils/errors.js +1 -1
  205. package/utils/fieldResolver.js +3 -9
  206. package/utils/fieldResolver.js.map +1 -1
@@ -1,24 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.updateTotalCommentsCount = exports.updateLatestCommentId = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
14
- 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; }
15
-
16
- 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; }
17
-
18
14
  const updateTotalCommentsCount = ({
19
15
  apw
20
16
  }) => {
21
- apw.comment.onAfterCommentDelete.subscribe(async ({
17
+ apw.comment.onCommentAfterDelete.subscribe(async ({
22
18
  comment
23
19
  }) => {
24
20
  const {
@@ -38,8 +34,8 @@ const updateTotalCommentsCount = ({
38
34
  contentReviewMethods: apw.contentReview,
39
35
  id,
40
36
  getNewContentReviewData: data => {
41
- return _objectSpread(_objectSpread({}, data), {}, {
42
- steps: (0, _utils.updateContentReviewStep)(data.steps, stepId, step => _objectSpread(_objectSpread({}, step), {}, {
37
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
38
+ steps: (0, _utils.updateContentReviewStep)(data.steps, stepId, step => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
43
39
  totalComments: step.totalComments - 1
44
40
  }))
45
41
  });
@@ -47,7 +43,7 @@ const updateTotalCommentsCount = ({
47
43
  });
48
44
  }
49
45
  });
50
- apw.comment.onAfterCommentCreate.subscribe(async ({
46
+ apw.comment.onCommentAfterCreate.subscribe(async ({
51
47
  comment
52
48
  }) => {
53
49
  /**
@@ -62,8 +58,8 @@ const updateTotalCommentsCount = ({
62
58
  contentReviewMethods: apw.contentReview,
63
59
  id,
64
60
  getNewContentReviewData: data => {
65
- return _objectSpread(_objectSpread({}, data), {}, {
66
- steps: (0, _utils.updateContentReviewStep)(data.steps, stepId, step => _objectSpread(_objectSpread({}, step), {}, {
61
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
62
+ steps: (0, _utils.updateContentReviewStep)(data.steps, stepId, step => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
67
63
  totalComments: step.totalComments + 1
68
64
  }))
69
65
  });
@@ -77,7 +73,7 @@ exports.updateTotalCommentsCount = updateTotalCommentsCount;
77
73
  const updateLatestCommentId = ({
78
74
  apw
79
75
  }) => {
80
- apw.comment.onAfterCommentCreate.subscribe(async ({
76
+ apw.comment.onCommentAfterCreate.subscribe(async ({
81
77
  comment
82
78
  }) => {
83
79
  /**
@@ -91,13 +87,13 @@ const updateLatestCommentId = ({
91
87
  contentReviewMethods: apw.contentReview,
92
88
  id,
93
89
  getNewContentReviewData: contentReview => {
94
- return _objectSpread(_objectSpread({}, contentReview), {}, {
90
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview), {}, {
95
91
  latestCommentId: comment.id
96
92
  });
97
93
  }
98
94
  });
99
95
  });
100
- apw.comment.onAfterCommentUpdate.subscribe(async ({
96
+ apw.comment.onCommentAfterUpdate.subscribe(async ({
101
97
  comment
102
98
  }) => {
103
99
  /**
@@ -111,13 +107,13 @@ const updateLatestCommentId = ({
111
107
  contentReviewMethods: apw.contentReview,
112
108
  id,
113
109
  getNewContentReviewData: contentReview => {
114
- return _objectSpread(_objectSpread({}, contentReview), {}, {
110
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview), {}, {
115
111
  latestCommentId: comment.id
116
112
  });
117
113
  }
118
114
  });
119
115
  });
120
- apw.comment.onAfterCommentDelete.subscribe(async ({
116
+ apw.comment.onCommentAfterDelete.subscribe(async ({
121
117
  comment
122
118
  }) => {
123
119
  /**
@@ -145,7 +141,7 @@ const updateLatestCommentId = ({
145
141
  contentReviewMethods: apw.contentReview,
146
142
  id,
147
143
  getNewContentReviewData: contentReview => {
148
- return _objectSpread(_objectSpread({}, contentReview), {}, {
144
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview), {}, {
149
145
  latestCommentId: latestComment ? latestComment.id : null
150
146
  });
151
147
  }
@@ -1 +1 @@
1
- {"version":3,"names":["updateTotalCommentsCount","apw","comment","onAfterCommentDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onAfterCommentCreate","updateLatestCommentId","latestCommentId","onAfterCommentUpdate","safelyGetContentReview","latestComment","list","where","changeRequest","sort"],"sources":["updateTotalComments.ts"],"sourcesContent":["import { LifeCycleHookCallbackParams } from \"~/types\";\nimport {\n extractContentReviewIdAndStep,\n safelyGetContentReview,\n updateContentReview,\n updateContentReviewStep\n} from \"../utils\";\n\nexport const updateTotalCommentsCount = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onAfterCommentDelete.subscribe(async ({ comment }) => {\n const { step } = comment;\n /**\n * After a \"comment\" is deleted, decrement the \"totalComments\" count\n * in the corresponding step of the content review entry.\n */\n if (step) {\n const { id, stepId } = extractContentReviewIdAndStep(step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments - 1\n }))\n };\n }\n });\n }\n });\n\n apw.comment.onAfterCommentCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, increment the \"totalComments\" count\n * of the corresponding step in the content review entry.\n */\n const { id, stepId } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments + 1\n }))\n };\n }\n });\n });\n};\n\nexport const updateLatestCommentId = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onAfterCommentCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onAfterCommentUpdate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onAfterCommentDelete.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n const contentReview = await safelyGetContentReview({\n id,\n contentReviewMethods: apw.contentReview\n });\n\n if (contentReview && contentReview.latestCommentId === comment.id) {\n const [[latestComment]] = await apw.comment.list({\n where: { changeRequest: { id: comment.changeRequest } },\n sort: [\"createdOn_DESC\"]\n });\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: latestComment ? latestComment.id : null\n };\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;;;;;AAOO,MAAMA,wBAAwB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAC3FA,GAAG,CAACC,OAAJ,CAAYC,oBAAZ,CAAiCC,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D,MAAM;MAAEG;IAAF,IAAWH,OAAjB;IACA;AACR;AACA;AACA;;IACQ,IAAIG,IAAJ,EAAU;MACN,MAAM;QAAEC,EAAF;QAAMC;MAAN,IAAiB,IAAAC,oCAAA,EAA8BH,IAA9B,CAAvB;MAEA,MAAM,IAAAI,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAEC,IAAI,IAAI;UAC7B,uCACOA,IADP;YAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAAI,CAACC,KAA7B,EAAoCP,MAApC,EAA4CF,IAAI,oCAChDA,IADgD;cAEnDW,aAAa,EAAEX,IAAI,CAACW,aAAL,GAAqB;YAFe,EAAhD;UAFX;QAOH;MAXqB,CAApB,CAAN;IAaH;EACJ,CAvBD;EAyBAf,GAAG,CAACC,OAAJ,CAAYe,oBAAZ,CAAiCb,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB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CAACU,aADJ;MAEtBL,EAFsB;MAGtBM,uBAAuB,EAAED,aAAa,IAAI;QACtC,uCACOA,aADP;UAEIQ,eAAe,EAAEjB,OAAO,CAACI;QAF7B;MAIH;IARqB,CAApB,CAAN;EAUH,CAjBD;EAmBAL,GAAG,CAACC,OAAJ,CAAYC,oBAAZ,CAAiCC,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D;AACR;AACA;AACA;IACQ,MAAM;MAAEI;IAAF,IAAS,IAAAE,oCAAA,EAA8BN,OAAO,CAACG,IAAtC,CAAf;IAEA,MAAMM,aAAa,GAAG,MAAM,IAAAU,6BAAA,EAAuB;MAC/Cf,EAD+C;MAE/CI,oBAAoB,EAAET,GAAG,CAACU;IAFqB,CAAvB,CAA5B;;IAKA,IAAIA,aAAa,IAAIA,aAAa,CAACQ,eAAd,KAAkCjB,OAAO,CAACI,EAA/D,EAAmE;MAC/D,MAAM,CAAC,CAACgB,aAAD,CAAD,IAAoB,MAAMrB,GAAG,CAACC,OAAJ,CAAYqB,IAAZ,CAAiB;QAC7CC,KAAK,EAAE;UAAEC,aAAa,EAAE;YAAEnB,EAAE,EAAEJ,OAAO,CAACuB;UAAd;QAAjB,CADsC;QAE7CC,IAAI,EAAE,CAAC,gBAAD;MAFuC,CAAjB,CAAhC;MAKA,MAAM,IAAAjB,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAED,aAAa,IAAI;UACtC,uCACOA,aADP;YAEIQ,eAAe,EAAEG,aAAa,GAAGA,aAAa,CAAChB,EAAjB,GAAsB;UAFxD;QAIH;MARqB,CAApB,CAAN;IAUH;EACJ,CA7BD;AA8BH,CArEM"}
1
+ {"version":3,"names":["updateTotalCommentsCount","apw","comment","onCommentAfterDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onCommentAfterCreate","updateLatestCommentId","latestCommentId","onCommentAfterUpdate","safelyGetContentReview","latestComment","list","where","changeRequest","sort"],"sources":["updateTotalComments.ts"],"sourcesContent":["import { LifeCycleHookCallbackParams } from \"~/types\";\nimport {\n extractContentReviewIdAndStep,\n safelyGetContentReview,\n updateContentReview,\n updateContentReviewStep\n} from \"../utils\";\n\nexport const updateTotalCommentsCount = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n const { step } = comment;\n /**\n * After a \"comment\" is deleted, decrement the \"totalComments\" count\n * in the corresponding step of the content review entry.\n */\n if (step) {\n const { id, stepId } = extractContentReviewIdAndStep(step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments - 1\n }))\n };\n }\n });\n }\n });\n\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, increment the \"totalComments\" count\n * of the corresponding step in the content review entry.\n */\n const { id, stepId } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments + 1\n }))\n };\n }\n });\n });\n};\n\nexport const updateLatestCommentId = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterUpdate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n const contentReview = await safelyGetContentReview({\n id,\n contentReviewMethods: apw.contentReview\n });\n\n if (contentReview && contentReview.latestCommentId === comment.id) {\n const [[latestComment]] = await apw.comment.list({\n where: { changeRequest: { id: comment.changeRequest } },\n sort: [\"createdOn_DESC\"]\n });\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: latestComment ? latestComment.id : null\n };\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAOO,MAAMA,wBAAwB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAC3FA,GAAG,CAACC,OAAJ,CAAYC,oBAAZ,CAAiCC,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D,MAAM;MAAEG;IAAF,IAAWH,OAAjB;IACA;AACR;AACA;AACA;;IACQ,IAAIG,IAAJ,EAAU;MACN,MAAM;QAAEC,EAAF;QAAMC;MAAN,IAAiB,IAAAC,oCAAA,EAA8BH,IAA9B,CAAvB;MAEA,MAAM,IAAAI,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAEC,IAAI,IAAI;UAC7B,mEACOA,IADP;YAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAAI,CAACC,KAA7B,EAAoCP,MAApC,EAA4CF,IAAI,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AjB,GAAsB;UAFxD;QAIH;MARqB,CAApB,CAAN;IAUH;EACJ,CA7BD;AA8BH,CArEM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,10 +11,14 @@ var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
12
  var _handlerGraphql = require("@webiny/handler-graphql");
13
13
 
14
+ var _utils = require("../utils");
15
+
16
+ var _utils2 = require("@webiny/utils");
17
+
14
18
  const validateChangeRequest = ({
15
19
  apw
16
20
  }) => {
17
- apw.changeRequest.onBeforeChangeRequestCreate.subscribe(async ({
21
+ apw.changeRequest.onChangeRequestBeforeCreate.subscribe(async ({
18
22
  input
19
23
  }) => {
20
24
  const {
@@ -24,7 +28,14 @@ const validateChangeRequest = ({
24
28
  * We need step to be in a particular format i.e. "contentReviewId#version#stepId"
25
29
  */
26
30
 
27
- const [entryId, version, stepId] = step.split("#");
31
+ const {
32
+ id: revisionId,
33
+ stepId
34
+ } = (0, _utils.extractContentReviewIdAndStep)(step);
35
+ const {
36
+ id: entryId,
37
+ version
38
+ } = (0, _utils2.parseIdentifier)(revisionId);
28
39
 
29
40
  if (!entryId || !version || !stepId) {
30
41
  throw new _error.default(`The step property in input is not properly formatted.`, "MALFORMED_CHANGE_REQUEST_STEP", {
@@ -36,8 +47,22 @@ const validateChangeRequest = ({
36
47
  */
37
48
 
38
49
 
39
- const revisionId = `${entryId}#${version}`;
40
- const contentReview = await apw.contentReview.get(revisionId);
50
+ let contentReview = undefined;
51
+
52
+ try {
53
+ contentReview = await apw.contentReview.get(revisionId);
54
+ } catch (ex) {
55
+ /**
56
+ * There is no need to output the log if this is the test environment.
57
+ */
58
+ if (process.env.NODE_ENV !== "test") {
59
+ console.log({
60
+ message: ex.message,
61
+ code: ex.data,
62
+ data: ex.data
63
+ });
64
+ }
65
+ }
41
66
 
42
67
  if (!contentReview) {
43
68
  throw new _handlerGraphql.NotFoundError(`Unable to found "ContentReview" with given id "${revisionId}"`);
@@ -1 +1 @@
1
- {"version":3,"names":["validateChangeRequest","apw","changeRequest","onBeforeChangeRequestCreate","subscribe","input","step","entryId","version","stepId","split","WebinyError","revisionId","contentReview","get","NotFoundError","steps","currentStep","find","id","signOffProvidedOn"],"sources":["validateChangeRequest.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateChangeRequest = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onBeforeChangeRequestCreate.subscribe(async ({ input }) => {\n const { step } = input;\n /**\n * We need step to be in a particular format i.e. \"contentReviewId#version#stepId\"\n */\n const [entryId, version, stepId] = step.split(\"#\");\n if (!entryId || !version || !stepId) {\n throw new WebinyError(\n `The step property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_STEP\",\n {\n step\n }\n );\n }\n /**\n * Check whether a contentReview entry exists with provided id.\n */\n const revisionId = `${entryId}#${version}`;\n\n const contentReview = await apw.contentReview.get(revisionId);\n if (!contentReview) {\n throw new NotFoundError(\n `Unable to found \"ContentReview\" with given id \"${revisionId}\"`\n );\n }\n /**\n * Don't allow \"change request\" creation once the sign-off has been provided.\n */\n const { steps } = contentReview;\n const currentStep = steps.find(step => step.id === stepId);\n\n if (currentStep && currentStep.signOffProvidedOn) {\n throw new WebinyError(\n `Please retract the sign-off before opening a new change request.`,\n \"SIGN_OFF_PROVIDED\",\n {\n step: currentStep,\n stepId: stepId\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAGO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAWD,KAAjB;IACA;AACR;AACA;;IACQ,MAAM,CAACE,OAAD,EAAUC,OAAV,EAAmBC,MAAnB,IAA6BH,IAAI,CAACI,KAAL,CAAW,GAAX,CAAnC;;IACA,IAAI,CAACH,OAAD,IAAY,CAACC,OAAb,IAAwB,CAACC,MAA7B,EAAqC;MACjC,MAAM,IAAIE,cAAJ,CACD,uDADC,EAEF,+BAFE,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;IACD;AACR;AACA;;;IACQ,MAAMM,UAAU,GAAI,GAAEL,OAAQ,IAAGC,OAAQ,EAAzC;IAEA,MAAMK,aAAa,GAAG,MAAMZ,GAAG,CAACY,aAAJ,CAAkBC,GAAlB,CAAsBF,UAAtB,CAA5B;;IACA,IAAI,CAACC,aAAL,EAAoB;MAChB,MAAM,IAAIE,6BAAJ,CACD,kDAAiDH,UAAW,GAD3D,CAAN;IAGH;IACD;AACR;AACA;;;IACQ,MAAM;MAAEI;IAAF,IAAYH,aAAlB;IACA,MAAMI,WAAW,GAAGD,KAAK,CAACE,IAAN,CAAWZ,IAAI,IAAIA,IAAI,CAACa,EAAL,KAAYV,MAA/B,CAApB;;IAEA,IAAIQ,WAAW,IAAIA,WAAW,CAACG,iBAA/B,EAAkD;MAC9C,MAAM,IAAIT,cAAJ,CACD,kEADC,EAEF,mBAFE,EAGF;QACIL,IAAI,EAAEW,WADV;QAEIR,MAAM,EAAEA;MAFZ,CAHE,CAAN;IAQH;EACJ,CA1CD;AA2CH,CA5CM"}
1
+ {"version":3,"names":["validateChangeRequest","apw","changeRequest","onChangeRequestBeforeCreate","subscribe","input","step","id","revisionId","stepId","extractContentReviewIdAndStep","entryId","version","parseIdentifier","WebinyError","contentReview","undefined","get","ex","process","env","NODE_ENV","console","log","message","code","data","NotFoundError","steps","currentStep","find","signOffProvidedOn"],"sources":["validateChangeRequest.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ApwContentReview, LifeCycleHookCallbackParams } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\nexport const validateChangeRequest = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onChangeRequestBeforeCreate.subscribe(async ({ input }) => {\n const { step } = input;\n /**\n * We need step to be in a particular format i.e. \"contentReviewId#version#stepId\"\n */\n const { id: revisionId, stepId } = extractContentReviewIdAndStep(step);\n\n const { id: entryId, version } = parseIdentifier(revisionId);\n if (!entryId || !version || !stepId) {\n throw new WebinyError(\n `The step property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_STEP\",\n {\n step\n }\n );\n }\n /**\n * Check whether a contentReview entry exists with provided id.\n */\n let contentReview: ApwContentReview | undefined = undefined;\n try {\n contentReview = await apw.contentReview.get(revisionId);\n } catch (ex) {\n /**\n * There is no need to output the log if this is the test environment.\n */\n if (process.env.NODE_ENV !== \"test\") {\n console.log({\n message: ex.message,\n code: ex.data,\n data: ex.data\n });\n }\n }\n if (!contentReview) {\n throw new NotFoundError(\n `Unable to found \"ContentReview\" with given id \"${revisionId}\"`\n );\n }\n /**\n * Don't allow \"change request\" creation once the sign-off has been provided.\n */\n const { steps } = contentReview;\n const currentStep = steps.find(step => step.id === stepId);\n\n if (currentStep && currentStep.signOffProvidedOn) {\n throw new WebinyError(\n `Please retract the sign-off before opening a new change request.`,\n \"SIGN_OFF_PROVIDED\",\n {\n step: currentStep,\n stepId: stepId\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAEO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,K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EAAEuB,WADV;QAEIpB,MAAM,EAAEA;MAFZ,CAHE,CAAN;IAQH;EACJ,CAxDD;AAyDH,CA1DM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -9,10 +9,12 @@ exports.validateComment = void 0;
9
9
 
10
10
  var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
+ var _utils = require("@webiny/utils");
13
+
12
14
  const validateComment = ({
13
15
  apw
14
16
  }) => {
15
- apw.comment.onBeforeCommentCreate.subscribe(async ({
17
+ apw.comment.onCommentBeforeCreate.subscribe(async ({
16
18
  input
17
19
  }) => {
18
20
  const {
@@ -22,9 +24,17 @@ const validateComment = ({
22
24
  * We need changeRequest to be in a particular format i.e. "contentReviewUniqueId#version"
23
25
  */
24
26
 
25
- const [entryId, version] = changeRequestId.split("#");
27
+ let result;
28
+
29
+ try {
30
+ result = (0, _utils.parseIdentifier)(changeRequestId);
26
31
 
27
- if (!entryId || !version) {
32
+ if (!result) {
33
+ throw new _error.default("Could not parse changeRequestId.", "MALFORMED_CHANGE_REQUEST_ID", {
34
+ changeRequestId
35
+ });
36
+ }
37
+ } catch (ex) {
28
38
  throw new _error.default(`The"changeRequest" property in input is not properly formatted.`, "MALFORMED_CHANGE_REQUEST_ID", {
29
39
  input
30
40
  });
@@ -1 +1 @@
1
- {"version":3,"names":["validateComment","apw","comment","onBeforeCommentCreate","subscribe","input","changeRequest","changeRequestId","entryId","version","split","WebinyError","get","step"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onBeforeCommentCreate.subscribe(async ({ input }) => {\n const { changeRequest: changeRequestId } = input;\n /**\n * We need changeRequest to be in a particular format i.e. \"contentReviewUniqueId#version\"\n */\n const [entryId, version] = changeRequestId.split(\"#\");\n if (!entryId || !version) {\n throw new WebinyError(\n `The\"changeRequest\" property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n input\n }\n );\n }\n\n /**\n * Assign value for \"step\" field from \"changeRequest\".\n */\n const changeRequest = await apw.changeRequest.get(changeRequestId);\n if (!changeRequest) {\n return;\n }\n input.step = changeRequest.step;\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAGO,MAAMA,eAAe,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAClFA,GAAG,CAACC,OAAJ,CAAYC,qBAAZ,CAAkCC,SAAlC,CAA4C,OAAO;IAAEC;EAAF,CAAP,KAAqB;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAjB,IAAqCF,KAA3C;IACA;AACR;AACA;;IACQ,MAAM,CAACG,OAAD,EAAUC,OAAV,IAAqBF,eAAe,CAACG,KAAhB,CAAsB,GAAtB,CAA3B;;IACA,IAAI,CAACF,OAAD,IAAY,CAACC,OAAjB,EAA0B;MACtB,MAAM,IAAIE,cAAJ,CACD,iEADC,EAEF,6BAFE,EAGF;QACIN;MADJ,CAHE,CAAN;IAOH;IAED;AACR;AACA;;;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAJ,CAAkBM,GAAlB,CAAsBL,eAAtB,CAA5B;;IACA,IAAI,CAACD,aAAL,EAAoB;MAChB;IACH;;IACDD,KAAK,CAACQ,IAAN,GAAaP,aAAa,CAACO,IAA3B;EACH,CAxBD;AAyBH,CA1BM"}
1
+ {"version":3,"names":["validateComment","apw","comment","onCommentBeforeCreate","subscribe","input","changeRequest","changeRequestId","result","parseIdentifier","WebinyError","ex","get","step"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\nimport { parseIdentifier, ParseIdentifierResult } from \"@webiny/utils\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentBeforeCreate.subscribe(async ({ input }) => {\n const { changeRequest: changeRequestId } = input;\n /**\n * We need changeRequest to be in a particular format i.e. \"contentReviewUniqueId#version\"\n */\n let result: ParseIdentifierResult;\n try {\n result = parseIdentifier(changeRequestId);\n if (!result) {\n throw new WebinyError(\n \"Could not parse changeRequestId.\",\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n changeRequestId\n }\n );\n }\n } catch (ex) {\n throw new WebinyError(\n `The\"changeRequest\" property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n input\n }\n );\n }\n\n /**\n * Assign value for \"step\" field from \"changeRequest\".\n */\n const changeRequest = await apw.changeRequest.get(changeRequestId);\n if (!changeRequest) {\n return;\n }\n input.step = changeRequest.step;\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAEO,MAAMA,eAAe,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAClFA,GAAG,CAACC,OAAJ,CAAYC,qBAAZ,CAAkCC,SAAlC,CAA4C,OAAO;IAAEC;EAAF,CAAP,KAAqB;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAjB,IAAqCF,KAA3C;IACA;AACR;AACA;;IACQ,IAAIG,MAAJ;;IACA,IAAI;MACAA,MAAM,GAAG,IAAAC,sBAAA,EAAgBF,eAAhB,CAAT;;MACA,IAAI,CAACC,MAAL,EAAa;QACT,MAAM,IAAIE,cAAJ,CACF,kCADE,EAEF,6BAFE,EAGF;UACIH;QADJ,CAHE,CAAN;MAOH;IACJ,CAXD,CAWE,OAAOI,EAAP,EAAW;MACT,MAAM,IAAID,cAAJ,CACD,iEADC,EAEF,6BAFE,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;IAED;AACR;AACA;;;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAJ,CAAkBM,GAAlB,CAAsBL,eAAtB,CAA5B;;IACA,IAAI,CAACD,aAAL,EAAoB;MAChB;IACH;;IACDD,KAAK,CAACQ,IAAN,GAAaP,aAAa,CAACO,IAA3B;EACH,CAnCD;AAoCH,CArCM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -12,7 +12,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
12
12
  const validateContentReview = ({
13
13
  apw
14
14
  }) => {
15
- apw.contentReview.onBeforeContentReviewCreate.subscribe(async ({
15
+ apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({
16
16
  input
17
17
  }) => {
18
18
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["validateContentReview","apw","contentReview","onBeforeContentReviewCreate","subscribe","input","content","contentReviewId","isReviewRequired","WebinyError"],"sources":["validateContentReview.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateContentReview = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onBeforeContentReviewCreate.subscribe(async ({ input }) => {\n const { content } = input;\n /**\n * Check whether a contentReview already exists for provided content.\n */\n const { contentReviewId } = await apw.contentReview.isReviewRequired(content);\n if (contentReviewId) {\n throw new WebinyError(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n content\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAGO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAcD,KAApB;IACA;AACR;AACA;;IACQ,MAAM;MAAEE;IAAF,IAAsB,MAAMN,GAAG,CAACC,aAAJ,CAAkBM,gBAAlB,CAAmCF,OAAnC,CAAlC;;IACA,IAAIC,eAAJ,EAAqB;MACjB,MAAM,IAAIE,cAAJ,CACD,4DADC,EAEF,sBAFE,EAGF;QACIF,eADJ;QAEID;MAFJ,CAHE,CAAN;IAQH;EACJ,CAhBD;AAiBH,CAlBM"}
1
+ {"version":3,"names":["validateContentReview","apw","contentReview","onContentReviewBeforeCreate","subscribe","input","content","contentReviewId","isReviewRequired","WebinyError"],"sources":["validateContentReview.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateContentReview = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { content } = input;\n /**\n * Check whether a contentReview already exists for provided content.\n */\n const { contentReviewId } = await apw.contentReview.isReviewRequired(content);\n if (contentReviewId) {\n throw new WebinyError(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n content\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAGO,MAAMA,qBAAqB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EACxFA,GAAG,CAACC,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC;IAAF,IAAcD,KAApB;IACA;AACR;AACA;;IACQ,MAAM;MAAEE;IAAF,IAAsB,MAAMN,GAAG,CAACC,aAAJ,CAAkBM,gBAAlB,CAAmCF,OAAnC,CAAlC;;IACA,IAAIC,eAAJ,EAAqB;MACjB,MAAM,IAAIE,cAAJ,CACD,4DADC,EAEF,sBAFE,EAGF;QACIF,eADJ;QAEID;MAFJ,CAHE,CAAN;IAQH;EACJ,CAhBD;AAiBH,CAlBM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -15,6 +15,14 @@ var _linkWorkflowToPage = require("./linkWorkflowToPage");
15
15
 
16
16
  var _PageApwSettingsGetterPlugin = require("./PageApwSettingsGetterPlugin");
17
17
 
18
+ var _commentNotification = require("./notifications/commentNotification");
19
+
20
+ var _contentUrl = require("./notifications/contentUrl");
21
+
22
+ var _changeRequestNotification = require("./notifications/changeRequestNotification");
23
+
24
+ var _contentReviewNotification = require("./notifications/contentReviewNotification");
25
+
18
26
  const apwPageBuilderHooks = params => {
19
27
  const {
20
28
  pageBuilder,
@@ -22,7 +30,7 @@ const apwPageBuilderHooks = params => {
22
30
  security,
23
31
  plugins
24
32
  } = params;
25
- plugins.register(new _PageApwSettingsGetterPlugin.PageApwSettingsGetterPlugin());
33
+ plugins.register([new _PageApwSettingsGetterPlugin.PageApwSettingsGetterPlugin(), (0, _commentNotification.createCommentNotification)(), (0, _changeRequestNotification.createChangeRequestNotification)(), (0, _contentUrl.createContentUrlPlugin)(), (0, _contentReviewNotification.createContentReviewNotification)()]);
26
34
  (0, _triggerContentReview.triggerContentReview)({
27
35
  apw,
28
36
  pageBuilder
@@ -1 +1 @@
1
- {"version":3,"names":["apwPageBuilderHooks","params","pageBuilder","apw","security","plugins","register","PageApwSettingsGetterPlugin","triggerContentReview","linkContentReviewToPage","updateContentReviewStatus","linkWorkflowToPage"],"sources":["index.ts"],"sourcesContent":["import { Security } from \"@webiny/api-security/types\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\nimport { AdvancedPublishingWorkflow } from \"~/types\";\nimport { triggerContentReview } from \"./triggerContentReview\";\nimport { linkContentReviewToPage } from \"./linkContentReviewToPage\";\nimport { updateContentReviewStatus } from \"./updateContentReviewStatus\";\nimport { linkWorkflowToPage } from \"./linkWorkflowToPage\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { PageApwSettingsGetterPlugin } from \"~/plugins/pageBuilder/PageApwSettingsGetterPlugin\";\n\nexport interface ApwPageBuilderPluginsParams {\n pageBuilder: PageBuilderContextObject;\n apw: AdvancedPublishingWorkflow;\n security: Security;\n plugins: PluginsContainer;\n}\n\nexport const apwPageBuilderHooks = (params: ApwPageBuilderPluginsParams) => {\n const { pageBuilder, apw, security, plugins } = params;\n\n plugins.register(new PageApwSettingsGetterPlugin());\n\n triggerContentReview({\n apw,\n pageBuilder\n });\n linkContentReviewToPage({\n apw,\n pageBuilder\n });\n updateContentReviewStatus({\n apw,\n pageBuilder,\n security\n });\n linkWorkflowToPage({\n apw,\n pageBuilder\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAEA;;AASO,MAAMA,mBAAmB,GAAIC,MAAD,IAAyC;EACxE,MAAM;IAAEC,WAAF;IAAeC,GAAf;IAAoBC,QAApB;IAA8BC;EAA9B,IAA0CJ,MAAhD;EAEAI,OAAO,CAACC,QAAR,CAAiB,IAAIC,wDAAJ,EAAjB;EAEA,IAAAC,0CAAA,EAAqB;IACjBL,GADiB;IAEjBD;EAFiB,CAArB;EAIA,IAAAO,gDAAA,EAAwB;IACpBN,GADoB;IAEpBD;EAFoB,CAAxB;EAIA,IAAAQ,oDAAA,EAA0B;IACtBP,GADsB;IAEtBD,WAFsB;IAGtBE;EAHsB,CAA1B;EAKA,IAAAO,sCAAA,EAAmB;IACfR,GADe;IAEfD;EAFe,CAAnB;AAIH,CAtBM"}
1
+ {"version":3,"names":["apwPageBuilderHooks","params","pageBuilder","apw","security","plugins","register","PageApwSettingsGetterPlugin","createCommentNotification","createChangeRequestNotification","createContentUrlPlugin","createContentReviewNotification","triggerContentReview","linkContentReviewToPage","updateContentReviewStatus","linkWorkflowToPage"],"sources":["index.ts"],"sourcesContent":["import { Security } from \"@webiny/api-security/types\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\nimport { AdvancedPublishingWorkflow } from \"~/types\";\nimport { triggerContentReview } from \"./triggerContentReview\";\nimport { linkContentReviewToPage } from \"./linkContentReviewToPage\";\nimport { updateContentReviewStatus } from \"./updateContentReviewStatus\";\nimport { linkWorkflowToPage } from \"./linkWorkflowToPage\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { PageApwSettingsGetterPlugin } from \"~/plugins/pageBuilder/PageApwSettingsGetterPlugin\";\nimport { createCommentNotification } from \"./notifications/commentNotification\";\nimport { createContentUrlPlugin } from \"./notifications/contentUrl\";\nimport { createChangeRequestNotification } from \"./notifications/changeRequestNotification\";\nimport { createContentReviewNotification } from \"./notifications/contentReviewNotification\";\n\nexport interface ApwPageBuilderPluginsParams {\n pageBuilder: PageBuilderContextObject;\n apw: AdvancedPublishingWorkflow;\n security: Security;\n plugins: PluginsContainer;\n}\n\nexport const apwPageBuilderHooks = (params: ApwPageBuilderPluginsParams) => {\n const { pageBuilder, apw, security, plugins } = params;\n\n plugins.register([\n new PageApwSettingsGetterPlugin(),\n createCommentNotification(),\n createChangeRequestNotification(),\n createContentUrlPlugin(),\n createContentReviewNotification()\n ]);\n\n triggerContentReview({\n apw,\n pageBuilder\n });\n linkContentReviewToPage({\n apw,\n pageBuilder\n });\n updateContentReviewStatus({\n apw,\n pageBuilder,\n security\n });\n linkWorkflowToPage({\n apw,\n pageBuilder\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AASO,MAAMA,mBAAmB,GAAIC,MAAD,IAAyC;EACxE,MAAM;IAAEC,WAAF;IAAeC,GAAf;IAAoBC,QAApB;IAA8BC;EAA9B,IAA0CJ,MAAhD;EAEAI,OAAO,CAACC,QAAR,CAAiB,CACb,IAAIC,wDAAJ,EADa,EAEb,IAAAC,8CAAA,GAFa,EAGb,IAAAC,0DAAA,GAHa,EAIb,IAAAC,kCAAA,GAJa,EAKb,IAAAC,0DAAA,GALa,CAAjB;EAQA,IAAAC,0CAAA,EAAqB;IACjBT,GADiB;IAEjBD;EAFiB,CAArB;EAIA,IAAAW,gDAAA,EAAwB;IACpBV,GADoB;IAEpBD;EAFoB,CAAxB;EAIA,IAAAY,oDAAA,EAA0B;IACtBX,GADsB;IAEtBD,WAFsB;IAGtBE;EAHsB,CAA1B;EAKA,IAAAW,sCAAA,EAAmB;IACfZ,GADe;IAEfD;EAFe,CAAnB;AAIH,CA5BM"}
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.linkContentReviewToPage = void 0;
9
9
 
10
- var _set = _interopRequireDefault(require("lodash/set"));
11
-
12
- var _get = _interopRequireDefault(require("lodash/get"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
11
 
14
12
  var _error = _interopRequireDefault(require("@webiny/error"));
15
13
 
@@ -22,46 +20,60 @@ const linkContentReviewToPage = params => {
22
20
  apw,
23
21
  pageBuilder
24
22
  } = params;
25
- apw.contentReview.onAfterContentReviewCreate.subscribe(async ({
23
+ apw.contentReview.onContentReviewAfterCreate.subscribe(async ({
26
24
  contentReview
27
25
  }) => {
28
26
  const {
29
27
  content
30
28
  } = contentReview;
31
29
 
32
- if (content.type === _types.ApwContentTypes.PAGE) {
33
- await (0, _utils.updatePageSettings)({
34
- getPage: pageBuilder.getPage,
35
- updatePage: pageBuilder.updatePage,
36
- uniquePageId: content.id,
37
- getNewSettings: settings => {
38
- return (0, _set.default)(settings, "apw.contentReviewId", contentReview.id);
39
- }
40
- });
30
+ if (content.type !== _types.ApwContentTypes.PAGE) {
31
+ return;
41
32
  }
33
+
34
+ await (0, _utils.updatePageSettings)({
35
+ getPage: pageBuilder.getPage,
36
+ updatePage: pageBuilder.updatePage,
37
+ uniquePageId: content.id,
38
+ getNewSettings: settings => {
39
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
40
+ apw: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings.apw || {}), {}, {
41
+ contentReviewId: contentReview.id
42
+ })
43
+ });
44
+ }
45
+ });
42
46
  });
43
- apw.contentReview.onAfterContentReviewDelete.subscribe(async ({
47
+ apw.contentReview.onContentReviewAfterDelete.subscribe(async ({
44
48
  contentReview
45
49
  }) => {
46
50
  const {
47
51
  content
48
52
  } = contentReview;
49
53
 
50
- if (content.type === _types.ApwContentTypes.PAGE) {
51
- await (0, _utils.updatePageSettings)({
52
- getPage: pageBuilder.getPage,
53
- updatePage: pageBuilder.updatePage,
54
- uniquePageId: content.id,
55
- getNewSettings: settings => {
56
- return (0, _set.default)(settings, "apw.contentReviewId", null);
57
- }
58
- });
54
+ if (content.type !== _types.ApwContentTypes.PAGE) {
55
+ return;
59
56
  }
57
+
58
+ await (0, _utils.updatePageSettings)({
59
+ getPage: pageBuilder.getPage,
60
+ updatePage: pageBuilder.updatePage,
61
+ uniquePageId: content.id,
62
+ getNewSettings: settings => {
63
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
64
+ apw: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings.apw || {}), {}, {
65
+ contentReviewId: null
66
+ })
67
+ });
68
+ }
69
+ });
60
70
  });
61
- pageBuilder.onBeforePageDelete.subscribe(async ({
71
+ pageBuilder.onPageBeforeDelete.subscribe(async ({
62
72
  page
63
73
  }) => {
64
- const contentReviewId = (0, _get.default)(page, "settings.apw.contentReviewId");
74
+ var _page$settings, _page$settings$apw;
75
+
76
+ const contentReviewId = (_page$settings = page.settings) === null || _page$settings === void 0 ? void 0 : (_page$settings$apw = _page$settings.apw) === null || _page$settings$apw === void 0 ? void 0 : _page$settings$apw.contentReviewId;
65
77
 
66
78
  if (!contentReviewId) {
67
79
  return;
@@ -71,13 +83,13 @@ const linkContentReviewToPage = params => {
71
83
 
72
84
  try {
73
85
  contentReview = await apw.contentReview.get(contentReviewId);
74
- } catch (e) {
86
+ } catch (ex) {
75
87
  /**
76
88
  * We're handling the case whereby "contentReviewId" is still linked to page;
77
89
  * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.
78
90
  */
79
- if (e.code !== "NOT_FOUND") {
80
- throw e;
91
+ if (ex.code !== "NOT_FOUND") {
92
+ throw ex;
81
93
  }
82
94
  }
83
95
 
@@ -1 +1 @@
1
- {"version":3,"names":["linkContentReviewToPage","params","apw","pageBuilder","contentReview","onAfterContentReviewCreate","subscribe","content","type","ApwContentTypes","PAGE","updatePageSettings","getPage","updatePage","uniquePageId","id","getNewSettings","settings","set","onAfterContentReviewDelete","onBeforePageDelete","page","contentReviewId","get","e","code","Error"],"sources":["linkContentReviewToPage.ts"],"sourcesContent":["import set from \"lodash/set\";\nimport get from \"lodash/get\";\nimport Error from \"@webiny/error\";\nimport { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { updatePageSettings } from \"./utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface LinkContentReviewToPageParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const linkContentReviewToPage = (params: LinkContentReviewToPageParams) => {\n const { apw, pageBuilder } = params;\n\n apw.contentReview.onAfterContentReviewCreate.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type === ApwContentTypes.PAGE) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return set(settings, \"apw.contentReviewId\", contentReview.id);\n }\n });\n }\n });\n\n apw.contentReview.onAfterContentReviewDelete.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type === ApwContentTypes.PAGE) {\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return set(settings, \"apw.contentReviewId\", null);\n }\n });\n }\n });\n\n pageBuilder.onBeforePageDelete.subscribe(async ({ page }) => {\n const contentReviewId = get(page, \"settings.apw.contentReviewId\");\n if (!contentReviewId) {\n return;\n }\n\n let contentReview;\n try {\n contentReview = await apw.contentReview.get(contentReviewId);\n } catch (e) {\n /**\n * We're handling the case whereby \"contentReviewId\" is still linked to page;\n * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.\n */\n if (e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n if (contentReview) {\n throw new Error(\n `Cannot delete the page because a peer review has been requested. Please delete the review first.`,\n \"CANNOT_DELETE_REVIEW_EXIST\",\n {\n contentReviewId,\n page\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAuBF,MAA7B;EAEAC,GAAG,CAACE,aAAJ,CAAkBC,0BAAlB,CAA6CC,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF,MAAM;MAAEG;IAAF,IAAcH,aAApB;;IAEA,IAAIG,OAAO,CAACC,IAAR,KAAiBC,sBAAA,CAAgBC,IAArC,EAA2C;MACvC,MAAM,IAAAC,yBAAA,EAAmB;QACrBC,OAAO,EAAET,WAAW,CAACS,OADA;QAErBC,UAAU,EAAEV,WAAW,CAACU,UAFH;QAGrBC,YAAY,EAAEP,OAAO,CAACQ,EAHD;QAIrBC,cAAc,EAAEC,QAAQ,IAAI;UACxB,OAAO,IAAAC,YAAA,EAAID,QAAJ,EAAc,qBAAd,EAAqCb,aAAa,CAACW,EAAnD,CAAP;QACH;MANoB,CAAnB,CAAN;IAQH;EACJ,CAbD;EAeAb,GAAG,CAACE,aAAJ,CAAkBe,0BAAlB,CAA6Cb,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF,MAAM;MAAEG;IAAF,IAAcH,aAApB;;IAEA,IAAIG,OAAO,CAACC,IAAR,KAAiBC,sBAAA,CAAgBC,IAArC,EAA2C;MACvC,MAAM,IAAAC,yBAAA,EAAmB;QACrBC,OAAO,EAAET,WAAW,CAACS,OADA;QAErBC,UAAU,EAAEV,WAAW,CAACU,UAFH;QAGrBC,YAAY,EAAEP,OAAO,CAACQ,EAHD;QAIrBC,cAAc,EAAEC,QAAQ,IAAI;UACxB,OAAO,IAAAC,YAAA,EAAID,QAAJ,EAAc,qBAAd,EAAqC,IAArC,CAAP;QACH;MANoB,CAAnB,CAAN;IAQH;EACJ,CAbD;EAeAd,WAAW,CAACiB,kBAAZ,CAA+Bd,SAA/B,CAAyC,OAAO;IAAEe;EAAF,CAAP,KAAoB;IACzD,MAAMC,eAAe,GAAG,IAAAC,YAAA,EAAIF,IAAJ,EAAU,8BAAV,CAAxB;;IACA,IAAI,CAACC,eAAL,EAAsB;MAClB;IACH;;IAED,IAAIlB,aAAJ;;IACA,IAAI;MACAA,aAAa,GAAG,MAAMF,GAAG,CAACE,aAAJ,CAAkBmB,GAAlB,CAAsBD,eAAtB,CAAtB;IACH,CAFD,CAEE,OAAOE,CAAP,EAAU;MACR;AACZ;AACA;AACA;MACY,IAAIA,CAAC,CAACC,IAAF,KAAW,WAAf,EAA4B;QACxB,MAAMD,CAAN;MACH;IACJ;;IAED,IAAIpB,aAAJ,EAAmB;MACf,MAAM,IAAIsB,cAAJ,CACD,kGADC,EAEF,4BAFE,EAGF;QACIJ,eADJ;QAEID;MAFJ,CAHE,CAAN;IAQH;EACJ,CA7BD;AA8BH,CA/DM"}
1
+ {"version":3,"names":["linkContentReviewToPage","params","apw","pageBuilder","contentReview","onContentReviewAfterCreate","subscribe","content","type","ApwContentTypes","PAGE","updatePageSettings","getPage","updatePage","uniquePageId","id","getNewSettings","settings","contentReviewId","onContentReviewAfterDelete","onPageBeforeDelete","page","get","ex","code","Error"],"sources":["linkContentReviewToPage.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { updatePageSettings } from \"./utils\";\nimport { PageBuilderContextObject } from \"@webiny/api-page-builder/graphql/types\";\n\ninterface LinkContentReviewToPageParams {\n apw: AdvancedPublishingWorkflow;\n pageBuilder: PageBuilderContextObject;\n}\n\nexport const linkContentReviewToPage = (params: LinkContentReviewToPageParams) => {\n const { apw, pageBuilder } = params;\n\n apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type !== ApwContentTypes.PAGE) {\n return;\n }\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return {\n ...settings,\n apw: {\n ...(settings.apw || {}),\n contentReviewId: contentReview.id\n }\n };\n }\n });\n });\n\n apw.contentReview.onContentReviewAfterDelete.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type !== ApwContentTypes.PAGE) {\n return;\n }\n await updatePageSettings({\n getPage: pageBuilder.getPage,\n updatePage: pageBuilder.updatePage,\n uniquePageId: content.id,\n getNewSettings: settings => {\n return {\n ...settings,\n apw: {\n ...(settings.apw || {}),\n contentReviewId: null\n }\n };\n }\n });\n });\n\n pageBuilder.onPageBeforeDelete.subscribe(async ({ page }) => {\n const contentReviewId = page.settings?.apw?.contentReviewId;\n if (!contentReviewId) {\n return;\n }\n\n let contentReview;\n try {\n contentReview = await apw.contentReview.get(contentReviewId);\n } catch (ex) {\n /**\n * We're handling the case whereby \"contentReviewId\" is still linked to page;\n * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.\n */\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n\n if (contentReview) {\n throw new Error(\n `Cannot delete the page because a peer review has been requested. Please delete the review first.`,\n \"CANNOT_DELETE_REVIEW_EXIST\",\n {\n contentReviewId,\n page\n }\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAuBF,MAA7B;EAEAC,GAAG,CAACE,aAAJ,CAAkBC,0BAAlB,CAA6CC,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF,MAAM;MAAEG;IAAF,IAAcH,aAApB;;IAEA,IAAIG,OAAO,CAACC,IAAR,KAAiBC,sBAAA,CAAgBC,IAArC,EAA2C;MACvC;IACH;;IACD,MAAM,IAAAC,yBAAA,EAAmB;MACrBC,OAAO,EAAET,WAAW,CAACS,OADA;MAErBC,UAAU,EAAEV,WAAW,CAACU,UAFH;MAGrBC,YAAY,EAAEP,OAAO,CAACQ,EAHD;MAIrBC,cAAc,EAAEC,QAAQ,IAAI;QACxB,mEACOA,QADP;UAEIf,GAAG,8DACKe,QAAQ,CAACf,GAAT,IAAgB,EADrB;YAECgB,eAAe,EAAEd,aAAa,CAACW;UAFhC;QAFP;MAOH;IAZoB,CAAnB,CAAN;EAcH,CApBD;EAsBAb,GAAG,CAACE,aAAJ,CAAkBe,0BAAlB,CAA6Cb,SAA7C,CAAuD,OAAO;IAAEF;EAAF,CAAP,KAA6B;IAChF,MAAM;MAAEG;IAAF,IAAcH,aAApB;;IAEA,IAAIG,OAAO,CAACC,IAAR,KAAiBC,sBAAA,CAAgBC,IAArC,EAA2C;MACvC;IACH;;IACD,MAAM,IAAAC,yBAAA,EAAmB;MACrBC,OAAO,EAAET,WAAW,CAACS,OADA;MAErBC,UAAU,EAAEV,WAAW,CAACU,UAFH;MAGrBC,YAAY,EAAEP,OAAO,CAACQ,EAHD;MAIrBC,cAAc,EAAEC,QAAQ,IAAI;QACxB,mEACOA,QADP;UAEIf,GAAG,8DACKe,QAAQ,CAACf,GAAT,IAAgB,EADrB;YAECgB,eAAe,EAAE;UAFlB;QAFP;MAOH;IAZoB,CAAnB,CAAN;EAcH,CApBD;EAsBAf,WAAW,CAACiB,kBAAZ,CAA+Bd,SAA/B,CAAyC,OAAO;IAAEe;EAAF,CAAP,KAAoB;IAAA;;IACzD,MAAMH,eAAe,qBAAGG,IAAI,CAACJ,QAAR,yEAAG,eAAef,GAAlB,uDAAG,mBAAoBgB,eAA5C;;IACA,IAAI,CAACA,eAAL,EAAsB;MAClB;IACH;;IAED,IAAId,aAAJ;;IACA,IAAI;MACAA,aAAa,GAAG,MAAMF,GAAG,CAACE,aAAJ,CAAkBkB,GAAlB,CAAsBJ,eAAtB,CAAtB;IACH,CAFD,CAEE,OAAOK,EAAP,EAAW;MACT;AACZ;AACA;AACA;MACY,IAAIA,EAAE,CAACC,IAAH,KAAY,WAAhB,EAA6B;QACzB,MAAMD,EAAN;MACH;IACJ;;IAED,IAAInB,aAAJ,EAAmB;MACf,MAAM,IAAIqB,cAAJ,CACD,kGADC,EAEF,4BAFE,EAGF;QACIP,eADJ;QAEIG;MAFJ,CAHE,CAAN;IAQH;EACJ,CA7BD;AA8BH,CA7EM"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,6 +11,8 @@ var _get = _interopRequireDefault(require("lodash/get"));
11
11
 
12
12
  var _set = _interopRequireDefault(require("lodash/set"));
13
13
 
14
+ var _types = require("../../types");
15
+
14
16
  var _utils = require("./utils");
15
17
 
16
18
  const linkWorkflowToPage = params => {
@@ -18,7 +20,7 @@ const linkWorkflowToPage = params => {
18
20
  apw,
19
21
  pageBuilder
20
22
  } = params;
21
- pageBuilder.onBeforePageCreate.subscribe(async ({
23
+ pageBuilder.onPageBeforeCreate.subscribe(async ({
22
24
  page
23
25
  }) => {
24
26
  await (0, _utils.assignWorkflowToPage)({
@@ -26,7 +28,7 @@ const linkWorkflowToPage = params => {
26
28
  page
27
29
  });
28
30
  });
29
- pageBuilder.onBeforePageCreateFrom.subscribe(async params => {
31
+ pageBuilder.onPageBeforeCreateFrom.subscribe(async params => {
30
32
  const {
31
33
  page,
32
34
  original
@@ -62,7 +64,7 @@ const linkWorkflowToPage = params => {
62
64
  page
63
65
  });
64
66
  });
65
- pageBuilder.onBeforePageUpdate.subscribe(async params => {
67
+ pageBuilder.onPageBeforeUpdate.subscribe(async params => {
66
68
  const {
67
69
  page,
68
70
  original
@@ -98,16 +100,21 @@ const linkWorkflowToPage = params => {
98
100
  * Link created workflow to associated pages.
99
101
  */
100
102
 
101
- apw.workflow.onAfterWorkflowCreate.subscribe(async ({
103
+ apw.workflow.onWorkflowAfterCreate.subscribe(async ({
102
104
  workflow
103
105
  }) => {
104
106
  const {
105
107
  scope
106
108
  } = workflow;
109
+
110
+ if (workflow.app !== _types.ApwWorkflowApplications.PB) {
111
+ return;
112
+ }
107
113
  /**
108
114
  * If the workflow has pages in it's scope, we'll link that workflow for each of those pages.
109
115
  */
110
116
 
117
+
111
118
  if ((0, _utils.hasPages)(workflow) === false) {
112
119
  return;
113
120
  }
@@ -129,13 +136,18 @@ const linkWorkflowToPage = params => {
129
136
  * Link updated workflow to associated pages.
130
137
  */
131
138
 
132
- apw.workflow.onAfterWorkflowUpdate.subscribe(async ({
139
+ apw.workflow.onWorkflowAfterUpdate.subscribe(async ({
133
140
  workflow,
134
141
  original
135
142
  }) => {
136
143
  const {
137
144
  scope
138
145
  } = workflow;
146
+
147
+ if (workflow.app !== _types.ApwWorkflowApplications.PB) {
148
+ return;
149
+ }
150
+
139
151
  const {
140
152
  scope: prevScope
141
153
  } = original;