@webiny/api-apw 5.23.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/createApw/createChangeRequestMethods.d.ts +2 -0
  4. package/createApw/createChangeRequestMethods.js +95 -0
  5. package/createApw/createCommentMethods.d.ts +2 -0
  6. package/createApw/createCommentMethods.js +96 -0
  7. package/createApw/createContentReviewMethods.d.ts +6 -0
  8. package/createApw/createContentReviewMethods.js +301 -0
  9. package/createApw/createReviewerMethods.d.ts +2 -0
  10. package/createApw/createReviewerMethods.js +96 -0
  11. package/createApw/createWorkflowMethods.d.ts +2 -0
  12. package/createApw/createWorkflowMethods.js +96 -0
  13. package/createApw/index.d.ts +2 -0
  14. package/createApw/index.js +54 -0
  15. package/index.d.ts +2 -0
  16. package/index.js +28 -0
  17. package/package.json +67 -0
  18. package/plugins/context.d.ts +4 -0
  19. package/plugins/context.js +89 -0
  20. package/plugins/createManageCMSPlugin.d.ts +2 -0
  21. package/plugins/createManageCMSPlugin.js +31 -0
  22. package/plugins/graphql/changeRequest.gql.d.ts +4 -0
  23. package/plugins/graphql/changeRequest.gql.js +152 -0
  24. package/plugins/graphql/comment.gql.d.ts +4 -0
  25. package/plugins/graphql/comment.gql.js +166 -0
  26. package/plugins/graphql/contentReview.gql.d.ts +4 -0
  27. package/plugins/graphql/contentReview.gql.js +224 -0
  28. package/plugins/graphql/reviewer.gql.d.ts +4 -0
  29. package/plugins/graphql/reviewer.gql.js +111 -0
  30. package/plugins/graphql/workflow.gql.d.ts +4 -0
  31. package/plugins/graphql/workflow.gql.js +199 -0
  32. package/plugins/graphql.d.ts +3 -0
  33. package/plugins/graphql.js +84 -0
  34. package/plugins/hooks/createReviewerFromIdentity.d.ts +2 -0
  35. package/plugins/hooks/createReviewerFromIdentity.js +44 -0
  36. package/plugins/hooks/deleteChangeRequestsAfterContentReview.d.ts +2 -0
  37. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +66 -0
  38. package/plugins/hooks/deleteCommentsAfterChangeRequest.d.ts +2 -0
  39. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +58 -0
  40. package/plugins/hooks/extendPbPageSchema.d.ts +4 -0
  41. package/plugins/hooks/extendPbPageSchema.js +24 -0
  42. package/plugins/hooks/index.d.ts +4 -0
  43. package/plugins/hooks/index.js +68 -0
  44. package/plugins/hooks/initializeContentReviewSteps.d.ts +7 -0
  45. package/plugins/hooks/initializeContentReviewSteps.js +70 -0
  46. package/plugins/hooks/linkWorkflowToPage.d.ts +9 -0
  47. package/plugins/hooks/linkWorkflowToPage.js +154 -0
  48. package/plugins/hooks/updatePendingChangeRequests.d.ts +2 -0
  49. package/plugins/hooks/updatePendingChangeRequests.js +107 -0
  50. package/plugins/utils.d.ts +15 -0
  51. package/plugins/utils.js +69 -0
  52. package/storageOperations/changeRequestStorageOperations.d.ts +3 -0
  53. package/storageOperations/changeRequestStorageOperations.js +96 -0
  54. package/storageOperations/commentStorageOperations.d.ts +3 -0
  55. package/storageOperations/commentStorageOperations.js +101 -0
  56. package/storageOperations/contentReviewStorageOperations.d.ts +3 -0
  57. package/storageOperations/contentReviewStorageOperations.js +72 -0
  58. package/storageOperations/index.d.ts +9 -0
  59. package/storageOperations/index.js +63 -0
  60. package/storageOperations/models/changeRequest.model.d.ts +7 -0
  61. package/storageOperations/models/changeRequest.model.js +52 -0
  62. package/storageOperations/models/comment.model.d.ts +9 -0
  63. package/storageOperations/models/comment.model.js +37 -0
  64. package/storageOperations/models/contentModelPluginFactory.d.ts +17 -0
  65. package/storageOperations/models/contentModelPluginFactory.js +33 -0
  66. package/storageOperations/models/contentReview.model.d.ts +25 -0
  67. package/storageOperations/models/contentReview.model.js +181 -0
  68. package/storageOperations/models/index.d.ts +1 -0
  69. package/storageOperations/models/index.js +87 -0
  70. package/storageOperations/models/reviewer.model.d.ts +7 -0
  71. package/storageOperations/models/reviewer.model.js +48 -0
  72. package/storageOperations/models/utils.d.ts +3 -0
  73. package/storageOperations/models/utils.js +35 -0
  74. package/storageOperations/models/workflow.model.d.ts +17 -0
  75. package/storageOperations/models/workflow.model.js +204 -0
  76. package/storageOperations/reviewerStorageOperations.d.ts +3 -0
  77. package/storageOperations/reviewerStorageOperations.js +72 -0
  78. package/storageOperations/types.d.ts +34 -0
  79. package/storageOperations/types.js +5 -0
  80. package/storageOperations/workflowStorageOperations.d.ts +3 -0
  81. package/storageOperations/workflowStorageOperations.js +72 -0
  82. package/types.d.ts +646 -0
  83. package/types.js +63 -0
  84. package/utils/errors.d.ts +16 -0
  85. package/utils/errors.js +75 -0
  86. package/utils/fieldResolver.d.ts +15 -0
  87. package/utils/fieldResolver.js +58 -0
  88. package/utils/resolve.d.ts +3 -0
  89. package/utils/resolve.js +18 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @webiny/api-awp
