@webiny/api-apw 5.34.8 → 5.35.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/ApwChangeRequestNotification.js +0 -10
  2. package/ApwChangeRequestNotification.js.map +1 -1
  3. package/ApwCommentNotification.js +0 -10
  4. package/ApwCommentNotification.js.map +1 -1
  5. package/ApwContentReviewNotification.js +0 -10
  6. package/ApwContentReviewNotification.js.map +1 -1
  7. package/ApwContentUrlPlugin.js +0 -10
  8. package/ApwContentUrlPlugin.js.map +1 -1
  9. package/ContentApwSettingsPlugin.js +0 -5
  10. package/ContentApwSettingsPlugin.js.map +1 -1
  11. package/crud/createChangeRequestMethods.js +4 -11
  12. package/crud/createChangeRequestMethods.js.map +1 -1
  13. package/crud/createCommentMethods.js +4 -12
  14. package/crud/createCommentMethods.js.map +1 -1
  15. package/crud/createContentReviewMethods.js +20 -84
  16. package/crud/createContentReviewMethods.js.map +1 -1
  17. package/crud/createReviewerMethods.js +4 -12
  18. package/crud/createReviewerMethods.js.map +1 -1
  19. package/crud/createWorkflowMethods.js +4 -17
  20. package/crud/createWorkflowMethods.js.map +1 -1
  21. package/crud/index.js +0 -25
  22. package/crud/index.js.map +1 -1
  23. package/crud/utils.js +0 -28
  24. package/crud/utils.js.map +1 -1
  25. package/index.d.ts +1 -2
  26. package/index.js +1 -15
  27. package/index.js.map +1 -1
  28. package/package.json +34 -34
  29. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +0 -15
  30. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  31. package/plugins/cms/apwEntryPlugins.js +0 -8
  32. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  33. package/plugins/cms/index.js +0 -13
  34. package/plugins/cms/index.js.map +1 -1
  35. package/plugins/cms/linkContentReviewToEntry.js +0 -17
  36. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  37. package/plugins/cms/linkWorkflowToEntry.js +2 -31
  38. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  39. package/plugins/cms/notifications/changeRequestNotification.js +0 -4
  40. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
  41. package/plugins/cms/notifications/commentNotification.js +0 -4
  42. package/plugins/cms/notifications/commentNotification.js.map +1 -1
  43. package/plugins/cms/notifications/contentReviewNotification.js +0 -4
  44. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
  45. package/plugins/cms/notifications/contentUrl.js +1 -8
  46. package/plugins/cms/notifications/contentUrl.js.map +1 -1
  47. package/plugins/cms/triggerContentReview.js +0 -14
  48. package/plugins/cms/triggerContentReview.js.map +1 -1
  49. package/plugins/cms/updateContentReviewStatus.js +0 -18
  50. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  51. package/plugins/cms/utils.js +2 -47
  52. package/plugins/cms/utils.js.map +1 -1
  53. package/plugins/context.d.ts +0 -1
  54. package/plugins/context.js +2 -47
  55. package/plugins/context.js.map +1 -1
  56. package/plugins/graphql/changeRequest.gql.js +3 -10
  57. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  58. package/plugins/graphql/comment.gql.js +3 -10
  59. package/plugins/graphql/comment.gql.js.map +1 -1
  60. package/plugins/graphql/contentReview.gql.js +6 -25
  61. package/plugins/graphql/contentReview.gql.js.map +1 -1
  62. package/plugins/graphql/reviewer.gql.js +3 -10
  63. package/plugins/graphql/reviewer.gql.js.map +1 -1
  64. package/plugins/graphql/workflow.gql.js +3 -10
  65. package/plugins/graphql/workflow.gql.js.map +1 -1
  66. package/plugins/graphql.js +3 -18
  67. package/plugins/graphql.js.map +1 -1
  68. package/plugins/hooks/createReviewerFromIdentity.js +2 -11
  69. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  70. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -9
  71. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  72. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -8
  73. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  74. package/plugins/hooks/index.js +0 -14
  75. package/plugins/hooks/index.js.map +1 -1
  76. package/plugins/hooks/initializeContentReviewSteps.js +2 -18
  77. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  78. package/plugins/hooks/initializeNotifications.js +0 -5
  79. package/plugins/hooks/initializeNotifications.js.map +1 -1
  80. package/plugins/hooks/listContentReviews.js +0 -12
  81. package/plugins/hooks/listContentReviews.js.map +1 -1
  82. package/plugins/hooks/notifications/appUrl.js +0 -4
  83. package/plugins/hooks/notifications/appUrl.js.map +1 -1
  84. package/plugins/hooks/notifications/changeRequestAfterCreate.js +3 -36
  85. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  86. package/plugins/hooks/notifications/changeRequestUrl.js +0 -4
  87. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
  88. package/plugins/hooks/notifications/commentAfterCreate.js +3 -38
  89. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  90. package/plugins/hooks/notifications/commentUrl.js +0 -4
  91. package/plugins/hooks/notifications/commentUrl.js.map +1 -1
  92. package/plugins/hooks/notifications/contentReviewAfterCreate.js +4 -32
  93. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  94. package/plugins/hooks/notifications/contentReviewUrl.js +0 -4
  95. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
  96. package/plugins/hooks/notifications/contentUrl.js +0 -5
  97. package/plugins/hooks/notifications/contentUrl.js.map +1 -1
  98. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +0 -4
  99. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
  100. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +0 -4
  101. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
  102. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +0 -4
  103. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
  104. package/plugins/hooks/notifications/reviewers.js +15 -21
  105. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  106. package/plugins/hooks/notifications/sendChangeRequestNotification.js +0 -11
  107. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
  108. package/plugins/hooks/notifications/sendCommentNotification.js +0 -11
  109. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
  110. package/plugins/hooks/notifications/sendContentReviewNotification.js +0 -11
  111. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
  112. package/plugins/hooks/updatePendingChangeRequests.js +0 -8
  113. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  114. package/plugins/hooks/updateTotalComments.js +0 -9
  115. package/plugins/hooks/updateTotalComments.js.map +1 -1
  116. package/plugins/hooks/validateChangeRequest.js +0 -16
  117. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  118. package/plugins/hooks/validateComment.js +1 -12
  119. package/plugins/hooks/validateComment.js.map +1 -1
  120. package/plugins/hooks/validateContentReview.js +0 -6
  121. package/plugins/hooks/validateContentReview.js.map +1 -1
  122. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -15
  123. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  124. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  125. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  126. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  127. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  128. package/plugins/pageBuilder/index.js +0 -11
  129. package/plugins/pageBuilder/index.js.map +1 -1
  130. package/plugins/pageBuilder/linkContentReviewToPage.js +0 -16
  131. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  132. package/plugins/pageBuilder/linkWorkflowToPage.js +1 -31
  133. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  134. package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -4
  135. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
  136. package/plugins/pageBuilder/notifications/commentNotification.js +0 -4
  137. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
  138. package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -4
  139. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
  140. package/plugins/pageBuilder/notifications/contentUrl.js +1 -7
  141. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
  142. package/plugins/pageBuilder/triggerContentReview.js +0 -11
  143. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  144. package/plugins/pageBuilder/updateContentReviewStatus.js +0 -12
  145. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  146. package/plugins/pageBuilder/utils.js +1 -35
  147. package/plugins/pageBuilder/utils.js.map +1 -1
  148. package/plugins/utils.js +0 -43
  149. package/plugins/utils.js.map +1 -1
  150. package/scheduler/createScheduleActionMethods.js +1 -20
  151. package/scheduler/createScheduleActionMethods.js.map +1 -1
  152. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  153. package/scheduler/handlers/executeAction/index.js +9 -40
  154. package/scheduler/handlers/executeAction/index.js.map +1 -1
  155. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +0 -7
  156. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  157. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -23
  158. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  159. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +4 -28
  160. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  161. package/scheduler/handlers/executeAction/security.js +0 -11
  162. package/scheduler/handlers/executeAction/security.js.map +1 -1
  163. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  164. package/scheduler/handlers/scheduleAction/index.js +5 -25
  165. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  166. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -23
  167. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  168. package/scheduler/handlers/utils.d.ts +1 -2
  169. package/scheduler/handlers/utils.js +3 -41
  170. package/scheduler/handlers/utils.js.map +1 -1
  171. package/scheduler/index.js +0 -3
  172. package/scheduler/index.js.map +1 -1
  173. package/scheduler/types.d.ts +2 -20
  174. package/scheduler/types.js +0 -11
  175. package/scheduler/types.js.map +1 -1
  176. package/storageOperations/changeRequestStorageOperations.js +20 -39
  177. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  178. package/storageOperations/commentStorageOperations.js +23 -44
  179. package/storageOperations/commentStorageOperations.js.map +1 -1
  180. package/storageOperations/contentReviewStorageOperations.js +20 -37
  181. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  182. package/storageOperations/index.js +0 -14
  183. package/storageOperations/index.js.map +1 -1
  184. package/storageOperations/models/changeRequest.model.js +0 -9
  185. package/storageOperations/models/changeRequest.model.js.map +1 -1
  186. package/storageOperations/models/comment.model.js +0 -8
  187. package/storageOperations/models/comment.model.js.map +1 -1
  188. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
  189. package/storageOperations/models/contentModelPluginFactory.js +3 -11
  190. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  191. package/storageOperations/models/contentReview.model.js +0 -26
  192. package/storageOperations/models/contentReview.model.js.map +1 -1
  193. package/storageOperations/models/index.js +2 -28
  194. package/storageOperations/models/index.js.map +1 -1
  195. package/storageOperations/models/reviewer.model.js +0 -8
  196. package/storageOperations/models/reviewer.model.js.map +1 -1
  197. package/storageOperations/models/utils.js +0 -4
  198. package/storageOperations/models/utils.js.map +1 -1
  199. package/storageOperations/models/workflow.model.js +0 -23
  200. package/storageOperations/models/workflow.model.js.map +1 -1
  201. package/storageOperations/reviewerStorageOperations.js +23 -45
  202. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  203. package/storageOperations/workflowStorageOperations.js +20 -39
  204. package/storageOperations/workflowStorageOperations.js.map +1 -1
  205. package/types.d.ts +6 -5
  206. package/types.js +0 -14
  207. package/types.js.map +1 -1
  208. package/utils/contentApwSettingsPlugin.js +0 -6
  209. package/utils/contentApwSettingsPlugin.js.map +1 -1
  210. package/utils/errors.js +0 -17
  211. package/utils/errors.js.map +1 -1
  212. package/utils/fieldResolver.js +2 -12
  213. package/utils/fieldResolver.js.map +1 -1
  214. package/utils/resolve.d.ts +1 -1
  215. package/utils/resolve.js +0 -3
  216. package/utils/resolve.js.map +1 -1
