@webiny/api-scheduler 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9

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 (147) hide show
  1. package/constants.d.ts +5 -0
  2. package/constants.js +11 -8
  3. package/constants.js.map +1 -1
  4. package/context.d.ts +1 -1
  5. package/context.js +32 -26
  6. package/context.js.map +1 -1
  7. package/createEventHandler.d.ts +1 -0
  8. package/createEventHandler.js +26 -39
  9. package/createEventHandler.js.map +1 -1
  10. package/createScheduler.d.ts +1 -1
  11. package/createScheduler.js +5 -7
  12. package/createScheduler.js.map +1 -1
  13. package/domain/SchedulePrivateModel.js +25 -19
  14. package/domain/SchedulePrivateModel.js.map +1 -1
  15. package/domain/ScheduledActionId.js +12 -4
  16. package/domain/ScheduledActionId.js.map +1 -1
  17. package/domain/ScheduledActionIdWithVersion.js +5 -6
  18. package/domain/ScheduledActionIdWithVersion.js.map +1 -1
  19. package/domain/ScheduledActionMapper.d.ts +16 -0
  20. package/domain/ScheduledActionMapper.js +36 -0
  21. package/domain/ScheduledActionMapper.js.map +1 -0
  22. package/domain/errors.d.ts +19 -1
  23. package/domain/errors.js +54 -56
  24. package/domain/errors.js.map +1 -1
  25. package/domain/isValidDate.d.ts +1 -1
  26. package/domain/isValidDate.js +4 -9
  27. package/domain/isValidDate.js.map +1 -1
  28. package/domain/permissionsSchema.d.ts +9 -0
  29. package/domain/permissionsSchema.js +18 -0
  30. package/domain/permissionsSchema.js.map +1 -0
  31. package/exports/api/scheduler.d.ts +10 -0
  32. package/exports/api/scheduler.js +8 -0
  33. package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +4 -2
  34. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +45 -61
  35. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
  36. package/features/CancelScheduledAction/abstractions.d.ts +9 -2
  37. package/features/CancelScheduledAction/abstractions.js +2 -10
  38. package/features/CancelScheduledAction/abstractions.js.map +1 -1
  39. package/features/CancelScheduledAction/feature.d.ts +4 -1
  40. package/features/CancelScheduledAction/feature.js +6 -12
  41. package/features/CancelScheduledAction/feature.js.map +1 -1
  42. package/features/CancelScheduledAction/index.js +0 -2
  43. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +1 -1
  44. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +65 -89
  45. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
  46. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +2 -2
  47. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +21 -25
  48. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -1
  49. package/features/ExecuteScheduledAction/abstractions.d.ts +9 -2
  50. package/features/ExecuteScheduledAction/abstractions.js +12 -36
  51. package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
  52. package/features/ExecuteScheduledAction/feature.d.ts +4 -1
  53. package/features/ExecuteScheduledAction/feature.js +7 -13
  54. package/features/ExecuteScheduledAction/feature.js.map +1 -1
  55. package/features/ExecuteScheduledAction/index.js +0 -2
  56. package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +6 -2
  57. package/features/GetScheduledAction/GetScheduledActionUseCase.js +38 -39
  58. package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
  59. package/features/GetScheduledAction/abstractions.d.ts +9 -2
  60. package/features/GetScheduledAction/abstractions.js +2 -11
  61. package/features/GetScheduledAction/abstractions.js.map +1 -1
  62. package/features/GetScheduledAction/feature.d.ts +4 -1
  63. package/features/GetScheduledAction/feature.js +6 -12
  64. package/features/GetScheduledAction/feature.js.map +1 -1
  65. package/features/GetScheduledAction/index.js +0 -2
  66. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +32 -0
  67. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +64 -0
  68. package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -0
  69. package/features/GetTargetScheduledAction/abstractions.d.ts +24 -0
  70. package/features/GetTargetScheduledAction/abstractions.js +5 -0
  71. package/features/GetTargetScheduledAction/abstractions.js.map +1 -0
  72. package/features/GetTargetScheduledAction/feature.d.ts +10 -0
  73. package/features/GetTargetScheduledAction/feature.js +11 -0
  74. package/features/GetTargetScheduledAction/feature.js.map +1 -0
  75. package/features/{RunAction → GetTargetScheduledAction}/index.js +0 -2
  76. package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -1
  77. package/features/ListScheduledActions/ListScheduledActionsUseCase.js +53 -67
  78. package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
  79. package/features/ListScheduledActions/abstractions.d.ts +11 -3
  80. package/features/ListScheduledActions/abstractions.js +2 -12
  81. package/features/ListScheduledActions/abstractions.js.map +1 -1
  82. package/features/ListScheduledActions/feature.d.ts +4 -1
  83. package/features/ListScheduledActions/feature.js +6 -12
  84. package/features/ListScheduledActions/feature.js.map +1 -1
  85. package/features/ListScheduledActions/index.js +0 -2
  86. package/features/NamespaceHandler/NamespaceHandlerExecutioner.d.ts +11 -0
  87. package/features/NamespaceHandler/NamespaceHandlerExecutioner.js +26 -0
  88. package/features/NamespaceHandler/NamespaceHandlerExecutioner.js.map +1 -0
  89. package/features/NamespaceHandler/abstractions.d.ts +50 -0
  90. package/features/NamespaceHandler/abstractions.js +6 -0
  91. package/features/NamespaceHandler/abstractions.js.map +1 -0
  92. package/features/NamespaceHandler/index.d.ts +1 -0
  93. package/features/NamespaceHandler/index.js +1 -0
  94. package/features/ScheduleAction/ScheduleActionUseCase.d.ts +4 -4
  95. package/features/ScheduleAction/ScheduleActionUseCase.js +146 -143
  96. package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
  97. package/features/ScheduleAction/abstractions.d.ts +11 -11
  98. package/features/ScheduleAction/abstractions.js +2 -10
  99. package/features/ScheduleAction/abstractions.js.map +1 -1
  100. package/features/ScheduleAction/feature.d.ts +4 -1
  101. package/features/ScheduleAction/feature.js +6 -12
  102. package/features/ScheduleAction/feature.js.map +1 -1
  103. package/features/ScheduleAction/index.js +0 -2
  104. package/features/SchedulerFeature.d.ts +4 -1
  105. package/features/SchedulerFeature.js +12 -20
  106. package/features/SchedulerFeature.js.map +1 -1
  107. package/features/SchedulerService/EventBridgeSchedulerService.d.ts +1 -1
  108. package/features/SchedulerService/EventBridgeSchedulerService.js +86 -120
  109. package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -1
  110. package/features/SchedulerService/VoidSchedulerService.js +17 -24
  111. package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
  112. package/features/permissions/abstractions.d.ts +14 -0
  113. package/features/permissions/abstractions.js +6 -0
  114. package/features/permissions/abstractions.js.map +1 -0
  115. package/features/permissions/feature.d.ts +4 -0
  116. package/features/permissions/feature.js +7 -0
  117. package/features/permissions/feature.js.map +1 -0
  118. package/graphql/SchedulerGraphQLFactory.d.ts +8 -0
  119. package/graphql/SchedulerGraphQLFactory.js +219 -0
  120. package/graphql/SchedulerGraphQLFactory.js.map +1 -0
  121. package/graphql/index.d.ts +1 -0
  122. package/graphql/index.js +1 -0
  123. package/index.d.ts +0 -6
  124. package/index.js +1 -11
  125. package/manifest.js +26 -30
  126. package/manifest.js.map +1 -1
  127. package/package.json +30 -32
  128. package/shared/abstractions.d.ts +19 -6
  129. package/shared/abstractions.js +4 -29
  130. package/shared/abstractions.js.map +1 -1
  131. package/features/CancelScheduledAction/index.js.map +0 -1
  132. package/features/ExecuteScheduledAction/index.js.map +0 -1
  133. package/features/GetScheduledAction/index.js.map +0 -1
  134. package/features/ListScheduledActions/index.js.map +0 -1
  135. package/features/RunAction/RunActionUseCase.d.ts +0 -23
  136. package/features/RunAction/RunActionUseCase.js +0 -37
  137. package/features/RunAction/RunActionUseCase.js.map +0 -1
  138. package/features/RunAction/abstractions.d.ts +0 -35
  139. package/features/RunAction/abstractions.js +0 -15
  140. package/features/RunAction/abstractions.js.map +0 -1
  141. package/features/RunAction/feature.d.ts +0 -7
  142. package/features/RunAction/feature.js +0 -17
  143. package/features/RunAction/feature.js.map +0 -1
  144. package/features/RunAction/index.js.map +0 -1
  145. package/features/ScheduleAction/index.js.map +0 -1
  146. package/index.js.map +0 -1
  147. /package/features/{RunAction → GetTargetScheduledAction}/index.d.ts +0 -0
