@webiny/api-apw 0.0.0-unstable.1e66d121db → 0.0.0-unstable.3386f66516

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 (125) 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/crud/createContentReviewMethods.js +15 -5
  14. package/crud/createContentReviewMethods.js.map +1 -1
  15. package/index.d.ts +2 -3
  16. package/index.js +5 -9
  17. package/index.js.map +1 -1
  18. package/package.json +32 -32
  19. package/plugins/cms/index.js +9 -1
  20. package/plugins/cms/index.js.map +1 -1
  21. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  22. package/plugins/cms/notifications/changeRequestNotification.js +35 -0
  23. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  24. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  25. package/plugins/cms/notifications/commentNotification.js +35 -0
  26. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  27. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  28. package/plugins/cms/notifications/contentReviewNotification.js +35 -0
  29. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  30. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  31. package/plugins/cms/notifications/contentUrl.js +60 -0
  32. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  33. package/plugins/context.d.ts +0 -1
  34. package/plugins/context.js +2 -19
  35. package/plugins/context.js.map +1 -1
  36. package/plugins/graphql/reviewer.gql.js +2 -0
  37. package/plugins/graphql/reviewer.gql.js.map +1 -1
  38. package/plugins/graphql.js +2 -2
  39. package/plugins/graphql.js.map +1 -1
  40. package/plugins/hooks/createReviewerFromIdentity.js +28 -8
  41. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  42. package/plugins/hooks/index.js +3 -0
  43. package/plugins/hooks/index.js.map +1 -1
  44. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  45. package/plugins/hooks/initializeNotifications.js +20 -0
  46. package/plugins/hooks/initializeNotifications.js.map +1 -0
  47. package/plugins/hooks/listContentReviews.d.ts +1 -1
  48. package/plugins/hooks/listContentReviews.js +11 -23
  49. package/plugins/hooks/listContentReviews.js.map +1 -1
  50. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  51. package/plugins/hooks/notifications/appUrl.js +22 -0
  52. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  53. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  54. package/plugins/hooks/notifications/changeRequestAfterCreate.js +144 -0
  55. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  56. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  57. package/plugins/hooks/notifications/changeRequestUrl.js +31 -0
  58. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  59. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  60. package/plugins/hooks/notifications/commentAfterCreate.js +157 -0
  61. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  62. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  63. package/plugins/hooks/notifications/commentUrl.js +31 -0
  64. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  65. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  66. package/plugins/hooks/notifications/contentReviewAfterCreate.js +122 -0
  67. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  68. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  69. package/plugins/hooks/notifications/contentReviewUrl.js +30 -0
  70. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  71. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  72. package/plugins/hooks/notifications/contentUrl.js +29 -0
  73. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  74. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  75. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +25 -0
  76. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  77. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  78. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +25 -0
  79. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  80. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  81. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +25 -0
  82. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  83. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  84. package/plugins/hooks/notifications/reviewers.js +51 -0
  85. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  86. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  87. package/plugins/hooks/notifications/sendChangeRequestNotification.js +52 -0
  88. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  89. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  90. package/plugins/hooks/notifications/sendCommentNotification.js +52 -0
  91. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  92. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  93. package/plugins/hooks/notifications/sendContentReviewNotification.js +52 -0
  94. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  95. package/plugins/hooks/validateChangeRequest.js +28 -3
  96. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  97. package/plugins/hooks/validateComment.js +12 -2
  98. package/plugins/hooks/validateComment.js.map +1 -1
  99. package/plugins/pageBuilder/index.js +9 -1
  100. package/plugins/pageBuilder/index.js.map +1 -1
  101. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  102. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  103. package/plugins/pageBuilder/notifications/changeRequestNotification.js +35 -0
  104. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  105. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  106. package/plugins/pageBuilder/notifications/commentNotification.js +35 -0
  107. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  108. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  109. package/plugins/pageBuilder/notifications/contentReviewNotification.js +35 -0
  110. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  111. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  112. package/plugins/pageBuilder/notifications/contentUrl.js +53 -0
  113. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  114. package/plugins/pageBuilder/utils.js.map +1 -1
  115. package/plugins/utils.d.ts +0 -1
  116. package/plugins/utils.js +1 -7
  117. package/plugins/utils.js.map +1 -1
  118. package/storageOperations/models/reviewer.model.js +18 -2
  119. package/storageOperations/models/reviewer.model.js.map +1 -1
  120. package/storageOperations/reviewerStorageOperations.js +13 -5
  121. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  122. package/storageOperations/workflowStorageOperations.js +3 -1
  123. package/storageOperations/workflowStorageOperations.js.map +1 -1
  124. package/types.d.ts +21 -9
  125. package/types.js.map +1 -1
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../types";
2
+ export declare const initializeNotifications: (context: ApwContext) => void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initializeNotifications = void 0;
7
+
8
+ var _contentReviewAfterCreate = require("./notifications/contentReviewAfterCreate");
9
+
10
+ var _commentAfterCreate = require("./notifications/commentAfterCreate");
11
+
12
+ var _changeRequestAfterCreate = require("./notifications/changeRequestAfterCreate");
13
+
14
+ const initializeNotifications = context => {
15
+ (0, _contentReviewAfterCreate.attachContentReviewAfterCreate)(context);
16
+ (0, _commentAfterCreate.attachCommentAfterCreate)(context);
17
+ (0, _changeRequestAfterCreate.attachChangeRequestAfterCreate)(context);
18
+ };
19
+
20
+ exports.initializeNotifications = initializeNotifications;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["initializeNotifications","context","attachContentReviewAfterCreate","attachCommentAfterCreate","attachChangeRequestAfterCreate"],"sources":["initializeNotifications.ts"],"sourcesContent":["import { ApwContext } from \"~/types\";\nimport { attachContentReviewAfterCreate } from \"./notifications/contentReviewAfterCreate\";\nimport { attachCommentAfterCreate } from \"./notifications/commentAfterCreate\";\nimport { attachChangeRequestAfterCreate } from \"./notifications/changeRequestAfterCreate\";\n\nexport const initializeNotifications = (context: ApwContext) => {\n attachContentReviewAfterCreate(context);\n attachCommentAfterCreate(context);\n attachChangeRequestAfterCreate(context);\n};\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAEO,MAAMA,uBAAuB,GAAIC,OAAD,IAAyB;EAC5D,IAAAC,wDAAA,EAA+BD,OAA/B;EACA,IAAAE,4CAAA,EAAyBF,OAAzB;EACA,IAAAG,wDAAA,EAA+BH,OAA/B;AACH,CAJM"}
@@ -6,5 +6,5 @@ interface ListWorkflowsParams {
6
6
  cms: HeadlessCms;
7
7
  security: Security;
8
8
  }
