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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/ApwChangeRequestNotification.js +0 -10
  2. package/ApwChangeRequestNotification.js.map +1 -1
  3. package/ApwCommentNotification.js +0 -10
  4. package/ApwCommentNotification.js.map +1 -1
  5. package/ApwContentReviewNotification.js +0 -10
  6. package/ApwContentReviewNotification.js.map +1 -1
  7. package/ApwContentUrlPlugin.js +0 -10
  8. package/ApwContentUrlPlugin.js.map +1 -1
  9. package/ContentApwSettingsPlugin.js +0 -5
  10. package/ContentApwSettingsPlugin.js.map +1 -1
  11. package/crud/createChangeRequestMethods.js +4 -11
  12. package/crud/createChangeRequestMethods.js.map +1 -1
  13. package/crud/createCommentMethods.js +4 -12
  14. package/crud/createCommentMethods.js.map +1 -1
  15. package/crud/createContentReviewMethods.js +20 -84
  16. package/crud/createContentReviewMethods.js.map +1 -1
  17. package/crud/createReviewerMethods.js +4 -12
  18. package/crud/createReviewerMethods.js.map +1 -1
  19. package/crud/createWorkflowMethods.js +4 -17
  20. package/crud/createWorkflowMethods.js.map +1 -1
  21. package/crud/index.js +0 -25
  22. package/crud/index.js.map +1 -1
  23. package/crud/utils.js +0 -28
  24. package/crud/utils.js.map +1 -1
  25. package/index.d.ts +1 -2
  26. package/index.js +1 -15
  27. package/index.js.map +1 -1
  28. package/package.json +34 -34
  29. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +0 -15
  30. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  31. package/plugins/cms/apwEntryPlugins.js +0 -8
  32. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  33. package/plugins/cms/index.js +0 -13
  34. package/plugins/cms/index.js.map +1 -1
  35. package/plugins/cms/linkContentReviewToEntry.js +0 -17
  36. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  37. package/plugins/cms/linkWorkflowToEntry.js +2 -31
  38. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  39. package/plugins/cms/notifications/changeRequestNotification.js +0 -4
  40. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
  41. package/plugins/cms/notifications/commentNotification.js +0 -4
  42. package/plugins/cms/notifications/commentNotification.js.map +1 -1
  43. package/plugins/cms/notifications/contentReviewNotification.js +0 -4
  44. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
  45. package/plugins/cms/notifications/contentUrl.js +1 -8
  46. package/plugins/cms/notifications/contentUrl.js.map +1 -1
  47. package/plugins/cms/triggerContentReview.js +0 -14
  48. package/plugins/cms/triggerContentReview.js.map +1 -1
  49. package/plugins/cms/updateContentReviewStatus.js +0 -18
  50. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  51. package/plugins/cms/utils.js +2 -47
  52. package/plugins/cms/utils.js.map +1 -1
  53. package/plugins/context.d.ts +0 -1
  54. package/plugins/context.js +2 -47
  55. package/plugins/context.js.map +1 -1
  56. package/plugins/graphql/changeRequest.gql.js +3 -10
  57. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  58. package/plugins/graphql/comment.gql.js +3 -10
  59. package/plugins/graphql/comment.gql.js.map +1 -1
  60. package/plugins/graphql/contentReview.gql.js +6 -25
  61. package/plugins/graphql/contentReview.gql.js.map +1 -1
  62. package/plugins/graphql/reviewer.gql.js +3 -10
  63. package/plugins/graphql/reviewer.gql.js.map +1 -1
  64. package/plugins/graphql/workflow.gql.js +3 -10
  65. package/plugins/graphql/workflow.gql.js.map +1 -1
  66. package/plugins/graphql.js +3 -18
  67. package/plugins/graphql.js.map +1 -1
  68. package/plugins/hooks/createReviewerFromIdentity.js +2 -11
  69. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  70. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -9
  71. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  72. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -8
  73. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  74. package/plugins/hooks/index.js +0 -14
  75. package/plugins/hooks/index.js.map +1 -1
  76. package/plugins/hooks/initializeContentReviewSteps.js +2 -18
  77. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  78. package/plugins/hooks/initializeNotifications.js +0 -5
  79. package/plugins/hooks/initializeNotifications.js.map +1 -1
  80. package/plugins/hooks/listContentReviews.js +0 -12
  81. package/plugins/hooks/listContentReviews.js.map +1 -1
  82. package/plugins/hooks/notifications/appUrl.js +0 -4
  83. package/plugins/hooks/notifications/appUrl.js.map +1 -1
  84. package/plugins/hooks/notifications/changeRequestAfterCreate.js +3 -36
  85. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  86. package/plugins/hooks/notifications/changeRequestUrl.js +0 -4
  87. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
  88. package/plugins/hooks/notifications/commentAfterCreate.js +3 -38
  89. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  90. package/plugins/hooks/notifications/commentUrl.js +0 -4
  91. package/plugins/hooks/notifications/commentUrl.js.map +1 -1
  92. package/plugins/hooks/notifications/contentReviewAfterCreate.js +4 -32
  93. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  94. package/plugins/hooks/notifications/contentReviewUrl.js +0 -4
  95. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
  96. package/plugins/hooks/notifications/contentUrl.js +0 -5
  97. package/plugins/hooks/notifications/contentUrl.js.map +1 -1
  98. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +0 -4
  99. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
  100. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +0 -4
  101. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
  102. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +0 -4
  103. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
  104. package/plugins/hooks/notifications/reviewers.js +15 -21
  105. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  106. package/plugins/hooks/notifications/sendChangeRequestNotification.js +0 -11
  107. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
  108. package/plugins/hooks/notifications/sendCommentNotification.js +0 -11
  109. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
  110. package/plugins/hooks/notifications/sendContentReviewNotification.js +0 -11
  111. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
  112. package/plugins/hooks/updatePendingChangeRequests.js +0 -8
  113. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  114. package/plugins/hooks/updateTotalComments.js +0 -9
  115. package/plugins/hooks/updateTotalComments.js.map +1 -1
  116. package/plugins/hooks/validateChangeRequest.js +0 -16
  117. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  118. package/plugins/hooks/validateComment.js +1 -12
  119. package/plugins/hooks/validateComment.js.map +1 -1
  120. package/plugins/hooks/validateContentReview.js +0 -6
  121. package/plugins/hooks/validateContentReview.js.map +1 -1
  122. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -15
  123. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  124. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  125. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  126. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  127. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  128. package/plugins/pageBuilder/index.js +0 -11
  129. package/plugins/pageBuilder/index.js.map +1 -1
  130. package/plugins/pageBuilder/linkContentReviewToPage.js +0 -16
  131. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  132. package/plugins/pageBuilder/linkWorkflowToPage.js +1 -31
  133. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  134. package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -4
  135. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
  136. package/plugins/pageBuilder/notifications/commentNotification.js +0 -4
  137. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
  138. package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -4
  139. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
  140. package/plugins/pageBuilder/notifications/contentUrl.js +1 -7
  141. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
  142. package/plugins/pageBuilder/triggerContentReview.js +0 -11
  143. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  144. package/plugins/pageBuilder/updateContentReviewStatus.js +0 -12
  145. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  146. package/plugins/pageBuilder/utils.js +1 -35
  147. package/plugins/pageBuilder/utils.js.map +1 -1
  148. package/plugins/utils.js +0 -43
  149. package/plugins/utils.js.map +1 -1
  150. package/scheduler/createScheduleActionMethods.js +1 -20
  151. package/scheduler/createScheduleActionMethods.js.map +1 -1
  152. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  153. package/scheduler/handlers/executeAction/index.js +9 -40
  154. package/scheduler/handlers/executeAction/index.js.map +1 -1
  155. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +0 -7
  156. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  157. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +1 -23
  158. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  159. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +4 -28
  160. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  161. package/scheduler/handlers/executeAction/security.js +0 -11
  162. package/scheduler/handlers/executeAction/security.js.map +1 -1
  163. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  164. package/scheduler/handlers/scheduleAction/index.js +5 -25
  165. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  166. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -23
  167. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  168. package/scheduler/handlers/utils.d.ts +1 -2
  169. package/scheduler/handlers/utils.js +3 -41
  170. package/scheduler/handlers/utils.js.map +1 -1
  171. package/scheduler/index.js +0 -3
  172. package/scheduler/index.js.map +1 -1
  173. package/scheduler/types.d.ts +2 -20
  174. package/scheduler/types.js +0 -11
  175. package/scheduler/types.js.map +1 -1
  176. package/storageOperations/changeRequestStorageOperations.js +20 -39
  177. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  178. package/storageOperations/commentStorageOperations.js +23 -44
  179. package/storageOperations/commentStorageOperations.js.map +1 -1
  180. package/storageOperations/contentReviewStorageOperations.js +20 -37
  181. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  182. package/storageOperations/index.js +0 -14
  183. package/storageOperations/index.js.map +1 -1
  184. package/storageOperations/models/changeRequest.model.js +0 -9
  185. package/storageOperations/models/changeRequest.model.js.map +1 -1
  186. package/storageOperations/models/comment.model.js +0 -8
  187. package/storageOperations/models/comment.model.js.map +1 -1
  188. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
  189. package/storageOperations/models/contentModelPluginFactory.js +3 -11
  190. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  191. package/storageOperations/models/contentReview.model.js +0 -26
  192. package/storageOperations/models/contentReview.model.js.map +1 -1
  193. package/storageOperations/models/index.js +2 -28
  194. package/storageOperations/models/index.js.map +1 -1
  195. package/storageOperations/models/reviewer.model.js +0 -8
  196. package/storageOperations/models/reviewer.model.js.map +1 -1
  197. package/storageOperations/models/utils.js +0 -4
  198. package/storageOperations/models/utils.js.map +1 -1
  199. package/storageOperations/models/workflow.model.js +0 -23
  200. package/storageOperations/models/workflow.model.js.map +1 -1
  201. package/storageOperations/reviewerStorageOperations.js +23 -45
  202. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  203. package/storageOperations/workflowStorageOperations.js +20 -39
  204. package/storageOperations/workflowStorageOperations.js.map +1 -1
  205. package/types.d.ts +6 -5
  206. package/types.js +0 -14
  207. package/types.js.map +1 -1
  208. package/utils/contentApwSettingsPlugin.js +0 -6
  209. package/utils/contentApwSettingsPlugin.js.map +1 -1
  210. package/utils/errors.js +0 -17
  211. package/utils/errors.js.map +1 -1
  212. package/utils/fieldResolver.js +2 -12
  213. package/utils/fieldResolver.js.map +1 -1
  214. package/utils/resolve.d.ts +1 -1
  215. package/utils/resolve.js +0 -3
  216. package/utils/resolve.js.map +1 -1
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.executeActionHandlerPlugins = void 0;
7
-
8
7
  var _utils = require("../utils");
