@webiny/api-apw 0.0.0-unstable.8c4d9f045a → 0.0.0-unstable.8feaff8c32

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 (248) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +30 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +30 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +30 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +30 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +1 -6
  14. package/ContentApwSettingsPlugin.js.map +1 -1
  15. package/crud/createChangeRequestMethods.js +21 -25
  16. package/crud/createChangeRequestMethods.js.map +1 -1
  17. package/crud/createCommentMethods.js +21 -26
  18. package/crud/createCommentMethods.js.map +1 -1
  19. package/crud/createContentReviewMethods.js +89 -128
  20. package/crud/createContentReviewMethods.js.map +1 -1
  21. package/crud/createReviewerMethods.js +21 -26
  22. package/crud/createReviewerMethods.js.map +1 -1
  23. package/crud/createWorkflowMethods.d.ts +1 -1
  24. package/crud/createWorkflowMethods.js +37 -28
  25. package/crud/createWorkflowMethods.js.map +1 -1
  26. package/crud/index.js +3 -32
  27. package/crud/index.js.map +1 -1
  28. package/crud/utils.js +4 -36
  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 -46
  34. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +1 -16
  35. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  36. package/plugins/cms/apwEntryPlugins.js +4 -16
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  38. package/plugins/cms/index.js +5 -10
  39. package/plugins/cms/index.js.map +1 -1
  40. package/plugins/cms/linkContentReviewToEntry.js +6 -23
  41. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  42. package/plugins/cms/linkWorkflowToEntry.js +14 -43
  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 +31 -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 +31 -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 +31 -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 +53 -0
  55. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  56. package/plugins/cms/triggerContentReview.js +6 -20
  57. package/plugins/cms/triggerContentReview.js.map +1 -1
  58. package/plugins/cms/updateContentReviewStatus.js +14 -36
  59. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  60. package/plugins/cms/utils.js +6 -55
  61. package/plugins/cms/utils.js.map +1 -1
  62. package/plugins/context.d.ts +0 -1
  63. package/plugins/context.js +3 -48
  64. package/plugins/context.js.map +1 -1
  65. package/plugins/graphql/changeRequest.gql.js +4 -11
  66. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  67. package/plugins/graphql/comment.gql.js +4 -11
  68. package/plugins/graphql/comment.gql.js.map +1 -1
  69. package/plugins/graphql/contentReview.gql.js +10 -29
  70. package/plugins/graphql/contentReview.gql.js.map +1 -1
  71. package/plugins/graphql/reviewer.gql.js +6 -11
  72. package/plugins/graphql/reviewer.gql.js.map +1 -1
  73. package/plugins/graphql/workflow.gql.js +4 -11
  74. package/plugins/graphql/workflow.gql.js.map +1 -1
  75. package/plugins/graphql.js +4 -19
  76. package/plugins/graphql.js.map +1 -1
  77. package/plugins/hooks/createReviewerFromIdentity.js +26 -15
  78. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  79. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +2 -10
  80. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  81. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +2 -9
  82. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  83. package/plugins/hooks/index.js +4 -12
  84. package/plugins/hooks/index.js.map +1 -1
  85. package/plugins/hooks/initializeContentReviewSteps.js +15 -25
  86. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  87. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  88. package/plugins/hooks/initializeNotifications.js +15 -0
  89. package/plugins/hooks/initializeNotifications.js.map +1 -0
  90. package/plugins/hooks/listContentReviews.d.ts +10 -0
  91. package/plugins/hooks/listContentReviews.js +56 -0
  92. package/plugins/hooks/listContentReviews.js.map +1 -0
  93. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  94. package/plugins/hooks/notifications/appUrl.js +18 -0
  95. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  96. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  97. package/plugins/hooks/notifications/changeRequestAfterCreate.js +111 -0
  98. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  99. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  100. package/plugins/hooks/notifications/changeRequestUrl.js +27 -0
  101. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  102. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  103. package/plugins/hooks/notifications/commentAfterCreate.js +122 -0
  104. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  105. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  106. package/plugins/hooks/notifications/commentUrl.js +27 -0
  107. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  108. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  109. package/plugins/hooks/notifications/contentReviewAfterCreate.js +94 -0
  110. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  111. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  112. package/plugins/hooks/notifications/contentReviewUrl.js +26 -0
  113. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  114. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  115. package/plugins/hooks/notifications/contentUrl.js +24 -0
  116. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  117. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  118. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +21 -0
  119. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  120. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  121. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +21 -0
  122. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  123. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  124. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +21 -0
  125. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  126. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  127. package/plugins/hooks/notifications/reviewers.js +45 -0
  128. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  129. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  130. package/plugins/hooks/notifications/sendChangeRequestNotification.js +41 -0
  131. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  132. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  133. package/plugins/hooks/notifications/sendCommentNotification.js +41 -0
  134. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  135. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  136. package/plugins/hooks/notifications/sendContentReviewNotification.js +41 -0
  137. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  138. package/plugins/hooks/updatePendingChangeRequests.js +7 -19
  139. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  140. package/plugins/hooks/updateTotalComments.js +14 -27
  141. package/plugins/hooks/updateTotalComments.js.map +1 -1
  142. package/plugins/hooks/validateChangeRequest.js +27 -18
  143. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  144. package/plugins/hooks/validateComment.js +13 -14
  145. package/plugins/hooks/validateComment.js.map +1 -1
  146. package/plugins/hooks/validateContentReview.js +2 -8
  147. package/plugins/hooks/validateContentReview.js.map +1 -1
  148. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +1 -16
  149. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  150. package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
  151. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  152. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
  153. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  154. package/plugins/pageBuilder/index.js +5 -8
  155. package/plugins/pageBuilder/index.js.map +1 -1
  156. package/plugins/pageBuilder/linkContentReviewToPage.js +38 -42
  157. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  158. package/plugins/pageBuilder/linkWorkflowToPage.js +14 -32
  159. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  160. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  161. package/plugins/pageBuilder/notifications/changeRequestNotification.js +31 -0
  162. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  163. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  164. package/plugins/pageBuilder/notifications/commentNotification.js +31 -0
  165. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  166. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  167. package/plugins/pageBuilder/notifications/contentReviewNotification.js +31 -0
  168. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  169. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  170. package/plugins/pageBuilder/notifications/contentUrl.js +47 -0
  171. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  172. package/plugins/pageBuilder/triggerContentReview.js +3 -14
  173. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  174. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -26
  175. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  176. package/plugins/pageBuilder/utils.js +2 -36
  177. package/plugins/pageBuilder/utils.js.map +1 -1
  178. package/plugins/utils.d.ts +1 -1
  179. package/plugins/utils.js +4 -57
  180. package/plugins/utils.js.map +1 -1
  181. package/scheduler/createScheduleActionMethods.js +15 -36
  182. package/scheduler/createScheduleActionMethods.js.map +1 -1
  183. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  184. package/scheduler/handlers/executeAction/index.js +45 -39
  185. package/scheduler/handlers/executeAction/index.js.map +1 -1
  186. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
  187. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +15 -6
  188. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  189. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
  190. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +8 -24
  191. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  192. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
  193. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +8 -87
  194. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  195. package/scheduler/handlers/executeAction/security.js +0 -11
  196. package/scheduler/handlers/executeAction/security.js.map +1 -1
  197. package/scheduler/handlers/scheduleAction/index.js +21 -38
  198. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  199. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +9 -32
  200. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  201. package/scheduler/handlers/utils.d.ts +0 -1
  202. package/scheduler/handlers/utils.js +4 -42
  203. package/scheduler/handlers/utils.js.map +1 -1
  204. package/scheduler/index.js +0 -3
  205. package/scheduler/index.js.map +1 -1
  206. package/scheduler/types.d.ts +2 -20
  207. package/scheduler/types.js +12 -23
  208. package/scheduler/types.js.map +1 -1
  209. package/storageOperations/changeRequestStorageOperations.js +22 -45
  210. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  211. package/storageOperations/commentStorageOperations.js +25 -50
  212. package/storageOperations/commentStorageOperations.js.map +1 -1
  213. package/storageOperations/contentReviewStorageOperations.js +22 -43
  214. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  215. package/storageOperations/index.js +5 -23
  216. package/storageOperations/index.js.map +1 -1
  217. package/storageOperations/models/changeRequest.model.js +0 -9
  218. package/storageOperations/models/changeRequest.model.js.map +1 -1
  219. package/storageOperations/models/comment.model.js +0 -8
  220. package/storageOperations/models/comment.model.js.map +1 -1
  221. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
  222. package/storageOperations/models/contentModelPluginFactory.js +5 -17
  223. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  224. package/storageOperations/models/contentReview.model.js +6 -31
  225. package/storageOperations/models/contentReview.model.js.map +1 -1
  226. package/storageOperations/models/index.js +3 -29
  227. package/storageOperations/models/index.js.map +1 -1
  228. package/storageOperations/models/reviewer.model.js +17 -9
  229. package/storageOperations/models/reviewer.model.js.map +1 -1
  230. package/storageOperations/models/utils.js +3 -6
  231. package/storageOperations/models/utils.js.map +1 -1
  232. package/storageOperations/models/workflow.model.js +0 -23
  233. package/storageOperations/models/workflow.model.js.map +1 -1
  234. package/storageOperations/reviewerStorageOperations.js +22 -40
  235. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  236. package/storageOperations/workflowStorageOperations.js +25 -48
  237. package/storageOperations/workflowStorageOperations.js.map +1 -1
  238. package/types.d.ts +104 -88
  239. package/types.js +124 -42
  240. package/types.js.map +1 -1
  241. package/utils/contentApwSettingsPlugin.js +0 -6
  242. package/utils/contentApwSettingsPlugin.js.map +1 -1
  243. package/utils/errors.js +1 -18
  244. package/utils/errors.js.map +1 -1
  245. package/utils/fieldResolver.js +5 -21
  246. package/utils/fieldResolver.js.map +1 -1
  247. package/utils/resolve.js +0 -3
  248. package/utils/resolve.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["log","console","scheduleLambdaExecution","cloudWatchEventClient","invokedFunctionArn","datetime","futureDatetime","tenant","locale","eventTargetId","eventRuleName","getApwSettings","removeTargetsCommand","RemoveTargetsCommand","Rule","Ids","removeTargetsResponse","send","FailedEntryCount","info","FailedEntries","deleteRuleCommand","DeleteRuleCommand","Name","cronExpression","dateTimeToCronExpression","ruleParams","ScheduleExpression","State","Description","PutRuleCommand","PutTargetsCommand","Targets","Arn","Id","Input","JSON","stringify","invocationType","InvocationTypes","SCHEDULED","shouldScheduleTask","nextTaskDatetime","currentTaskDatetime","restoreDateTime","task","currentTask","storageOperations","id","item","get","where","newDateTime","moveDateTimeToCurrentCentury","data","update","input","executeTask","args","lambdaName","handlerClient","Date","toISOString","invoke","name","payload","await","deleteCurrentTask","e","error"],"sources":["scheduleAction.utils.ts"],"sourcesContent":["import { dateTimeToCronExpression, moveDateTimeToCurrentCentury } from \"~/scheduler/handlers/utils\";\nimport { ApwScheduleAction } from \"~/scheduler/types\";\nimport {\n HandlerArgs,\n InvocationTypes,\n Configuration\n} from \"~/scheduler/handlers/scheduleAction/index\";\nimport {\n DeleteRuleCommand,\n RemoveTargetsCommand,\n PutTargetsCommand,\n PutRuleCommand\n} from \"@aws-sdk/client-cloudwatch-events\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst log = console.log;\n\ninterface ScheduleLambdaExecutionParams extends Omit<HandlerArgs, \"invocationType\"> {\n cloudWatchEventClient: any;\n invokedFunctionArn: string;\n}\n\n/**\n * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;\n * in case of scheduling becoming the most frequently used feature.\n * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/\n */\nexport async function scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn,\n datetime,\n futureDatetime,\n tenant,\n locale\n}: ScheduleLambdaExecutionParams) {\n const { eventTargetId, eventRuleName } = await getApwSettings();\n /**\n * Remove the target\n */\n const removeTargetsCommand = new RemoveTargetsCommand({\n Rule: eventRuleName,\n Ids: [eventTargetId]\n });\n const removeTargetsResponse = await cloudWatchEventClient.send(removeTargetsCommand);\n /**\n * Log error.\n */\n if (\n typeof removeTargetsResponse.FailedEntryCount === \"number\" &&\n removeTargetsResponse.FailedEntryCount !== 0\n ) {\n console.info(\"Failed in removing the targets!\");\n console.info(removeTargetsResponse.FailedEntries);\n }\n /**\n * Delete the Rule\n */\n const deleteRuleCommand = new DeleteRuleCommand({\n Name: eventRuleName\n });\n await cloudWatchEventClient.send(deleteRuleCommand);\n\n /**\n * Create a new one.\n * Min H D M DW Y\n * 20 10 10 03 * 2022\n */\n const cronExpression = dateTimeToCronExpression(datetime);\n\n const ruleParams = {\n Name: eventRuleName,\n ScheduleExpression: `cron(${cronExpression})`,\n State: \"ENABLED\",\n Description: `Enable us to schedule an action in publishing workflow at a particular datetime`\n };\n\n await cloudWatchEventClient.send(new PutRuleCommand(ruleParams));\n /**\n * Add lambda as target for the rule.\n */\n await cloudWatchEventClient.send(\n new PutTargetsCommand({\n Rule: eventRuleName,\n Targets: [\n {\n Arn: invokedFunctionArn,\n Id: eventTargetId,\n Input: JSON.stringify({\n datetime: datetime,\n tenant: tenant,\n locale: locale,\n invocationType: InvocationTypes.SCHEDULED,\n futureDatetime: futureDatetime\n } as HandlerArgs)\n }\n ]\n })\n );\n}\n\nexport const shouldScheduleTask = (\n nextTaskDatetime: string,\n currentTaskDatetime: string | null\n): boolean => {\n return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;\n};\n\ninterface RestoreDateTimeParams\n extends Pick<Configuration, \"storageOperations\">,\n Pick<HandlerArgs, \"tenant\" | \"locale\"> {\n task: ApwScheduleAction;\n}\n\nexport const restoreDateTime = async ({\n locale,\n tenant,\n task: currentTask,\n storageOperations\n}: RestoreDateTimeParams): Promise<void> => {\n log(`Mark task \"${currentTask.id}\" as undone by restoring original \"datetime\".`);\n const item = await storageOperations.get({\n where: {\n tenant,\n locale,\n id: currentTask.id\n }\n });\n if (item) {\n const newDateTime = moveDateTimeToCurrentCentury(item.data.datetime);\n await storageOperations.update({\n item: {\n ...item,\n data: { ...item.data, datetime: newDateTime }\n },\n input: { ...item.data, datetime: newDateTime }\n });\n }\n};\n\ninterface ExecuteTaskParams\n extends Pick<ClientContext, \"handlerClient\">,\n Pick<Configuration, \"storageOperations\"> {\n args: HandlerArgs;\n lambdaName: string;\n}\n\nexport const executeTask = async ({\n args,\n lambdaName,\n handlerClient,\n storageOperations\n}: ExecuteTaskParams): Promise<void> => {\n log(`Executing task at: `, new Date().toISOString());\n\n if (typeof handlerClient.invoke === \"function\") {\n await handlerClient.invoke({\n name: lambdaName,\n payload: {\n futureDatetime: args.futureDatetime,\n datetime: args.datetime,\n tenant: args.tenant,\n locale: args.locale\n },\n await: false\n });\n }\n\n /**\n * Delete current schedule Task. So that, we can schedule a new one later.\n */\n try {\n await storageOperations.deleteCurrentTask({\n tenant: args.tenant,\n locale: args.locale\n });\n } catch (e) {\n console.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AAE+C;QAA5B;MAFJ,EADuB;MAK3BI,KAAK,kCAAOP,IAAI,CAACK,IAAZ;QAAkBjD,QAAQ,EAAE+C;MAA5B;IALsB,CAAzB,CAAN;EAOH;AACJ,CAxBM;;;;AAiCA,MAAMK,WAAW,GAAG,OAAO;EAC9BC,IAD8B;EAE9BC,UAF8B;EAG9BC,aAH8B;EAI9Bb;AAJ8B,CAAP,KAKa;EACpC/C,GAAG,CAAE,qBAAF,EAAwB,IAAI6D,IAAJ,GAAWC,WAAX,EAAxB,CAAH;;EAEA,IAAI,OAAOF,aAAa,CAACG,MAArB,KAAgC,UAApC,EAAgD;IAC5C,MAAMH,aAAa,CAACG,MAAd,CAAqB;MACvBC,IAAI,EAAEL,UADiB;MAEvBM,OAAO,EAAE;QACL3D,cAAc,EAAEoD,IAAI,CAACpD,cADhB;QAELD,QAAQ,EAAEqD,IAAI,CAACrD,QAFV;QAGLE,MAAM,EAAEmD,IAAI,CAACnD,MAHR;QAILC,MAAM,EAAEkD,IAAI,CAAClD;MAJR,CAFc;MAQvB0D,KAAK,EAAE;IARgB,CAArB,CAAN;EAUH;EAED;AACJ;AACA;;;EACI,IAAI;IACA,MAAMnB,iBAAiB,CAACoB,iBAAlB,CAAoC;MACtC5D,MAAM,EAAEmD,IAAI,CAACnD,MADyB;MAEtCC,MAAM,EAAEkD,IAAI,CAAClD;IAFyB,CAApC,CAAN;EAIH,CALD,CAKE,OAAO4D,CAAP,EAAU;IACRnE,OAAO,CAACoE,KAAR,CAAcD,CAAd;EACH;AACJ,CAhCM"}
