@webiny/api-apw 5.25.0 → 5.30.0

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 (216) hide show
  1. package/ContentApwSettingsPlugin.d.ts +10 -0
  2. package/ContentApwSettingsPlugin.js +17 -0
  3. package/ContentApwSettingsPlugin.js.map +1 -0
  4. package/README.md +7 -6
  5. package/{createApw → crud}/createChangeRequestMethods.d.ts +0 -0
  6. package/{createApw → crud}/createChangeRequestMethods.js +0 -0
  7. package/crud/createChangeRequestMethods.js.map +1 -0
  8. package/{createApw → crud}/createCommentMethods.d.ts +0 -0
  9. package/{createApw → crud}/createCommentMethods.js +0 -0
  10. package/crud/createCommentMethods.js.map +1 -0
  11. package/crud/createContentReviewMethods.d.ts +10 -0
  12. package/{createApw → crud}/createContentReviewMethods.js +269 -19
  13. package/crud/createContentReviewMethods.js.map +1 -0
  14. package/{createApw → crud}/createReviewerMethods.d.ts +0 -0
  15. package/{createApw → crud}/createReviewerMethods.js +0 -0
  16. package/crud/createReviewerMethods.js.map +1 -0
  17. package/{createApw → crud}/createWorkflowMethods.d.ts +0 -0
  18. package/{createApw → crud}/createWorkflowMethods.js +0 -0
  19. package/crud/createWorkflowMethods.js.map +1 -0
  20. package/{createApw → crud}/index.d.ts +0 -0
  21. package/{createApw → crud}/index.js +55 -11
  22. package/crud/index.js.map +1 -0
  23. package/crud/utils.d.ts +21 -0
  24. package/crud/utils.js +142 -0
  25. package/crud/utils.js.map +1 -0
  26. package/index.d.ts +4 -2
  27. package/index.js +11 -5
  28. package/index.js.map +1 -1
  29. package/package.json +37 -30
  30. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +10 -0
  31. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +51 -0
  32. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -0
  33. package/plugins/cms/README.md +49 -0
  34. package/plugins/cms/apwEntryPlugins.d.ts +8 -0
  35. package/plugins/cms/apwEntryPlugins.js +50 -0
  36. package/plugins/cms/apwEntryPlugins.js.map +1 -0
  37. package/plugins/cms/index.d.ts +12 -0
  38. package/plugins/cms/index.js +37 -0
  39. package/plugins/cms/index.js.map +1 -0
  40. package/plugins/cms/linkContentReviewToEntry.d.ts +8 -0
  41. package/plugins/cms/linkContentReviewToEntry.js +108 -0
  42. package/plugins/cms/linkContentReviewToEntry.js.map +1 -0
  43. package/plugins/cms/linkWorkflowToEntry.d.ts +8 -0
  44. package/plugins/cms/linkWorkflowToEntry.js +166 -0
  45. package/plugins/cms/linkWorkflowToEntry.js.map +1 -0
  46. package/plugins/cms/triggerContentReview.d.ts +8 -0
  47. package/plugins/cms/triggerContentReview.js +59 -0
  48. package/plugins/cms/triggerContentReview.js.map +1 -0
  49. package/plugins/cms/updateContentReviewStatus.d.ts +10 -0
  50. package/plugins/cms/updateContentReviewStatus.js +101 -0
  51. package/plugins/cms/updateContentReviewStatus.js.map +1 -0
  52. package/plugins/cms/utils.d.ts +27 -0
  53. package/plugins/cms/utils.js +211 -0
  54. package/plugins/cms/utils.js.map +1 -0
  55. package/plugins/context.d.ts +3 -2
  56. package/plugins/context.js +82 -49
  57. package/plugins/context.js.map +1 -1
  58. package/plugins/graphql/changeRequest.gql.js +1 -1
  59. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  60. package/plugins/graphql/comment.gql.js +8 -17
  61. package/plugins/graphql/comment.gql.js.map +1 -1
  62. package/plugins/graphql/contentReview.gql.js +168 -13
  63. package/plugins/graphql/contentReview.gql.js.map +1 -1
  64. package/plugins/graphql/reviewer.gql.js +1 -1
  65. package/plugins/graphql/reviewer.gql.js.map +1 -1
  66. package/plugins/graphql/workflow.gql.js +18 -15
  67. package/plugins/graphql/workflow.gql.js.map +1 -1
  68. package/plugins/graphql.d.ts +3 -2
  69. package/plugins/graphql.js +11 -1
  70. package/plugins/graphql.js.map +1 -1
  71. package/plugins/hooks/createReviewerFromIdentity.js +18 -0
  72. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  73. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +8 -8
  74. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  75. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +6 -6
  76. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  77. package/plugins/hooks/index.d.ts +1 -2
  78. package/plugins/hooks/index.js +25 -25
  79. package/plugins/hooks/index.js.map +1 -1
  80. package/plugins/hooks/initializeContentReviewSteps.d.ts +2 -7
  81. package/plugins/hooks/initializeContentReviewSteps.js +42 -24
  82. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  83. package/plugins/hooks/updatePendingChangeRequests.js +27 -39
  84. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  85. package/plugins/hooks/updateTotalComments.d.ts +3 -0
  86. package/plugins/hooks/updateTotalComments.js +157 -0
  87. package/plugins/hooks/updateTotalComments.js.map +1 -0
  88. package/plugins/hooks/validateChangeRequest.d.ts +2 -0
  89. package/plugins/hooks/validateChangeRequest.js +64 -0
  90. package/plugins/hooks/validateChangeRequest.js.map +1 -0
  91. package/plugins/hooks/validateComment.d.ts +2 -0
  92. package/plugins/hooks/validateComment.js +45 -0
  93. package/plugins/hooks/validateComment.js.map +1 -0
  94. package/plugins/hooks/validateContentReview.d.ts +2 -0
  95. package/plugins/hooks/validateContentReview.js +38 -0
  96. package/plugins/hooks/validateContentReview.js.map +1 -0
  97. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +9 -0
  98. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +51 -0
  99. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -0
  100. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +3 -0
  101. package/plugins/pageBuilder/apwContentPagePlugins.js +30 -0
  102. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -0
  103. package/plugins/{hooks/extendPbPageSchema.d.ts → pageBuilder/extendPbPageSettingsSchema.d.ts} +1 -2
  104. package/plugins/{hooks/extendPbPageSchema.js → pageBuilder/extendPbPageSettingsSchema.js} +4 -3
  105. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -0
  106. package/plugins/pageBuilder/index.d.ts +11 -0
  107. package/plugins/pageBuilder/index.js +45 -0
  108. package/plugins/pageBuilder/index.js.map +1 -0
  109. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +8 -0
  110. package/plugins/pageBuilder/linkContentReviewToPage.js +93 -0
  111. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -0
  112. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +8 -0
  113. package/plugins/pageBuilder/linkWorkflowToPage.js +182 -0
  114. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -0
  115. package/plugins/pageBuilder/triggerContentReview.d.ts +8 -0
  116. package/plugins/pageBuilder/triggerContentReview.js +50 -0
  117. package/plugins/pageBuilder/triggerContentReview.js.map +1 -0
  118. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +10 -0
  119. package/plugins/pageBuilder/updateContentReviewStatus.js +83 -0
  120. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -0
  121. package/plugins/pageBuilder/utils.d.ts +22 -0
  122. package/plugins/pageBuilder/utils.js +184 -0
  123. package/plugins/pageBuilder/utils.js.map +1 -0
  124. package/plugins/utils.d.ts +22 -2
  125. package/plugins/utils.js +128 -2
  126. package/plugins/utils.js.map +1 -1
  127. package/scheduler/createScheduleActionMethods.d.ts +2 -0
  128. package/scheduler/createScheduleActionMethods.js +146 -0
  129. package/scheduler/createScheduleActionMethods.js.map +1 -0
  130. package/scheduler/handlers/executeAction/index.d.ts +16 -0
  131. package/scheduler/handlers/executeAction/index.js +148 -0
  132. package/scheduler/handlers/executeAction/index.js.map +1 -0
  133. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +13 -0
  134. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +17 -0
  135. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -0
  136. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +11 -0
  137. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +126 -0
  138. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -0
  139. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +11 -0
  140. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +163 -0
  141. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -0
  142. package/scheduler/handlers/executeAction/security.d.ts +4 -0
  143. package/scheduler/handlers/executeAction/security.js +68 -0
  144. package/scheduler/handlers/executeAction/security.js.map +1 -0
  145. package/scheduler/handlers/scheduleAction/index.d.ts +22 -0
  146. package/scheduler/handlers/scheduleAction/index.js +162 -0
  147. package/scheduler/handlers/scheduleAction/index.js.map +1 -0
  148. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +24 -0
  149. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +176 -0
  150. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -0
  151. package/scheduler/handlers/utils.d.ts +33 -0
  152. package/scheduler/handlers/utils.js +168 -0
  153. package/scheduler/handlers/utils.js.map +1 -0
  154. package/scheduler/index.d.ts +2 -0
  155. package/scheduler/index.js +27 -0
  156. package/scheduler/index.js.map +1 -0
  157. package/scheduler/types.d.ts +171 -0
  158. package/scheduler/types.js +34 -0
  159. package/scheduler/types.js.map +1 -0
  160. package/storageOperations/changeRequestStorageOperations.js +1 -3
  161. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  162. package/storageOperations/commentStorageOperations.js +25 -11
  163. package/storageOperations/commentStorageOperations.js.map +1 -1
  164. package/storageOperations/contentReviewStorageOperations.js +1 -3
  165. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  166. package/storageOperations/index.js.map +1 -1
  167. package/storageOperations/models/changeRequest.model.d.ts +1 -0
  168. package/storageOperations/models/changeRequest.model.js +10 -5
  169. package/storageOperations/models/changeRequest.model.js.map +1 -1
  170. package/storageOperations/models/comment.model.d.ts +1 -0
  171. package/storageOperations/models/comment.model.js +24 -3
  172. package/storageOperations/models/comment.model.js.map +1 -1
  173. package/storageOperations/models/contentModelPluginFactory.d.ts +2 -2
  174. package/storageOperations/models/contentModelPluginFactory.js +2 -2
  175. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  176. package/storageOperations/models/contentReview.model.d.ts +1 -0
  177. package/storageOperations/models/contentReview.model.js +98 -26
  178. package/storageOperations/models/contentReview.model.js.map +1 -1
  179. package/storageOperations/models/index.js +25 -5
  180. package/storageOperations/models/index.js.map +1 -1
  181. package/storageOperations/models/reviewer.model.d.ts +1 -0
  182. package/storageOperations/models/reviewer.model.js +11 -6
  183. package/storageOperations/models/reviewer.model.js.map +1 -1
  184. package/storageOperations/models/utils.js.map +1 -1
  185. package/storageOperations/models/workflow.model.d.ts +2 -1
  186. package/storageOperations/models/workflow.model.js +32 -30
  187. package/storageOperations/models/workflow.model.js.map +1 -1
  188. package/storageOperations/reviewerStorageOperations.js +1 -3
  189. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  190. package/storageOperations/types.js.map +1 -1
  191. package/storageOperations/workflowStorageOperations.js +21 -7
  192. package/storageOperations/workflowStorageOperations.js.map +1 -1
  193. package/types.d.ts +138 -49
  194. package/types.js +9 -3
  195. package/types.js.map +1 -1
  196. package/utils/contentApwSettingsPlugin.d.ts +9 -0
  197. package/utils/contentApwSettingsPlugin.js +26 -0
  198. package/utils/contentApwSettingsPlugin.js.map +1 -0
  199. package/utils/errors.js.map +1 -1
  200. package/utils/fieldResolver.js +2 -2
  201. package/utils/fieldResolver.js.map +1 -1
  202. package/utils/resolve.js.map +1 -1
  203. package/createApw/createChangeRequestMethods.js.map +0 -1
  204. package/createApw/createCommentMethods.js.map +0 -1
  205. package/createApw/createContentReviewMethods.d.ts +0 -6
  206. package/createApw/createContentReviewMethods.js.map +0 -1
  207. package/createApw/createReviewerMethods.js.map +0 -1
  208. package/createApw/createWorkflowMethods.js.map +0 -1
  209. package/createApw/index.js.map +0 -1
  210. package/plugins/createManageCMSPlugin.d.ts +0 -2
  211. package/plugins/createManageCMSPlugin.js +0 -31
  212. package/plugins/createManageCMSPlugin.js.map +0 -1
  213. package/plugins/hooks/extendPbPageSchema.js.map +0 -1
  214. package/plugins/hooks/linkWorkflowToPage.d.ts +0 -9
  215. package/plugins/hooks/linkWorkflowToPage.js +0 -155
  216. package/plugins/hooks/linkWorkflowToPage.js.map +0 -1