9
-
10
8
  var _api = require("@webiny/api");
11
-
12
9
  var _PageBuilderGraphQL = require("./plugins/PageBuilderGraphQL");
13
-
14
10
  var _HeadlessCMSGraphQL = require("./plugins/HeadlessCMSGraphQL");
15
-
16
11
  var _ApplicationGraphQL = require("./plugins/ApplicationGraphQL");
17
-
18
12
  var _handlerAws = require("@webiny/handler-aws");
19
-
20
13
  /**
21
14
  * Handler that execute the provided action(s) for the schedule action workflow.
22
15
  */
@@ -30,35 +23,27 @@ const createExecuteActionLambda = params => {
30
23
  }) => {
31
24
  const log = console.log;
32
25
  const applicationGraphQLPlugins = context.plugins.byType(_ApplicationGraphQL.ApplicationGraphQL.type);
33
-
34
26
  if (applicationGraphQLPlugins.length === 0) {
35
27
  console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);
36
28
  return;
37
29
  }
38
-
39
30
  const applicationGraphQLPluginCache = {};
40
-
41
31
  const getApplicationGraphQLPlugin = data => {
42
32
  const {
43
33
  type
44
34
  } = data;
45
-
46
35
  if (applicationGraphQLPluginCache[type]) {
47
36
  return applicationGraphQLPluginCache[type];
48
37
  }
49
-
50
38
  for (const plugin of applicationGraphQLPlugins) {
51
39
  if (!plugin.canUse(data)) {
52
40
  continue;
53
41
  }
54
-
55
42
  applicationGraphQLPluginCache[type] = plugin;
56
43
  return plugin;
57
44
  }
58
-
59
45
  return null;
60
46
  };