9
- export declare const listContentReviews: ({ apw, cms, security }: ListWorkflowsParams) => void;
9
+ export declare const listContentReviews: ({ apw, security }: ListWorkflowsParams) => void;
10
10
  export {};
@@ -5,24 +5,27 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.listContentReviews = void 0;
7
7
 
8
- var _contentReview = require("../../storageOperations/models/contentReview.model");
9
-
10
8
  const listContentReviews = ({
11
9
  apw,
12
- cms,
13
10
  security
14
11
  }) => {
15
12
  /**
16
13
  * We need to hook into listing the content review entries.
17
14
  * When listing content review entries, we need to check which ones current user can actually see.
18
15
  */
19
- cms.onEntryBeforeList.subscribe(async ({
20
- model,
16
+ apw.contentReview.onContentReviewBeforeList.subscribe(async ({
21
17
  where
22
18
  }) => {
19
+ /**
20
+ * If there is workflowId_in attached on where, we will not change it.
21
+ */
22
+ if (where.workflowId_in) {
23
+ return;
24
+ }
25
+
23
26
  const identity = security.getIdentity();
24
27
 
25
- if (!(identity !== null && identity !== void 0 && identity.id) || model.modelId !== _contentReview.CONTENT_REVIEW_MODEL_ID) {
28
+ if (!(identity !== null && identity !== void 0 && identity.id)) {
26
29
  return;
27
30
  }
28
31
  /**
@@ -35,31 +38,16 @@ const listContentReviews = ({
35
38
  if (workflows.length === 0) {
36
39
  return;
37
40
  }
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
41
  /**
55
42
  * Find all workflows which user has access to.
56
43
  * User access is buried quite deep in the workflow data, so we need to do some traversing.
57
44
  */
58
45
 
46
+
59
47
  const userWorkflows = workflows.filter(workflow => {
60
48
  return workflow.steps.some(step => {
61
49
  return step.reviewers.some(reviewer => {
62
- return reviewerList.includes(reviewer.entryId);
50
+ return identity.id === reviewer.identityId;
63
51
  });
64
52
  });
65
53
  });
@@ -1 +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,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A4CH,CAjDM"}
1
+ {"version":3,"names":["listContentReviews","apw","security","contentReview","onContentReviewBeforeList","subscribe","where","workflowId_in","identity","getIdentity","id","workflows","workflow","list","length","userWorkflows","filter","steps","some","step","reviewers","reviewer","identityId","map"],"sources":["listContentReviews.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow } from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\n\ninterface ListWorkflowsParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\nexport const listContentReviews = ({ apw, security }: ListWorkflowsParams) => {\n /**\n * We need to hook into listing the content review entries.\n * When listing content review entries, we need to check which ones current user can actually see.\n */\n apw.contentReview.onContentReviewBeforeList.subscribe(async ({ where }) => {\n /**\n * If there is workflowId_in attached on where, we will not change it.\n */\n if (where.workflowId_in) {\n return;\n }\n const identity = security.getIdentity();\n if (!identity?.id) {\n return;\n }\n /**\n * Find all available workflows.\n */\n const [workflows] = await apw.workflow.list();\n if (workflows.length === 0) {\n return;\n }\n /**\n * Find all workflows which user has access to.\n * User access is buried quite deep in the workflow data, so we need to do some traversing.\n */\n const userWorkflows = workflows.filter(workflow => {\n return workflow.steps.some(step => {\n return step.reviewers.some(reviewer => {\n return identity.id === reviewer.identityId;\n });\n });\n });\n if (userWorkflows.length === 0) {\n return;\n }\n /**\n * In the end, we need to attach the workflow filter by the entryId.\n * Just in case we add versioning at some point...\n */\n where.workflowId_in = userWorkflows.map(workflow => workflow.id);\n });\n};\n"],"mappings":";;;;;;;AASO,MAAMA,kBAAkB,GAAG,CAAC;EAAEC,GAAF;EAAOC;AAAP,CAAD,KAA4C;EAC1E;AACJ;AACA;AACA;EACID,GAAG,CAACE,aAAJ,CAAkBC,yBAAlB,CAA4CC,SAA5C,CAAsD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACvE;AACR;AACA;IACQ,IAAIA,KAAK,CAACC,aAAV,EAAyB;MACrB;IACH;;IACD,MAAMC,QAAQ,GAAGN,QAAQ,CAACO,WAAT,EAAjB;;IACA,IAAI,EAACD,QAAD,aAACA,QAAD,eAACA,QAAQ,CAAEE,EAAX,CAAJ,EAAmB;MACf;IACH;IACD;AACR;AACA;;;IACQ,MAAM,CAACC,SAAD,IAAc,MAAMV,GAAG,CAACW,QAAJ,CAAaC,IAAb,EAA1B;;IACA,IAAIF,SAAS,CAACG,MAAV,KAAqB,CAAzB,EAA4B;MACxB;IACH;IACD;AACR;AACA;AACA;;;IACQ,MAAMC,aAAa,GAAGJ,SAAS,CAACK,MAAV,CAAiBJ,QAAQ,IAAI;MAC/C,OAAOA,QAAQ,CAACK,KAAT,CAAeC,IAAf,CAAoBC,IAAI,IAAI;QAC/B,OAAOA,IAAI,CAACC,SAAL,CAAeF,IAAf,CAAoBG,QAAQ,IAAI;UACnC,OAAOb,QAAQ,CAACE,EAAT,KAAgBW,QAAQ,CAACC,UAAhC;QACH,CAFM,CAAP;MAGH,CAJM,CAAP;IAKH,CANqB,CAAtB;;IAOA,IAAIP,aAAa,CAACD,MAAd,KAAyB,CAA7B,EAAgC;MAC5B;IACH;IACD;AACR;AACA;AACA;;;IACQR,KAAK,CAACC,aAAN,GAAsBQ,aAAa,CAACQ,GAAd,CAAkBX,QAAQ,IAAIA,QAAQ,CAACF,EAAvC,CAAtB;EACH,CArCD;AAsCH,CA3CM"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const getAppUrl: (context: ApwContext) => Promise<import("@webiny/api-admin-settings/types").AdminSettings | null>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAppUrl = void 0;
7
+
8
+ const getAppUrl = async context => {
9
+ const tenant = context.tenancy.getCurrentTenant().id;
10
+
11
+ try {
12
+ return await context.settings.getSettings(tenant);
13
+ } catch (ex) {
14
+ if (ex.code !== "NOT_FOUND") {
15
+ throw ex;
16
+ }
17
+ }
18
+
19
+ return null;
20
+ };
21
+
22
+ exports.getAppUrl = getAppUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getAppUrl","context","tenant","tenancy","getCurrentTenant","id","settings","getSettings","ex","code"],"sources":["appUrl.ts"],"sourcesContent":["import { ApwContext } from \"~/types\";\n\nexport const getAppUrl = async (context: ApwContext) => {\n const tenant = context.tenancy.getCurrentTenant().id;\n try {\n return await context.settings.getSettings(tenant);\n } catch (ex) {\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n return null;\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,SAAS,GAAG,MAAOC,OAAP,IAA+B;EACpD,MAAMC,MAAM,GAAGD,OAAO,CAACE,OAAR,CAAgBC,gBAAhB,GAAmCC,EAAlD;;EACA,IAAI;IACA,OAAO,MAAMJ,OAAO,CAACK,QAAR,CAAiBC,WAAjB,CAA6BL,MAA7B,CAAb;EACH,CAFD,CAEE,OAAOM,EAAP,EAAW;IACT,IAAIA,EAAE,CAACC,IAAH,KAAY,WAAhB,EAA6B;MACzB,MAAMD,EAAN;IACH;EACJ;;EACD,OAAO,IAAP;AACH,CAVM"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachChangeRequestAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.attachChangeRequestAfterCreate = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _utils = require("../../utils");
13
+
14
+ var _contentUrl = require("./contentUrl");
15
+
16
+ var _sendChangeRequestNotification = require("./sendChangeRequestNotification");
17
+
18
+ var _reviewers = require("./reviewers");
19
+
20
+ var _changeRequestUrl = require("./changeRequestUrl");
21
+
22
+ var _appUrl = require("./appUrl");
23
+
24
+ const attachChangeRequestAfterCreate = context => {
25
+ context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({
26
+ changeRequest
27
+ }) => {
28
+ const execute = async () => {
29
+ const {
30
+ id: contentReviewId,
31
+ stepId
32
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
33
+
34
+ if (!stepId) {
35
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
36
+ step: changeRequest.step
37
+ });
38
+ }
39
+
40
+ const settings = await (0, _appUrl.getAppUrl)(context);
41
+
42
+ if (!settings) {
43
+ return;
44
+ }
45
+ /**
46
+ * We will check if we can create a comment url before we go digging further into the database.
47
+ */
48
+
49
+
50
+ const changeRequestUrl = (0, _changeRequestUrl.createChangeRequestUrl)({
51
+ baseUrl: settings.appUrl,
52
+ changeRequestId: changeRequest.id,
53
+ contentReviewId,
54
+ stepId
55
+ });
56
+
57
+ if (!changeRequestUrl) {
58
+ return;
59
+ }
60
+ /**
61
+ * Let's see if content review exists.
62
+ */
63
+
64
+
65
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
66
+
67
+ if (!contentReview) {
68
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
69
+ contentReviewId
70
+ });
71
+ }
72
+ /**
73
+ * We go and check the workflow.
74
+ */
75
+
76
+
77
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
78
+
79
+ if (!workflow) {
80
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
81
+ workflowId: contentReview.workflowId
82
+ });
83
+ }
84
+
85
+ const contentUrl = (0, _contentUrl.createContentUrl)({
86
+ plugins: context.plugins,
87
+ baseUrl: settings.appUrl,
88
+ contentReview,
89
+ workflow
90
+ });
91
+
92
+ if (!contentUrl) {
93
+ return;
94
+ }
95
+
96
+ const reviewers = await (0, _reviewers.fetchReviewers)({
97
+ context,
98
+ workflow,
99
+ exclude: [changeRequest.createdBy.id]
100
+ });
101
+
102
+ if (reviewers.length === 0) {
103
+ return;
104
+ }
105
+
106
+ try {
107
+ await (0, _sendChangeRequestNotification.sendChangeRequestNotification)({
108
+ context,
109
+ reviewers,
110
+ changeRequest,
111
+ contentReview,
112
+ workflow,
113
+ changeRequestUrl,
114
+ contentUrl
115
+ });
116
+ } catch (ex) {
117
+ throw new _error.default(`Could not send change request notifications.`, "CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT", {
118
+ workflowId: workflow.id,
119
+ changeRequestId: changeRequest.id,
120
+ contentReviewId,
121
+ changeRequestUrl,
122
+ contentUrl,
123
+ error: {
124
+ message: ex.message,
125
+ code: ex.code,
126
+ data: ex.data,
127
+ stack: ex.stack
128
+ }
129
+ });
130
+ }
131
+ };
132
+
133
+ try {
134
+ context.security.disableAuthorization();
135
+ await execute();
136
+ } catch (ex) {
137
+ throw ex;
138
+ } finally {
139
+ context.security.enableAuthorization();
140
+ }
141
+ });
142
+ };
143
+
144
+ exports.attachChangeRequestAfterCreate = attachChangeRequestAfterCreate;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["attachChangeRequestAfterCreate","context","apw","changeRequest","onChangeRequestAfterCreate","subscribe","execute","id","contentReviewId","stepId","extractContentReviewIdAndStep","step","WebinyError","settings","getAppUrl","changeRequestUrl","createChangeRequestUrl","baseUrl","appUrl","changeRequestId","contentReview","get","workflow","workflowId","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","length","sendChangeRequestNotification","ex","error","message","code","data","stack","security","disableAuthorization","enableAuthorization"],"sources":["changeRequestAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { sendChangeRequestNotification } from \"./sendChangeRequestNotification\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { createChangeRequestUrl } from \"./changeRequestUrl\";\nimport { getAppUrl } from \"~/plugins/hooks/notifications/appUrl\";\n\nexport const attachChangeRequestAfterCreate = (context: ApwContext): void => {\n context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({ changeRequest }) => {\n const execute = async () => {\n const { id: contentReviewId, stepId } = extractContentReviewIdAndStep(\n changeRequest.step\n );\n if (!stepId) {\n throw new WebinyError(\"Malformed changeRequest.step value.\", \"MALFORMED_VALUE\", {\n step: changeRequest.step\n });\n }\n\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n /**\n * We will check if we can create a comment url before we go digging further into the database.\n */\n const changeRequestUrl = createChangeRequestUrl({\n baseUrl: settings.appUrl,\n changeRequestId: changeRequest.id,\n contentReviewId,\n stepId\n });\n if (!changeRequestUrl) {\n return;\n }\n /**\n * Let's see if content review exists.\n */\n const contentReview = await context.apw.contentReview.get(contentReviewId);\n if (!contentReview) {\n throw new WebinyError(\n `There is no contentReview with id \"${contentReviewId}\".`,\n \"CONTENT_REVIEW_NOT_FOUND\",\n {\n contentReviewId\n }\n );\n }\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with workflowId \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [changeRequest.createdBy.id]\n });\n if (reviewers.length === 0) {\n return;\n }\n\n try {\n await sendChangeRequestNotification({\n context,\n reviewers,\n changeRequest,\n contentReview,\n workflow,\n changeRequestUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send change request notifications.`,\n \"CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT\",\n {\n workflowId: workflow.id,\n changeRequestId: changeRequest.id,\n contentReviewId,\n changeRequestUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n try {\n context.security.disableAuthorization();\n await execute();\n } catch (ex) {\n throw ex;\n } finally {\n context.security.enableAuthorization();\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,8BAA8B,GAAIC,OAAD,IAA+B;EACzEA,OAAO,CAACC,GAAR,CAAYC,aAAZ,CAA0BC,0BAA1B,CAAqDC,SAArD,CAA+D,OAAO;IAAEF;EAAF,CAAP,KAA6B;IACxF,MAAMG,OAAO,GAAG,YAAY;MACxB,MAAM;QAAEC,EAAE,EAAEC,eAAN;QAAuBC;MAAvB,IAAkC,IAAAC,oCAAA,EACpCP,aAAa,CAACQ,IADsB,CAAxC;;MAGA,IAAI,CAACF,MAAL,EAAa;QACT,MAAM,IAAIG,cAAJ,CAAgB,qCAAhB,EAAuD,iBAAvD,EAA0E;UAC5ED,IAAI,EAAER,aAAa,CAACQ;QADwD,CAA1E,CAAN;MAGH;;MAED,MAAME,QAAQ,GAAG,MAAM,IAAAC,iBAAA,EAAUb,OAAV,CAAvB;;MACA,IAAI,CAACY,QAAL,EAAe;QACX;MACH;MACD;AACZ;AACA;;;MACY,MAAME,gBAAgB,GAAG,IAAAC,wCAAA,EAAuB;QAC5CC,OAAO,EAAEJ,QAAQ,CAACK,MAD0B;QAE5CC,eAAe,EAAEhB,aAAa,CAACI,EAFa;QAG5CC,eAH4C;QAI5CC;MAJ4C,CAAvB,CAAzB;;MAMA,IAAI,CAACM,gBAAL,EAAuB;QACnB;MACH;MACD;AACZ;AACA;;;MACY,MAAMK,aAAa,GAAG,MAAMnB,OAAO,CAACC,GAAR,CAAYkB,aAAZ,CAA0BC,GAA1B,CAA8Bb,eAA9B,CAA5B;;MACA,IAAI,CAACY,aAAL,EAAoB;QAChB,MAAM,IAAIR,cAAJ,CACD,sCAAqCJ,eAAgB,I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,EAAE,CAACE,OADT;YAEHC,IAAI,EAAEH,EAAE,CAACG,IAFN;YAGHC,IAAI,EAAEJ,EAAE,CAACI,IAHN;YAIHC,KAAK,EAAEL,EAAE,CAACK;UAJP;QANX,CAHE,CAAN;MAiBH;IACJ,CArGD;;IAuGA,IAAI;MACArC,OAAO,CAACsC,QAAR,CAAiBC,oBAAjB;MACA,MAAMlC,OAAO,EAAb;IACH,CAHD,CAGE,OAAO2B,EAAP,EAAW;MACT,MAAMA,EAAN;IACH,CALD,SAKU;MACNhC,OAAO,CAACsC,QAAR,CAAiBE,mBAAjB;IACH;EACJ,CAhHD;AAiHH,CAlHM"}
@@ -0,0 +1,8 @@
1
+ interface Params {
2
+ baseUrl?: string;
3
+ changeRequestId: string;
4
+ contentReviewId: string;
5
+ stepId: string;
6
+ }
7
+ export declare const createChangeRequestUrl: (params: Params) => string | null;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createChangeRequestUrl = void 0;
7
+
8
+ const createChangeRequestUrl = params => {
9
+ /**
10
+ * All variables must exist for URL to be created.
11
+ * We go through all vars and throw a log if it does not exist.
12
+ */
13
+ for (const key in params) {
14
+ if (!!key) {
15
+ continue;
16
+ }
17
+
18
+ console.log(`Missing variable "${key}", which we use to create a comment URL.`);
19
+ return null;
20
+ }
21
+
22
+ const {
23
+ baseUrl,
24
+ changeRequestId,
25
+ contentReviewId,
26
+ stepId
27
+ } = params;
28
+ return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;
29
+ };
30
+
31
+ exports.createChangeRequestUrl = createChangeRequestUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createChangeRequestUrl","params","key","console","log","baseUrl","changeRequestId","contentReviewId","stepId"],"sources":["changeRequestUrl.ts"],"sourcesContent":["interface Params {\n baseUrl?: string;\n changeRequestId: string;\n contentReviewId: string;\n stepId: string;\n}\nexport const createChangeRequestUrl = (params: Params) => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a comment URL.`);\n return null;\n }\n const { baseUrl, changeRequestId, contentReviewId, stepId } = params;\n\n return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;\n};\n"],"mappings":";;;;;;;AAMO,MAAMA,sBAAsB,GAAIC,MAAD,IAAoB;EACtD;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAX,IAAkBD,MAAlB,EAA0B;IACtB,IAAI,CAAC,CAACC,GAAN,EAAW;MACP;IACH;;IACDC,OAAO,CAACC,GAAR,CAAa,qBAAoBF,GAAI,0CAArC;IACA,OAAO,IAAP;EACH;;EACD,MAAM;IAAEG,OAAF;IAAWC,eAAX;IAA4BC,eAA5B;IAA6CC;EAA7C,IAAwDP,MAA9D;EAEA,OAAQ,GAAEI,OAAQ,wBAAuBE,eAAgB,IAAGC,MAAO,IAAGF,eAAgB,EAAtF;AACH,CAfM"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachCommentAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.attachCommentAfterCreate = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _utils = require("../../utils");
13
+
14
+ var _contentUrl = require("./contentUrl");
15
+
16
+ var _commentUrl = require("./commentUrl");
17
+
18
+ var _reviewers = require("./reviewers");
19
+
20
+ var _sendCommentNotification = require("./sendCommentNotification");
21
+
22
+ var _appUrl = require("./appUrl");
23
+
24
+ const attachCommentAfterCreate = context => {
25
+ context.apw.comment.onCommentAfterCreate.subscribe(async ({
26
+ comment
27
+ }) => {
28
+ const execute = async () => {
29
+ const changeRequest = await context.apw.changeRequest.get(comment.changeRequest);
30
+
31
+ if (!changeRequest) {
32
+ throw new _error.default("Missing change request.", "CHANGE_REQUEST_NOT_FOUND", {
33
+ changeRequest: comment.changeRequest,
34
+ comment: comment.id
35
+ });
36
+ }
37
+
38
+ const {
39
+ id: contentReviewId,
40
+ stepId
41
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
42
+
43
+ if (!stepId) {
44
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
45
+ step: changeRequest.step
46
+ });
47
+ }
48
+
49
+ const settings = await (0, _appUrl.getAppUrl)(context);
50
+
51
+ if (!settings) {
52
+ return;
53
+ }
54
+ /**
55
+ * We will check if we can create a comment url before we go digging further into the database.
56
+ */
57
+
58
+
59
+ const commentUrl = (0, _commentUrl.createCommentUrl)({
60
+ baseUrl: settings.appUrl,
61
+ changeRequestId: changeRequest.id,
62
+ contentReviewId,
63
+ stepId
64
+ });
65
+
66
+ if (!commentUrl) {
67
+ console.log("No comment url.");
68
+ return;
69
+ }
70
+ /**
71
+ * Let's see if content review exists.
72
+ */
73
+
74
+
75
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
76
+
77
+ if (!contentReview) {
78
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
79
+ contentReviewId
80
+ });
81
+ }
82
+ /**
83
+ * We go and check the workflow.
84
+ */
85
+
86
+
87
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
88
+
89
+ if (!workflow) {
90
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
91
+ workflowId: contentReview.workflowId
92
+ });
93
+ }
94
+
95
+ const contentUrl = (0, _contentUrl.createContentUrl)({
96
+ plugins: context.plugins,
97
+ baseUrl: settings.appUrl,
98
+ contentReview,
99
+ workflow
100
+ });
101
+
102
+ if (!contentUrl) {
103
+ console.log("No content url.");
104
+ return;
105
+ }
106
+
107
+ const reviewers = await (0, _reviewers.fetchReviewers)({
108
+ context,
109
+ workflow,
110
+ exclude: [comment.createdBy.id]
111
+ });
112
+
113
+ if (reviewers.length === 0) {
114
+ console.log("No reviewers to send the e-mail notification to.");
115
+ return;
116
+ }
117
+
118
+ try {
119
+ await (0, _sendCommentNotification.sendCommentNotification)({
120
+ context,
121
+ reviewers,
122
+ changeRequest,
123
+ contentReview,
124
+ workflow,
125
+ commentUrl,
126
+ contentUrl
127
+ });
128
+ } catch (ex) {
129
+ throw new _error.default(`Could not send comment notifications.`, "COMMENT_NOTIFICATIONS_NOT_SENT", {
130
+ commentId: comment.id,
131
+ workflowId: workflow.id,
132
+ changeRequestId: changeRequest.id,
133
+ contentReviewId,
134
+ commentUrl,
135
+ contentUrl,
136
+ error: {
137
+ message: ex.message,
138
+ code: ex.code,
139
+ data: ex.data,
140
+ stack: ex.stack
141
+ }
142
+ });
143
+ }
144
+ };
145
+
146
+ try {
147
+ context.security.disableAuthorization();
148
+ await execute();
149
+ } catch (ex) {
150
+ throw ex;
151
+ } finally {
152
+ context.security.enableAuthorization();
153
+ }
154
+ });
155
+ };
156
+
157
+ exports.attachCommentAfterCreate = attachCommentAfterCreate;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["attachCommentAfterCreate","context","apw","comment","onCommentAfterCreate","subscribe","execute","changeRequest","get","WebinyError","id","contentReviewId","stepId","extractContentReviewIdAndStep","step","settings","getAppUrl","commentUrl","createCommentUrl","baseUrl","appUrl","changeRequestId","console","log","contentReview","workflow","workflowId","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","length","sendCommentNotification","ex","commentId","error","message","code","data","stack","security","disableAuthorization","enableAuthorization"],"sources":["commentAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { createCommentUrl } from \"./commentUrl\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { sendCommentNotification } from \"./sendCommentNotification\";\nimport { getAppUrl } from \"~/plugins/hooks/notifications/appUrl\";\n\nexport const attachCommentAfterCreate = (context: ApwContext): void => {\n context.apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n const execute = async () => {\n const changeRequest = await context.apw.changeRequest.get(comment.changeRequest);\n if (!changeRequest) {\n throw new WebinyError(\"Missing change request.\", \"CHANGE_REQUEST_NOT_FOUND\", {\n changeRequest: comment.changeRequest,\n comment: comment.id\n });\n }\n\n const { id: contentReviewId, stepId } = extractContentReviewIdAndStep(\n changeRequest.step\n );\n if (!stepId) {\n throw new WebinyError(\"Malformed changeRequest.step value.\", \"MALFORMED_VALUE\", {\n step: changeRequest.step\n });\n }\n\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n /**\n * We will check if we can create a comment url before we go digging further into the database.\n */\n const commentUrl = createCommentUrl({\n baseUrl: settings.appUrl,\n changeRequestId: changeRequest.id,\n contentReviewId,\n stepId\n });\n if (!commentUrl) {\n console.log(\"No comment url.\");\n return;\n }\n /**\n * Let's see if content review exists.\n */\n const contentReview = await context.apw.contentReview.get(contentReviewId);\n if (!contentReview) {\n throw new WebinyError(\n `There is no contentReview with id \"${contentReviewId}\".`,\n \"CONTENT_REVIEW_NOT_FOUND\",\n {\n contentReviewId\n }\n );\n }\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with workflowId \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n console.log(\"No content url.\");\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [comment.createdBy.id]\n });\n\n if (reviewers.length === 0) {\n console.log(\"No reviewers to send the e-mail notification to.\");\n return;\n }\n\n try {\n await sendCommentNotification({\n context,\n reviewers,\n changeRequest,\n contentReview,\n workflow,\n commentUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send comment notifications.`,\n \"COMMENT_NOTIFICATIONS_NOT_SENT\",\n {\n commentId: comment.id,\n workflowId: workflow.id,\n changeRequestId: changeRequest.id,\n contentReviewId,\n commentUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n try {\n context.security.disableAuthorization();\n await execute();\n } catch (ex) {\n throw ex;\n } finally {\n context.security.enableAuthorization();\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,wBAAwB,GAAIC,OAAD,IAA+B;EACnEA,OAAO,CAACC,GAAR,CAAYC,OAAZ,CAAoBC,oBAApB,CAAyCC,SAAzC,CAAmD,OAAO;IAAEF;EAAF,CAAP,KAAuB;IACtE,MAAMG,OAAO,GAAG,YAAY;MACxB,MAAMC,aAAa,GAAG,MAAMN,OAAO,CAACC,GAAR,CAAYK,aAAZ,CAA0BC,GAA1B,CAA8BL,OAAO,CAACI,aAAtC,CAA5B;;MACA,IAAI,CAACA,aAAL,EAAoB;QAChB,MAAM,IAAIE,cAAJ,CAAgB,yBAAhB,EAA2C,0BAA3C,EAAuE;UACzEF,aAAa,EAAEJ,OAAO,CAACI,aADkD;UAEzEJ,OAAO,EAAEA,OAAO,CAACO;QAFwD,CAAvE,CAAN;MAIH;;MAED,MAAM;QAAEA,EAAE,EAAEC,eAAN;QAAuBC;MAAvB,IAAkC,IAAAC,oCAAA,EACpCN,aAAa,CAACO,IADsB,CAAxC;;MAGA,IAAI,CAACF,MAAL,EAAa;QACT,MAAM,IAAIH,cAAJ,CAAgB,qCAAhB,EAAuD,iBAAvD,EAA0E;UA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 changeRequestId: string;
4
+ contentReviewId: string;
5
+ stepId: string;
6
+ }
7
+ export declare const createCommentUrl: (params: CreateCommentUrlParams) => string | null;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCommentUrl = void 0;
7
+
8
+ const createCommentUrl = params => {
9
+ /**
10
+ * All variables must exist for URL to be created.
11
+ * We go through all vars and throw a log if it does not exist.
12
+ */
13
+ for (const key in params) {
14
+ if (!!key) {
15
+ continue;
16
+ }
17
+
18
+ console.log(`Missing variable "${key}", which we use to create a comment URL.`);
19
+ return null;
20
+ }
21
+
22
+ const {
23
+ baseUrl,
24
+ changeRequestId,
25
+ contentReviewId,
26
+ stepId
27
+ } = params;
28
+ return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;
29
+ };
30
+
31
+ exports.createCommentUrl = createCommentUrl;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createCommentUrl","params","key","console","log","baseUrl","changeRequestId","contentReviewId","stepId"],"sources":["commentUrl.ts"],"sourcesContent":["interface CreateCommentUrlParams {\n baseUrl?: string;\n changeRequestId: string;\n contentReviewId: string;\n stepId: string;\n}\nexport const createCommentUrl = (params: CreateCommentUrlParams): string | null => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a comment URL.`);\n return null;\n }\n const { baseUrl, changeRequestId, contentReviewId, stepId } = params;\n\n return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;\n};\n"],"mappings":";;;;;;;AAMO,MAAMA,gBAAgB,GAAIC,MAAD,IAAmD;EAC/E;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAX,IAAkBD,MAAlB,EAA0B;IACtB,IAAI,CAAC,CAACC,GAAN,EAAW;MACP;IACH;;IACDC,OAAO,CAACC,GAAR,CAAa,qBAAoBF,GAAI,0CAArC;IACA,OAAO,IAAP;EACH;;EACD,MAAM;IAAEG,OAAF;IAAWC,eAAX;IAA4BC,eAA5B;IAA6CC;EAA7C,IAAwDP,MAA9D;EAEA,OAAQ,GAAEI,OAAQ,wBAAuBE,eAAgB,IAAGC,MAAO,IAAGF,eAAgB,EAAtF;AACH,CAfM"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachContentReviewAfterCreate: (context: ApwContext) => void;