@webiny/api-apw 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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 (315) hide show
  1. package/ApwChangeRequestNotification.d.ts +1 -1
  2. package/ApwChangeRequestNotification.js +3 -15
  3. package/ApwChangeRequestNotification.js.map +1 -1
  4. package/ApwCommentNotification.d.ts +1 -1
  5. package/ApwCommentNotification.js +3 -15
  6. package/ApwCommentNotification.js.map +1 -1
  7. package/ApwContentReviewNotification.d.ts +1 -1
  8. package/ApwContentReviewNotification.js +3 -15
  9. package/ApwContentReviewNotification.js.map +1 -1
  10. package/ApwContentUrlPlugin.d.ts +1 -1
  11. package/ApwContentUrlPlugin.js +3 -15
  12. package/ApwContentUrlPlugin.js.map +1 -1
  13. package/ContentApwSettingsPlugin.d.ts +1 -1
  14. package/ContentApwSettingsPlugin.js +5 -9
  15. package/ContentApwSettingsPlugin.js.map +1 -1
  16. package/README.md +3 -3
  17. package/crud/createChangeRequestMethods.d.ts +1 -1
  18. package/crud/createChangeRequestMethods.js +7 -12
  19. package/crud/createChangeRequestMethods.js.map +1 -1
  20. package/crud/createCommentMethods.d.ts +1 -1
  21. package/crud/createCommentMethods.js +7 -13
  22. package/crud/createCommentMethods.js.map +1 -1
  23. package/crud/createContentReviewMethods.d.ts +2 -2
  24. package/crud/createContentReviewMethods.js +76 -115
  25. package/crud/createContentReviewMethods.js.map +1 -1
  26. package/crud/createReviewerMethods.d.ts +1 -1
  27. package/crud/createReviewerMethods.js +7 -13
  28. package/crud/createReviewerMethods.js.map +1 -1
  29. package/crud/createWorkflowMethods.d.ts +1 -1
  30. package/crud/createWorkflowMethods.js +7 -18
  31. package/crud/createWorkflowMethods.js.map +1 -1
  32. package/crud/index.d.ts +1 -1
  33. package/crud/index.js +5 -29
  34. package/crud/index.js.map +1 -1
  35. package/crud/utils.d.ts +2 -2
  36. package/crud/utils.js +7 -35
  37. package/crud/utils.js.map +1 -1
  38. package/index.d.ts +2 -3
  39. package/index.js +6 -19
  40. package/index.js.map +1 -1
  41. package/package.json +32 -50
  42. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +1 -1
  43. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +4 -19
  44. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  45. package/plugins/cms/apwEntryPlugins.d.ts +2 -2
  46. package/plugins/cms/apwEntryPlugins.js +18 -14
  47. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  48. package/plugins/cms/index.d.ts +4 -4
  49. package/plugins/cms/index.js +2 -13
  50. package/plugins/cms/index.js.map +1 -1
  51. package/plugins/cms/linkContentReviewToEntry.d.ts +2 -2
  52. package/plugins/cms/linkContentReviewToEntry.js +4 -20
  53. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  54. package/plugins/cms/linkWorkflowToEntry.d.ts +2 -2
  55. package/plugins/cms/linkWorkflowToEntry.js +18 -46
  56. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  57. package/plugins/cms/notifications/changeRequestNotification.js +2 -4
  58. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
  59. package/plugins/cms/notifications/commentNotification.js +2 -4
  60. package/plugins/cms/notifications/commentNotification.js.map +1 -1
  61. package/plugins/cms/notifications/contentReviewNotification.js +2 -4
  62. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
  63. package/plugins/cms/notifications/contentUrl.js +3 -8
  64. package/plugins/cms/notifications/contentUrl.js.map +1 -1
  65. package/plugins/cms/triggerContentReview.d.ts +2 -2
  66. package/plugins/cms/triggerContentReview.js +5 -18
  67. package/plugins/cms/triggerContentReview.js.map +1 -1
  68. package/plugins/cms/updateContentReviewStatus.d.ts +3 -3
  69. package/plugins/cms/updateContentReviewStatus.js +14 -30
  70. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  71. package/plugins/cms/utils.d.ts +5 -4
  72. package/plugins/cms/utils.js +20 -59
  73. package/plugins/cms/utils.js.map +1 -1
  74. package/plugins/context.d.ts +3 -4
  75. package/plugins/context.js +4 -58
  76. package/plugins/context.js.map +1 -1
  77. package/plugins/graphql/changeRequest.gql.d.ts +1 -1
  78. package/plugins/graphql/changeRequest.gql.js +16 -20
  79. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  80. package/plugins/graphql/comment.gql.d.ts +1 -1
  81. package/plugins/graphql/comment.gql.js +41 -43
  82. package/plugins/graphql/comment.gql.js.map +1 -1
  83. package/plugins/graphql/contentReview.gql.d.ts +1 -1
  84. package/plugins/graphql/contentReview.gql.js +25 -35
  85. package/plugins/graphql/contentReview.gql.js.map +1 -1
  86. package/plugins/graphql/reviewer.gql.d.ts +1 -1
  87. package/plugins/graphql/reviewer.gql.js +15 -20
  88. package/plugins/graphql/reviewer.gql.js.map +1 -1
  89. package/plugins/graphql/utils.d.ts +2 -0
  90. package/plugins/graphql/utils.js +10 -0
  91. package/plugins/graphql/utils.js.map +1 -0
  92. package/plugins/graphql/workflow.gql.d.ts +1 -1
  93. package/plugins/graphql/workflow.gql.js +15 -20
  94. package/plugins/graphql/workflow.gql.js.map +1 -1
  95. package/plugins/graphql.d.ts +1 -1
  96. package/plugins/graphql.js +5 -18
  97. package/plugins/graphql.js.map +1 -1
  98. package/plugins/hooks/createReviewerFromIdentity.d.ts +1 -1
  99. package/plugins/hooks/createReviewerFromIdentity.js +5 -12
  100. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  101. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +1 -1
  102. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +3 -9
  103. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  104. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +1 -1
  105. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +3 -8
  106. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  107. package/plugins/hooks/index.d.ts +1 -1
  108. package/plugins/hooks/index.js +2 -14
  109. package/plugins/hooks/index.js.map +1 -1
  110. package/plugins/hooks/initializeContentReviewSteps.d.ts +1 -1
  111. package/plugins/hooks/initializeContentReviewSteps.js +15 -20
  112. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  113. package/plugins/hooks/initializeNotifications.d.ts +1 -1
  114. package/plugins/hooks/initializeNotifications.js +2 -5
  115. package/plugins/hooks/initializeNotifications.js.map +1 -1
  116. package/plugins/hooks/listContentReviews.d.ts +3 -3
  117. package/plugins/hooks/listContentReviews.js +3 -13
  118. package/plugins/hooks/listContentReviews.js.map +1 -1
  119. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +1 -1
  120. package/plugins/hooks/notifications/changeRequestAfterCreate.js +7 -38
  121. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  122. package/plugins/hooks/notifications/changeRequestUrl.js +2 -4
  123. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
  124. package/plugins/hooks/notifications/commentAfterCreate.d.ts +1 -1
  125. package/plugins/hooks/notifications/commentAfterCreate.js +7 -40
  126. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  127. package/plugins/hooks/notifications/commentUrl.js +2 -4
  128. package/plugins/hooks/notifications/commentUrl.js.map +1 -1
  129. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +1 -1
  130. package/plugins/hooks/notifications/contentReviewAfterCreate.js +9 -35
  131. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  132. package/plugins/hooks/notifications/contentReviewUrl.js +2 -4
  133. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
  134. package/plugins/hooks/notifications/contentUrl.d.ts +2 -2
  135. package/plugins/hooks/notifications/contentUrl.js +2 -5
  136. package/plugins/hooks/notifications/contentUrl.js.map +1 -1
  137. package/plugins/hooks/notifications/getAppUrl.d.ts +2 -0
  138. package/plugins/hooks/notifications/getAppUrl.js +19 -0
  139. package/plugins/hooks/notifications/getAppUrl.js.map +1 -0
  140. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +1 -1
  141. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +2 -4
  142. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
  143. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +1 -1
  144. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +2 -4
  145. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
  146. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +1 -1
  147. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +2 -4
  148. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
  149. package/plugins/hooks/notifications/reviewers.d.ts +1 -1
  150. package/plugins/hooks/notifications/reviewers.js +17 -21
  151. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  152. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +1 -1
  153. package/plugins/hooks/notifications/sendChangeRequestNotification.js +2 -11
  154. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
  155. package/plugins/hooks/notifications/sendCommentNotification.d.ts +1 -1
  156. package/plugins/hooks/notifications/sendCommentNotification.js +2 -11
  157. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
  158. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +1 -1
  159. package/plugins/hooks/notifications/sendContentReviewNotification.js +2 -11
  160. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
  161. package/plugins/hooks/updatePendingChangeRequests.d.ts +1 -1
  162. package/plugins/hooks/updatePendingChangeRequests.js +7 -13
  163. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  164. package/plugins/hooks/updateTotalComments.d.ts +1 -1
  165. package/plugins/hooks/updateTotalComments.js +21 -23
  166. package/plugins/hooks/updateTotalComments.js.map +1 -1
  167. package/plugins/hooks/validateChangeRequest.d.ts +1 -1
  168. package/plugins/hooks/validateChangeRequest.js +2 -16
  169. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  170. package/plugins/hooks/validateComment.d.ts +1 -1
  171. package/plugins/hooks/validateComment.js +3 -12
  172. package/plugins/hooks/validateComment.js.map +1 -1
  173. package/plugins/hooks/validateContentReview.d.ts +1 -1
  174. package/plugins/hooks/validateContentReview.js +2 -6
  175. package/plugins/hooks/validateContentReview.js.map +1 -1
  176. package/plugins/utils.d.ts +7 -6
  177. package/plugins/utils.js +11 -50
  178. package/plugins/utils.js.map +1 -1
  179. package/scheduler/createScheduleActionMethods.d.ts +1 -1
  180. package/scheduler/createScheduleActionMethods.js +105 -85
  181. package/scheduler/createScheduleActionMethods.js.map +1 -1
  182. package/scheduler/handlers/executeAction/index.d.ts +2 -2
  183. package/scheduler/handlers/executeAction/index.js +47 -41
  184. package/scheduler/handlers/executeAction/index.js.map +1 -1
  185. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
  186. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +19 -9
  187. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  188. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +3 -3
  189. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +11 -28
  190. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  191. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +4 -3
  192. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +10 -92
  193. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  194. package/scheduler/handlers/executeAction/security.d.ts +2 -2
  195. package/scheduler/handlers/executeAction/security.js +2 -11
  196. package/scheduler/handlers/executeAction/security.js.map +1 -1
  197. package/scheduler/handlers/scheduleAction/index.d.ts +2 -2
  198. package/scheduler/handlers/scheduleAction/index.js +23 -38
  199. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  200. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +3 -3
  201. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +20 -36
  202. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  203. package/scheduler/handlers/utils.d.ts +2 -4
  204. package/scheduler/handlers/utils.js +22 -53
  205. package/scheduler/handlers/utils.js.map +1 -1
  206. package/scheduler/index.d.ts +1 -1
  207. package/scheduler/index.js +2 -3
  208. package/scheduler/index.js.map +1 -1
  209. package/scheduler/types.d.ts +20 -36
  210. package/scheduler/types.js +11 -23
  211. package/scheduler/types.js.map +1 -1
  212. package/storageOperations/changeRequestStorageOperations.d.ts +2 -2
  213. package/storageOperations/changeRequestStorageOperations.js +43 -41
  214. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  215. package/storageOperations/commentStorageOperations.d.ts +3 -3
  216. package/storageOperations/commentStorageOperations.js +16 -44
  217. package/storageOperations/commentStorageOperations.js.map +1 -1
  218. package/storageOperations/contentReviewStorageOperations.d.ts +3 -3
  219. package/storageOperations/contentReviewStorageOperations.js +19 -41
  220. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  221. package/storageOperations/index.d.ts +3 -9
  222. package/storageOperations/index.js +10 -29
  223. package/storageOperations/index.js.map +1 -1
  224. package/storageOperations/models/changeRequest.model.d.ts +1 -2
  225. package/storageOperations/models/changeRequest.model.js +9 -19
  226. package/storageOperations/models/changeRequest.model.js.map +1 -1
  227. package/storageOperations/models/comment.model.d.ts +1 -2
  228. package/storageOperations/models/comment.model.js +9 -18
  229. package/storageOperations/models/comment.model.js.map +1 -1
  230. package/storageOperations/models/contentReview.model.d.ts +1 -2
  231. package/storageOperations/models/contentReview.model.js +16 -41
  232. package/storageOperations/models/contentReview.model.js.map +1 -1
  233. package/storageOperations/models/index.d.ts +1 -1
  234. package/storageOperations/models/index.js +11 -55
  235. package/storageOperations/models/index.js.map +1 -1
  236. package/storageOperations/models/reviewer.model.d.ts +1 -2
  237. package/storageOperations/models/reviewer.model.js +10 -19
  238. package/storageOperations/models/reviewer.model.js.map +1 -1
  239. package/storageOperations/models/utils.d.ts +2 -2
  240. package/storageOperations/models/utils.js +2 -4
  241. package/storageOperations/models/utils.js.map +1 -1
  242. package/storageOperations/models/workflow.model.d.ts +2 -3
  243. package/storageOperations/models/workflow.model.js +22 -46
  244. package/storageOperations/models/workflow.model.js.map +1 -1
  245. package/storageOperations/reviewerStorageOperations.d.ts +3 -3
  246. package/storageOperations/reviewerStorageOperations.js +23 -50
  247. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  248. package/storageOperations/types.d.ts +2 -2
  249. package/storageOperations/types.js +3 -1
  250. package/storageOperations/types.js.map +1 -1
  251. package/storageOperations/workflowStorageOperations.d.ts +2 -2
  252. package/storageOperations/workflowStorageOperations.js +24 -44
  253. package/storageOperations/workflowStorageOperations.js.map +1 -1
  254. package/types.d.ts +49 -64
  255. package/types.js +121 -43
  256. package/types.js.map +1 -1
  257. package/utils/contentApwSettingsPlugin.d.ts +2 -2
  258. package/utils/contentApwSettingsPlugin.js +2 -6
  259. package/utils/contentApwSettingsPlugin.js.map +1 -1
  260. package/utils/errors.js +2 -17
  261. package/utils/errors.js.map +1 -1
  262. package/utils/fieldResolver.d.ts +2 -2
  263. package/utils/fieldResolver.js +8 -18
  264. package/utils/fieldResolver.js.map +1 -1
  265. package/utils/pickEntryFieldValues.d.ts +3 -0
  266. package/utils/pickEntryFieldValues.js +30 -0
  267. package/utils/pickEntryFieldValues.js.map +1 -0
  268. package/utils/resolve.d.ts +1 -1
  269. package/utils/resolve.js +2 -3
  270. package/utils/resolve.js.map +1 -1
  271. package/plugins/hooks/notifications/appUrl.d.ts +0 -2
  272. package/plugins/hooks/notifications/appUrl.js +0 -22
  273. package/plugins/hooks/notifications/appUrl.js.map +0 -1
  274. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +0 -9
  275. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -51
  276. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +0 -1
  277. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +0 -3
  278. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -30
  279. package/plugins/pageBuilder/apwContentPagePlugins.js.map +0 -1
  280. package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +0 -3
  281. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +0 -25
  282. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +0 -1
  283. package/plugins/pageBuilder/index.d.ts +0 -11
  284. package/plugins/pageBuilder/index.js +0 -53
  285. package/plugins/pageBuilder/index.js.map +0 -1
  286. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +0 -8
  287. package/plugins/pageBuilder/linkContentReviewToPage.js +0 -105
  288. package/plugins/pageBuilder/linkContentReviewToPage.js.map +0 -1
  289. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +0 -8
  290. package/plugins/pageBuilder/linkWorkflowToPage.js +0 -194
  291. package/plugins/pageBuilder/linkWorkflowToPage.js.map +0 -1
  292. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +0 -1
  293. package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -35
  294. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +0 -1
  295. package/plugins/pageBuilder/notifications/commentNotification.d.ts +0 -1
  296. package/plugins/pageBuilder/notifications/commentNotification.js +0 -35
  297. package/plugins/pageBuilder/notifications/commentNotification.js.map +0 -1
  298. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +0 -1
  299. package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -35
  300. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +0 -1
  301. package/plugins/pageBuilder/notifications/contentUrl.d.ts +0 -1
  302. package/plugins/pageBuilder/notifications/contentUrl.js +0 -53
  303. package/plugins/pageBuilder/notifications/contentUrl.js.map +0 -1
  304. package/plugins/pageBuilder/triggerContentReview.d.ts +0 -8
  305. package/plugins/pageBuilder/triggerContentReview.js +0 -50
  306. package/plugins/pageBuilder/triggerContentReview.js.map +0 -1
  307. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +0 -10
  308. package/plugins/pageBuilder/updateContentReviewStatus.js +0 -79
  309. package/plugins/pageBuilder/updateContentReviewStatus.js.map +0 -1
  310. package/plugins/pageBuilder/utils.d.ts +0 -22
  311. package/plugins/pageBuilder/utils.js +0 -184
  312. package/plugins/pageBuilder/utils.js.map +0 -1
  313. package/storageOperations/models/contentModelPluginFactory.d.ts +0 -15
  314. package/storageOperations/models/contentModelPluginFactory.js +0 -28
  315. package/storageOperations/models/contentModelPluginFactory.js.map +0 -1