61
-
62
47
  try {
63
48
  const apwSettings = await (0, _utils.getApwSettings)();
64
49
  const {
@@ -69,16 +54,14 @@ const createExecuteActionLambda = params => {
69
54
  /**
70
55
  * If there is no datetime we bail out early.
71
56
  */
72
-
73
57
  if (!datetime || typeof datetime !== "string") {
74
58
  log(`Bailing out!!`);
75
59
  return;
76
60
  }
61
+
77
62
  /**
78
63
  * Get tasks from the DB by datetime.
79
64
  */
80
-
81
-
82
65
  const [items] = await storageOperations.list({
83
66
  where: {
84
67
  tenant,
@@ -88,28 +71,23 @@ const createExecuteActionLambda = params => {
88
71
  sort: ["datetime_ASC"],
89
72
  limit: 1000
90
73
  });
74
+
91
75
  /**
92
76
  * Execute all actions.
93
77
  */
94
-
95
78
  if (!items || items.length === 0) {
96
79
  return;
97
80
  }
98
-
99
81
  log(`Found ${items.length} actions.`);
100
-
101
82
  for (const item of items) {
102
83
  log(`Performing mutation "${item.data.action}" on "${item.data.type}" at "${item.data.datetime}"`);
103
84
  const plugin = getApplicationGraphQLPlugin(item.data);
104
-
105
85
  if (!plugin) {
106
86
  console.error(`There is no plugin to determine GraphQL endpoint and mutations for type "${item.data.type}".`);
107
87
  console.log(JSON.stringify(item));
108
88
  continue;
109
89
  }
110
-
111
90
  const name = plugin.getArn(apwSettings);
112
-
113
91
  if (!name) {
114
92
  console.error(`There is no FunctionName found for type "${item.data.type}".`);
115
93
  console.log(JSON.stringify({
@@ -118,28 +96,23 @@ const createExecuteActionLambda = params => {
118
96
  }));
119
97
  continue;
120
98
  }
121
-
122
99
  const url = plugin.getUrl({
123
100
  locale,
124
101
  tenant
125
102
  });
126
-
127
103
  if (!url) {
128
104
  console.error(`There is no url defined, in the Plugin, for type "${item.data.type}".`);
129
105
  console.log(JSON.stringify(item));
130
106
  continue;
131
107
  }
132
-
133
108
  const body = plugin.getGraphQLBody(item.data);
134
-
135
109
  if (!body) {
136
110
  console.error(`There is no GraphQL body defined, in the Plugin, for type "${item.data.type}".`);
137
111
  console.log(JSON.stringify(item));
138
112
  continue;
139
113
  }
140
-
141
- console.log(`Invoking Lambda "${name}" with url "${url}".`); // Perform the actual action call.
142
-
114
+ console.log(`Invoking Lambda "${name}" with url "${url}".`);
115
+ // Perform the actual action call.
143
116
  const response = await context.handlerClient.invoke({
144
117
  name,
145
118
  payload: {
@@ -162,7 +135,6 @@ const createExecuteActionLambda = params => {
162
135
  /**
163
136
  *
164
137
  */
165
-
166
138
  await storageOperations.delete({
167
139
  locale,
168
140
  tenant,
@@ -171,33 +143,31 @@ const createExecuteActionLambda = params => {
171
143
  /**
172
144
  * Check for the response and log the error if any.
173
145
  */
174
-
175
146
  if (response !== null && response !== void 0 && response.body) {
176
147
  var _response$body$data, _response$body$data$c;
177
-
178
148
  const error = (_response$body$data = response.body.data) === null || _response$body$data === void 0 ? void 0 : (_response$body$data$c = _response$body$data.content) === null || _response$body$data$c === void 0 ? void 0 : _response$body$data$c.error;
179
-
180
149
  if (!error) {
181
150
  console.log("Invoke successful.");
182
151
  continue;
183
152
  }
184
-
185
153
  console.log(JSON.stringify({
186
154
  error
187
155
  }, null, 2));
188
156
  continue;
189
157
  }
190
-
191
158
  console.log(JSON.stringify({
192
159
  response
193
- }, null, 2)); // TODO: Maybe update the status like error in original item in DB.
160
+ }, null, 2));
161
+
162
+ // TODO: Maybe update the status like error in original item in DB.
194
163
  }
195
164
  } catch (ex) {
196
165
  console.error("[HANDLER_EXECUTE_ACTION] => ", JSON.stringify({
197
166
  message: ex.message,
198
167
  code: ex.code,
199
168
  data: ex.data
200
- })); // TODO: Maybe update the status like error in original item in DB.
169
+ }));
170
+ // TODO: Maybe update the status like error in original item in DB.
201
171
  }
202
172
  });
203
173
  };
@@ -205,5 +175,4 @@ const createExecuteActionLambda = params => {
205
175
  const executeActionHandlerPlugins = config => [new _api.ContextPlugin(async context => {
206
176
  context.plugins.register([new _PageBuilderGraphQL.PageBuilderGraphQL(), new _HeadlessCMSGraphQL.HeadlessCMSGraphQL()]);
207
177
  }), (0, _utils.basePlugins)(), createExecuteActionLambda(config)];
208
-
209
178
  exports.executeActionHandlerPlugins = executeActionHandlerPlugins;
@@ -1 +1 @@
1
- {"version":3,"names":["createExecuteActionLambda","params","storageOperations","createRawEventHandler","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","url","getUrl","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","delete","content","ex","message","code","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createRawEventHandler<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n console.log(`Invoking Lambda \"${name}\" with url \"${url}\".`);\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: url,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n /**\n *\n */\n await storageOperations.delete({\n locale,\n tenant,\n id: item.id\n });\n /**\n * Check for the response and log the error if any.\n */\n if (response?.body) {\n const error = response.body.data?.content?.error;\n if (!error) {\n console.log(\"Invoke successful.\");\n continue;\n }\n console.log(JSON.stringify({ error }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (ex) {\n console.error(\n \"[HANDLER_EXECUTE_ACTION] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAD,IAA2B;EACzD,MAAM;IAAEC;EAAF,IAAwBD,MAA9B;EAEA,OAAO,IAAAE,iCAAA,EAAmC,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IACtE,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;IAEA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G,sBAA6BzC,KAA3C;;UACA,IAAI,CAACA,KAAL,EAAY;YACRP,OAAO,CAACD,GAAR,CAAY,oBAAZ;YACA;UACH;;UACDC,OAAO,CAACD,GAAR,CAAY6B,IAAI,CAACC,SAAL,CAAe;YAAEtB;UAAF,CAAf,EAA0B,IAA1B,EAAgC,CAAhC,CAAZ;UACA;QACH;;QACDP,OAAO,CAACD,GAAR,CAAY6B,IAAI,CAACC,SAAL,CAAe;UAAEQ;QAAF,CAAf,EAA6B,IAA7B,EAAmC,CAAnC,CAAZ,EAzFsB,CA2FtB;MACH;IACJ,CA7HD,CA6HE,OAAOY,EAAP,EAAW;MACTjD,OAAO,CAACO,KAAR,CACI,8BADJ,EAEIqB,IAAI,CAACC,SAAL,CAAe;QACXqB,OAAO,EAAED,EAAE,CAACC,OADD;QAEXC,IAAI,EAAEF,EAAE,CAACE,IAFE;QAGXzC,IAAI,EAAEuC,EAAE,CAACvC;MAHE,CAAf,CAFJ,EADS,CAST;IACH;EACJ,CAvKM,CAAP;AAwKH,CA3KD;;AA6KO,MAAM0C,2BAA2B,GAAIC,MAAD,IAA2B,CAClE,IAAIC,kBAAJ,CAAkB,MAAMxD,OAAN,IAAiB;EAC/BA,OAAO,CAACI,OAAR,CAAgBqD,QAAhB,CAAyB,CAAC,IAAIC,sCAAJ,EAAD,EAA2B,IAAIC,sCAAJ,EAA3B,CAAzB;AACH,CAFD,CADkE,EAIlE,IAAAC,kBAAA,GAJkE,EAKlEjE,yBAAyB,CAAC4D,MAAD,CALyC,CAA/D"}
1
+ {"version":3,"names":["createExecuteActionLambda","params","storageOperations","createRawEventHandler","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","url","getUrl","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","delete","content","ex","message","code","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createRawEventHandler<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n console.log(`Invoking Lambda \"${name}\" with url \"${url}\".`);\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: url,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n /**\n *\n */\n await storageOperations.delete({\n locale,\n tenant,\n id: item.id\n });\n /**\n * Check for the response and log the error if any.\n */\n if (response?.body) {\n const error = response.body.data?.content?.error;\n if (!error) {\n console.log(\"Invoke successful.\");\n continue;\n }\n console.log(JSON.stringify({ error }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (ex) {\n console.error(\n \"[HANDLER_EXECUTE_ACTION] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAqB,IAAK;EACzD,MAAM;IAAEC;EAAkB,CAAC,GAAGD,MAAM;EAEpC,OAAO,IAAAE,iCAAqB,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IACtE,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvB,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAO,CAACC,MAAM,CACpDC,sCAAkB,CAACC,IAAI,CAC1B;IAED,IAAIJ,yBAAyB,CAACK,MAAM,KAAK,CAAC,EAAE;MACxCN,OAAO,CAACO,KAAK,CAAE,mEAAkE,CAAC;MAClF;IACJ;IAEA,MAAMC,6BAAiE,GAAG,CAAC,CAAC;IAE5E,MAAMC,2BAA2B,GAC7BC,IAA2B,IACC;MAC5B,MAAM;QAAEL;MAAK,CAAC,GAAGK,IAAI;MACrB,IAAIF,6BAA6B,CAACH,IAAI,CAAC,EAAE;QACrC,OAAOG,6BAA6B,CAACH,IAAI,CAAC;MAC9C;MACA,KAAK,MAAMM,MAAM,IAAIV,yBAAyB,EAAE;QAC5C,IAAI,CAAC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AAE,CAACE,IAAI;QACbzC,IAAI,EAAEuC,EAAE,CAACvC;MACb,CAAC,CAAC,CACL;MACD;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAM0C,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMxD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAACqD,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACbjE,yBAAyB,CAAC4D,MAAM,CAAC,CACpC;AAAC"}
@@ -1,7 +1,6 @@
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
  });
@@ -18,16 +17,10 @@ Object.defineProperty(exports, "ApwSettings", {
18
17
  return _utils.ApwSettings;
19
18
  }
20
19
  });
21
-
22
20
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
-
24
21
  var _Plugin = require("@webiny/plugins/Plugin");
25
-
26
22
  var _types = require("../../../types");
27
-
28
23
  var _utils = require("../../utils");
29
-
30
24
  class ApplicationGraphQL extends _Plugin.Plugin {}
31
-
32
25
  exports.ApplicationGraphQL = ApplicationGraphQL;
33
26
  (0, _defineProperty2.default)(ApplicationGraphQL, "type", "apw.scheduler.applicationGraphQL");
@@ -1 +1 @@
1
- {"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport { ApwScheduleActionData, ApwSettings };\n\nexport interface ApplicationGraphQLGetUrlParams {\n tenant: string;\n locale: string;\n}\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract getUrl(params: ApplicationGraphQLGetUrlParams): string;\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAaO,MAAeA,kBAAf,SAA0CC,cAA1C,CAAiD;;;8BAAlCD,kB,UAC6B,kC"}
1
+ {"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport { ApwScheduleActionData, ApwSettings };\n\nexport interface ApplicationGraphQLGetUrlParams {\n tenant: string;\n locale: string;\n}\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract getUrl(params: ApplicationGraphQLGetUrlParams): string;\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAaO,MAAeA,kBAAkB,SAASC,cAAM,CAAC;AAUvD;AAAA,8BAVqBD,kBAAkB,UACW,kCAAkC"}
@@ -1,22 +1,15 @@
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.HeadlessCMSGraphQL = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _ApplicationGraphQL = require("./ApplicationGraphQL");
13
-
14
10
  var _types = require("../../../types");
15
-
16
11
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
12
  var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
19
-
20
13
  const META_FIELDS = `
21
14
  title
22
15
  publishedOn
@@ -31,7 +24,6 @@ const ERROR_FIELD = `
31
24
  message
32
25
  }
33
26
  `;
34
-
35
27
  const createPublishMutation = modelId => {
36
28
  const ucFirstModelId = (0, _upperFirst.default)(modelId);
37
29
  return `
@@ -47,7 +39,6 @@ const createPublishMutation = modelId => {
47
39
  }
48
40
  }`;
49
41
  };
50
-
51
42
  const createUnpublishMutation = modelId => {
52
43
  const ucFirstModelId = (0, _upperFirst.default)(modelId);
53
44
  return `
@@ -63,47 +54,38 @@ const createUnpublishMutation = modelId => {
63
54
  }
64
55
  }`;
65
56
  };
66
-
67
57
  class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
68
58
  constructor(...args) {
69
59
  super(...args);
70
60
  (0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.headlessCms");
71
61
  }
72
-
73
62
  canUse(data) {
74
63
  return data.type === _types.ApwContentTypes.CMS_ENTRY;
75
64
  }
76
-
77
65
  getUrl({
78
66
  locale
79
67
  }) {
80
68
  return `/cms/manage/${locale}`;
81
69
  }
82
-
83
70
  getArn(settings) {
84
- return settings.cmsGraphqlFunctionArn;
71
+ return settings.mainGraphqlFunctionArn;
85
72
  }
86
-
87
73
  getGraphQLBody(data) {
88
74
  switch (data.action) {
89
75
  case _types.ApwScheduleActionTypes.PUBLISH:
90
76
  return this.getPublishBody(data);
91
-
92
77
  case _types.ApwScheduleActionTypes.UNPUBLISH:
93
78
  return this.getUnpublishBody(data);
94
-
95
79
  default:
96
80
  return null;
97
81
  }
98
82
  }
99
-
100
83
  getPublishBody(data) {
101
84
  if (!data.modelId) {
102
85
  throw new _error.default("Missing model ID in the schedule action data.", "SCHEDULE_ACTION_ERROR", {
103
86
  data
104
87
  });
105
88
  }
106
-
107
89
  return {
108
90
  query: createPublishMutation(data.modelId),
109
91
  variables: {
@@ -111,14 +93,12 @@ class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
111
93
  }
112
94
  };
113
95
  }
114
-
115
96
  getUnpublishBody(data) {
116
97
  if (!data.modelId) {
117
98
  throw new _error.default("Missing model ID in the schedule action data.", "SCHEDULE_ACTION_ERROR", {
118
99
  data
119
100
  });
120
101
  }
121
-
122
102
  return {
123
103
  query: createUnpublishMutation(data.modelId),
124
104
  variables: {
@@ -126,7 +106,5 @@ class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
126
106
  }
127
107
  };
128
108
  }
129
-
130
109
  }
131
-
132
110
  exports.HeadlessCMSGraphQL = HeadlessCMSGraphQL;
@@ -1 +1 @@
1
- {"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getUrl","locale","getArn","settings","cmsGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwSettings,\n ApplicationGraphQLGetUrlParams,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n publishedOn\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.headlessCms\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getUrl({ locale }: ApplicationGraphQLGetUrlParams): string {\n return `/cms/manage/${locale}`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.cmsGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOA;;AACA;;AACA;;AAEA,MAAMA,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CANA;;AAQA,MAAMC,qBAAqB,GAAIC,OAAD,IAA6B;EACvD,MAAMC,cAAc,GAAG,IAAAC,mBAAA,EAAWF,OAAX,CAAvB;EAEA,OAAQ;AACZ,6BAA6BC,cAAe;AAC5C,8BAA8BA,cAAe;AAC7C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAXI;AAYH,CAfD;;AAiBA,MAAMK,uBAAuB,GAAIH,OAAD,IAAqB;EACjD,MAAMC,cAAc,GAAG,IAAAC,mBAAA,EAAWF,OAAX,CAAvB;EAEA,OAAQ;AACZ,+BAA+BC,cAAe;AAC9C,gCAAgCA,cAAe;AAC/C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAXI;AAYH,CAfD;;AAqBO,MAAMM,kBAAN,SAAiCC,sCAAjC,CAAoD;EAAA;IAAA;IAAA,4CAChC,8CADgC;EAAA;;EAGvCC,MAAM,CAACC,IAAD,EAAuC;IACzD,OAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAA,CAAgBC,SAArC;EACH;;EAEeC,MAAM,CAAC;IAAEC;EAAF,CAAD,EAAqD;IACvE,OAAQ,eAAcA,MAAO,EAA7B;EACH;;EAEeC,MAAM,CAACC,QAAD,EAAgC;IAClD,OAAOA,QAAQ,CAACC,qBAAhB;EACH;;EAEeC,cAAc,CAACT,IAAD,EAA6D;IACvF,QAAQA,IAAI,CAACU,MAAb;MACI,KAAKC,6BAAA,CAAuBC,OAA5B;QACI,OAAO,KAAKC,cAAL,CAAoBb,IAApB,CAAP;;MACJ,KAAKW,6BAAA,CAAuBG,SAA5B;QACI,OAAO,KAAKC,gBAAL,CAAsBf,IAAtB,CAAP;;MACJ;QACI,OAAO,IAAP;IANR;EAQH;;EAEOa,cAAc,CAClBb,IADkB,EAEqC;IACvD,IAAI,CAACA,IAAI,CAACP,OAAV,EAAmB;MACf,MAAM,IAAIuB,cAAJ,CACF,+CADE,EAEF,uBAFE,EAGF;QACIhB;MADJ,CAHE,CAAN;IAOH;;IACD,OAAO;MACHiB,KAAK,EAAEzB,qBAAqB,CAACQ,IAAI,CAACP,OAAN,CADzB;MAEHyB,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MADR;IAFR,CAAP;EAMH;;EAEOL,gBAAgB,CACpBf,IADoB,EAEmC;IACvD,IAAI,CAACA,IAAI,CAACP,OAAV,EAAmB;MACf,MAAM,IAAIuB,cAAJ,CACF,+CADE,EAEF,uBAFE,EAGF;QACIhB;MADJ,CAHE,CAAN;IAOH;;IACD,OAAO;MACHiB,KAAK,EAAErB,uBAAuB,CAACI,IAAI,CAACP,OAAN,CAD3B;MAEHyB,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MADR;IAFR,CAAP;EAMH;;AAhEsD"}
1
+ {"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getUrl","locale","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwSettings,\n ApplicationGraphQLGetUrlParams,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n publishedOn\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.headlessCms\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getUrl({ locale }: ApplicationGraphQLGetUrlParams): string {\n return `/cms/manage/${locale}`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAOA;AACA;AACA;AAEA,MAAMA,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,qBAAqB,GAAIC,OAAe,IAAa;EACvD,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAACF,OAAO,CAAC;EAE1C,OAAQ;AACZ,6BAA6BC,cAAe;AAC5C,8BAA8BA,cAAe;AAC7C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAAU;AACV,CAAC;AAED,MAAMK,uBAAuB,GAAIH,OAAe,IAAK;EACjD,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAACF,OAAO,CAAC;EAE1C,OAAQ;AACZ,+BAA+BC,cAAe;AAC9C,gCAAgCA,cAAe;AAC/C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAAU;AACV,CAAC;AAMM,MAAMM,kBAAkB,SAASC,sCAAkB,CAAC;EAAA;IAAA;IAAA,4CAChC,8CAA8C;EAAA;EAErDC,MAAM,CAACC,IAA2B,EAAW;IACzD,OAAOA,IAAI,CAACC,IAAI,KAAKC,sBAAe,CAACC,SAAS;EAClD;EAEgBC,MAAM,CAAC;IAAEC;EAAuC,CAAC,EAAU;IACvE,OAAQ,eAAcA,MAAO,EAAC;EAClC;EAEgBC,MAAM,CAACC,QAAqB,EAAU;IAClD,OAAOA,QAAQ,CAACC,sBAAsB;EAC1C;EAEgBC,cAAc,CAACT,IAA2B,EAAiC;IACvF,QAAQA,IAAI,CAACU,MAAM;MACf,KAAKC,6BAAsB,CAACC,OAAO;QAC/B,OAAO,IAAI,CAACC,cAAc,CAACb,IAAI,CAAC;MACpC,KAAKW,6BAAsB,CAACG,SAAS;QACjC,OAAO,IAAI,CAACC,gBAAgB,CAACf,IAAI,CAAC;MACtC;QACI,OAAO,IAAI;IAAC;EAExB;EAEQa,cAAc,CAClBb,IAA2B,EAC4B;IACvD,IAAI,CAACA,IAAI,CAACP,OAAO,EAAE;MACf,MAAM,IAAIuB,cAAW,CACjB,+CAA+C,EAC/C,uBAAuB,EACvB;QACIhB;MACJ,CAAC,CACJ;IACL;IACA,OAAO;MACHiB,KAAK,EAAEzB,qBAAqB,CAACQ,IAAI,CAACP,OAAO,CAAC;MAC1CyB,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MACnB;IACJ,CAAC;EACL;EAEQL,gBAAgB,CACpBf,IAA2B,EAC4B;IACvD,IAAI,CAACA,IAAI,CAACP,OAAO,EAAE;MACf,MAAM,IAAIuB,cAAW,CACjB,+CAA+C,EAC/C,uBAAuB,EACvB;QACIhB;MACJ,CAAC,CACJ;IACL;IACA,OAAO;MACHiB,KAAK,EAAErB,uBAAuB,CAACI,IAAI,CAACP,OAAO,CAAC;MAC5CyB,SAAS,EAAE;QACPC,QAAQ,EAAEnB,IAAI,CAACoB;MACnB;IACJ,CAAC;EACL;AACJ;AAAC"}
@@ -1,37 +1,26 @@
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.PageBuilderGraphQL = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _ApplicationGraphQL = require("./ApplicationGraphQL");
13
-
14
10
  var _types = require("../../../types");
15
-
16
- const PB_PAGE_DATA_FIELD =
17
- /* GraphQL */
18
- `
11
+ const PB_PAGE_DATA_FIELD = /* GraphQL */`
19
12
  {
20
13
  id
21
14
  }
22
15
  `;
