@webiny/api-apw 0.0.0-unstable.1e66d121db → 0.0.0-unstable.2696f9d9e8

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 (267) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +28 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +28 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +28 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +28 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +5 -9
  14. package/ContentApwSettingsPlugin.js.map +1 -1
  15. package/README.md +3 -3
  16. package/crud/createChangeRequestMethods.js +7 -12
  17. package/crud/createChangeRequestMethods.js.map +1 -1
  18. package/crud/createCommentMethods.js +7 -13
  19. package/crud/createCommentMethods.js.map +1 -1
  20. package/crud/createContentReviewMethods.js +83 -111
  21. package/crud/createContentReviewMethods.js.map +1 -1
  22. package/crud/createReviewerMethods.js +7 -13
  23. package/crud/createReviewerMethods.js.map +1 -1
  24. package/crud/createWorkflowMethods.js +7 -18
  25. package/crud/createWorkflowMethods.js.map +1 -1
  26. package/crud/index.js +5 -29
  27. package/crud/index.js.map +1 -1
  28. package/crud/utils.js +6 -33
  29. package/crud/utils.js.map +1 -1
  30. package/index.d.ts +2 -3
  31. package/index.js +6 -16
  32. package/index.js.map +1 -1
  33. package/package.json +40 -47
  34. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +4 -19
  35. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  36. package/plugins/cms/apwEntryPlugins.js +8 -13
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  38. package/plugins/cms/index.js +7 -10
  39. package/plugins/cms/index.js.map +1 -1
  40. package/plugins/cms/linkContentReviewToEntry.js +4 -20
  41. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  42. package/plugins/cms/linkWorkflowToEntry.js +17 -45
  43. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  44. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  45. package/plugins/cms/notifications/changeRequestNotification.js +33 -0
  46. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  47. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  48. package/plugins/cms/notifications/commentNotification.js +33 -0
  49. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  50. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  51. package/plugins/cms/notifications/contentReviewNotification.js +33 -0
  52. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  53. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  54. package/plugins/cms/notifications/contentUrl.js +55 -0
  55. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  56. package/plugins/cms/triggerContentReview.js +5 -18
  57. package/plugins/cms/triggerContentReview.js.map +1 -1
  58. package/plugins/cms/updateContentReviewStatus.js +14 -30
  59. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  60. package/plugins/cms/utils.d.ts +3 -2
  61. package/plugins/cms/utils.js +23 -60
  62. package/plugins/cms/utils.js.map +1 -1
  63. package/plugins/context.d.ts +0 -1
  64. package/plugins/context.js +2 -45
  65. package/plugins/context.js.map +1 -1
  66. package/plugins/graphql/changeRequest.gql.js +16 -19
  67. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  68. package/plugins/graphql/comment.gql.js +41 -42
  69. package/plugins/graphql/comment.gql.js.map +1 -1
  70. package/plugins/graphql/contentReview.gql.js +25 -34
  71. package/plugins/graphql/contentReview.gql.js.map +1 -1
  72. package/plugins/graphql/reviewer.gql.js +17 -19
  73. package/plugins/graphql/reviewer.gql.js.map +1 -1
  74. package/plugins/graphql/utils.d.ts +2 -0
  75. package/plugins/graphql/utils.js +12 -0
  76. package/plugins/graphql/utils.js.map +1 -0
  77. package/plugins/graphql/workflow.gql.js +15 -19
  78. package/plugins/graphql/workflow.gql.js.map +1 -1
  79. package/plugins/graphql.js +5 -18
  80. package/plugins/graphql.js.map +1 -1
  81. package/plugins/hooks/createReviewerFromIdentity.js +28 -15
  82. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  83. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +3 -9
  84. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  85. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +3 -8
  86. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  87. package/plugins/hooks/index.js +4 -13
  88. package/plugins/hooks/index.js.map +1 -1
  89. package/plugins/hooks/initializeContentReviewSteps.js +15 -20
  90. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  91. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  92. package/plugins/hooks/initializeNotifications.js +17 -0
  93. package/plugins/hooks/initializeNotifications.js.map +1 -0
  94. package/plugins/hooks/listContentReviews.d.ts +1 -1
  95. package/plugins/hooks/listContentReviews.js +11 -33
  96. package/plugins/hooks/listContentReviews.js.map +1 -1
  97. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  98. package/plugins/hooks/notifications/appUrl.js +20 -0
  99. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  100. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  101. package/plugins/hooks/notifications/changeRequestAfterCreate.js +113 -0
  102. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  103. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  104. package/plugins/hooks/notifications/changeRequestUrl.js +29 -0
  105. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  106. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  107. package/plugins/hooks/notifications/commentAfterCreate.js +124 -0
  108. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  109. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  110. package/plugins/hooks/notifications/commentUrl.js +29 -0
  111. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  112. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  113. package/plugins/hooks/notifications/contentReviewAfterCreate.js +96 -0
  114. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  115. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  116. package/plugins/hooks/notifications/contentReviewUrl.js +28 -0
  117. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  118. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  119. package/plugins/hooks/notifications/contentUrl.js +26 -0
  120. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  121. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  122. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +23 -0
  123. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  124. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  125. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +23 -0
  126. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  127. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  128. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +23 -0
  129. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  130. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  131. package/plugins/hooks/notifications/reviewers.js +47 -0
  132. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  133. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  134. package/plugins/hooks/notifications/sendChangeRequestNotification.js +43 -0
  135. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  136. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  137. package/plugins/hooks/notifications/sendCommentNotification.js +43 -0
  138. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  139. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  140. package/plugins/hooks/notifications/sendContentReviewNotification.js +43 -0
  141. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  142. package/plugins/hooks/updatePendingChangeRequests.js +7 -13
  143. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  144. package/plugins/hooks/updateTotalComments.js +21 -23
  145. package/plugins/hooks/updateTotalComments.js.map +1 -1
  146. package/plugins/hooks/validateChangeRequest.js +27 -16
  147. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  148. package/plugins/hooks/validateComment.js +13 -12
  149. package/plugins/hooks/validateComment.js.map +1 -1
  150. package/plugins/hooks/validateContentReview.js +2 -6
  151. package/plugins/hooks/validateContentReview.js.map +1 -1
  152. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +4 -19
  153. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  154. package/plugins/pageBuilder/apwContentPagePlugins.js +2 -4
  155. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  156. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +3 -6
  157. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  158. package/plugins/pageBuilder/index.js +7 -8
  159. package/plugins/pageBuilder/index.js.map +1 -1
  160. package/plugins/pageBuilder/linkContentReviewToPage.js +15 -27
  161. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  162. package/plugins/pageBuilder/linkWorkflowToPage.js +3 -31
  163. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  164. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  165. package/plugins/pageBuilder/notifications/changeRequestNotification.js +33 -0
  166. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  167. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  168. package/plugins/pageBuilder/notifications/commentNotification.js +33 -0
  169. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  170. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  171. package/plugins/pageBuilder/notifications/contentReviewNotification.js +33 -0
  172. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  173. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  174. package/plugins/pageBuilder/notifications/contentUrl.js +49 -0
  175. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  176. package/plugins/pageBuilder/triggerContentReview.js +2 -11
  177. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  178. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -17
  179. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  180. package/plugins/pageBuilder/utils.d.ts +2 -2
  181. package/plugins/pageBuilder/utils.js +3 -35
  182. package/plugins/pageBuilder/utils.js.map +1 -1
  183. package/plugins/utils.d.ts +1 -2
  184. package/plugins/utils.js +6 -52
  185. package/plugins/utils.js.map +1 -1
  186. package/scheduler/createScheduleActionMethods.js +45 -50
  187. package/scheduler/createScheduleActionMethods.js.map +1 -1
  188. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  189. package/scheduler/handlers/executeAction/index.js +47 -40
  190. package/scheduler/handlers/executeAction/index.js.map +1 -1
  191. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
  192. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +19 -9
  193. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  194. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
  195. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +11 -28
  196. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  197. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
  198. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +10 -92
  199. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  200. package/scheduler/handlers/executeAction/security.js +2 -11
  201. package/scheduler/handlers/executeAction/security.js.map +1 -1
  202. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  203. package/scheduler/handlers/scheduleAction/index.js +24 -37
  204. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  205. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +20 -36
  206. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  207. package/scheduler/handlers/utils.d.ts +2 -4
  208. package/scheduler/handlers/utils.js +8 -47
  209. package/scheduler/handlers/utils.js.map +1 -1
  210. package/scheduler/index.js +2 -3
  211. package/scheduler/index.js.map +1 -1
  212. package/scheduler/types.d.ts +12 -28
  213. package/scheduler/types.js +13 -22
  214. package/scheduler/types.js.map +1 -1
  215. package/storageOperations/changeRequestStorageOperations.js +59 -45
  216. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  217. package/storageOperations/commentStorageOperations.js +35 -50
  218. package/storageOperations/commentStorageOperations.js.map +1 -1
  219. package/storageOperations/contentReviewStorageOperations.d.ts +1 -1
  220. package/storageOperations/contentReviewStorageOperations.js +34 -43
  221. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  222. package/storageOperations/index.d.ts +1 -7
  223. package/storageOperations/index.js +10 -29
  224. package/storageOperations/index.js.map +1 -1
  225. package/storageOperations/models/changeRequest.model.d.ts +1 -2
  226. package/storageOperations/models/changeRequest.model.js +6 -15
  227. package/storageOperations/models/changeRequest.model.js.map +1 -1
  228. package/storageOperations/models/comment.model.d.ts +1 -2
  229. package/storageOperations/models/comment.model.js +6 -14
  230. package/storageOperations/models/comment.model.js.map +1 -1
  231. package/storageOperations/models/contentReview.model.d.ts +1 -2
  232. package/storageOperations/models/contentReview.model.js +13 -37
  233. package/storageOperations/models/contentReview.model.js.map +1 -1
  234. package/storageOperations/models/index.js +6 -50
  235. package/storageOperations/models/index.js.map +1 -1
  236. package/storageOperations/models/reviewer.model.d.ts +1 -2
  237. package/storageOperations/models/reviewer.model.js +22 -14
  238. package/storageOperations/models/reviewer.model.js.map +1 -1
  239. package/storageOperations/models/utils.js +2 -4
  240. package/storageOperations/models/utils.js.map +1 -1
  241. package/storageOperations/models/workflow.model.d.ts +1 -2
  242. package/storageOperations/models/workflow.model.js +19 -42
  243. package/storageOperations/models/workflow.model.js.map +1 -1
  244. package/storageOperations/reviewerStorageOperations.d.ts +1 -1
  245. package/storageOperations/reviewerStorageOperations.js +34 -40
  246. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  247. package/storageOperations/types.js +3 -1
  248. package/storageOperations/workflowStorageOperations.js +40 -47
  249. package/storageOperations/workflowStorageOperations.js.map +1 -1
  250. package/types.d.ts +39 -25
  251. package/types.js +126 -42
  252. package/types.js.map +1 -1
  253. package/utils/contentApwSettingsPlugin.js +2 -6
  254. package/utils/contentApwSettingsPlugin.js.map +1 -1
  255. package/utils/errors.js +2 -17
  256. package/utils/errors.js.map +1 -1
  257. package/utils/fieldResolver.js +8 -18
  258. package/utils/fieldResolver.js.map +1 -1
  259. package/utils/pickEntryFieldValues.d.ts +3 -0
  260. package/utils/pickEntryFieldValues.js +31 -0
  261. package/utils/pickEntryFieldValues.js.map +1 -0
  262. package/utils/resolve.d.ts +1 -1
  263. package/utils/resolve.js +2 -3
  264. package/utils/resolve.js.map +1 -1
  265. package/storageOperations/models/contentModelPluginFactory.d.ts +0 -15
  266. package/storageOperations/models/contentModelPluginFactory.js +0 -28
  267. package/storageOperations/models/contentModelPluginFactory.js.map +0 -1