package/constants.d.ts CHANGED
@@ -6,3 +6,8 @@ export declare const SCHEDULE_ID_PREFIX = "wby-schedule-";
6
6
  */
7
7
  export declare const SCHEDULE_MIN_FUTURE_SECONDS = 65;
8
8
  export declare const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
9
+ /** Constant identifier for the publish scheduled action type. */
10
+ export declare const SCHEDULED_ACTION_PUBLISH: "publish";
11
+ /** Constant identifier for the unpublish scheduled action type. */
12
+ export declare const SCHEDULED_ACTION_UNPUBLISH: "unpublish";
13
+ export declare const SCHEDULED_ACTIONS: readonly ["publish", "unpublish"];
package/constants.js CHANGED
@@ -1,10 +1,13 @@
1
- export const SCHEDULE_MODEL_ID = "wbySchedule";
2
- export const SCHEDULE_ID_PREFIX = "wby-schedule-";
3
- /**
4
- * Minimum number of seconds in the future that a schedule can be set.
5
- * Everything else will result in immediately running the action.
6
- */
7
- export const SCHEDULE_MIN_FUTURE_SECONDS = 65;
8
- export const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
1
+ const SCHEDULE_MODEL_ID = "wbySchedule";
2
+ const SCHEDULE_ID_PREFIX = "wby-schedule-";
3
+ const SCHEDULE_MIN_FUTURE_SECONDS = 65;
4
+ const SCHEDULED_ACTION_EVENT_IDENTIFIER = "WebinyScheduledAction";
5
+ const SCHEDULED_ACTION_PUBLISH = "publish";
6
+ const SCHEDULED_ACTION_UNPUBLISH = "unpublish";
7
+ const SCHEDULED_ACTIONS = [
8
+ SCHEDULED_ACTION_PUBLISH,
9
+ SCHEDULED_ACTION_UNPUBLISH
10
+ ];
11
+ export { SCHEDULED_ACTIONS, SCHEDULED_ACTION_EVENT_IDENTIFIER, SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH, SCHEDULE_ID_PREFIX, SCHEDULE_MIN_FUTURE_SECONDS, SCHEDULE_MODEL_ID };
9
12
 
10
13
  //# sourceMappingURL=constants.js.map
package/constants.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["SCHEDULE_MODEL_ID","SCHEDULE_ID_PREFIX","SCHEDULE_MIN_FUTURE_SECONDS","SCHEDULED_ACTION_EVENT_IDENTIFIER"],"sources":["constants.ts"],"sourcesContent":["export const SCHEDULE_MODEL_ID = \"wbySchedule\";\nexport const SCHEDULE_ID_PREFIX = \"wby-schedule-\";\n/**\n * Minimum number of seconds in the future that a schedule can be set.\n * Everything else will result in immediately running the action.\n */\nexport const SCHEDULE_MIN_FUTURE_SECONDS = 65;\n\nexport const SCHEDULED_ACTION_EVENT_IDENTIFIER = \"WebinyScheduledAction\";\n"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB,GAAG,aAAa;AAC9C,OAAO,MAAMC,kBAAkB,GAAG,eAAe;AACjD;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAG,EAAE;AAE7C,OAAO,MAAMC,iCAAiC,GAAG,uBAAuB","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const SCHEDULE_MODEL_ID = \"wbySchedule\";\nexport const SCHEDULE_ID_PREFIX = \"wby-schedule-\";\n/**\n * Minimum number of seconds in the future that a schedule can be set.\n * Everything else will result in immediately running the action.\n */\nexport const SCHEDULE_MIN_FUTURE_SECONDS = 65;\n\nexport const SCHEDULED_ACTION_EVENT_IDENTIFIER = \"WebinyScheduledAction\";\n\n/** Constant identifier for the publish scheduled action type. */\nexport const SCHEDULED_ACTION_PUBLISH = \"publish\" as const;\n/** Constant identifier for the unpublish scheduled action type. */\nexport const SCHEDULED_ACTION_UNPUBLISH = \"unpublish\" as const;\n\nexport const SCHEDULED_ACTIONS = [SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH] as const;\n"],"names":["SCHEDULE_MODEL_ID","SCHEDULE_ID_PREFIX","SCHEDULE_MIN_FUTURE_SECONDS","SCHEDULED_ACTION_EVENT_IDENTIFIER","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH","SCHEDULED_ACTIONS"],"mappings":"AAAO,MAAMA,oBAAoB;AAC1B,MAAMC,qBAAqB;AAK3B,MAAMC,8BAA8B;AAEpC,MAAMC,oCAAoC;AAG1C,MAAMC,2BAA2B;AAEjC,MAAMC,6BAA6B;AAEnC,MAAMC,oBAAoB;IAACF;IAA0BC;CAA2B"}
package/context.d.ts CHANGED
@@ -4,4 +4,4 @@ import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
4
4
  export interface ICreateHeadlessCmsSchedulerContextParams {
5
5
  getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
6
6
  }
7
- export declare const createSchedulerContext: (params: ICreateHeadlessCmsSchedulerContextParams) => ContextPlugin<CmsContext>;
7
+ export declare const createSchedulerContext: (params: ICreateHeadlessCmsSchedulerContextParams) => (ContextPlugin<CmsContext> | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>)[];
package/context.js CHANGED
@@ -8,34 +8,40 @@ import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
8
8
  import { SchedulerFeature } from "./features/SchedulerFeature.js";
9
9
  import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
10
10
  import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