@@ -3,6 +3,7 @@ import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types
3
3
  import { I18NLocale, I18NContext } from "@webiny/api-i18n/types";
4
4
  import { Tenant } from "@webiny/api-tenancy/types";
5
5
  import { TenancyContext } from "@webiny/api-tenancy/types";
6
+ import { ApwIdentity } from "../types";
6
7
  export interface ListWhere {
7
8
  /**
8
9
  * Fields.
@@ -29,25 +30,6 @@ export interface ListParams {
29
30
  limit?: number;
30
31
  after?: string;
31
32
  }
32
- /**
33
- * A interface describing the reference to a user that created some data in the database.
34
- *
35
- * @category General
36
- */
37
- export interface CreatedBy {
38
- /**
39
- * ID if the user.
40
- */
41
- id: string;
42
- /**
43
- * Full name of the user.
44
- */
45
- displayName: string | null;
46
- /**
47
- * Type of the user (admin, user)
48
- */
49
- type: string;
50
- }
51
33
  export interface ListMeta {
52
34
  /**
53
35
  * A cursor for pagination.
@@ -70,7 +52,7 @@ export interface BaseFields {
70
52
  id: string;
71
53
  createdOn: string;
72
54
  savedOn?: string;
73
- createdBy: CreatedBy;
55
+ createdBy: ApwIdentity;
74
56
  tenant: string;
75
57
  locale: string;
76
58
  }
@@ -4,31 +4,20 @@ 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
7
  let ApwContentTypes;
14
8
  exports.ApwContentTypes = ApwContentTypes;
15
-
16
9
  (function (ApwContentTypes) {
17
10
  ApwContentTypes["PAGE"] = "page";
18
11
  ApwContentTypes["CMS_ENTRY"] = "cms_entry";
19
12
  })(ApwContentTypes || (exports.ApwContentTypes = ApwContentTypes = {}));
20
-
21
13
  let ApwScheduleActionTypes;
22
14
  exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
23
-
24
15
  (function (ApwScheduleActionTypes) {
25
16
  ApwScheduleActionTypes["PUBLISH"] = "publish";
26
17
  ApwScheduleActionTypes["UNPUBLISH"] = "unpublish";
27
18
  })(ApwScheduleActionTypes || (exports.ApwScheduleActionTypes = ApwScheduleActionTypes = {}));
28
-
29
19
  let InvocationTypes;
30
20
  exports.InvocationTypes = InvocationTypes;
31
-
32
21
  (function (InvocationTypes) {
33
22
  InvocationTypes["SCHEDULED"] = "scheduled";
34
23
  })(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
@@ -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","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\";\nimport { 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 createdOn: string;\n savedOn?: string;\n createdBy: ApwIdentity;\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":";;;;;;IAkDYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe;AAAA,IAkBfC,sBAAsB;AAAA;AAAA,WAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;AAAA,GAAtBA,sBAAsB,sCAAtBA,sBAAsB;AAAA,IAiBtBC,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe"}
@@ -1,46 +1,36 @@
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
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _index = require("./index");
13
-
14
10
  var _fieldResolver = require("../utils/fieldResolver");
15
-
16
11
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
12
  const createChangeRequestStorageOperations = params => {
19
13
  const {
20
14
  cms,
21
15
  getCmsContext,
22
16
  security
23
17
  } = params;
24
-
25
18
  const getChangeRequestModel = async () => {
26
- security.disableAuthorization();
27
- const model = await cms.getModel("apwChangeRequestModelDefinition");
28
- security.enableAuthorization();
29
-
19
+ const model = await security.withoutAuthorization(async () => {
20
+ return cms.getModel("apwChangeRequestModelDefinition");
21
+ });
30
22
  if (!model) {
31
23
  throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
32
24
  }
33
-
34
25
  return model;
35
26
  };
36
-
37
27
  const getChangeRequest = async ({
38
28
  id
39
29
  }) => {
40
30
  const model = await getChangeRequestModel();
41
- security.disableAuthorization();
42
- const entry = await cms.getEntryById(model, id);
43
- security.enableAuthorization();
31
+ const entry = await security.withoutAuthorization(async () => {
32
+ return cms.getEntryById(model, id);
33
+ });
44
34
  return (0, _fieldResolver.getFieldValues)({
45
35
  entry,
46
36
  fields: _index.baseFields,
@@ -48,19 +38,16 @@ const createChangeRequestStorageOperations = params => {
48
38
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
49
39
  });
50
40
  };
51
-
52
41
  return {
53
42
  getChangeRequestModel,
54
43
  getChangeRequest,
55
-
56
44
  async listChangeRequests(params) {
57
45
  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
-
46
+ const [entries, meta] = await security.withoutAuthorization(async () => {
47
+ return cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
48
+ where: (0, _objectSpread2.default)({}, params.where)
49
+ }));
50
+ });
64
51
  try {
65
52
  const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
66
53
  entry,
@@ -73,12 +60,11 @@ const createChangeRequestStorageOperations = params => {
73
60
  throw new _error.default(ex.message, ex.code, ex.data);
74
61
  }
75
62
  },
76
-
77
63
  async createChangeRequest(params) {
78
64
  const model = await getChangeRequestModel();
79
- security.disableAuthorization();
80
- const entry = await cms.createEntry(model, params.data);
81
- security.enableAuthorization();
65
+ const entry = await security.withoutAuthorization(async () => {
66
+ return cms.createEntry(model, params.data);
67
+ });
82
68
  return (0, _fieldResolver.getFieldValues)({
83
69
  entry,
84
70
  fields: _index.baseFields,
@@ -86,20 +72,18 @@ const createChangeRequestStorageOperations = params => {
86
72
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
87
73
  });
88
74
  },
89
-
90
75
  async updateChangeRequest(params) {
91
76
  const model = await getChangeRequestModel();
92
77
  /**
93
78
  * We're fetching the existing entry here because we're not accepting "app" field as input,
94
79
  * but, we still need to retain its value after the "update" operation.
95
80
  */
96
-
97
81
  const existingEntry = await getChangeRequest({
98
82
  id: params.id
99
83
  });
100
- security.disableAuthorization();
101
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
102
- security.enableAuthorization();
84
+ const entry = await security.withoutAuthorization(async () => {
85
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
86
+ });
103
87
  return (0, _fieldResolver.getFieldValues)({
104
88
  entry,
105
89
  fields: _index.baseFields,
@@ -107,16 +91,13 @@ const createChangeRequestStorageOperations = params => {
107
91
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
108
92
  });
109
93
  },
110
-
111
94
  async deleteChangeRequest(params) {
112
95
  const model = await getChangeRequestModel();
113
- security.disableAuthorization();
114
- await cms.deleteEntry(model, params.id);
115
- security.enableAuthorization();
96
+ await security.withoutAuthorization(async () => {
97
+ return cms.deleteEntry(model, params.id);
98
+ });
116
99
  return true;
117
100
  }
118
-
119
101
  };
120
102
  };
