@webiny/api-apw 0.0.0-unstable.1e66d121db

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 (232) hide show
  1. package/ContentApwSettingsPlugin.d.ts +10 -0
  2. package/ContentApwSettingsPlugin.js +17 -0
  3. package/ContentApwSettingsPlugin.js.map +1 -0
  4. package/LICENSE +21 -0
  5. package/README.md +34 -0
  6. package/crud/createChangeRequestMethods.d.ts +2 -0
  7. package/crud/createChangeRequestMethods.js +98 -0
  8. package/crud/createChangeRequestMethods.js.map +1 -0
  9. package/crud/createCommentMethods.d.ts +2 -0
  10. package/crud/createCommentMethods.js +99 -0
  11. package/crud/createCommentMethods.js.map +1 -0
  12. package/crud/createContentReviewMethods.d.ts +10 -0
  13. package/crud/createContentReviewMethods.js +552 -0
  14. package/crud/createContentReviewMethods.js.map +1 -0
  15. package/crud/createReviewerMethods.d.ts +2 -0
  16. package/crud/createReviewerMethods.js +99 -0
  17. package/crud/createReviewerMethods.js.map +1 -0
  18. package/crud/createWorkflowMethods.d.ts +2 -0
  19. package/crud/createWorkflowMethods.js +118 -0
  20. package/crud/createWorkflowMethods.js.map +1 -0
  21. package/crud/index.d.ts +2 -0
  22. package/crud/index.js +96 -0
  23. package/crud/index.js.map +1 -0
  24. package/crud/utils.d.ts +21 -0
  25. package/crud/utils.js +138 -0
  26. package/crud/utils.js.map +1 -0
  27. package/index.d.ts +4 -0
  28. package/index.js +36 -0
  29. package/index.js.map +1 -0
  30. package/package.json +76 -0
  31. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +10 -0
  32. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +51 -0
  33. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -0
  34. package/plugins/cms/README.md +49 -0
  35. package/plugins/cms/apwEntryPlugins.d.ts +8 -0
  36. package/plugins/cms/apwEntryPlugins.js +46 -0
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -0
  38. package/plugins/cms/index.d.ts +12 -0
  39. package/plugins/cms/index.js +37 -0
  40. package/plugins/cms/index.js.map +1 -0
  41. package/plugins/cms/linkContentReviewToEntry.d.ts +8 -0
  42. package/plugins/cms/linkContentReviewToEntry.js +108 -0
  43. package/plugins/cms/linkContentReviewToEntry.js.map +1 -0
  44. package/plugins/cms/linkWorkflowToEntry.d.ts +8 -0
  45. package/plugins/cms/linkWorkflowToEntry.js +166 -0
  46. package/plugins/cms/linkWorkflowToEntry.js.map +1 -0
  47. package/plugins/cms/triggerContentReview.d.ts +8 -0
  48. package/plugins/cms/triggerContentReview.js +59 -0
  49. package/plugins/cms/triggerContentReview.js.map +1 -0
  50. package/plugins/cms/updateContentReviewStatus.d.ts +10 -0
  51. package/plugins/cms/updateContentReviewStatus.js +97 -0
  52. package/plugins/cms/updateContentReviewStatus.js.map +1 -0
  53. package/plugins/cms/utils.d.ts +27 -0
  54. package/plugins/cms/utils.js +207 -0
  55. package/plugins/cms/utils.js.map +1 -0
  56. package/plugins/context.d.ts +5 -0
  57. package/plugins/context.js +146 -0
  58. package/plugins/context.js.map +1 -0
  59. package/plugins/graphql/changeRequest.gql.d.ts +4 -0
  60. package/plugins/graphql/changeRequest.gql.js +155 -0
  61. package/plugins/graphql/changeRequest.gql.js.map +1 -0
  62. package/plugins/graphql/comment.gql.d.ts +4 -0
  63. package/plugins/graphql/comment.gql.js +160 -0
  64. package/plugins/graphql/comment.gql.js.map +1 -0
  65. package/plugins/graphql/contentReview.gql.d.ts +4 -0
  66. package/plugins/graphql/contentReview.gql.js +382 -0
  67. package/plugins/graphql/contentReview.gql.js.map +1 -0
  68. package/plugins/graphql/reviewer.gql.d.ts +4 -0
  69. package/plugins/graphql/reviewer.gql.js +114 -0
  70. package/plugins/graphql/reviewer.gql.js.map +1 -0
  71. package/plugins/graphql/workflow.gql.d.ts +4 -0
  72. package/plugins/graphql/workflow.gql.js +205 -0
  73. package/plugins/graphql/workflow.gql.js.map +1 -0
  74. package/plugins/graphql.d.ts +4 -0
  75. package/plugins/graphql.js +95 -0
  76. package/plugins/graphql.js.map +1 -0
  77. package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
  78. package/plugins/hooks/createReviewerFromIdentity.js +62 -0
  79. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -0
  80. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
  81. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +67 -0
  82. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -0
  83. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
  84. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +59 -0
  85. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -0
  86. package/plugins/hooks/index.d.ts +3 -0
  87. package/plugins/hooks/index.js +71 -0
  88. package/plugins/hooks/index.js.map +1 -0
  89. package/plugins/hooks/initializeContentReviewSteps.d.ts +2 -0
  90. package/plugins/hooks/initializeContentReviewSteps.js +86 -0
  91. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -0
  92. package/plugins/hooks/listContentReviews.d.ts +10 -0
  93. package/plugins/hooks/listContentReviews.js +80 -0
  94. package/plugins/hooks/listContentReviews.js.map +1 -0
  95. package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
  96. package/plugins/hooks/updatePendingChangeRequests.js +94 -0
  97. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -0
  98. package/plugins/hooks/updateTotalComments.d.ts +3 -0
  99. package/plugins/hooks/updateTotalComments.js +153 -0
  100. package/plugins/hooks/updateTotalComments.js.map +1 -0
  101. package/plugins/hooks/validateChangeRequest.d.ts +2 -0
  102. package/plugins/hooks/validateChangeRequest.js +64 -0
  103. package/plugins/hooks/validateChangeRequest.js.map +1 -0
  104. package/plugins/hooks/validateComment.d.ts +2 -0
  105. package/plugins/hooks/validateComment.js +47 -0
  106. package/plugins/hooks/validateComment.js.map +1 -0
  107. package/plugins/hooks/validateContentReview.d.ts +2 -0
  108. package/plugins/hooks/validateContentReview.js +38 -0
  109. package/plugins/hooks/validateContentReview.js.map +1 -0
  110. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +9 -0
  111. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +51 -0
  112. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -0
  113. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +3 -0
  114. package/plugins/pageBuilder/apwContentPagePlugins.js +30 -0
  115. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -0
  116. package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +3 -0
  117. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +25 -0
  118. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -0
  119. package/plugins/pageBuilder/index.d.ts +11 -0
  120. package/plugins/pageBuilder/index.js +45 -0
  121. package/plugins/pageBuilder/index.js.map +1 -0
  122. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +8 -0
  123. package/plugins/pageBuilder/linkContentReviewToPage.js +105 -0
  124. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -0
  125. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +8 -0
  126. package/plugins/pageBuilder/linkWorkflowToPage.js +194 -0
  127. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -0
  128. package/plugins/pageBuilder/triggerContentReview.d.ts +8 -0
  129. package/plugins/pageBuilder/triggerContentReview.js +50 -0
  130. package/plugins/pageBuilder/triggerContentReview.js.map +1 -0
  131. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +10 -0
  132. package/plugins/pageBuilder/updateContentReviewStatus.js +79 -0
  133. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -0
  134. package/plugins/pageBuilder/utils.d.ts +22 -0
  135. package/plugins/pageBuilder/utils.js +184 -0
  136. package/plugins/pageBuilder/utils.js.map +1 -0
  137. package/plugins/utils.d.ts +36 -0
  138. package/plugins/utils.js +193 -0
  139. package/plugins/utils.js.map +1 -0
  140. package/scheduler/createScheduleActionMethods.d.ts +2 -0
  141. package/scheduler/createScheduleActionMethods.js +149 -0
  142. package/scheduler/createScheduleActionMethods.js.map +1 -0
  143. package/scheduler/handlers/executeAction/index.d.ts +13 -0
  144. package/scheduler/handlers/executeAction/index.js +172 -0
  145. package/scheduler/handlers/executeAction/index.js.map +1 -0
  146. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +13 -0
  147. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +17 -0
  148. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -0
  149. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +11 -0
  150. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +126 -0
  151. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -0
  152. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +11 -0
  153. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +163 -0
  154. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -0
  155. package/scheduler/handlers/executeAction/security.d.ts +4 -0
  156. package/scheduler/handlers/executeAction/security.js +68 -0
  157. package/scheduler/handlers/executeAction/security.js.map +1 -0
  158. package/scheduler/handlers/scheduleAction/index.d.ts +22 -0
  159. package/scheduler/handlers/scheduleAction/index.js +164 -0
  160. package/scheduler/handlers/scheduleAction/index.js.map +1 -0
  161. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +24 -0
  162. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +172 -0
  163. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -0
  164. package/scheduler/handlers/utils.d.ts +33 -0
  165. package/scheduler/handlers/utils.js +168 -0
  166. package/scheduler/handlers/utils.js.map +1 -0
  167. package/scheduler/index.d.ts +2 -0
  168. package/scheduler/index.js +27 -0
  169. package/scheduler/index.js.map +1 -0
  170. package/scheduler/types.d.ts +171 -0
  171. package/scheduler/types.js +34 -0
  172. package/scheduler/types.js.map +1 -0
  173. package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
  174. package/storageOperations/changeRequestStorageOperations.js +122 -0
  175. package/storageOperations/changeRequestStorageOperations.js.map +1 -0
  176. package/storageOperations/commentStorageOperations.d.ts +3 -0
  177. package/storageOperations/commentStorageOperations.js +138 -0
  178. package/storageOperations/commentStorageOperations.js.map +1 -0
  179. package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
  180. package/storageOperations/contentReviewStorageOperations.js +93 -0
  181. package/storageOperations/contentReviewStorageOperations.js.map +1 -0
  182. package/storageOperations/index.d.ts +15 -0
  183. package/storageOperations/index.js +48 -0
  184. package/storageOperations/index.js.map +1 -0
  185. package/storageOperations/models/changeRequest.model.d.ts +3 -0
  186. package/storageOperations/models/changeRequest.model.js +59 -0
  187. package/storageOperations/models/changeRequest.model.js.map +1 -0
  188. package/storageOperations/models/comment.model.d.ts +7 -0
  189. package/storageOperations/models/comment.model.js +60 -0
  190. package/storageOperations/models/comment.model.js.map +1 -0
  191. package/storageOperations/models/contentModelPluginFactory.d.ts +15 -0
  192. package/storageOperations/models/contentModelPluginFactory.js +28 -0
  193. package/storageOperations/models/contentModelPluginFactory.js.map +1 -0
  194. package/storageOperations/models/contentReview.model.d.ts +7 -0
  195. package/storageOperations/models/contentReview.model.js +258 -0
  196. package/storageOperations/models/contentReview.model.js.map +1 -0
  197. package/storageOperations/models/index.d.ts +2 -0
  198. package/storageOperations/models/index.js +115 -0
  199. package/storageOperations/models/index.js.map +1 -0
  200. package/storageOperations/models/reviewer.model.d.ts +3 -0
  201. package/storageOperations/models/reviewer.model.js +55 -0
  202. package/storageOperations/models/reviewer.model.js.map +1 -0
  203. package/storageOperations/models/utils.d.ts +3 -0
  204. package/storageOperations/models/utils.js +37 -0
  205. package/storageOperations/models/utils.js.map +1 -0
  206. package/storageOperations/models/workflow.model.d.ts +12 -0
  207. package/storageOperations/models/workflow.model.js +208 -0
  208. package/storageOperations/models/workflow.model.js.map +1 -0
  209. package/storageOperations/reviewerStorageOperations.d.ts +3 -0
  210. package/storageOperations/reviewerStorageOperations.js +89 -0
  211. package/storageOperations/reviewerStorageOperations.js.map +1 -0
  212. package/storageOperations/types.d.ts +34 -0
  213. package/storageOperations/types.js +5 -0
  214. package/storageOperations/types.js.map +1 -0
  215. package/storageOperations/workflowStorageOperations.d.ts +3 -0
  216. package/storageOperations/workflowStorageOperations.js +109 -0
  217. package/storageOperations/workflowStorageOperations.js.map +1 -0
  218. package/types.d.ts +740 -0
  219. package/types.js +69 -0
  220. package/types.js.map +1 -0
  221. package/utils/contentApwSettingsPlugin.d.ts +9 -0
  222. package/utils/contentApwSettingsPlugin.js +26 -0
  223. package/utils/contentApwSettingsPlugin.js.map +1 -0
  224. package/utils/errors.d.ts +16 -0
  225. package/utils/errors.js +75 -0
  226. package/utils/errors.js.map +1 -0
  227. package/utils/fieldResolver.d.ts +16 -0
  228. package/utils/fieldResolver.js +54 -0
  229. package/utils/fieldResolver.js.map +1 -0
  230. package/utils/resolve.d.ts +3 -0
  231. package/utils/resolve.js +18 -0
  232. package/utils/resolve.js.map +1 -0