11
- export const createSchedulerContext = params => {
12
- return new ContextPlugin(async context => {
13
- const tenantContext = context.container.resolve(TenantContext);
14
- const getModel = context.container.resolve(GetModelUseCase);
15
- if (!tenantContext.getTenant()) {
16
- return;
17
- }
18
- const manifest = await getManifest({
19
- client: context.db.driver.getClient()
11
+ import { SchedulerGraphQLFactory } from "./graphql/index.js";
12
+ import { SchedulerPermissionsFeature } from "./features/permissions/feature.js";
13
+ import { NamespaceHandlerExecutioner } from "./features/NamespaceHandler/NamespaceHandlerExecutioner.js";
14
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
15
+ const createSchedulerContext = (params)=>{
16
+ const modelsPlugin = createRegisterExtensionPlugin((context)=>{
17
+ context.container.register(SchedulePrivateModel);
20
18
  });
21
- if (manifest.error) {
22
- context.container.registerInstance(SchedulerService, new VoidSchedulerService());
23
- } else {
24
- // TODO: in the future, extract AWS specific implementation into a separate package
25
- context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
26
- lambdaArn: manifest.data.lambdaArn,
27
- roleArn: manifest.data.roleArn
28
- }));
29
- }
30
- context.container.register(SchedulePrivateModel);
31
- await context.security.withoutAuthorization(async () => {
32
- const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);
33
- context.container.registerInstance(ScheduledActionModel, schedulerModel.value);
19
+ const schedulerContextPlugin = new ContextPlugin(async (context)=>{
20
+ const tenantContext = context.container.resolve(TenantContext);
21
+ const getModel = context.container.resolve(GetModelUseCase);
22
+ if (!tenantContext.getTenant()) return;
23
+ const manifest = await getManifest({
24
+ client: context.db.driver.getClient()
25
+ });
26
+ if (manifest.error) context.container.registerInstance(SchedulerService, new VoidSchedulerService());
27
+ else context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
28
+ lambdaArn: manifest.data.lambdaArn,
29
+ roleArn: manifest.data.roleArn
30
+ }));
31
+ SchedulerPermissionsFeature.register(context.container);
32
+ context.container.register(SchedulerGraphQLFactory);
33
+ context.container.register(NamespaceHandlerExecutioner);
34
+ await context.security.withoutAuthorization(async ()=>{
35
+ const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);
36
+ context.container.registerInstance(ScheduledActionModel, schedulerModel.value);
37
+ });
38
+ SchedulerFeature.register(context.container);
34
39
  });
35
-
36
- // Register all features
37
- SchedulerFeature.register(context.container);
38
- });
40
+ return [
41
+ schedulerContextPlugin,
42
+ modelsPlugin
43
+ ];
39
44
  };
45
+ export { createSchedulerContext };
40
46
 
41
47
  //# sourceMappingURL=context.js.map