121
-
122
103
  exports.createChangeRequestStorageOperations = createChangeRequestStorageOperations;
@@ -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":";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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":["createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","model","withoutAuthorization","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","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 const model = await security.withoutAuthorization(async () => {\n return cms.getModel(\"apwChangeRequestModelDefinition\");\n });\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 security.withoutAuthorization(async () => {\n return 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 security.withoutAuthorization(async () => {\n return 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\n const entry = await security.withoutAuthorization(async () => {\n return 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 * 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 const entry = await security.withoutAuthorization(async () => {\n return cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\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 await security.withoutAuthorization(async () => {\n return cms.deleteEntry(model, params.id);\n });\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AAGO,MAAMA,oCAAoC,GAC7CC,MAAwC,IACJ;EACpC,MAAM;IAAEC,GAAG;IAAEC,aAAa;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAC/C,MAAMI,qBAAqB,GAAG,YAAY;IACtC,MAAMC,KAAK,GAAG,MAAMF,QAAQ,CAACG,oBAAoB,CAAC,YAAY;MAC1D,OAAOL,GAAG,CAACM,QAAQ,CAAC,iCAAiC,CAAC;IAC1D,CAAC,CAAC;IACF,IAAI,CAACF,KAAK,EAAE;MACR,MAAM,IAAIG,cAAW,CACjB,yDAAyD,EACzD,uBAAuB,CAC1B;IACL;IACA,OAAOH,KAAK;EAChB,CAAC;EACD,MAAMI,gBAAuE,GAAG,OAAO;IACnFC;EACJ,CAAC,KAAK;IACF,MAAML,KAAK,GAAG,MAAMD,qBAAqB,EAAE;IAE3C,MAAMO,KAAK,GAAG,MAAMR,QAAQ,CAACG,oBAAoB,CAAC,YAAY;MAC1D,OAAOL,GAAG,CAACW,YAAY,CAACP,KAAK,EAAEK,EAAE,CAAC;IACtC,CAAC,CAAC;IACF,OAAO,IAAAG,6BAAc,EAAC;MAClBF,KAAK;MACLG,MAAM,EAAEC,iBAAU;MAClBC,OAAO,EAAEd,aAAa,EAAE;MACxBe,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACb,KAAK,EAAE,MAAM,CAAC;IAChD,CAAC,CAAC;EACN,CAAC;EACD,OAAO;IACHD,qBAAqB;IACrBK,gBAAgB;IAChB,MAAMU,kBAAkB,CAACnB,MAAM,EAAE;MAC7B,MAAMK,KAAK,GAAG,MAAMD,qBAAqB,EAAE;MAE3C,MAAM,CAACgB,OAAO,EAAEC,IAAI,CAAC,GAAG,MAAMlB,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QACpE,OAAOL,GAAG,CAACq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AAEC,EAAE,EAAEV,MAAM,CAACU;MAAG,CAAC,CAAC;MAE/D,MAAMC,KAAK,GAAG,MAAMR,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC1D,OAAOL,GAAG,CAACkC,WAAW,CAAC9B,KAAK,EAAEL,MAAM,CAACU,EAAE,8DAChCwB,aAAa,GACblC,MAAM,CAAC8B,IAAI,EAChB;MACN,CAAC,CAAC;MACF,OAAO,IAAAjB,6BAAc,EAAC;QAClBF,KAAK;QACLG,MAAM,EAAEC,iBAAU;QAClBC,OAAO,EAAEd,aAAa,EAAE;QACxBe,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACb,KAAK,EAAE,MAAM,CAAC;MAChD,CAAC,CAAC;IACN,CAAC;IACD,MAAM+B,mBAAmB,CAACpC,MAAM,EAAE;MAC9B,MAAMK,KAAK,GAAG,MAAMD,qBAAqB,EAAE;MAE3C,MAAMD,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC5C,OAAOL,GAAG,CAACoC,WAAW,CAAChC,KAAK,EAAEL,MAAM,CAACU,EAAE,CAAC;MAC5C,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,57 +1,44 @@
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
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _index = require("./index");
13
-
14
10
  var _fieldResolver = require("../utils/fieldResolver");
15
-
16
11
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
12
  var _comment = require("./models/comment.model");
19
-
20
13
  const pickIdFromChangeRequest = obj => {
21
14
  const rawValue = obj["changeRequest"];
22
-
23
15
  if (!rawValue) {
24
16
  return obj;
25
17
  }
26
-
27
18
  obj["changeRequest"] = rawValue.id;
28
19
  return obj;
29
20
  };
30
-
31
21
  const createCommentStorageOperations = ({
32
22
  cms,
33
23
  getCmsContext,
34
24
  security
35
25
  }) => {
36
26
  const getCommentModel = async () => {
37
- security.disableAuthorization();
38
- const model = await cms.getModel(_comment.COMMENT_MODEL_ID);
39
- security.enableAuthorization();
40
-
27
+ const model = await security.withoutAuthorization(async () => {
28
+ return cms.getModel(_comment.COMMENT_MODEL_ID);
29
+ });
41
30
  if (!model) {
42
31
  throw new _error.default(`Could not find "${_comment.COMMENT_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
43
32
  }
44
-
45
33
  return model;
46
34
  };
47
-
48
35
  const getComment = async ({
49
36
  id
50
37
  }) => {
51
38
  const model = await getCommentModel();
52
- security.disableAuthorization();
53
- const entry = await cms.getEntryById(model, id);
54
- security.enableAuthorization();
39
+ const entry = await security.withoutAuthorization(async () => {
40
+ return cms.getEntryById(model, id);
41
+ });
55
42
  return (0, _fieldResolver.getFieldValues)({
56
43
  entry,
57
44
  fields: _index.baseFields,
@@ -59,19 +46,17 @@ const createCommentStorageOperations = ({
59
46
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
60
47
  });
61
48
  };
62
-
63
49
  return {
64
50
  getCommentModel,
65
51
  getComment: async params => {
66
52
  const values = await getComment(params);
67
53
  return pickIdFromChangeRequest(values);
68
54
  },
69
-
70
55
  async listComments(params) {
71
56
  const model = await getCommentModel();
72
- security.disableAuthorization();
73
- const [entries, meta] = await cms.listLatestEntries(model, params);
74
- security.enableAuthorization();
57
+ const [entries, meta] = await security.withoutAuthorization(async () => {
58
+ return cms.listLatestEntries(model, params);
59
+ });
75
60
  const values = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
76
61
  entry,
77
62
  fields: _index.baseFields,
@@ -81,18 +66,17 @@ const createCommentStorageOperations = ({
81
66
  const all = values.map(value => pickIdFromChangeRequest(value));
82
67
  return [all, meta];
83
68
  },
84
-
85
69
  async createComment(params) {
86
70
  const model = await getCommentModel();
87
71
  const refModel = await this.getChangeRequestModel();
88
- security.disableAuthorization();
89
- const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.data), {}, {
90
- changeRequest: {
91
- id: params.data.changeRequest,
92
- modelId: refModel.modelId
93
- }
94
- }));
95
- security.enableAuthorization();
72
+ const entry = await security.withoutAuthorization(async () => {
73
+ return cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.data), {}, {
74
+ changeRequest: {
75
+ id: params.data.changeRequest,
76
+ modelId: refModel.modelId
77
+ }
78
+ }));
79
+ });
96
80
  const values = await (0, _fieldResolver.getFieldValues)({
97
81
  entry,
98
82
  fields: _index.baseFields,
@@ -101,20 +85,18 @@ const createCommentStorageOperations = ({
101
85
  });
102
86
  return pickIdFromChangeRequest(values);
103
87
  },
104
-
105
88
  async updateComment(params) {
106
89
  const model = await getCommentModel();
107
90
  /**
108
91
  * We're fetching the existing entry here because we're not accepting "app" field as input,
109
92
  * but, we still need to retain its value after the "update" operation.
110
93
  */
111
-
112
94
  const existingEntry = await getComment({
113
95
  id: params.id
114
96
  });
115
- security.disableAuthorization();
116
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
117
- security.enableAuthorization();
97
+ const entry = await security.withoutAuthorization(async () => {
98
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
99
+ });
118
100
  const values = await (0, _fieldResolver.getFieldValues)({
119
101
  entry,
120
102
  fields: _index.baseFields,
@@ -123,16 +105,13 @@ const createCommentStorageOperations = ({
123
105
  });
124
106
  return pickIdFromChangeRequest(values);
125
107
  },
126
-
127
108
  async deleteComment(params) {
128
109
  const model = await getCommentModel();
129
- security.disableAuthorization();
130
- await cms.deleteEntry(model, params.id);
131
- security.enableAuthorization();
110
+ await security.withoutAuthorization(async () => {
111
+ return cms.deleteEntry(model, params.id);
112
+ });
132
113
  return true;
133
114
  }
134
-
135
115
  };
136
116
  };
137
-
138
117
  exports.createCommentStorageOperations = createCommentStorageOperations;
@@ -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 true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AACA;;AAGA;;AAEA,MAAMA,uBAAuB,GAAIC,GAAD,IAA0C;EACtE,MAAMC,QA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QAIhCgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJkB,CAAf,CAArB;MAMA,OAAOV,uBAAuB,CAACyB,MAAD,CAA9B;IACH,CA/CE;;IAgDH,MAAMgB,aAAN,CAAoBjB,MAApB,EAA4B;MACxB,MAAMd,KAAK,GAAG,MAAMF,eAAe,EAAnC;MACA;AACZ;AACA;AACA;;MACY,MAAMkC,aAAa,GAAG,MAAM3B,UAAU,CAAC;QAAEZ,EAAE,EAAEqB,MAAM,CAACrB;MAAb,CAAD,CAAtC;MAEAI,QAAQ,CAACE,oBAAT;MACA,MAAMO,KAAK,GAAG,MAAMX,GAAG,CAACsC,WAAJ,CAAgBjC,KAAhB,EAAuBc,MAAM,CAACrB,EAA9B,8DACbuC,aADa,GAEblB,MAAM,CAACc,IAFM,EAApB;MAIA/B,QAAQ,CAACM,mBAAT;MACA,MAAMY,MAAM,GAAG,MAAM,IAAAP,6BAAA,EAAe;QAChCF,KADgC;QAEhCG,MAAM,EAAEC,iBAFwB;QAGhCC,OAAO,EAAEf,aAAa,EAHU;QAIhCgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJkB,CAAf,CAArB;MAMA,OAAOV,uBAAuB,CAACyB,MAAD,CAA9B;IACH,CArEE;;IAsEH,MAAMmB,aAAN,CAAoBpB,MAApB,EAA4B;MACxB,MAAMd,KAAK,GAAG,MAAMF,eAAe,EAAnC;MACAD,QAAQ,CAACE,oBAAT;MACA,MAAMJ,GAAG,CAACwC,WAAJ,CAAgBnC,KAAhB,EAAuBc,MAAM,CAACrB,EAA9B,CAAN;MACAI,QAAQ,CAACM,mBAAT;MACA,OAAO,IAAP;IACH;;EA5EE,CAAP;AA8EH,CA3GM"}
1
+ {"version":3,"names":["pickIdFromChangeRequest","obj","rawValue","id","createCommentStorageOperations","cms","getCmsContext","security","getCommentModel","model","withoutAuthorization","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","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 const model = await security.withoutAuthorization(async () => {\n return cms.getModel(COMMENT_MODEL_ID);\n });\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 security.withoutAuthorization(async () => {\n return cms.getEntryById(model, id);\n });\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 security.withoutAuthorization(async () => {\n return cms.listLatestEntries(model, 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 security.withoutAuthorization(async () => {\n return cms.createEntry(model, {\n ...params.data,\n changeRequest: {\n id: params.data.changeRequest,\n modelId: refModel.modelId\n }\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 security.withoutAuthorization(async () => {\n return cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\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 deleteComment(params) {\n const model = await getCommentModel();\n await security.withoutAuthorization(async () => {\n return cms.deleteEntry(model, params.id);\n });\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAEA;AACA;AACA;AAGA;AAEA,MAAMA,uBAAuB,GAAIC,GAAwB,IAAiB;EACtE,MAAMC,QAAQ,GAAGD,GAAG,CAAC,eAAe,CAAC;EACrC,IAAI,CAACC,QAAQ,EAAE;IACX,OAAOD,GAAG;EACd;EACAA,GAAG,CAAC,eAAe,CAAC,GAAGC,QAAQ,CAACC,EAAE;EAClC,OAAOF,GAAG;AACd,CAAC;AAEM,MAAMG,8BAA8B,GAAG,CAAC;EAC3CC,GAAG;EACHC,aAAa;EACbC;AAC8B,CAA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AG,MAAM3B,UAAU,CAAC;QAAEX,EAAE,EAAEoB,MAAM,CAACpB;MAAG,CAAC,CAAC;MAEzD,MAAMY,KAAK,GAAG,MAAMR,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC1D,OAAOL,GAAG,CAACqC,WAAW,CAACjC,KAAK,EAAEc,MAAM,CAACpB,EAAE,8DAChCsC,aAAa,GACblB,MAAM,CAACc,IAAI,EAChB;MACN,CAAC,CAAC;MAEF,MAAMb,MAAM,GAAG,MAAM,IAAAP,6BAAc,EAAC;QAChCF,KAAK;QACLG,MAAM,EAAEC,iBAAU;QAClBC,OAAO,EAAEd,aAAa,EAAE;QACxBe,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACb,KAAK,EAAE,MAAM,CAAC;MAChD,CAAC,CAAC;MACF,OAAOT,uBAAuB,CAACwB,MAAM,CAAC;IAC1C,CAAC;IACD,MAAMmB,aAAa,CAACpB,MAAM,EAAE;MACxB,MAAMd,KAAK,GAAG,MAAMD,eAAe,EAAE;MACrC,MAAMD,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC5C,OAAOL,GAAG,CAACuC,WAAW,CAACnC,KAAK,EAAEc,MAAM,CAACpB,EAAE,CAAC;MAC5C,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,93 +1,76 @@
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.createContentReviewStorageOperations = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _index = require("./index");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  var _contentReview = require("./models/contentReview.model");
17
-
18
12
  const createContentReviewStorageOperations = ({
19
13
  cms,
20
14
  security
21
15
  }) => {
22
16
  const getContentReviewModel = async () => {
23
- security.disableAuthorization();
24
- const model = await cms.getModel(_contentReview.CONTENT_REVIEW_MODEL_ID);
25
- security.enableAuthorization();
26
-
17
+ const model = await security.withoutAuthorization(async () => {
18
+ return cms.getModel(_contentReview.CONTENT_REVIEW_MODEL_ID);
19
+ });
27
20
  if (!model) {
28
21
  throw new _error.default(`Could not find "${_contentReview.CONTENT_REVIEW_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
29
22
  }
30
-
31
23
  return model;
32
24
  };
33
-
34
25
  const getContentReview = async ({
35
26
  id
36
27
  }) => {
37
28
  const model = await getContentReviewModel();
38
- security.disableAuthorization();
39
- const entry = await cms.getEntryById(model, id);
40
- security.enableAuthorization();
29
+ const entry = await security.withoutAuthorization(async () => {
30
+ return cms.getEntryById(model, id);
31
+ });
41
32
  return (0, _index.getFieldValues)(entry, _index.baseFields);
42
33
  };
43
-
44
34
  return {
45
35
  getContentReviewModel,
46
36
  getContentReview,
47
-
48
37
  async listContentReviews(params) {
49
38
  const model = await getContentReviewModel();
50
- security.disableAuthorization();
51
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
52
- where: (0, _objectSpread2.default)({}, params.where)
53
- }));
54
- security.enableAuthorization();
39
+ const [entries, meta] = await security.withoutAuthorization(async () => {
40
+ return cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
41
+ where: (0, _objectSpread2.default)({}, params.where)
42
+ }));
43
+ });
55
44
  return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
56
45
  },