@@ -24,32 +24,76 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
24
24
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
25
 
26
26
  const createApw = params => {
27
- const workflowGetters = new Map();
27
+ const contentGetters = new Map();
28
+ const contentPublisher = new Map();
29
+ const contentUnPublisher = new Map();
28
30
  const workflowMethods = (0, _createWorkflowMethods.createWorkflowMethods)(params);
29
31
  const reviewerMethods = (0, _createReviewerMethods.createReviewerMethods)(params);
30
32
  const changeRequestMethods = (0, _createChangeRequestMethods.createChangeRequestMethods)(params);
33
+
34
+ function getContentGetter(type) {
35
+ const getter = contentGetters.get(type);
36
+
37
+ if (!getter) {
38
+ throw new Error(`No "ContentGetter" loader found for type: "${type}". You must define a loader.`);
39
+ }
40
+
41
+ return getter;
42
+ }
43
+
44
+ function getContentUnPublisher(type) {
45
+ const getter = contentUnPublisher.get(type);
46
+
47
+ if (!getter) {
48
+ throw new Error(`No "Content UnPublisher" loader found for type: "${type}". You must define a loader.`);
49
+ }
50
+
51
+ return getter;
52
+ }
53
+
54
+ function getContentPublisher(type) {
55
+ const getter = contentPublisher.get(type);
56
+
57
+ if (!getter) {
58
+ throw new Error(`No "ContentPublisher" loader found for type: "${type}". You must define a loader.`);
59
+ }
60
+
61
+ return getter;
62
+ }
63
+
31
64
  return {
32
- addWorkflowGetter(type, func) {
33
- workflowGetters.set(type, func);
65
+ addContentPublisher(type, func) {
66
+ contentPublisher.set(type, func);
34
67
  },
35
68
 
36
- getWorkflowGetter(type) {
37
- const getter = workflowGetters.get(type);
69
+ getContentPublisher,
70
+
71
+ addContentGetter(type, func) {
72
+ contentGetters.set(type, func);
73
+ },
38
74
 
39
- if (!getter) {
40
- throw new Error(`No loader found for type: "${type}". You must define a loader.`);
41
- }
75
+ getContentGetter,
42
76
 
43
- return getter;
77
+ addContentUnPublisher(type, func) {
78
+ contentUnPublisher.set(type, func);
44
79
  },
45
80
 
81
+ getContentUnPublisher,
46
82
  workflow: workflowMethods,
47
83
  reviewer: reviewerMethods,
48
84
  changeRequest: changeRequestMethods,
49
85
  comment: (0, _createCommentMethods.createCommentMethods)(params),
50
86
  contentReview: (0, _createContentReviewMethods.createContentReviewMethods)(_objectSpread(_objectSpread({}, params), {}, {
51
- getReviewer: reviewerMethods.get.bind(reviewerMethods)
52
- }))
87
+ getReviewer: reviewerMethods.get.bind(reviewerMethods),
88
+ getContentGetter,
89
+ getContentPublisher,
90
+ getContentUnPublisher
91
+ })),
92
+
93
+ /**
94
+ * Add scheduler to context so that we can access it later. For example, during testing.
95
+ */
96
+ scheduleAction: params.scheduler
53
97
  };