package/context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","getManifest","SCHEDULE_MODEL_ID","ScheduledActionModel","SchedulerService","EventBridgeSchedulerService","VoidSchedulerService","SchedulePrivateModel","SchedulerFeature","TenantContext","GetModelUseCase","createSchedulerContext","params","context","tenantContext","container","resolve","getModel","getTenant","manifest","client","db","driver","getClient","error","registerInstance","lambdaArn","data","roleArn","register","security","withoutAuthorization","schedulerModel","execute","value"],"sources":["context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"~/features/SchedulerService/VoidSchedulerService.js\";\nimport { SchedulePrivateModel } from \"~/domain/SchedulePrivateModel.js\";\nimport { SchedulerFeature } from \"./features/SchedulerFeature.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createSchedulerContext = (params: ICreateHeadlessCmsSchedulerContextParams) => {\n return new ContextPlugin<CmsContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n\n if (manifest.error) {\n context.container.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n // TODO: in the future, extract AWS specific implementation into a separate package\n context.container.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n\n context.container.register(SchedulePrivateModel);\n\n await context.security.withoutAuthorization(async () => {\n const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);\n context.container.registerInstance(ScheduledActionModel, schedulerModel.value);\n });\n\n // Register all features\n SchedulerFeature.register(context.container);\n });\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAK3C,SAASC,WAAW;AAEpB,SAASC,iBAAiB;AAE1B,SAASC,oBAAoB,EAAEC,gBAAgB;AAC/C,SAASC,2BAA2B;AACpC,SAASC,oBAAoB;AAC7B,SAASC,oBAAoB;AAC7B,SAASC,gBAAgB;AACzB,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,eAAe,QAAQ,kEAAkE;AAMlG,OAAO,MAAMC,sBAAsB,GAAIC,MAAgD,IAAK;EACxF,OAAO,IAAIZ,aAAa,CAAa,MAAMa,OAAO,IAAI;IAClD,MAAMC,aAAa,GAAGD,OAAO,CAACE,SAAS,CAACC,OAAO,CAACP,aAAa,CAAC;IAC9D,MAAMQ,QAAQ,GAAGJ,OAAO,CAACE,SAAS,CAACC,OAAO,CAACN,eAAe,CAAC;IAE3D,IAAI,CAACI,aAAa,CAACI,SAAS,CAAC,CAAC,EAAE;MAC5B;IACJ;IAEA,MAAMC,QAAQ,GAAG,MAAMlB,WAAW,CAAC;MAC/BmB,MAAM,EAAEP,OAAO,CAACQ,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC;IACxC,CAAC,CAAC;IAEF,IAAIJ,QAAQ,CAACK,KAAK,EAAE;MAChBX,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAACrB,gBAAgB,EAAE,IAAIE,oBAAoB,CAAC,CAAC,CAAC;IACpF,CAAC,MAAM;MACH;MACAO,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAC9BrB,gBAAgB,EAChB,IAAIC,2BAA2B,CAACO,MAAM,CAACW,SAAS,EAAE;QAC9CG,SAAS,EAAEP,QAAQ,CAACQ,IAAI,CAACD,SAAS;QAClCE,OAAO,EAAET,QAAQ,CAACQ,IAAI,CAACC;MAC3B,CAAC,CACL,CAAC;IACL;IAEAf,OAAO,CAACE,SAAS,CAACc,QAAQ,CAACtB,oBAAoB,CAAC;IAEhD,MAAMM,OAAO,CAACiB,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACpD,MAAMC,cAAc,GAAG,MAAMf,QAAQ,CAACgB,OAAO,CAAC/B,iBAAiB,CAAC;MAChEW,OAAO,CAACE,SAAS,CAACU,gBAAgB,CAACtB,oBAAoB,EAAE6B,cAAc,CAACE,KAAK,CAAC;IAClF,CAAC,CAAC;;IAEF;IACA1B,gBAAgB,CAACqB,QAAQ,CAAChB,OAAO,CAACE,SAAS,CAAC;EAChD,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"~/features/SchedulerService/VoidSchedulerService.js\";\nimport { SchedulePrivateModel } from \"~/domain/SchedulePrivateModel.js\";\nimport { SchedulerFeature } from \"./features/SchedulerFeature.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { SchedulerGraphQLFactory } from \"~/graphql/index.js\";\nimport { SchedulerPermissionsFeature } from \"~/features/permissions/feature.js\";\nimport { NamespaceHandlerExecutioner } from \"~/features/NamespaceHandler/NamespaceHandlerExecutioner.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createSchedulerContext = (params: ICreateHeadlessCmsSchedulerContextParams) => {\n const modelsPlugin = createRegisterExtensionPlugin(context => {\n context.container.register(SchedulePrivateModel);\n });\n\n const schedulerContextPlugin = new ContextPlugin<CmsContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n\n if (manifest.error) {\n context.container.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n // TODO: in the future, extract AWS specific implementation into a separate package\n context.container.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n\n SchedulerPermissionsFeature.register(context.container);\n context.container.register(SchedulerGraphQLFactory);\n context.container.register(NamespaceHandlerExecutioner);\n\n await context.security.withoutAuthorization(async () => {\n const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);\n context.container.registerInstance(ScheduledActionModel, schedulerModel.value);\n });\n\n // Register all features\n SchedulerFeature.register(context.container);\n });\n\n return [schedulerContextPlugin, modelsPlugin];\n};\n"],"names":["createSchedulerContext","params","modelsPlugin","createRegisterExtensionPlugin","context","SchedulePrivateModel","schedulerContextPlugin","ContextPlugin","tenantContext","TenantContext","getModel","GetModelUseCase","manifest","getManifest","SchedulerService","VoidSchedulerService","EventBridgeSchedulerService","SchedulerPermissionsFeature","SchedulerGraphQLFactory","NamespaceHandlerExecutioner","schedulerModel","SCHEDULE_MODEL_ID","ScheduledActionModel","SchedulerFeature"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA,yBAAyB,CAACC;IACnC,MAAMC,eAAeC,8BAA8BC,CAAAA;QAC/CA,QAAQ,SAAS,CAAC,QAAQ,CAACC;IAC/B;IAEA,MAAMC,yBAAyB,IAAIC,cAA0B,OAAMH;QAC/D,MAAMI,gBAAgBJ,QAAQ,SAAS,CAAC,OAAO,CAACK;QAChD,MAAMC,WAAWN,QAAQ,SAAS,CAAC,OAAO,CAACO;QAE3C,IAAI,CAACH,cAAc,SAAS,IACxB;QAGJ,MAAMI,WAAW,MAAMC,YAAY;YAC/B,QAAQT,QAAQ,EAAE,CAAC,MAAM,CAAC,SAAS;QACvC;QAEA,IAAIQ,SAAS,KAAK,EACdR,QAAQ,SAAS,CAAC,gBAAgB,CAACU,kBAAkB,IAAIC;aAGzDX,QAAQ,SAAS,CAAC,gBAAgB,CAC9BU,kBACA,IAAIE,4BAA4Bf,OAAO,SAAS,EAAE;YAC9C,WAAWW,SAAS,IAAI,CAAC,SAAS;YAClC,SAASA,SAAS,IAAI,CAAC,OAAO;QAClC;QAIRK,4BAA4B,QAAQ,CAACb,QAAQ,SAAS;QACtDA,QAAQ,SAAS,CAAC,QAAQ,CAACc;QAC3Bd,QAAQ,SAAS,CAAC,QAAQ,CAACe;QAE3B,MAAMf,QAAQ,QAAQ,CAAC,oBAAoB,CAAC;YACxC,MAAMgB,iBAAiB,MAAMV,SAAS,OAAO,CAACW;YAC9CjB,QAAQ,SAAS,CAAC,gBAAgB,CAACkB,sBAAsBF,eAAe,KAAK;QACjF;QAGAG,iBAAiB,QAAQ,CAACnB,QAAQ,SAAS;IAC/C;IAEA,OAAO;QAACE;QAAwBJ;KAAa;AACjD"}
@@ -1,6 +1,7 @@
1
1
  import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
2
2
  import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
3
3
  export interface IScheduledActionEventPayload {
4
+ namespace: string;
4
5
  id: string;
5
6
  scheduleFor: string;
6
7
  }
@@ -3,48 +3,35 @@ import { createSourceHandler } from "@webiny/handler-aws/sourceHandler.js";
3
3
  import { createEventHandler, createHandler } from "@webiny/handler-aws/raw/index.js";
4
4
  import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
5
5
  import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
6
- const canHandle = event => {
7
- if (typeof event?.hasOwnProperty !== "function") {
8
- return false;
9
- } else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {
10
- return false;
11
- }
12
- const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
13
- return !!(value?.id && value?.scheduleFor);
6
+ const canHandle = (event)=>{
7
+ if ("function" != typeof event?.hasOwnProperty) return false;
8
+ if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) return false;
9
+ const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
10
+ return !!(value?.id && value?.scheduleFor);
14
11
  };
15
12
  const handler = createSourceHandler({
16
- name: "handler-aws-event-bridge-scheduled-cms-action-event",
17
- canUse: canHandle,
18
- handle: async ({
19
- params,
20
- event,
21
- context
22
- }) => {
23
- return createHandler(params)(event, context);
24
- }
13
+ name: "handler-aws-event-bridge-scheduled-cms-action-event",
14
+ canUse: canHandle,
15
+ handle: async ({ params, event, context })=>createHandler(params)(event, context)
25
16
  });
26
17
  registry.register(handler);
27
- export const createScheduledActionEventHandler = () => {
28
- return createEventHandler({
29
- canHandle,
30
- handle: async params => {
31
- const {
32
- payload,
33
- context
34
- } = params;
35
- const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
36
- const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);
37
- const result = await executeScheduledAction.execute(input.id);
38
- if (result.isFail()) {
39
- const error = result.error;
40
- console.error(error.code, error.message);
41
- throw error;
42
- }
43
- return {
44
- success: true
45
- };
46
- }
47
- });
48
- };
18
+ const createScheduledActionEventHandler = ()=>createEventHandler({
19
+ canHandle: canHandle,
20
+ handle: async (params)=>{
21
+ const { payload, context } = params;
22
+ const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
23
+ const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);
24
+ const result = await executeScheduledAction.execute(input);
25
+ if (result.isFail()) {
26
+ const error = result.error;
27
+ console.error(error.code, error.message);
28
+ throw error;
29
+ }
30
+ return {
31
+ success: true
32
+ };
33
+ }
34
+ });
35
+ export { createScheduledActionEventHandler };
49
36
 