2
+
3
+ [![](https://img.shields.io/npm/dw/@webiny/api-awp.svg)](https://www.npmjs.com/package/@webiny/api-awp)
4
+ [![](https://img.shields.io/npm/v/@webiny/api-awp.svg)](https://www.npmjs.com/package/@webiny/api-awp)
5
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
+
8
+ ## Install
9
+
10
+ ```
11
+ npm install --save @webiny/api-awp
12
+ ```
13
+
14
+ Or if you prefer yarn:
15
+
16
+ ```
17
+ yarn add @webiny/api-awp
18
+ ```
19
+
20
+
21
+ ## Testing
22
+
23
+ To run tests api-apw tests with targeted storage operations loaded use:
24
+
25
+ #### DynamoDB
26
+ ```
27
+ yarn test packages/api-apw --keyword=cms:ddb --keyword=apw:base
28
+ ```
29
+
30
+ #### DynamoDB+Elasticsearch
31
+ ```
32
+ yarn test packages/api-apw --keyword=cms:ddb-es --keyword=apw:base
33
+ ```
@@ -0,0 +1,2 @@
1
+ import { ApwChangeRequestCrud, CreateApwParams } from "../types";
2
+ export declare function createChangeRequestMethods({ storageOperations }: CreateApwParams): ApwChangeRequestCrud;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createChangeRequestMethods = createChangeRequestMethods;
7
+
8
+ var _pubsub = require("@webiny/pubsub");
9
+
10
+ function createChangeRequestMethods({
11
+ storageOperations
12
+ }) {
13
+ const onBeforeChangeRequestCreate = (0, _pubsub.createTopic)();
14
+ const onAfterChangeRequestCreate = (0, _pubsub.createTopic)();
15
+ const onBeforeChangeRequestUpdate = (0, _pubsub.createTopic)();
16
+ const onAfterChangeRequestUpdate = (0, _pubsub.createTopic)();
17
+ const onBeforeChangeRequestDelete = (0, _pubsub.createTopic)();
18
+ const onAfterChangeRequestDelete = (0, _pubsub.createTopic)();
19
+ return {
20
+ async get(id) {
21
+ return storageOperations.getChangeRequest({
22
+ id
23
+ });
24
+ },
25
+
26
+ async list(params) {
27
+ return storageOperations.listChangeRequests(params);
28
+ },
29
+
30
+ async create(data) {
31
+ await onBeforeChangeRequestCreate.publish({
32
+ input: data
33
+ });
34
+ const changeRequest = await storageOperations.createChangeRequest({
35
+ data
36
+ });
37
+ await onAfterChangeRequestCreate.publish({
38
+ changeRequest
39
+ });
40
+ return changeRequest;
41
+ },
42
+
43
+ async update(id, data) {
44
+ const original = await storageOperations.getChangeRequest({
45
+ id
46
+ });
47
+ await onBeforeChangeRequestUpdate.publish({
48
+ original,
49
+ input: {
50
+ id,
51
+ data
52
+ }
53
+ });
54
+ const changeRequest = await storageOperations.updateChangeRequest({
55
+ id,
56
+ data
57
+ });
58
+ await onAfterChangeRequestUpdate.publish({
59
+ original,
60
+ input: {
61
+ id,
62
+ data
63
+ },
64
+ changeRequest
65
+ });
66
+ return changeRequest;
67
+ },
68
+
69
+ async delete(id) {
70
+ const changeRequest = await storageOperations.getChangeRequest({
71
+ id
72
+ });
73
+ await onBeforeChangeRequestDelete.publish({
74
+ changeRequest
75
+ });
76
+ await storageOperations.deleteChangeRequest({
77
+ id
78
+ });
79
+ await onAfterChangeRequestDelete.publish({
80
+ changeRequest
81
+ });
82
+ return true;
83
+ },
84
+
85
+ /**
86
+ * Lifecycle events
87
+ */
88
+ onBeforeChangeRequestCreate,
89
+ onAfterChangeRequestCreate,
90
+ onBeforeChangeRequestUpdate,
91
+ onAfterChangeRequestUpdate,
92
+ onBeforeChangeRequestDelete,
93
+ onAfterChangeRequestDelete
94
+ };
95
+ }
@@ -0,0 +1,2 @@
1
+ import { ApwCommentCrud, CreateApwParams } from "../types";
2
+ export declare function createCommentMethods({ storageOperations }: CreateApwParams): ApwCommentCrud;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createCommentMethods = createCommentMethods;
7
+
8
+ var _pubsub = require("@webiny/pubsub");
9
+
10
+ function createCommentMethods({
11
+ storageOperations
12
+ }) {
13
+ const onBeforeCommentCreate = (0, _pubsub.createTopic)();
14
+ const onAfterCommentCreate = (0, _pubsub.createTopic)();
15
+ const onBeforeCommentUpdate = (0, _pubsub.createTopic)();
16
+ const onAfterCommentUpdate = (0, _pubsub.createTopic)();
17
+ const onBeforeCommentDelete = (0, _pubsub.createTopic)();
18
+ const onAfterCommentDelete = (0, _pubsub.createTopic)();
19
+ return {
20
+ /**
21
+ * Lifecycle events
22
+ */
23
+ onBeforeCommentCreate,
24
+ onAfterCommentCreate,
25
+ onBeforeCommentUpdate,
26
+ onAfterCommentUpdate,
27
+ onBeforeCommentDelete,
28
+ onAfterCommentDelete,
29
+
30
+ async get(id) {
31
+ return storageOperations.getComment({
32
+ id
33
+ });
34
+ },
35
+
36
+ async list(params) {
37
+ return storageOperations.listComments(params);
38
+ },
39
+
40
+ async create(data) {
41
+ await onBeforeCommentCreate.publish({
42
+ input: data
43
+ });
44
+ const comment = await storageOperations.createComment({
45
+ data
46
+ });
47
+ await onAfterCommentCreate.publish({
48
+ comment
49
+ });
50
+ return comment;
51
+ },
52
+
53
+ async update(id, data) {
54
+ const original = await storageOperations.getComment({
55
+ id
56
+ });
57
+ await onBeforeCommentUpdate.publish({
58
+ original,
59
+ input: {
60
+ id,
61
+ data
62
+ }
63
+ });
64
+ const comment = await storageOperations.updateComment({
65
+ id,
66
+ data
67
+ });
68
+ await onAfterCommentUpdate.publish({
69
+ original,
70
+ comment,
71
+ input: {
72
+ id,
73
+ data
74
+ }
75
+ });
76
+ return comment;
77
+ },
78
+
79
+ async delete(id) {
80
+ const comment = await storageOperations.getComment({
81
+ id
82
+ });
83
+ await onBeforeCommentDelete.publish({
84
+ comment
85
+ });
86
+ await storageOperations.deleteComment({
87
+ id
88
+ });
89
+ await onAfterCommentDelete.publish({
90
+ comment
91
+ });
92
+ return true;
93
+ }
94
+
95
+ };
96
+ }
@@ -0,0 +1,6 @@
1
+ import { ApwContentReviewCrud, CreateApwParams, ApwReviewerCrud } from "../types";
2
+ interface CreateContentReviewMethodsParams extends CreateApwParams {
3
+ getReviewer: ApwReviewerCrud["get"];
4
+ }
5
+ export declare function createContentReviewMethods({ getIdentity, storageOperations, getReviewer }: CreateContentReviewMethodsParams): ApwContentReviewCrud;
6
+ export {};
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createContentReviewMethods = createContentReviewMethods;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _pubsub = require("@webiny/pubsub");
13
+
14
+ var _types = require("../types");
15
+
16
+ var _utils = require("../plugins/utils");
17
+
18
+ var _errors = require("../utils/errors");
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
+ function createContentReviewMethods({
25
+ getIdentity,
26
+ storageOperations,
27
+ getReviewer
28
+ }) {
29
+ const onBeforeContentReviewCreate = (0, _pubsub.createTopic)();
30
+ const onAfterContentReviewCreate = (0, _pubsub.createTopic)();
31
+ const onBeforeContentReviewUpdate = (0, _pubsub.createTopic)();
32
+ const onAfterContentReviewUpdate = (0, _pubsub.createTopic)();
33
+ const onBeforeContentReviewDelete = (0, _pubsub.createTopic)();
34
+ const onAfterContentReviewDelete = (0, _pubsub.createTopic)();
35
+ return {
36
+ /**
37
+ * Lifecycle events
38
+ */
39
+ onBeforeContentReviewCreate,
40
+ onAfterContentReviewCreate,
41
+ onBeforeContentReviewUpdate,
42
+ onAfterContentReviewUpdate,
43
+ onBeforeContentReviewDelete,
44
+ onAfterContentReviewDelete,
45
+
46
+ async get(id) {
47
+ return storageOperations.getContentReview({
48
+ id
49
+ });
50
+ },
51
+
52
+ async list(params) {
53
+ return storageOperations.listContentReviews(params);
54
+ },
55
+
56
+ async create(data) {
57
+ const input = _objectSpread(_objectSpread({}, data), {}, {
58
+ status: _types.ApwContentReviewStatus.UNDER_REVIEW
59
+ });
60
+
61
+ await onBeforeContentReviewCreate.publish({
62
+ input
63
+ });
64
+ const contentReview = await storageOperations.createContentReview({
65
+ data: input
66
+ });
67
+ await onAfterContentReviewCreate.publish({
68
+ contentReview
69
+ });
70
+ return contentReview;
71
+ },
72
+
73
+ async update(id, data) {
74
+ const original = await storageOperations.getContentReview({
75
+ id
76
+ });
77
+ await onBeforeContentReviewUpdate.publish({
78
+ original,
79
+ input: {
80
+ id,
81
+ data
82
+ }
83
+ });
84
+ const contentReview = await storageOperations.updateContentReview({
85
+ id,
86
+ data
87
+ });
88
+ await onAfterContentReviewUpdate.publish({
89
+ original,
90
+ input: {
91
+ id,
92
+ data
93
+ },
94
+ contentReview
95
+ });
96
+ return contentReview;
97
+ },
98
+
99
+ async delete(id) {
100
+ const contentReview = await storageOperations.getContentReview({
101
+ id
102
+ });
103
+ await onBeforeContentReviewDelete.publish({
104
+ contentReview
105
+ });
106
+ await storageOperations.deleteContentReview({
107
+ id
108
+ });
109
+ await onAfterContentReviewDelete.publish({
110
+ contentReview
111
+ });
112
+ return true;
113
+ },
114
+
115
+ async provideSignOff(id, stepSlug) {
116
+ const entry = await this.get(id);
117
+ const {
118
+ steps
119
+ } = entry;
120
+ const stepIndex = steps.findIndex(step => step.slug === stepSlug);
121
+ const currentStep = steps[stepIndex];
122
+ const previousStep = steps[stepIndex - 1];
123
+ const identity = getIdentity();
124
+ const hasPermission = await (0, _utils.hasReviewer)({
125
+ getReviewer,
126
+ identity,
127
+ step: currentStep
128
+ });
129
+ /**
130
+ * Check whether the sign-off is requested by a reviewer.
131
+ */
132
+
133
+ if (!hasPermission) {
134
+ throw new _errors.NotAuthorizedError({
135
+ entry,
136
+ input: {
137
+ id,
138
+ step: stepSlug
139
+ }
140
+ });
141
+ }
142
+ /**
143
+ * Don't allow sign off, if previous step is of "mandatory_blocking" type and undone.
144
+ */
145
+
146
+
147
+ if (previousStep && previousStep.status !== _types.ApwContentReviewStepStatus.DONE && previousStep.type === _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
148
+ throw new _errors.StepMissingError({
149
+ entry,
150
+ input: {
151
+ id,
152
+ step: stepSlug
153
+ }
154
+ });
155
+ }
156
+ /**
157
+ * Don't allow sign off, if there are pending change requests.
158
+ */
159
+
160
+
161
+ if (currentStep.pendingChangeRequests > 0) {
162
+ throw new _errors.PendingChangeRequestsError({
163
+ entry,
164
+ input: {
165
+ id,
166
+ step: stepSlug
167
+ }
168
+ });
169
+ }
170
+ /**
171
+ * Don't allow sign off, if current step is not in "active" state.
172
+ */
173
+
174
+
175
+ if (currentStep.status !== _types.ApwContentReviewStepStatus.ACTIVE) {
176
+ throw new _errors.StepInActiveError({
177
+ entry,
178
+ input: {
179
+ id,
180
+ step: stepSlug
181
+ }
182
+ });
183
+ }
184
+
185
+ let previousStepStatus;
186
+ /*
187
+ * Provide sign-off for give step.
188
+ */
189
+
190
+ const updatedSteps = steps.map((step, index) => {
191
+ if (index === stepIndex) {
192
+ previousStepStatus = _types.ApwContentReviewStepStatus.DONE;
193
+ return _objectSpread(_objectSpread({}, step), {}, {
194
+ status: _types.ApwContentReviewStepStatus.DONE,
195
+ signOffProvidedOn: new Date().toISOString(),
196
+ signOffProvidedBy: identity
197
+ });
198
+ }
199
+ /**
200
+ * Update next steps status based on type.
201
+ */
202
+
203
+
204
+ if (index > stepIndex) {
205
+ const previousStep = steps[index - 1];
206
+ previousStepStatus = (0, _utils.getNextStepStatus)(previousStep.type, previousStepStatus);
207
+ return _objectSpread(_objectSpread({}, step), {}, {
208
+ status: previousStepStatus
209
+ });
210
+ }
211
+
212
+ return step;
213
+ });
214
+ /**
215
+ * Save updated steps.
216
+ */
217
+
218
+ await this.update(id, {
219
+ steps: updatedSteps
220
+ });
221
+ return true;
222
+ },
223
+
224
+ async retractSignOff(id, stepSlug) {
225
+ const entry = await this.get(id);
226
+ const {
227
+ steps
228
+ } = entry;
229
+ const stepIndex = steps.findIndex(step => step.slug === stepSlug);
230
+ const currentStep = steps[stepIndex];
231
+ const identity = getIdentity();
232
+ const hasPermission = await (0, _utils.hasReviewer)({
233
+ getReviewer,
234
+ identity,
235
+ step: currentStep
236
+ });
237
+ /**
238
+ * Check whether the retract sign-off is requested by a reviewer.
239
+ */
240
+
241
+ if (!hasPermission) {
242
+ throw new _errors.NotAuthorizedError({
243
+ entry,
244
+ input: {
245
+ id,
246
+ step: stepSlug
247
+ }
248
+ });
249
+ }
250
+ /**
251
+ * Don't allow, if step in not "done" i.e. no sign-off was provided for it.
252
+ */
253
+
254
+
255
+ if (currentStep.status !== _types.ApwContentReviewStepStatus.DONE) {
256
+ throw new _errors.NoSignOffProvidedError({
257
+ entry,
258
+ input: {
259
+ id,
260
+ step: stepSlug
261
+ }
262
+ });
263
+ }
264
+
265
+ let previousStepStatus;
266
+ /*
267
+ * Retract sign-off for give step.
268
+ */
269
+
270
+ const updatedSteps = steps.map((step, index) => {
271
+ if (index === stepIndex) {
272
+ previousStepStatus = _types.ApwContentReviewStepStatus.ACTIVE;
273
+ return _objectSpread(_objectSpread({}, step), {}, {
274
+ status: previousStepStatus,
275
+ signOffProvidedOn: null,
276
+ signOffProvidedBy: null
277
+ });
278
+ }
279
+ /**
280
+ * Set next step status as "inactive".
281
+ */
282
+
283
+
284
+ if (index > stepIndex) {
285
+ const previousStep = steps[index - 1];
286
+ previousStepStatus = (0, _utils.getNextStepStatus)(previousStep.type, previousStepStatus);
287
+ return _objectSpread(_objectSpread({}, step), {}, {
288
+ status: previousStepStatus
289
+ });
290
+ }
291
+
292
+ return step;
293
+ });
294
+ await this.update(id, {
295
+ steps: updatedSteps
296
+ });
297
+ return true;
298
+ }
299
+
300
+ };
301
+ }
@@ -0,0 +1,2 @@
1
+ import { ApwReviewerCrud, CreateApwParams } from "../types";
2
+ export declare function createReviewerMethods({ storageOperations }: CreateApwParams): ApwReviewerCrud;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createReviewerMethods = createReviewerMethods;
7
+
8
+ var _pubsub = require("@webiny/pubsub");
9
+
10
+ function createReviewerMethods({
11
+ storageOperations
12
+ }) {
13
+ const onBeforeReviewerCreate = (0, _pubsub.createTopic)();
14
+ const onAfterReviewerCreate = (0, _pubsub.createTopic)();
15
+ const onBeforeReviewerUpdate = (0, _pubsub.createTopic)();
16
+ const onAfterReviewerUpdate = (0, _pubsub.createTopic)();
17
+ const onBeforeReviewerDelete = (0, _pubsub.createTopic)();
18
+ const onAfterReviewerDelete = (0, _pubsub.createTopic)();
19
+ return {
20
+ /**
21
+ * Lifecycle events
22
+ */
23
+ onBeforeReviewerCreate,
24
+ onAfterReviewerCreate,
25
+ onBeforeReviewerUpdate,
26
+ onAfterReviewerUpdate,
27
+ onBeforeReviewerDelete,
28
+ onAfterReviewerDelete,
29
+
30
+ async get(id) {
31
+ return storageOperations.getReviewer({
32
+ id
33
+ });
34
+ },
35
+
36
+ async list(params) {
37
+ return storageOperations.listReviewers(params);
38
+ },
39
+
40
+ async create(data) {
41
+ await onBeforeReviewerCreate.publish({
42
+ input: data
43
+ });
44
+ const reviewer = await storageOperations.createReviewer({
45
+ data
46
+ });
47
+ await onAfterReviewerCreate.publish({
48
+ reviewer
49
+ });
50
+ return reviewer;
51
+ },
52
+
53
+ async update(id, data) {
54
+ const original = await storageOperations.getReviewer({
55
+ id
56
+ });
57
+ await onBeforeReviewerUpdate.publish({
58
+ original,
59
+ input: {
60
+ id,
61
+ data
62
+ }
63
+ });
64
+ const reviewer = await storageOperations.updateReviewer({
65
+ id,
66
+ data
67
+ });
68
+ await onAfterReviewerUpdate.publish({
69
+ original,
70
+ input: {
71
+ id,
72
+ data
73
+ },
74
+ reviewer
75
+ });
76
+ return reviewer;
77
+ },
78
+
79
+ async delete(id) {
80
+ const reviewer = await storageOperations.getReviewer({
81
+ id
82
+ });
83
+ await onBeforeReviewerDelete.publish({
84
+ reviewer
85
+ });
86
+ await storageOperations.deleteReviewer({
87
+ id
88
+ });
89
+ await onAfterReviewerDelete.publish({
90
+ reviewer
91
+ });
92
+ return true;
93
+ }
94
+
95
+ };
96
+ }
@@ -0,0 +1,2 @@
1
+ import { ApwWorkflowCrud, CreateApwParams } from "../types";
2
+ export declare function createWorkflowMethods({ storageOperations }: CreateApwParams): ApwWorkflowCrud;