@webiny/api-apw 5.39.0-beta.1 → 5.39.0-beta.3

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 (133) hide show
  1. package/ApwChangeRequestNotification.js +1 -5
  2. package/ApwChangeRequestNotification.js.map +1 -1
  3. package/ApwCommentNotification.js +1 -5
  4. package/ApwCommentNotification.js.map +1 -1
  5. package/ApwContentReviewNotification.js +1 -5
  6. package/ApwContentReviewNotification.js.map +1 -1
  7. package/ApwContentUrlPlugin.js +1 -5
  8. package/ApwContentUrlPlugin.js.map +1 -1
  9. package/ContentApwSettingsPlugin.js +3 -4
  10. package/ContentApwSettingsPlugin.js.map +1 -1
  11. package/crud/createContentReviewMethods.js +37 -28
  12. package/crud/createContentReviewMethods.js.map +1 -1
  13. package/crud/index.js +3 -4
  14. package/crud/index.js.map +1 -1
  15. package/crud/utils.js +4 -5
  16. package/crud/utils.js.map +1 -1
  17. package/index.d.ts +1 -1
  18. package/package.json +27 -27
  19. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +2 -4
  20. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  21. package/plugins/cms/apwEntryPlugins.js +6 -5
  22. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  23. package/plugins/cms/linkContentReviewToEntry.js +1 -2
  24. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  25. package/plugins/cms/linkWorkflowToEntry.js +6 -9
  26. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  27. package/plugins/cms/triggerContentReview.js +2 -3
  28. package/plugins/cms/triggerContentReview.js.map +1 -1
  29. package/plugins/cms/updateContentReviewStatus.js +10 -10
  30. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  31. package/plugins/cms/utils.d.ts +1 -1
  32. package/plugins/cms/utils.js +5 -6
  33. package/plugins/cms/utils.js.map +1 -1
  34. package/plugins/graphql/changeRequest.gql.js +13 -11
  35. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  36. package/plugins/graphql/comment.gql.js +38 -34
  37. package/plugins/graphql/comment.gql.js.map +1 -1
  38. package/plugins/graphql/contentReview.gql.js +20 -12
  39. package/plugins/graphql/contentReview.gql.js.map +1 -1
  40. package/plugins/graphql/reviewer.gql.js +12 -11
  41. package/plugins/graphql/reviewer.gql.js.map +1 -1
  42. package/plugins/graphql/utils.d.ts +2 -0
  43. package/plugins/graphql/utils.js +12 -0
  44. package/plugins/graphql/utils.js.map +1 -0
  45. package/plugins/graphql/workflow.gql.js +12 -11
  46. package/plugins/graphql/workflow.gql.js.map +1 -1
  47. package/plugins/hooks/createReviewerFromIdentity.js +1 -1
  48. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  49. package/plugins/hooks/initializeContentReviewSteps.js +3 -3
  50. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  51. package/plugins/hooks/listContentReviews.js +1 -1
  52. package/plugins/hooks/listContentReviews.js.map +1 -1
  53. package/plugins/hooks/notifications/contentReviewAfterCreate.js +1 -1
  54. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  55. package/plugins/hooks/updatePendingChangeRequests.js +5 -5
  56. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  57. package/plugins/hooks/updateTotalComments.js +19 -14
  58. package/plugins/hooks/updateTotalComments.js.map +1 -1
  59. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +2 -4
  60. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  61. package/plugins/pageBuilder/linkContentReviewToPage.js +13 -11
  62. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  63. package/plugins/pageBuilder/updateContentReviewStatus.js +8 -5
  64. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  65. package/plugins/pageBuilder/utils.d.ts +2 -2
  66. package/plugins/pageBuilder/utils.js.map +1 -1
  67. package/plugins/utils.d.ts +1 -1
  68. package/plugins/utils.js +3 -2
  69. package/plugins/utils.js.map +1 -1
  70. package/scheduler/createScheduleActionMethods.js +39 -22
  71. package/scheduler/createScheduleActionMethods.js.map +1 -1
  72. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  73. package/scheduler/handlers/executeAction/index.js +2 -3
  74. package/scheduler/handlers/executeAction/index.js.map +1 -1
  75. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +3 -4
  76. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  77. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +3 -6
  78. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  79. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +1 -6
  80. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  81. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  82. package/scheduler/handlers/scheduleAction/index.js +9 -8
  83. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  84. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +14 -13
  85. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  86. package/scheduler/handlers/utils.d.ts +2 -3
  87. package/scheduler/handlers/utils.js +3 -6
  88. package/scheduler/handlers/utils.js.map +1 -1
  89. package/scheduler/types.d.ts +8 -5
  90. package/scheduler/types.js.map +1 -1
  91. package/storageOperations/changeRequestStorageOperations.js +15 -11
  92. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  93. package/storageOperations/commentStorageOperations.js +12 -10
  94. package/storageOperations/commentStorageOperations.js.map +1 -1
  95. package/storageOperations/contentReviewStorageOperations.d.ts +1 -1
  96. package/storageOperations/contentReviewStorageOperations.js +15 -11
  97. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  98. package/storageOperations/index.d.ts +1 -7
  99. package/storageOperations/index.js +8 -15
  100. package/storageOperations/index.js.map +1 -1
  101. package/storageOperations/models/changeRequest.model.d.ts +1 -2
  102. package/storageOperations/models/changeRequest.model.js +4 -6
  103. package/storageOperations/models/changeRequest.model.js.map +1 -1
  104. package/storageOperations/models/comment.model.d.ts +1 -2
  105. package/storageOperations/models/comment.model.js +4 -6
  106. package/storageOperations/models/comment.model.js.map +1 -1
  107. package/storageOperations/models/contentReview.model.d.ts +1 -2
  108. package/storageOperations/models/contentReview.model.js +9 -9
  109. package/storageOperations/models/contentReview.model.js.map +1 -1
  110. package/storageOperations/models/index.js +3 -23
  111. package/storageOperations/models/index.js.map +1 -1
  112. package/storageOperations/models/reviewer.model.d.ts +1 -2
  113. package/storageOperations/models/reviewer.model.js +5 -7
  114. package/storageOperations/models/reviewer.model.js.map +1 -1
  115. package/storageOperations/models/workflow.model.d.ts +1 -2
  116. package/storageOperations/models/workflow.model.js +12 -12
  117. package/storageOperations/models/workflow.model.js.map +1 -1
  118. package/storageOperations/reviewerStorageOperations.d.ts +1 -1
  119. package/storageOperations/reviewerStorageOperations.js +15 -11
  120. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  121. package/storageOperations/workflowStorageOperations.js +20 -14
  122. package/storageOperations/workflowStorageOperations.js.map +1 -1
  123. package/types.d.ts +15 -14
  124. package/types.js.map +1 -1
  125. package/utils/fieldResolver.js +4 -6
  126. package/utils/fieldResolver.js.map +1 -1
  127. package/utils/pickEntryFieldValues.d.ts +3 -0
  128. package/utils/pickEntryFieldValues.js +31 -0
  129. package/utils/pickEntryFieldValues.js.map +1 -0
  130. package/utils/resolve.d.ts +1 -1
  131. package/storageOperations/models/contentModelPluginFactory.d.ts +0 -8
  132. package/storageOperations/models/contentModelPluginFactory.js +0 -22
  133. package/storageOperations/models/contentModelPluginFactory.js.map +0 -1
package/crud/utils.js CHANGED
@@ -7,11 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META = void 0;
8
8
  exports.checkValidDateTime = checkValidDateTime;
9
9
  exports.getPendingRequiredSteps = exports.filterContentReviewsByRequiresMyAttention = void 0;
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
10
  var _error = _interopRequireDefault(require("@webiny/error"));
12
11
  var _dayjs = _interopRequireDefault(require("dayjs"));
13
12
  var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
14
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
15
13
  var _set = _interopRequireDefault(require("lodash/set"));
16
14
  var _types = require("../types");
17
15
  _dayjs.default.extend(_utc.default);
@@ -69,7 +67,7 @@ const filterContentReviewsByRequiresMyAttention = async params => {
69
67
  /**
70
68
  * Get all "content reviews" with status "underReview"
71
69
  */
72
- const newListParams = (0, _set.default)((0, _cloneDeep.default)(listParams), "where.reviewStatus", _types.ApwContentReviewStatus.UNDER_REVIEW);
70
+ const newListParams = (0, _set.default)(structuredClone(listParams), "where.reviewStatus", _types.ApwContentReviewStatus.UNDER_REVIEW);
73
71
  const [contentReviews, meta] = await listContentReviews(newListParams);
74
72
  const identity = getIdentity();
75
73
  const filteredItems = [];
@@ -103,9 +101,10 @@ const filterContentReviewsByRequiresMyAttention = async params => {
103
101
  filteredItems.push(contentReview);
104
102
  }
105
103
  }
106
- return [filteredItems, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, meta), {}, {
104
+ return [filteredItems, {
105
+ ...meta,
107
106
  totalCount: filteredItems.length
108
- })];
107
+ }];
109
108
  };
110
109
  exports.filterContentReviewsByRequiresMyAttention = filterContentReviewsByRequiresMyAttention;
111
110
 
