@webiny/api-apw 0.0.0-unstable.5e7233243f

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 (229) hide show
  1. package/ContentApwSettingsPlugin.d.ts +10 -0
  2. package/ContentApwSettingsPlugin.js +17 -0
  3. package/ContentApwSettingsPlugin.js.map +1 -0
  4. package/LICENSE +21 -0
  5. package/README.md +34 -0
  6. package/crud/createChangeRequestMethods.d.ts +2 -0
  7. package/crud/createChangeRequestMethods.js +95 -0
  8. package/crud/createChangeRequestMethods.js.map +1 -0
  9. package/crud/createCommentMethods.d.ts +2 -0
  10. package/crud/createCommentMethods.js +96 -0
  11. package/crud/createCommentMethods.js.map +1 -0
  12. package/crud/createContentReviewMethods.d.ts +10 -0
  13. package/crud/createContentReviewMethods.js +552 -0
  14. package/crud/createContentReviewMethods.js.map +1 -0
  15. package/crud/createReviewerMethods.d.ts +2 -0
  16. package/crud/createReviewerMethods.js +96 -0
  17. package/crud/createReviewerMethods.js.map +1 -0
  18. package/crud/createWorkflowMethods.d.ts +2 -0
  19. package/crud/createWorkflowMethods.js +96 -0
  20. package/crud/createWorkflowMethods.js.map +1 -0
  21. package/crud/index.d.ts +2 -0
  22. package/crud/index.js +100 -0
  23. package/crud/index.js.map +1 -0
  24. package/crud/utils.d.ts +21 -0
  25. package/crud/utils.js +142 -0
  26. package/crud/utils.js.map +1 -0
  27. package/index.d.ts +4 -0
  28. package/index.js +34 -0
  29. package/index.js.map +1 -0
  30. package/package.json +75 -0
  31. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.d.ts +10 -0
  32. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +51 -0
  33. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -0
  34. package/plugins/cms/README.md +49 -0
  35. package/plugins/cms/apwEntryPlugins.d.ts +8 -0
  36. package/plugins/cms/apwEntryPlugins.js +50 -0
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -0
  38. package/plugins/cms/index.d.ts +12 -0
  39. package/plugins/cms/index.js +37 -0
  40. package/plugins/cms/index.js.map +1 -0
  41. package/plugins/cms/linkContentReviewToEntry.d.ts +8 -0
  42. package/plugins/cms/linkContentReviewToEntry.js +108 -0
  43. package/plugins/cms/linkContentReviewToEntry.js.map +1 -0
  44. package/plugins/cms/linkWorkflowToEntry.d.ts +8 -0
  45. package/plugins/cms/linkWorkflowToEntry.js +166 -0
  46. package/plugins/cms/linkWorkflowToEntry.js.map +1 -0
  47. package/plugins/cms/triggerContentReview.d.ts +8 -0
  48. package/plugins/cms/triggerContentReview.js +59 -0
  49. package/plugins/cms/triggerContentReview.js.map +1 -0
  50. package/plugins/cms/updateContentReviewStatus.d.ts +10 -0
  51. package/plugins/cms/updateContentReviewStatus.js +101 -0
  52. package/plugins/cms/updateContentReviewStatus.js.map +1 -0
  53. package/plugins/cms/utils.d.ts +27 -0
  54. package/plugins/cms/utils.js +211 -0
  55. package/plugins/cms/utils.js.map +1 -0
  56. package/plugins/context.d.ts +5 -0
  57. package/plugins/context.js +146 -0
  58. package/plugins/context.js.map +1 -0
  59. package/plugins/graphql/changeRequest.gql.d.ts +4 -0
  60. package/plugins/graphql/changeRequest.gql.js +155 -0
  61. package/plugins/graphql/changeRequest.gql.js.map +1 -0
  62. package/plugins/graphql/comment.gql.d.ts +4 -0
  63. package/plugins/graphql/comment.gql.js +160 -0
  64. package/plugins/graphql/comment.gql.js.map +1 -0
  65. package/plugins/graphql/contentReview.gql.d.ts +4 -0
  66. package/plugins/graphql/contentReview.gql.js +382 -0
  67. package/plugins/graphql/contentReview.gql.js.map +1 -0
  68. package/plugins/graphql/reviewer.gql.d.ts +4 -0
  69. package/plugins/graphql/reviewer.gql.js +114 -0
  70. package/plugins/graphql/reviewer.gql.js.map +1 -0
  71. package/plugins/graphql/workflow.gql.d.ts +4 -0
  72. package/plugins/graphql/workflow.gql.js +205 -0
  73. package/plugins/graphql/workflow.gql.js.map +1 -0
  74. package/plugins/graphql.d.ts +4 -0
  75. package/plugins/graphql.js +95 -0
  76. package/plugins/graphql.js.map +1 -0
  77. package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
  78. package/plugins/hooks/createReviewerFromIdentity.js +62 -0
  79. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -0
  80. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
  81. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +67 -0
  82. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -0
  83. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
  84. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +59 -0
  85. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -0
  86. package/plugins/hooks/index.d.ts +3 -0
  87. package/plugins/hooks/index.js +68 -0
  88. package/plugins/hooks/index.js.map +1 -0
  89. package/plugins/hooks/initializeContentReviewSteps.d.ts +2 -0
  90. package/plugins/hooks/initializeContentReviewSteps.js +89 -0
  91. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -0
  92. package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
  93. package/plugins/hooks/updatePendingChangeRequests.js +98 -0
  94. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -0
  95. package/plugins/hooks/updateTotalComments.d.ts +3 -0
  96. package/plugins/hooks/updateTotalComments.js +157 -0
  97. package/plugins/hooks/updateTotalComments.js.map +1 -0
  98. package/plugins/hooks/validateChangeRequest.d.ts +2 -0
  99. package/plugins/hooks/validateChangeRequest.js +64 -0
  100. package/plugins/hooks/validateChangeRequest.js.map +1 -0
  101. package/plugins/hooks/validateComment.d.ts +2 -0
  102. package/plugins/hooks/validateComment.js +47 -0
  103. package/plugins/hooks/validateComment.js.map +1 -0
  104. package/plugins/hooks/validateContentReview.d.ts +2 -0
  105. package/plugins/hooks/validateContentReview.js +38 -0
  106. package/plugins/hooks/validateContentReview.js.map +1 -0
  107. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.d.ts +9 -0
  108. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +51 -0
  109. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -0
  110. package/plugins/pageBuilder/apwContentPagePlugins.d.ts +3 -0
  111. package/plugins/pageBuilder/apwContentPagePlugins.js +30 -0
  112. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -0
  113. package/plugins/pageBuilder/extendPbPageSettingsSchema.d.ts +3 -0
  114. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +25 -0
  115. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -0
  116. package/plugins/pageBuilder/index.d.ts +11 -0
  117. package/plugins/pageBuilder/index.js +45 -0
  118. package/plugins/pageBuilder/index.js.map +1 -0
  119. package/plugins/pageBuilder/linkContentReviewToPage.d.ts +8 -0
  120. package/plugins/pageBuilder/linkContentReviewToPage.js +93 -0
  121. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -0
  122. package/plugins/pageBuilder/linkWorkflowToPage.d.ts +8 -0
  123. package/plugins/pageBuilder/linkWorkflowToPage.js +182 -0
  124. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -0
  125. package/plugins/pageBuilder/triggerContentReview.d.ts +8 -0
  126. package/plugins/pageBuilder/triggerContentReview.js +50 -0
  127. package/plugins/pageBuilder/triggerContentReview.js.map +1 -0
  128. package/plugins/pageBuilder/updateContentReviewStatus.d.ts +10 -0
  129. package/plugins/pageBuilder/updateContentReviewStatus.js +83 -0
  130. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -0
  131. package/plugins/pageBuilder/utils.d.ts +22 -0
  132. package/plugins/pageBuilder/utils.js +184 -0
  133. package/plugins/pageBuilder/utils.js.map +1 -0
  134. package/plugins/utils.d.ts +35 -0
  135. package/plugins/utils.js +197 -0
  136. package/plugins/utils.js.map +1 -0
  137. package/scheduler/createScheduleActionMethods.d.ts +2 -0
  138. package/scheduler/createScheduleActionMethods.js +146 -0
  139. package/scheduler/createScheduleActionMethods.js.map +1 -0
  140. package/scheduler/handlers/executeAction/index.d.ts +13 -0
  141. package/scheduler/handlers/executeAction/index.js +172 -0
  142. package/scheduler/handlers/executeAction/index.js.map +1 -0
  143. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +13 -0
  144. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +17 -0
  145. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -0
  146. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +11 -0
  147. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +126 -0
  148. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -0
  149. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +11 -0
  150. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +163 -0
  151. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -0
  152. package/scheduler/handlers/executeAction/security.d.ts +4 -0
  153. package/scheduler/handlers/executeAction/security.js +68 -0
  154. package/scheduler/handlers/executeAction/security.js.map +1 -0
  155. package/scheduler/handlers/scheduleAction/index.d.ts +22 -0
  156. package/scheduler/handlers/scheduleAction/index.js +165 -0
  157. package/scheduler/handlers/scheduleAction/index.js.map +1 -0
  158. package/scheduler/handlers/scheduleAction/scheduleAction.utils.d.ts +24 -0
  159. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +176 -0
  160. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -0
  161. package/scheduler/handlers/utils.d.ts +33 -0
  162. package/scheduler/handlers/utils.js +168 -0
  163. package/scheduler/handlers/utils.js.map +1 -0
  164. package/scheduler/index.d.ts +2 -0
  165. package/scheduler/index.js +27 -0
  166. package/scheduler/index.js.map +1 -0
  167. package/scheduler/types.d.ts +171 -0
  168. package/scheduler/types.js +34 -0
  169. package/scheduler/types.js.map +1 -0
  170. package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
  171. package/storageOperations/changeRequestStorageOperations.js +126 -0
  172. package/storageOperations/changeRequestStorageOperations.js.map +1 -0
  173. package/storageOperations/commentStorageOperations.d.ts +3 -0
  174. package/storageOperations/commentStorageOperations.js +142 -0
  175. package/storageOperations/commentStorageOperations.js.map +1 -0
  176. package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
  177. package/storageOperations/contentReviewStorageOperations.js +97 -0
  178. package/storageOperations/contentReviewStorageOperations.js.map +1 -0
  179. package/storageOperations/index.d.ts +15 -0
  180. package/storageOperations/index.js +52 -0
  181. package/storageOperations/index.js.map +1 -0
  182. package/storageOperations/models/changeRequest.model.d.ts +3 -0
  183. package/storageOperations/models/changeRequest.model.js +59 -0
  184. package/storageOperations/models/changeRequest.model.js.map +1 -0
  185. package/storageOperations/models/comment.model.d.ts +7 -0
  186. package/storageOperations/models/comment.model.js +60 -0
  187. package/storageOperations/models/comment.model.js.map +1 -0
  188. package/storageOperations/models/contentModelPluginFactory.d.ts +15 -0
  189. package/storageOperations/models/contentModelPluginFactory.js +32 -0
  190. package/storageOperations/models/contentModelPluginFactory.js.map +1 -0
  191. package/storageOperations/models/contentReview.model.d.ts +7 -0
  192. package/storageOperations/models/contentReview.model.js +257 -0
  193. package/storageOperations/models/contentReview.model.js.map +1 -0
  194. package/storageOperations/models/index.d.ts +2 -0
  195. package/storageOperations/models/index.js +115 -0
  196. package/storageOperations/models/index.js.map +1 -0
  197. package/storageOperations/models/reviewer.model.d.ts +3 -0
  198. package/storageOperations/models/reviewer.model.js +55 -0
  199. package/storageOperations/models/reviewer.model.js.map +1 -0
  200. package/storageOperations/models/utils.d.ts +3 -0
  201. package/storageOperations/models/utils.js +36 -0
  202. package/storageOperations/models/utils.js.map +1 -0
  203. package/storageOperations/models/workflow.model.d.ts +12 -0
  204. package/storageOperations/models/workflow.model.js +208 -0
  205. package/storageOperations/models/workflow.model.js.map +1 -0
  206. package/storageOperations/reviewerStorageOperations.d.ts +3 -0
  207. package/storageOperations/reviewerStorageOperations.js +93 -0
  208. package/storageOperations/reviewerStorageOperations.js.map +1 -0
  209. package/storageOperations/types.d.ts +34 -0
  210. package/storageOperations/types.js +5 -0
  211. package/storageOperations/types.js.map +1 -0
  212. package/storageOperations/workflowStorageOperations.d.ts +3 -0
  213. package/storageOperations/workflowStorageOperations.js +115 -0
  214. package/storageOperations/workflowStorageOperations.js.map +1 -0
  215. package/types.d.ts +737 -0
  216. package/types.js +69 -0
  217. package/types.js.map +1 -0
  218. package/utils/contentApwSettingsPlugin.d.ts +9 -0
  219. package/utils/contentApwSettingsPlugin.js +26 -0
  220. package/utils/contentApwSettingsPlugin.js.map +1 -0
  221. package/utils/errors.d.ts +16 -0
  222. package/utils/errors.js +75 -0
  223. package/utils/errors.js.map +1 -0
  224. package/utils/fieldResolver.d.ts +16 -0
  225. package/utils/fieldResolver.js +60 -0
  226. package/utils/fieldResolver.js.map +1 -0
  227. package/utils/resolve.d.ts +3 -0
  228. package/utils/resolve.js +18 -0
  229. package/utils/resolve.js.map +1 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createScheduler = void 0;