54
98
  };
55
99
 
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createApw","params","contentGetters","Map","contentPublisher","contentUnPublisher","workflowMethods","createWorkflowMethods","reviewerMethods","createReviewerMethods","changeRequestMethods","createChangeRequestMethods","getContentGetter","type","getter","get","Error","getContentUnPublisher","getContentPublisher","addContentPublisher","func","set","addContentGetter","addContentUnPublisher","workflow","reviewer","changeRequest","comment","createCommentMethods","contentReview","createContentReviewMethods","getReviewer","bind","scheduleAction","scheduler"],"sources":["index.ts"],"sourcesContent":["import { createWorkflowMethods } from \"./createWorkflowMethods\";\nimport { createReviewerMethods } from \"./createReviewerMethods\";\nimport { createCommentMethods } from \"./createCommentMethods\";\nimport { createChangeRequestMethods } from \"./createChangeRequestMethods\";\nimport { createContentReviewMethods } from \"./createContentReviewMethods\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentTypes,\n ContentGetter,\n ContentPublisher,\n ContentUnPublisher,\n CreateApwParams\n} from \"~/types\";\n\nexport const createApw = (params: CreateApwParams): AdvancedPublishingWorkflow => {\n const contentGetters = new Map<ApwContentTypes, ContentGetter>();\n const contentPublisher = new Map<ApwContentTypes, ContentPublisher>();\n const contentUnPublisher = new Map<ApwContentTypes, ContentUnPublisher>();\n\n const workflowMethods = createWorkflowMethods(params);\n const reviewerMethods = createReviewerMethods(params);\n const changeRequestMethods = createChangeRequestMethods(params);\n\n function getContentGetter(type: ApwContentTypes) {\n const getter = contentGetters.get(type);\n if (!getter) {\n throw new Error(\n `No \"ContentGetter\" loader found for type: \"${type}\". You must define a loader.`\n );\n }\n return getter;\n }\n\n function getContentUnPublisher(type: ApwContentTypes) {\n const getter = contentUnPublisher.get(type);\n if (!getter) {\n throw new Error(\n `No \"Content UnPublisher\" loader found for type: \"${type}\". You must define a loader.`\n );\n }\n return getter;\n }\n\n function getContentPublisher(type: ApwContentTypes) {\n const getter = contentPublisher.get(type);\n if (!getter) {\n throw new Error(\n `No \"ContentPublisher\" loader found for type: \"${type}\". You must define a loader.`\n );\n }\n return getter;\n }\n\n return {\n addContentPublisher(type, func) {\n contentPublisher.set(type, func);\n },\n getContentPublisher,\n addContentGetter(type, func) {\n contentGetters.set(type, func);\n },\n getContentGetter,\n addContentUnPublisher(type, func) {\n contentUnPublisher.set(type, func);\n },\n getContentUnPublisher,\n workflow: workflowMethods,\n reviewer: reviewerMethods,\n changeRequest: changeRequestMethods,\n comment: createCommentMethods(params),\n contentReview: createContentReviewMethods({\n ...params,\n getReviewer: reviewerMethods.get.bind(reviewerMethods),\n getContentGetter,\n getContentPublisher,\n getContentUnPublisher\n }),\n /**\n * Add scheduler to context so that we can access it later. For example, during testing.\n */\n scheduleAction: params.scheduler\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAUO,MAAMA,SAAS,GAAIC,MAAD,IAAyD;EAC9E,MAAMC,cAAc,GAAG,IAAIC,GAAJ,EAAvB;EACA,MAAMC,gBAAgB,GAAG,IAAID,GAAJ,EAAzB;EACA,MAAME,kBAAkB,GAAG,IAAIF,GAAJ,EAA3B;EAEA,MAAMG,eAAe,GAAG,IAAAC,4CAAA,EAAsBN,MAAtB,CAAxB;EACA,MAAMO,eAAe,GAAG,IAAAC,4CAAA,EAAsBR,MAAtB,CAAxB;EACA,MAAMS,oBAAoB,GAAG,IAAAC,sDAAA,EAA2BV,MAA3B,CAA7B;;EAEA,SAASW,gBAAT,CAA0BC,IAA1B,EAAiD;IAC7C,MAAMC,MAAM,GAAGZ,cAAc,CAACa,GAAf,CAAmBF,IAAnB,CAAf;;IACA,IAAI,CAACC,MAAL,EAAa;MACT,MAAM,IAAIE,KAAJ,CACD,8CAA6CH,IAAK,8BADjD,CAAN;IAGH;;IACD,OAAOC,MAAP;EACH;;EAED,SAASG,qBAAT,CAA+BJ,IAA/B,EAAsD;IAClD,MAAMC,MAAM,GAAGT,kBAAkB,CAACU,GAAnB,CAAuBF,IAAvB,CAAf;;IACA,IAAI,CAACC,MAAL,EAAa;MACT,MAAM,IAAIE,KAAJ,CACD,oDAAmDH,IAAK,8BADvD,CAAN;IAGH;;IACD,OAAOC,MAAP;EACH;;EAED,SAASI,mBAAT,CAA6BL,IAA7B,EAAoD;IAChD,MAAMC,MAAM,GAAGV,gBAAgB,CAACW,GAAjB,CAAqBF,IAArB,CAAf;;IACA,IAAI,CAACC,MAAL,EAAa;MACT,MAAM,IAAIE,KAAJ,CACD,iDAAgDH,IAAK,8BADpD,CAAN;IAGH;;IACD,OAAOC,MAAP;EACH;;EAED,OAAO;IACHK,mBAAmB,CAACN,IAAD,EAAOO,IAAP,EAAa;MAC5BhB,gBAAgB,CAACiB,GAAjB,CAAqBR,IAArB,EAA2BO,IAA3B;IACH,CAHE;;IAIHF,mBAJG;;IAKHI,gBAAgB,CAACT,IAAD,EAAOO,IAAP,EAAa;MACzBlB,cAAc,CAACmB,GAAf,CAAmBR,IAAnB,EAAyBO,IAAzB;IACH,CAPE;;IAQHR,gBARG;;IASHW,qBAAqB,CAACV,IAAD,EAAOO,IAAP,EAAa;MAC9Bf,kBAAkB,CAACgB,GAAnB,CAAuBR,IAAvB,EAA6BO,IAA7B;IACH,CAXE;;IAYHH,qBAZG;IAaHO,QAAQ,EAAElB,eAbP;IAcHmB,QAAQ,EAAEjB,eAdP;IAeHkB,aAAa,EAAEhB,oBAfZ;IAgBHiB,OAAO,EAAE,IAAAC,0CAAA,EAAqB3B,MAArB,CAhBN;IAiBH4B,aAAa,EAAE,IAAAC,sDAAA,kCACR7B,MADQ;MAEX8B,WAAW,EAAEvB,eAAe,CAACO,GAAhB,CAAoBiB,IAApB,CAAyBxB,eAAzB,CAFF;MAGXI,gBAHW;MAIXM,mBAJW;MAKXD;IALW,GAjBZ;;IAwBH;AACR;AACA;IACQgB,cAAc,EAAEhC,MAAM,CAACiC;EA3BpB,CAAP;AA6BH,CApEM"}
@@ -0,0 +1,21 @@
1
+ import { ApwContentReview, ApwContentReviewListParams, ApwContentReviewStep, ListMeta } from "../types";
2
+ import { CreateContentReviewMethodsParams } from "./createContentReviewMethods";
3
+ export declare function checkValidDateTime(datetime: string | undefined): void;
4
+ export interface GetPendingRequiredSteps {
5
+ (steps: ApwContentReviewStep[], predicate: (step: ApwContentReviewStep) => boolean): ApwContentReviewStep[];
6
+ }
7
+ export declare const getPendingRequiredSteps: GetPendingRequiredSteps;
8
+ export declare const INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META: {
9
+ scheduledOn: null;
10
+ scheduledBy: null;
11
+ scheduledActionId: null;
12
+ };
13
+ export interface FilterContentReviewsParams extends Pick<CreateContentReviewMethodsParams, "getReviewer" | "getIdentity"> {
14
+ listParams: ApwContentReviewListParams;
15
+ listContentReviews: CreateContentReviewMethodsParams["storageOperations"]["listContentReviews"];
16
+ }
17
+ /**
18
+ * Filter "content reviews" that are "underReview" and current user is a reviewer for the active step.
19
+ * That is the user is able to provide sign-off or comment.
20
+ */
21
+ export declare const filterContentReviewsByRequiresMyAttention: (params: FilterContentReviewsParams) => Promise<[ApwContentReview[], ListMeta]>;
package/crud/utils.js ADDED
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META = void 0;
9
+ exports.checkValidDateTime = checkValidDateTime;
10
+ exports.getPendingRequiredSteps = exports.filterContentReviewsByRequiresMyAttention = void 0;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ var _dayjs = _interopRequireDefault(require("dayjs"));
17
+
18
+ var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
19
+
20
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
21
+
22
+ var _set = _interopRequireDefault(require("lodash/set"));
23
+
24
+ var _types = require("../types");
25
+
26
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
27
+
28
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
29
+
30
+ _dayjs.default.extend(_utc.default);
31
+
32
+ function checkValidDateTime(datetime) {
33
+ if (typeof datetime !== "string") {
34
+ return;
35
+ }
36
+
37
+ if (!(0, _dayjs.default)(datetime).isValid()) {
38
+ throw new _error.default({
39
+ message: `Invalid input "datetime" should be an ISO string.`,
40
+ code: "INVALID_DATETIME_FORMAT",
41
+ data: {
42
+ datetime
43
+ }
44
+ });
45
+ }
46
+
47
+ const today = _dayjs.default.utc();
48
+
49
+ if ((0, _dayjs.default)(datetime).isBefore(today)) {
50
+ throw new _error.default({
51
+ message: `Cannot schedule for a past "datetime".`,
52
+ code: "PAST_DATETIME",
53
+ data: {
54
+ datetime
55
+ }
56
+ });
57
+ }
58
+ }
59
+
60
+ const getPendingRequiredSteps = (steps, predicate) => {
61
+ return steps.filter(step => {
62
+ const isRequiredStep = [_types.ApwWorkflowStepTypes.MANDATORY_BLOCKING, _types.ApwWorkflowStepTypes.MANDATORY_NON_BLOCKING].includes(step.type);
63
+
64
+ if (!isRequiredStep) {
65
+ return false;
66
+ }
67
+
68
+ return predicate(step);
69
+ });
70
+ };
71
+
72
+ exports.getPendingRequiredSteps = getPendingRequiredSteps;
73
+ const INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META = {
74
+ scheduledOn: null,
75
+ scheduledBy: null,
76
+ scheduledActionId: null
77
+ };
78
+ exports.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META = INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META;
79
+
80
+ /**
81
+ * Filter "content reviews" that are "underReview" and current user is a reviewer for the active step.
82
+ * That is the user is able to provide sign-off or comment.
83
+ */
84
+ const filterContentReviewsByRequiresMyAttention = async params => {
85
+ const {
86
+ listContentReviews,
87
+ listParams,
88
+ getIdentity,
89
+ getReviewer
90
+ } = params;
91
+ /**
92
+ * Get all "content reviews" with status "underReview"
93
+ */
94
+
95
+ const newListParams = (0, _set.default)((0, _cloneDeep.default)(listParams), "where.status", _types.ApwContentReviewStatus.UNDER_REVIEW);
96
+ const [contentReviews, meta] = await listContentReviews(newListParams);
97
+ const identity = getIdentity();
98
+ const filteredItems = [];
99
+ /**
100
+ * Filter items where current user is a reviewer for the active step.
101
+ */
102
+
103
+ for (let i = 0; i < contentReviews.length; i++) {
104
+ const contentReview = contentReviews[i];
105
+ const activeStep = contentReview.steps.find(step => step.status === _types.ApwContentReviewStepStatus.ACTIVE);
106
+
107
+ if (!activeStep) {
108
+ continue;
109
+ }
110
+
111
+ let requiresMyAttention = false;
112
+
113
+ for (let j = 0; j < activeStep.reviewers.length; j++) {
114
+ const {
115
+ id
116
+ } = activeStep.reviewers[j];
117
+ /**
118
+ * Load reviewer
119
+ */
120
+
121
+ const reviewer = await getReviewer(id);
122
+ /**
123
+ * Check if the current logged in user is the reviewer.
124
+ */
125
+
126
+ if (reviewer.identityId === identity.id) {
127
+ requiresMyAttention = true;
128
+ break;
129
+ }
130
+ }
131
+
132
+ if (requiresMyAttention) {
133
+ filteredItems.push(contentReview);
134
+ }
135
+ }
136
+
137
+ return [filteredItems, _objectSpread(_objectSpread({}, meta), {}, {
138
+ totalCount: filteredItems.length
139
+ })];
140
+ };
141
+
142
+ exports.filterContentReviewsByRequiresMyAttention = filterContentReviewsByRequiresMyAttention;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["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","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","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.status\",\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;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAWAA,cAAA,CAAMC,MAAN,CAAaC,YAAb;;AAEO,SAASC,kBAAT,CAA4BC,QAA5B,EAAgE;EACnE,IAAI,OAAOA,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ANGED
@@ -1,2 +1,4 @@
1
- export declare const createApwContext: () => (import("@webiny/handler").ContextPlugin<import("./types").ApwContext> | (import("@webiny/handler-graphql/plugins").GraphQLSchemaPlugin<import("./types").ApwContext> | import("@webiny/handler").ContextPlugin<import("./types").ApwContext>)[])[];
2
- export declare const createApwGraphQL: () => import("@webiny/handler-graphql/plugins").GraphQLSchemaPlugin<import("./types").ApwContext>[];
1
+ import { CreateApwContextParams } from "./scheduler/types";
2
+ export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => import("@webiny/handler").ContextPlugin<import("./types").ApwContext>;
3
+ export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => import("@webiny/handler").ContextPlugin<import("./types").ApwContext>;
4
+ export declare const createApwGraphQL: () => import("@webiny/handler").ContextPlugin<import("./types").ApwContext>;
package/index.js CHANGED
@@ -5,21 +5,27 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.createApwGraphQL = exports.createApwContext = void 0;
8
+ exports.createApwPageBuilderContext = exports.createApwHeadlessCmsContext = exports.createApwGraphQL = void 0;
9
9
 
10
10
  var _graphql = _interopRequireDefault(require("./plugins/graphql"));
11
11
 
12
- var _context = _interopRequireDefault(require("./plugins/context"));
12
+ var _context = require("./plugins/context");
13
13
 
14
14
  /**
15
15
  * We have separated context and GraphQL creation so user can initialize only context if required.
16
16
  * GraphQL will not work without context, but context will without GraphQL.
17
17
  */
18
- const createApwContext = () => {
19
- return (0, _context.default)();
18
+ const createApwHeadlessCmsContext = params => {
19
+ return (0, _context.createApwHeadlessCmsContext)(params);
20
20
  };
21
21
 
22
- exports.createApwContext = createApwContext;
22
+ exports.createApwHeadlessCmsContext = createApwHeadlessCmsContext;
23
+
24
+ const createApwPageBuilderContext = params => {
25
+ return (0, _context.createApwPageBuilderContext)(params);
26
+ };
27
+
28
+ exports.createApwPageBuilderContext = createApwPageBuilderContext;
23
29
 
24
30
  const createApwGraphQL = () => {
25
31
  return (0, _graphql.default)();
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["createApwContext","createApwGraphQL"],"mappings":";;;;;;;;;AAIA;;AACA;;AALA;AACA;AACA;AACA;AAIO,MAAMA,gBAAgB,GAAG,MAAM;AAClC,SAAO,uBAAP;AACH,CAFM;;;;AAIA,MAAMC,gBAAgB,GAAG,MAAM;AAClC,SAAO,uBAAP;AACH,CAFM","sourcesContent":["/**\n * We have separated context and GraphQL creation so user can initialize only context if required.\n * GraphQL will not work without context, but context will without GraphQL.\n */\nimport graphql from \"~/plugins/graphql\";\nimport context from \"./plugins/context\";\n\nexport const createApwContext = () => {\n return context();\n};\n\nexport const createApwGraphQL = () => {\n return graphql();\n};\n"]}
1
+ {"version":3,"names":["createApwHeadlessCmsContext","params","createHeadlessCms","createApwPageBuilderContext","createPageBuilder","createApwGraphQL","graphql"],"sources":["index.ts"],"sourcesContent":["/**\n * We have separated context and GraphQL creation so user can initialize only context if required.\n * GraphQL will not work without context, but context will without GraphQL.\n */\nimport graphql from \"~/plugins/graphql\";\nimport {\n createApwHeadlessCmsContext as createHeadlessCms,\n createApwPageBuilderContext as createPageBuilder\n} from \"./plugins/context\";\nimport { CreateApwContextParams } from \"./scheduler/types\";\n\nexport const createApwHeadlessCmsContext = (params: CreateApwContextParams) => {\n return createHeadlessCms(params);\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return createPageBuilder(params);\n};\n\nexport const createApwGraphQL = () => {\n return graphql();\n};\n"],"mappings":";;;;;;;;;AAIA;;AACA;;AALA;AACA;AACA;AACA;AAQO,MAAMA,2BAA2B,GAAIC,MAAD,IAAoC;EAC3E,OAAO,IAAAC,oCAAA,EAAkBD,MAAlB,CAAP;AACH,CAFM;;;;AAIA,MAAME,2BAA2B,GAAIF,MAAD,IAAoC;EAC3E,OAAO,IAAAG,oCAAA,EAAkBH,MAAlB,CAAP;AACH,CAFM;;;;AAIA,MAAMI,gBAAgB,GAAG,MAAM;EAClC,OAAO,IAAAC,gBAAA,GAAP;AACH,CAFM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-apw",
3
- "version": "5.25.0",
3
+ "version": "5.30.0",
4
4
  "keywords": [
5
5
  "apw:base"
6
6
  ],
@@ -11,49 +11,56 @@
11
11
  "directory": "packages/api-apw"
12
12
  },
13
13
  "description": "GraphQL API for Webiny Advanced Publishing Workflow.",
14
- "contributors": [
15
- "Pavel Denisjuk <pavel@webiny.com>",
16
- "Sven Al Hamad <sven@webiny.com>",
17
- "Adrian Smijulj <adrian@webiny.com>"
18
- ],
14
+ "author": "Webiny Ltd",
19
15
  "license": "MIT",
20
16
  "dependencies": {
21
- "@babel/runtime": "7.17.7",
22
- "@webiny/api-headless-cms": "5.25.0",
23
- "@webiny/api-i18n": "5.25.0",
24
- "@webiny/api-i18n-content": "5.25.0",
25
- "@webiny/api-i18n-ddb": "5.25.0",
26
- "@webiny/api-page-builder": "5.25.0",
27
- "@webiny/api-page-builder-so-ddb": "5.25.0",
28
- "@webiny/api-security": "5.25.0",
29
- "@webiny/api-tenancy": "5.25.0",
30
- "@webiny/error": "5.25.0",
31
- "@webiny/handler": "5.25.0",
32
- "@webiny/handler-aws": "5.25.0",
33
- "@webiny/handler-graphql": "5.25.0",
34
- "@webiny/plugins": "5.25.0",
35
- "@webiny/pubsub": "5.25.0",
36
- "lodash": "4.17.21"
17
+ "@aws-sdk/client-cloudwatch-events": "3.128.0",
18
+ "@babel/runtime": "7.18.6",
19
+ "@commodo/fields": "1.1.2-beta.20",
20
+ "@webiny/api-headless-cms": "5.30.0",
21
+ "@webiny/api-i18n": "5.30.0",
22
+ "@webiny/api-i18n-ddb": "5.30.0",
23
+ "@webiny/api-page-builder": "5.30.0",
24
+ "@webiny/api-security": "5.30.0",
25
+ "@webiny/api-tenancy": "5.30.0",
26
+ "@webiny/api-wcp": "5.30.0",
27
+ "@webiny/db-dynamodb": "5.30.0",
28
+ "@webiny/error": "5.30.0",
29
+ "@webiny/handler": "5.30.0",
30
+ "@webiny/handler-args": "5.30.0",
31
+ "@webiny/handler-aws": "5.30.0",
32
+ "@webiny/handler-client": "5.30.0",
33
+ "@webiny/handler-db": "5.30.0",
34
+ "@webiny/handler-graphql": "5.30.0",
35
+ "@webiny/handler-logs": "5.30.0",
36
+ "@webiny/plugins": "5.30.0",
37
+ "@webiny/pubsub": "5.30.0",
38
+ "@webiny/validation": "5.30.0",
39
+ "dayjs": "1.11.3",
40
+ "lodash": "4.17.21",
41
+ "mdbid": "1.0.0",
42
+ "nanoid": "3.3.4"
37
43
  },
38
44
  "devDependencies": {
39
45
  "@babel/cli": "^7.5.5",
40
46
  "@babel/core": "^7.5.5",
41
47
  "@babel/preset-env": "^7.5.5",
42
48
  "@babel/preset-flow": "^7.0.0",
43
- "@webiny/api-security-so-ddb": "^5.25.0",
44
- "@webiny/api-tenancy-so-ddb": "^5.25.0",
45
- "@webiny/cli": "^5.25.0",
46
- "@webiny/project-utils": "^5.25.0",
47
- "apollo-graphql": "^0.4.1",
49
+ "@webiny/api-headless-cms-ddb": "^5.30.0",
50
+ "@webiny/api-page-builder-so-ddb": "^5.30.0",
51
+ "@webiny/api-security-so-ddb": "^5.30.0",
52
+ "@webiny/api-tenancy-so-ddb": "^5.30.0",
53
+ "@webiny/cli": "^5.30.0",
54
+ "@webiny/project-utils": "^5.30.0",
48
55
  "get-yarn-workspaces": "^1.0.2",
49
56
  "graphql": "^15.7.2",
50
- "jest": "^26.6.3",
57
+ "jest": "^28.1.0",
51
58
  "mdbid": "^1.0.0",
52
59
  "prettier": "^2.3.2",
53
60
  "rimraf": "^3.0.2",
54
61
  "sinon": "^9.0.2",
55
62
  "ttypescript": "^1.5.12",
56
- "typescript": "4.5.5"
63
+ "typescript": "4.7.4"
57
64
  },
58
65
  "publishConfig": {
59
66
  "access": "public",
@@ -63,5 +70,5 @@
63
70
  "build": "yarn webiny run build",
64
71
  "watch": "yarn webiny run watch"
65
72
  },
66
- "gitHead": "4622d2aafbbecea051ab404859ced09a0a97434e"
73
+ "gitHead": "3cadc5d26e565586b28772afbc18ae554ce7b782"
67
74
  }
@@ -0,0 +1,10 @@
1
+ import { ContentApwSettingsPlugin } from "../../ContentApwSettingsPlugin";
2
+ import { CmsEntry } from "@webiny/api-headless-cms/types";
3
+ import { ApwContentTypes } from "../../types";
4
+ export declare class CmsEntryApwSettingsGetterPlugin extends ContentApwSettingsPlugin {
5
+ canUse(type: ApwContentTypes): boolean;
6
+ setWorkflowId(entry: CmsEntry, id: string | null): void;
7
+ getWorkflowId(entry: CmsEntry): string | null;
8
+ setContentReviewId(entry: CmsEntry, id: string | null): void;
9
+ getContentReviewId(entry: CmsEntry): string | null;
10
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.CmsEntryApwSettingsGetterPlugin = void 0;
9
+
10
+ var _ContentApwSettingsPlugin = require("../../ContentApwSettingsPlugin");
11
+
12
+ var _types = require("../../types");
13
+
14
+ var _set = _interopRequireDefault(require("lodash/set"));
15
+
16
+ class CmsEntryApwSettingsGetterPlugin extends _ContentApwSettingsPlugin.ContentApwSettingsPlugin {
17
+ canUse(type) {
18
+ return type === _types.ApwContentTypes.CMS_ENTRY;
19
+ }
20
+
21
+ setWorkflowId(entry, id) {
22
+ entry.meta = (0, _set.default)(entry.meta || {}, "apw.workflowId", id);
23
+ }
24
+
25
+ getWorkflowId(entry) {
26
+ var _entry$meta$apw;
27
+
28
+ if (!entry.meta) {
29
+ return null;
30
+ }
31
+
32
+ return ((_entry$meta$apw = entry.meta.apw) === null || _entry$meta$apw === void 0 ? void 0 : _entry$meta$apw.workflowId) || null;
33
+ }
34
+
35
+ setContentReviewId(entry, id) {
36
+ entry.meta = (0, _set.default)(entry.meta || {}, "apw.contentReviewId", id);
37
+ }
38
+
39
+ getContentReviewId(entry) {
40
+ var _entry$meta$apw2;
41
+
42
+ if (!entry.meta) {
43
+ return null;
44
+ }
45
+
46
+ return ((_entry$meta$apw2 = entry.meta.apw) === null || _entry$meta$apw2 === void 0 ? void 0 : _entry$meta$apw2.contentReviewId) || null;
47
+ }
48
+
49
+ }
50
+
51
+ exports.CmsEntryApwSettingsGetterPlugin = CmsEntryApwSettingsGetterPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CmsEntryApwSettingsGetterPlugin","ContentApwSettingsPlugin","canUse","type","ApwContentTypes","CMS_ENTRY","setWorkflowId","entry","id","meta","set","getWorkflowId","apw","workflowId","setContentReviewId","getContentReviewId","contentReviewId"],"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;;AAEA;;AACA;;AAEO,MAAMA,+BAAN,SAA8CC,kDAA9C,CAAuE;EAC1DC,MAAM,CAACC,IAAD,EAAiC;IACnD,OAAOA,IAAI,KAAKC,sBAAA,CAAgBC,SAAhC;EACH;;EAEeC,aAAa,CAACC,KAAD,EAAkBC,EAAlB,EAAqC;IAC9DD,KAAK,CAACE,IAAN,GAAa,IAAAC,YAAA,EAAIH,KAAK,CAACE,IAAN,IAAc,EAAlB,EAAsB,gBAAtB,EAAwCD,EAAxC,CAAb;EACH;;EAEeG,aAAa,CAACJ,KAAD,EAAiC;IAAA;;IAC1D,IAAI,CAACA,KAAK,CAACE,IAAX,EAAiB;MACb,OAAO,IAAP;IACH;;IACD,OAAO,oBAAAF,KAAK,CAACE,IAAN,CAAWG,GAAX,oEAAgBC,UAAhB,KAA8B,IAArC;EACH;;EAEeC,kBAAkB,CAACP,KAAD,EAAkBC,EAAlB,EAAqC;IACnED,KAAK,CAACE,IAAN,GAAa,IAAAC,YAAA,EAAIH,KAAK,CAACE,IAAN,IAAc,EAAlB,EAAsB,qBAAtB,EAA6CD,EAA7C,CAAb;EACH;;EACeO,kBAAkB,CAACR,KAAD,EAAiC;IAAA;;IAC/D,IAAI,CAACA,KAAK,CAACE,IAAX,EAAiB;MACb,OAAO,IAAP;IACH;;IACD,OAAO,qBAAAF,KAAK,CAACE,IAAN,CAAWG,GAAX,sEAAgBI,eAAhB,KAAmC,IAA1C;EACH;;AAxByE"}
@@ -0,0 +1,49 @@
1
+ # APW for CMS
2
+
3
+ ## Overview
4
+
5
+ This file contains a high-level overview of the process of integrating CMS with Advanced Publishing Workflow (APW). We
6
+ will only discuss _API_ side of things here but if you are interested in _APP_ side please feel free to check
7
+ out [this file](/packages/app-apw/src/plugins/cms/README.md).
8
+
9
+ We have already integrated the Page Builder application. The [pageBuilder](../pageBuilder) folder contains all the
10
+ source code (plugins, methods) for integrating it with APW.
11
+
12
+ We will briefly discuss each of those files:
13
+
14
+ - [apwContentPagePlugins.ts](../pageBuilder/apwContentPagePlugins.ts) - It registers functions onto APW context which
15
+ helps to execute logic such as `getContent`, `publishContent` and `unpublishContent` during the whole workflow.
16
+ - [linkContentReviewToPage.ts](../pageBuilder/linkContentReviewToPage.ts) - It contains logic for hooking into apw
17
+ `contentReivew` and `page` lifecycle events to manipulate `apw.contentReviewId` property in page `settings`. Which is
18
+ essential for performing various business logic checks across the APW application.
19
+ - [linkWorkflowToPage.ts](../pageBuilder/linkWorkflowToPage.ts) - It contains logic for hooking into apw
20
+ `contentReivew` and `page` lifecycle events to manipulate `apw.workflowId` property in page `settings`. Which is
21
+ essential for performing various business logic checks across the APW application.
22
+ - [triggerContentReview.ts](../pageBuilder/triggerContentReview.ts) - It contains logic for hooking
23
+ into `onBeforePagePublish`
24
+ lifecycle event to execute various business logic checks which among other things prevent triggering more than one
25
+ __content review__ for a page.
26
+ - [updateContentReviewStatus.ts](../pageBuilder/updateContentReviewStatus.ts) - As the name suggest, this file contains
27
+ logic that hooks into `onAfterPagePublish` and `onAfterPageUnPublish` lifecycle events to update __content review__
28
+ status and metadata accordingly.
29
+ - [utils.ts](../pageBuilder/utils.ts) - It contains various helper functions that are used in the above-mentioned files.
30
+ I would like to highlight [`assignWorkflowToPage`](../pageBuilder/utils.ts#L70) function
31
+ which is responsible for assigning the most suitable workflow to a page. We need to implement a similar function that
32
+ will work with CMS.
33
+
34
+ As you may have already noticed we are heavily using lifecycle events
35
+ from [`AdvancedPublishingWorkflow`](/packages/api-apw/src/types.ts#L467)
36
+ and [`PageBuilderContextObject`](/packages/api-page-builder/src/graphql/types.ts#L505)
37
+ to executing various business logic which makes it modular and easy to understand.
38
+
39
+ One can follow a similar approach when building the APW integration for CMS. A good amount of code can be taken
40
+ from [pageBuilder](../pageBuilder) and make it work for CMS with slight adjustment to how CMS works.
41
+
42
+ ## We should keep in mind the following points about CMS when building the integration:
43
+
44
+ - CMS entry does not offer a place to store any metadata at the moment. For instance, we need to store `apw` object
45
+ containing `contentReviewId` and `workflowId` for it to be integrated with APW.
46
+ - Unlike PB page, to load an entry we need to know `modelId` as well besides the `entryId`. So, make sure that we save
47
+ that information when assigning __entries__ to a workflow.
48
+
49
+
@@ -0,0 +1,8 @@
1
+ import { AdvancedPublishingWorkflow } from "../../types";
2
+ import { HeadlessCms } from "@webiny/api-headless-cms/types";
3
+ interface ApwEntryPlugins {
4
+ apw: AdvancedPublishingWorkflow;
5
+ cms: HeadlessCms;
6
+ }
7
+ export declare const apwEntryPlugins: (params: ApwEntryPlugins) => void;
8
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.apwEntryPlugins = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _types = require("../../types");
13
+
14
+ var _utils = require("./utils");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
+
20
+ const apwEntryPlugins = params => {
21
+ const {
22
+ cms,
23
+ apw
24
+ } = params;
25
+ apw.addContentGetter(_types.ApwContentTypes.CMS_ENTRY, async (id, settings) => {
26
+ const model = await (0, _utils.fetchModel)(cms, id, settings);
27
+ const item = await cms.getEntryById(model, id);
28
+
29
+ if (!item) {
30
+ return null;
31
+ }
32
+
33
+ return _objectSpread(_objectSpread({}, item), {}, {
34
+ meta: _objectSpread({}, item.meta || {}),
35
+ title: (0, _utils.getEntryTitle)(model, item)
36
+ });
37
+ });
38
+ apw.addContentPublisher(_types.ApwContentTypes.CMS_ENTRY, async (id, settings) => {
39
+ const model = await (0, _utils.fetchModel)(cms, id, settings);
40
+ await cms.publishEntry(model, id);
41
+ return true;
42
+ });
43
+ apw.addContentUnPublisher(_types.ApwContentTypes.CMS_ENTRY, async (id, settings) => {
44
+ const model = await (0, _utils.fetchModel)(cms, id, settings);
45
+ await cms.unpublishEntry(model, id);
46
+ return true;
47
+ });
48
+ };
49
+
50
+ exports.apwEntryPlugins = apwEntryPlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["apwEntryPlugins","params","cms","apw","addContentGetter","ApwContentTypes","CMS_ENTRY","id","settings","model","fetchModel","item","getEntryById","meta","title","getEntryTitle","addContentPublisher","publishEntry","addContentUnPublisher","unpublishEntry"],"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;;AACA;;;;;;AAOO,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2
+ import { HeadlessCms } from "@webiny/api-headless-cms/types";
3
+ import { Security } from "@webiny/api-security/types";
4
+ import { PluginsContainer } from "@webiny/plugins";
5
+ interface ApwCmsHooksParams {
6
+ apw: AdvancedPublishingWorkflow;
7
+ cms: HeadlessCms;
8
+ plugins: PluginsContainer;
9
+ security: Security;
10
+ }
11
+ export declare const apwCmsHooks: (params: ApwCmsHooksParams) => void;
12
+ export {};