package/crud/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_dayjs","_utc","_cloneDeep","_set","_types","dayjs","extend","utc","checkValidDateTime","datetime","isValid","Error","message","code","data","today","isBefore","getPendingRequiredSteps","steps","predicate","filter","step","isRequiredStep","ApwWorkflowStepTypes","MANDATORY_BLOCKING","MANDATORY_NON_BLOCKING","includes","type","exports","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","scheduledOn","scheduledBy","scheduledActionId","filterContentReviewsByRequiresMyAttention","params","listContentReviews","listParams","getIdentity","getReviewer","newListParams","set","cloneDeep","ApwContentReviewStatus","UNDER_REVIEW","contentReviews","meta","identity","filteredItems","i","length","contentReview","activeStep","find","status","ApwContentReviewStepStatus","ACTIVE","requiresMyAttention","j","reviewers","id","reviewer","identityId","push","_objectSpread2","default","totalCount"],"sources":["utils.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport cloneDeep from \"lodash/cloneDeep\";\nimport set from \"lodash/set\";\nimport {\n ApwContentReview,\n ApwContentReviewListParams,\n ApwContentReviewStatus,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwWorkflowStepTypes,\n ListMeta\n} from \"~/types\";\nimport { CreateContentReviewMethodsParams } from \"./createContentReviewMethods\";\n\ndayjs.extend(utc);\n\nexport function checkValidDateTime(datetime: string | undefined): void {\n if (typeof datetime !== \"string\") {\n return;\n }\n\n if (!dayjs(datetime).isValid()) {\n throw new Error({\n message: `Invalid input \"datetime\" should be an ISO string.`,\n code: \"INVALID_DATETIME_FORMAT\",\n data: {\n datetime\n }\n });\n }\n const today = dayjs.utc();\n\n if (dayjs(datetime).isBefore(today)) {\n throw new Error({\n message: `Cannot schedule for a past \"datetime\".`,\n code: \"PAST_DATETIME\",\n data: {\n datetime\n }\n });\n }\n}\n\nexport interface GetPendingRequiredSteps {\n (\n steps: ApwContentReviewStep[],\n predicate: (step: ApwContentReviewStep) => boolean\n ): ApwContentReviewStep[];\n}\n\nexport const getPendingRequiredSteps: GetPendingRequiredSteps = (steps, predicate) => {\n return steps.filter(step => {\n const isRequiredStep = [\n ApwWorkflowStepTypes.MANDATORY_BLOCKING,\n ApwWorkflowStepTypes.MANDATORY_NON_BLOCKING\n ].includes(step.type);\n\n if (!isRequiredStep) {\n return false;\n }\n\n return predicate(step);\n });\n};\n\nexport const INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META = {\n scheduledOn: null,\n scheduledBy: null,\n scheduledActionId: null\n};\n\nexport interface FilterContentReviewsParams\n extends Pick<CreateContentReviewMethodsParams, \"getReviewer\" | \"getIdentity\"> {\n listParams: ApwContentReviewListParams;\n listContentReviews: CreateContentReviewMethodsParams[\"storageOperations\"][\"listContentReviews\"];\n}\n\n/**\n * Filter \"content reviews\" that are \"underReview\" and current user is a reviewer for the active step.\n * That is the user is able to provide sign-off or comment.\n */\nexport const filterContentReviewsByRequiresMyAttention = async (\n params: FilterContentReviewsParams\n): Promise<[ApwContentReview[], ListMeta]> => {\n const { listContentReviews, listParams, getIdentity, getReviewer } = params;\n /**\n * Get all \"content reviews\" with status \"underReview\"\n */\n const newListParams = set(\n cloneDeep(listParams),\n \"where.reviewStatus\",\n ApwContentReviewStatus.UNDER_REVIEW\n );\n const [contentReviews, meta] = await listContentReviews(newListParams);\n\n const identity = getIdentity();\n const filteredItems = [];\n /**\n * Filter items where current user is a reviewer for the active step.\n */\n for (let i = 0; i < contentReviews.length; i++) {\n const contentReview = contentReviews[i];\n\n const activeStep = contentReview.steps.find(\n step => step.status === ApwContentReviewStepStatus.ACTIVE\n );\n\n if (!activeStep) {\n continue;\n }\n\n let requiresMyAttention = false;\n\n for (let j = 0; j < activeStep.reviewers.length; j++) {\n const { id } = activeStep.reviewers[j];\n /**\n * Load reviewer\n */\n const reviewer = await getReviewer(id);\n /**\n * Check if the current logged in user is the reviewer.\n */\n if (reviewer.identityId === identity.id) {\n requiresMyAttention = true;\n break;\n }\n }\n\n if (requiresMyAttention) {\n filteredItems.push(contentReview);\n }\n }\n\n return [\n filteredItems,\n {\n ...meta,\n totalCount: filteredItems.length\n }\n ];\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,IAAA,GAAAH,sBAAA,CAAAC,OAAA;A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AIC,QAAQ,CAACC,UAAU,KAAKf,QAAQ,CAACa,EAAE,EAAE;QACrCH,mBAAmB,GAAG,IAAI;QAC1B;MACJ;IACJ;IAEA,IAAIA,mBAAmB,EAAE;MACrBT,aAAa,CAACe,IAAI,CAACZ,aAAa,CAAC;IACrC;EACJ;EAEA,OAAO,CACHH,aAAa,MAAAgB,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MAENnB,IAAI;IACPoB,UAAU,EAAElB,aAAa,CAACE;EAAM,GAEvC;AACL,CAAC;AAACrB,OAAA,CAAAK,yCAAA,GAAAA,yCAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_dayjs","_utc","_set","_types","dayjs","extend","utc","checkValidDateTime","datetime","isValid","Error","message","code","data","today","isBefore","getPendingRequiredSteps","steps","predicate","filter","step","isRequiredStep","ApwWorkflowStepTypes","MANDATORY_BLOCKING","MANDATORY_NON_BLOCKING","includes","type","exports","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","scheduledOn","scheduledBy","scheduledActionId","filterContentReviewsByRequiresMyAttention","params","listContentReviews","listParams","getIdentity","getReviewer","newListParams","set","structuredClone","ApwContentReviewStatus","UNDER_REVIEW","contentReviews","meta","identity","filteredItems","i","length","contentReview","activeStep","find","status","ApwContentReviewStepStatus","ACTIVE","requiresMyAttention","j","reviewers","id","reviewer","identityId","push","totalCount"],"sources":["utils.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport set from \"lodash/set\";\nimport {\n ApwContentReview,\n ApwContentReviewListParams,\n ApwContentReviewStatus,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwWorkflowStepTypes,\n ListMeta\n} from \"~/types\";\nimport { CreateContentReviewMethodsParams } from \"./createContentReviewMethods\";\n\ndayjs.extend(utc);\n\nexport function checkValidDateTime(datetime: string | undefined): void {\n if (typeof datetime !== \"string\") {\n return;\n }\n\n if (!dayjs(datetime).isValid()) {\n throw new Error({\n message: `Invalid input \"datetime\" should be an ISO string.`,\n code: \"INVALID_DATETIME_FORMAT\",\n data: {\n datetime\n }\n });\n }\n const today = dayjs.utc();\n\n if (dayjs(datetime).isBefore(today)) {\n throw new Error({\n message: `Cannot schedule for a past \"datetime\".`,\n code: \"PAST_DATETIME\",\n data: {\n datetime\n }\n });\n }\n}\n\nexport interface GetPendingRequiredSteps {\n (\n steps: ApwContentReviewStep[],\n predicate: (step: ApwContentReviewStep) => boolean\n ): ApwContentReviewStep[];\n}\n\nexport const getPendingRequiredSteps: GetPendingRequiredSteps = (steps, predicate) => {\n return steps.filter(step => {\n const isRequiredStep = [\n ApwWorkflowStepTypes.MANDATORY_BLOCKING,\n ApwWorkflowStepTypes.MANDATORY_NON_BLOCKING\n ].includes(step.type);\n\n if (!isRequiredStep) {\n return false;\n }\n\n return predicate(step);\n });\n};\n\nexport const INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META = {\n scheduledOn: null,\n scheduledBy: null,\n scheduledActionId: null\n};\n\nexport interface FilterContentReviewsParams\n extends Pick<CreateContentReviewMethodsParams, \"getReviewer\" | \"getIdentity\"> {\n listParams: ApwContentReviewListParams;\n listContentReviews: CreateContentReviewMethodsParams[\"storageOperations\"][\"listContentReviews\"];\n}\n\n/**\n * Filter \"content reviews\" that are \"underReview\" and current user is a reviewer for the active step.\n * That is the user is able to provide sign-off or comment.\n */\nexport const filterContentReviewsByRequiresMyAttention = async (\n params: FilterContentReviewsParams\n): Promise<[ApwContentReview[], ListMeta]> => {\n const { listContentReviews, listParams, getIdentity, getReviewer } = params;\n /**\n * Get all \"content reviews\" with status \"underReview\"\n */\n const newListParams = set(\n structuredClone(listParams),\n \"where.reviewStatus\",\n ApwContentReviewStatus.UNDER_REVIEW\n );\n const [contentReviews, meta] = await listContentReviews(newListParams);\n\n const identity = getIdentity();\n const filteredItems = [];\n /**\n * Filter items where current user is a reviewer for the active step.\n */\n for (let i = 0; i < contentReviews.length; i++) {\n const contentReview = contentReviews[i];\n\n const activeStep = contentReview.steps.find(\n step => step.status === ApwContentReviewStepStatus.ACTIVE\n );\n\n if (!activeStep) {\n continue;\n }\n\n let requiresMyAttention = false;\n\n for (let j = 0; j < activeStep.reviewers.length; j++) {\n const { id } = activeStep.reviewers[j];\n /**\n * Load reviewer\n */\n const reviewer = await getReviewer(id);\n /**\n * Check if the current logged in user is the reviewer.\n */\n if (reviewer.identityId === identity.id) {\n requiresMyAttention = true;\n break;\n }\n }\n\n if (requiresMyAttention) {\n filteredItems.push(contentReview);\n }\n }\n\n return [\n filteredItems,\n {\n ...meta,\n totalCount: filteredItems.length\n }\n ];\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,IAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,IAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAWAK,cAAK,CAACC,MAAM,CAACC,YAAG,CAAC;AAEV,SAASC,kBAAkBA,CAACC,QAA4B,EAAQ;EACnE,IAAI,OAAOA,QAAQ,KAAK,QAAQ,EAAE;IAC9B;EACJ;EAEA,IAAI,CAAC,IAAAJ,cAAK,EAACI,QAAQ,CAAC,CAACC,OAAO,CAAC,CAAC,EAAE;IAC5B,MAAM,IAAIC,cAAK,CAAC;MACZC,OAAO,EAAG,mDAAkD;MAC5DC,IAAI,EAAE,yBAAyB;MAC/BC,IAAI,EAAE;QACFL;MACJ;IACJ,CAAC,CAAC;EACN;EACA,MAAMM,KAAK,GAAGV,cAAK,CAACE,GAAG,CAAC,CAAC;EAEzB,IAAI,IAAAF,cAAK,EAACI,QAAQ,CAAC,CAACO,QAAQ,CAACD,KAAK,CAAC,EAAE;IACjC,MAAM,IAAIJ,cAAK,CAAC;MACZC,OAAO,EAAG,wCAAuC;MACjDC,IA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GN,cAAc,CAACI,CAAC,CAAC;IAEvC,MAAMG,UAAU,GAAGD,aAAa,CAAChC,KAAK,CAACkC,IAAI,CACvC/B,IAAI,IAAIA,IAAI,CAACgC,MAAM,KAAKC,iCAA0B,CAACC,MACvD,CAAC;IAED,IAAI,CAACJ,UAAU,EAAE;MACb;IACJ;IAEA,IAAIK,mBAAmB,GAAG,KAAK;IAE/B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,UAAU,CAACO,SAAS,CAACT,MAAM,EAAEQ,CAAC,EAAE,EAAE;MAClD,MAAM;QAAEE;MAAG,CAAC,GAAGR,UAAU,CAACO,SAAS,CAACD,CAAC,CAAC;MACtC;AACZ;AACA;MACY,MAAMG,QAAQ,GAAG,MAAMtB,WAAW,CAACqB,EAAE,CAAC;MACtC;AACZ;AACA;MACY,IAAIC,QAAQ,CAACC,UAAU,KAAKf,QAAQ,CAACa,EAAE,EAAE;QACrCH,mBAAmB,GAAG,IAAI;QAC1B;MACJ;IACJ;IAEA,IAAIA,mBAAmB,EAAE;MACrBT,aAAa,CAACe,IAAI,CAACZ,aAAa,CAAC;IACrC;EACJ;EAEA,OAAO,CACHH,aAAa,EACb;IACI,GAAGF,IAAI;IACPkB,UAAU,EAAEhB,aAAa,CAACE;EAC9B,CAAC,CACJ;AACL,CAAC;AAACrB,OAAA,CAAAK,yCAAA,GAAAA,yCAAA"}
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { CreateApwContextParams } from "./scheduler/types";
2
- export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => (import("@webiny/api").ContextPlugin<import("./types").ApwContext> | import("@webiny/plugins/types").Plugin<Record<string, any>> | import("@webiny/plugins/types").PluginCollection | import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("@webiny/api-mailer/types").MailerContext>)[];
2
+ export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => (import("@webiny/plugins/types").Plugin<Record<string, any>> | import("@webiny/plugins/types").PluginFactory | import("@webiny/plugins/types").PluginCollection | import("@webiny/api").ContextPlugin<import("./types").ApwContext> | import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("@webiny/api-mailer/types").MailerContext>)[];
3
3
  export declare const createApwGraphQL: () => import("@webiny/api").ContextPlugin<import("./types").ApwContext>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-apw",