@@ -4,31 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTypes = void 0;
7
-
8
- /**
9
- * A interface describing the reference to a user that created some data in the database.
10
- *
11
- * @category General
12
- */
13
- let ApwContentTypes;
14
- exports.ApwContentTypes = ApwContentTypes;
15
-
16
- (function (ApwContentTypes) {
7
+ let ApwContentTypes = exports.ApwContentTypes = /*#__PURE__*/function (ApwContentTypes) {
17
8
  ApwContentTypes["PAGE"] = "page";
18
9
  ApwContentTypes["CMS_ENTRY"] = "cms_entry";
19
- })(ApwContentTypes || (exports.ApwContentTypes = ApwContentTypes = {}));
20
-
21
- let ApwScheduleActionTypes;
22
- exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
23
-
24
- (function (ApwScheduleActionTypes) {
10
+ return ApwContentTypes;
11
+ }({});
12
+ let ApwScheduleActionTypes = exports.ApwScheduleActionTypes = /*#__PURE__*/function (ApwScheduleActionTypes) {
25
13
  ApwScheduleActionTypes["PUBLISH"] = "publish";
26
14
  ApwScheduleActionTypes["UNPUBLISH"] = "unpublish";
27
- })(ApwScheduleActionTypes || (exports.ApwScheduleActionTypes = ApwScheduleActionTypes = {}));
28
-
29
- let InvocationTypes;
30
- exports.InvocationTypes = InvocationTypes;
31
-
32
- (function (InvocationTypes) {
15
+ return ApwScheduleActionTypes;
16
+ }({});
17
+ let InvocationTypes = exports.InvocationTypes = /*#__PURE__*/function (InvocationTypes) {
33
18
  InvocationTypes["SCHEDULED"] = "scheduled";
34
- })(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
19
+ return InvocationTypes;
20
+ }({});
21
+
22
+ //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\n/**\n * A interface describing the reference to a user that created some data in the database.\n *\n * @category General\n */\nexport interface CreatedBy {\n /**\n * ID if the user.\n */\n id: string;\n /**\n * Full name of the user.\n */\n displayName: string | null;\n /**\n * Type of the user (admin, user)\n */\n type: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: CreatedBy;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;;AAkCA;AACA;AACA;AACA;AACA;IA+BYA,e;;;WAAAA,e;EAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e;;IAkBAC,sB;;;WAAAA,sB;EAAAA,sB;EAAAA,sB;GAAAA,sB,sCAAAA,sB;;IAiBAC,e;;;WAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e"}
1
+ {"version":3,"names":["ApwContentTypes","exports","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types\";\nimport type { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport type { I18NContext, I18NLocale } from \"@webiny/api-i18n/types\";\nimport type { TenancyContext, Tenant } from \"@webiny/api-tenancy/types\";\nimport type { ApwIdentity } from \"~/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n\n createdOn: string;\n modifiedOn: string | null;\n savedOn: string;\n createdBy: ApwIdentity;\n modifiedBy: ApwIdentity | null;\n savedBy: ApwIdentity;\n\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;IAiDYA,eAAe,GAAAC,OAAA,CAAAD,eAAA,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AAAA,IAuBfE,sBAAsB,GAAAD,OAAA,CAAAC,sBAAA,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAA,IAiBtBC,eAAe,GAAAF,OAAA,CAAAE,eAAA,0BAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { ApwChangeRequestStorageOperations } from "./types";
2
- import { CreateApwStorageOperationsParams } from "./index";
1
+ import type { ApwChangeRequestStorageOperations } from "./types";
2
+ import type { CreateApwStorageOperationsParams } from "./index";
3
3
  export declare const createChangeRequestStorageOperations: (params: CreateApwStorageOperationsParams) => ApwChangeRequestStorageOperations;
@@ -1,70 +1,53 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createChangeRequestStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _index = require("./index");
13
-
8
+ var _pickEntryFieldValues = require("../utils/pickEntryFieldValues");
14
9
  var _fieldResolver = require("../utils/fieldResolver");
15
-
16
10
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
11
  const createChangeRequestStorageOperations = params => {
19
12
  const {
20
13
  cms,
21
14
  getCmsContext,
22
15
  security
23
16
  } = params;
24
-
25
17
  const getChangeRequestModel = async () => {
26
- security.disableAuthorization();
27
18
  const model = await cms.getModel("apwChangeRequestModelDefinition");
28
- security.enableAuthorization();
29
-
30
19
  if (!model) {
31
20
  throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
32
21
  }
33
-
34
22
  return model;
35
23
  };
36
-
37
24
  const getChangeRequest = async ({
38
25
  id
39
26
  }) => {
40
27
  const model = await getChangeRequestModel();
41
- security.disableAuthorization();
42
28
  const entry = await cms.getEntryById(model, id);
43
- security.enableAuthorization();
44
29
  return (0, _fieldResolver.getFieldValues)({
45
30
  entry,
46
- fields: _index.baseFields,
31
+ fields: _pickEntryFieldValues.baseFields,
47
32
  context: getCmsContext(),
48
33
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
49
34
  });
50
35
  };
51
-
52
36
  return {
53
37
  getChangeRequestModel,
54
38
  getChangeRequest,
55
-
56
39
  async listChangeRequests(params) {
57
40
  const model = await getChangeRequestModel();
58
- security.disableAuthorization();
59
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
60
- where: (0, _objectSpread2.default)({}, params.where)
61
- }));
62
- security.enableAuthorization();
63
-
41
+ const [entries, meta] = await cms.listLatestEntries(model, {
42
+ ...params,
43
+ where: {
44
+ ...params.where
45
+ }
46
+ });
64
47
  try {
65
48
  const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
66
49
  entry,
67
- fields: _index.baseFields,
50
+ fields: _pickEntryFieldValues.baseFields,
68
51
  context: getCmsContext(),
69
52
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
70
53
  })));