57
-
58
46
  async createContentReview(params) {
59
47
  const model = await getContentReviewModel();
60
- security.disableAuthorization();
61
- const entry = await cms.createEntry(model, params.data);
62
- security.enableAuthorization();
48
+ const entry = await security.withoutAuthorization(async () => {
49
+ return cms.createEntry(model, params.data);
50
+ });
63
51
  return (0, _index.getFieldValues)(entry, _index.baseFields);
64
52
  },
65
-
66
53
  async updateContentReview(params) {
67
54
  const model = await getContentReviewModel();
68
55
  /**
69
56
  * We're fetching the existing entry here because we're not accepting "app" field as input,
70
57
  * but, we still need to retain its value after the "update" operation.
71
58
  */
72
-
73
59
  const existingEntry = await getContentReview({
74
60
  id: params.id
75
61
  });
76
- security.disableAuthorization();
77
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
78
- security.enableAuthorization();
62
+ const entry = await security.withoutAuthorization(async () => {
63
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
64
+ });
79
65
  return (0, _index.getFieldValues)(entry, _index.baseFields);
80
66
  },
81
-
82
67
  async deleteContentReview(params) {
83
68
  const model = await getContentReviewModel();
84
- security.disableAuthorization();
85
- await cms.deleteEntry(model, params.id);
86
- security.enableAuthorization();
69
+ await security.withoutAuthorization(async () => {
70
+ return cms.deleteEntry(model, params.id);
71
+ });
87
72
  return true;
88
73
  }
89
-
90
74
  };
91
75
  };
92
-
93
76
  exports.createContentReviewStorageOperations = createContentReviewStorageOperations;