3
- "version": "5.39.0-beta.1",
3
+ "version": "5.39.0-beta.3",
4
4
  "keywords": [
5
5
  "apw:base"
6
6
  ],
@@ -14,29 +14,29 @@
14
14
  "author": "Webiny Ltd",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@aws-sdk/client-cloudwatch-events": "3.54.1",
18
17
  "@babel/runtime": "7.22.6",
19
18
  "@commodo/fields": "1.1.2-beta.20",
20
- "@webiny/api": "5.39.0-beta.1",
21
- "@webiny/api-admin-settings": "5.39.0-beta.1",
22
- "@webiny/api-headless-cms": "5.39.0-beta.1",
23
- "@webiny/api-i18n": "5.39.0-beta.1",
24
- "@webiny/api-mailer": "5.39.0-beta.1",
25
- "@webiny/api-page-builder": "5.39.0-beta.1",
26
- "@webiny/api-security": "5.39.0-beta.1",
27
- "@webiny/api-tenancy": "5.39.0-beta.1",
28
- "@webiny/api-wcp": "5.39.0-beta.1",
29
- "@webiny/db-dynamodb": "5.39.0-beta.1",
30
- "@webiny/error": "5.39.0-beta.1",
31
- "@webiny/handler": "5.39.0-beta.1",
32
- "@webiny/handler-client": "5.39.0-beta.1",
33
- "@webiny/handler-db": "5.39.0-beta.1",
34
- "@webiny/handler-graphql": "5.39.0-beta.1",
35
- "@webiny/handler-logs": "5.39.0-beta.1",
36
- "@webiny/plugins": "5.39.0-beta.1",
37
- "@webiny/pubsub": "5.39.0-beta.1",
38
- "@webiny/utils": "5.39.0-beta.1",
39
- "@webiny/validation": "5.39.0-beta.1",
19
+ "@webiny/api": "5.39.0-beta.3",
20
+ "@webiny/api-admin-settings": "5.39.0-beta.3",
21
+ "@webiny/api-headless-cms": "5.39.0-beta.3",
22
+ "@webiny/api-i18n": "5.39.0-beta.3",
23
+ "@webiny/api-mailer": "5.39.0-beta.3",
24
+ "@webiny/api-page-builder": "5.39.0-beta.3",
25
+ "@webiny/api-security": "5.39.0-beta.3",
26
+ "@webiny/api-tenancy": "5.39.0-beta.3",
27
+ "@webiny/api-wcp": "5.39.0-beta.3",
28
+ "@webiny/aws-sdk": "5.39.0-beta.3",
29
+ "@webiny/db-dynamodb": "5.39.0-beta.3",
30
+ "@webiny/error": "5.39.0-beta.3",
31
+ "@webiny/handler": "5.39.0-beta.3",
32
+ "@webiny/handler-client": "5.39.0-beta.3",
33
+ "@webiny/handler-db": "5.39.0-beta.3",
34
+ "@webiny/handler-graphql": "5.39.0-beta.3",
35
+ "@webiny/handler-logs": "5.39.0-beta.3",
36
+ "@webiny/plugins": "5.39.0-beta.3",
37
+ "@webiny/pubsub": "5.39.0-beta.3",
38
+ "@webiny/utils": "5.39.0-beta.3",
39
+ "@webiny/validation": "5.39.0-beta.3",
40
40
  "dayjs": "1.11.7",
41
41
  "lodash": "4.17.21"
42
42
  },
@@ -44,10 +44,10 @@
44
44
  "@babel/cli": "7.22.6",
45
45
  "@babel/core": "7.22.8",
46
46
  "@babel/preset-env": "7.22.7",
47
- "@webiny/cli": "5.39.0-beta.1",
48
- "@webiny/handler-aws": "5.39.0-beta.1",
49
- "@webiny/project-utils": "5.39.0-beta.1",
50
- "@webiny/wcp": "5.39.0-beta.1",
47
+ "@webiny/cli": "5.39.0-beta.3",
48
+ "@webiny/handler-aws": "5.39.0-beta.3",
49
+ "@webiny/project-utils": "5.39.0-beta.3",
50
+ "@webiny/wcp": "5.39.0-beta.3",
51
51
  "get-yarn-workspaces": "1.0.2",
52
52
  "graphql": "15.8.0",
53
53
  "jest": "29.5.0",
@@ -65,5 +65,5 @@
65
65
  "build": "yarn webiny run build",
66
66
  "watch": "yarn webiny run watch"
67
67
  },
68
- "gitHead": "a22d4ab9fbb4ad35106687cbe17b51a84afd4976"
68
+ "gitHead": "3846541fd9c1764e6a8041f0b4208d720eb9c314"
69
69
  }
@@ -16,21 +16,19 @@ class CmsEntryApwSettingsGetterPlugin extends _ContentApwSettingsPlugin.ContentA
16
16
  entry.meta = (0, _set.default)(entry.meta || {}, "apw.workflowId", id);
17
17
  }
18
18
  getWorkflowId(entry) {
19
- var _entry$meta$apw;
20
19
  if (!entry.meta) {
21
20
  return null;
22
21
  }
23
- return ((_entry$meta$apw = entry.meta.apw) === null || _entry$meta$apw === void 0 ? void 0 : _entry$meta$apw.workflowId) || null;
22
+ return entry.meta.apw?.workflowId || null;
24
23
  }
25
24
  setContentReviewId(entry, id) {
26
25
  entry.meta = (0, _set.default)(entry.meta || {}, "apw.contentReviewId", id);
27
26
  }
28
27
  getContentReviewId(entry) {
29
- var _entry$meta$apw2;
30
28
  if (!entry.meta) {
31
29
  return null;
32
30
  }
33
- return ((_entry$meta$apw2 = entry.meta.apw) === null || _entry$meta$apw2 === void 0 ? void 0 : _entry$meta$apw2.contentReviewId) || null;
31
+ return entry.meta.apw?.contentReviewId || null;
34
32
  }
35
33
  }
36
34
  exports.CmsEntryApwSettingsGetterPlugin = CmsEntryApwSettingsGetterPlugin;