7
+
8
+ var _createScheduleActionMethods = require("./createScheduleActionMethods");
9
+
10
+ const createScheduler = params => {
11
+ const {
12
+ getLocale,
13
+ getIdentity,
14
+ getTenant,
15
+ getPermission,
16
+ storageOperations
17
+ } = params;
18
+ return (0, _createScheduleActionMethods.createScheduleActionMethods)({
19
+ getLocale,
20
+ getIdentity,
21
+ getTenant,
22
+ getPermission,
23
+ storageOperations
24
+ });
25
+ };
26
+
27
+ exports.createScheduler = createScheduler;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createScheduler","params","getLocale","getIdentity","getTenant","getPermission","storageOperations","createScheduleActionMethods"],"sources":["index.ts"],"sourcesContent":["import { createScheduleActionMethods } from \"./createScheduleActionMethods\";\nimport { ApwScheduleActionCrud, CreateScheduleActionParams } from \"./types\";\n\nexport const createScheduler = (params: CreateScheduleActionParams): ApwScheduleActionCrud => {\n const { getLocale, getIdentity, getTenant, getPermission, storageOperations } = params;\n\n return createScheduleActionMethods({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations\n });\n};\n"],"mappings":";;;;;;;AAAA;;AAGO,MAAMA,eAAe,GAAIC,MAAD,IAA+D;EAC1F,MAAM;IAAEC,SAAF;IAAaC,WAAb;IAA0BC,SAA1B;IAAqCC,aAArC;IAAoDC;EAApD,IAA0EL,MAAhF;EAEA,OAAO,IAAAM,wDAAA,EAA4B;IAC/BL,SAD+B;IAE/BC,WAF+B;IAG/BC,SAH+B;IAI/BC,aAJ+B;IAK/BC;EAL+B,CAA5B,CAAP;AAOH,CAVM"}
@@ -0,0 +1,171 @@
1
+ import { Context } from "@webiny/api/types";
2
+ import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types";
3
+ import { I18NLocale, I18NContext } from "@webiny/api-i18n/types";
4
+ import { Tenant } from "@webiny/api-tenancy/types";
5
+ import { TenancyContext } from "@webiny/api-tenancy/types";
6
+ export interface ListWhere {
7
+ /**
8
+ * Fields.
9
+ */
10
+ id?: string;
11
+ id_in?: string[];
12
+ id_not?: string;
13
+ id_not_in?: string[];
14
+ /**
15
+ * Who created the entry?
16
+ */
17
+ createdBy?: string;
18
+ createdBy_not?: string;
19
+ createdBy_in?: string[];
20
+ createdBy_not_in?: string[];
21
+ /**
22
+ * By datetime field.
23
+ */
24
+ datetime_startsWith?: string;
25
+ }
26
+ export interface ListParams {
27
+ where: ListWhere;
28
+ sort?: ("datetime_ASC" | "datetime_DESC")[];
29
+ limit?: number;
30
+ after?: string;
31
+ }
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
+ export interface ListMeta {
52
+ /**
53
+ * A cursor for pagination.
54
+ */
55
+ cursor: string | null;
56
+ /**
57
+ * Is there more items to load?
58
+ */
59
+ hasMoreItems: boolean;
60
+ /**
61
+ * Total count of the items in the storage.
62
+ */
63
+ totalCount: number;
64
+ }
65
+ export declare enum ApwContentTypes {
66
+ PAGE = "page",
67
+ CMS_ENTRY = "cms_entry"
68
+ }
69
+ export interface BaseFields {
70
+ id: string;
71
+ createdOn: string;
72
+ savedOn?: string;
73
+ createdBy: CreatedBy;
74
+ tenant: string;
75
+ locale: string;
76
+ }
77
+ export interface ApwScheduleAction extends BaseFields {
78
+ data: ApwScheduleActionData;
79
+ }
80
+ export declare enum ApwScheduleActionTypes {
81
+ PUBLISH = "publish",
82
+ UNPUBLISH = "unpublish"
83
+ }
84
+ export interface ApwScheduleActionData {
85
+ action: ApwScheduleActionTypes;
86
+ type: ApwContentTypes;
87
+ datetime: string;
88
+ entryId: string;
89
+ /**
90
+ * We will add modelId to the data for now.
91
+ * TODO extract in separate package?
92
+ */
93
+ modelId?: string;
94
+ }
95
+ export declare enum InvocationTypes {
96
+ SCHEDULED = "scheduled"
97
+ }
98
+ interface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {
99
+ get(id: string): Promise<TEntry | null>;
100
+ create(data: TCreateEntryParams): Promise<TEntry>;
101
+ update(id: string, data: TUpdateEntryParams): Promise<TEntry>;
102
+ delete(id: string): Promise<Boolean>;
103
+ }
104
+ export interface ApwScheduleActionCrud extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {
105
+ list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;
106
+ getCurrentTask(): Promise<ApwScheduleAction | null>;
107
+ updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;
108
+ deleteCurrentTask(): Promise<Boolean>;
109
+ }
110
+ export interface ScheduleActionContext extends Context, I18NContext, TenancyContext {
111
+ scheduleAction: ApwScheduleActionCrud;
112
+ }
113
+ export interface CreateScheduleActionParams {
114
+ getLocale: () => I18NLocale;
115
+ getIdentity: () => SecurityIdentity;
116
+ getTenant: () => Tenant;
117
+ getPermission: (name: string) => Promise<SecurityPermission | null>;
118
+ storageOperations: ApwScheduleActionStorageOperations;
119
+ }
120
+ interface CreateApwScheduleActionParams {
121
+ item: ApwScheduleAction;
122
+ input: ApwScheduleActionData;
123
+ }
124
+ interface StorageOperationsGetParams {
125
+ where: {
126
+ id: string;
127
+ tenant: string;
128
+ locale: string;
129
+ };
130
+ }
131
+ interface StorageOperationsDeleteParams {
132
+ id: string;
133
+ tenant: string;
134
+ locale: string;
135
+ }
136
+ export interface ApwScheduleActionListParams extends ListParams {
137
+ where: ListWhere & {
138
+ tenant: string;
139
+ locale: string;
140
+ };
141
+ }
142
+ export declare type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;
143
+ export declare type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;
144
+ export declare type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;
145
+ export declare type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;
146
+ export interface StorageOperationsUpdateScheduleActionParams {
147
+ item: ApwScheduleAction;
148
+ input: ApwScheduleActionData;
149
+ }
150
+ export declare type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];
151
+ export interface StorageOperationsUpdateCurrentTaskParams {
152
+ item: ApwScheduleAction;
153
+ }
154
+ export interface StorageOperationsGetCurrentTaskParams {
155
+ where: Pick<StorageOperationsGetParams["where"], "tenant" | "locale">;
156
+ }
157
+ export declare type StorageOperationsDeleteCurrentTaskParams = Pick<StorageOperationsDeleteParams, "tenant" | "locale">;
158
+ export interface ApwScheduleActionStorageOperations {
159
+ get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;
160
+ list(params: StorageOperationsListScheduleActionsParams): Promise<StorageOperationsListScheduleActionsResponse>;
161
+ create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;
162
+ update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;
163
+ delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;
164
+ getCurrentTask(params: StorageOperationsGetCurrentTaskParams): Promise<ApwScheduleAction | null>;
165
+ updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;
166
+ deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;
167
+ }
168
+ export interface CreateApwContextParams {
169
+ storageOperations: ApwScheduleActionStorageOperations;
170
+ }
171
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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) {
17
+ ApwContentTypes["PAGE"] = "page";
18
+ ApwContentTypes["CMS_ENTRY"] = "cms_entry";
19
+ })(ApwContentTypes || (exports.ApwContentTypes = ApwContentTypes = {}));
20
+
21
+ let ApwScheduleActionTypes;
22
+ exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
23
+
24
+ (function (ApwScheduleActionTypes) {
25
+ ApwScheduleActionTypes["PUBLISH"] = "publish";
26
+ ApwScheduleActionTypes["UNPUBLISH"] = "unpublish";
27
+ })(ApwScheduleActionTypes || (exports.ApwScheduleActionTypes = ApwScheduleActionTypes = {}));
28
+
29
+ let InvocationTypes;
30
+ exports.InvocationTypes = InvocationTypes;
31
+
32
+ (function (InvocationTypes) {
33
+ InvocationTypes["SCHEDULED"] = "scheduled";
34
+ })(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ import { ApwChangeRequestStorageOperations } from "./types";
2
+ import { CreateApwStorageOperationsParams } from "./index";
3
+ export declare const createChangeRequestStorageOperations: (params: CreateApwStorageOperationsParams) => ApwChangeRequestStorageOperations;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createChangeRequestStorageOperations = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _index = require("./index");
13
+
14
+ var _fieldResolver = require("../utils/fieldResolver");
15
+
16
+ var _error = _interopRequireDefault(require("@webiny/error"));
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
+
22
+ const createChangeRequestStorageOperations = params => {
23
+ const {
24
+ cms,
25
+ getCmsContext,
26
+ security
27
+ } = params;
28
+
29
+ const getChangeRequestModel = async () => {
30
+ security.disableAuthorization();
31
+ const model = await cms.getModel("apwChangeRequestModelDefinition");
32
+ security.enableAuthorization();
33
+
34
+ if (!model) {
35
+ throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
36
+ }
37
+
38
+ return model;
39
+ };
40
+
41
+ const getChangeRequest = async ({
42
+ id
43
+ }) => {
44
+ const model = await getChangeRequestModel();
45
+ security.disableAuthorization();
46
+ const entry = await cms.getEntryById(model, id);
47
+ security.enableAuthorization();
48
+ return (0, _fieldResolver.getFieldValues)({
49
+ entry,
50
+ fields: _index.baseFields,
51
+ context: getCmsContext(),
52
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
53
+ });
54
+ };
55
+
56
+ return {
57
+ getChangeRequestModel,
58
+ getChangeRequest,
59
+
60
+ async listChangeRequests(params) {
61
+ const model = await getChangeRequestModel();
62
+ security.disableAuthorization();
63
+ const [entries, meta] = await cms.listLatestEntries(model, _objectSpread(_objectSpread({}, params), {}, {
64
+ where: _objectSpread({}, params.where)
65
+ }));
66
+ security.enableAuthorization();
67
+
68
+ try {
69
+ const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
70
+ entry,
71
+ fields: _index.baseFields,
72
+ context: getCmsContext(),
73
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
74
+ })));
75
+ return [all, meta];
76
+ } catch (ex) {
77
+ throw new _error.default(ex.message, ex.code, ex.data);
78
+ }
79
+ },
80
+
81
+ async createChangeRequest(params) {
82
+ const model = await getChangeRequestModel();
83
+ security.disableAuthorization();
84
+ const entry = await cms.createEntry(model, params.data);
85
+ security.enableAuthorization();
86
+ return (0, _fieldResolver.getFieldValues)({
87
+ entry,
88
+ fields: _index.baseFields,
89
+ context: getCmsContext(),
90
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
91
+ });
92
+ },
93
+
94
+ async updateChangeRequest(params) {
95
+ const model = await getChangeRequestModel();
96
+ /**
97
+ * We're fetching the existing entry here because we're not accepting "app" field as input,
98
+ * but, we still need to retain its value after the "update" operation.
99
+ */
100
+
101
+ const existingEntry = await getChangeRequest({
102
+ id: params.id
103
+ });
104
+ security.disableAuthorization();
105
+ const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
106
+ security.enableAuthorization();
107
+ return (0, _fieldResolver.getFieldValues)({
108
+ entry,
109
+ fields: _index.baseFields,
110
+ context: getCmsContext(),
111
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
112
+ });
113
+ },
114
+
115
+ async deleteChangeRequest(params) {
116
+ const model = await getChangeRequestModel();
117
+ security.disableAuthorization();
118
+ await cms.deleteEntry(model, params.id);
119
+ security.enableAuthorization();
120
+ return true;
121
+ }
122
+
123
+ };
124
+ };
125
+
126
+ exports.createChangeRequestStorageOperations = createChangeRequestStorageOperations;
@@ -0,0 +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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H,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"}
@@ -0,0 +1,3 @@
1
+ import { ApwCommentStorageOperations } from "./types";
2
+ import { CreateApwStorageOperationsParams } from "./index";
3
+ export declare const createCommentStorageOperations: ({ cms, getCmsContext, security }: CreateApwStorageOperationsParams) => ApwCommentStorageOperations;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createCommentStorageOperations = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _index = require("./index");
13
+
14
+ var _fieldResolver = require("../utils/fieldResolver");
15
+
16
+ var _error = _interopRequireDefault(require("@webiny/error"));
17
+
18
+ var _comment = require("./models/comment.model");
19
+
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
+
24
+ const pickIdFromChangeRequest = obj => {
25
+ const rawValue = obj["changeRequest"];
26
+
27
+ if (!rawValue) {
28
+ return obj;
29
+ }
30
+
31
+ obj["changeRequest"] = rawValue.id;
32
+ return obj;
33
+ };
34
+
35
+ const createCommentStorageOperations = ({
36
+ cms,
37
+ getCmsContext,
38
+ security
39
+ }) => {
40
+ const getCommentModel = async () => {
41
+ security.disableAuthorization();
42
+ const model = await cms.getModel(_comment.COMMENT_MODEL_ID);
43
+ security.enableAuthorization();
44
+
45
+ if (!model) {
46
+ throw new _error.default(`Could not find "${_comment.COMMENT_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
47
+ }
48
+
49
+ return model;
50
+ };
51
+
52
+ const getComment = async ({
53
+ id
54
+ }) => {
55
+ const model = await getCommentModel();
56
+ security.disableAuthorization();
57
+ const entry = await cms.getEntryById(model, id);
58
+ security.enableAuthorization();
59
+ return (0, _fieldResolver.getFieldValues)({
60
+ entry,
61
+ fields: _index.baseFields,
62
+ context: getCmsContext(),
63
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
64
+ });
65
+ };
66
+
67
+ return {
68
+ getCommentModel,
69
+ getComment: async params => {
70
+ const values = await getComment(params);
71
+ return pickIdFromChangeRequest(values);
72
+ },
73
+
74
+ async listComments(params) {
75
+ const model = await getCommentModel();
76
+ security.disableAuthorization();
77
+ const [entries, meta] = await cms.listLatestEntries(model, params);
78
+ security.enableAuthorization();
79
+ const values = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
80
+ entry,
81
+ fields: _index.baseFields,
82
+ context: getCmsContext(),
83
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
84
+ })));
85
+ const all = values.map(value => pickIdFromChangeRequest(value));
86
+ return [all, meta];
87
+ },
88
+
89
+ async createComment(params) {
90
+ const model = await getCommentModel();
91
+ const refModel = await this.getChangeRequestModel();
92
+ security.disableAuthorization();
93
+ const entry = await cms.createEntry(model, _objectSpread(_objectSpread({}, params.data), {}, {
94
+ changeRequest: {
95
+ id: params.data.changeRequest,
96
+ modelId: refModel.modelId
97
+ }
98
+ }));
99
+ security.enableAuthorization();
100
+ const values = await (0, _fieldResolver.getFieldValues)({
101
+ entry,
102
+ fields: _index.baseFields,
103
+ context: getCmsContext(),
104
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
105
+ });
106
+ return pickIdFromChangeRequest(values);
107
+ },
108
+
109
+ async updateComment(params) {
110
+ const model = await getCommentModel();
111
+ /**
112
+ * We're fetching the existing entry here because we're not accepting "app" field as input,
113
+ * but, we still need to retain its value after the "update" operation.
114
+ */
115
+
116
+ const existingEntry = await getComment({
117
+ id: params.id
118
+ });
119
+ security.disableAuthorization();
120
+ const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
121
+ security.enableAuthorization();
122
+ const values = await (0, _fieldResolver.getFieldValues)({
123
+ entry,
124
+ fields: _index.baseFields,
125
+ context: getCmsContext(),
126
+ transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
127
+ });
128
+ return pickIdFromChangeRequest(values);
129
+ },
130
+
131
+ async deleteComment(params) {
132
+ const model = await getCommentModel();
133
+ security.disableAuthorization();
134
+ await cms.deleteEntry(model, params.id);
135
+ security.enableAuthorization();
136
+ return true;
137
+ }
138
+
139
+ };
140
+ };
141
+
142
+ exports.createCommentStorageOperations = createCommentStorageOperations;
@@ -0,0 +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,QAAQ,GAAGD,GAAG,CAAC,eAAD,CAApB;;EACA,IAAI,CAACC,QAAL,EAAe;IACX,OAAOD,GAAP;EACH;;EACDA,GAAG,CAAC,eAAD,CAAH,GAAuBC,QAAQ,CAACC,EAAhC;EACA,OAAOF,GAAP;AACH,CAPD;;AASO,MAAMG,8BAA8B,GAAG,CAAC;EAC3CC,GAD2C;EAE3CC,aAF2C;EAG3CC;AAH2C,CAAD,KAIuB;EACjE,MAAMC,eAAe,GAAG,YAAY;IAChCD,QAAQ,CAACE,oBAAT;IACA,MAAMC,KAAK,GAAG,MAAML,GAAG,CAACM,QAAJ,CAAaC,yBAAb,CAApB;IACAL,QAAQ,C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MAAMX,GAAG,CAACsC,WAAJ,CAAgBjC,KAAhB,EAAuBc,MAAM,CAACrB,EAA9B,kCACbuC,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"}
@@ -0,0 +1,3 @@
1
+ import { ApwContentReviewStorageOperations } from "./types";
2
+ import { CreateApwStorageOperationsParams } from "./index";
3
+ export declare const createContentReviewStorageOperations: ({ cms, security }: CreateApwStorageOperationsParams) => ApwContentReviewStorageOperations;