@@ -73,50 +56,69 @@ const createChangeRequestStorageOperations = params => {
73
56
  throw new _error.default(ex.message, ex.code, ex.data);
74
57
  }
75
58
  },
76
-
77
59
  async createChangeRequest(params) {
78
60
  const model = await getChangeRequestModel();
79
- security.disableAuthorization();
80
61
  const entry = await cms.createEntry(model, params.data);
81
- security.enableAuthorization();
82
62
  return (0, _fieldResolver.getFieldValues)({
83
63
  entry,
84
- fields: _index.baseFields,
64
+ fields: _pickEntryFieldValues.baseFields,
85
65
  context: getCmsContext(),
86
66
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
87
67
  });
88
68
  },
89
-
90
69
  async updateChangeRequest(params) {
91
70
  const model = await getChangeRequestModel();
71
+
92
72
  /**
93
73
  * We're fetching the existing entry here because we're not accepting "app" field as input,
94
74
  * but, we still need to retain its value after the "update" operation.
95
75
  */
96
-
97
76
  const existingEntry = await getChangeRequest({
98
77
  id: params.id
99
78
  });
100
- security.disableAuthorization();
101
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
102
- security.enableAuthorization();
79
+
80
+ /**
81
+ * Only creator can update the change request
82
+ */
83
+ if (existingEntry.createdBy.id !== security.getIdentity().id) {
84
+ throw new _error.default("A change request can only be updated by its creator.", "ONLY_CREATOR_CAN_UPDATE_CHANGE_REQUEST");
85
+ }
86
+ const entry = await cms.updateEntry(model, params.id, {
87
+ ...existingEntry,
88
+ ...params.data,
89
+ savedOn: new Date()
90
+ });
103
91
  return (0, _fieldResolver.getFieldValues)({
104
92
  entry,
105
- fields: _index.baseFields,
93
+ fields: _pickEntryFieldValues.baseFields,
106
94
  context: getCmsContext(),
107
95
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
108
96
  });
109
97
  },