@@ -1 +1 @@
1
- {"version":3,"names":["_ContentApwSettingsPlugin","require","_types","_set","_interopRequireDefault","CmsEntryApwSettingsGetterPlugin","ContentApwSettingsPlugin","canUse","type","ApwContentTypes","CMS_ENTRY","setWorkflowId","entry","id","meta","set","getWorkflowId","_entry$meta$apw","apw","workflowId","setContentReviewId","getContentReviewId","_entry$meta$apw2","contentReviewId","exports"],"sources":["CmsEntryApwSettingsGetterPlugin.ts"],"sourcesContent":["import { ContentApwSettingsPlugin } from \"~/ContentApwSettingsPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { ApwContentTypes } from \"~/types\";\nimport set from \"lodash/set\";\n\nexport class CmsEntryApwSettingsGetterPlugin extends ContentApwSettingsPlugin {\n public override canUse(type: ApwContentTypes): boolean {\n return type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override setWorkflowId(entry: CmsEntry, id: string | null) {\n entry.meta = set(entry.meta || {}, \"apw.workflowId\", id);\n }\n\n public override getWorkflowId(entry: CmsEntry): string | null {\n if (!entry.meta) {\n return null;\n }\n return entry.meta.apw?.workflowId || null;\n }\n\n public override setContentReviewId(entry: CmsEntry, id: string | null) {\n entry.meta = set(entry.meta || {}, \"apw.contentReviewId\", id);\n }\n public override getContentReviewId(entry: CmsEntry): string | null {\n if (!entry.meta) {\n return null;\n }\n return entry.meta.apw?.contentReviewId || null;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,yBAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEO,MAAMI,+BAA+B,SAASC,kDAAwB,CAAC;EAC1DC,MAAMA,CAACC,IAAqB,EAAW;IACnD,OAAOA,IAAI,KAAKC,sBAAe,CAACC,SAAS;EAC7C;EAEgBC,aAAaA,CAACC,KAAe,EAAEC,EAAiB,EAAE;IAC9DD,KAAK,CAACE,IAAI,GAAG,IAAAC,YAAG,EAACH,KAAK,CAACE,IAAI,IAAI,CAAC,CAAC,EAAE,gBAAgB,EAAED,EAAE,CAAC;EAC5D;EAEgBG,aAAaA,CAACJ,KAAe,EAAiB;IAAA,IAAAK,eAAA;IAC1D,IAAI,CAACL,KAAK,CAACE,IAAI,EAAE;MACb,OAAO,IAAI;IACf;IACA,OAAO,EAAAG,eAAA,GAAAL,KAAK,CAACE,IAAI,CAACI,GAAG,cAAAD,eAAA,uBAAdA,eAAA,CAAgBE,UAAU,KAAI,IAAI;EAC7C;EAEgBC,kBAAkBA,CAACR,KAAe,EAAEC,EAAiB,EAAE;IACnED,KAAK,CAACE,IAAI,GAAG,IAAAC,YAAG,EAACH,KAAK,CAACE,IAAI,IAAI,CAAC,CAAC,EAAE,qBAAqB,EAAED,EAAE,CAAC;EACjE;EACgBQ,kBAAkBA,CAACT,KAAe,EAAiB;IAAA,IAAAU,gBAAA;IAC/D,IAAI,CAACV,KAAK,CAACE,IAAI,EAAE;MACb,OAAO,IAAI;IACf;IACA,OAAO,EAAAQ,gBAAA,GAAAV,KAAK,CAACE,IAAI,CAACI,GAAG,cAAAI,gBAAA,uBAAdA,gBAAA,CAAgBC,eAAe,KAAI,IAAI;EAClD;AACJ;AAACC,OAAA,CAAAnB,+BAAA,GAAAA,+BAAA"}
1
+ {"version":3,"names":["_ContentApwSettingsPlugin","require","_types","_set","_interopRequireDefault","CmsEntryApwSettingsGetterPlugin","ContentApwSettingsPlugin","canUse","type","ApwContentTypes","CMS_ENTRY","setWorkflowId","entry","id","meta","set","getWorkflowId","apw","workflowId","setContentReviewId","getContentReviewId","contentReviewId","exports"],"sources":["CmsEntryApwSettingsGetterPlugin.ts"],"sourcesContent":["import { ContentApwSettingsPlugin } from \"~/ContentApwSettingsPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { ApwContentTypes } from \"~/types\";\nimport set from \"lodash/set\";\n\nexport class CmsEntryApwSettingsGetterPlugin extends ContentApwSettingsPlugin {\n public override canUse(type: ApwContentTypes): boolean {\n return type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override setWorkflowId(entry: CmsEntry, id: string | null) {\n entry.meta = set(entry.meta || {}, \"apw.workflowId\", id);\n }\n\n public override getWorkflowId(entry: CmsEntry): string | null {\n if (!entry.meta) {\n return null;\n }\n return entry.meta.apw?.workflowId || null;\n }\n\n public override setContentReviewId(entry: CmsEntry, id: string | null) {\n entry.meta = set(entry.meta || {}, \"apw.contentReviewId\", id);\n }\n public override getContentReviewId(entry: CmsEntry): string | null {\n if (!entry.meta) {\n return null;\n }\n return entry.meta.apw?.contentReviewId || null;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,yBAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEO,MAAMI,+BAA+B,SAASC,kDAAwB,CAAC;EAC1DC,MAAMA,CAACC,IAAqB,EAAW;IACnD,OAAOA,IAAI,KAAKC,sBAAe,CAACC,SAAS;EAC7C;EAEgBC,aAAaA,CAACC,KAAe,EAAEC,EAAiB,EAAE;IAC9DD,KAAK,CAACE,IAAI,GAAG,IAAAC,YAAG,EAACH,KAAK,CAACE,IAAI,IAAI,CAAC,CAAC,EAAE,gBAAgB,EAAED,EAAE,CAAC;EAC5D;EAEgBG,aAAaA,CAACJ,KAAe,EAAiB;IAC1D,IAAI,CAACA,KAAK,CAACE,IAAI,EAAE;MACb,OAAO,IAAI;IACf;IACA,OAAOF,KAAK,CAACE,IAAI,CAACG,GAAG,EAAEC,UAAU,IAAI,IAAI;EAC7C;EAEgBC,kBAAkBA,CAACP,KAAe,EAAEC,EAAiB,EAAE;IACnED,KAAK,CAACE,IAAI,GAAG,IAAAC,YAAG,EAACH,KAAK,CAACE,IAAI,IAAI,CAAC,CAAC,EAAE,qBAAqB,EAAED,EAAE,CAAC;EACjE;EACgBO,kBAAkBA,CAACR,KAAe,EAAiB;IAC/D,IAAI,CAACA,KAAK,CAACE,IAAI,EAAE;MACb,OAAO,IAAI;IACf;IACA,OAAOF,KAAK,CAACE,IAAI,CAACG,GAAG,EAAEI,eAAe,IAAI,IAAI;EAClD;AACJ;AAACC,OAAA,CAAAjB,+BAAA,GAAAA,+BAAA"}
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.apwEntryPlugins = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
7
  var _types = require("../../types");
10
8
  var _utils = require("./utils");
11
9
  const apwEntryPlugins = params => {
@@ -19,10 +17,13 @@ const apwEntryPlugins = params => {
19
17
  if (!item) {
20
18
  return null;
21
19
  }
22
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
23
- meta: (0, _objectSpread2.default)({}, item.meta || {}),
20
+ return {
21
+ ...item,
22
+ meta: {
23
+ ...(item.meta || {})
24
+ },
24
25
  title: (0, _utils.getEntryTitle)(model, item)
25
- });
26
+ };
26
27
  });