1
+ {"version":3,"names":["_utils","require","_index","_clientCloudwatchEvents","log","console","scheduleLambdaExecution","cloudWatchEventClient","invokedFunctionArn","datetime","futureDatetime","tenant","locale","eventTargetId","eventRuleName","getApwSettings","removeTargetsCommand","RemoveTargetsCommand","Rule","Ids","removeTargetsResponse","send","FailedEntryCount","info","FailedEntries","deleteRuleCommand","DeleteRuleCommand","Name","cronExpression","dateTimeToCronExpression","ruleParams","ScheduleExpression","State","Description","PutRuleCommand","PutTargetsCommand","Targets","Arn","Id","Input","JSON","stringify","invocationType","InvocationTypes","SCHEDULED","shouldScheduleTask","nextTaskDatetime","currentTaskDatetime","exports","restoreDateTime","task","currentTask","storageOperations","id","item","get","where","newDateTime","moveDateTimeToCurrentCentury","data","update","_objectSpread2","default","input","executeTask","args","lambdaName","handlerClient","Date","toISOString","invoke","name","payload","await","deleteCurrentTask","e","error"],"sources":["scheduleAction.utils.ts"],"sourcesContent":["import { dateTimeToCronExpression, moveDateTimeToCurrentCentury } from \"~/scheduler/handlers/utils\";\nimport { ApwScheduleAction } from \"~/scheduler/types\";\nimport {\n HandlerArgs,\n InvocationTypes,\n Configuration\n} from \"~/scheduler/handlers/scheduleAction/index\";\nimport {\n DeleteRuleCommand,\n RemoveTargetsCommand,\n PutTargetsCommand,\n PutRuleCommand\n} from \"@aws-sdk/client-cloudwatch-events\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst log = console.log;\n\ninterface ScheduleLambdaExecutionParams extends Omit<HandlerArgs, \"invocationType\"> {\n cloudWatchEventClient: any;\n invokedFunctionArn: string;\n}\n\n/**\n * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;\n * in case of scheduling becoming the most frequently used feature.\n * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/\n */\nexport async function scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn,\n datetime,\n futureDatetime,\n tenant,\n locale\n}: ScheduleLambdaExecutionParams) {\n const { eventTargetId, eventRuleName } = await getApwSettings();\n /**\n * Remove the target\n */\n const removeTargetsCommand = new RemoveTargetsCommand({\n Rule: eventRuleName,\n Ids: [eventTargetId]\n });\n const removeTargetsResponse = await cloudWatchEventClient.send(removeTargetsCommand);\n /**\n * Log error.\n */\n if (\n typeof removeTargetsResponse.FailedEntryCount === \"number\" &&\n removeTargetsResponse.FailedEntryCount !== 0\n ) {\n console.info(\"Failed in removing the targets!\");\n console.info(removeTargetsResponse.FailedEntries);\n }\n /**\n * Delete the Rule\n */\n const deleteRuleCommand = new DeleteRuleCommand({\n Name: eventRuleName\n });\n await cloudWatchEventClient.send(deleteRuleCommand);\n\n /**\n * Create a new one.\n * Min H D M DW Y\n * 20 10 10 03 * 2022\n */\n const cronExpression = dateTimeToCronExpression(datetime);\n\n const ruleParams = {\n Name: eventRuleName,\n ScheduleExpression: `cron(${cronExpression})`,\n State: \"ENABLED\",\n Description: `Enable us to schedule an action in publishing workflow at a particular datetime`\n };\n\n await cloudWatchEventClient.send(new PutRuleCommand(ruleParams));\n /**\n * Add lambda as target for the rule.\n */\n await cloudWatchEventClient.send(\n new PutTargetsCommand({\n Rule: eventRuleName,\n Targets: [\n {\n Arn: invokedFunctionArn,\n Id: eventTargetId,\n Input: JSON.stringify({\n datetime: datetime,\n tenant: tenant,\n locale: locale,\n invocationType: InvocationTypes.SCHEDULED,\n futureDatetime: futureDatetime\n } as HandlerArgs)\n }\n ]\n })\n );\n}\n\nexport const shouldScheduleTask = (\n nextTaskDatetime: string,\n currentTaskDatetime: string | null\n): boolean => {\n return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;\n};\n\ninterface RestoreDateTimeParams\n extends Pick<Configuration, \"storageOperations\">,\n Pick<HandlerArgs, \"tenant\" | \"locale\"> {\n task: ApwScheduleAction;\n}\n\nexport const restoreDateTime = async ({\n locale,\n tenant,\n task: currentTask,\n storageOperations\n}: RestoreDateTimeParams): Promise<void> => {\n log(`Mark task \"${currentTask.id}\" as undone by restoring original \"datetime\".`);\n const item = await storageOperations.get({\n where: {\n tenant,\n locale,\n id: currentTask.id\n }\n });\n if (item) {\n const newDateTime = moveDateTimeToCurrentCentury(item.data.datetime);\n await storageOperations.update({\n item: {\n ...item,\n data: { ...item.data, datetime: newDateTime }\n },\n input: { ...item.data, datetime: newDateTime }\n });\n }\n};\n\ninterface ExecuteTaskParams\n extends Pick<ClientContext, \"handlerClient\">,\n Pick<Configuration, \"storageOperations\"> {\n args: HandlerArgs;\n lambdaName: string;\n}\n\nexport const executeTask = async ({\n args,\n lambdaName,\n handlerClient,\n storageOperations\n}: ExecuteTaskParams): Promise<void> => {\n log(`Executing task at: `, new Date().toISOString());\n\n if (typeof handlerClient.invoke === \"function\") {\n await handlerClient.invoke({\n name: lambdaName,\n payload: {\n futureDatetime: args.futureDatetime,\n datetime: args.datetime,\n tenant: args.tenant,\n locale: args.locale\n },\n await: false\n });\n } else {\n console.log(`context.handlerClient.invoke is not a function!`);\n }\n\n /**\n * Delete current schedule Task. So that, we can schedule a new one later.\n */\n try {\n await storageOperations.deleteCurrentTask({\n tenant: args.tenant,\n locale: args.locale\n });\n } catch (e) {\n console.error(e);\n }\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,uBAAA,GAAAF,OAAA;AASA,MAAMG,GAAG,GAAGC,OAAO,CAACD,GAAG;AAOvB;AACA;AACA;AACA;AACA;AACO,eAAeE,uBAAuBA,CAAC;EAC1CC,qBAAqB;EACrBC,kBAAkB;EAClBC,QAAQ;EACRC,cAAc;EACdC,MAAM;EACNC;AAC2B,CAAC,EAAE;EAC9B,MAAM;IAAEC,aAAa;IAAEC;EAAc,CAAC,GAAG,MAAM,IAAAC,qBAAc,EAAC,CAAC;EAC/D;AACJ;AACA;EACI,MAAMC,oBAAoB,GAAG,IAAIC,4CAAoB,CAAC;IAClDC,IAAI,EAAEJ,aAAa;IACnBK,GAAG,EAAE,CAACN,aAAa;EACvB,CAAC,CAAC;EACF,MAAMO,qBAAqB,GAAG,MAAMb,qBAAqB,CAACc,IAAI,CAACL,oBAAoB,CAAC;EACpF;AACJ;AACA;EACI,IACI,OAAOI,qBAAqB,CAACE,gBAAgB,KAAK,QAAQ,IAC1DF,qBAAqB,CAACE,gBAAgB,KAAK,CAAC,EAC9C;IACEjB,OAA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,EAAEwD,IAAI,CAACxD,QAAQ;QACvBE,MAAM,EAAEsD,IAAI,CAACtD,MAAM;QACnBC,MAAM,EAAEqD,IAAI,CAACrD;MACjB,CAAC;MACD6D,KAAK,EAAE;IACX,CAAC,CAAC;EACN,CAAC,MAAM;IACHpE,OAAO,CAACD,GAAG,CAAE,iDAAgD,CAAC;EAClE;;EAEA;AACJ;AACA;EACI,IAAI;IACA,MAAMgD,iBAAiB,CAACsB,iBAAiB,CAAC;MACtC/D,MAAM,EAAEsD,IAAI,CAACtD,MAAM;MACnBC,MAAM,EAAEqD,IAAI,CAACrD;IACjB,CAAC,CAAC;EACN,CAAC,CAAC,OAAO+D,CAAC,EAAE;IACRtE,OAAO,CAACuE,KAAK,CAACD,CAAC,CAAC;EACpB;AACJ,CAAC;AAAC3B,OAAA,CAAAgB,WAAA,GAAAA,WAAA"}
@@ -25,7 +25,6 @@ export declare const basePlugins: () => (import("@webiny/handler").HandlerResult
25
25
  */
26
26
  export interface ApwSettings {
27
27
  mainGraphqlFunctionArn: string;
28
- cmsGraphqlFunctionArn: string;
29
28
  eventRuleName: string;
30
29
  eventTargetId: string;
31
30
  }
@@ -1,51 +1,36 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.shouldRestoreDatetime = exports.moveDateTimeToNextCentury = exports.moveDateTimeToCurrentCentury = exports.isDateTimeInNextCentury = exports.getIsoStringTillMinutes = exports.getApwSettings = exports.encodeToken = exports.documentClient = exports.decodeToken = exports.dateTimeToCronExpression = exports.basePlugins = exports.TOKEN_PREFIX = void 0;
9
-
10
8
  var _dayjs = _interopRequireDefault(require("dayjs"));
11
-
12
9
  var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
13
-
14
10
  var _dynamodb = require("aws-sdk/clients/dynamodb");
15
-
16
11
  var _handlerDb = _interopRequireDefault(require("@webiny/handler-db"));
17
-
18
12
  var _dbDynamodb = require("@webiny/db-dynamodb");
19
-
20
13
  var _plugins = _interopRequireDefault(require("@webiny/db-dynamodb/plugins"));
21
-
22
14
  var _handlerLogs = _interopRequireDefault(require("@webiny/handler-logs"));
23
-
24
15
  var _types = require("../types");
25
-
26
16
  /**
27
17
  * https://day.js.org/docs/en/plugin/utc
28
18
  */
29
19
  _dayjs.default.extend(_utc.default);
30
-
31
20
  const TIME_SEPARATOR = ":";
32
21
  const ELAPSED_CRON_EXPRESSION = "* * * * ? 2000";
33
-
34
22
  const getIsoStringTillMinutes = datetime => {
35
23
  /**
36
24
  * Validate datetime.
37
25
  */
38
26
  if (isNaN(Date.parse(datetime))) {
39
27
  return datetime;
40
- } // input = "2022-03-08T05:41:13.230Z"
28
+ }
29
+ // input = "2022-03-08T05:41:13.230Z"
41
30
  // output = "2022-03-08T05:41"
42
-
43
-
44
31
  return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));