@@ -1,32 +1,19 @@
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.createContentReviewMethods = createContentReviewMethods;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
8
  var _get = _interopRequireDefault(require("lodash/get"));
13
-
14
9
  var _pubsub = require("@webiny/pubsub");
15
-
16
10
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
11
  var _types = require("../types");
19
-
20
12
  var _utils = require("../plugins/utils");
21
-
22
13
  var _errors = require("../utils/errors");
23
-
24
14
  var _types2 = require("../scheduler/types");
25
-
26
15
  var _utils2 = require("./utils");
27
-
28
16
  var _contentApwSettingsPlugin = require("../utils/contentApwSettingsPlugin");
29
-
30
17
  function createContentReviewMethods(params) {
31
18
  const {
32
19
  getIdentity,
@@ -40,16 +27,19 @@ function createContentReviewMethods(params) {
40
27
  getTenant,
41
28
  getLocale,
42
29
  plugins
43
- } = params; // create
30
+ } = params;
44
31
 
32
+ // create
45
33
  const onContentReviewBeforeCreate = (0, _pubsub.createTopic)("apw.onContentReviewBeforeCreate");
46
- const onContentReviewAfterCreate = (0, _pubsub.createTopic)("apw.onContentReviewAfterCreate"); // update
47
-
34
+ const onContentReviewAfterCreate = (0, _pubsub.createTopic)("apw.onContentReviewAfterCreate");
35
+ // update
48
36
  const onContentReviewBeforeUpdate = (0, _pubsub.createTopic)("apw.onContentReviewBeforeUpdate");
49
- const onContentReviewAfterUpdate = (0, _pubsub.createTopic)("apw.onContentReviewAfterUpdate"); // delete
50
-
37
+ const onContentReviewAfterUpdate = (0, _pubsub.createTopic)("apw.onContentReviewAfterUpdate");
38
+ // delete
51
39
  const onContentReviewBeforeDelete = (0, _pubsub.createTopic)("apw.onContentReviewBeforeDelete");
52
40
  const onContentReviewAfterDelete = (0, _pubsub.createTopic)("apw.onContentReviewAfterDelete");
41
+ // list
42
+ const onContentReviewBeforeList = (0, _pubsub.createTopic)("apw.onContentReviewBeforeList");
53
43
  return {
54
44
  /**
55
45
  * Lifecycle events
@@ -60,32 +50,38 @@ function createContentReviewMethods(params) {
60
50
  onContentReviewAfterUpdate,
61
51
  onContentReviewBeforeDelete,
62
52
  onContentReviewAfterDelete,
63
-
53
+ onContentReviewBeforeList,
64
54
  async get(id) {
65
55
  return storageOperations.getContentReview({
66
56
  id
67
57
  });
68
58
  },
69
-
70
59
  async list(params) {
71
- var _params$where;
72
-
73
- if (((_params$where = params.where) === null || _params$where === void 0 ? void 0 : _params$where.reviewStatus) === "requiresMyAttention") {
60
+ const where = params.where || {};
61
+ await onContentReviewBeforeList.publish({
62
+ where
63
+ });
64
+ if (where.reviewStatus === "requiresMyAttention") {
74
65
  return (0, _utils2.filterContentReviewsByRequiresMyAttention)({
75
- listParams: params,
66
+ listParams: {
67
+ ...params,
68
+ where
69
+ },
76
70
  listContentReviews: storageOperations.listContentReviews,
77
71
  getReviewer,
78
72
  getIdentity
79
73
  });
80
74
  }
81
-
82
- return storageOperations.listContentReviews(params);
75
+ return storageOperations.listContentReviews({
76
+ ...params,
77
+ where
78
+ });
83
79
  },
84
-
85
80
  async create(data) {
86
- const input = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
81
+ const input = {
82
+ ...data,
87
83
  reviewStatus: _types.ApwContentReviewStatus.UNDER_REVIEW
88
- });
84
+ };
89
85
  await onContentReviewBeforeCreate.publish({
90
86
  input
91
87
  });
@@ -97,7 +93,6 @@ function createContentReviewMethods(params) {
97
93
  });
98
94
  return contentReview;
99
95
  },
100
-
101
96
  async update(id, data) {
102
97
  const original = await storageOperations.getContentReview({
103
98
  id
@@ -123,7 +118,6 @@ function createContentReviewMethods(params) {
123
118
  });
124
119
  return contentReview;
125
120
  },
126
-
127
121
  async delete(id) {
128
122
  const contentReview = await storageOperations.getContentReview({
129
123
  id
@@ -139,7 +133,6 @@ function createContentReviewMethods(params) {
139
133
  });
140
134
  return true;
141
135
  },
142
-
143
136
  async provideSignOff(id, stepId) {
144
137
  const entry = await this.get(id);
145
138
  const {
@@ -155,10 +148,10 @@ function createContentReviewMethods(params) {
155
148
  identity,
156
149
  step: currentStep
157
150
  });
151
+
158
152
  /**
159
153
  * Check whether the sign-off is requested by a reviewer.
160
154
  */
161
-
162
155
  if (!hasPermission) {
163
156
  throw new _errors.NotAuthorizedError({
164
157
  entry,
@@ -171,8 +164,6 @@ function createContentReviewMethods(params) {
171
164
  /**
172
165
  * Don't allow sign off, if previous step is of "mandatory_blocking" type and undone.
173
166
  */
174
-
175
-
176
167
  if (previousStep && previousStep.status !== _types.ApwContentReviewStepStatus.DONE && previousStep.type === _types.ApwWorkflowStepTypes.MANDATORY_BLOCKING) {
177
168
  throw new _errors.StepMissingError({
178
169
  entry,
@@ -185,8 +176,6 @@ function createContentReviewMethods(params) {
185
176
  /**
186
177
  * Don't allow sign off, if there are pending change requests.
187
178
  */
188
-
189
-
190
179
  if (currentStep.pendingChangeRequests > 0) {
191
180
  throw new _errors.PendingChangeRequestsError({
192
181
  entry,
@@ -199,8 +188,6 @@ function createContentReviewMethods(params) {
199
188
  /**
200
189
  * Don't allow sign off, if current step is not in "active" state.
201
190
  */
202
-
203
-
204
191
  if (currentStep.status !== _types.ApwContentReviewStepStatus.ACTIVE) {
205
192
  throw new _errors.StepInActiveError({
206
193
  entry,
@@ -210,67 +197,62 @@ function createContentReviewMethods(params) {
210
197
  }
211
198
  });
212
199
  }
213
-
214
200
  let previousStepStatus;
215
201
  /*
216
202
  * Provide sign-off for give step.
217
203
  */
218
-
219
204
  const updatedSteps = steps.map((step, index) => {
220
205
  if (index === stepIndex) {
221
206
  previousStepStatus = _types.ApwContentReviewStepStatus.DONE;
222
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
207
+ return {
208
+ ...step,
223
209
  status: _types.ApwContentReviewStepStatus.DONE,
224
210
  signOffProvidedOn: new Date().toISOString(),
225
211
  signOffProvidedBy: identity
226
- });
212
+ };
227
213
  }
228
214
  /**
229
215
  * Update next steps status based on type.
230
216
  */
231
-
232
-
233
217
  if (index > stepIndex) {
234
218
  const previousStep = steps[index - 1];
235
219
  previousStepStatus = (0, _utils.getNextStepStatus)(previousStep.type, previousStepStatus);
236
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
220
+ return {
221
+ ...step,
237
222
  status: previousStepStatus
238
- });
223
+ };
239
224
  }
240
-
241
225
  return step;
242
226
  });
243
227
  /**
244
228
  * Check for pending steps
245
229
  */
246
-
247
230
  let newStatus = reviewStatus;
248
231
  const pendingRequiredSteps = (0, _utils2.getPendingRequiredSteps)(updatedSteps, step => typeof step.signOffProvidedOn !== "string");
232
+
249
233
  /**
250
234
  * If there are no required steps that are pending, set the status to "READY_TO_BE_PUBLISHED".
251
235
  */
252
-
253
236
  if (pendingRequiredSteps.length === 0) {
254
237
  newStatus = _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED;
255
238
  }
239
+
256
240
  /**
257
241
  * Save updated steps.
258
242
  */
259
-
260
-
261
243
  await this.update(id, {
262
244
  steps: updatedSteps,
263
245
  reviewStatus: newStatus
264
246
  });
265
247
  return true;
266
248
  },
267
-
268
249
  async retractSignOff(id, stepId) {
269
- const entry = await this.get(id);
250
+ const contentReview = await this.get(id);
270
251
  const {
271
252
  steps,
272
- reviewStatus
273
- } = entry;
253
+ reviewStatus,
254
+ content
255
+ } = contentReview;
274
256
  const stepIndex = steps.findIndex(step => step.id === stepId);
275
257
  const currentStep = steps[stepIndex];
276
258
  const identity = getIdentity();
@@ -279,13 +261,13 @@ function createContentReviewMethods(params) {
279
261
  identity,
280
262
  step: currentStep
281
263
  });
264
+
282
265
  /**
283
266
  * Check whether the retract sign-off is requested by a reviewer.
284
267
  */
285
-
286
268
  if (!hasPermission) {
287
269
  throw new _errors.NotAuthorizedError({
288
- entry,
270
+ entry: contentReview,
289
271
  input: {
290
272
  id,
291
273
  step: stepId
@@ -295,68 +277,75 @@ function createContentReviewMethods(params) {
295
277
  /**
296
278
  * Don't allow, if step in not "done" i.e. no sign-off was provided for it.
297
279
  */
298
-
299
-
300
280
  if (currentStep.status !== _types.ApwContentReviewStepStatus.DONE) {
301
281
  throw new _errors.NoSignOffProvidedError({
302
- entry,
282
+ entry: contentReview,
303
283
  input: {
304
284
  id,
305
285
  step: stepId
306
286
  }
307
287
  });
308
288
  }
309
-
310
289
  let previousStepStatus;
290
+
311
291
  /*
312
292
  * Retract sign-off for give step.
313
293
  */
314
-
315
294
  const updatedSteps = steps.map((step, index) => {
316
295
  if (index === stepIndex) {
317
296
  previousStepStatus = _types.ApwContentReviewStepStatus.ACTIVE;
318
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
297
+ return {
298
+ ...step,
319
299
  status: previousStepStatus,
320
300
  signOffProvidedOn: null,
321
301
  signOffProvidedBy: null
322
- });
302
+ };
323
303
  }
324
304
  /**
325
305
  * Set next step status as "inactive".
326
306
  */
327
-
328
-
329
307
  if (index > stepIndex) {
330
308
  const previousStep = steps[index - 1];
331
309
  previousStepStatus = (0, _utils.getNextStepStatus)(previousStep.type, previousStepStatus);
332
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
310
+ return {
311
+ ...step,
333
312
  status: previousStepStatus
334
- });
313
+ };
335
314
  }
336
-
337
315
  return step;
338
316
  });
317
+
339
318
  /**
340
319
  * Check for pending steps
341
320
  */
342
-
343
321
  let newStatus = reviewStatus;
344
322
  const pendingRequiredSteps = (0, _utils2.getPendingRequiredSteps)(updatedSteps, step => step.signOffProvidedOn === null);
345
323
  /**
346
324
  * If there are required steps that are pending, set the status to "UNDER_REVIEW".
347
325
  */
348
-
349
326
  if (pendingRequiredSteps.length !== 0) {
350
327
  newStatus = _types.ApwContentReviewStatus.UNDER_REVIEW;
351
328
  }
352
329
 
330
+ /**
331
+ * We need to delete the scheduled action if one was created.
332
+ */
333
+ const scheduledActionId = contentReview.content?.scheduledActionId;
334
+ if (!!scheduledActionId) {
335
+ await scheduler.delete(scheduledActionId);
336
+ }
353
337
  await this.update(id, {
338
+ content: {
339
+ ...content,
340
+ scheduledOn: null,
341
+ scheduledBy: null,
342
+ scheduledActionId: null
343
+ },
354
344
  steps: updatedSteps,
355
345
  reviewStatus: newStatus
356
346
  });
357
347
  return true;
358
348
  },
359
-
360
349
  async isReviewRequired(data) {
361
350
  const contentGetter = getContentGetter(data.type);
362
351
  const content = await contentGetter(data.id, data.settings);
@@ -366,31 +355,24 @@ function createContentReviewMethods(params) {
366
355
  plugins,
367
356
  type: data.type
368
357
  });
369
-
370
358
  if (contentApwSettingsPlugin) {
371
359
  contentReviewId = contentApwSettingsPlugin.getContentReviewId(content);
372
360
  const workflowId = contentApwSettingsPlugin.getWorkflowId(content);
373
-
374
361
  if (workflowId) {
375
362
  isReviewRequired = true;
376
363
  }
377
364
  }
378
-
379
365
  return {
380
366
  isReviewRequired,
381
367
  contentReviewId
382
368
  };
383
369
  },
384
-
385
370
  async publishContent(id, datetime) {
386
- var _content$settings;
387
-
388
371
  const {
389
372
  content,
390
373
  reviewStatus
391
374
  } = await this.get(id);
392
375
  const identity = getIdentity();
393
-
394
376
  if (reviewStatus !== _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED) {
395
377
  throw new _error.default({
396
378
  message: `Cannot publish content because it is not yet ready to be published.`,
@@ -402,50 +384,44 @@ function createContentReviewMethods(params) {
402
384
  }
403
385
  });
404
386
  }
405
-
406
387
  (0, _utils2.checkValidDateTime)(datetime);
388
+
407
389
  /**
408
390
  * If datetime is present it means we're scheduling this action.
409
391
  * And if not, we are publishing immediately.
410
392
  */
411
-
412
393
  if (!datetime) {
413
394
  const contentPublisher = getContentPublisher(content.type);
414
395
  await contentPublisher(content.id, content.settings);
415
396
  return true;
416
397
  }
417
-
418
398
  const data = {
419
399
  action: _types2.ApwScheduleActionTypes.PUBLISH,
420
400
  type: content.type,
421
401
  entryId: content.id,
422
- modelId: (_content$settings = content.settings) === null || _content$settings === void 0 ? void 0 : _content$settings.modelId,
402
+ modelId: content.settings?.modelId,
423
403
  datetime
424
404
  };
425
405
  const scheduledActionId = await this.scheduleAction(data);
426
406
  /**
427
407
  * Update scheduled related meta data.
428
408
  */
429
-
430
409
  await this.update(id, {
431
- content: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, content), {}, {
410
+ content: {
411
+ ...content,
432
412
  scheduledOn: datetime,
433
413
  scheduledBy: identity.id,
434
414
  scheduledActionId
435
- })
415
+ }
436
416
  });
437
417
  return true;
438
418
  },
439
-
440
419
  async unpublishContent(id, datetime) {
441
- var _content$settings2;
442
-
443
420
  const {
444
421
  content,
445
422
  reviewStatus
446
423
  } = await this.get(id);
447
424
  const identity = getIdentity();
448
-
449
425
  if (reviewStatus !== _types.ApwContentReviewStatus.PUBLISHED) {
450
426
  throw new _error.default({
451
427
  message: `Cannot unpublish content because it is not yet published.`,
@@ -457,40 +433,37 @@ function createContentReviewMethods(params) {
457
433
  }
458
434
  });
459
435
  }
460
-
461
436
  (0, _utils2.checkValidDateTime)(datetime);
437
+
462
438
  /**
463
439
  * If datetime is present it means we're scheduling this action.
464
440
  * If not, we are unpublishing immediately.
465
441
  */
466
-
467
442
  if (!datetime) {
468
443
  const contentUnPublisher = getContentUnPublisher(content.type);
469
444
  await contentUnPublisher(content.id, content.settings);
470
445
  return true;
471
446
  }
472
-
473
447
  const scheduledActionId = await this.scheduleAction({
474
448
  action: _types2.ApwScheduleActionTypes.UNPUBLISH,
475
449
  type: content.type,
476
450
  entryId: content.id,
477
- modelId: (_content$settings2 = content.settings) === null || _content$settings2 === void 0 ? void 0 : _content$settings2.modelId,
451
+ modelId: content.settings?.modelId,
478
452
  datetime
479
453
  });
480
454
  /**
481
455
  * Update scheduled related meta data.
482
456
  */
483
-
484
457
  await this.update(id, {
485
- content: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, content), {}, {
458
+ content: {
459
+ ...content,
486
460
  scheduledOn: datetime,
487
461
  scheduledBy: identity.id,
488
462
  scheduledActionId
489
- })
463
+ }
490
464
  });
491
465
  return true;
492
466
  },
493
-
494
467
  async scheduleAction(data) {
495
468
  // Save input in DB
496
469
  const scheduledAction = await scheduler.create(data);
@@ -498,12 +471,10 @@ function createContentReviewMethods(params) {
498
471
  * This function contains logic of lambda invocation.
499
472
  * Current we're not mocking it, therefore, we're just returning true.
500
473
  */
501
-
502
474
  if (process.env.NODE_ENV === "test") {
503
475
  return scheduledAction.id;
504
- } // Invoke handler
505
-
506
-
476
+ }
477
+ // Invoke handler
507
478
  await handlerClient.invoke({
508
479
  name: String(process.env.APW_SCHEDULER_SCHEDULE_ACTION_HANDLER),
509
480
  payload: {
@@ -515,14 +486,13 @@ function createContentReviewMethods(params) {
515
486
  });
516
487
  return scheduledAction.id;
517
488
  },
518
-
519
489
  async deleteScheduledAction(id) {
520
490
  const contentReview = await this.get(id);
521
491
  const scheduledActionId = (0, _get.default)(contentReview, "content.scheduledActionId");
492
+
522
493
  /**
523
494
  * Check if there is any action scheduled for this "content review".
524
495
  */
525
-
526
496
  if (!scheduledActionId) {
527
497
  throw new _error.default({
528
498
  message: `There is no action scheduled for content review.`,
@@ -535,18 +505,20 @@ function createContentReviewMethods(params) {
535
505
  /**
536
506
  * Delete scheduled action.
537
507
  */
538
-
539
-
540
508
  await scheduler.delete(scheduledActionId);
509
+
541
510
  /**
542
511
  * Reset scheduled related meta data.
543
512
  */
544
-
545
513
  await this.update(id, {
546
- content: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentReview.content), _utils2.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META)
514
+ content: {
515
+ ...contentReview.content,
516
+ ..._utils2.INITIAL_CONTENT_REVIEW_CONTENT_SCHEDULE_META
517
+ }
547
518
  });
548
519
  return true;
549
520
  }
550
-
551
521
  };
552
- }
522
+ }
523
+
524
+ //# sourceMappingURL=createContentReviewMethods.js.map