27
28
  apw.addContentPublisher(_types.ApwContentTypes.CMS_ENTRY, async (id, settings) => {
28
29
  const model = await (0, _utils.fetchModel)(cms, id, settings);
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_utils","apwEntryPlugins","params","cms","apw","addContentGetter","ApwContentTypes","CMS_ENTRY","id","settings","model","fetchModel","item","getEntryById","_objectSpread2","default","meta","title","getEntryTitle","addContentPublisher","publishEntry","addContentUnPublisher","unpublishEntry","exports"],"sources":["apwEntryPlugins.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { fetchModel, getEntryTitle } from \"./utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\n\ninterface ApwEntryPlugins {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const apwEntryPlugins = (params: ApwEntryPlugins) => {\n const { cms, apw } = params;\n\n apw.addContentGetter(ApwContentTypes.CMS_ENTRY, async (id, settings) => {\n const model = await fetchModel(cms, id, settings);\n\n const item = await cms.getEntryById(model, id);\n\n if (!item) {\n return null;\n }\n\n return {\n ...item,\n meta: {\n ...(item.meta || {})\n },\n title: getEntryTitle(model, item)\n };\n });\n\n apw.addContentPublisher(ApwContentTypes.CMS_ENTRY, async (id, settings) => {\n const model = await fetchModel(cms, id, settings);\n await cms.publishEntry(model, id);\n return true;\n });\n\n apw.addContentUnPublisher(ApwContentTypes.CMS_ENTRY, async (id, settings) => {\n const model = await fetchModel(cms, id, settings);\n await cms.unpublishEntry(model, id);\n return true;\n });\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;A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O,IAAI;EACf,CAAC,CAAC;AACN,CAAC;AAACe,OAAA,CAAAtB,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"names":["_types","require","_utils","apwEntryPlugins","params","cms","apw","addContentGetter","ApwContentTypes","CMS_ENTRY","id","settings","model","fetchModel","item","getEntryById","meta","title","getEntryTitle","addContentPublisher","publishEntry","addContentUnPublisher","unpublishEntry","exports"],"sources":["apwEntryPlugins.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { fetchModel, getEntryTitle } from \"./utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\n\ninterface ApwEntryPlugins {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const apwEntryPlugins = (params: ApwEntryPlugins) => {\n const { cms, apw } = params;\n\n apw.addContentGetter(ApwContentTypes.CMS_ENTRY, async (id, settings) => {\n const model = await fetchModel(cms, id, settings);\n\n const item = await cms.getEntryById(model, id);\n\n if (!item) {\n return null;\n }\n\n return {\n ...item,\n meta: {\n ...(item.meta || {})\n },\n title: getEntryTitle(model, item)\n };\n });\n\n apw.addContentPublisher(ApwContentTypes.CMS_ENTRY, async (id, settings) => {\n const model = await fetchModel(cms, id, settings);\n await cms.publishEntry(model, id);\n return true;\n });\n\n apw.addContentUnPublisher(ApwContentTypes.CMS_ENTRY, async (id, settings) => {\n const model = await fetchModel(cms, id, settings);\n await cms.unpublishEntry(model, id);\n return true;\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAOO,MAAME,eAAe,GAAIC,MAAuB,IAAK;EACxD,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BE,GAAG,CAACC,gBAAgB,CAACC,sBAAe,CAACC,SAAS,EAAE,OAAOC,EAAE,EAAEC,QAAQ,KAAK;IACpE,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAU,EAACR,GAAG,EAAEK,EAAE,EAAEC,QAAQ,CAAC;IAEjD,MAAMG,IAAI,GAAG,MAAMT,GAAG,CAACU,YAAY,CAACH,KAAK,EAAEF,EAAE,CAAC;IAE9C,IAAI,CAACI,IAAI,EAAE;MACP,OAAO,IAAI;IACf;IAEA,OAAO;MACH,GAAGA,IAAI;MACPE,IAAI,EAAE;QACF,IAAIF,IAAI,CAACE,IAAI,IAAI,CAAC,CAAC;MACvB,CAAC;MACDC,KAAK,EAAE,IAAAC,oBAAa,EAACN,KAAK,EAAEE,IAAI;IACpC,CAAC;EACL,CAAC,CAAC;EAEFR,GAAG,CAACa,mBAAmB,CAACX,sBAAe,CAACC,SAAS,EAAE,OAAOC,EAAE,EAAEC,QAAQ,KAAK;IACvE,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAU,EAACR,GAAG,EAAEK,EAAE,EAAEC,QAAQ,CAAC;IACjD,MAAMN,GAAG,CAACe,YAAY,CAACR,KAAK,EAAEF,EAAE,CAAC;IACjC,OAAO,IAAI;EACf,CAAC,CAAC;EAEFJ,GAAG,CAACe,qBAAqB,CAACb,sBAAe,CAACC,SAAS,EAAE,OAAOC,EAAE,EAAEC,QAAQ,KAAK;IACzE,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAU,EAACR,GAAG,EAAEK,EAAE,EAAEC,QAAQ,CAAC;IACjD,MAAMN,GAAG,CAACiB,cAAc,CAACV,KAAK,EAAEF,EAAE,CAAC;IACnC,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC;AAACa,OAAA,CAAApB,eAAA,GAAAA,eAAA"}
@@ -59,11 +59,10 @@ const linkContentReviewToEntry = params => {
59
59
  entry,
60
60
  model
61
61
  }) => {
62
- var _entry$meta;
63
62
  if ((0, _utils.isApwDisabledOnModel)(model)) {
64
63
  return;
65
64
  }
66
- const contentReviewId = (_entry$meta = entry.meta) === null || _entry$meta === void 0 || (_entry$meta = _entry$meta.apw) === null || _entry$meta === void 0 ? void 0 : _entry$meta.contentReviewId;
65
+ const contentReviewId = entry.meta?.apw?.contentReviewId;
67
66
  if (!contentReviewId) {
68
67
  return;
69
68
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_utils","_error","_interopRequireDefault","linkContentReviewToEntry","params","apw","cms","contentReview","onContentReviewAfterCreate","subscribe","content","type","ApwContentTypes","CMS_ENTRY","model","fetchModel","id","settings","updateEntryMeta","meta","contentReviewId","entryId","onContentReviewAfterDelete","onEntryBeforeDelete","entry","_entry$meta","isApwDisabledOnModel","get","ex","code","Error","exports"],"sources":["linkContentReviewToEntry.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { fetchModel, isApwDisabledOnModel, updateEntryMeta } from \"~/plugins/cms/utils\";\nimport Error from \"@webiny/error\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\n\ninterface LinkContentReviewToEntryParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const linkContentReviewToEntry = (params: LinkContentReviewToEntryParams) => {\n const { apw, cms } = params;\n\n apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type !== ApwContentTypes.CMS_ENTRY) {\n return;\n }\n\n const model = await fetchModel(cms, content.id, content.settings);\n\n await updateEntryMeta({\n cms,\n model,\n meta: {\n apw: {\n contentReviewId: contentReview.id\n }\n },\n entryId: content.id\n });\n });\n\n apw.contentReview.onContentReviewAfterDelete.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n if (content.type !== ApwContentTypes.CMS_ENTRY) {\n return;\n }\n\n const model = await fetchModel(cms, content.id, content.settings);\n\n await updateEntryMeta({\n cms,\n model,\n meta: {\n apw: {\n contentReviewId: null\n }\n },\n entryId: content.id\n });\n });\n\n cms.onEntryBeforeDelete.subscribe(async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n\n if (!contentReviewId) {\n return;\n }\n let contentReview;\n try {\n contentReview = await apw.contentReview.get(contentReviewId);\n } catch (ex) {\n /**\n * We're handling the case whereby \"contentReviewId\" is still linked to page;\n * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.\n */\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n\n if (!contentReview) {\n return;\n }\n throw new Error(\n `Cannot delete the entry because a peer review has been requested. Please delete the review first.`,\n \"CANNOT_DELETE_REVIEW_EXIST\",\n {\n contentReviewId,\n entry\n }\n );\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAOO,MAAMI,wBAAwB,GAAIC,MAAsC,IAAK;EAChF,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BC,GAAG,CAACE,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IAChF,MAAM;MAAEG;IAAQ,CAAC,GAAGH,aAAa;IAEjC,IAAIG,OAAO,CAACC,IAAI,KAAKC,sBAAe,CAACC,SAAS,EAAE;MAC5C;IACJ;IAEA,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAU,EAACT,GAAG,EAAEI,OAAO,CAACM,EAAE,EAAEN,OAAO,CAACO,QAAQ,CAAC;IAEjE,MAAM,IAAAC,sBAAe,EAAC;MAClBZ,GAAG;MACHQ,KAAK;MACLK,IAAI,EAAE;QACFd,GAAG,EAAE;UACDe,eAAe,EAAEb,aAAa,CAACS;QACnC;MACJ,CAAC;MACDK,OAAO,EAAEX,OAAO,CAACM;IACrB,CAAC,CAAC;EACN,CAAC,CAAC;EAEFX,GAAG,CAACE,aAAa,CAACe,0BAA0B,CAACb,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IAChF,MAAM;MAAEG;IAAQ,CAAC,GA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
1
+ {"version":3,"names":["_types","require","_utils","_error","_interopRequireDefault","linkContentReviewToEntry","params","apw","cms","contentReview","onContentReviewAfterCreate","subscribe","content","type","ApwContentTypes","CMS_ENTRY","model","fetchModel","id","settings","updateEntryMeta","meta","contentReviewId","entryId","onContentReviewAfterDelete","onEntryBeforeDelete","entry","isApwDisabledOnModel","get","ex","code","Error","exports"],"sources":["linkContentReviewToEntry.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow, ApwContentTypes } from \"~/types\";\nimport { fetchModel, isApwDisabledOnModel, updateEntryMeta } from \"~/plugins/cms/utils\";\nimport Error from \"@webiny/error\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\n\ninterface LinkContentReviewToEntryParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const linkContentReviewToEntry = (params: LinkContentReviewToEntryParams) => {\n const { apw, cms } = params;\n\n apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n\n if (content.type !== ApwContentTypes.CMS_ENTRY) {\n return;\n }\n\n const model = await fetchModel(cms, content.id, content.settings);\n\n await updateEntryMeta({\n cms,\n model,\n meta: {\n apw: {\n contentReviewId: contentReview.id\n }\n },\n entryId: content.id\n });\n });\n\n apw.contentReview.onContentReviewAfterDelete.subscribe(async ({ contentReview }) => {\n const { content } = contentReview;\n if (content.type !== ApwContentTypes.CMS_ENTRY) {\n return;\n }\n\n const model = await fetchModel(cms, content.id, content.settings);\n\n await updateEntryMeta({\n cms,\n model,\n meta: {\n apw: {\n contentReviewId: null\n }\n },\n entryId: content.id\n });\n });\n\n cms.onEntryBeforeDelete.subscribe(async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n\n if (!contentReviewId) {\n return;\n }\n let contentReview;\n try {\n contentReview = await apw.contentReview.get(contentReviewId);\n } catch (ex) {\n /**\n * We're handling the case whereby \"contentReviewId\" is still linked to page;\n * even when the contentReview entry has been deleted. In that case, we'll allow page deletion.\n */\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n\n if (!contentReview) {\n return;\n }\n throw new Error(\n `Cannot delete the entry because a peer review has been requested. Please delete the review first.`,\n \"CANNOT_DELETE_REVIEW_EXIST\",\n {\n contentReviewId,\n entry\n }\n );\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAOO,MAAMI,wBAAwB,GAAIC,MAAsC,IAAK;EAChF,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BC,GAAG,CAACE,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IAChF,MAAM;MAAEG;IAAQ,CAAC,GAAGH,aAAa;IAEjC,IAAIG,OAAO,CAACC,IAAI,KAAKC,sBAAe,CAACC,SAAS,EAAE;MAC5C;IACJ;IAEA,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAU,EAACT,GAAG,EAAEI,OAAO,CAACM,EAAE,EAAEN,OAAO,CAACO,QAAQ,CAAC;IAEjE,MAAM,IAAAC,sBAAe,EAAC;MAClBZ,GAAG;MACHQ,KAAK;MACLK,IAAI,EAAE;QACFd,GAAG,EAAE;UACDe,eAAe,EAAEb,aAAa,CAACS;QACnC;MACJ,CAAC;MACDK,OAAO,EAAEX,OAAO,CAACM;IACrB,CAAC,CAAC;EACN,CAAC,CAAC;EAEFX,GAAG,CAACE,aAAa,CAACe,0BAA0B,CAACb,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IAChF,MAAM;MAAEG;IAAQ,CAAC,GAAGH,aAAa;IACjC,IAAIG,OAAO,CAACC,IAAI,KAAKC,sBAAe,CAACC,SAAS,EAAE;MAC5C;IACJ;IAEA,MAAMC,KAAK,GAAG,MAAM,IAAAC,iBAAU,EAACT,GAAG,EAAEI,OAAO,CAACM,EAAE,EAAEN,OAAO,CAACO,QAAQ,CAAC;IAEjE,MAAM,IAAAC,sBAAe,EAAC;MAClBZ,GAAG;MACHQ,KAAK;MACLK,IAAI,EAAE;QACFd,GAAG,EAAE;UACDe,eAAe,EAAE;QACrB;MACJ,CAAC;MACDC,OAAO,EAAEX,OAAO,CAACM;IACrB,CAAC,CAAC;EACN,CAAC,CAAC;EAEFV,GAAG,CAACiB,mBAAmB,CAACd,SAAS,CAAC,OAAO;IAAEe,KAAK;IAAEV;EAAM,CAAC,KAAK;IAC1D,IAAI,IAAAW,2BAAoB,EAACX,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAMM,eAAe,GAAGI,KAAK,CAACL,IAAI,EAAEd,GAAG,EAAEe,eAAe;IAExD,IAAI,CAACA,eAAe,EAAE;MAClB;IACJ;IACA,IAAIb,aAAa;IACjB,IAAI;MACAA,aAAa,GAAG,MAAMF,GAAG,CAACE,aAAa,CAACmB,GAAG,CAACN,eAAe,CAAC;IAChE,CAAC,CAAC,OAAOO,EAAE,EAAE;MACT;AACZ;AACA;AACA;MACY,IAAIA,EAAE,CAACC,IAAI,KAAK,WAAW,EAAE;QACzB,MAAMD,EAAE;MACZ;IACJ;IAEA,IAAI,CAACpB,aAAa,EAAE;MAChB;IACJ;IACA,MAAM,IAAIsB,cAAK,CACV,mGAAkG,EACnG,4BAA4B,EAC5B;MACIT,eAAe;MACfI;IACJ,CACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACM,OAAA,CAAA3B,wBAAA,GAAAA,wBAAA"}
@@ -30,7 +30,6 @@ const linkWorkflowToEntry = params => {
30
30
  original,
31
31
  model
32
32
  }) => {
33
- var _original$meta, _original$meta2;
34
33
  if ((0, _utils.isApwDisabledOnModel)(model)) {
35
34
  return;
36
35
  }
@@ -38,7 +37,7 @@ const linkWorkflowToEntry = params => {
38
37
  * If the previous revision(original) already had the "contentReviewId",
39
38
  * we need to unlink it so that new "contentReview" can be request for the new revision.
40
39
  */
41
- const previousContentReviewId = (_original$meta = original.meta) === null || _original$meta === void 0 || (_original$meta = _original$meta.apw) === null || _original$meta === void 0 ? void 0 : _original$meta.contentReviewId;
40
+ const previousContentReviewId = original.meta?.apw?.contentReviewId;
42
41
  if (previousContentReviewId) {
43
42
  entry.meta = (0, _set.default)(entry.meta || {}, "apw.contentReviewId", null);
44
43
  }
@@ -47,7 +46,7 @@ const linkWorkflowToEntry = params => {
47
46
  * If the previous revision(original) already had the "workflowId",
48
47
  * we don't need to do anything we'll just let it be copied over.
49
48
  */
50
- const previousWorkflowId = (_original$meta2 = original.meta) === null || _original$meta2 === void 0 || (_original$meta2 = _original$meta2.apw) === null || _original$meta2 === void 0 ? void 0 : _original$meta2.workflowId;
49
+ const previousWorkflowId = original.meta?.apw?.workflowId;
51
50
  if (previousWorkflowId) {
52
51
  return;
53
52
  }
@@ -65,12 +64,11 @@ const linkWorkflowToEntry = params => {
65
64
  original,
66
65
  model
67
66
  }) => {
68
- var _original$meta3, _entry$meta, _entry$meta2;
69
67
  if ((0, _utils.isApwDisabledOnModel)(model)) {
70
68
  return;
71
69
  }
72
- const prevApwWorkflowId = (_original$meta3 = original.meta) === null || _original$meta3 === void 0 || (_original$meta3 = _original$meta3.apw) === null || _original$meta3 === void 0 ? void 0 : _original$meta3.workflowId;
73
- const currentApwWorkflowId = (_entry$meta = entry.meta) === null || _entry$meta === void 0 || (_entry$meta = _entry$meta.apw) === null || _entry$meta === void 0 ? void 0 : _entry$meta.workflowId;
70
+ const prevApwWorkflowId = original.meta?.apw?.workflowId;
71
+ const currentApwWorkflowId = entry.meta?.apw?.workflowId;
74
72
  /**
75
73
  * Make sure the apw property doesn't get lost between updates.
76
74
  * It can happen because we run modal validation in "onBeforePageUpdate" event,
@@ -83,7 +81,7 @@ const linkWorkflowToEntry = params => {
83
81
  * If there is a linked "contentReview" for this page and the page "title" has changed.
84
82
  * Let's update the "title" field in "contentReview".
85
83
  */
86
- const linkedContentReviewId = (_entry$meta2 = entry.meta) === null || _entry$meta2 === void 0 || (_entry$meta2 = _entry$meta2.apw) === null || _entry$meta2 === void 0 ? void 0 : _entry$meta2.contentReviewId;
84
+ const linkedContentReviewId = entry.meta?.apw?.contentReviewId;
87
85
  const prevTitle = (0, _utils.getEntryTitle)(model, original);
88
86
  const newTitle = (0, _utils.getEntryTitle)(model, entry);
89
87
  if (!linkedContentReviewId || prevTitle === newTitle) {
@@ -100,7 +98,6 @@ const linkWorkflowToEntry = params => {
100
98
  apw.workflow.onWorkflowAfterCreate.subscribe(async ({
101
99
  workflow
102
100
  }) => {
103
- var _scope$data;
104
101
  const {
105
102
  scope
106
103
  } = workflow;
@@ -111,7 +108,7 @@ const linkWorkflowToEntry = params => {
111
108
  return;
112
109
  }
113
110
  const models = await cms.listModels();
114
- const values = (_scope$data = scope.data) === null || _scope$data === void 0 ? void 0 : _scope$data.entries;
111
+ const values = scope.data?.entries;
115
112
  if (!values || Array.isArray(values) === false || values.length === 0) {
116
113
  return;
117
114
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_set","_interopRequireDefault","require","_utils","linkWorkflowToEntry","params","apw","cms","onEntryBeforeCreate","subscribe","entry","model","isApwDisabledOnModel","assignWorkflowToEntry","onEntryRevisionBeforeCreate","original","_original$meta","_original$meta2","previousContentReviewId","meta","contentReviewId","set","previousWorkflowId","workflowId","onEntryBeforeUpdate","_original$meta3","_entry$meta","_entry$meta2","prevApwWorkflowId","currentApwWorkflowId","linkedContentReviewId","prevTitle","getEntryTitle","newTitle","contentReview","update","title","workflow","onWorkflowAfterCreate","_scope$data","scope","hasEntries","models","listModels","values","data","entries","Array","isArray","length","value","modelId","id","find","m","updateEntryMeta","entryId","exports"],"sources":["linkWorkflowToEntry.ts"],"sourcesContent":["import set from \"lodash/set\";\nimport { AdvancedPublishingWorkflow } from \"~/types\";\nimport {\n assignWorkflowToEntry,\n getEntryTitle,\n hasEntries,\n isApwDisabledOnModel,\n updateEntryMeta\n} from \"~/plugins/cms/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\n\ninterface Value {\n id: string;\n modelId: string;\n}\n\ninterface LinkWorkflowToEntryParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const linkWorkflowToEntry = (params: LinkWorkflowToEntryParams) => {\n const { apw, cms } = params;\n\n cms.onEntryBeforeCreate.subscribe(async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n await assignWorkflowToEntry({\n apw,\n entry,\n model\n });\n });\n\n cms.onEntryRevisionBeforeCreate.subscribe(async ({ entry, original, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n /**\n * If the previous revision(original) already had the \"contentReviewId\",\n * we need to unlink it so that new \"contentReview\" can be request for the new revision.\n */\n const previousContentReviewId = original.meta?.apw?.contentReviewId;\n if (previousContentReviewId) {\n entry.meta = set(entry.meta || {}, \"apw.contentReviewId\", null);\n }\n\n /**\n * If the previous revision(original) already had the \"workflowId\",\n * we don't need to do anything we'll just let it be copied over.\n */\n const previousWorkflowId = original.meta?.apw?.workflowId;\n if (previousWorkflowId) {\n return;\n }\n /**\n * Lookup and assign \"workflowId\".\n */\n await assignWorkflowToEntry({\n apw,\n entry,\n model\n });\n });\n\n cms.onEntryBeforeUpdate.subscribe(async ({ entry, original, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const prevApwWorkflowId = original.meta?.apw?.workflowId;\n const currentApwWorkflowId = entry.meta?.apw?.workflowId;\n /**\n * Make sure the apw property doesn't get lost between updates.\n * It can happen because we run modal validation in \"onBeforePageUpdate\" event,\n * which doesn't have the \"apw\" property.\n */\n if (prevApwWorkflowId && !currentApwWorkflowId) {\n entry.meta = set(entry.meta || {}, \"apw\", (original.meta || {}).apw || {});\n }\n /*\n * If there is a linked \"contentReview\" for this page and the page \"title\" has changed.\n * Let's update the \"title\" field in \"contentReview\".\n */\n const linkedContentReviewId = entry.meta?.apw?.contentReviewId;\n const prevTitle = getEntryTitle(model, original);\n const newTitle = getEntryTitle(model, entry);\n\n if (!linkedContentReviewId || prevTitle === newTitle) {\n return;\n }\n await apw.contentReview.update(linkedContentReviewId, {\n title: newTitle\n });\n });\n\n /**\n * Link created workflow to associated entries.\n */\n apw.workflow.onWorkflowAfterCreate.subscribe(async ({ workflow }) => {\n const { scope } = workflow;\n /**\n * If the workflow has entries in it's scope, we'll link that workflow for each of those entries.\n */\n if (hasEntries(workflow) === false) {\n return;\n }\n\n const models = await cms.listModels();\n\n const values: Value[] | undefined = scope.data?.entries;\n if (!values || Array.isArray(values) === false || values.length === 0) {\n return;\n }\n\n for (const value of values) {\n if (!value || !value.modelId || !value.id) {\n continue;\n }\n const model = models.find(m => m.modelId === value.modelId);\n if (!model) {\n continue;\n }\n await updateEntryMeta({\n cms,\n model,\n entryId: value.id,\n meta: {\n apw: {\n workflowId: workflow.id\n }\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAkBO,MAAME,mBAAmB,GAAIC,MAAiC,IAAK;EACtE,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BE,GAAG,CAACC,mBAAmB,CAACC,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IAC1D,IAAI,IAAAC,2BAAoB,EAACD,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAM,IAAAE,4BAAqB,EAAC;MACxBP,GAAG;MACHI,KAAK;MACLC;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFJ,GAAG,CAACO,2BAA2B,CAACL,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEK,QAAQ;IAAEJ;EAAM,CAAC,KAAK;IAAA,IAAAK,cAAA,EAAAC,eAAA;IAC5E,IAAI,IAAAL,2BAAoB,EAACD,KAAK,CAAC,EA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CAACF,MAAM,IAAIG,KAAK,CAACC,OAAO,CAACJ,MAAM,CAAC,KAAK,KAAK,IAAIA,MAAM,CAACK,MAAM,KAAK,CAAC,EAAE;MACnE;IACJ;IAEA,KAAK,MAAMC,KAAK,IAAIN,MAAM,EAAE;MACxB,IAAI,CAACM,KAAK,IAAI,CAACA,KAAK,CAACC,OAAO,IAAI,CAACD,KAAK,CAACE,EAAE,EAAE;QACvC;MACJ;MACA,MAAMzC,KAAK,GAAG+B,MAAM,CAACW,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,KAAKD,KAAK,CAACC,OAAO,CAAC;MAC3D,IAAI,CAACxC,KAAK,EAAE;QACR;MACJ;MACA,MAAM,IAAA4C,sBAAe,EAAC;QAClBhD,GAAG;QACHI,KAAK;QACL6C,OAAO,EAAEN,KAAK,CAACE,EAAE;QACjBjC,IAAI,EAAE;UACFb,GAAG,EAAE;YACDiB,UAAU,EAAEc,QAAQ,CAACe;UACzB;QACJ;MACJ,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACK,OAAA,CAAArD,mBAAA,GAAAA,mBAAA"}
1
+ {"version":3,"names":["_set","_interopRequireDefault","require","_utils","linkWorkflowToEntry","params","apw","cms","onEntryBeforeCreate","subscribe","entry","model","isApwDisabledOnModel","assignWorkflowToEntry","onEntryRevisionBeforeCreate","original","previousContentReviewId","meta","contentReviewId","set","previousWorkflowId","workflowId","onEntryBeforeUpdate","prevApwWorkflowId","currentApwWorkflowId","linkedContentReviewId","prevTitle","getEntryTitle","newTitle","contentReview","update","title","workflow","onWorkflowAfterCreate","scope","hasEntries","models","listModels","values","data","entries","Array","isArray","length","value","modelId","id","find","m","updateEntryMeta","entryId","exports"],"sources":["linkWorkflowToEntry.ts"],"sourcesContent":["import set from \"lodash/set\";\nimport { AdvancedPublishingWorkflow } from \"~/types\";\nimport {\n assignWorkflowToEntry,\n getEntryTitle,\n hasEntries,\n isApwDisabledOnModel,\n updateEntryMeta\n} from \"~/plugins/cms/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\n\ninterface Value {\n id: string;\n modelId: string;\n}\n\ninterface LinkWorkflowToEntryParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const linkWorkflowToEntry = (params: LinkWorkflowToEntryParams) => {\n const { apw, cms } = params;\n\n cms.onEntryBeforeCreate.subscribe(async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n await assignWorkflowToEntry({\n apw,\n entry,\n model\n });\n });\n\n cms.onEntryRevisionBeforeCreate.subscribe(async ({ entry, original, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n /**\n * If the previous revision(original) already had the \"contentReviewId\",\n * we need to unlink it so that new \"contentReview\" can be request for the new revision.\n */\n const previousContentReviewId = original.meta?.apw?.contentReviewId;\n if (previousContentReviewId) {\n entry.meta = set(entry.meta || {}, \"apw.contentReviewId\", null);\n }\n\n /**\n * If the previous revision(original) already had the \"workflowId\",\n * we don't need to do anything we'll just let it be copied over.\n */\n const previousWorkflowId = original.meta?.apw?.workflowId;\n if (previousWorkflowId) {\n return;\n }\n /**\n * Lookup and assign \"workflowId\".\n */\n await assignWorkflowToEntry({\n apw,\n entry,\n model\n });\n });\n\n cms.onEntryBeforeUpdate.subscribe(async ({ entry, original, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const prevApwWorkflowId = original.meta?.apw?.workflowId;\n const currentApwWorkflowId = entry.meta?.apw?.workflowId;\n /**\n * Make sure the apw property doesn't get lost between updates.\n * It can happen because we run modal validation in \"onBeforePageUpdate\" event,\n * which doesn't have the \"apw\" property.\n */\n if (prevApwWorkflowId && !currentApwWorkflowId) {\n entry.meta = set(entry.meta || {}, \"apw\", (original.meta || {}).apw || {});\n }\n /*\n * If there is a linked \"contentReview\" for this page and the page \"title\" has changed.\n * Let's update the \"title\" field in \"contentReview\".\n */\n const linkedContentReviewId = entry.meta?.apw?.contentReviewId;\n const prevTitle = getEntryTitle(model, original);\n const newTitle = getEntryTitle(model, entry);\n\n if (!linkedContentReviewId || prevTitle === newTitle) {\n return;\n }\n await apw.contentReview.update(linkedContentReviewId, {\n title: newTitle\n });\n });\n\n /**\n * Link created workflow to associated entries.\n */\n apw.workflow.onWorkflowAfterCreate.subscribe(async ({ workflow }) => {\n const { scope } = workflow;\n /**\n * If the workflow has entries in it's scope, we'll link that workflow for each of those entries.\n */\n if (hasEntries(workflow) === false) {\n return;\n }\n\n const models = await cms.listModels();\n\n const values: Value[] | undefined = scope.data?.entries;\n if (!values || Array.isArray(values) === false || values.length === 0) {\n return;\n }\n\n for (const value of values) {\n if (!value || !value.modelId || !value.id) {\n continue;\n }\n const model = models.find(m => m.modelId === value.modelId);\n if (!model) {\n continue;\n }\n await updateEntryMeta({\n cms,\n model,\n entryId: value.id,\n meta: {\n apw: {\n workflowId: workflow.id\n }\n }\n });\n }\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAkBO,MAAME,mBAAmB,GAAIC,MAAiC,IAAK;EACtE,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BE,GAAG,CAACC,mBAAmB,CAACC,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IAC1D,IAAI,IAAAC,2BAAoB,EAACD,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAM,IAAAE,4BAAqB,EAAC;MACxBP,GAAG;MACHI,KAAK;MACLC;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFJ,GAAG,CAACO,2BAA2B,CAACL,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEK,QAAQ;IAAEJ;EAAM,CAAC,KAAK;IAC5E,IAAI,IAAAC,2BAAoB,EAACD,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAMK,uBA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c;UACzB;QACJ;MACJ,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACK,OAAA,CAAA/C,mBAAA,GAAAA,mBAAA"}
@@ -17,11 +17,10 @@ const triggerContentReview = params => {
17
17
  entry,
18
18
  model
19
19
  }) => {
20
- var _entry$meta, _entry$meta2;
21
20
  if ((0, _utils.isApwDisabledOnModel)(model)) {
22
21
  return;
23
22
  }
24
- const contentReviewId = (_entry$meta = entry.meta) === null || _entry$meta === void 0 || (_entry$meta = _entry$meta.apw) === null || _entry$meta === void 0 ? void 0 : _entry$meta.contentReviewId;
23
+ const contentReviewId = entry.meta?.apw?.contentReviewId;
25
24
  if (contentReviewId) {
26
25
  const contentReview = await apw.contentReview.get(contentReviewId);
27
26
  if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.UNDER_REVIEW) {
@@ -32,7 +31,7 @@ const triggerContentReview = params => {
32
31
  entry
33
32
  });
34
33
  }
35
- const workflowId = (_entry$meta2 = entry.meta) === null || _entry$meta2 === void 0 || (_entry$meta2 = _entry$meta2.apw) === null || _entry$meta2 === void 0 ? void 0 : _entry$meta2.workflowId;
34
+ const workflowId = entry.meta?.apw?.workflowId;
36
35
  if (!workflowId) {
37
36
  return;
38
37
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_types","_utils","triggerContentReview","params","cms","apw","onEntryBeforePublish","subscribe","entry","model","_entry$meta","_entry$meta2","isApwDisabledOnModel","contentReviewId","meta","contentReview","get","reviewStatus","ApwContentReviewStatus","UNDER_REVIEW","Error","workflowId","exports"],"sources":["triggerContentReview.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryBeforePublishTopicParams\n} from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { isApwDisabledOnModel } from \"~/plugins/cms/utils\";\n\ninterface TriggerContentReviewParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const triggerContentReview = (params: TriggerContentReviewParams) => {\n const { cms, apw } = params;\n\n cms.onEntryBeforePublish.subscribe<OnCmsEntryBeforePublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n if (contentReviewId) {\n const contentReview = await apw.contentReview.get(contentReviewId);\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.UNDER_REVIEW) {\n return;\n }\n throw new Error(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n entry\n }\n );\n }\n\n const workflowId = entry.meta?.apw?.workflowId;\n\n if (!workflowId) {\n return;\n }\n throw new Error(\n \"This content requires peer review approval before it can be published.\",\n \"REVIEW_REQUIRED\",\n {\n workflowId,\n entry\n }\n );\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AAMO,MAAMG,oBAAoB,GAAIC,MAAkC,IAAK;EACxE,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BC,GAAG,CAACE,oBAAoB,CAACC,SAAS,CAC9B,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IAAA,IAAAC,WAAA,EAAAC,YAAA;IACxB,IAAI,IAAAC,2BAAoB,EAACH,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAMI,eAAe,IAAAH,WAAA,GAAGF,KAAK,CAACM,IAAI,cAAAJ,WAAA,gBAAAA,WAAA,GAAVA,WAAA,CAAYL,GAAG,cAAAK,WAAA,uBAAfA,WAAA,CAAiBG,eAAe;IACxD,IAAIA,eAAe,EAAE;MACjB,MAAME,aAAa,GAAG,MAAMV,GAAG,CAACU,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;MAElE,IAAIE,aAAa,CAACE,YAAY,KAAKC,6BAAsB,CAACC,YAAY,EAAE;QACpE;MACJ;MACA,MAAM,IAAIC,cAAK,CACV,4DAA2D,EAC5D,sBAAsB,EACtB;QACIP,eAAe;QACfL;MACJ,CACJ,CAAC;IACL;IAEA,MAAMa,UAAU,IAAAV,YAAA,GAAGH,KAAK,CAACM,IAAI,cAAAH,YAAA,gBAAAA,YAAA,GAAVA,YAAA,CAAYN,GAAG,cAAAM,YAAA,uBAAfA,YAAA,CAAiBU,UAAU;IAE9C,IAAI,CAACA,UAAU,EAAE;MACb;IACJ;IACA,MAAM,IAAID,cAAK,CACX,wEAAwE,EACxE,iBAAiB,EACjB;MACIC,UAAU;MACVb;IACJ,CACJ,CAAC;EACL,CACJ,CAAC;AACL,CAAC;AAACc,OAAA,CAAApB,oBAAA,GAAAA,oBAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_types","_utils","triggerContentReview","params","cms","apw","onEntryBeforePublish","subscribe","entry","model","isApwDisabledOnModel","contentReviewId","meta","contentReview","get","reviewStatus","ApwContentReviewStatus","UNDER_REVIEW","Error","workflowId","exports"],"sources":["triggerContentReview.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryBeforePublishTopicParams\n} from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { isApwDisabledOnModel } from \"~/plugins/cms/utils\";\n\ninterface TriggerContentReviewParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n}\nexport const triggerContentReview = (params: TriggerContentReviewParams) => {\n const { cms, apw } = params;\n\n cms.onEntryBeforePublish.subscribe<OnCmsEntryBeforePublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n if (contentReviewId) {\n const contentReview = await apw.contentReview.get(contentReviewId);\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.UNDER_REVIEW) {\n return;\n }\n throw new Error(\n `A peer review for this content has been already requested.`,\n \"REVIEW_ALREADY_EXIST\",\n {\n contentReviewId,\n entry\n }\n );\n }\n\n const workflowId = entry.meta?.apw?.workflowId;\n\n if (!workflowId) {\n return;\n }\n throw new Error(\n \"This content requires peer review approval before it can be published.\",\n \"REVIEW_REQUIRED\",\n {\n workflowId,\n entry\n }\n );\n }\n );\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AAMO,MAAMG,oBAAoB,GAAIC,MAAkC,IAAK;EACxE,MAAM;IAAEC,GAAG;IAAEC;EAAI,CAAC,GAAGF,MAAM;EAE3BC,GAAG,CAACE,oBAAoB,CAACC,SAAS,CAC9B,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IACxB,IAAI,IAAAC,2BAAoB,EAACD,KAAK,CAAC,EAAE;MAC7B;IACJ;IACA,MAAME,eAAe,GAAGH,KAAK,CAACI,IAAI,EAAEP,GAAG,EAAEM,eAAe;IACxD,IAAIA,eAAe,EAAE;MACjB,MAAME,aAAa,GAAG,MAAMR,GAAG,CAACQ,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;MAElE,IAAIE,aAAa,CAACE,YAAY,KAAKC,6BAAsB,CAACC,YAAY,EAAE;QACpE;MACJ;MACA,MAAM,IAAIC,cAAK,CACV,4DAA2D,EAC5D,sBAAsB,EACtB;QACIP,eAAe;QACfH;MACJ,CACJ,CAAC;IACL;IAEA,MAAMW,UAAU,GAAGX,KAAK,CAACI,IAAI,EAAEP,GAAG,EAAEc,UAAU;IAE9C,IAAI,CAACA,UAAU,EAAE;MACb;IACJ;IACA,MAAM,IAAID,cAAK,CACX,wEAAwE,EACxE,iBAAiB,EACjB;MACIC,UAAU;MACVX;IACJ,CACJ,CAAC;EACL,CACJ,CAAC;AACL,CAAC;AAACY,OAAA,CAAAlB,oBAAA,GAAAA,oBAAA"}
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.updateContentReviewStatus = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
7
  var _types = require("../../types");
10
8
  var _utils = require("../../crud/utils");
11
9
  var _utils2 = require("./utils");
@@ -19,11 +17,10 @@ const updateContentReviewStatus = params => {
19
17
  entry,
20
18
  model
21
19
  }) => {
22
- var _entry$meta;
23
20
  if ((0, _utils2.isApwDisabledOnModel)(model)) {
24
21
  return;
25
22
  }
26
- const contentReviewId = (_entry$meta = entry.meta) === null || _entry$meta === void 0 || (_entry$meta = _entry$meta.apw) === null || _entry$meta === void 0 ? void 0 : _entry$meta.contentReviewId;
23
+ const contentReviewId = entry.meta?.apw?.contentReviewId;
27
24
  /**
28
25
  * Bail out if there is no "content review" linked.
29
26
  */
@@ -40,20 +37,21 @@ const updateContentReviewStatus = params => {
40
37
  }
41
38
  await apw.contentReview.update(contentReviewId, {
42
39
  reviewStatus: _types.ApwContentReviewStatus.PUBLISHED,
43
- content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
40
+ content: {
41
+ ...contentReview.content,
42
+ ..._utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,
44
43
  publishedBy: identity.id
45
- })
44
+ }
46
45
  });
47
46
  });
48
47
  cms.onEntryAfterUnpublish.subscribe(async ({
49
48
  entry,
50
49
  model
51
50
  }) => {
52
- var _entry$meta2;
53
51
  if ((0, _utils2.isApwDisabledOnModel)(model)) {
54
52
  return;
55
53
  }
56
- const contentReviewId = (_entry$meta2 = entry.meta) === null || _entry$meta2 === void 0 || (_entry$meta2 = _entry$meta2.apw) === null || _entry$meta2 === void 0 ? void 0 : _entry$meta2.contentReviewId;
54
+ const contentReviewId = entry.meta?.apw?.contentReviewId;
57
55
  /**
58
56
  * Bail out if there is no "content review" linked.
59
57
  */
@@ -70,9 +68,11 @@ const updateContentReviewStatus = params => {
70
68
  }
71
69
  await apw.contentReview.update(contentReviewId, {
72
70
  reviewStatus: _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED,
73
- content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
71
+ content: {
72
+ ...contentReview.content,
73
+ ..._utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,
74
74
  publishedBy: null
75
- })
75
+ }
76
76
  });
77
77
  });
78
78
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_utils","_utils2","updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","_entry$meta","isApwDisabledOnModel","contentReviewId","meta","contentReview","get","identity","getIdentity","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","_objectSpread2","default","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onEntryAfterUnpublish","_entry$meta2","exports"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryAfterPublishTopicParams,\n OnCmsEntryAfterUnpublishTopicParams\n} from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\nimport { isApwDisabledOnModel } from \"~/plugins/cms/utils\";\n\ninterface UpdateContentReviewStatusParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\n\nexport const updateContentReviewStatus = (params: UpdateContentReviewStatusParams) => {\n const { apw, cms, security } = params;\n\n cms.onEntryAfterPublish.subscribe<OnCmsEntryAfterPublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n /**\n * Bail out if there is no \"content review\" linked.\n */\n if (!contentReviewId) {\n return;\n }\n\n const contentReview = await apw.contentReview.get(contentReviewId);\n const identity = security.getIdentity();\n /**\n * If content review is \"readyToBePublished set its status as \"published\" after page publish.\n */\n if (contentReview.reviewStatus !== ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n reviewStatus: ApwContentReviewStatus.PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: identity.id\n }\n });\n }\n );\n cms.onEntryAfterUnpublish.subscribe<OnCmsEntryAfterUnpublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n /**\n * Bail out if there is no \"content review\" linked.\n */\n if (!contentReviewId) {\n return;\n }\n\n const contentReview = await apw.contentReview.get(contentReviewId);\n /**\n * If content review is \"published set its status as \"readyToBePublished\" after page unpublish.\n */\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n reviewStatus: ApwContentReviewStatus.READY_TO_BE_PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: null\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,OAAA,GAAAF,OAAA;AAQO,MAAMG,yBAAyB,GAAIC,MAAuC,IAAK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K,CAACK,IAAI,cAAAiB,YAAA,gBAAAA,YAAA,GAAVA,YAAA,CAAY3B,GAAG,cAAA2B,YAAA,uBAAfA,YAAA,CAAiBlB,eAAe;IACxD;AACZ;AACA;IACY,IAAI,CAACA,eAAe,EAAE;MAClB;IACJ;IAEA,MAAME,aAAa,GAAG,MAAMX,GAAG,CAACW,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;IAClE;AACZ;AACA;;IAEY,IAAIE,aAAa,CAACI,YAAY,KAAKC,6BAAsB,CAACG,SAAS,EAAE;MACjE;IACJ;IACA,MAAMnB,GAAG,CAACW,aAAa,CAACO,MAAM,CAACT,eAAe,EAAE;MAC5CM,YAAY,EAAEC,6BAAsB,CAACC,qBAAqB;MAC1DG,OAAO,MAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MACAX,aAAa,CAACS,OAAO,GACrBG,mDAA4C;QAC/CC,WAAW,EAAE;MAAI;IAEzB,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAACI,OAAA,CAAA9B,yBAAA,GAAAA,yBAAA"}
1
+ {"version":3,"names":["_types","require","_utils","_utils2","updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","isApwDisabledOnModel","contentReviewId","meta","contentReview","get","identity","getIdentity","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onEntryAfterUnpublish","exports"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnCmsEntryAfterPublishTopicParams,\n OnCmsEntryAfterUnpublishTopicParams\n} from \"~/types\";\nimport { INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META } from \"~/crud/utils\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\nimport { isApwDisabledOnModel } from \"~/plugins/cms/utils\";\n\ninterface UpdateContentReviewStatusParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\n\nexport const updateContentReviewStatus = (params: UpdateContentReviewStatusParams) => {\n const { apw, cms, security } = params;\n\n cms.onEntryAfterPublish.subscribe<OnCmsEntryAfterPublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n /**\n * Bail out if there is no \"content review\" linked.\n */\n if (!contentReviewId) {\n return;\n }\n\n const contentReview = await apw.contentReview.get(contentReviewId);\n const identity = security.getIdentity();\n /**\n * If content review is \"readyToBePublished set its status as \"published\" after page publish.\n */\n if (contentReview.reviewStatus !== ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n reviewStatus: ApwContentReviewStatus.PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: identity.id\n }\n });\n }\n );\n cms.onEntryAfterUnpublish.subscribe<OnCmsEntryAfterUnpublishTopicParams>(\n async ({ entry, model }) => {\n if (isApwDisabledOnModel(model)) {\n return;\n }\n const contentReviewId = entry.meta?.apw?.contentReviewId;\n /**\n * Bail out if there is no \"content review\" linked.\n */\n if (!contentReviewId) {\n return;\n }\n\n const contentReview = await apw.contentReview.get(contentReviewId);\n /**\n * If content review is \"published set its status as \"readyToBePublished\" after page unpublish.\n */\n\n if (contentReview.reviewStatus !== ApwContentReviewStatus.PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n reviewStatus: ApwContentReviewStatus.READY_TO_BE_PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: null\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,O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ACJ;IAEA,MAAME,aAAa,GAAG,MAAMV,GAAG,CAACU,aAAa,CAACC,GAAG,CAACH,eAAe,CAAC;IAClE;AACZ;AACA;;IAEY,IAAIE,aAAa,CAACI,YAAY,KAAKC,6BAAsB,CAACG,SAAS,EAAE;MACjE;IACJ;IACA,MAAMlB,GAAG,CAACU,aAAa,CAACO,MAAM,CAACT,eAAe,EAAE;MAC5CM,YAAY,EAAEC,6BAAsB,CAACC,qBAAqB;MAC1DG,OAAO,EAAE;QACL,GAAGT,aAAa,CAACS,OAAO;QACxB,GAAGC,mDAA4C;QAC/CC,WAAW,EAAE;MACjB;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAACG,OAAA,CAAA1B,yBAAA,GAAAA,yBAAA"}
@@ -23,6 +23,6 @@ interface AssignWorkflowToEntryParams {
23
23
  model: CmsModel;
24
24
  }
25
25
  export declare const assignWorkflowToEntry: (params: AssignWorkflowToEntryParams) => Promise<void>;
26
- export declare const hasEntries: (workflow: ApwWorkflow) => Boolean;
26
+ export declare const hasEntries: (workflow: ApwWorkflow) => boolean;
27
27
  export declare const isApwDisabledOnModel: (model: Pick<CmsModel, "modelId" | "isPrivate">) => boolean;
28
28
  export {};
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.updateEntryMeta = exports.isApwDisabledOnModel = exports.hasEntries = exports.getLatestEntryRevision = exports.getEntryTitle = exports.fetchModel = exports.assignWorkflowToEntry = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
8
  var _error = _interopRequireDefault(require("@webiny/error"));
10
9
  var _types = require("../../types");
11
10
  var _utils = require("../utils");
@@ -85,12 +84,11 @@ const isWorkflowApplicable = (entry, workflow) => {
85
84
  if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
86
85
  return true;
87
86
  } else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
88
- var _workflow$scope$data, _workflow$scope$data2;
89
- const models = (_workflow$scope$data = workflow.scope.data) === null || _workflow$scope$data === void 0 ? void 0 : _workflow$scope$data.models;
87
+ const models = workflow.scope.data?.models;
90
88
  if (Array.isArray(models) && models.includes(entry.modelId)) {
91
89
  return true;
92
90
  }
93
- const entries = ((_workflow$scope$data2 = workflow.scope.data) === null || _workflow$scope$data2 === void 0 ? void 0 : _workflow$scope$data2.entries) || [];
91
+ const entries = workflow.scope.data?.entries || [];
94
92
  if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {
95
93
  return true;
96
94
  }
@@ -136,12 +134,13 @@ const assignWorkflowToEntry = async params => {
136
134
  console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);
137
135
  continue;
138
136
  }
139
- entry.meta = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry.meta || {}), {}, {
137
+ entry.meta = {
138
+ ...(entry.meta || {}),
140
139
  apw: {
141
140
  workflowId: workflow.id,
142
141
  contentReviewId: null
143
142
  }
144
- });
143
+ };
145
144
  return;
146
145
  }
147
146
  } catch (ex) {