45
32
  };
46
-
47
33
  exports.getIsoStringTillMinutes = getIsoStringTillMinutes;
48
-
49
34
  const dateTimeToCronExpression = datetime => {
50
35
  if (!datetime) {
51
36
  return ELAPSED_CRON_EXPRESSION;
@@ -56,32 +41,22 @@ const dateTimeToCronExpression = datetime => {
56
41
  *
57
42
  * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
58
43
  */
59
-
60
-
61
44
  const dayOfWeek = "?";
62
45
  return _dayjs.default.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);
63
46
  };
64
-
65
47
  exports.dateTimeToCronExpression = dateTimeToCronExpression;
66
-
67
48
  const moveDateTimeToNextCentury = datetime => {
68
49
  return _dayjs.default.utc(datetime).add(100, "year").toISOString();
69
50
  };
70
-
71
51
  exports.moveDateTimeToNextCentury = moveDateTimeToNextCentury;
72
-
73
52
  const moveDateTimeToCurrentCentury = datetime => {
74
53
  return _dayjs.default.utc(datetime).subtract(100, "year").toISOString();
75
54
  };
76
-
77
55
  exports.moveDateTimeToCurrentCentury = moveDateTimeToCurrentCentury;
78
-
79
56
  const isDateTimeInNextCentury = datetime => {
80
57
  return _dayjs.default.utc(datetime).isAfter("2100-01-01", "year");
81
58
  };
82
-
83
59
  exports.isDateTimeInNextCentury = isDateTimeInNextCentury;
84
-
85
60
  const shouldRestoreDatetime = ({
86
61
  invocationType,
87
62
  datetime
@@ -93,16 +68,11 @@ const shouldRestoreDatetime = ({
93
68
  * scheduled action if it has not been executed already.
94
69
  */
95
70
  const selfInvoked = invocationType === _types.InvocationTypes.SCHEDULED;
96
-
97
71
  const today = _dayjs.default.utc();
98
-
99
72
  const isExecutionPending = _dayjs.default.utc(datetime).isAfter(today);
100
-
101
73
  return !selfInvoked && isExecutionPending;
102
74
  };
103
-
104
75
  exports.shouldRestoreDatetime = shouldRestoreDatetime;
105
-
106
76
  const encodeToken = ({
107
77
  id,
108
78
  tenant,
@@ -110,11 +80,9 @@ const encodeToken = ({
110
80
  }) => {
111
81
  return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;
112
82
  };
113
-
114
83
  exports.encodeToken = encodeToken;
115
84
  const TOKEN_PREFIX = "apw-";
116
85
  exports.TOKEN_PREFIX = TOKEN_PREFIX;
117
-
118
86
  const decodeToken = token => {
119
87
  const auth = token.slice(TOKEN_PREFIX.length);
120
88
  const [id, tenant, locale] = auth.split("__");
@@ -124,27 +92,23 @@ const decodeToken = token => {
124
92
  locale
125
93
  };
126
94
  };
127
-
128
95
  exports.decodeToken = decodeToken;
129
96
  const documentClient = new _dynamodb.DocumentClient({
130
97
  convertEmptyValues: true,
131
98
  region: process.env.AWS_REGION
132
99
  });
133
100
  exports.documentClient = documentClient;
134
-
135
101
  const basePlugins = () => [(0, _plugins.default)(), (0, _handlerLogs.default)(), (0, _handlerDb.default)({
136
102
  table: process.env.DB_TABLE,
137
103
  driver: new _dbDynamodb.DynamoDbDriver({
138
104
  documentClient
139
105
  })
140
106
  })];
107
+
141
108
  /**
142
109
  * Get APW settings record from DDB.
143
110
  */
144
-
145
-
146
111
  exports.basePlugins = basePlugins;
147
-
148
112
  const getApwSettings = async () => {
149
113
  const variant = process.env.STAGED_ROLLOUTS_VARIANT;
150
114
  const params = {
@@ -159,10 +123,8 @@ const getApwSettings = async () => {
159
123
  } = await documentClient.get(params).promise();
160
124
  return {
161
125
  mainGraphqlFunctionArn: Item ? Item["mainGraphqlFunctionArn"] : "mainGraphqlFunctionArn",
162
- cmsGraphqlFunctionArn: Item ? Item["cmsGraphqlFunctionArn"] : "cmsGraphqlFunctionArn",
163
126
  eventRuleName: Item ? Item["eventRuleName"] : "eventRuleName",
164
127
  eventTargetId: Item ? Item["eventTargetId"] : "eventTargetId"
165
128
  };
166
129
  };
167
-
168
130
  exports.getApwSettings = getApwSettings;
@@ -1 +1 @@
1
- {"version":3,"names":["dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","cmsGraphqlFunctionArn","eventRuleName","eventTargetId"],"sources":["utils.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport dbPlugins from \"@webiny/handler-db\";\nimport { DynamoDbDriver } from \"@webiny/db-dynamodb\";\nimport dynamoDbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport logsPlugins from \"@webiny/handler-logs\";\nimport { InvocationTypes } from \"~/scheduler/types\";\n\n/**\n * https://day.js.org/docs/en/plugin/utc\n */\ndayjs.extend(utc);\n\nconst TIME_SEPARATOR = \":\";\nconst ELAPSED_CRON_EXPRESSION = \"* * * * ? 2000\";\n\nexport const getIsoStringTillMinutes = (datetime: string): string => {\n /**\n * Validate datetime.\n */\n if (isNaN(Date.parse(datetime))) {\n return datetime;\n }\n // input = \"2022-03-08T05:41:13.230Z\"\n // output = \"2022-03-08T05:41\"\n return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));\n};\n\nexport const dateTimeToCronExpression = (datetime: string): string => {\n if (!datetime) {\n return ELAPSED_CRON_EXPRESSION;\n }\n /**\n * You can't specify the Day-of-month and Day-of-week fields in the same cron expression.\n * If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.\n *\n * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html\n */\n const dayOfWeek = \"?\";\n\n return dayjs.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);\n};\n\nexport const moveDateTimeToNextCentury = (datetime: string): string => {\n return dayjs.utc(datetime).add(100, \"year\").toISOString();\n};\n\nexport const moveDateTimeToCurrentCentury = (datetime: string): string => {\n return dayjs.utc(datetime).subtract(100, \"year\").toISOString();\n};\n\nexport const isDateTimeInNextCentury = (datetime: string): boolean => {\n return dayjs.utc(datetime).isAfter(\"2100-01-01\", \"year\");\n};\n\ninterface ShouldRestoreDatetimeParams {\n invocationType?: InvocationTypes;\n datetime: string;\n}\n\nexport const shouldRestoreDatetime = ({\n invocationType,\n datetime\n}: ShouldRestoreDatetimeParams): boolean => {\n /**\n * \"invocationType\" will not be SCHEDULED when the lambda is called from Main GQL handler.\n *\n * Which means a new content is scheduled for \"publish\"/\"unpublish\" therefore, we need to restore the previously\n * scheduled action if it has not been executed already.\n */\n const selfInvoked = invocationType === InvocationTypes.SCHEDULED;\n\n const today = dayjs.utc();\n const isExecutionPending = dayjs.utc(datetime).isAfter(today);\n\n return !selfInvoked && isExecutionPending;\n};\n\ninterface EncodeTokenParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport const encodeToken = ({ id, tenant, locale }: EncodeTokenParams) => {\n return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;\n};\n\nexport const TOKEN_PREFIX = \"apw-\";\n\nexport const decodeToken = (token: string): Partial<EncodeTokenParams> => {\n const auth = token.slice(TOKEN_PREFIX.length);\n const [id, tenant, locale] = auth.split(\"__\");\n\n return {\n id,\n tenant,\n locale\n };\n};\n\nexport const documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: process.env.AWS_REGION\n});\n\nexport const basePlugins = () => [\n dynamoDbPlugins(),\n logsPlugins(),\n dbPlugins({\n table: process.env.DB_TABLE,\n driver: new DynamoDbDriver({\n documentClient\n })\n })\n];\n\n/**\n * Get APW settings record from DDB.\n */\nexport interface ApwSettings {\n mainGraphqlFunctionArn: string;\n cmsGraphqlFunctionArn: string;\n eventRuleName: string;\n eventTargetId: string;\n}\n\nexport const getApwSettings = async (): Promise<ApwSettings> => {\n const variant = process.env.STAGED_ROLLOUTS_VARIANT;\n\n const params = {\n TableName: process.env.DB_TABLE as string,\n Key: {\n PK: `APW#SETTINGS`,\n SK: variant || \"default\"\n }\n };\n\n const { Item } = await documentClient.get(params).promise();\n\n return {\n mainGraphqlFunctionArn: Item ? Item[\"mainGraphqlFunctionArn\"] : \"mainGraphqlFunctionArn\",\n cmsGraphqlFunctionArn: Item ? Item[\"cmsGraphqlFunctionArn\"] : \"cmsGraphqlFunctionArn\",\n eventRuleName: Item ? Item[\"eventRuleName\"] : \"eventRuleName\",\n eventTargetId: Item ? Item[\"eventTargetId\"] : \"eventTargetId\"\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;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cAAc,GAAG,YAAkC;EAC5D,MAAMC,OAAO,GAAGZ,OAAO,CAACC,GAAR,CAAYY,uBAA5B;EAEA,MAAMC,MAAM,GAAG;IACXC,SAAS,EAAEf,OAAO,CAACC,GAAR,CAAYO,QADZ;IAEXQ,GAAG,EAAE;MACDC,EAAE,EAAG,cADJ;MAEDC,EAAE,EAAEN,OAAO,IAAI;IAFd;EAFM,CAAf;EAQA,MAAM;IAAEO;EAAF,IAAW,MAAMvB,cAAc,CAACwB,GAAf,CAAmBN,MAAnB,EAA2BO,OAA3B,EAAvB;EAEA,OAAO;IACHC,sBAAsB,EAAEH,IAAI,GAAGA,IAAI,CAAC,wBAAD,CAAP,GAAoC,wBAD7D;IAEHI,qBAAqB,EAAEJ,IAAI,GAAGA,IAAI,CAAC,uBAAD,CAAP,GAAmC,uBAF3D;IAGHK,aAAa,EAAEL,IAAI,GAAGA,IAAI,CAAC,eAAD,CAAP,GAA2B,eAH3C;IAIHM,aAAa,EAAEN,IAAI,GAAGA,IAAI,CAAC,eAAD,CAAP,GAA2B;EAJ3C,CAAP;AAMH,CAnBM"}
1
+ {"version":3,"names":["_dayjs","_interopRequireDefault","require","_utc","_dynamodb","_handlerDb","_dbDynamodb","_plugins","_handlerLogs","_types","dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","exports","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","eventRuleName","eventTargetId"],"sources":["utils.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport dbPlugins from \"@webiny/handler-db\";\nimport { DynamoDbDriver } from \"@webiny/db-dynamodb\";\nimport dynamoDbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport logsPlugins from \"@webiny/handler-logs\";\nimport { InvocationTypes } from \"~/scheduler/types\";\n\n/**\n * https://day.js.org/docs/en/plugin/utc\n */\ndayjs.extend(utc);\n\nconst TIME_SEPARATOR = \":\";\nconst ELAPSED_CRON_EXPRESSION = \"* * * * ? 2000\";\n\nexport const getIsoStringTillMinutes = (datetime: string): string => {\n /**\n * Validate datetime.\n */\n if (isNaN(Date.parse(datetime))) {\n return datetime;\n }\n // input = \"2022-03-08T05:41:13.230Z\"\n // output = \"2022-03-08T05:41\"\n return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));\n};\n\nexport const dateTimeToCronExpression = (datetime: string): string => {\n if (!datetime) {\n return ELAPSED_CRON_EXPRESSION;\n }\n /**\n * You can't specify the Day-of-month and Day-of-week fields in the same cron expression.\n * If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.\n *\n * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html\n */\n const dayOfWeek = \"?\";\n\n return dayjs.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);\n};\n\nexport const moveDateTimeToNextCentury = (datetime: string): string => {\n return dayjs.utc(datetime).add(100, \"year\").toISOString();\n};\n\nexport const moveDateTimeToCurrentCentury = (datetime: string): string => {\n return dayjs.utc(datetime).subtract(100, \"year\").toISOString();\n};\n\nexport const isDateTimeInNextCentury = (datetime: string): boolean => {\n return dayjs.utc(datetime).isAfter(\"2100-01-01\", \"year\");\n};\n\ninterface ShouldRestoreDatetimeParams {\n invocationType?: InvocationTypes;\n datetime: string;\n}\n\nexport const shouldRestoreDatetime = ({\n invocationType,\n datetime\n}: ShouldRestoreDatetimeParams): boolean => {\n /**\n * \"invocationType\" will not be SCHEDULED when the lambda is called from Main GQL handler.\n *\n * Which means a new content is scheduled for \"publish\"/\"unpublish\" therefore, we need to restore the previously\n * scheduled action if it has not been executed already.\n */\n const selfInvoked = invocationType === InvocationTypes.SCHEDULED;\n\n const today = dayjs.utc();\n const isExecutionPending = dayjs.utc(datetime).isAfter(today);\n\n return !selfInvoked && isExecutionPending;\n};\n\ninterface EncodeTokenParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport const encodeToken = ({ id, tenant, locale }: EncodeTokenParams) => {\n return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;\n};\n\nexport const TOKEN_PREFIX = \"apw-\";\n\nexport const decodeToken = (token: string): Partial<EncodeTokenParams> => {\n const auth = token.slice(TOKEN_PREFIX.length);\n const [id, tenant, locale] = auth.split(\"__\");\n\n return {\n id,\n tenant,\n locale\n };\n};\n\nexport const documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: process.env.AWS_REGION\n});\n\nexport const basePlugins = () => [\n dynamoDbPlugins(),\n logsPlugins(),\n dbPlugins({\n table: process.env.DB_TABLE,\n driver: new DynamoDbDriver({\n documentClient\n })\n })\n];\n\n/**\n * Get APW settings record from DDB.\n */\nexport interface ApwSettings {\n mainGraphqlFunctionArn: string;\n eventRuleName: string;\n eventTargetId: string;\n}\n\nexport const getApwSettings = async (): Promise<ApwSettings> => {\n const variant = process.env.STAGED_ROLLOUTS_VARIANT;\n\n const params = {\n TableName: process.env.DB_TABLE as string,\n Key: {\n PK: `APW#SETTINGS`,\n SK: variant || \"default\"\n }\n };\n\n const { Item } = await documentClient.get(params).promise();\n\n return {\n mainGraphqlFunctionArn: Item ? Item[\"mainGraphqlFunctionArn\"] : \"mainGraphqlFunctionArn\",\n eventRuleName: Item ? Item[\"eventRuleName\"] : \"eventRuleName\",\n eventTargetId: Item ?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I,GAAGA,IAAI,CAAC,wBAAwB,CAAC,GAAG,wBAAwB;IACxFI,aAAa,EAAEJ,IAAI,GAAGA,IAAI,CAAC,eAAe,CAAC,GAAG,eAAe;IAC7DK,aAAa,EAAEL,IAAI,GAAGA,IAAI,CAAC,eAAe,CAAC,GAAG;EAClD,CAAC;AACL,CAAC;AAACnD,OAAA,CAAA2C,cAAA,GAAAA,cAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createScheduler = void 0;
7
-
8
7
  var _createScheduleActionMethods = require("./createScheduleActionMethods");
9
-
10
8
  const createScheduler = params => {
11
9
  const {
12
10
  getLocale,
@@ -23,5 +21,4 @@ const createScheduler = params => {
23
21
  storageOperations
24
22
  });
25
23
  };
26
-
27
24
  exports.createScheduler = createScheduler;
@@ -1 +1 @@
1
- {"version":3,"names":["createScheduler","params","getLocale","getIdentity","getTenant","getPermission","storageOperations","createScheduleActionMethods"],"sources":["index.ts"],"sourcesContent":["import { createScheduleActionMethods } from \"./createScheduleActionMethods\";\nimport { ApwScheduleActionCrud, CreateScheduleActionParams } from \"./types\";\n\nexport const createScheduler = (params: CreateScheduleActionParams): ApwScheduleActionCrud => {\n const { getLocale, getIdentity, getTenant, getPermission, storageOperations } = params;\n\n return createScheduleActionMethods({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations\n });\n};\n"],"mappings":";;;;;;;AAAA;;AAGO,MAAMA,eAAe,GAAIC,MAAD,IAA+D;EAC1F,MAAM;IAAEC,SAAF;IAAaC,WAAb;IAA0BC,SAA1B;IAAqCC,aAArC;IAAoDC;EAApD,IAA0EL,MAAhF;EAEA,OAAO,IAAAM,wDAAA,EAA4B;IAC/BL,SAD+B;IAE/BC,WAF+B;IAG/BC,SAH+B;IAI/BC,aAJ+B;IAK/BC;EAL+B,CAA5B,CAAP;AAOH,CAVM"}
1
+ {"version":3,"names":["_createScheduleActionMethods","require","createScheduler","params","getLocale","getIdentity","getTenant","getPermission","storageOperations","createScheduleActionMethods","exports"],"sources":["index.ts"],"sourcesContent":["import { createScheduleActionMethods } from \"./createScheduleActionMethods\";\nimport { ApwScheduleActionCrud, CreateScheduleActionParams } from \"./types\";\n\nexport const createScheduler = (params: CreateScheduleActionParams): ApwScheduleActionCrud => {\n const { getLocale, getIdentity, getTenant, getPermission, storageOperations } = params;\n\n return createScheduleActionMethods({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,4BAAA,GAAAC,OAAA;AAGO,MAAMC,eAAe,GAAIC,MAAkC,IAA4B;EAC1F,MAAM;IAAEC,SAAS;IAAEC,WAAW;IAAEC,SAAS;IAAEC,aAAa;IAAEC;EAAkB,CAAC,GAAGL,MAAM;EAEtF,OAAO,IAAAM,wDAA2B,EAAC;IAC/BL,SAAS;IACTC,WAAW;IACXC,SAAS;IACTC,aAAa;IACbC;EACJ,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAR,eAAA,GAAAA,eAAA"}
@@ -3,6 +3,7 @@ import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types
3
3
  import { I18NLocale, I18NContext } from "@webiny/api-i18n/types";
4
4
  import { Tenant } from "@webiny/api-tenancy/types";
5
5
  import { TenancyContext } from "@webiny/api-tenancy/types";
6
+ import { ApwIdentity } from "../types";
6
7
  export interface ListWhere {
7
8
  /**
8
9
  * Fields.
@@ -29,25 +30,6 @@ export interface ListParams {
29
30
  limit?: number;
30
31
  after?: string;
31
32
  }
32
- /**
33
- * A interface describing the reference to a user that created some data in the database.
34
- *
35
- * @category General
36
- */
37
- export interface CreatedBy {
38
- /**
39
- * ID if the user.
40
- */
41
- id: string;
42
- /**
43
- * Full name of the user.
44
- */
45
- displayName: string | null;
46
- /**
47
- * Type of the user (admin, user)
48
- */
49
- type: string;
50
- }
51
33
  export interface ListMeta {
52
34
  /**
53
35
  * A cursor for pagination.
@@ -70,7 +52,7 @@ export interface BaseFields {
70
52
  id: string;
71
53
  createdOn: string;
72
54
  savedOn?: string;
73
- createdBy: CreatedBy;
55
+ createdBy: ApwIdentity;
74
56
  tenant: string;
75
57
  locale: string;
76
58
  }
@@ -4,31 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTypes = void 0;
7
-
8
- /**
9
- * A interface describing the reference to a user that created some data in the database.
10
- *
11
- * @category General
12
- */
13
- let ApwContentTypes;
14
- exports.ApwContentTypes = ApwContentTypes;
15
-
16
- (function (ApwContentTypes) {
7
+ let ApwContentTypes = /*#__PURE__*/function (ApwContentTypes) {
17
8
  ApwContentTypes["PAGE"] = "page";
18
9
  ApwContentTypes["CMS_ENTRY"] = "cms_entry";
19
- })(ApwContentTypes || (exports.ApwContentTypes = ApwContentTypes = {}));
20
-
21
- let ApwScheduleActionTypes;
22
- exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
23
-
24
- (function (ApwScheduleActionTypes) {
10
+ return ApwContentTypes;
11
+ }({});
12
+ exports.ApwContentTypes = ApwContentTypes;
13
+ let ApwScheduleActionTypes = /*#__PURE__*/function (ApwScheduleActionTypes) {
25
14
  ApwScheduleActionTypes["PUBLISH"] = "publish";
26
15
  ApwScheduleActionTypes["UNPUBLISH"] = "unpublish";
27
- })(ApwScheduleActionTypes || (exports.ApwScheduleActionTypes = ApwScheduleActionTypes = {}));
28
-
29
- let InvocationTypes;
30
- exports.InvocationTypes = InvocationTypes;
31
-
32
- (function (InvocationTypes) {
16
+ return ApwScheduleActionTypes;
17
+ }({});
18
+ exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
19
+ let InvocationTypes = /*#__PURE__*/function (InvocationTypes) {
33
20
  InvocationTypes["SCHEDULED"] = "scheduled";
34
- })(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
21
+ return InvocationTypes;
22
+ }({});
23
+ exports.InvocationTypes = InvocationTypes;
@@ -1 +1 @@
1
- {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\n/**\n * A interface describing the reference to a user that created some data in the database.\n *\n * @category General\n */\nexport interface CreatedBy {\n /**\n * ID if the user.\n */\n id: string;\n /**\n * Full name of the user.\n */\n displayName: string | null;\n /**\n * Type of the user (admin, user)\n */\n type: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: CreatedBy;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;;AAkCA;AACA;AACA;AACA;AACA;IA+BYA,e;;;WAAAA,e;EAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e;;IAkBAC,sB;;;WAAAA,sB;EAAAA,sB;EAAAA,sB;GAAAA,sB,sCAAAA,sB;;IAiBAC,e;;;WAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e"}
1
+ {"version":3,"names":["ApwContentTypes","exports","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { ApwIdentity } from \"~/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: ApwIdentity;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;IAkDYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AAAAC,OAAA,CAAAD,eAAA,GAAAA,eAAA;AAAA,IAkBfE,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAAD,OAAA,CAAAC,sBAAA,GAAAA,sBAAA;AAAA,IAiBtBC,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AAAAF,OAAA,CAAAE,eAAA,GAAAA,eAAA"}
@@ -1,50 +1,36 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createChangeRequestStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _index = require("./index");
13
-
14
10
  var _fieldResolver = require("../utils/fieldResolver");
15
-
16
11
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
-
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
-
22
12
  const createChangeRequestStorageOperations = params => {
23
13
  const {
24
14
  cms,
25
15
  getCmsContext,
26
16
  security
27
17
  } = params;
28
-
29
18
  const getChangeRequestModel = async () => {
30
- security.disableAuthorization();
31
- const model = await cms.getModel("apwChangeRequestModelDefinition");
32
- security.enableAuthorization();
33
-
19
+ const model = await security.withoutAuthorization(async () => {
20
+ return cms.getModel("apwChangeRequestModelDefinition");
21
+ });
34
22
  if (!model) {
35
23
  throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
36
24
  }
37
-
38
25
  return model;
39
26
  };
40
-
41
27
  const getChangeRequest = async ({
42
28
  id
43
29
  }) => {
44
30
  const model = await getChangeRequestModel();
45
- security.disableAuthorization();
46
- const entry = await cms.getEntryById(model, id);
47
- security.enableAuthorization();
31
+ const entry = await security.withoutAuthorization(async () => {
32
+ return cms.getEntryById(model, id);
33
+ });
48
34
  return (0, _fieldResolver.getFieldValues)({
49
35
  entry,
50
36
  fields: _index.baseFields,
@@ -52,19 +38,16 @@ const createChangeRequestStorageOperations = params => {
52
38
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
53
39
  });
54
40
  };
55
-
56
41
  return {
57
42
  getChangeRequestModel,
58
43
  getChangeRequest,
59
-
60
44
  async listChangeRequests(params) {
61
45
  const model = await getChangeRequestModel();
62
- security.disableAuthorization();
63
- const [entries, meta] = await cms.listLatestEntries(model, _objectSpread(_objectSpread({}, params), {}, {
64
- where: _objectSpread({}, params.where)
65
- }));
66
- security.enableAuthorization();
67
-
46
+ const [entries, meta] = await security.withoutAuthorization(async () => {
47
+ return cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
48
+ where: (0, _objectSpread2.default)({}, params.where)
49
+ }));
50
+ });
68
51
  try {
69
52
  const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
70
53
  entry,
@@ -77,12 +60,11 @@ const createChangeRequestStorageOperations = params => {
77
60
  throw new _error.default(ex.message, ex.code, ex.data);
78
61
  }
79
62
  },
80
-
81
63
  async createChangeRequest(params) {
82
64
  const model = await getChangeRequestModel();
83
- security.disableAuthorization();
84
- const entry = await cms.createEntry(model, params.data);
85
- security.enableAuthorization();
65
+ const entry = await security.withoutAuthorization(async () => {
66
+ return cms.createEntry(model, params.data);
67
+ });
86
68
  return (0, _fieldResolver.getFieldValues)({
87
69
  entry,
88
70
  fields: _index.baseFields,
@@ -90,20 +72,18 @@ const createChangeRequestStorageOperations = params => {
90
72
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
91
73
  });
92
74
  },
93
-
94
75
  async updateChangeRequest(params) {
95
76
  const model = await getChangeRequestModel();
96
77
  /**
97
78
  * We're fetching the existing entry here because we're not accepting "app" field as input,
98
79
  * but, we still need to retain its value after the "update" operation.
99
80
  */
100
-
101
81
  const existingEntry = await getChangeRequest({
102
82
  id: params.id
103
83
  });
104
- security.disableAuthorization();
105
- const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
106
- security.enableAuthorization();
84
+ const entry = await security.withoutAuthorization(async () => {
85
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
86
+ });
107
87
  return (0, _fieldResolver.getFieldValues)({
108
88
  entry,
109
89
  fields: _index.baseFields,
@@ -111,16 +91,13 @@ const createChangeRequestStorageOperations = params => {
111
91
  transformers: [(0, _fieldResolver.getTransformer)(model, "body")]
112
92
  });
113
93
  },
114
-
115
94
  async deleteChangeRequest(params) {
116
95
  const model = await getChangeRequestModel();
117
- security.disableAuthorization();
118
- await cms.deleteEntry(model, params.id);
119
- security.enableAuthorization();
96
+ await security.withoutAuthorization(async () => {
97
+ return cms.deleteEntry(model, params.id);
98
+ });
120
99
  return true;
121
100
  }
122
-
123
101
  };
124
102
  };
125
-
126
103
  exports.createChangeRequestStorageOperations = createChangeRequestStorageOperations;