50
37
  //# sourceMappingURL=createEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["registry","createSourceHandler","createEventHandler","createHandler","SCHEDULED_ACTION_EVENT_IDENTIFIER","ExecuteScheduledActionUseCase","canHandle","event","hasOwnProperty","value","id","scheduleFor","handler","name","canUse","handle","params","context","register","createScheduledActionEventHandler","payload","input","executeScheduledAction","container","resolve","result","execute","isFail","error","console","code","message","success"],"sources":["createEventHandler.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws/sourceHandler.js\";\nimport { createEventHandler, createHandler } from \"@webiny/handler-aws/raw/index.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\n\nexport interface IScheduledActionEventPayload {\n id: string;\n scheduleFor: string;\n}\n\nexport interface IScheduledActionEvent {\n [SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst canHandle = (event: Partial<IScheduledActionEvent>): boolean => {\n if (typeof event?.hasOwnProperty !== \"function\") {\n return false;\n } else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {\n return false;\n }\n\n const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n return !!(value?.id && value?.scheduleFor);\n};\n\nconst handler = createSourceHandler<IScheduledActionEvent, HandlerParams>({\n name: \"handler-aws-event-bridge-scheduled-cms-action-event\",\n canUse: canHandle,\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n\nexport const createScheduledActionEventHandler = () => {\n return createEventHandler<IScheduledActionEvent>({\n canHandle,\n handle: async params => {\n const { payload, context } = params;\n const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);\n const result = await executeScheduledAction.execute(input.id);\n\n if (result.isFail()) {\n const error = result.error;\n console.error(error.code, error.message);\n throw error;\n }\n return {\n success: true\n };\n }\n });\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,iCAAiC;AAE1D,SAASC,mBAAmB,QAAQ,sCAAsC;AAC1E,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,kCAAkC;AACpF,SAASC,iCAAiC;AAC1C,SAASC,6BAA6B;AAetC,MAAMC,SAAS,GAAIC,KAAqC,IAAc;EAClE,IAAI,OAAOA,KAAK,EAAEC,cAAc,KAAK,UAAU,EAAE;IAC7C,OAAO,KAAK;EAChB,CAAC,MAAM,IAAI,CAACD,KAAK,CAACC,cAAc,CAACJ,iCAAiC,CAAC,EAAE;IACjE,OAAO,KAAK;EAChB;EAEA,MAAMK,KAAK,GAAGF,KAAK,CAACH,iCAAiC,CAAC;EACtD,OAAO,CAAC,EAAEK,KAAK,EAAEC,EAAE,IAAID,KAAK,EAAEE,WAAW,CAAC;AAC9C,CAAC;AAED,MAAMC,OAAO,GAAGX,mBAAmB,CAAuC;EACtEY,IAAI,EAAE,qDAAqD;EAC3DC,MAAM,EAAER,SAAS;EACjBS,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAOd,aAAa,CAACa,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFjB,QAAQ,CAACkB,QAAQ,CAACN,OAAO,CAAC;AAE1B,OAAO,MAAMO,iCAAiC,GAAGA,CAAA,KAAM;EACnD,OAAOjB,kBAAkB,CAAwB;IAC7CI,SAAS;IACTS,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEI,OAAO;QAAEH;MAAQ,CAAC,GAAGD,MAAM;MACnC,MAAMK,KAAK,GAAGD,OAAO,CAAChB,iCAAiC,CAAC;MAExD,MAAMkB,sBAAsB,GAAGL,OAAO,CAACM,SAAS,CAACC,OAAO,CAACnB,6BAA6B,CAAC;MACvF,MAAMoB,MAAM,GAAG,MAAMH,sBAAsB,CAACI,OAAO,CAACL,KAAK,CAACX,EAAE,CAAC;MAE7D,IAAIe,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;QACjB,MAAMC,KAAK,GAAGH,MAAM,CAACG,KAAK;QAC1BC,OAAO,CAACD,KAAK,CAACA,KAAK,CAACE,IAAI,EAAEF,KAAK,CAACG,OAAO,CAAC;QACxC,MAAMH,KAAK;MACf;MACA,OAAO;QACHI,OAAO,EAAE;MACb,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"createEventHandler.js","sources":["../src/createEventHandler.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws/sourceHandler.js\";\nimport { createEventHandler, createHandler } from \"@webiny/handler-aws/raw/index.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\n\nexport interface IScheduledActionEventPayload {\n namespace: string;\n id: string;\n scheduleFor: string;\n}\n\nexport interface IScheduledActionEvent {\n [SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst canHandle = (event: Partial<IScheduledActionEvent>): boolean => {\n if (typeof event?.hasOwnProperty !== \"function\") {\n return false;\n } else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {\n return false;\n }\n\n const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n return !!(value?.id && value?.scheduleFor);\n};\n\nconst handler = createSourceHandler<IScheduledActionEvent, HandlerParams>({\n name: \"handler-aws-event-bridge-scheduled-cms-action-event\",\n canUse: canHandle,\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n\nexport const createScheduledActionEventHandler = () => {\n return createEventHandler<IScheduledActionEvent>({\n canHandle,\n handle: async params => {\n const { payload, context } = params;\n const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);\n const result = await executeScheduledAction.execute(input);\n\n if (result.isFail()) {\n const error = result.error;\n console.error(error.code, error.message);\n throw error;\n }\n return {\n success: true\n };\n }\n });\n};\n"],"names":["canHandle","event","SCHEDULED_ACTION_EVENT_IDENTIFIER","value","handler","createSourceHandler","params","context","createHandler","registry","createScheduledActionEventHandler","createEventHandler","payload","input","executeScheduledAction","ExecuteScheduledActionUseCase","result","error","console"],"mappings":";;;;;AAqBA,MAAMA,YAAY,CAACC;IACf,IAAI,AAAiC,cAAjC,OAAOA,OAAO,gBACd,OAAO;IACJ,IAAI,CAACA,MAAM,cAAc,CAACC,oCAC7B,OAAO;IAGX,MAAMC,QAAQF,KAAK,CAACC,kCAAkC;IACtD,OAAO,CAAC,CAAEC,CAAAA,OAAO,MAAMA,OAAO,WAAU;AAC5C;AAEA,MAAMC,UAAUC,oBAA0D;IACtE,MAAM;IACN,QAAQL;IACR,QAAQ,OAAO,EAAEM,MAAM,EAAEL,KAAK,EAAEM,OAAO,EAAE,GAC9BC,cAAcF,QAAQL,OAAOM;AAE5C;AAEAE,SAAS,QAAQ,CAACL;AAEX,MAAMM,oCAAoC,IACtCC,mBAA0C;QAC7CX,WAAAA;QACA,QAAQ,OAAMM;YACV,MAAM,EAAEM,OAAO,EAAEL,OAAO,EAAE,GAAGD;YAC7B,MAAMO,QAAQD,OAAO,CAACV,kCAAkC;YAExD,MAAMY,yBAAyBP,QAAQ,SAAS,CAAC,OAAO,CAACQ;YACzD,MAAMC,SAAS,MAAMF,uBAAuB,OAAO,CAACD;YAEpD,IAAIG,OAAO,MAAM,IAAI;gBACjB,MAAMC,QAAQD,OAAO,KAAK;gBAC1BE,QAAQ,KAAK,CAACD,MAAM,IAAI,EAAEA,MAAM,OAAO;gBACvC,MAAMA;YACV;YACA,OAAO;gBACH,SAAS;YACb;QACJ;IACJ"}
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from "@webiny/plugins/types.js";
2
- import { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler";
2
+ import { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
3
3
  export interface ICreateSchedulerParams {
4
4
  getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
5
5
  }
@@ -1,11 +1,9 @@
1
1
  import { createSchedulerContext } from "./context.js";
2
2
  import { createScheduledActionEventHandler } from "./createEventHandler.js";
3
- export const createScheduler = params => {
4
- return [
5
- /**
6
- * Handler for the Scheduled Action Event.
7
- */
8
- createScheduledActionEventHandler(), createSchedulerContext(params)];
9
- };
3
+ const createScheduler = (params)=>[
4
+ createScheduledActionEventHandler(),
5
+ ...createSchedulerContext(params)
6
+ ];
7
+ export { createScheduler };
10
8
 
11
9
  //# sourceMappingURL=createScheduler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createSchedulerContext","createScheduledActionEventHandler","createScheduler","params"],"sources":["createScheduler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport { SchedulerClient, SchedulerClientConfig } from \"@webiny/aws-sdk/client-scheduler\";\nimport { createSchedulerContext } from \"~/context.js\";\nimport { createScheduledActionEventHandler } from \"~/createEventHandler.js\";\n\nexport interface ICreateSchedulerParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\nexport const createScheduler = (params: ICreateSchedulerParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled Action Event.\n */\n createScheduledActionEventHandler(),\n createSchedulerContext(params)\n ];\n};\n"],"mappings":"AAEA,SAASA,sBAAsB;AAC/B,SAASC,iCAAiC;AAK1C,OAAO,MAAMC,eAAe,GAAIC,MAA8B,IAAe;EACzE,OAAO;EACH;AACR;AACA;EACQF,iCAAiC,CAAC,CAAC,EACnCD,sBAAsB,CAACG,MAAM,CAAC,CACjC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"createScheduler.js","sources":["../src/createScheduler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport { SchedulerClient, SchedulerClientConfig } from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { createSchedulerContext } from \"~/context.js\";\nimport { createScheduledActionEventHandler } from \"~/createEventHandler.js\";\n\nexport interface ICreateSchedulerParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\nexport const createScheduler = (params: ICreateSchedulerParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled Action Event.\n */\n createScheduledActionEventHandler(),\n ...createSchedulerContext(params)\n ];\n};\n"],"names":["createScheduler","params","createScheduledActionEventHandler","createSchedulerContext"],"mappings":";;AAQO,MAAMA,kBAAkB,CAACC,SACrB;QAIHC;WACGC,uBAAuBF;KAC7B"}
@@ -1,26 +1,32 @@
1
1
  import { ModelFactory } from "@webiny/api-headless-cms/features/modelBuilder/index.js";
2
2
  import { SCHEDULE_MODEL_ID } from "../constants.js";
3
3
  class SchedulePrivateModelImpl {
4
- async execute(builder) {
5
- return [builder.private().modelId(SCHEDULE_MODEL_ID).name("Webiny CMS Schedule").fields(fields => ({
6
- namespace: fields.text().label("Namespace"),
7
- actionType: fields.text().label("Action Type"),
8
- targetId: fields.text().label("Target ID"),
9
- scheduledBy: fields.object().label("Scheduled By").fields(fields => ({
10
- id: fields.text().label("Identity ID"),
11
- displayName: fields.text().label("Display Name"),
12
- type: fields.text().label("Type")
13
- })),
14
- scheduledFor: fields.datetime().label("Scheduled For"),
15
- title: fields.text().label("Title"),
16
- error: fields.text().label("Error"),
17
- payload: fields.json().label("Payload")
18
- }))];
19
- }
4
+ async execute(builder) {
5
+ return [
6
+ builder.private({
7
+ modelId: SCHEDULE_MODEL_ID,
8
+ name: "Webiny CMS Schedule"
9
+ }).fields((fields)=>({
10
+ namespace: fields.text().label("Namespace"),
11
+ actionType: fields.text().label("Action Type"),
12
+ targetId: fields.text().label("Target ID"),
13
+ scheduledBy: fields.object().label("Scheduled By").fields((fields)=>({
14
+ id: fields.text().label("Identity ID"),
15
+ displayName: fields.text().label("Display Name"),
16
+ type: fields.text().label("Type")
17
+ })),
18
+ scheduledFor: fields.datetime().label("Scheduled For"),
19
+ title: fields.text().label("Title"),
20
+ error: fields.text().label("Error"),
21
+ payload: fields.json().label("Payload")
22
+ }))
23
+ ];
24
+ }
20
25
  }
21
- export const SchedulePrivateModel = ModelFactory.createImplementation({
22
- implementation: SchedulePrivateModelImpl,
23
- dependencies: []
26
+ const SchedulePrivateModel = ModelFactory.createImplementation({
27
+ implementation: SchedulePrivateModelImpl,
28
+ dependencies: []
24
29
  });
30
+ export { SchedulePrivateModel };
25
31
 
26
32
  //# sourceMappingURL=SchedulePrivateModel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ModelFactory","SCHEDULE_MODEL_ID","SchedulePrivateModelImpl","execute","builder","private","modelId","name","fields","namespace","text","label","actionType","targetId","scheduledBy","object","id","displayName","type","scheduledFor","datetime","title","error","payload","json","SchedulePrivateModel","createImplementation","implementation","dependencies"],"sources":["SchedulePrivateModel.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nclass SchedulePrivateModelImpl implements ModelFactory.Interface {\n public async execute(builder: ModelFactory.Builder) {\n return [\n builder\n .private()\n .modelId(SCHEDULE_MODEL_ID)\n .name(\"Webiny CMS Schedule\")\n .fields(fields => ({\n namespace: fields.text().label(\"Namespace\"),\n actionType: fields.text().label(\"Action Type\"),\n targetId: fields.text().label(\"Target ID\"),\n scheduledBy: fields\n .object()\n .label(\"Scheduled By\")\n .fields(fields => ({\n id: fields.text().label(\"Identity ID\"),\n displayName: fields.text().label(\"Display Name\"),\n type: fields.text().label(\"Type\")\n })),\n scheduledFor: fields.datetime().label(\"Scheduled For\"),\n title: fields.text().label(\"Title\"),\n error: fields.text().label(\"Error\"),\n payload: fields.json().label(\"Payload\")\n }))\n ];\n }\n}\n\nexport const SchedulePrivateModel = ModelFactory.createImplementation({\n implementation: SchedulePrivateModelImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,yDAAyD;AACtF,SAASC,iBAAiB;AAE1B,MAAMC,wBAAwB,CAAmC;EAC7D,MAAaC,OAAOA,CAACC,OAA6B,EAAE;IAChD,OAAO,CACHA,OAAO,CACFC,OAAO,CAAC,CAAC,CACTC,OAAO,CAACL,iBAAiB,CAAC,CAC1BM,IAAI,CAAC,qBAAqB,CAAC,CAC3BC,MAAM,CAACA,MAAM,KAAK;MACfC,SAAS,EAAED,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC;MAC3CC,UAAU,EAAEJ,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC;MAC9CE,QAAQ,EAAEL,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC;MAC1CG,WAAW,EAAEN,MAAM,CACdO,MAAM,CAAC,CAAC,CACRJ,KAAK,CAAC,cAAc,CAAC,CACrBH,MAAM,CAACA,MAAM,KAAK;QACfQ,EAAE,EAAER,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,aAAa,CAAC;QACtCM,WAAW,EAAET,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,cAAc,CAAC;QAChDO,IAAI,EAAEV,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM;MACpC,CAAC,CAAC,CAAC;MACPQ,YAAY,EAAEX,MAAM,CAACY,QAAQ,CAAC,CAAC,CAACT,KAAK,CAAC,eAAe,CAAC;MACtDU,KAAK,EAAEb,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC;MACnCW,KAAK,EAAEd,MAAM,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC;MACnCY,OAAO,EAAEf,MAAM,CAACgB,IAAI,CAAC,CAAC,CAACb,KAAK,CAAC,SAAS;IAC1C,CAAC,CAAC,CAAC,CACV;EACL;AACJ;AAEA,OAAO,MAAMc,oBAAoB,GAAGzB,YAAY,CAAC0B,oBAAoB,CAAC;EAClEC,cAAc,EAAEzB,wBAAwB;EACxC0B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"domain/SchedulePrivateModel.js","sources":["../../src/domain/SchedulePrivateModel.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nclass SchedulePrivateModelImpl implements ModelFactory.Interface {\n public async execute(builder: ModelFactory.Builder) {\n return [\n builder\n .private({\n modelId: SCHEDULE_MODEL_ID,\n name: \"Webiny CMS Schedule\"\n })\n .fields(fields => ({\n namespace: fields.text().label(\"Namespace\"),\n actionType: fields.text().label(\"Action Type\"),\n targetId: fields.text().label(\"Target ID\"),\n scheduledBy: fields\n .object()\n .label(\"Scheduled By\")\n .fields(fields => ({\n id: fields.text().label(\"Identity ID\"),\n displayName: fields.text().label(\"Display Name\"),\n type: fields.text().label(\"Type\")\n })),\n scheduledFor: fields.datetime().label(\"Scheduled For\"),\n title: fields.text().label(\"Title\"),\n error: fields.text().label(\"Error\"),\n payload: fields.json().label(\"Payload\")\n }))\n ];\n }\n}\n\nexport const SchedulePrivateModel = ModelFactory.createImplementation({\n implementation: SchedulePrivateModelImpl,\n dependencies: []\n});\n"],"names":["SchedulePrivateModelImpl","builder","SCHEDULE_MODEL_ID","fields","SchedulePrivateModel","ModelFactory"],"mappings":";;AAGA,MAAMA;IACF,MAAa,QAAQC,OAA6B,EAAE;QAChD,OAAO;YACHA,QACK,OAAO,CAAC;gBACL,SAASC;gBACT,MAAM;YACV,GACC,MAAM,CAACC,CAAAA,SAAW;oBACf,WAAWA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC/B,YAAYA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAChC,UAAUA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC9B,aAAaA,OACR,MAAM,GACN,KAAK,CAAC,gBACN,MAAM,CAACA,CAAAA,SAAW;4BACf,IAAIA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACxB,aAAaA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACjC,MAAMA,OAAO,IAAI,GAAG,KAAK,CAAC;wBAC9B;oBACJ,cAAcA,OAAO,QAAQ,GAAG,KAAK,CAAC;oBACtC,OAAOA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC3B,OAAOA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC3B,SAASA,OAAO,IAAI,GAAG,KAAK,CAAC;gBACjC;SACP;IACL;AACJ;AAEO,MAAMC,uBAAuBC,aAAa,oBAAoB,CAAC;IAClE,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
@@ -1,9 +1,17 @@
1
1
  import { createCacheKey } from "@webiny/utils";
2
2
  import { SCHEDULE_ID_PREFIX } from "../constants.js";
3
- export class ScheduledActionId {
4
- static from(params) {
5
- return [SCHEDULE_ID_PREFIX, createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)].join("");
6
- }
3
+ class ScheduledActionId {
4
+ static from(params) {
5
+ return [
6
+ SCHEDULE_ID_PREFIX,
7
+ createCacheKey([
8
+ params.namespace,
9
+ params.actionType,
10
+ params.targetId
11
+ ]).slice(-24)
12
+ ].join("");
13
+ }
7
14
  }
15
+ export { ScheduledActionId };
8
16
 
9
17
  //# sourceMappingURL=ScheduledActionId.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createCacheKey","SCHEDULE_ID_PREFIX","ScheduledActionId","from","params","namespace","actionType","targetId","slice","join"],"sources":["ScheduledActionId.ts"],"sourcesContent":["import { createCacheKey } from \"@webiny/utils\";\nimport { SCHEDULE_ID_PREFIX } from \"~/constants.js\";\n\nexport interface IScheduledActionIdParams {\n namespace: string;\n actionType: string;\n targetId: string;\n}\n\nexport class ScheduledActionId {\n static from(params: IScheduledActionIdParams) {\n return [\n SCHEDULE_ID_PREFIX,\n createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)\n ].join(\"\");\n }\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,kBAAkB;AAQ3B,OAAO,MAAMC,iBAAiB,CAAC;EAC3B,OAAOC,IAAIA,CAACC,MAAgC,EAAE;IAC1C,OAAO,CACHH,kBAAkB,EAClBD,cAAc,CAAC,CAACI,MAAM,CAACC,SAAS,EAAED,MAAM,CAACE,UAAU,EAAEF,MAAM,CAACG,QAAQ,CAAC,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CACpF,CAACC,IAAI,CAAC,EAAE,CAAC;EACd;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"domain/ScheduledActionId.js","sources":["../../src/domain/ScheduledActionId.ts"],"sourcesContent":["import { createCacheKey } from \"@webiny/utils\";\nimport { SCHEDULE_ID_PREFIX } from \"~/constants.js\";\n\nexport interface IScheduledActionIdParams {\n namespace: string;\n actionType: string;\n targetId: string;\n}\n\nexport class ScheduledActionId {\n static from(params: IScheduledActionIdParams) {\n return [\n SCHEDULE_ID_PREFIX,\n createCacheKey([params.namespace, params.actionType, params.targetId]).slice(-24)\n ].join(\"\");\n }\n}\n"],"names":["ScheduledActionId","params","SCHEDULE_ID_PREFIX","createCacheKey"],"mappings":";;AASO,MAAMA;IACT,OAAO,KAAKC,MAAgC,EAAE;QAC1C,OAAO;YACHC;YACAC,eAAe;gBAACF,OAAO,SAAS;gBAAEA,OAAO,UAAU;gBAAEA,OAAO,QAAQ;aAAC,EAAE,KAAK,CAAC;SAChF,CAAC,IAAI,CAAC;IACX;AACJ"}
@@ -1,10 +1,9 @@
1
- export class ScheduledActionIdWithVersion {
2
- static from(id) {
3
- if (id.endsWith("#0001")) {
4
- return id;
1
+ class ScheduledActionIdWithVersion {
2
+ static from(id) {
3
+ if (id.endsWith("#0001")) return id;
4
+ return `${id}#0001`;
5
5
  }
6
- return `${id}#0001`;
7
- }
8
6
  }
7
+ export { ScheduledActionIdWithVersion };
9
8
 
10
9
  //# sourceMappingURL=ScheduledActionIdWithVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ScheduledActionIdWithVersion","from","id","endsWith"],"sources":["ScheduledActionIdWithVersion.ts"],"sourcesContent":["export class ScheduledActionIdWithVersion {\n static from(id: string) {\n if (id.endsWith(\"#0001\")) {\n return id;\n }\n\n return `${id}#0001`;\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,4BAA4B,CAAC;EACtC,OAAOC,IAAIA,CAACC,EAAU,EAAE;IACpB,IAAIA,EAAE,CAACC,QAAQ,CAAC,OAAO,CAAC,EAAE;MACtB,OAAOD,EAAE;IACb;IAEA,OAAO,GAAGA,EAAE,OAAO;EACvB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"domain/ScheduledActionIdWithVersion.js","sources":["../../src/domain/ScheduledActionIdWithVersion.ts"],"sourcesContent":["export class ScheduledActionIdWithVersion {\n static from(id: string) {\n if (id.endsWith(\"#0001\")) {\n return id;\n }\n\n return `${id}#0001`;\n }\n}\n"],"names":["ScheduledActionIdWithVersion","id"],"mappings":"AAAO,MAAMA;IACT,OAAO,KAAKC,EAAU,EAAE;QACpB,IAAIA,GAAG,QAAQ,CAAC,UACZ,OAAOA;QAGX,OAAO,GAAGA,GAAG,KAAK,CAAC;IACvB;AACJ"}
@@ -0,0 +1,16 @@
1
+ import type { IScheduledAction, IScheduledActionEntry } from "../shared/abstractions.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ export declare class ScheduledActionMapper {
4
+ static toAction<T extends GenericRecord = GenericRecord>(action: IScheduledActionEntry<T>): IScheduledAction<T>;
5
+ static toActions<T extends GenericRecord = GenericRecord>(actions: IScheduledActionEntry<T>[]): IScheduledAction<T>[];
6
+ static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>): {
7
+ id: string;
8
+ targetId: string;
9
+ namespace: string;
10
+ scheduledBy: import("~/shared/abstractions.js").Identity;
11
+ publishOn: Date | null;
12
+ unpublishOn: Date | null;
13
+ actionType: import("~/shared/abstractions.js").ScheduledActionType;
14
+ title: string;
15
+ };
16
+ }
@@ -0,0 +1,36 @@
1
+ import { parseIdentifier } from "@webiny/utils";
2
+ import { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from "../constants.js";
3
+ class ScheduledActionMapper {
4
+ static toAction(action) {
5
+ const { id: scheduleId } = parseIdentifier(action.id);
6
+ return {
7
+ id: scheduleId,
8
+ targetId: action.values.targetId,
9
+ namespace: action.values.namespace,
10
+ scheduledBy: action.values.scheduledBy,
11
+ scheduledFor: new Date(action.values.scheduledFor),
12
+ actionType: action.values.actionType,
13
+ title: action.values.title,
14
+ payload: action.values.payload,
15
+ error: action.values.error
16
+ };
17
+ }
18
+ static toActions(actions) {
19
+ return actions.map(ScheduledActionMapper.toAction);
20
+ }
21
+ static toGraphQL(action) {
22
+ return {
23
+ id: action.id,
24
+ targetId: action.targetId,
25
+ namespace: action.namespace,
26
+ scheduledBy: action.scheduledBy,
27
+ publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,
28
+ unpublishOn: action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,
29
+ actionType: action.actionType,
30
+ title: action.title
31
+ };
32
+ }
33
+ }
34
+ export { ScheduledActionMapper };
35
+
36
+ //# sourceMappingURL=ScheduledActionMapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain/ScheduledActionMapper.js","sources":["../../src/domain/ScheduledActionMapper.ts"],"sourcesContent":["import type { IScheduledAction, IScheduledActionEntry } from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\nexport class ScheduledActionMapper {\n static toAction<T extends GenericRecord = GenericRecord>(\n action: IScheduledActionEntry<T>\n ): IScheduledAction<T> {\n const { id: scheduleId } = parseIdentifier(action.id);\n return {\n id: scheduleId,\n targetId: action.values.targetId,\n namespace: action.values.namespace,\n scheduledBy: action.values.scheduledBy,\n scheduledFor: new Date(action.values.scheduledFor),\n actionType: action.values.actionType,\n title: action.values.title,\n payload: action.values.payload,\n error: action.values.error\n };\n }\n\n static toActions<T extends GenericRecord = GenericRecord>(\n actions: IScheduledActionEntry<T>[]\n ): IScheduledAction<T>[] {\n return actions.map(ScheduledActionMapper.toAction);\n }\n\n static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>) {\n return {\n id: action.id,\n targetId: action.targetId,\n namespace: action.namespace,\n scheduledBy: action.scheduledBy,\n publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,\n unpublishOn:\n action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,\n actionType: action.actionType,\n title: action.title\n };\n }\n}\n"],"names":["ScheduledActionMapper","action","scheduleId","parseIdentifier","Date","actions","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH"],"mappings":";;AAKO,MAAMA;IACT,OAAO,SACHC,MAAgC,EACb;QACnB,MAAM,EAAE,IAAIC,UAAU,EAAE,GAAGC,gBAAgBF,OAAO,EAAE;QACpD,OAAO;YACH,IAAIC;YACJ,UAAUD,OAAO,MAAM,CAAC,QAAQ;YAChC,WAAWA,OAAO,MAAM,CAAC,SAAS;YAClC,aAAaA,OAAO,MAAM,CAAC,WAAW;YACtC,cAAc,IAAIG,KAAKH,OAAO,MAAM,CAAC,YAAY;YACjD,YAAYA,OAAO,MAAM,CAAC,UAAU;YACpC,OAAOA,OAAO,MAAM,CAAC,KAAK;YAC1B,SAASA,OAAO,MAAM,CAAC,OAAO;YAC9B,OAAOA,OAAO,MAAM,CAAC,KAAK;QAC9B;IACJ;IAEA,OAAO,UACHI,OAAmC,EACd;QACrB,OAAOA,QAAQ,GAAG,CAACL,sBAAsB,QAAQ;IACrD;IAEA,OAAO,UAAmDC,MAA2B,EAAE;QACnF,OAAO;YACH,IAAIA,OAAO,EAAE;YACb,UAAUA,OAAO,QAAQ;YACzB,WAAWA,OAAO,SAAS;YAC3B,aAAaA,OAAO,WAAW;YAC/B,WAAWA,OAAO,UAAU,KAAKK,2BAA2BL,OAAO,YAAY,GAAG;YAClF,aACIA,OAAO,UAAU,KAAKM,6BAA6BN,OAAO,YAAY,GAAG;YAC7E,YAAYA,OAAO,UAAU;YAC7B,OAAOA,OAAO,KAAK;QACvB;IACJ;AACJ"}
@@ -1,4 +1,11 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
+ /**
3
+ * Not authorized error when user lacks permissions to manage scheduled actions.
4
+ */
5
+ export declare class NotAuthorizedError extends BaseError {
6
+ readonly code: "Scheduler/NotAuthorized";
7
+ constructor();
8
+ }
2
9
  /**
3
10
  * Scheduled action not found error
4
11
  */
@@ -24,7 +31,7 @@ export declare class InvalidScheduleDateError extends BaseError<{
24
31
  scheduleFor: string;
25
32
  }> {
26
33
  readonly code: "Scheduler/ScheduledAction/InvalidDate";
27
- constructor(scheduleFor: string);
34
+ constructor(scheduleFor: Date);
28
35
  }
29
36
  /**
30
37
  * Scheduler service error (EventBridge/cloud provider errors)
@@ -35,3 +42,14 @@ export declare class SchedulerServiceError extends BaseError<{
35
42
  readonly code: "Scheduler/Service/Error";
36
43
  constructor(error: Error);
37
44
  }
45
+ interface INamespaceHandlerNotFoundErrorData {
46
+ namespace: string;
47
+ }
48
+ /**
49
+ * Namespace handler not found error.
50
+ */
51
+ export declare class NamespaceHandlerNotFoundError extends BaseError<INamespaceHandlerNotFoundErrorData> {
52
+ readonly code: "Scheduler/NamespaceHandler/NotFound";
53
+ constructor(namespace: string);
54
+ }
55
+ export {};