23
- const ERROR_FIELD =
24
- /* GraphQL */
25
- `
16
+ const ERROR_FIELD = /* GraphQL */`
26
17
  {
27
18
  code
28
19
  data
29
20
  message
30
21
  }
31
22
  `;
32
- const PUBLISH_MUTATION =
33
- /* GraphQL */
34
- `
23
+ const PUBLISH_MUTATION = /* GraphQL */`
35
24
  mutation PublishPage($id: ID!) {
36
25
  pageBuilder {
37
26
  publishPage(id: $id) {
@@ -41,9 +30,7 @@ const PUBLISH_MUTATION =
41
30
  }
42
31
  }
43
32
  `;
44
- const UNPUBLISH_MUTATION =
45
- /* GraphQL */
46
- `
33
+ const UNPUBLISH_MUTATION = /* GraphQL */`
47
34
  mutation UnpublishPage($id: ID!) {
48
35
  pageBuilder {
49
36
  unpublishPage(id: $id) {
@@ -53,38 +40,30 @@ const UNPUBLISH_MUTATION =
53
40
  }
54
41
  }
55
42
  `;
56
-
57
43
  class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
58
44
  constructor(...args) {
59
45
  super(...args);
60
46
  (0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.pageBuilder");
61
47
  }
62
-
63
48
  canUse(data) {
64
49
  return data.type === _types.ApwContentTypes.PAGE;
65
50
  }
66
-
67
51
  getUrl() {
68
52
  return `/graphql`;
69
53
  }
70
-
71
54
  getArn(settings) {
72
55
  return settings.mainGraphqlFunctionArn;
73
56
  }
74
-
75
57
  getGraphQLBody(data) {
76
58
  switch (data.action) {
77
59
  case _types.ApwScheduleActionTypes.PUBLISH:
78
60
  return this.getPublishBody(data);
79
-
80
61
  case _types.ApwScheduleActionTypes.UNPUBLISH:
81
62
  return this.getUnpublishBody(data);
82
-
83
63
  default:
84
64
  return null;
85
65
  }
86
66
  }
87
-
88
67
  getPublishBody(data) {
89
68
  return {
90
69
  query: PUBLISH_MUTATION,
@@ -93,7 +72,6 @@ class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
93
72
  }
94
73
  };
95
74
  }
96
-
97
75
  getUnpublishBody(data) {
98
76
  return {
99
77
  query: UNPUBLISH_MUTATION,
@@ -102,7 +80,5 @@ class PageBuilderGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
102
80
  }
103
81
  };
104
82
  }
105
-
106
83
  }
107
-
108
84
  exports.PageBuilderGraphQL = PageBuilderGraphQL;
@@ -1 +1 @@
1
- {"version":3,"names":["PB_PAGE_DATA_FIELD","ERROR_FIELD","PUBLISH_MUTATION","UNPUBLISH_MUTATION","PageBuilderGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","PAGE","getUrl","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","query","variables","id","entryId"],"sources":["PageBuilderGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst PB_PAGE_DATA_FIELD = /* GraphQL */ `\n {\n id\n }\n`;\n\nconst ERROR_FIELD = /* GraphQL */ `\n {\n code\n data\n message\n }\n`;\n\nconst PUBLISH_MUTATION = /* GraphQL */ `\n mutation PublishPage($id: ID!) {\n pageBuilder {\n publishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\nconst UNPUBLISH_MUTATION = /* GraphQL */ `\n mutation UnpublishPage($id: ID!) {\n pageBuilder {\n unpublishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\ninterface ApplicationGraphQLBodyVariables {\n id: string;\n}\n\nexport class PageBuilderGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.PAGE;\n }\n\n public override getUrl(): string {\n return `/graphql`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: PUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: UNPUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AAGA,MAAMA,kBAAkB;AAAG;AAAe;AAC1C;AACA;AACA;AACA,CAJA;AAMA,MAAMC,WAAW;AAAG;AAAe;AACnC;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,gBAAgB;AAAG;AAAe;AACxC;AACA;AACA;AACA,uBAAuBF,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CATA;AAWA,MAAME,kBAAkB;AAAG;AAAe;AAC1C;AACA;AACA;AACA,uBAAuBH,kBAAmB;AAC1C,wBAAwBC,WAAY;AACpC;AACA;AACA;AACA,CATA;;AAeO,MAAMG,kBAAN,SAAiCC,sCAAjC,CAAoD;EAAA;IAAA;IAAA,4CAChC,8CADgC;EAAA;;EAGvCC,MAAM,CAACC,IAAD,EAAuC;IACzD,OAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAA,CAAgBC,IAArC;EACH;;EAEeC,MAAM,GAAW;IAC7B,OAAQ,UAAR;EACH;;EAEeC,MAAM,CAACC,QAAD,EAAgC;IAClD,OAAOA,QAAQ,CAACC,sBAAhB;EACH;;EAEeC,cAAc,CAACR,IAAD,EAA6D;IACvF,QAAQA,IAAI,CAACS,MAAb;MACI,KAAKC,6BAAA,CAAuBC,OAA5B;QACI,OAAO,KAAKC,cAAL,CAAoBZ,IAApB,CAAP;;MACJ,KAAKU,6BAAA,CAAuBG,SAA5B;QACI,OAAO,KAAKC,gBAAL,CAAsBd,IAAtB,CAAP;;MACJ;QACI,OAAO,IAAP;IANR;EAQH;;EAEOY,cAAc,CAClBZ,IADkB,EAEqC;IACvD,OAAO;MACHe,KAAK,EAAEpB,gBADJ;MAEHqB,SAAS,EAAE;QACPC,EAAE,EAAEjB,IAAI,CAACkB;MADF;IAFR,CAAP;EAMH;;EAEOJ,gBAAgB,CACpBd,IADoB,EAEmC;IACvD,OAAO;MACHe,KAAK,EAAEnB,kBADJ;MAEHoB,SAAS,EAAE;QACPC,EAAE,EAAEjB,IAAI,CAACkB;MADF;IAFR,CAAP;EAMH;;AA9CsD"}
1
+ {"version":3,"names":["PB_PAGE_DATA_FIELD","ERROR_FIELD","PUBLISH_MUTATION","UNPUBLISH_MUTATION","PageBuilderGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","PAGE","getUrl","getArn","settings","mainGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","query","variables","id","entryId"],"sources":["PageBuilderGraphQL.ts"],"sourcesContent":["import {\n ApplicationGraphQL,\n ApplicationGraphQLBody,\n ApwScheduleActionData\n} from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst PB_PAGE_DATA_FIELD = /* GraphQL */ `\n {\n id\n }\n`;\n\nconst ERROR_FIELD = /* GraphQL */ `\n {\n code\n data\n message\n }\n`;\n\nconst PUBLISH_MUTATION = /* GraphQL */ `\n mutation PublishPage($id: ID!) {\n pageBuilder {\n publishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\nconst UNPUBLISH_MUTATION = /* GraphQL */ `\n mutation UnpublishPage($id: ID!) {\n pageBuilder {\n unpublishPage(id: $id) {\n data ${PB_PAGE_DATA_FIELD}\n error ${ERROR_FIELD}\n }\n }\n }\n`;\n\ninterface ApplicationGraphQLBodyVariables {\n id: string;\n}\n\nexport class PageBuilderGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.PAGE;\n }\n\n public override getUrl(): string {\n return `/graphql`;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.mainGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: PUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n return {\n query: UNPUBLISH_MUTATION,\n variables: {\n id: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAKA;AAGA,MAAMA,kBAAkB,GAAG,aAAe;AAC1C;AACA;AACA;AACA,CAAC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ports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createCustomAuth = void 0;
7
-
8
7
  var _api = require("@webiny/api");
9
-
10
8
  var _utils = require("../utils");
11
-
12
9
  const createCustomAuth = ({
13
10
  storageOperations
14
11
  }) => {
@@ -20,7 +17,6 @@ const createCustomAuth = ({
20
17
  if (!token.startsWith(_utils.TOKEN_PREFIX)) {
21
18
  return null;
22
19
  }
23
-
24
20
  const {
25
21
  id,
26
22
  tenant,
@@ -29,15 +25,12 @@ const createCustomAuth = ({
29
25
  /**
30
26
  * No point in going further if any piece of information is missing.
31
27
  */
32
-
33
28
  if (!id || !tenant || !locale) {
34
29
  return null;
35
30
  }
36
31
  /**
37
32
  * We must verify that action we are trying to execute actually exists.
38
33
  */
39
-
40
-
41
34
  const item = await storageOperations.get({
42
35
  where: {
43
36
  id,
@@ -45,11 +38,9 @@ const createCustomAuth = ({
45
38
  locale
46
39
  }
47
40
  });
48
-
49
41
  if (!item) {
50
42
  return null;
51
43
  }
52
-
53
44
  hasApwToken = true;
54
45
  return item.createdBy;
55
46
  });
@@ -57,12 +48,10 @@ const createCustomAuth = ({
57
48
  if (!hasApwToken) {
58
49
  return null;
59
50
  }
60
-
61
51
  return [{
62
52
  name: "*"
63
53
  }];
64
54
  });
65
55
  });
66
56
  };
67
-
68
57
  exports.createCustomAuth = createCustomAuth;
@@ -1 +1 @@
1
- {"version":3,"names":["createCustomAuth","storageOperations","ContextPlugin","security","hasApwToken","addAuthenticator","token","startsWith","TOKEN_PREFIX","id","tenant","locale","decodeToken","item","get","where","createdBy","addAuthorizer","name"],"sources":["security.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { decodeToken, TOKEN_PREFIX } from \"~/scheduler/handlers/utils\";\nimport { ApwContext } from \"~/types\";\n\nexport const createCustomAuth = ({ storageOperations }: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(({ security }) => {\n let hasApwToken = false;\n\n security.addAuthenticator(async token => {\n if (!token.startsWith(TOKEN_PREFIX)) {\n return null;\n }\n\n const { id, tenant, locale } = decodeToken(token);\n /**\n * No point in going further if any piece of information is missing.\n */\n if (!id || !tenant || !locale) {\n return null;\n }\n /**\n * We must verify that action we are trying to execute actually exists.\n */\n const item = await storageOperations.get({\n where: {\n id,\n tenant,\n locale\n }\n });\n\n if (!item) {\n return null;\n }\n\n hasApwToken = true;\n\n return item.createdBy;\n });\n\n security.addAuthorizer(async () => {\n if (!hasApwToken) {\n return null;\n }\n return [{ name: \"*\" }];\n });\n });\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAGO,MAAMA,gBAAgB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAmD;EAC/E,OAAO,IAAIC,kBAAJ,CAA8B,CAAC;IAAEC;EAAF,CAAD,KAAkB;IACnD,IAAIC,WAAW,GAAG,KAAlB;IAEAD,QAAQ,CAACE,gBAAT,CAA0B,MAAMC,KAAN,IAAe;MACrC,IAAI,CAACA,KAAK,CAACC,UAAN,CAAiBC,mBAAjB,CAAL,EAAqC;QACjC,OAAO,IAAP;MACH;;MAED,MAAM;QAAEC,EAAF;QAAMC,MAAN;QAAcC;MAAd,IAAyB,IAAAC,kBAAA,EAAYN,KAAZ,CAA/B;MACA;AACZ;AACA;;MACY,IAAI,CAACG,EAAD,IAAO,CAACC,MAAR,IAAkB,CAACC,MAAvB,EAA+B;QAC3B,OAAO,IAAP;MACH;MACD;AACZ;AACA;;;MACY,MAAME,IAAI,GAAG,MAAMZ,iBAAiB,CAACa,GAAlB,CAAsB;QACrCC,KAAK,EAAE;UACHN,EADG;UAEHC,MAFG;UAGHC;QAHG;MAD8B,CAAtB,CAAnB;;MAQA,IAAI,CAACE,IAAL,EAAW;QACP,OAAO,IAAP;MACH;;MAEDT,WAAW,GAAG,IAAd;MAEA,OAAOS,IAAI,CAACG,SAAZ;IACH,CA9BD;IAgCAb,QAAQ,CAACc,aAAT,CAAuB,YAAY;MAC/B,IAAI,CAACb,WAAL,EAAkB;QACd,OAAO,IAAP;MACH;;MACD,OAAO,CAAC;QAAEc,IAAI,EAAE;MAAR,CAAD,CAAP;IACH,CALD;EAMH,CAzCM,CAAP;AA0CH,CA3CM"}
1
+ {"version":3,"names":["createCustomAuth","storageOperations","ContextPlugin","security","hasApwToken","addAuthenticator","token","startsWith","TOKEN_PREFIX","id","tenant","locale","decodeToken","item","get","where","createdBy","addAuthorizer","name"],"sources":["security.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { decodeToken, TOKEN_PREFIX } from \"~/scheduler/handlers/utils\";\nimport { ApwContext } from \"~/types\";\n\nexport const createCustomAuth = ({ storageOperations }: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(({ security }) => {\n let hasApwToken = false;\n\n security.addAuthenticator(async token => {\n if (!token.startsWith(TOKEN_PREFIX)) {\n return null;\n }\n\n const { id, tenant, locale } = decodeToken(token);\n /**\n * No point in going further if any piece of information is missing.\n */\n if (!id || !tenant || !locale) {\n return null;\n }\n /**\n * We must verify that action we are trying to execute actually exists.\n */\n const item = await storageOperations.get({\n where: {\n id,\n tenant,\n locale\n }\n });\n\n if (!item) {\n return null;\n }\n\n hasApwToken = true;\n\n return item.createdBy;\n });\n\n security.addAuthorizer(async () => {\n if (!hasApwToken) {\n return null;\n }\n return [{ name: \"*\" }];\n });\n });\n};\n"],"mappings":";;;;;;AAAA;AAEA;AAGO,MAAMA,gBAAgB,GAAG,CAAC;EAAEC;AAA0C,CAAC,KAAK;EAC/E,OAAO,IAAIC,kBAAa,CAAa,CAAC;IAAEC;EAAS,CAAC,KAAK;IACnD,IAAIC,WAAW,GAAG,KAAK;IAEvBD,QAAQ,CAACE,gBAAgB,CAAC,MAAMC,KAAK,IAAI;MACrC,IAAI,CAACA,KAAK,CAACC,UAAU,CAACC,mBAAY,CAAC,EAAE;QACjC,OAAO,IAAI;MACf;MAEA,MAAM;QAAEC,EAAE;QAAEC,MAAM;QAAEC;MAAO,CAAC,GAAG,IAAAC,kBAAW,EAACN,KAAK,CAAC;MACjD;AACZ;AACA;MACY,IAAI,CAACG,EAAE,IAAI,CAACC,MAAM,IAAI,CAACC,MAAM,EAAE;QAC3B,OAAO,IAAI;MACf;MACA;AACZ;AACA;MACY,MAAME,IAAI,GAAG,MAAMZ,iBAAiB,CAACa,GAAG,CAAC;QACrCC,KAAK,EAAE;UACHN,EAAE;UACFC,MAAM;UACNC;QACJ;MACJ,CAAC,CAAC;MAEF,IAAI,CAACE,IAAI,EAAE;QACP,OAAO,IAAI;MACf;MAEAT,WAAW,GAAG,IAAI;MAElB,OAAOS,IAAI,CAACG,SAAS;IACzB,CAAC,CAAC;IAEFb,QAAQ,CAACc,aAAa,CAAC,YAAY;MAC/B,IAAI,CAACb,WAAW,EAAE;QACd,OAAO,IAAI;MACf;MACA,OAAO,CAAC;QAAEc,IAAI,EAAE;MAAI,CAAC,CAAC;IAC1B,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -19,4 +19,4 @@ export interface Configuration {
19
19
  executeAction: string;
20
20
  };
21
21
  }
22
- export declare const scheduleActionHandlerPlugins: (config: Configuration) => ((import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any>)[];
22
+ export declare const scheduleActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any>)[];