@webiny/api-apw 0.0.0-unstable.8c4d9f045a → 0.0.0-unstable.8feaff8c32

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 (248) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +30 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +30 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +30 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +30 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +1 -6
  14. package/ContentApwSettingsPlugin.js.map +1 -1
  15. package/crud/createChangeRequestMethods.js +21 -25
  16. package/crud/createChangeRequestMethods.js.map +1 -1
  17. package/crud/createCommentMethods.js +21 -26
  18. package/crud/createCommentMethods.js.map +1 -1
  19. package/crud/createContentReviewMethods.js +89 -128
  20. package/crud/createContentReviewMethods.js.map +1 -1
  21. package/crud/createReviewerMethods.js +21 -26
  22. package/crud/createReviewerMethods.js.map +1 -1
  23. package/crud/createWorkflowMethods.d.ts +1 -1
  24. package/crud/createWorkflowMethods.js +37 -28
  25. package/crud/createWorkflowMethods.js.map +1 -1
  26. package/crud/index.js +3 -32
  27. package/crud/index.js.map +1 -1
  28. package/crud/utils.js +4 -36
  29. package/crud/utils.js.map +1 -1
  30. package/index.d.ts +2 -3
  31. package/index.js +6 -16
  32. package/index.js.map +1 -1
  33. package/package.json +40 -46
  34. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +1 -16
  35. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  36. package/plugins/cms/apwEntryPlugins.js +4 -16
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  38. package/plugins/cms/index.js +5 -10
  39. package/plugins/cms/index.js.map +1 -1
  40. package/plugins/cms/linkContentReviewToEntry.js +6 -23
  41. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  42. package/plugins/cms/linkWorkflowToEntry.js +14 -43
  43. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  44. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  45. package/plugins/cms/notifications/changeRequestNotification.js +31 -0
  46. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  47. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  48. package/plugins/cms/notifications/commentNotification.js +31 -0
  49. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  50. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  51. package/plugins/cms/notifications/contentReviewNotification.js +31 -0
  52. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  53. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  54. package/plugins/cms/notifications/contentUrl.js +53 -0
  55. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  56. package/plugins/cms/triggerContentReview.js +6 -20
  57. package/plugins/cms/triggerContentReview.js.map +1 -1
  58. package/plugins/cms/updateContentReviewStatus.js +14 -36
  59. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  60. package/plugins/cms/utils.js +6 -55
  61. package/plugins/cms/utils.js.map +1 -1
  62. package/plugins/context.d.ts +0 -1
  63. package/plugins/context.js +3 -48
  64. package/plugins/context.js.map +1 -1
  65. package/plugins/graphql/changeRequest.gql.js +4 -11
  66. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  67. package/plugins/graphql/comment.gql.js +4 -11
  68. package/plugins/graphql/comment.gql.js.map +1 -1
  69. package/plugins/graphql/contentReview.gql.js +10 -29
  70. package/plugins/graphql/contentReview.gql.js.map +1 -1
  71. package/plugins/graphql/reviewer.gql.js +6 -11
  72. package/plugins/graphql/reviewer.gql.js.map +1 -1
  73. package/plugins/graphql/workflow.gql.js +4 -11
  74. package/plugins/graphql/workflow.gql.js.map +1 -1
  75. package/plugins/graphql.js +4 -19
  76. package/plugins/graphql.js.map +1 -1
  77. package/plugins/hooks/createReviewerFromIdentity.js +26 -15
  78. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  79. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +2 -10
  80. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  81. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +2 -9
  82. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  83. package/plugins/hooks/index.js +4 -12
  84. package/plugins/hooks/index.js.map +1 -1
  85. package/plugins/hooks/initializeContentReviewSteps.js +15 -25
  86. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  87. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  88. package/plugins/hooks/initializeNotifications.js +15 -0
  89. package/plugins/hooks/initializeNotifications.js.map +1 -0
  90. package/plugins/hooks/listContentReviews.d.ts +10 -0
  91. package/plugins/hooks/listContentReviews.js +56 -0
  92. package/plugins/hooks/listContentReviews.js.map +1 -0
  93. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  94. package/plugins/hooks/notifications/appUrl.js +18 -0
  95. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  96. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  97. package/plugins/hooks/notifications/changeRequestAfterCreate.js +111 -0
  98. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  99. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  100. package/plugins/hooks/notifications/changeRequestUrl.js +27 -0
  101. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  102. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  103. package/plugins/hooks/notifications/commentAfterCreate.js +122 -0
  104. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  105. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  106. package/plugins/hooks/notifications/commentUrl.js +27 -0
  107. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  108. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  109. package/plugins/hooks/notifications/contentReviewAfterCreate.js +94 -0
  110. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  111. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  112. package/plugins/hooks/notifications/contentReviewUrl.js +26 -0
  113. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  114. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  115. package/plugins/hooks/notifications/contentUrl.js +24 -0
  116. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  117. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  118. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +21 -0
  119. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  120. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  121. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +21 -0
  122. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  123. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  124. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +21 -0
  125. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  126. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  127. package/plugins/hooks/notifications/reviewers.js +45 -0
  128. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  129. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  130. package/plugins/hooks/notifications/sendChangeRequestNotification.js +41 -0
  131. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  132. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  133. package/plugins/hooks/notifications/sendCommentNotification.js +41 -0
  134. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  135. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  136. package/plugins/hooks/notifications/sendContentReviewNotification.js +41 -0
  137. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  138. package/plugins/hooks/updatePendingChangeRequests.js +7 -19
  139. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  140. package/plugins/hooks/updateTotalComments.js +14 -27
  141. package/plugins/hooks/updateTotalComments.js.map +1 -1
  142. package/plugins/hooks/validateChangeRequest.js +27 -18
  143. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  144. package/plugins/hooks/validateComment.js +13 -14
  145. package/plugins/hooks/validateComment.js.map +1 -1
  146. package/plugins/hooks/validateContentReview.js +2 -8
  147. package/plugins/hooks/validateContentReview.js.map +1 -1
  148. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +1 -16
  149. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  150. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  151. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  152. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  153. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  154. package/plugins/pageBuilder/index.js +5 -8
  155. package/plugins/pageBuilder/index.js.map +1 -1
  156. package/plugins/pageBuilder/linkContentReviewToPage.js +38 -42
  157. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  158. package/plugins/pageBuilder/linkWorkflowToPage.js +14 -32
  159. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  160. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  161. package/plugins/pageBuilder/notifications/changeRequestNotification.js +31 -0
  162. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  163. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  164. package/plugins/pageBuilder/notifications/commentNotification.js +31 -0
  165. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  166. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  167. package/plugins/pageBuilder/notifications/contentReviewNotification.js +31 -0
  168. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  169. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  170. package/plugins/pageBuilder/notifications/contentUrl.js +47 -0
  171. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  172. package/plugins/pageBuilder/triggerContentReview.js +3 -14
  173. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  174. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -26
  175. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  176. package/plugins/pageBuilder/utils.js +2 -36
  177. package/plugins/pageBuilder/utils.js.map +1 -1
  178. package/plugins/utils.d.ts +1 -1
  179. package/plugins/utils.js +4 -57
  180. package/plugins/utils.js.map +1 -1
  181. package/scheduler/createScheduleActionMethods.js +15 -36
  182. package/scheduler/createScheduleActionMethods.js.map +1 -1
  183. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  184. package/scheduler/handlers/executeAction/index.js +45 -39
  185. package/scheduler/handlers/executeAction/index.js.map +1 -1
  186. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
  187. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +15 -6
  188. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  189. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
  190. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +8 -24
  191. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  192. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
  193. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +8 -87
  194. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  195. package/scheduler/handlers/executeAction/security.js +0 -11
  196. package/scheduler/handlers/executeAction/security.js.map +1 -1
  197. package/scheduler/handlers/scheduleAction/index.js +21 -38
  198. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  199. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +9 -32
  200. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  201. package/scheduler/handlers/utils.d.ts +0 -1
  202. package/scheduler/handlers/utils.js +4 -42
  203. package/scheduler/handlers/utils.js.map +1 -1
  204. package/scheduler/index.js +0 -3
  205. package/scheduler/index.js.map +1 -1
  206. package/scheduler/types.d.ts +2 -20
  207. package/scheduler/types.js +12 -23
  208. package/scheduler/types.js.map +1 -1
  209. package/storageOperations/changeRequestStorageOperations.js +22 -45
  210. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  211. package/storageOperations/commentStorageOperations.js +25 -50
  212. package/storageOperations/commentStorageOperations.js.map +1 -1
  213. package/storageOperations/contentReviewStorageOperations.js +22 -43
  214. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  215. package/storageOperations/index.js +5 -23
  216. package/storageOperations/index.js.map +1 -1
  217. package/storageOperations/models/changeRequest.model.js +0 -9
  218. package/storageOperations/models/changeRequest.model.js.map +1 -1
  219. package/storageOperations/models/comment.model.js +0 -8
  220. package/storageOperations/models/comment.model.js.map +1 -1
  221. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
  222. package/storageOperations/models/contentModelPluginFactory.js +5 -17
  223. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  224. package/storageOperations/models/contentReview.model.js +6 -31
  225. package/storageOperations/models/contentReview.model.js.map +1 -1
  226. package/storageOperations/models/index.js +3 -29
  227. package/storageOperations/models/index.js.map +1 -1
  228. package/storageOperations/models/reviewer.model.js +17 -9
  229. package/storageOperations/models/reviewer.model.js.map +1 -1
  230. package/storageOperations/models/utils.js +3 -6
  231. package/storageOperations/models/utils.js.map +1 -1
  232. package/storageOperations/models/workflow.model.js +0 -23
  233. package/storageOperations/models/workflow.model.js.map +1 -1
  234. package/storageOperations/reviewerStorageOperations.js +22 -40
  235. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  236. package/storageOperations/workflowStorageOperations.js +25 -48
  237. package/storageOperations/workflowStorageOperations.js.map +1 -1
  238. package/types.d.ts +104 -88
  239. package/types.js +124 -42
  240. package/types.js.map +1 -1
  241. package/utils/contentApwSettingsPlugin.js +0 -6
  242. package/utils/contentApwSettingsPlugin.js.map +1 -1
  243. package/utils/errors.js +1 -18
  244. package/utils/errors.js.map +1 -1
  245. package/utils/fieldResolver.js +5 -21
  246. package/utils/fieldResolver.js.map +1 -1
  247. package/utils/resolve.js +0 -3
  248. package/utils/resolve.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["triggerContentReview","params","cms","apw","onBeforeEntryPublish","subscribe","entry","model","isAwpModel","contentReviewId","meta","contentReview","get","status","ApwContentReviewStatus","UNDER_REVIEW","Error","workflowId"],"sources":["triggerContentReview.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnBeforeCmsEntryPublishTopicParams\n} from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { isAwpModel } 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.onBeforeEntryPublish.subscribe<OnBeforeCmsEntryPublishTopicParams>(\n async ({ entry, model }) => {\n if (isAwpModel(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.status !== 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;;AACA;;AAMA;;AAMO,MAAMA,oBAAoB,GAAIC,MAAD,IAAwC;EACxE,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAeF,MAArB;EAEAC,GAAG,CAACE,oBAAJ,CAAyBC,SAAzB,CACI,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA4B;IAAA;;IACxB,IAAI,IAAAC,iBAAA,EAAWD,KAAX,CAAJ,EAAuB;MACnB;IACH;;IACD,MAAME,eAAe,kBAAGH,KAAK,CAACI,IAAT,mEAAG,YAAYP,GAAf,oDAAG,gBAAiBM,eAAzC;;IACA,IAAIA,eAAJ,EAAqB;MACjB,MAAME,aAAa,GAAG,MAAMR,GAAG,CAACQ,aAAJ,CAAkBC,GAAlB,CAAsBH,eAAtB,CAA5B;;MAEA,IAAIE,aAAa,CAACE,MAAd,KAAyBC,6BAAA,CAAuBC,YAApD,EAAkE;QAC9D;MACH;;MACD,MAAM,IAAIC,cAAJ,CACD,4DADC,EAEF,sBAFE,EAGF;QACIP,eADJ;QAEIH;MAFJ,CAHE,CAAN;IAQH;;IAED,MAAMW,UAAU,mBAAGX,KAAK,CAACI,IAAT,qEAAG,aAAYP,GAAf,qDAAG,iBAAiBc,UAApC;;IAEA,IAAI,CAACA,UAAL,EAAiB;MACb;IACH;;IACD,MAAM,IAAID,cAAJ,CACF,wEADE,EAEF,iBAFE,EAGF;MACIC,UADJ;MAEIX;IAFJ,CAHE,CAAN;EAQH,CAnCL;AAqCH,CAxCM"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_types","_utils","triggerContentReview","params","cms","apw","onEntryBeforePublish","subscribe","entry","model","_entry$meta","_entry$meta2","isAwpModel","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 { isAwpModel } 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 (isAwpModel(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,iBAAU,EAACH,KAAK,CAAC,EAAE;MACnB;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,101 +1,79 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.updateContentReviewStatus = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _types = require("../../types");
13
-
14
10
  var _utils = require("../../crud/utils");
15
-
16
11
  var _utils2 = require("./utils");
17
-
18
- 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; }
19
-
20
- 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; }
21
-
22
12
  const updateContentReviewStatus = params => {
23
13
  const {
24
14
  apw,
25
15
  cms,
26
16
  security
27
17
  } = params;
28
- cms.onAfterEntryPublish.subscribe(async ({
18
+ cms.onEntryAfterPublish.subscribe(async ({
29
19
  entry,
30
20
  model
31
21
  }) => {
32
- var _entry$meta, _entry$meta$apw;
33
-
22
+ var _entry$meta;
34
23
  if ((0, _utils2.isAwpModel)(model)) {
35
24
  return;
36
25
  }
37
-
38
- const contentReviewId = (_entry$meta = entry.meta) === null || _entry$meta === void 0 ? void 0 : (_entry$meta$apw = _entry$meta.apw) === null || _entry$meta$apw === void 0 ? void 0 : _entry$meta$apw.contentReviewId;
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;
39
27
  /**
40
28
  * Bail out if there is no "content review" linked.
41
29
  */
42
-
43
30
  if (!contentReviewId) {
44
31
  return;
45
32
  }
46
-
47
33
  const contentReview = await apw.contentReview.get(contentReviewId);
48
34
  const identity = security.getIdentity();
49
35
  /**
50
36
  * If content review is "readyToBePublished set its status as "published" after page publish.
51
37
  */
52
-
53
- if (contentReview.status !== _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {
38
+ if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {
54
39
  return;
55
40
  }
56
-
57
41
  await apw.contentReview.update(contentReviewId, {
58
- status: _types.ApwContentReviewStatus.PUBLISHED,
59
- content: _objectSpread(_objectSpread(_objectSpread({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
42
+ reviewStatus: _types.ApwContentReviewStatus.PUBLISHED,
43
+ content: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
60
44
  publishedBy: identity.id
61
45
  })
62
46
  });
63
47
  });
64
- cms.onAfterEntryUnpublish.subscribe(async ({
48
+ cms.onEntryAfterUnpublish.subscribe(async ({
65
49
  entry,
66
50
  model
67
51
  }) => {
68
- var _entry$meta2, _entry$meta2$apw;
69
-
52
+ var _entry$meta2;
70
53
  if ((0, _utils2.isAwpModel)(model)) {
71
54
  return;
72
55
  }
73
-
74
- const contentReviewId = (_entry$meta2 = entry.meta) === null || _entry$meta2 === void 0 ? void 0 : (_entry$meta2$apw = _entry$meta2.apw) === null || _entry$meta2$apw === void 0 ? void 0 : _entry$meta2$apw.contentReviewId;
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;
75
57
  /**
76
58
  * Bail out if there is no "content review" linked.
77
59
  */
78
-
79
60
  if (!contentReviewId) {
80
61
  return;
81
62
  }
82
-
83
63
  const contentReview = await apw.contentReview.get(contentReviewId);
84
64
  /**
85
65
  * If content review is "published set its status as "readyToBePublished" after page unpublish.
86
66
  */
87
67
 
88
- if (contentReview.status !== _types.ApwContentReviewStatus.PUBLISHED) {
68
+ if (contentReview.reviewStatus !== _types.ApwContentReviewStatus.PUBLISHED) {
89
69
  return;
90
70
  }
91
-
92
71
  await apw.contentReview.update(contentReviewId, {
93
- status: _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED,
94
- content: _objectSpread(_objectSpread(_objectSpread({}, contentReview.content), _utils.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META), {}, {
72
+ 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), {}, {
95
74
  publishedBy: null
96
75
  })
97
76
  });
98
77
  });
99
78
  };
100
-
101
79
  exports.updateContentReviewStatus = updateContentReviewStatus;
@@ -1 +1 @@
1
- {"version":3,"names":["updateContentReviewStatus","params","apw","cms","security","onAfterEntryPublish","subscribe","entry","model","isAwpModel","contentReviewId","meta","contentReview","get","identity","getIdentity","status","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","update","PUBLISHED","content","INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META","publishedBy","id","onAfterEntryUnpublish"],"sources":["updateContentReviewStatus.ts"],"sourcesContent":["import {\n AdvancedPublishingWorkflow,\n ApwContentReviewStatus,\n OnAfterCmsEntryPublishTopicParams,\n OnAfterCmsEntryUnpublishTopicParams\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 { isAwpModel } 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.onAfterEntryPublish.subscribe<OnAfterCmsEntryPublishTopicParams>(\n async ({ entry, model }) => {\n if (isAwpModel(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.status !== ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n status: ApwContentReviewStatus.PUBLISHED,\n content: {\n ...contentReview.content,\n ...INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META,\n publishedBy: identity.id\n }\n });\n }\n );\n cms.onAfterEntryUnpublish.subscribe<OnAfterCmsEntryUnpublishTopicParams>(\n async ({ entry, model }) => {\n if (isAwpModel(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.status !== ApwContentReviewStatus.PUBLISHED) {\n return;\n }\n await apw.contentReview.update(contentReviewId, {\n status: 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;;AAMA;;AAGA;;;;;;AAQO,MAAMA,yBAAyB,GAAIC,MAAD,IAA6C;EAClF,MAAM;IAAEC,GAAF;IAAOC,GAAP;IAAYC;EAAZ,IAAyBH,MAA/B;EAEAE,GAAG,CAACE,mBAAJ,CAAwBC,SAAxB,CACI,OAAO;IAAEC,KAAF;IAASC;EAAT,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AG,CAACU,aAAJ,CAAkBO,MAAlB,CAAyBT,eAAzB,EAA0C;MAC5CM,MAAM,EAAEC,6BAAA,CAAuBC,qBADa;MAE5CG,OAAO,gDACAT,aAAa,CAACS,OADd,GAEAC,mDAFA;QAGHC,WAAW,EAAE;MAHV;IAFqC,CAA1C,CAAN;EAQH,CA7BL;AA+BH,CAjEM"}
1
+ {"version":3,"names":["_types","require","_utils","_utils2","updateContentReviewStatus","params","apw","cms","security","onEntryAfterPublish","subscribe","entry","model","_entry$meta","isAwpModel","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 { isAwpModel } 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 (isAwpModel(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 (isAwpModel(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;EAClF,MAAM;IAAEC,GAAG;IAAEC,GAAG;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAErCE,GAAG,CAACE,mBAAmB,CAACC,SAAS,CAC7B,OAAO;IAAEC,KAAK;IAAEC;EAAM,CAAC,KAAK;IAAA,IAAAC,WAAA;IACxB,IAAI,IAAAC,kBAAU,EAACF,KAAK,CAAC,EAAE;MACnB;IACJ;IACA,MAAMG,eAAe,IAAAF,WAAA,GAAGF,KAAK,CAACK,IAAI,cAAAH,WAAA,gBAAAA,WAAA,GAAVA,WAAA,CAAYP,GAAG,cA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AG,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,76 +1,50 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.updateEntryMeta = exports.isAwpModel = exports.hasEntries = exports.getLatestEntryRevision = exports.getEntryTitle = exports.fetchModel = exports.assignWorkflowToEntry = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _types = require("../../types");
15
-
16
11
  var _utils = require("../utils");
17
-
18
12
  var _changeRequest = require("../../storageOperations/models/changeRequest.model");
19
-
20
13
  var _comment = require("../../storageOperations/models/comment.model");
21
-
22
14
  var _contentReview = require("../../storageOperations/models/contentReview.model");
23
-
24
15
  var _reviewer = require("../../storageOperations/models/reviewer.model");
25
-
26
16
  var _workflow = require("../../storageOperations/models/workflow.model");
27
-
28
- 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; }
29
-
30
- 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; }
31
-
32
17
  const fetchModel = async (cms, id, settings) => {
33
18
  if (!settings) {
34
19
  throw new _error.default("Missing settings.", "SETTINGS_ERROR", {
35
20
  id
36
21
  });
37
22
  }
38
-
39
23
  const modelId = settings.modelId;
40
-
41
24
  if (!modelId) {
42
25
  throw new _error.default("Missing modelId in settings.", "MODEL_ID_ERROR", {
43
26
  id,
44
27
  settings
45
28
  });
46
29
  }
47
-
48
30
  const model = await cms.getModel(modelId);
49
-
50
31
  if (model) {
51
32
  return model;
52
33
  }
53
-
54
34
  throw new _error.default("There is no requested model in the system.", "MODEL_NOT_EXISTS", {
55
35
  id,
56
36
  settings
57
37
  });
58
38
  };
59
-
60
39
  exports.fetchModel = fetchModel;
61
-
62
40
  const getEntryTitle = (model, entry) => {
63
41
  const titleFieldId = model.titleFieldId;
64
-
65
42
  if (!titleFieldId || !entry.values[titleFieldId]) {
66
43
  return entry.id;
67
44
  }
68
-
69
45
  return entry.values[titleFieldId];
70
46
  };
71
-
72
47
  exports.getEntryTitle = getEntryTitle;
73
-
74
48
  const getLatestEntryRevision = async params => {
75
49
  const {
76
50
  cms,
@@ -79,18 +53,14 @@ const getLatestEntryRevision = async params => {
79
53
  } = params;
80
54
  const items = await cms.getLatestEntriesByIds(model, [entryId]);
81
55
  const item = items.shift();
82
-
83
56
  if (!item) {
84
57
  throw new _error.default("There is no entry with given ID.", "ENTRY_NOT_FOUND", {
85
58
  entryId
86
59
  });
87
60
  }
88
-
89
61
  return item;
90
62
  };
91
-
92
63
  exports.getLatestEntryRevision = getLatestEntryRevision;
93
-
94
64
  const updateEntryMeta = async params => {
95
65
  const {
96
66
  entryId,
@@ -105,43 +75,31 @@ const updateEntryMeta = async params => {
105
75
  });
106
76
  await cms.updateEntry(model, entry.id, {}, meta);
107
77
  };
108
-
109
78
  exports.updateEntryMeta = updateEntryMeta;
110
-
111
79
  const isWorkflowApplicable = (entry, workflow) => {
112
80
  const application = workflow.app;
113
-
114
81
  if (application !== _types.ApwWorkflowApplications.CMS) {
115
82
  return false;
116
83
  }
117
-
118
84
  const scopeType = workflow.scope.type;
119
-
120
85
  if (scopeType === _types.WorkflowScopeTypes.DEFAULT) {
121
86
  return true;
122
87
  } else if (scopeType === _types.WorkflowScopeTypes.CUSTOM) {
123
88
  var _workflow$scope$data, _workflow$scope$data2;
124
-
125
89
  const models = (_workflow$scope$data = workflow.scope.data) === null || _workflow$scope$data === void 0 ? void 0 : _workflow$scope$data.models;
126
-
127
90
  if (Array.isArray(models) && models.includes(entry.modelId)) {
128
91
  return true;
129
92
  }
130
-
131
93
  const entries = ((_workflow$scope$data2 = workflow.scope.data) === null || _workflow$scope$data2 === void 0 ? void 0 : _workflow$scope$data2.entries) || [];
132
-
133
94
  if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {
134
95
  return true;
135
96
  }
136
-
137
97
  return false;
138
98
  }
139
-
140
99
  throw new _error.default(`Unknown scope type "${scopeType}".`, "UNKNOWN_SCOPE_TYPE", {
141
100
  workflow
142
101
  });
143
102
  };
144
-
145
103
  const assignWorkflowToEntry = async params => {
146
104
  const {
147
105
  apw,
@@ -150,10 +108,9 @@ const assignWorkflowToEntry = async params => {
150
108
  /**
151
109
  * Lookup and assign "workflowId".
152
110
  */
153
-
154
111
  try {
155
112
  /*
156
- * List all workflows for app pageBuilder
113
+ * List all workflows for app cms
157
114
  */
158
115
  const [entries] = await apw.workflow.list({
159
116
  where: {
@@ -161,25 +118,24 @@ const assignWorkflowToEntry = async params => {
161
118
  }
162
119
  });
163
120
  console.log(`Found ${entries.length} workflows.`);
121
+
164
122
  /*
165
123
  * Re-order them based on workflow scope and pre-defined rule i.e.
166
124
  * "specific" entry -> entry for a "category" -> "default".
167
125
  * There can be more than one workflow with same "scope" and "app".
168
126
  * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.
169
127
  */
170
-
171
128
  const sortedWorkflows = entries.sort(_utils.workflowByPrecedenceDesc).sort(_utils.workflowByCreatedOnDesc);
129
+
172
130
  /**
173
131
  * Assign the first applicable workflow to the page and exit.
174
132
  */
175
-
176
133
  for (const workflow of sortedWorkflows) {
177
134
  if (isWorkflowApplicable(entry, workflow) === false) {
178
135
  console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);
179
136
  continue;
180
137
  }
181
-
182
- entry.meta = _objectSpread(_objectSpread({}, entry.meta || {}), {}, {
138
+ entry.meta = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry.meta || {}), {}, {
183
139
  apw: {
184
140
  workflowId: workflow.id,
185
141
  contentReviewId: null
@@ -191,9 +147,7 @@ const assignWorkflowToEntry = async params => {
191
147
  throw new _error.default(`Failed to assign workflow to CMS entry "${entry.id}".`, ex.code, ex.data);
192
148
  }
193
149
  };
194
-
195
150
  exports.assignWorkflowToEntry = assignWorkflowToEntry;
196
-
197
151
  const hasEntries = workflow => {
198
152
  const {
199
153
  app,
@@ -201,11 +155,8 @@ const hasEntries = workflow => {
201
155
  } = workflow;
202
156
  return app === _types.ApwWorkflowApplications.CMS && scope.type === _types.WorkflowScopeTypes.CUSTOM && scope.data && Array.isArray(scope.data.entries);
203
157
  };
204
-
205
158
  exports.hasEntries = hasEntries;
206
-
207
159
  const isAwpModel = model => {
208
160
  return [_changeRequest.CHANGE_REQUEST_MODEL_ID, _comment.COMMENT_MODEL_ID, _contentReview.CONTENT_REVIEW_MODEL_ID, _reviewer.REVIEWER_MODEL_ID, _workflow.WORKFLOW_MODEL_ID].includes(model.modelId);
209
161
  };
210
-
211
162
  exports.isAwpModel = isAwpModel;
@@ -1 +1 @@
1
- {"version":3,"names":["fetchModel","cms","id","settings","WebinyError","modelId","model","getModel","getEntryTitle","entry","titleFieldId","values","getLatestEntryRevision","params","entryId","items","getLatestEntriesByIds","item","shift","updateEntryMeta","meta","updateEntry","isWorkflowApplicable","workflow","application","app","ApwWorkflowApplications","CMS","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","models","data","Array","isArray","includes","entries","some","value","assignWorkflowToEntry","apw","list","where","console","log","length","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","workflowId","contentReviewId","ex","code","hasEntries","isAwpModel","CHANGE_REQUEST_MODEL_ID","COMMENT_MODEL_ID","CONTENT_REVIEW_MODEL_ID","REVIEWER_MODEL_ID","WORKFLOW_MODEL_ID"],"sources":["utils.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport {\n AdvancedPublishingWorkflow,\n ApwWorkflow,\n ApwWorkflowApplications,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { CHANGE_REQUEST_MODEL_ID } from \"~/storageOperations/models/changeRequest.model\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\nimport { REVIEWER_MODEL_ID } from \"~/storageOperations/models/reviewer.model\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\nexport const fetchModel = async (\n cms: HeadlessCms,\n id: string,\n settings?: { modelId?: string } | null\n): Promise<CmsModel> => {\n if (!settings) {\n throw new WebinyError(\"Missing settings.\", \"SETTINGS_ERROR\", {\n id\n });\n }\n const modelId = settings.modelId;\n if (!modelId) {\n throw new WebinyError(\"Missing modelId in settings.\", \"MODEL_ID_ERROR\", {\n id,\n settings\n });\n }\n const model = await cms.getModel(modelId);\n if (model) {\n return model;\n }\n throw new WebinyError(\"There is no requested model in the system.\", \"MODEL_NOT_EXISTS\", {\n id,\n settings\n });\n};\n\nexport const getEntryTitle = (model: CmsModel, entry: CmsEntry): string => {\n const titleFieldId = model.titleFieldId;\n if (!titleFieldId || !entry.values[titleFieldId]) {\n return entry.id;\n }\n return entry.values[titleFieldId];\n};\n\ninterface GetLatestEntryRevisionParams {\n cms: HeadlessCms;\n model: CmsModel;\n entryId: string;\n}\nexport const getLatestEntryRevision = async (\n params: GetLatestEntryRevisionParams\n): Promise<CmsEntry> => {\n const { cms, model, entryId } = params;\n const items = await cms.getLatestEntriesByIds(model, [entryId]);\n\n const item = items.shift();\n if (!item) {\n throw new WebinyError(\"There is no entry with given ID.\", \"ENTRY_NOT_FOUND\", {\n entryId\n });\n }\n return item;\n};\n\ninterface UpdateEntryMetaParams {\n meta: Record<string, any>;\n entryId: string;\n cms: HeadlessCms;\n model: CmsModel;\n}\nexport const updateEntryMeta = async (params: UpdateEntryMetaParams): Promise<void> => {\n const { entryId, cms, model, meta } = params;\n\n const entry = await getLatestEntryRevision({\n cms,\n model,\n entryId\n });\n\n await cms.updateEntry(model, entry.id, {}, meta);\n};\n\nconst isWorkflowApplicable = (entry: CmsEntry, workflow: ApwWorkflow): boolean => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.CMS) {\n return false;\n }\n\n const scopeType = workflow.scope.type;\n\n if (scopeType === WorkflowScopeTypes.DEFAULT) {\n return true;\n } else if (scopeType === WorkflowScopeTypes.CUSTOM) {\n const models = workflow.scope.data?.models;\n\n if (Array.isArray(models) && models.includes(entry.modelId)) {\n return true;\n }\n\n const entries = workflow.scope.data?.entries || [];\n if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {\n return true;\n }\n return false;\n }\n throw new WebinyError(`Unknown scope type \"${scopeType}\".`, \"UNKNOWN_SCOPE_TYPE\", {\n workflow\n });\n};\n\ninterface AssignWorkflowToEntryParams {\n apw: AdvancedPublishingWorkflow;\n entry: CmsEntry;\n}\nexport const assignWorkflowToEntry = async (params: AssignWorkflowToEntryParams): Promise<void> => {\n const { apw, entry } = params;\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app pageBuilder\n */\n const [entries] = await apw.workflow.list({\n where: {\n app: ApwWorkflowApplications.CMS\n }\n });\n\n console.log(`Found ${entries.length} workflows.`);\n\n /*\n * Re-order them based on workflow scope and pre-defined rule i.e.\n * \"specific\" entry -> entry for a \"category\" -> \"default\".\n * There can be more than one workflow with same \"scope\" and \"app\".\n * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.\n */\n const sortedWorkflows = entries\n .sort(workflowByPrecedenceDesc)\n .sort(workflowByCreatedOnDesc);\n\n /**\n * Assign the first applicable workflow to the page and exit.\n */\n for (const workflow of sortedWorkflows) {\n if (isWorkflowApplicable(entry, workflow) === false) {\n console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);\n continue;\n }\n entry.meta = {\n ...(entry.meta || {}),\n apw: {\n workflowId: workflow.id,\n contentReviewId: null\n }\n };\n return;\n }\n } catch (ex) {\n throw new WebinyError(\n `Failed to assign workflow to CMS entry \"${entry.id}\".`,\n ex.code,\n ex.data\n );\n }\n};\n\nexport const hasEntries = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.CMS &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.entries)\n );\n};\n\nexport const isAwpModel = (model: CmsModel): boolean => {\n return [\n CHANGE_REQUEST_MODEL_ID,\n COMMENT_MODEL_ID,\n CONTENT_REVIEW_MODEL_ID,\n REVIEWER_MODEL_ID,\n WORKFLOW_MODEL_ID\n ].includes(model.modelId);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEO,MAAMA,UAAU,GAAG,OACtBC,GADsB,EAEtBC,EAFsB,EAGtBC,Q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CK,KAAK,CAACP,EAAG,IADlD,EAEFqD,EAAE,CAACC,IAFD,EAGFD,EAAE,CAACpB,IAHD,CAAN;EAKH;AACJ,CAnDM;;;;AAqDA,MAAMsB,UAAU,GAAIlC,QAAD,IAAoC;EAC1D,MAAM;IAAEE,GAAF;IAAOI;EAAP,IAAiBN,QAAvB;EACA,OACIE,GAAG,KAAKC,8BAAA,CAAwBC,GAAhC,IACAE,KAAK,CAACC,IAAN,KAAeC,yBAAA,CAAmBE,MADlC,IAEAJ,KAAK,CAACM,IAFN,IAGAC,KAAK,CAACC,OAAN,CAAcR,KAAK,CAACM,IAAN,CAAWI,OAAzB,CAJJ;AAMH,CARM;;;;AAUA,MAAMmB,UAAU,GAAIpD,KAAD,IAA8B;EACpD,OAAO,CACHqD,sCADG,EAEHC,yBAFG,EAGHC,sCAHG,EAIHC,2BAJG,EAKHC,2BALG,EAMLzB,QANK,CAMIhC,KAAK,CAACD,OANV,CAAP;AAOH,CARM"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_types","_utils","_changeRequest","_comment","_contentReview","_reviewer","_workflow","fetchModel","cms","id","settings","WebinyError","modelId","model","getModel","exports","getEntryTitle","entry","titleFieldId","values","getLatestEntryRevision","params","entryId","items","getLatestEntriesByIds","item","shift","updateEntryMeta","meta","updateEntry","isWorkflowApplicable","workflow","application","app","ApwWorkflowApplications","CMS","scopeType","scope","type","WorkflowScopeTypes","DEFAULT","CUSTOM","_workflow$scope$data","_workflow$scope$data2","models","data","Array","isArray","includes","entries","some","value","assignWorkflowToEntry","apw","list","where","console","log","length","sortedWorkflows","sort","workflowByPrecedenceDesc","workflowByCreatedOnDesc","_objectSpread2","default","workflowId","contentReviewId","ex","code","hasEntries","isAwpModel","CHANGE_REQUEST_MODEL_ID","COMMENT_MODEL_ID","CONTENT_REVIEW_MODEL_ID","REVIEWER_MODEL_ID","WORKFLOW_MODEL_ID"],"sources":["utils.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport {\n AdvancedPublishingWorkflow,\n ApwWorkflow,\n ApwWorkflowApplications,\n WorkflowScopeTypes\n} from \"~/types\";\nimport { workflowByCreatedOnDesc, workflowByPrecedenceDesc } from \"~/plugins/utils\";\nimport { CHANGE_REQUEST_MODEL_ID } from \"~/storageOperations/models/changeRequest.model\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\nimport { REVIEWER_MODEL_ID } from \"~/storageOperations/models/reviewer.model\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\nexport const fetchModel = async (\n cms: HeadlessCms,\n id: string,\n settings?: { modelId?: string } | null\n): Promise<CmsModel> => {\n if (!settings) {\n throw new WebinyError(\"Missing settings.\", \"SETTINGS_ERROR\", {\n id\n });\n }\n const modelId = settings.modelId;\n if (!modelId) {\n throw new WebinyError(\"Missing modelId in settings.\", \"MODEL_ID_ERROR\", {\n id,\n settings\n });\n }\n const model = await cms.getModel(modelId);\n if (model) {\n return model;\n }\n throw new WebinyError(\"There is no requested model in the system.\", \"MODEL_NOT_EXISTS\", {\n id,\n settings\n });\n};\n\nexport const getEntryTitle = (model: CmsModel, entry: CmsEntry): string => {\n const titleFieldId = model.titleFieldId;\n if (!titleFieldId || !entry.values[titleFieldId]) {\n return entry.id;\n }\n return entry.values[titleFieldId];\n};\n\ninterface GetLatestEntryRevisionParams {\n cms: HeadlessCms;\n model: CmsModel;\n entryId: string;\n}\nexport const getLatestEntryRevision = async (\n params: GetLatestEntryRevisionParams\n): Promise<CmsEntry> => {\n const { cms, model, entryId } = params;\n const items = await cms.getLatestEntriesByIds(model, [entryId]);\n\n const item = items.shift();\n if (!item) {\n throw new WebinyError(\"There is no entry with given ID.\", \"ENTRY_NOT_FOUND\", {\n entryId\n });\n }\n return item;\n};\n\ninterface UpdateEntryMetaParams {\n meta: Record<string, any>;\n entryId: string;\n cms: HeadlessCms;\n model: CmsModel;\n}\nexport const updateEntryMeta = async (params: UpdateEntryMetaParams): Promise<void> => {\n const { entryId, cms, model, meta } = params;\n\n const entry = await getLatestEntryRevision({\n cms,\n model,\n entryId\n });\n\n await cms.updateEntry(model, entry.id, {}, meta);\n};\n\nconst isWorkflowApplicable = (entry: CmsEntry, workflow: ApwWorkflow): boolean => {\n const application = workflow.app;\n if (application !== ApwWorkflowApplications.CMS) {\n return false;\n }\n\n const scopeType = workflow.scope.type;\n\n if (scopeType === WorkflowScopeTypes.DEFAULT) {\n return true;\n } else if (scopeType === WorkflowScopeTypes.CUSTOM) {\n const models = workflow.scope.data?.models;\n\n if (Array.isArray(models) && models.includes(entry.modelId)) {\n return true;\n }\n\n const entries = workflow.scope.data?.entries || [];\n if (Array.isArray(entries) && entries.some(value => value.id === entry.entryId)) {\n return true;\n }\n return false;\n }\n throw new WebinyError(`Unknown scope type \"${scopeType}\".`, \"UNKNOWN_SCOPE_TYPE\", {\n workflow\n });\n};\n\ninterface AssignWorkflowToEntryParams {\n apw: AdvancedPublishingWorkflow;\n entry: CmsEntry;\n}\nexport const assignWorkflowToEntry = async (params: AssignWorkflowToEntryParams): Promise<void> => {\n const { apw, entry } = params;\n /**\n * Lookup and assign \"workflowId\".\n */\n try {\n /*\n * List all workflows for app cms\n */\n const [entries] = await apw.workflow.list({\n where: {\n app: ApwWorkflowApplications.CMS\n }\n });\n\n console.log(`Found ${entries.length} workflows.`);\n\n /*\n * Re-order them based on workflow scope and pre-defined rule i.e.\n * \"specific\" entry -> entry for a \"category\" -> \"default\".\n * There can be more than one workflow with same \"scope\" and \"app\".\n * Therefore, we are also sorting the workflows by `createdOn` to get the latest workflow.\n */\n const sortedWorkflows = entries\n .sort(workflowByPrecedenceDesc)\n .sort(workflowByCreatedOnDesc);\n\n /**\n * Assign the first applicable workflow to the page and exit.\n */\n for (const workflow of sortedWorkflows) {\n if (isWorkflowApplicable(entry, workflow) === false) {\n console.log(`Not applying workflow ${workflow.id} to entry ${entry.id}.`);\n continue;\n }\n entry.meta = {\n ...(entry.meta || {}),\n apw: {\n workflowId: workflow.id,\n contentReviewId: null\n }\n };\n return;\n }\n } catch (ex) {\n throw new WebinyError(\n `Failed to assign workflow to CMS entry \"${entry.id}\".`,\n ex.code,\n ex.data\n );\n }\n};\n\nexport const hasEntries = (workflow: ApwWorkflow): Boolean => {\n const { app, scope } = workflow;\n return (\n app === ApwWorkflowApplications.CMS &&\n scope.type === WorkflowScopeTypes.CUSTOM &&\n scope.data &&\n Array.isArray(scope.data.entries)\n );\n};\n\nexport const isAwpModel = (model: CmsModel): boolean => {\n return [\n CHANGE_REQUEST_MODEL_ID,\n COMMENT_MODEL_ID,\n CONTENT_REVIEW_MODEL_ID,\n REVIEWER_MODEL_ID,\n WORKFLOW_MODEL_ID\n ].includes(model.modelId);\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAEO,MAAMQ,UAAU,GAAG,MAAAA,CACtBC,GAAgB,EAChBC,EAAU,EACVC,QAAsC,KAClB;EACpB,IAAI,CAACA,QAAQ,EAAE;IACX,MAAM,IAAIC,cAAW,CAAC,mBAAmB,EAAE,gBAAgB,EAAE;MACzDF;IACJ,CAAC,CAAC;EACN;EACA,MAAMG,OAAO,GAAGF,QAAQ,CAACE,OAAO;EAChC,IAAI,CAACA,OAAO,EAAE;IACV,MAAM,IAAID,cAAW,CAAC,8BAA8B,EAAE,gBAAgB,EAAE;MACpEF,EAAE;MACFC;IACJ,CAAC,CAAC;EACN;EACA,MAAMG,KAAK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CAAC;EACL;AACJ,CAAC;AAAC9B,OAAA,CAAAqC,qBAAA,GAAAA,qBAAA;AAEK,MAAMiB,UAAU,GAAItC,QAAqB,IAAc;EAC1D,MAAM;IAAEE,GAAG;IAAEI;EAAM,CAAC,GAAGN,QAAQ;EAC/B,OACIE,GAAG,KAAKC,8BAAuB,CAACC,GAAG,IACnCE,KAAK,CAACC,IAAI,KAAKC,yBAAkB,CAACE,MAAM,IACxCJ,KAAK,CAACQ,IAAI,IACVC,KAAK,CAACC,OAAO,CAACV,KAAK,CAACQ,IAAI,CAACI,OAAO,CAAC;AAEzC,CAAC;AAAClC,OAAA,CAAAsD,UAAA,GAAAA,UAAA;AAEK,MAAMC,UAAU,GAAIzD,KAAe,IAAc;EACpD,OAAO,CACH0D,sCAAuB,EACvBC,yBAAgB,EAChBC,sCAAuB,EACvBC,2BAAiB,EACjBC,2BAAiB,CACpB,CAAC3B,QAAQ,CAACnC,KAAK,CAACD,OAAO,CAAC;AAC7B,CAAC;AAACG,OAAA,CAAAuD,UAAA,GAAAA,UAAA"}
@@ -2,4 +2,3 @@ import { ContextPlugin } from "@webiny/api";
2
2
  import { ApwContext } from "../types";
3
3
  import { CreateApwContextParams } from "../scheduler/types";
4
4
  export declare const createApwPageBuilderContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
5
- export declare const createApwHeadlessCmsContext: (params: CreateApwContextParams) => ContextPlugin<ApwContext>;
@@ -1,36 +1,22 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.createApwPageBuilderContext = exports.createApwHeadlessCmsContext = void 0;
9
-
7
+ exports.createApwPageBuilderContext = void 0;
10
8
  var _hooks = require("./hooks");
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _api = require("@webiny/api");
15
-
16
11
  var _crud = require("../crud");
17
-
18
12
  var _pageBuilder = require("./pageBuilder");
19
-
20
13
  var _storageOperations = require("../storageOperations");
21
-
22
14
  var _scheduler = require("../scheduler");
23
-
24
15
  var _security = require("../scheduler/handlers/executeAction/security");
25
-
26
16
  var _utils = require("./utils");
27
-
28
17
  var _extendPbPageSettingsSchema = require("./pageBuilder/extendPbPageSettingsSchema");
29
-
30
18
  var _apwContentPagePlugins = require("./pageBuilder/apwContentPagePlugins");
31
-
32
19
  var _cms = require("./cms");
33
-
34
20
  const setupApwContext = params => new _api.ContextPlugin(async context => {
35
21
  const {
36
22
  tenancy,
@@ -38,34 +24,26 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
38
24
  i18n,
39
25
  handlerClient
40
26
  } = context;
41
-
42
27
  if ((0, _utils.isInstallationPending)({
43
28
  tenancy,
44
29
  i18n
45
30
  })) {
46
31
  return;
47
32
  }
48
-
49
33
  const getLocale = () => {
50
34
  const locale = i18n.getContentLocale();
51
-
52
35
  if (!locale) {
53
36
  throw new _error.default("Missing content locale in api-apw/plugins/context.ts", "LOCALE_ERROR");
54
37
  }
55
-
56
38
  return locale;
57
39
  };
58
-
59
40
  const getTenant = () => {
60
41
  return tenancy.getCurrentTenant();
61
42
  };
62
-
63
43
  const getPermission = async name => {
64
44
  return security.getPermission(name);
65
45
  };
66
-
67
46
  const getIdentity = () => security.getIdentity();
68
-
69
47
  const scheduler = (0, _scheduler.createScheduler)({
70
48
  getLocale,
71
49
  getIdentity,
@@ -83,7 +61,6 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
83
61
  * TODO: We need to figure out a way to pass "cms" from outside (e.g. apps/api/graphql)
84
62
  */
85
63
  cms: context.cms,
86
-
87
64
  /**
88
65
  * TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
89
66
  */
@@ -95,19 +72,16 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
95
72
  plugins: context.plugins
96
73
  });
97
74
  });
98
-
99
75
  const setupApwPageBuilder = () => {
100
76
  return new _api.ContextPlugin(async context => {
101
77
  (0, _pageBuilder.apwPageBuilderHooks)(context);
102
78
  });
103
79
  };
104
-
105
80
  const setupApwHeadlessCms = () => {
106
81
  return new _api.ContextPlugin(async context => {
107
82
  (0, _cms.apwCmsHooks)(context);
108
83
  });
109
84
  };
110
-
111
85
  const createApwPageBuilderContext = params => {
112
86
  return new _api.ContextPlugin(async context => {
113
87
  if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
@@ -115,7 +89,6 @@ const createApwPageBuilderContext = params => {
115
89
  } else if ((0, _utils.isInstallationPending)(context)) {
116
90
  return;
117
91
  }
118
-
119
92
  await setupApwContext(params).apply(context);
120
93
  await setupApwPageBuilder().apply(context);
121
94
  await setupApwHeadlessCms().apply(context);
@@ -125,22 +98,4 @@ const createApwPageBuilderContext = params => {
125
98
  context.plugins.register((0, _extendPbPageSettingsSchema.extendPbPageSettingsSchema)());
126
99
  });
127
100
  };
128
-
129
- exports.createApwPageBuilderContext = createApwPageBuilderContext;
130
-
131
- const createApwHeadlessCmsContext = params => {
132
- return new _api.ContextPlugin(async context => {
133
- if (!context.wcp.canUseFeature("advancedPublishingWorkflow")) {
134
- return;
135
- } else if ((0, _utils.isInstallationPending)(context)) {
136
- return;
137
- }
138
-
139
- await setupApwContext(params).apply(context);
140
- await setupApwHeadlessCms().apply(context);
141
- await (0, _hooks.attachApwHooks)().apply(context);
142
- await (0, _security.createCustomAuth)(params).apply(context);
143
- });
144
- };
145
-
146
- exports.createApwHeadlessCmsContext = createApwHeadlessCmsContext;
101
+ exports.createApwPageBuilderContext = createApwPageBuilderContext;
@@ -1 +1 @@
1
- {"version":3,"names":["setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema","createApwHeadlessCmsContext"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { apwPageBuilderHooks } from \"./pageBuilder\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { extendPbPageSettingsSchema } from \"~/plugins/pageBuilder/extendPbPageSettingsSchema\";\nimport { apwContentPagePlugins } from \"~/plugins/pageBuilder/apwContentPagePlugins\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst setupApwContext = (params: CreateApwContextParams) =>\n new ContextPlugin<ApwContext>(async context => {\n const { tenancy, security, i18n, handlerClient } = context;\n\n if (isInstallationPending({ tenancy, i18n })) {\n return;\n }\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getPermission = async (name: string): Promise<SecurityPermission | null> => {\n return security.getPermission(name);\n };\n const getIdentity = () => security.getIdentity();\n\n const scheduler = createScheduler({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: params.storageOperations\n });\n\n context.apw = createApw({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: createStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context,\n security\n }),\n scheduler,\n handlerClient,\n plugins: context.plugins\n });\n });\n\nconst setupApwPageBuilder = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwPageBuilderHooks(context);\n });\n};\n\nconst setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwPageBuilder().apply(context);\n await setupApwHeadlessCms().apply(context);\n await apwContentPagePlugins().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n\n context.plugins.register(extendPbPageSettingsSchema());\n });\n};\n\nexport const createApwHeadlessCmsContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwHeadlessCms().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA,MAAMA,eAAe,GAAIC,MAAD,IACpB,IAAIC,kBAAJ,CAA8B,MAAMC,OAAN,IAAiB;EAC3C,MAAM;IAAEC,OAAF;IAAWC,QAAX;IAAqBC,IAArB;IAA2BC;EAA3B,IAA6CJ,OAAnD;;EAEA,IAAI,IAAAK,4BAAA,EAAsB;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EAAoC;MACvC;IACH;;IAED,MAAMH,eAAe,CAACC,MAAD,CAAf,CAAwBiC,KAAxB,CAA8B/B,OAA9B,CAAN;IACA,MAAM0B,mBAAmB,GAAGK,KAAtB,CAA4B/B,OAA5B,CAAN;IACA,MAAM,IAAAiC,qBAAA,IAAiBF,KAAjB,CAAuB/B,OAAvB,CAAN;IACA,MAAM,IAAAkC,0BAAA,EAAiBpC,MAAjB,EAAyBiC,KAAzB,CAA+B/B,OAA/B,CAAN;EACH,CAXM,CAAP;AAYH,CAbM"}
1
+ {"version":3,"names":["_hooks","require","_error","_interopRequireDefault","_api","_crud","_pageBuilder","_storageOperations","_scheduler","_security","_utils","_extendPbPageSettingsSchema","_apwContentPagePlugins","_cms","setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema","exports"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { apwPageBuilderHooks } from \"./pageBuilder\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { extendPbPageSettingsSchema } from \"~/plugins/pageBuilder/extendPbPageSettingsSchema\";\nimport { apwContentPagePlugins } from \"~/plugins/pageBuilder/apwContentPagePlugins\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst setupApwContext = (params: CreateApwContextParams) =>\n new ContextPlugin<ApwContext>(async context => {\n const { tenancy, security, i18n, handlerClient } = context;\n\n if (isInstallationPending({ tenancy, i18n })) {\n return;\n }\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getPermission = async (name: string): Promise<SecurityPermission | null> => {\n return security.getPermission(name);\n };\n const getIdentity = () => security.getIdentity();\n\n const scheduler = createScheduler({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: params.storageOperations\n });\n\n context.apw = createApw({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: createStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context,\n security\n }),\n scheduler,\n handlerClient,\n plugins: context.plugins\n });\n });\n\nconst setupApwPageBuilder = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwPageBuilderHooks(context);\n });\n};\n\nconst setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwPageBuilder().apply(context);\n await setupApwHeadlessCms().apply(context);\n await apwContentPagePlugins().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n\n context.plugins.register(extendPbPageSettingsSchema());\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,kBAAA,GAAAN,OAAA;AAIA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,2BAAA,GAAAV,OAAA;AACA,IAAAW,sBAAA,GAAAX,OAAA;AACA,IAAAY,IAAA,GAAAZ,OAAA;AAGA,MAAMa,eAAe,GAAIC,MAA8B,IACnD,IAAIC,kBAAa,CAAa,MAAMC,OAAO,IAAI;EAC3C,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC,IAAI;IAAEC;EAAc,CAAC,GAAGJ,OAAO;EAE1D,IAAI,IAAAK,4BAAqB,EAAC;IAAEJ,OAAO;IAAEE;EAAK,CAAC,CAAC,EAAE;IAC1C;EACJ;EAEA,MAAMG,SAAS,GAAGA,CAAA,KAAkB;IAChC,MAAMC,MAAM,GAAGJ,IAAI,CAACK,gBAAgB,CAAC,CAAC;IACtC,IAAI,CAACD,MAAM,EAAE;MACT,MAAM,IAAIE,cAAW,CACjB,sDAAsD,EACtD,cACJ,CAAC;IACL;IAEA,OAAOF,MAAM;EACjB,CAAC;EAED,MAAMG,SAAS,GAAGA,CAAA,KAAc;IAC5B,OAAOT,OAAO,CAACU,gBAAgB,CAAC,CAAC;EACrC,CAAC;EAED,MAAMC,aAAa,GAAG,MAAOC,IAAY,IAAyC;IAC9E,OAAOX,QAAQ,CAACU,aAAa,CAACC,IAAI,CAAC;EACvC,CAAC;EACD,MAAMC,WAAW,GAAGA,CAAA,KAAMZ,QAAQ,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