@@ -0,0 +1,86 @@
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.initializeContentReviewSteps = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _set = _interopRequireDefault(require("lodash/set"));
13
+
14
+ var _utils = require("../utils");
15
+
16
+ var _handlerGraphql = require("@webiny/handler-graphql");
17
+
18
+ var _contentApwSettingsPlugin = require("../../utils/contentApwSettingsPlugin");
19
+
20
+ const initializeContentReviewSteps = ({
21
+ apw,
22
+ plugins
23
+ }) => {
24
+ apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({
25
+ input
26
+ }) => {
27
+ const {
28
+ type,
29
+ id,
30
+ settings
31
+ } = input.content;
32
+ /*
33
+ * Let's set "title" field value.
34
+ */
35
+
36
+ const getContent = apw.getContentGetter(type);
37
+ const content = await getContent(id, settings);
38
+
39
+ if (!content) {
40
+ throw new _handlerGraphql.NotFoundError(`Content "${type}" with id ${id} not found.`);
41
+ }
42
+
43
+ const {
44
+ title
45
+ } = content;
46
+ input = (0, _set.default)(input, "title", title);
47
+ /**
48
+ * We need to find a plugin which can get a workflow ID for the given type of content.
49
+ */
50
+
51
+ const contentApwSettingsPlugin = (0, _contentApwSettingsPlugin.getContentApwSettingsPlugin)({
52
+ plugins,
53
+ type
54
+ });
55
+ const workflowId = contentApwSettingsPlugin.getWorkflowId(content);
56
+ /**
57
+ * Let's initialize the "ContentReview" steps.
58
+ */
59
+
60
+ if (!workflowId) {
61
+ throw new _handlerGraphql.NotFoundError(`Unable to initiate a "Content review". No workflow found!`);
62
+ }
63
+
64
+ input.workflowId = workflowId;
65
+ const workflow = await apw.workflow.get(workflowId);
66
+ const workflowSteps = workflow.steps;
67
+ let previousStepStatus = undefined;
68
+ const updatedSteps = workflow.steps.map((step, index) => {
69
+ const status = (0, _utils.getContentReviewStepInitialStatus)(workflowSteps, index, previousStepStatus);
70
+ previousStepStatus = status;
71
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
72
+ status,
73
+ pendingChangeRequests: 0,
74
+ totalComments: 0
75
+ });
76
+ });
77
+ /**
78
+ * TODO Figure our what does this actually do?
79
+ * There is no steps property on CreateApwContentReviewParams
80
+ */
81
+
82
+ input = (0, _set.default)(input, "steps", updatedSteps);
83
+ });
84
+ };
85
+
86
+ exports.initializeContentReviewSteps = initializeContentReviewSteps;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["initializeContentReviewSteps","apw","plugins","contentReview","onContentReviewBeforeCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport { ApwContentReviewStepStatus, ApwContext } from \"~/types\";\nimport { getContentReviewStepInitialStatus } from \"~/plugins/utils\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { getContentApwSettingsPlugin } from \"~/utils/contentApwSettingsPlugin\";\n\nexport const initializeContentReviewSteps = ({ apw, plugins }: ApwContext) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { type, id, settings } = input.content;\n /*\n * Let's set \"title\" field value.\n */\n const getContent = apw.getContentGetter(type);\n const content = await getContent(id, settings);\n if (!content) {\n throw new NotFoundError(`Content \"${type}\" with id ${id} not found.`);\n }\n\n const { title } = content;\n input = lodashSet(input, \"title\", title);\n\n /**\n * We need to find a plugin which can get a workflow ID for the given type of content.\n */\n const contentApwSettingsPlugin = getContentApwSettingsPlugin({\n plugins,\n type\n });\n\n const workflowId = contentApwSettingsPlugin.getWorkflowId(content);\n\n /**\n * Let's initialize the \"ContentReview\" steps.\n */\n if (!workflowId) {\n throw new NotFoundError(`Unable to initiate a \"Content review\". No workflow found!`);\n }\n\n input.workflowId = workflowId;\n\n const workflow = await apw.workflow.get(workflowId);\n const workflowSteps = workflow.steps;\n\n let previousStepStatus: ApwContentReviewStepStatus | undefined = undefined;\n const updatedSteps = workflow.steps.map((step, index) => {\n const status = getContentReviewStepInitialStatus(\n workflowSteps,\n index,\n previousStepStatus\n );\n previousStepStatus = status;\n return {\n ...step,\n status,\n pendingChangeRequests: 0,\n totalComments: 0\n };\n });\n /**\n * TODO Figure our what does this actually do?\n * There is no steps property on CreateApwContentReviewParams\n */\n input = lodashSet(input, \"steps\", updatedSteps);\n });\n};\n"],"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AAf,CAAmB,CAACC,IAAD,EAAOC,KAAP,KAAiB;MACrD,MAAMC,MAAM,GAAG,IAAAC,wCAAA,EACXT,aADW,EAEXO,KAFW,EAGXL,kBAHW,CAAf;MAKAA,kBAAkB,GAAGM,MAArB;MACA,mEACOF,IADP;QAEIE,MAFJ;QAGIE,qBAAqB,EAAE,CAH3B;QAIIC,aAAa,EAAE;MAJnB;IAMH,CAboB,CAArB;IAcA;AACR;AACA;AACA;;IACQ3B,KAAK,GAAG,IAAAS,YAAA,EAAUT,KAAV,EAAiB,OAAjB,EAA0BoB,YAA1B,CAAR;EACH,CAxDD;AAyDH,CA1DM"}
@@ -0,0 +1,10 @@
1
+ import { AdvancedPublishingWorkflow } from "../../types";
2
+ import { HeadlessCms } from "@webiny/api-headless-cms/types";
3
+ import { Security } from "@webiny/api-security/types";
4
+ interface ListWorkflowsParams {
5
+ apw: AdvancedPublishingWorkflow;
6
+ cms: HeadlessCms;
7
+ security: Security;
8
+ }
9
+ export declare const listContentReviews: ({ apw, cms, security }: ListWorkflowsParams) => void;
10
+ export {};
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.listContentReviews = void 0;
7
+
8
+ var _contentReview = require("../../storageOperations/models/contentReview.model");
9
+
10
+ const listContentReviews = ({
11
+ apw,
12
+ cms,
13
+ security
14
+ }) => {
15
+ /**
16
+ * We need to hook into listing the content review entries.
17
+ * When listing content review entries, we need to check which ones current user can actually see.
18
+ */
19
+ cms.onEntryBeforeList.subscribe(async ({
20
+ model,
21
+ where
22
+ }) => {
23
+ const identity = security.getIdentity();
24
+
25
+ if (!(identity !== null && identity !== void 0 && identity.id) || model.modelId !== _contentReview.CONTENT_REVIEW_MODEL_ID) {
26
+ return;
27
+ }
28
+ /**
29
+ * Find all available workflows.
30
+ */
31
+
32
+
33
+ const [workflows] = await apw.workflow.list();
34
+
35
+ if (workflows.length === 0) {
36
+ return;
37
+ }
38
+ /**
39
+ * We need to find the reviewer entryId to be able to match it to the reviewer entryId in the workflow steps.
40
+ */
41
+
42
+
43
+ const [reviewers] = await apw.reviewer.list({
44
+ where: {
45
+ identityId: identity.id
46
+ }
47
+ });
48
+
49
+ if (reviewers.length === 0) {
50
+ return;
51
+ }
52
+
53
+ const reviewerList = reviewers.map(reviewer => reviewer.entryId);
54
+ /**
55
+ * Find all workflows which user has access to.
56
+ * User access is buried quite deep in the workflow data, so we need to do some traversing.
57
+ */
58
+
59
+ const userWorkflows = workflows.filter(workflow => {
60
+ return workflow.steps.some(step => {
61
+ return step.reviewers.some(reviewer => {
62
+ return reviewerList.includes(reviewer.entryId);
63
+ });
64
+ });
65
+ });
66
+
67
+ if (userWorkflows.length === 0) {
68
+ return;
69
+ }
70
+ /**
71
+ * In the end, we need to attach the workflow filter by the entryId.
72
+ * Just in case we add versioning at some point...
73
+ */
74
+
75
+
76
+ where.workflowId_in = userWorkflows.map(workflow => workflow.id);
77
+ });
78
+ };
79
+
80
+ exports.listContentReviews = listContentReviews;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["listContentReviews","apw","cms","security","onEntryBeforeList","subscribe","model","where","identity","getIdentity","id","modelId","CONTENT_REVIEW_MODEL_ID","workflows","workflow","list","length","reviewers","reviewer","identityId","reviewerList","map","entryId","userWorkflows","filter","steps","some","step","includes","workflowId_in"],"sources":["listContentReviews.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow } from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\nimport { Security } from \"@webiny/api-security/types\";\n\ninterface ListWorkflowsParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\nexport const listContentReviews = ({ apw, cms, security }: ListWorkflowsParams) => {\n /**\n * We need to hook into listing the content review entries.\n * When listing content review entries, we need to check which ones current user can actually see.\n */\n cms.onEntryBeforeList.subscribe(async ({ model, where }) => {\n const identity = security.getIdentity();\n if (!identity?.id || model.modelId !== CONTENT_REVIEW_MODEL_ID) {\n return;\n }\n /**\n * Find all available workflows.\n */\n const [workflows] = await apw.workflow.list();\n if (workflows.length === 0) {\n return;\n }\n /**\n * We need to find the reviewer entryId to be able to match it to the reviewer entryId in the workflow steps.\n */\n const [reviewers] = await apw.reviewer.list({\n where: {\n identityId: identity.id\n }\n });\n if (reviewers.length === 0) {\n return;\n }\n const reviewerList = reviewers.map(reviewer => reviewer.entryId);\n /**\n * Find all workflows which user has access to.\n * User access is buried quite deep in the workflow data, so we need to do some traversing.\n */\n const userWorkflows = workflows.filter(workflow => {\n return workflow.steps.some(step => {\n return step.reviewers.some(reviewer => {\n return reviewerList.includes(reviewer.entryId);\n });\n });\n });\n if (userWorkflows.length === 0) {\n return;\n }\n /**\n * In the end, we need to attach the workflow filter by the entryId.\n * Just in case we add versioning at some point...\n */\n where.workflowId_in = userWorkflows.map(workflow => workflow.id);\n });\n};\n"],"mappings":";;;;;;;AAEA;;AAQO,MAAMA,kBAAkB,GAAG,CAAC;EAAEC,GAAF;EAAOC,GAAP;EAAYC;AAAZ,CAAD,KAAiD;EAC/E;AACJ;AACA;AACA;EACID,GAAG,CAACE,iBAAJ,CAAsBC,SAAtB,CAAgC,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA4B;IACxD,MAAMC,QAAQ,GAAGL,QAAQ,CAACM,WAAT,EAAjB;;IACA,IAAI,EAACD,QAAD,aAACA,QAAD,eAACA,QAAQ,CAAEE,EAAX,KAAiBJ,KAAK,CAACK,OAAN,KAAkBC,sCAAvC,EAAgE;MAC5D;IACH;IACD;AACR;AACA;;;IACQ,MAAM,CAACC,SAAD,IAAc,MAAMZ,GAAG,CAACa,QAAJ,CAAaC,IAAb,EAA1B;;IACA,IAAIF,SAAS,CAACG,MAAV,KAAqB,CAAzB,EAA4B;MACxB;IACH;IACD;AACR;AACA;;;IACQ,MAAM,CAACC,SAAD,IAAc,MAAMhB,GAAG,CAACiB,QAAJ,CAAaH,IAAb,CAAkB;MACxCR,KAAK,EAAE;QACHY,UAAU,EAAEX,QAAQ,CAACE;MADlB;IADiC,CAAlB,CAA1B;;IAKA,IAAIO,SAAS,CAACD,MAAV,KAAqB,CAAzB,EAA4B;MACxB;IACH;;IACD,MAAMI,YAAY,GAAGH,SAAS,CAACI,GAAV,CAAcH,QAAQ,IAAIA,QAAQ,CAACI,OAAnC,CAArB;IACA;AACR;AACA;AACA;;IACQ,MAAMC,aAAa,GAAGV,SAAS,CAACW,MAAV,CAAiBV,QAAQ,IAAI;MAC/C,OAAOA,QAAQ,CAACW,KAAT,CAAeC,IAAf,CAAoBC,IAAI,IAAI;QAC/B,OAAOA,IAAI,CAACV,SAAL,CAAeS,IAAf,CAAoBR,QAAQ,IAAI;UACnC,OAAOE,YAAY,CAACQ,QAAb,CAAsBV,QAAQ,CAACI,OAA/B,CAAP;QACH,CAFM,CAAP;MAGH,CAJM,CAAP;IAKH,CANqB,CAAtB;;IAOA,IAAIC,aAAa,CAACP,MAAd,KAAyB,CAA7B,EAAgC;MAC5B;IACH;IACD;AACR;AACA;AACA;;;IACQT,KAAK,CAACsB,aAAN,GAAsBN,aAAa,CAACF,GAAd,CAAkBP,QAAQ,IAAIA,QAAQ,CAACJ,EAAvC,CAAtB;EACH,CA3CD;AA4CH,CAjDM"}
@@ -0,0 +1,2 @@
1
+ import { LifeCycleHookCallbackParams } from "../../types";
2
+ export declare const updatePendingChangeRequestsCount: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -0,0 +1,94 @@
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.updatePendingChangeRequestsCount = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _utils = require("../utils");
13
+
14
+ const updatePendingChangeRequests = async ({
15
+ contentReviewMethods,
16
+ step,
17
+ delta
18
+ }) => {
19
+ const {
20
+ id,
21
+ stepId
22
+ } = (0, _utils.extractContentReviewIdAndStep)(step);
23
+ await (0, _utils.updateContentReview)({
24
+ contentReviewMethods,
25
+ id,
26
+ getNewContentReviewData: data => {
27
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
28
+ steps: (0, _utils.updateContentReviewStep)(data.steps, stepId, step => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
29
+ pendingChangeRequests: step.pendingChangeRequests + delta
30
+ }))
31
+ });
32
+ }
33
+ });
34
+ };
35
+
36
+ const updatePendingChangeRequestsCount = ({
37
+ apw
38
+ }) => {
39
+ apw.changeRequest.onChangeRequestAfterDelete.subscribe(async ({
40
+ changeRequest
41
+ }) => {
42
+ /**
43
+ * If the deleted changeRequest was marked as resolved. We don't need to do anything here,
44
+ * because "pendingChangeRequests has been already updated in "onAfterChangeRequestUpdate" hook.
45
+ */
46
+ if (changeRequest.resolved === true) {
47
+ return;
48
+ }
49
+ /**
50
+ * After a "changeRequest" is deleted, decrement the "pendingChangeRequests" count
51
+ * in the corresponding step of the content review entry.
52
+ */
53
+
54
+
55
+ await updatePendingChangeRequests({
56
+ contentReviewMethods: apw.contentReview,
57
+ step: changeRequest.step,
58
+ delta: -1
59
+ });
60
+ });
61
+ apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({
62
+ changeRequest
63
+ }) => {
64
+ /**
65
+ * After a "changeRequest" is created, increment the "pendingChangeRequests" count
66
+ * of the corresponding step in the content review entry.
67
+ */
68
+ await updatePendingChangeRequests({
69
+ contentReviewMethods: apw.contentReview,
70
+ step: changeRequest.step,
71
+ delta: 1
72
+ });
73
+ });
74
+ apw.changeRequest.onChangeRequestAfterUpdate.subscribe(async ({
75
+ changeRequest,
76
+ original
77
+ }) => {
78
+ /**
79
+ * After a "changeRequest" is created, and the value of "resolved" field has changed;
80
+ * then we also need to update the "pendingChangeRequests" count of the corresponding step in the content review entry.
81
+ */
82
+ if (original.resolved !== changeRequest.resolved) {
83
+ const resolved = changeRequest.resolved;
84
+ const delta = resolved === true ? -1 : 1;
85
+ await updatePendingChangeRequests({
86
+ contentReviewMethods: apw.contentReview,
87
+ step: changeRequest.step,
88
+ delta
89
+ });
90
+ }
91
+ });
92
+ };
93
+
94
+ exports.updatePendingChangeRequestsCount = updatePendingChangeRequestsCount;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["updatePendingChangeRequests","contentReviewMethods","step","delta","id","stepId","extractContentReviewIdAndStep","updateContentReview","getNewContentReviewData","data","steps","updateContentReviewStep","pendingChangeRequests","updatePendingChangeRequestsCount","apw","changeRequest","onChangeRequestAfterDelete","subscribe","resolved","contentReview","onChangeRequestAfterCreate","onChangeRequestAfterUpdate","original"],"sources":["updatePendingChangeRequests.ts"],"sourcesContent":["import { ApwChangeRequest, ApwContentReviewCrud, LifeCycleHookCallbackParams } from \"~/types\";\nimport {\n extractContentReviewIdAndStep,\n updateContentReview,\n updateContentReviewStep\n} from \"../utils\";\n\ninterface UpdatePendingChangeRequestsParams {\n contentReviewMethods: ApwContentReviewCrud;\n delta: number;\n step: ApwChangeRequest[\"step\"];\n}\n\nconst updatePendingChangeRequests = async ({\n contentReviewMethods,\n step,\n delta\n}: UpdatePendingChangeRequestsParams): Promise<void> => {\n const { id, stepId } = extractContentReviewIdAndStep(step);\n\n await updateContentReview({\n contentReviewMethods,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n pendingChangeRequests: step.pendingChangeRequests + delta\n }))\n };\n }\n });\n};\n\nexport const updatePendingChangeRequestsCount = ({\n apw\n}: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.changeRequest.onChangeRequestAfterDelete.subscribe(async ({ changeRequest }) => {\n /**\n * If the deleted changeRequest was marked as resolved. We don't need to do anything here,\n * because \"pendingChangeRequests has been already updated in \"onAfterChangeRequestUpdate\" hook.\n */\n if (changeRequest.resolved === true) {\n return;\n }\n /**\n * After a \"changeRequest\" is deleted, decrement the \"pendingChangeRequests\" count\n * in the corresponding step of the content review entry.\n */\n await updatePendingChangeRequests({\n contentReviewMethods: apw.contentReview,\n step: changeRequest.step,\n delta: -1\n });\n });\n\n apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({ changeRequest }) => {\n /**\n * After a \"changeRequest\" is created, increment the \"pendingChangeRequests\" count\n * of the corresponding step in the content review entry.\n */\n await updatePendingChangeRequests({\n contentReviewMethods: apw.contentReview,\n step: changeRequest.step,\n delta: 1\n });\n });\n\n apw.changeRequest.onChangeRequestAfterUpdate.subscribe(async ({ changeRequest, original }) => {\n /**\n * After a \"changeRequest\" is created, and the value of \"resolved\" field has changed;\n * then we also need to update the \"pendingChangeRequests\" count of the corresponding step in the content review entry.\n */\n if (original.resolved !== changeRequest.resolved) {\n const resolved = changeRequest.resolved;\n const delta = resolved === true ? -1 : 1;\n\n await updatePendingChangeRequests({\n contentReviewMethods: apw.contentReview,\n step: changeRequest.step,\n delta\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAYA,MAAMA,2BAA2B,GAAG,OAAO;EACvCC,oBADuC;EAEvCC,IAFuC;EAGvCC;AAHuC,CAAP,KAIoB;EACpD,MAAM;IAAEC,EAAF;IAAMC;EAAN,IAAiB,IAAAC,oCAAA,EAA8BJ,IAA9B,CAAvB;EAEA,MAAM,IAAAK,0BAAA,EAAoB;IACtBN,oBADsB;IAEtBG,EAFsB;IAGtBI,uBAAuB,EAAEC,IAAI,IAAI;MAC7B,mEACOA,IADP;QAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAAI,CAACC,KAA7B,EAAoCL,MAApC,EAA4CH,IAAI,gEAChDA,IADgD;UAEnDU,qBAAqB,EAAEV,IAAI,CAACU,qBAAL,GAA6BT;QAFD,EAAhD;MAFX;IAOH;EAXqB,CAApB,CAAN;AAaH,CApBD;;AAsBO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+1,3 @@
1
+ import { LifeCycleHookCallbackParams } from "../../types";
2
+ export declare const updateTotalCommentsCount: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
3
+ export declare const updateLatestCommentId: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -0,0 +1,153 @@
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.updateTotalCommentsCount = exports.updateLatestCommentId = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _utils = require("../utils");
13
+
14
+ const updateTotalCommentsCount = ({
15
+ apw
16
+ }) => {
17
+ apw.comment.onCommentAfterDelete.subscribe(async ({
18
+ comment
19
+ }) => {
20
+ const {
21
+ step
22
+ } = comment;
23
+ /**
24
+ * After a "comment" is deleted, decrement the "totalComments" count
25
+ * in the corresponding step of the content review entry.
26
+ */
27
+
28
+ if (step) {
29
+ const {
30
+ id,
31
+ stepId
32
+ } = (0, _utils.extractContentReviewIdAndStep)(step);
33
+ await (0, _utils.updateContentReview)({
34
+ contentReviewMethods: apw.contentReview,
35
+ id,
36
+ getNewContentReviewData: data => {
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), {}, {
39
+ totalComments: step.totalComments - 1
40
+ }))
41
+ });
42
+ }
43
+ });
44
+ }
45
+ });
46
+ apw.comment.onCommentAfterCreate.subscribe(async ({
47
+ comment
48
+ }) => {
49
+ /**
50
+ * After a "comment" is created, increment the "totalComments" count
51
+ * of the corresponding step in the content review entry.
52
+ */
53
+ const {
54
+ id,
55
+ stepId
56
+ } = (0, _utils.extractContentReviewIdAndStep)(comment.step);
57
+ await (0, _utils.updateContentReview)({
58
+ contentReviewMethods: apw.contentReview,
59
+ id,
60
+ getNewContentReviewData: data => {
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), {}, {
63
+ totalComments: step.totalComments + 1
64
+ }))
65
+ });
66
+ }
67
+ });
68
+ });
69
+ };
70
+
71
+ exports.updateTotalCommentsCount = updateTotalCommentsCount;
72
+
73
+ const updateLatestCommentId = ({
74
+ apw
75
+ }) => {
76
+ apw.comment.onCommentAfterCreate.subscribe(async ({
77
+ comment
78
+ }) => {
79
+ /**
80
+ * After a "comment" is created, update the "latestCommentId" in
81
+ * the corresponding content review entry.
82
+ */
83
+ const {
84
+ id
85
+ } = (0, _utils.extractContentReviewIdAndStep)(comment.step);
86
+ await (0, _utils.updateContentReview)({
87
+ contentReviewMethods: apw.contentReview,
88
+ id,
89
+ getNewContentReviewData: contentReview => {
90
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview), {}, {
91
+ latestCommentId: comment.id
92
+ });
93
+ }
94
+ });
95
+ });
96
+ apw.comment.onCommentAfterUpdate.subscribe(async ({
97
+ comment
98
+ }) => {
99
+ /**
100
+ * After a "comment" is updated, update the "latestCommentId" in
101
+ * the corresponding content review entry.
102
+ */
103
+ const {
104
+ id
105
+ } = (0, _utils.extractContentReviewIdAndStep)(comment.step);
106
+ await (0, _utils.updateContentReview)({
107
+ contentReviewMethods: apw.contentReview,
108
+ id,
109
+ getNewContentReviewData: contentReview => {
110
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview), {}, {
111
+ latestCommentId: comment.id
112
+ });
113
+ }
114
+ });
115
+ });
116
+ apw.comment.onCommentAfterDelete.subscribe(async ({
117
+ comment
118
+ }) => {
119
+ /**
120
+ * After a "comment" is updated, update the "latestCommentId" in
121
+ * the corresponding content review entry.
122
+ */
123
+ const {
124
+ id
125
+ } = (0, _utils.extractContentReviewIdAndStep)(comment.step);
126
+ const contentReview = await (0, _utils.safelyGetContentReview)({
127
+ id,
128
+ contentReviewMethods: apw.contentReview
129
+ });
130
+
131
+ if (contentReview && contentReview.latestCommentId === comment.id) {
132
+ const [[latestComment]] = await apw.comment.list({
133
+ where: {
134
+ changeRequest: {
135
+ id: comment.changeRequest
136
+ }
137
+ },
138
+ sort: ["createdOn_DESC"]
139
+ });
140
+ await (0, _utils.updateContentReview)({
141
+ contentReviewMethods: apw.contentReview,
142
+ id,
143
+ getNewContentReviewData: contentReview => {
144
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview), {}, {
145
+ latestCommentId: latestComment ? latestComment.id : null
146
+ });
147
+ }
148
+ });
149
+ }
150
+ });
151
+ };
152
+
153
+ exports.updateLatestCommentId = updateLatestCommentId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["updateTotalCommentsCount","apw","comment","onCommentAfterDelete","subscribe","step","id","stepId","extractContentReviewIdAndStep","updateContentReview","contentReviewMethods","contentReview","getNewContentReviewData","data","steps","updateContentReviewStep","totalComments","onCommentAfterCreate","updateLatestCommentId","latestCommentId","onCommentAfterUpdate","safelyGetContentReview","latestComment","list","where","changeRequest","sort"],"sources":["updateTotalComments.ts"],"sourcesContent":["import { LifeCycleHookCallbackParams } from \"~/types\";\nimport {\n extractContentReviewIdAndStep,\n safelyGetContentReview,\n updateContentReview,\n updateContentReviewStep\n} from \"../utils\";\n\nexport const updateTotalCommentsCount = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n const { step } = comment;\n /**\n * After a \"comment\" is deleted, decrement the \"totalComments\" count\n * in the corresponding step of the content review entry.\n */\n if (step) {\n const { id, stepId } = extractContentReviewIdAndStep(step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments - 1\n }))\n };\n }\n });\n }\n });\n\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, increment the \"totalComments\" count\n * of the corresponding step in the content review entry.\n */\n const { id, stepId } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: data => {\n return {\n ...data,\n steps: updateContentReviewStep(data.steps, stepId, step => ({\n ...step,\n totalComments: step.totalComments + 1\n }))\n };\n }\n });\n });\n};\n\nexport const updateLatestCommentId = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is created, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterUpdate.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: comment.id\n };\n }\n });\n });\n\n apw.comment.onCommentAfterDelete.subscribe(async ({ comment }) => {\n /**\n * After a \"comment\" is updated, update the \"latestCommentId\" in\n * the corresponding content review entry.\n */\n const { id } = extractContentReviewIdAndStep(comment.step);\n\n const contentReview = await safelyGetContentReview({\n id,\n contentReviewMethods: apw.contentReview\n });\n\n if (contentReview && contentReview.latestCommentId === comment.id) {\n const [[latestComment]] = await apw.comment.list({\n where: { changeRequest: { id: comment.changeRequest } },\n sort: [\"createdOn_DESC\"]\n });\n\n await updateContentReview({\n contentReviewMethods: apw.contentReview,\n id,\n getNewContentReviewData: contentReview => {\n return {\n ...contentReview,\n latestCommentId: latestComment ? latestComment.id : null\n };\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAOO,MAAMA,wBAAwB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAC3FA,GAAG,CAACC,OAAJ,CAAYC,oBAAZ,CAAiCC,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D,MAAM;MAAEG;IAAF,IAAWH,OAAjB;IACA;AACR;AACA;AACA;;IACQ,IAAIG,IAAJ,EAAU;MACN,MAAM;QAAEC,EAAF;QAAMC;MAAN,IAAiB,IAAAC,oCAAA,EAA8BH,IAA9B,CAAvB;MAEA,MAAM,IAAAI,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAEC,IAAI,IAAI;UAC7B,mEACOA,IADP;YAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAAI,CAACC,KAA7B,EAAoCP,MAApC,EAA4CF,IAAI,gEAChDA,IADgD;cAEnDW,aAAa,EAAEX,IAAI,CAACW,aAAL,GAAqB;YAFe,EAAhD;UAFX;QAOH;MAXqB,CAApB,CAAN;IAaH;EACJ,CAvBD;EAyBAf,GAAG,CAACC,OAAJ,CAAYe,oBAAZ,CAAiCb,SAAjC,CAA2C,OAAO;IAAEF;EAAF,CAAP,KAAuB;IAC9D;AACR;AACA;AACA;IACQ,MAAM;MAAEI,EAAF;MAAMC;IAAN,IAAiB,IAAAC,oCAAA,EAA8BN,OAAO,CAACG,IAAtC,CAAvB;IAEA,MAAM,IAAAI,0BAAA,EAAoB;MACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;MAEtBL,EAFsB;MAGtBM,uBAAuB,EAAEC,IAAI,IAAI;QAC7B,mEACOA,IADP;UAEIC,KAAK,EAAE,IAAAC,8BAAA,EAAwBF,IAAI,CAACC,KAA7B,EAAoCP,MAApC,E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,CAACG,IAAtC,CAAf;IAEA,MAAMM,aAAa,GAAG,MAAM,IAAAU,6BAAA,EAAuB;MAC/Cf,EAD+C;MAE/CI,oBAAoB,EAAET,GAAG,CAACU;IAFqB,CAAvB,CAA5B;;IAKA,IAAIA,aAAa,IAAIA,aAAa,CAACQ,eAAd,KAAkCjB,OAAO,CAACI,EAA/D,EAAmE;MAC/D,MAAM,CAAC,CAACgB,aAAD,CAAD,IAAoB,MAAMrB,GAAG,CAACC,OAAJ,CAAYqB,IAAZ,CAAiB;QAC7CC,KAAK,EAAE;UAAEC,aAAa,EAAE;YAAEnB,EAAE,EAAEJ,OAAO,CAACuB;UAAd;QAAjB,CADsC;QAE7CC,IAAI,EAAE,CAAC,gBAAD;MAFuC,CAAjB,CAAhC;MAKA,MAAM,IAAAjB,0BAAA,EAAoB;QACtBC,oBAAoB,EAAET,GAAG,CAACU,aADJ;QAEtBL,EAFsB;QAGtBM,uBAAuB,EAAED,aAAa,IAAI;UACtC,mEACOA,aADP;YAEIQ,eAAe,EAAEG,aAAa,GAAGA,aAAa,CAAChB,EAAjB,GAAsB;UAFxD;QAIH;MARqB,CAApB,CAAN;IAUH;EACJ,CA7BD;AA8BH,CArEM"}
@@ -0,0 +1,2 @@
1
+ import { LifeCycleHookCallbackParams } from "../../types";
2
+ export declare const validateChangeRequest: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -0,0 +1,64 @@
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.validateChangeRequest = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _handlerGraphql = require("@webiny/handler-graphql");
13
+
14
+ const validateChangeRequest = ({
15
+ apw
16
+ }) => {
17
+ apw.changeRequest.onChangeRequestBeforeCreate.subscribe(async ({
18
+ input
19
+ }) => {
20
+ const {
21
+ step
22
+ } = input;
23
+ /**
24
+ * We need step to be in a particular format i.e. "contentReviewId#version#stepId"
25
+ */
26
+
27
+ const [entryId, version, stepId] = step.split("#");
28
+
29
+ if (!entryId || !version || !stepId) {
30
+ throw new _error.default(`The step property in input is not properly formatted.`, "MALFORMED_CHANGE_REQUEST_STEP", {
31
+ step
32
+ });
33
+ }
34
+ /**
35
+ * Check whether a contentReview entry exists with provided id.
36
+ */
37
+
38
+
39
+ const revisionId = `${entryId}#${version}`;
40
+ const contentReview = await apw.contentReview.get(revisionId);
41
+
42
+ if (!contentReview) {
43
+ throw new _handlerGraphql.NotFoundError(`Unable to found "ContentReview" with given id "${revisionId}"`);
44
+ }
45
+ /**
46
+ * Don't allow "change request" creation once the sign-off has been provided.
47
+ */
48
+
49
+
50
+ const {
51
+ steps
52
+ } = contentReview;
53
+ const currentStep = steps.find(step => step.id === stepId);
54
+
55
+ if (currentStep && currentStep.signOffProvidedOn) {
56
+ throw new _error.default(`Please retract the sign-off before opening a new change request.`, "SIGN_OFF_PROVIDED", {
57
+ step: currentStep,
58
+ stepId: stepId
59
+ });
60
+ }
61
+ });
62
+ };
63
+
64
+ exports.validateChangeRequest = validateChangeRequest;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateChangeRequest","apw","changeRequest","onChangeRequestBeforeCreate","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.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 [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"}
@@ -0,0 +1,2 @@
1
+ import { LifeCycleHookCallbackParams } from "../../types";
2
+ export declare const validateComment: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;
@@ -0,0 +1,47 @@
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.validateComment = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ const validateComment = ({
13
+ apw
14
+ }) => {
15
+ apw.comment.onCommentBeforeCreate.subscribe(async ({
16
+ input
17
+ }) => {
18
+ const {
19
+ changeRequest: changeRequestId
20
+ } = input;
21
+ /**
22
+ * We need changeRequest to be in a particular format i.e. "contentReviewUniqueId#version"
23
+ */
24
+
25
+ const [entryId, version] = changeRequestId.split("#");
26
+
27
+ if (!entryId || !version) {
28
+ throw new _error.default(`The"changeRequest" property in input is not properly formatted.`, "MALFORMED_CHANGE_REQUEST_ID", {
29
+ input
30
+ });
31
+ }
32
+ /**
33
+ * Assign value for "step" field from "changeRequest".
34
+ */
35
+
36
+
37
+ const changeRequest = await apw.changeRequest.get(changeRequestId);
38
+
39
+ if (!changeRequest) {
40
+ return;
41
+ }
42
+
43
+ input.step = changeRequest.step;
44
+ });
45
+ };
46
+
47
+ exports.validateComment = validateComment;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateComment","apw","comment","onCommentBeforeCreate","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.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 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"}
@@ -0,0 +1,2 @@
1
+ import { LifeCycleHookCallbackParams } from "../../types";
2
+ export declare const validateContentReview: ({ apw }: Pick<LifeCycleHookCallbackParams, "apw">) => void;