110
-
111
98
  async deleteChangeRequest(params) {
112
99
  const model = await getChangeRequestModel();
113
- security.disableAuthorization();
100
+ if (!security.getIdentity()) {
101
+ return true;
102
+ }
103
+
104
+ /**
105
+ * We're fetching the existing entry
106
+ */
107
+ const existingEntry = await getChangeRequest({
108
+ id: params.id
109
+ });
110
+
111
+ /**
112
+ * Only creator can delete the change request
113
+ */
114
+ if (existingEntry.createdBy.id !== security.getIdentity().id) {
115
+ throw new _error.default("A change request can only be deleted by its creator.", "ONLY_CREATOR_CAN_DELETE_CHANGE_REQUEST");
116
+ }
114
117
  await cms.deleteEntry(model, params.id);
115
- security.enableAuthorization();
116
118
  return true;
117
119
  }
118
-
119
120
  };
120
121
  };
122
+ exports.createChangeRequestStorageOperations = createChangeRequestStorageOperations;
121
123
 
122
- exports.createChangeRequestStorageOperations = createChangeRequestStorageOperations;
124
+ //# sourceMappingURL=changeRequestStorageOperations.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","disableAuthorization","model","getModel","enableAuthorization","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","entries","meta","listLatestEntries","where","all","Promise","map","ex","message","code","data","createChangeRequest","createEntry","updateChangeRequest","existingEntry","updateEntry","deleteChangeRequest","deleteEntry"],"sources":["changeRequestStorageOperations.ts"],"sourcesContent":["import { ApwChangeRequestStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwChangeRequest } from \"~/types\";\n\nexport const createChangeRequestStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwChangeRequestStorageOperations => {\n const { cms, getCmsContext, security } = params;\n const getChangeRequestModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(\"apwChangeRequestModelDefinition\");\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwChangeRequestModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getChangeRequest: ApwChangeRequestStorageOperations[\"getChangeRequest\"] = async ({\n id\n }) => {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getChangeRequestModel,\n getChangeRequest,\n async listChangeRequests(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n security.enableAuthorization();\n try {\n const all = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwChangeRequest>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n return [all, meta];\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, params.data);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async updateChangeRequest(params) {\n const model = await getChangeRequestModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async deleteChangeRequest(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAGO,MAAMA,oCAAoC,GAC7CC,MADgD,IAEZ;EACpC,MAAM;IAAEC,GAAF;IAAOC,aAAP;IAAsBC;EAAtB,IAAmCH,MAAzC;;EACA,MAAMI,qBAAqB,GAAG,YAAY;IACtCD,QAAQ,CAACE,oBAAT;IACA,MAAMC,KAAK,GAAG,MAAML,GAAG,CAACM,QAAJ,CAAa,iCAAb,CAApB;IACAJ,QAAQ,CAACK,mBAAT;;IACA,IAAI,CAACF,KAAL,EAAY;MACR,MAAM,IAAIG,cAAJ,CACF,yDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOH,KAAP;EACH,CAXD;;EAYA,MAAMI,gBAAuE,GAAG,OAAO;IACnFC;EADmF,CAAP,KAE1E;IACF,MAAML,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;IACAD,QAAQ,CAACE,oBAAT;IACA,MAAMO,KAAK,GAAG,MAAMX,GAAG,CAACY,YAAJ,CAAiBP,KAAjB,EAAwBK,EAAxB,CAApB;IACAR,QAAQ,CAACK,mBAAT;IACA,OAAO,IAAAM,6BAAA,EAAe;MAClBF,KADkB;MAElBG,MAAM,EAAEC,iBAFU;MAGlBC,OAAO,EAAEf,aAAa,EAHJ;MAIlBgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;IAJI,CAAf,CAAP;EAMH,CAbD;;EAcA,OAAO;IACHF,qBADG;IAEHM,gBAFG;;IAGH,MA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,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJI,CAAf,CAAP;IAMH,CAxCE;;IAyCH,MAAM4B,mBAAN,CAA0BlC,MAA1B,EAAkC;MAC9B,MAAMM,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;MACA;AACZ;AACA;AACA;;MACY,MAAM+B,aAAa,GAAG,MAAMzB,gBAAgB,CAAC;QAAEC,EAAE,EAAEX,MAAM,CAACW;MAAb,CAAD,CAA5C;MAEAR,QAAQ,CAACE,oBAAT;MACA,MAAMO,KAAK,GAAG,MAAMX,GAAG,CAACmC,WAAJ,CAAgB9B,KAAhB,EAAuBN,MAAM,CAACW,EAA9B,8DACbwB,aADa,GAEbnC,MAAM,CAAC+B,IAFM,EAApB;MAIA5B,QAAQ,CAACK,mBAAT;MACA,OAAO,IAAAM,6BAAA,EAAe;QAClBF,KADkB;QAElBG,MAAM,EAAEC,iBAFU;QAGlBC,OAAO,EAAEf,aAAa,EAHJ;QAIlBgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJI,CAAf,CAAP;IAMH,CA7DE;;IA8DH,MAAM+B,mBAAN,CAA0BrC,MAA1B,EAAkC;MAC9B,MAAMM,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;MACAD,QAAQ,CAACE,oBAAT;MACA,MAAMJ,GAAG,CAACqC,WAAJ,CAAgBhC,KAAhB,EAAuBN,MAAM,CAACW,EAA9B,CAAN;MACAR,QAAQ,CAACK,mBAAT;MACA,OAAO,IAAP;IACH;;EApEE,CAAP;AAsEH,CApGM"}
1
+ {"version":3,"names":["_pickEntryFieldValues","require","_fieldResolver","_error","_interopRequireDefault","createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","model","getModel","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","entries","meta","listLatestEntries","where","all","Promise","map","ex","message","code","data","createChangeRequest","createEntry","updateChangeRequest","existingEntry","createdBy","getIdentity","updateEntry","savedOn","Date","deleteChangeRequest","deleteEntry","exports"],"sources":["changeRequestStorageOperations.ts"],"sourcesContent":["import type { ApwChangeRequestStorageOperations } from \"./types\";\nimport type { CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { baseFields } from \"~/utils/pickEntryFieldValues\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport type { ApwChangeRequest } from \"~/types\";\n\nexport const createChangeRequestStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwChangeRequestStorageOperations => {\n const { cms, getCmsContext, security } = params;\n const getChangeRequestModel = async () => {\n const model = await cms.getModel(\"apwChangeRequestModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwChangeRequestModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getChangeRequest: ApwChangeRequestStorageOperations[\"getChangeRequest\"] = async ({\n id\n }) => {\n const model = await getChangeRequestModel();\n\n const entry = await cms.getEntryById(model, id);\n\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getChangeRequestModel,\n getChangeRequest,\n async listChangeRequests(params) {\n const model = await getChangeRequestModel();\n\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n\n try {\n const all = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwChangeRequest>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n return [all, meta];\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n const entry = await cms.createEntry(model, params.data);\n\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async updateChangeRequest(params) {\n const model = await getChangeRequestModel();\n\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n /**\n * Only creator can update the change request\n */\n if (existingEntry.createdBy.id !== security.getIdentity().id) {\n throw new WebinyError(\n \"A change request can only be updated by its creator.\",\n \"ONLY_CREATOR_CAN_UPDATE_CHANGE_REQUEST\"\n );\n }\n\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data,\n savedOn: new Date()\n });\n\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async deleteChangeRequest(params) {\n const model = await getChangeRequestModel();\n\n if (!security.getIdentity()) {\n return true;\n }\n\n /**\n * We're fetching the existing entry\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n /**\n * Only creator can delete the change request\n */\n if (existingEntry.createdBy.id !== security.getIdentity().id) {\n throw new WebinyError(\n \"A change request can only be deleted by its creator.\",\n \"ONLY_CREATOR_CAN_DELETE_CHANGE_REQUEST\"\n );\n }\n\n await cms.deleteEntry(model, params.id);\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAEA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGO,MAAMI,oCAAoC,GAC7CC,MAAwC,IACJ;EACpC,MAAM;IAAEC,GAAG;IAAEC,aAAa;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAC/C,MAAMI,qBAAqB,GAAG,MAAAA,CAAA,KAAY;IACtC,MAAMC,KAAK,GAAG,MAAMJ,GAAG,CAACK,QAAQ,CAAC,iCAAiC,CAAC;IACnE,IAAI,CAACD,KAAK,EAAE;MACR,MAAM,IAAIE,cAAW,CACjB,yDAAyD,EACzD,uBACJ,CAAC;IACL;IACA,OAAOF,KAAK;EAChB,CAAC;EACD,MAA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C;IACN,CAAC;IACD,MAAMkC,mBAAmBA,CAACvC,MAAM,EAAE;MAC9B,MAAMK,KAAK,GAAG,MAAMD,qBAAqB,CAAC,CAAC;MAE3C,IAAI,CAACD,QAAQ,CAACgC,WAAW,CAAC,CAAC,EAAE;QACzB,OAAO,IAAI;MACf;;MAEA;AACZ;AACA;MACY,MAAMF,aAAa,GAAG,MAAMzB,gBAAgB,CAAC;QAAEC,EAAE,EAAET,MAAM,CAACS;MAAG,CAAC,CAAC;;MAE/D;AACZ;AACA;MACY,IAAIwB,aAAa,CAACC,SAAS,CAACzB,EAAE,KAAKN,QAAQ,CAACgC,WAAW,CAAC,CAAC,CAAC1B,EAAE,EAAE;QAC1D,MAAM,IAAIF,cAAW,CACjB,sDAAsD,EACtD,wCACJ,CAAC;MACL;MAEA,MAAMN,GAAG,CAACuC,WAAW,CAACnC,KAAK,EAAEL,MAAM,CAACS,EAAE,CAAC;MAEvC,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAACgC,OAAA,CAAA1C,oCAAA,GAAAA,oCAAA","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { ApwCommentStorageOperations } from "./types";
2
- import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createCommentStorageOperations: ({ cms, getCmsContext, security }: CreateApwStorageOperationsParams) => ApwCommentStorageOperations;
1
+ import type { ApwCommentStorageOperations } from "./types";
2
+ import type { CreateApwStorageOperationsParams } from "./index";
3
+ export declare const createCommentStorageOperations: ({ cms, getCmsContext }: CreateApwStorageOperationsParams) => ApwCommentStorageOperations;
@@ -1,138 +1,110 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createCommentStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _index = require("./index");
13
-
14
8
  var _fieldResolver = require("../utils/fieldResolver");
15
-
9
+ var _pickEntryFieldValues = require("../utils/pickEntryFieldValues");
16
10
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
11
  var _comment = require("./models/comment.model");
19
-
20
12
  const pickIdFromChangeRequest = obj => {
21
13
  const rawValue = obj["changeRequest"];
22
-
23
14
  if (!rawValue) {
24
15
  return obj;
25
16
  }
26
-
27
17
  obj["changeRequest"] = rawValue.id;
28
18
  return obj;
29
19
  };
30
-
31
20
  const createCommentStorageOperations = ({
32
21
  cms,
33
- getCmsContext,
34
- security
22
+ getCmsContext
35
23
  }) => {
36
24
  const getCommentModel = async () => {
37
- security.disableAuthorization();
38
25
  const model = await cms.getModel(_comment.COMMENT_MODEL_ID);
39
- security.enableAuthorization();
40
-
41
26
  if (!model) {
42
27
  throw new _error.default(`Could not find "${_comment.COMMENT_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
43
28
  }
44
-
45
29
  return model;
46
30
  };
47
-
48
31
  const getComment = async ({
49
32
  id
50
33
  }) => {
51
34
  const model = await getCommentModel();
52
- security.disableAuthorization();
53
35
  const entry = await cms.getEntryById(model, id);
54
- security.enableAuthorization();
55
36
  return (0, _fieldResolver.getFieldValues)({
56
37
  entry,
57
- fields: _index.baseFields,
38
+ fields: _pickEntryFieldValues.baseFields,
58
39
  context: getCmsContext(),
59
40
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
60
41
  });
61
42
  };
62
-
63
43
  return {
64
44
  getCommentModel,
65
45
  getComment: async params => {
66
46
  const values = await getComment(params);
67
47
  return pickIdFromChangeRequest(values);
68
48
  },
69
-
70
49
  async listComments(params) {
71
50
  const model = await getCommentModel();
72
- security.disableAuthorization();
73
51
  const [entries, meta] = await cms.listLatestEntries(model, params);
74
- security.enableAuthorization();
75
52
  const values = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
76
53
  entry,
77
- fields: _index.baseFields,
54
+ fields: _pickEntryFieldValues.baseFields,
78
55
  context: getCmsContext(),
79
56
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
80
57
  })));
81
58
  const all = values.map(value => pickIdFromChangeRequest(value));
82
59
  return [all, meta];
83
60
  },
84
-
85
61
  async createComment(params) {
86
62
  const model = await getCommentModel();
87
63
  const refModel = await this.getChangeRequestModel();
88
- security.disableAuthorization();
89
- const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.data), {}, {
64
+ const entry = await cms.createEntry(model, {
65
+ ...params.data,
90
66
  changeRequest: {
91
67
  id: params.data.changeRequest,
92
68
  modelId: refModel.modelId
93
69
  }
94
- }));
95
- security.enableAuthorization();
70
+ });
96
71
  const values = await (0, _fieldResolver.getFieldValues)({
97
72
  entry,
98
- fields: _index.baseFields,
73
+ fields: _pickEntryFieldValues.baseFields,
99
74
  context: getCmsContext(),
100
75
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
101
76
  });
102
77
  return pickIdFromChangeRequest(values);
103
78
  },
104
-
105
79
  async updateComment(params) {
106
80
  const model = await getCommentModel();
107
81
  /**
108
82
  * We're fetching the existing entry here because we're not accepting "app" field as input,
109
83
  * but, we still need to retain its value after the "update" operation.
110
84
  */
111
-
112
85
  const existingEntry = await getComment({
113
86
  id: params.id
114
87
  });
115
- security.disableAuthorization();
116
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
117
- security.enableAuthorization();
88
+ const entry = await cms.updateEntry(model, params.id, {
89
+ ...existingEntry,
90
+ ...params.data,
91
+ savedOn: new Date()
92
+ });
118
93
  const values = await (0, _fieldResolver.getFieldValues)({
119
94
  entry,
120
- fields: _index.baseFields,
95
+ fields: _pickEntryFieldValues.baseFields,
121
96
  context: getCmsContext(),
122
97
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
123
98
  });
124
99
  return pickIdFromChangeRequest(values);
125
100
  },
126
-
127
101
  async deleteComment(params) {
128
102
  const model = await getCommentModel();
129
- security.disableAuthorization();
130
103
  await cms.deleteEntry(model, params.id);
131
- security.enableAuthorization();
132
104
  return true;
133
105
  }
134
-
135
106
  };
136
107
  };
108
+ exports.createCommentStorageOperations = createCommentStorageOperations;
137
109
 
138
- exports.createCommentStorageOperations = createCommentStorageOperations;
110
+ //# sourceMappingURL=commentStorageOperations.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["pickIdFromChangeRequest","obj","rawValue","id","createCommentStorageOperations","cms","getCmsContext","security","getCommentModel","disableAuthorization","model","getModel","COMMENT_MODEL_ID","enableAuthorization","WebinyError","getComment","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","params","values","listComments","entries","meta","listLatestEntries","Promise","all","map","value","createComment","refModel","getChangeRequestModel","createEntry","data","changeRequest","modelId","updateComment","existingEntry","updateEntry","deleteComment","deleteEntry"],"sources":["commentStorageOperations.ts"],"sourcesContent":["import { ApwStorageOperations } from \"./types\";\nimport { ApwCommentStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwComment } from \"~/types\";\nimport { CmsEntryListParams } from \"@webiny/api-headless-cms/types\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\n\nconst pickIdFromChangeRequest = (obj: Record<string, any>): ApwComment => {\n const rawValue = obj[\"changeRequest\"];\n if (!rawValue) {\n return obj as unknown as ApwComment;\n }\n obj[\"changeRequest\"] = rawValue.id;\n return obj as unknown as ApwComment;\n};\n\nexport const createCommentStorageOperations = ({\n cms,\n getCmsContext,\n security\n}: CreateApwStorageOperationsParams): ApwCommentStorageOperations => {\n const getCommentModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(COMMENT_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${COMMENT_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getComment: ApwCommentStorageOperations[\"getComment\"] = async ({ id }) => {\n const model = await getCommentModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getCommentModel,\n getComment: async params => {\n const values = await getComment(params);\n return pickIdFromChangeRequest(values);\n },\n async listComments(params) {\n const model = await getCommentModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(\n model,\n params as CmsEntryListParams\n );\n security.enableAuthorization();\n const values = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwComment>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n const all = values.map(value => pickIdFromChangeRequest(value));\n return [all, meta];\n },\n async createComment(this: ApwStorageOperations, params) {\n const model = await getCommentModel();\n const refModel = await this.getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, {\n ...params.data,\n changeRequest: {\n id: params.data.changeRequest,\n modelId: refModel.modelId\n }\n });\n security.enableAuthorization();\n\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async updateComment(params) {\n const model = await getCommentModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getComment({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async deleteComment(params) {\n const model = await getCommentModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return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CA3GM"}
1
+ {"version":3,"names":["_fieldResolver","require","_pickEntryFieldValues","_error","_interopRequireDefault","_comment","pickIdFromChangeRequest","obj","rawValue","id","createCommentStorageOperations","cms","getCmsContext","getCommentModel","model","getModel","COMMENT_MODEL_ID","WebinyError","getComment","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","params","values","listComments","entries","meta","listLatestEntries","Promise","all","map","value","createComment","refModel","getChangeRequestModel","createEntry","data","changeRequest","modelId","updateComment","existingEntry","updateEntry","savedOn","Date","deleteComment","deleteEntry","exports"],"sources":["commentStorageOperations.ts"],"sourcesContent":["import type { ApwStorageOperations } from \"./types\";\nimport type { ApwCommentStorageOperations } from \"./types\";\nimport type { CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport { baseFields } from \"~/utils/pickEntryFieldValues\";\n\nimport WebinyError from \"@webiny/error\";\nimport type { ApwComment } from \"~/types\";\nimport type { CmsEntryListParams } from \"@webiny/api-headless-cms/types\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\n\nconst pickIdFromChangeRequest = (obj: Record<string, any>): ApwComment => {\n const rawValue = obj[\"changeRequest\"];\n if (!rawValue) {\n return obj as unknown as ApwComment;\n }\n obj[\"changeRequest\"] = rawValue.id;\n return obj as unknown as ApwComment;\n};\n\nexport const createCommentStorageOperations = ({\n cms,\n getCmsContext\n}: CreateApwStorageOperationsParams): ApwCommentStorageOperations => {\n const getCommentModel = async () => {\n const model = await cms.getModel(COMMENT_MODEL_ID);\n\n if (!model) {\n throw new WebinyError(\n `Could not find \"${COMMENT_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getComment: ApwCommentStorageOperations[\"getComment\"] = async ({ id }) => {\n const model = await getCommentModel();\n const entry = await cms.getEntryById(model, id);\n\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getCommentModel,\n getComment: async params => {\n const values = await getComment(params);\n return pickIdFromChangeRequest(values);\n },\n async listComments(params) {\n const model = await getCommentModel();\n const [entries, meta] = await cms.listLatestEntries(\n model,\n params as CmsEntryListParams\n );\n const values = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwComment>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n const all = values.map(value => pickIdFromChangeRequest(value));\n return [all, meta];\n },\n async createComment(this: ApwStorageOperations, params) {\n const model = await getCommentModel();\n const refModel = await this.getChangeRequestModel();\n\n const entry = await cms.createEntry(model, {\n ...params.data,\n changeRequest: {\n id: params.data.changeRequest,\n modelId: refModel.modelId\n }\n });\n\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async updateComment(params) {\n const model = await getCommentModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getComment({ id: params.id });\n\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data,\n savedOn: new Date()\n });\n\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async deleteComment(params) {\n const model = await getCommentModel();\n await cms.deleteEntry(model, params.id);\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,QAAA,GAAAJ,OAAA;AAEA,MAAMK,uBAAuB,GAAIC,GAAwB,IAAiB;EACtE,MAAMC,QAAQ,GAAGD,GAAG,CAAC,eAAe,CAAC;EACrC,IAAI,CAACC,QAAQ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Y,MAAMgC,aAAa,GAAG,MAAM3B,UAAU,CAAC;QAAET,EAAE,EAAEkB,MAAM,CAAClB;MAAG,CAAC,CAAC;MAEzD,MAAMU,KAAK,GAAG,MAAMR,GAAG,CAACmC,WAAW,CAAChC,KAAK,EAAEa,MAAM,CAAClB,EAAE,EAAE;QAClD,GAAGoC,aAAa;QAChB,GAAGlB,MAAM,CAACc,IAAI;QACdM,OAAO,EAAE,IAAIC,IAAI,CAAC;MACtB,CAAC,CAAC;MAEF,MAAMpB,MAAM,GAAG,MAAM,IAAAP,6BAAc,EAAC;QAChCF,KAAK;QACLG,MAAM,EAAEC,gCAAU;QAClBC,OAAO,EAAEZ,aAAa,CAAC,CAAC;QACxBa,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACZ,KAAK,EAAE,MAAM,CAAC;MAChD,CAAC,CAAC;MACF,OAAOR,uBAAuB,CAACsB,MAAM,CAAC;IAC1C,CAAC;IACD,MAAMqB,aAAaA,CAACtB,MAAM,EAAE;MACxB,MAAMb,KAAK,GAAG,MAAMD,eAAe,CAAC,CAAC;MACrC,MAAMF,GAAG,CAACuC,WAAW,CAACpC,KAAK,EAAEa,MAAM,CAAClB,EAAE,CAAC;MACvC,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC0C,OAAA,CAAAzC,8BAAA,GAAAA,8BAAA","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { ApwContentReviewStorageOperations } from "./types";
2
- import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createContentReviewStorageOperations: ({ cms, security }: CreateApwStorageOperationsParams) => ApwContentReviewStorageOperations;
1
+ import type { ApwContentReviewStorageOperations } from "./types";
2
+ import type { CreateApwStorageOperationsParams } from "./";
3
+ export declare const createContentReviewStorageOperations: ({ cms }: CreateApwStorageOperationsParams) => ApwContentReviewStorageOperations;