@webiny/api-scheduler 0.0.0-unstable.61c048f412

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 (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/constants.d.ts +8 -0
  4. package/constants.js +10 -0
  5. package/constants.js.map +1 -0
  6. package/context.d.ts +7 -0
  7. package/context.js +41 -0
  8. package/context.js.map +1 -0
  9. package/createEventHandler.d.ts +13 -0
  10. package/createEventHandler.js +50 -0
  11. package/createEventHandler.js.map +1 -0
  12. package/createScheduler.d.ts +6 -0
  13. package/createScheduler.js +11 -0
  14. package/createScheduler.js.map +1 -0
  15. package/domain/SchedulePrivateModel.d.ts +8 -0
  16. package/domain/SchedulePrivateModel.js +29 -0
  17. package/domain/SchedulePrivateModel.js.map +1 -0
  18. package/domain/ScheduledActionId.d.ts +8 -0
  19. package/domain/ScheduledActionId.js +9 -0
  20. package/domain/ScheduledActionId.js.map +1 -0
  21. package/domain/ScheduledActionIdWithVersion.d.ts +3 -0
  22. package/domain/ScheduledActionIdWithVersion.js +10 -0
  23. package/domain/ScheduledActionIdWithVersion.js.map +1 -0
  24. package/domain/errors.d.ts +37 -0
  25. package/domain/errors.js +63 -0
  26. package/domain/errors.js.map +1 -0
  27. package/domain/isValidDate.d.ts +6 -0
  28. package/domain/isValidDate.js +13 -0
  29. package/domain/isValidDate.js.map +1 -0
  30. package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +26 -0
  31. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +74 -0
  32. package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -0
  33. package/features/CancelScheduledAction/abstractions.d.ts +24 -0
  34. package/features/CancelScheduledAction/abstractions.js +13 -0
  35. package/features/CancelScheduledAction/abstractions.js.map +1 -0
  36. package/features/CancelScheduledAction/feature.d.ts +7 -0
  37. package/features/CancelScheduledAction/feature.js +17 -0
  38. package/features/CancelScheduledAction/feature.js.map +1 -0
  39. package/features/CancelScheduledAction/index.d.ts +1 -0
  40. package/features/CancelScheduledAction/index.js +3 -0
  41. package/features/CancelScheduledAction/index.js.map +1 -0
  42. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +33 -0
  43. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +106 -0
  44. package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -0
  45. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +19 -0
  46. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +32 -0
  47. package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -0
  48. package/features/ExecuteScheduledAction/abstractions.d.ts +46 -0
  49. package/features/ExecuteScheduledAction/abstractions.js +41 -0
  50. package/features/ExecuteScheduledAction/abstractions.js.map +1 -0
  51. package/features/ExecuteScheduledAction/feature.d.ts +7 -0
  52. package/features/ExecuteScheduledAction/feature.js +19 -0
  53. package/features/ExecuteScheduledAction/feature.js.map +1 -0
  54. package/features/ExecuteScheduledAction/index.d.ts +1 -0
  55. package/features/ExecuteScheduledAction/index.js +3 -0
  56. package/features/ExecuteScheduledAction/index.js.map +1 -0
  57. package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +24 -0
  58. package/features/GetScheduledAction/GetScheduledActionUseCase.js +49 -0
  59. package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -0
  60. package/features/GetScheduledAction/abstractions.d.ts +26 -0
  61. package/features/GetScheduledAction/abstractions.js +14 -0
  62. package/features/GetScheduledAction/abstractions.js.map +1 -0
  63. package/features/GetScheduledAction/feature.d.ts +7 -0
  64. package/features/GetScheduledAction/feature.js +17 -0
  65. package/features/GetScheduledAction/feature.js.map +1 -0
  66. package/features/GetScheduledAction/index.d.ts +1 -0
  67. package/features/GetScheduledAction/index.js +3 -0
  68. package/features/GetScheduledAction/index.js.map +1 -0
  69. package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +27 -0
  70. package/features/ListScheduledActions/ListScheduledActionsUseCase.js +77 -0
  71. package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -0
  72. package/features/ListScheduledActions/abstractions.d.ts +49 -0
  73. package/features/ListScheduledActions/abstractions.js +15 -0
  74. package/features/ListScheduledActions/abstractions.js.map +1 -0
  75. package/features/ListScheduledActions/feature.d.ts +7 -0
  76. package/features/ListScheduledActions/feature.js +17 -0
  77. package/features/ListScheduledActions/feature.js.map +1 -0
  78. package/features/ListScheduledActions/index.d.ts +1 -0
  79. package/features/ListScheduledActions/index.js +3 -0
  80. package/features/ListScheduledActions/index.js.map +1 -0
  81. package/features/RunAction/RunActionUseCase.d.ts +23 -0
  82. package/features/RunAction/RunActionUseCase.js +37 -0
  83. package/features/RunAction/RunActionUseCase.js.map +1 -0
  84. package/features/RunAction/abstractions.d.ts +35 -0
  85. package/features/RunAction/abstractions.js +15 -0
  86. package/features/RunAction/abstractions.js.map +1 -0
  87. package/features/RunAction/feature.d.ts +7 -0
  88. package/features/RunAction/feature.js +17 -0
  89. package/features/RunAction/feature.js.map +1 -0
  90. package/features/RunAction/index.d.ts +1 -0
  91. package/features/RunAction/index.js +3 -0
  92. package/features/RunAction/index.js.map +1 -0
  93. package/features/ScheduleAction/ScheduleActionUseCase.d.ts +45 -0
  94. package/features/ScheduleAction/ScheduleActionUseCase.js +164 -0
  95. package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -0
  96. package/features/ScheduleAction/abstractions.d.ts +35 -0
  97. package/features/ScheduleAction/abstractions.js +13 -0
  98. package/features/ScheduleAction/abstractions.js.map +1 -0
  99. package/features/ScheduleAction/feature.d.ts +7 -0
  100. package/features/ScheduleAction/feature.js +17 -0
  101. package/features/ScheduleAction/feature.js.map +1 -0
  102. package/features/ScheduleAction/index.d.ts +1 -0
  103. package/features/ScheduleAction/index.js +3 -0
  104. package/features/ScheduleAction/index.js.map +1 -0
  105. package/features/SchedulerFeature.d.ts +8 -0
  106. package/features/SchedulerFeature.js +29 -0
  107. package/features/SchedulerFeature.js.map +1 -0
  108. package/features/SchedulerService/EventBridgeSchedulerService.d.ts +26 -0
  109. package/features/SchedulerService/EventBridgeSchedulerService.js +131 -0
  110. package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -0
  111. package/features/SchedulerService/VoidSchedulerService.d.ts +15 -0
  112. package/features/SchedulerService/VoidSchedulerService.js +31 -0
  113. package/features/SchedulerService/VoidSchedulerService.js.map +1 -0
  114. package/index.d.ts +10 -0
  115. package/index.js +13 -0
  116. package/index.js.map +1 -0
  117. package/manifest.d.ts +17 -0
  118. package/manifest.js +39 -0
  119. package/manifest.js.map +1 -0
  120. package/package.json +55 -0
  121. package/shared/abstractions.d.ts +77 -0
  122. package/shared/abstractions.js +32 -0
  123. package/shared/abstractions.js.map +1 -0
@@ -0,0 +1,35 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { IScheduledAction } from "../../shared/abstractions.js";
3
+ import { InvalidScheduleDateError, ScheduledActionPersistenceError, SchedulerServiceError } from "../../domain/errors.js";
4
+ import type { GenericRecord } from "@webiny/api/types.js";
5
+ /**
6
+ * ScheduleActionUseCase - Schedule an action for future execution
7
+ *
8
+ * Handles both new schedules and rescheduling (update) automatically:
9
+ * - If no schedule exists for the namespace+actionType+targetId combination: creates new schedule
10
+ * - If schedule already exists: updates the existing schedule (reschedule)
11
+ */
12
+ export interface IScheduleActionErrors {
13
+ persistence: ScheduledActionPersistenceError;
14
+ invalidDate: InvalidScheduleDateError;
15
+ schedulerService: SchedulerServiceError;
16
+ }
17
+ type ScheduleActionError = IScheduleActionErrors[keyof IScheduleActionErrors];
18
+ interface IScheduleActionParams<T extends GenericRecord> {
19
+ namespace: string;
20
+ actionType: string;
21
+ targetId: string;
22
+ scheduleFor: string;
23
+ title: string;
24
+ payload: T;
25
+ }
26
+ export interface IScheduleActionUseCase {
27
+ execute<T extends GenericRecord>(params: IScheduleActionParams<T>): Promise<Result<IScheduledAction<T>, ScheduleActionError>>;
28
+ }
29
+ export declare const ScheduleActionUseCase: import("@webiny/di").Abstraction<IScheduleActionUseCase>;
30
+ export declare namespace ScheduleActionUseCase {
31
+ type Interface = IScheduleActionUseCase;
32
+ type Params<T extends GenericRecord> = IScheduleActionParams<T>;
33
+ type Error = ScheduleActionError;
34
+ }
35
+ export {};
@@ -0,0 +1,13 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+
3
+ /**
4
+ * ScheduleActionUseCase - Schedule an action for future execution
5
+ *
6
+ * Handles both new schedules and rescheduling (update) automatically:
7
+ * - If no schedule exists for the namespace+actionType+targetId combination: creates new schedule
8
+ * - If schedule already exists: updates the existing schedule (reschedule)
9
+ */
10
+
11
+ export const ScheduleActionUseCase = createAbstraction("ScheduleActionUseCase");
12
+
13
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","ScheduleActionUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport {\n InvalidScheduleDateError,\n ScheduledActionPersistenceError,\n SchedulerServiceError\n} from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * ScheduleActionUseCase - Schedule an action for future execution\n *\n * Handles both new schedules and rescheduling (update) automatically:\n * - If no schedule exists for the namespace+actionType+targetId combination: creates new schedule\n * - If schedule already exists: updates the existing schedule (reschedule)\n */\n\nexport interface IScheduleActionErrors {\n persistence: ScheduledActionPersistenceError;\n invalidDate: InvalidScheduleDateError;\n schedulerService: SchedulerServiceError;\n}\n\ntype ScheduleActionError = IScheduleActionErrors[keyof IScheduleActionErrors];\n\ninterface IScheduleActionParams<T extends GenericRecord> {\n namespace: string;\n actionType: string;\n targetId: string;\n scheduleFor: string;\n title: string;\n payload: T;\n}\n\nexport interface IScheduleActionUseCase {\n execute<T extends GenericRecord>(\n params: IScheduleActionParams<T>\n ): Promise<Result<IScheduledAction<T>, ScheduleActionError>>;\n}\n\nexport const ScheduleActionUseCase =\n createAbstraction<IScheduleActionUseCase>(\"ScheduleActionUseCase\");\n\nexport namespace ScheduleActionUseCase {\n export type Interface = IScheduleActionUseCase;\n export type Params<T extends GenericRecord> = IScheduleActionParams<T>;\n export type Error = ScheduleActionError;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;;AAS/D;AACA;AACA;AACA;AACA;AACA;AACA;;AAyBA,OAAO,MAAMC,qBAAqB,GAC9BD,iBAAiB,CAAyB,uBAAuB,CAAC","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * ScheduleAction Feature
3
+ *
4
+ * Provides the ability to schedule actions for future execution.
5
+ * Handles both creating new schedules and updating existing ones (reschedule).
6
+ */
7
+ export declare const ScheduleActionFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -0,0 +1,17 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ScheduleActionUseCase } from "./ScheduleActionUseCase.js";
3
+
4
+ /**
5
+ * ScheduleAction Feature
6
+ *
7
+ * Provides the ability to schedule actions for future execution.
8
+ * Handles both creating new schedules and updating existing ones (reschedule).
9
+ */
10
+ export const ScheduleActionFeature = createFeature({
11
+ name: "ScheduleAction",
12
+ register(container) {
13
+ container.register(ScheduleActionUseCase);
14
+ }
15
+ });
16
+
17
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","ScheduleActionUseCase","ScheduleActionFeature","name","register","container"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ScheduleActionUseCase } from \"./ScheduleActionUseCase.js\";\n\n/**\n * ScheduleAction Feature\n *\n * Provides the ability to schedule actions for future execution.\n * Handles both creating new schedules and updating existing ones (reschedule).\n */\nexport const ScheduleActionFeature = createFeature({\n name: \"ScheduleAction\",\n register(container) {\n container.register(ScheduleActionUseCase);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,qBAAqB;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,GAAGF,aAAa,CAAC;EAC/CG,IAAI,EAAE,gBAAgB;EACtBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,qBAAqB,CAAC;EAC7C;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export * from "./abstractions.js";
@@ -0,0 +1,3 @@
1
+ export * from "./abstractions.js";
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./abstractions.js\";\n"],"mappings":"AAAA","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Main Scheduler Feature
3
+ *
4
+ * Registers all scheduler use cases and the composite handler.
5
+ * Individual handler implementations are registered by consumer packages
6
+ * (e.g., api-headless-cms-scheduler registers CMS-specific handlers).
7
+ */
8
+ export declare const SchedulerFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -0,0 +1,29 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ScheduleActionFeature } from "./ScheduleAction/feature.js";
3
+ import { GetScheduledActionFeature } from "./GetScheduledAction/feature.js";
4
+ import { ListScheduledActionsFeature } from "./ListScheduledActions/feature.js";
5
+ import { CancelScheduledActionFeature } from "./CancelScheduledAction/feature.js";
6
+ import { ExecuteScheduledActionFeature } from "./ExecuteScheduledAction/feature.js";
7
+ import { RunActionFeature } from "./RunAction/feature.js";
8
+
9
+ /**
10
+ * Main Scheduler Feature
11
+ *
12
+ * Registers all scheduler use cases and the composite handler.
13
+ * Individual handler implementations are registered by consumer packages
14
+ * (e.g., api-headless-cms-scheduler registers CMS-specific handlers).
15
+ */
16
+ export const SchedulerFeature = createFeature({
17
+ name: "Scheduler",
18
+ register(container) {
19
+ // Register all features
20
+ ScheduleActionFeature.register(container);
21
+ GetScheduledActionFeature.register(container);
22
+ ListScheduledActionsFeature.register(container);
23
+ CancelScheduledActionFeature.register(container);
24
+ ExecuteScheduledActionFeature.register(container);
25
+ RunActionFeature.register(container);
26
+ }
27
+ });
28
+
29
+ //# sourceMappingURL=SchedulerFeature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","ScheduleActionFeature","GetScheduledActionFeature","ListScheduledActionsFeature","CancelScheduledActionFeature","ExecuteScheduledActionFeature","RunActionFeature","SchedulerFeature","name","register","container"],"sources":["SchedulerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ScheduleActionFeature } from \"./ScheduleAction/feature.js\";\nimport { GetScheduledActionFeature } from \"./GetScheduledAction/feature.js\";\nimport { ListScheduledActionsFeature } from \"./ListScheduledActions/feature.js\";\nimport { CancelScheduledActionFeature } from \"./CancelScheduledAction/feature.js\";\nimport { ExecuteScheduledActionFeature } from \"./ExecuteScheduledAction/feature.js\";\nimport { RunActionFeature } from \"~/features/RunAction/feature.js\";\n\n/**\n * Main Scheduler Feature\n *\n * Registers all scheduler use cases and the composite handler.\n * Individual handler implementations are registered by consumer packages\n * (e.g., api-headless-cms-scheduler registers CMS-specific handlers).\n */\nexport const SchedulerFeature = createFeature({\n name: \"Scheduler\",\n register(container) {\n // Register all features\n ScheduleActionFeature.register(container);\n GetScheduledActionFeature.register(container);\n ListScheduledActionsFeature.register(container);\n CancelScheduledActionFeature.register(container);\n ExecuteScheduledActionFeature.register(container);\n RunActionFeature.register(container);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,qBAAqB;AAC9B,SAASC,yBAAyB;AAClC,SAASC,2BAA2B;AACpC,SAASC,4BAA4B;AACrC,SAASC,6BAA6B;AACtC,SAASC,gBAAgB;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAGP,aAAa,CAAC;EAC1CQ,IAAI,EAAE,WAAW;EACjBC,QAAQA,CAACC,SAAS,EAAE;IAChB;IACAT,qBAAqB,CAACQ,QAAQ,CAACC,SAAS,CAAC;IACzCR,yBAAyB,CAACO,QAAQ,CAACC,SAAS,CAAC;IAC7CP,2BAA2B,CAACM,QAAQ,CAACC,SAAS,CAAC;IAC/CN,4BAA4B,CAACK,QAAQ,CAACC,SAAS,CAAC;IAChDL,6BAA6B,CAACI,QAAQ,CAACC,SAAS,CAAC;IACjDJ,gBAAgB,CAACG,QAAQ,CAACC,SAAS,CAAC;EACxC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import { type ISchedulerServiceCreateParams, type ISchedulerServiceUpdateParams, SchedulerService } from "../../shared/abstractions.js";
2
+ import { type SchedulerClient } from "@webiny/aws-sdk/client-scheduler";
3
+ export interface ISchedulerConfig {
4
+ lambdaArn: string;
5
+ roleArn: string;
6
+ }
7
+ /**
8
+ * AWS EventBridge Scheduler implementation
9
+ *
10
+ * This is the AWS-specific implementation of the cloud-agnostic SchedulerService abstraction.
11
+ *
12
+ * Manages schedules in AWS EventBridge Scheduler for triggering Lambda functions
13
+ * at specified future times.
14
+ */
15
+ export declare class EventBridgeSchedulerService implements SchedulerService.Interface {
16
+ private getClient;
17
+ private config;
18
+ constructor(getClient: (config?: any) => Pick<SchedulerClient, "send">, config: ISchedulerConfig);
19
+ create(params: ISchedulerServiceCreateParams): Promise<void>;
20
+ update(params: ISchedulerServiceUpdateParams): Promise<void>;
21
+ delete(id: string): Promise<void>;
22
+ exists(id: string): Promise<boolean>;
23
+ private createScheduleExpression;
24
+ private createScheduledActionEventInput;
25
+ private createScheduledActionEventPayload;
26
+ }
@@ -0,0 +1,131 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { CreateScheduleCommand, DeleteScheduleCommand, GetScheduleCommand, UpdateScheduleCommand } from "@webiny/aws-sdk/client-scheduler";
3
+ import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "../../constants.js";
4
+ /**
5
+ * AWS EventBridge Scheduler implementation
6
+ *
7
+ * This is the AWS-specific implementation of the cloud-agnostic SchedulerService abstraction.
8
+ *
9
+ * Manages schedules in AWS EventBridge Scheduler for triggering Lambda functions
10
+ * at specified future times.
11
+ */
12
+ export class EventBridgeSchedulerService {
13
+ constructor(getClient, config) {
14
+ this.getClient = getClient;
15
+ this.config = config;
16
+ }
17
+ async create(params) {
18
+ const {
19
+ id,
20
+ scheduleFor
21
+ } = params;
22
+
23
+ // Validate date is in future
24
+ if (scheduleFor <= new Date()) {
25
+ throw new WebinyError(`Cannot create a schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
26
+ scheduleFor,
27
+ id
28
+ });
29
+ }
30
+ const client = this.getClient();
31
+
32
+ // Check if schedule already exists (for auto-update logic)
33
+ const exists = await this.exists(id);
34
+ if (exists) {
35
+ return this.update(params);
36
+ }
37
+ await client.send(new CreateScheduleCommand({
38
+ Name: id,
39
+ ScheduleExpression: this.createScheduleExpression(scheduleFor),
40
+ FlexibleTimeWindow: {
41
+ Mode: "OFF"
42
+ },
43
+ Target: {
44
+ Arn: this.config.lambdaArn,
45
+ RoleArn: this.config.roleArn,
46
+ Input: this.createScheduledActionEventInput(params)
47
+ },
48
+ ActionAfterCompletion: "DELETE" // Auto-cleanup after execution
49
+ }));
50
+ }
51
+ async update(params) {
52
+ const {
53
+ id,
54
+ scheduleFor
55
+ } = params;
56
+
57
+ // Validate date is in future
58
+ if (scheduleFor <= new Date()) {
59
+ throw new WebinyError(`Cannot update an existing schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
60
+ scheduleFor,
61
+ id
62
+ });
63
+ }
64
+ const client = this.getClient();
65
+ await client.send(new UpdateScheduleCommand({
66
+ Name: id,
67
+ ScheduleExpression: this.createScheduleExpression(scheduleFor),
68
+ FlexibleTimeWindow: {
69
+ Mode: "OFF"
70
+ },
71
+ Target: {
72
+ Arn: this.config.lambdaArn,
73
+ RoleArn: this.config.roleArn,
74
+ Input: this.createScheduledActionEventInput(params)
75
+ },
76
+ ActionAfterCompletion: "DELETE"
77
+ }));
78
+ }
79
+ async delete(id) {
80
+ const client = this.getClient();
81
+ const exists = await this.exists(id);
82
+ if (!exists) {
83
+ throw new WebinyError(`Cannot delete schedule "${id}" because it does not exist.`);
84
+ }
85
+ try {
86
+ await client.send(new DeleteScheduleCommand({
87
+ Name: id
88
+ }));
89
+ } catch (ex) {
90
+ if (ex.name === "ResourceNotFoundException") {
91
+ return;
92
+ }
93
+ throw WebinyError.from(ex);
94
+ }
95
+ }
96
+ async exists(id) {
97
+ const client = this.getClient();
98
+ try {
99
+ await client.send(new GetScheduleCommand({
100
+ Name: id
101
+ }));
102
+ return true;
103
+ } catch (ex) {
104
+ if (ex.name === "ResourceNotFoundException") {
105
+ return false;
106
+ }
107
+ throw ex;
108
+ }
109
+ }
110
+ createScheduleExpression(scheduleFor) {
111
+ // Format: at(YYYY-MM-DDTHH:mm:ss) - EventBridge expects this format
112
+ return `at(${scheduleFor.toISOString().replace(/\.\d{3}Z$/, "")})`;
113
+ }
114
+ createScheduledActionEventInput(params) {
115
+ return JSON.stringify({
116
+ [SCHEDULED_ACTION_EVENT_IDENTIFIER]: this.createScheduledActionEventPayload(params)
117
+ });
118
+ }
119
+ createScheduledActionEventPayload(params) {
120
+ const {
121
+ id,
122
+ scheduleFor
123
+ } = params;
124
+ return {
125
+ id,
126
+ scheduleFor: scheduleFor.toISOString()
127
+ };
128
+ }
129
+ }
130
+
131
+ //# sourceMappingURL=EventBridgeSchedulerService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WebinyError","CreateScheduleCommand","DeleteScheduleCommand","GetScheduleCommand","UpdateScheduleCommand","SCHEDULED_ACTION_EVENT_IDENTIFIER","EventBridgeSchedulerService","constructor","getClient","config","create","params","id","scheduleFor","Date","client","exists","update","send","Name","ScheduleExpression","createScheduleExpression","FlexibleTimeWindow","Mode","Target","Arn","lambdaArn","RoleArn","roleArn","Input","createScheduledActionEventInput","ActionAfterCompletion","delete","ex","name","from","toISOString","replace","JSON","stringify","createScheduledActionEventPayload"],"sources":["EventBridgeSchedulerService.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport {\n type ISchedulerServiceCreateParams,\n type ISchedulerServiceUpdateParams,\n SchedulerService\n} from \"~/shared/abstractions.js\";\nimport {\n CreateScheduleCommand,\n DeleteScheduleCommand,\n GetScheduleCommand,\n type SchedulerClient,\n UpdateScheduleCommand\n} from \"@webiny/aws-sdk/client-scheduler\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport type { IScheduledActionEventPayload } from \"~/createEventHandler.js\";\n\nexport interface ISchedulerConfig {\n lambdaArn: string;\n roleArn: string;\n}\n\n/**\n * AWS EventBridge Scheduler implementation\n *\n * This is the AWS-specific implementation of the cloud-agnostic SchedulerService abstraction.\n *\n * Manages schedules in AWS EventBridge Scheduler for triggering Lambda functions\n * at specified future times.\n */\nexport class EventBridgeSchedulerService implements SchedulerService.Interface {\n public constructor(\n private getClient: (config?: any) => Pick<SchedulerClient, \"send\">,\n private config: ISchedulerConfig\n ) {}\n\n public async create(params: ISchedulerServiceCreateParams): Promise<void> {\n const { id, scheduleFor } = params;\n\n // Validate date is in future\n if (scheduleFor <= new Date()) {\n throw new WebinyError(\n `Cannot create a schedule for \"${id}\" with date in the past`,\n \"INVALID_SCHEDULE_DATE\",\n {\n scheduleFor,\n id\n }\n );\n }\n\n const client = this.getClient();\n\n // Check if schedule already exists (for auto-update logic)\n const exists = await this.exists(id);\n if (exists) {\n return this.update(params);\n }\n\n await client.send(\n new CreateScheduleCommand({\n Name: id,\n ScheduleExpression: this.createScheduleExpression(scheduleFor),\n FlexibleTimeWindow: {\n Mode: \"OFF\"\n },\n Target: {\n Arn: this.config.lambdaArn,\n RoleArn: this.config.roleArn,\n Input: this.createScheduledActionEventInput(params)\n },\n ActionAfterCompletion: \"DELETE\" // Auto-cleanup after execution\n })\n );\n }\n\n public async update(params: ISchedulerServiceUpdateParams): Promise<void> {\n const { id, scheduleFor } = params;\n\n // Validate date is in future\n if (scheduleFor <= new Date()) {\n throw new WebinyError(\n `Cannot update an existing schedule for \"${id}\" with date in the past`,\n \"INVALID_SCHEDULE_DATE\",\n {\n scheduleFor,\n id\n }\n );\n }\n\n const client = this.getClient();\n\n await client.send(\n new UpdateScheduleCommand({\n Name: id,\n ScheduleExpression: this.createScheduleExpression(scheduleFor),\n FlexibleTimeWindow: {\n Mode: \"OFF\"\n },\n Target: {\n Arn: this.config.lambdaArn,\n RoleArn: this.config.roleArn,\n Input: this.createScheduledActionEventInput(params)\n },\n ActionAfterCompletion: \"DELETE\"\n })\n );\n }\n\n public async delete(id: string): Promise<void> {\n const client = this.getClient();\n\n const exists = await this.exists(id);\n if (!exists) {\n throw new WebinyError(`Cannot delete schedule \"${id}\" because it does not exist.`);\n }\n\n try {\n await client.send(new DeleteScheduleCommand({ Name: id }));\n } catch (ex) {\n if (ex.name === \"ResourceNotFoundException\") {\n return;\n }\n throw WebinyError.from(ex);\n }\n }\n\n public async exists(id: string): Promise<boolean> {\n const client = this.getClient();\n\n try {\n await client.send(new GetScheduleCommand({ Name: id }));\n return true;\n } catch (ex) {\n if (ex.name === \"ResourceNotFoundException\") {\n return false;\n }\n throw ex;\n }\n }\n\n private createScheduleExpression(scheduleFor: Date): string {\n // Format: at(YYYY-MM-DDTHH:mm:ss) - EventBridge expects this format\n return `at(${scheduleFor.toISOString().replace(/\\.\\d{3}Z$/, \"\")})`;\n }\n\n private createScheduledActionEventInput(\n params: ISchedulerServiceCreateParams | ISchedulerServiceUpdateParams\n ): string {\n return JSON.stringify({\n [SCHEDULED_ACTION_EVENT_IDENTIFIER]: this.createScheduledActionEventPayload(params)\n });\n }\n\n private createScheduledActionEventPayload(\n params: ISchedulerServiceCreateParams | ISchedulerServiceUpdateParams\n ): IScheduledActionEventPayload {\n const { id, scheduleFor } = params;\n\n return {\n id,\n scheduleFor: scheduleFor.toISOString()\n };\n }\n}\n"],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import { type ISchedulerServiceCreateParams, type ISchedulerServiceUpdateParams, SchedulerService } from "../../shared/abstractions.js";
2
+ export interface IVoidSchedulerServiceParams {
3
+ create?: (params: ISchedulerServiceCreateParams) => Promise<void>;
4
+ update?: (params: ISchedulerServiceUpdateParams) => Promise<void>;
5
+ delete?: (id: string) => Promise<void>;
6
+ exists?: (id: string) => Promise<boolean>;
7
+ }
8
+ export declare class VoidSchedulerService implements SchedulerService.Interface {
9
+ private readonly callbacks;
10
+ constructor(callbacks?: IVoidSchedulerServiceParams);
11
+ create(params: ISchedulerServiceCreateParams): Promise<void>;
12
+ update(params: ISchedulerServiceUpdateParams): Promise<void>;
13
+ delete(id: string): Promise<void>;
14
+ exists(id: string): Promise<boolean>;
15
+ }
@@ -0,0 +1,31 @@
1
+ export class VoidSchedulerService {
2
+ constructor(callbacks) {
3
+ this.callbacks = callbacks;
4
+ }
5
+ async create(params) {
6
+ if (!this.callbacks?.create) {
7
+ return;
8
+ }
9
+ return this.callbacks?.create(params);
10
+ }
11
+ async update(params) {
12
+ if (!this.callbacks?.update) {
13
+ return;
14
+ }
15
+ return this.callbacks?.update(params);
16
+ }
17
+ async delete(id) {
18
+ if (!this.callbacks?.delete) {
19
+ return;
20
+ }
21
+ return this.callbacks?.delete(id);
22
+ }
23
+ async exists(id) {
24
+ if (!this.callbacks?.exists) {
25
+ return false;
26
+ }
27
+ return this.callbacks?.exists(id);
28
+ }
29
+ }
30
+
31
+ //# sourceMappingURL=VoidSchedulerService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VoidSchedulerService","constructor","callbacks","create","params","update","delete","id","exists"],"sources":["VoidSchedulerService.ts"],"sourcesContent":["import {\n type ISchedulerServiceCreateParams,\n type ISchedulerServiceUpdateParams,\n SchedulerService\n} from \"~/shared/abstractions.js\";\n\nexport interface IVoidSchedulerServiceParams {\n create?: (params: ISchedulerServiceCreateParams) => Promise<void>;\n update?: (params: ISchedulerServiceUpdateParams) => Promise<void>;\n delete?: (id: string) => Promise<void>;\n exists?: (id: string) => Promise<boolean>;\n}\n\nexport class VoidSchedulerService implements SchedulerService.Interface {\n private readonly callbacks: IVoidSchedulerServiceParams | undefined;\n\n public constructor(callbacks?: IVoidSchedulerServiceParams) {\n this.callbacks = callbacks;\n }\n\n public async create(params: ISchedulerServiceCreateParams): Promise<void> {\n if (!this.callbacks?.create) {\n return;\n }\n return this.callbacks?.create(params);\n }\n\n public async update(params: ISchedulerServiceUpdateParams): Promise<void> {\n if (!this.callbacks?.update) {\n return;\n }\n return this.callbacks?.update(params);\n }\n\n public async delete(id: string): Promise<void> {\n if (!this.callbacks?.delete) {\n return;\n }\n return this.callbacks?.delete(id);\n }\n\n public async exists(id: string): Promise<boolean> {\n if (!this.callbacks?.exists) {\n return false;\n }\n return this.callbacks?.exists(id);\n }\n}\n"],"mappings":"AAaA,OAAO,MAAMA,oBAAoB,CAAuC;EAG7DC,WAAWA,CAACC,SAAuC,EAAE;IACxD,IAAI,CAACA,SAAS,GAAGA,SAAS;EAC9B;EAEA,MAAaC,MAAMA,CAACC,MAAqC,EAAiB;IACtE,IAAI,CAAC,IAAI,CAACF,SAAS,EAAEC,MAAM,EAAE;MACzB;IACJ;IACA,OAAO,IAAI,CAACD,SAAS,EAAEC,MAAM,CAACC,MAAM,CAAC;EACzC;EAEA,MAAaC,MAAMA,CAACD,MAAqC,EAAiB;IACtE,IAAI,CAAC,IAAI,CAACF,SAAS,EAAEG,MAAM,EAAE;MACzB;IACJ;IACA,OAAO,IAAI,CAACH,SAAS,EAAEG,MAAM,CAACD,MAAM,CAAC;EACzC;EAEA,MAAaE,MAAMA,CAACC,EAAU,EAAiB;IAC3C,IAAI,CAAC,IAAI,CAACL,SAAS,EAAEI,MAAM,EAAE;MACzB;IACJ;IACA,OAAO,IAAI,CAACJ,SAAS,EAAEI,MAAM,CAACC,EAAE,CAAC;EACrC;EAEA,MAAaC,MAAMA,CAACD,EAAU,EAAoB;IAC9C,IAAI,CAAC,IAAI,CAACL,SAAS,EAAEM,MAAM,EAAE;MACzB,OAAO,KAAK;IAChB;IACA,OAAO,IAAI,CAACN,SAAS,EAAEM,MAAM,CAACD,EAAE,CAAC;EACrC;AACJ","ignoreList":[]}
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export { SchedulerService, ScheduledActionModel, ScheduledActionHandler } from "./shared/abstractions.js";
2
+ export type { IScheduledAction } from "./shared/abstractions.js";
3
+ export { ScheduledActionId } from "./domain/ScheduledActionId.js";
4
+ export { createScheduler } from "./createScheduler.js";
5
+ export * from "./features/ScheduleAction/index.js";
6
+ export * from "./features/GetScheduledAction/index.js";
7
+ export * from "./features/ListScheduledActions/index.js";
8
+ export * from "./features/CancelScheduledAction/index.js";
9
+ export * from "./features/ExecuteScheduledAction/index.js";
10
+ export * from "./features/RunAction/index.js";
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export { SchedulerService, ScheduledActionModel, ScheduledActionHandler } from "./shared/abstractions.js";
2
+ export { ScheduledActionId } from "./domain/ScheduledActionId.js";
3
+ export { createScheduler } from "./createScheduler.js";
4
+
5
+ // Feature abstractions (for use case dependencies)
6
+ export * from "./features/ScheduleAction/index.js";
7
+ export * from "./features/GetScheduledAction/index.js";
8
+ export * from "./features/ListScheduledActions/index.js";
9
+ export * from "./features/CancelScheduledAction/index.js";
10
+ export * from "./features/ExecuteScheduledAction/index.js";
11
+ export * from "./features/RunAction/index.js";
12
+
13
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SchedulerService","ScheduledActionModel","ScheduledActionHandler","ScheduledActionId","createScheduler"],"sources":["index.ts"],"sourcesContent":["export {\n SchedulerService,\n ScheduledActionModel,\n ScheduledActionHandler\n} from \"./shared/abstractions.js\";\n\nexport type { IScheduledAction } from \"./shared/abstractions.js\";\n\nexport { ScheduledActionId } from \"./domain/ScheduledActionId.js\";\nexport { createScheduler } from \"./createScheduler.js\";\n\n// Feature abstractions (for use case dependencies)\nexport * from \"./features/ScheduleAction/index.js\";\nexport * from \"./features/GetScheduledAction/index.js\";\nexport * from \"./features/ListScheduledActions/index.js\";\nexport * from \"./features/CancelScheduledAction/index.js\";\nexport * from \"./features/ExecuteScheduledAction/index.js\";\nexport * from \"./features/RunAction/index.js\";\n"],"mappings":"AAAA,SACIA,gBAAgB,EAChBC,oBAAoB,EACpBC,sBAAsB;AAK1B,SAASC,iBAAiB;AAC1B,SAASC,eAAe;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
package/manifest.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ export interface IGetManifestErrorResult {
3
+ error: Error;
4
+ data?: never;
5
+ }
6
+ export interface IGetManifestSuccessResult {
7
+ data: {
8
+ lambdaArn: string;
9
+ roleArn: string;
10
+ };
11
+ error?: never;
12
+ }
13
+ export type IGetManifestResult = IGetManifestSuccessResult | IGetManifestErrorResult;
14
+ export interface IGetManifestParams {
15
+ client: DynamoDBDocument;
16
+ }
17
+ export declare const getManifest: (params: IGetManifestParams) => Promise<IGetManifestResult>;
package/manifest.js ADDED
@@ -0,0 +1,39 @@
1
+ import { ServiceDiscovery } from "@webiny/api";
2
+ import { createZodError } from "@webiny/utils";
3
+ import zod from "zod";
4
+ const schema = zod.object({
5
+ scheduler: zod.object({
6
+ lambdaArn: zod.string(),
7
+ roleArn: zod.string()
8
+ })
9
+ });
10
+ export const getManifest = async params => {
11
+ try {
12
+ ServiceDiscovery.setDocumentClient(params.client);
13
+ const manifest = await ServiceDiscovery.load();
14
+ if (!manifest) {
15
+ return {
16
+ error: new Error("Manifest could not be loaded.")
17
+ };
18
+ } else if (!manifest.scheduler) {
19
+ return {
20
+ error: new Error("Scheduler not found in the Manifest.")
21
+ };
22
+ }
23
+ const result = await schema.safeParseAsync(manifest);
24
+ if (!result.success) {
25
+ return {
26
+ error: createZodError(result.error)
27
+ };
28
+ }
29
+ return {
30
+ data: result.data.scheduler
31
+ };
32
+ } catch (ex) {
33
+ return {
34
+ error: ex
35
+ };
36
+ }
37
+ };
38
+
39
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ServiceDiscovery","createZodError","zod","schema","object","scheduler","lambdaArn","string","roleArn","getManifest","params","setDocumentClient","client","manifest","load","error","Error","result","safeParseAsync","success","data","ex"],"sources":["manifest.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport zod from \"zod\";\n\nconst schema = zod.object({\n scheduler: zod.object({\n lambdaArn: zod.string(),\n roleArn: zod.string()\n })\n});\n\nexport interface IGetManifestErrorResult {\n error: Error;\n data?: never;\n}\n\nexport interface IGetManifestSuccessResult {\n data: {\n lambdaArn: string;\n roleArn: string;\n };\n error?: never;\n}\n\nexport type IGetManifestResult = IGetManifestSuccessResult | IGetManifestErrorResult;\n\nexport interface IGetManifestParams {\n client: DynamoDBDocument;\n}\n\nexport const getManifest = async (params: IGetManifestParams): Promise<IGetManifestResult> => {\n try {\n ServiceDiscovery.setDocumentClient(params.client);\n const manifest = await ServiceDiscovery.load();\n if (!manifest) {\n return {\n error: new Error(\"Manifest could not be loaded.\")\n };\n } else if (!manifest.scheduler) {\n return {\n error: new Error(\"Scheduler not found in the Manifest.\")\n };\n }\n\n const result = await schema.safeParseAsync(manifest);\n if (!result.success) {\n return {\n error: createZodError(result.error)\n };\n }\n\n return {\n data: result.data.scheduler\n };\n } catch (ex) {\n return {\n error: ex\n };\n }\n};\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,aAAa;AAE9C,SAASC,cAAc,QAAQ,eAAe;AAC9C,OAAOC,GAAG,MAAM,KAAK;AAErB,MAAMC,MAAM,GAAGD,GAAG,CAACE,MAAM,CAAC;EACtBC,SAAS,EAAEH,GAAG,CAACE,MAAM,CAAC;IAClBE,SAAS,EAAEJ,GAAG,CAACK,MAAM,CAAC,CAAC;IACvBC,OAAO,EAAEN,GAAG,CAACK,MAAM,CAAC;EACxB,CAAC;AACL,CAAC,CAAC;AAqBF,OAAO,MAAME,WAAW,GAAG,MAAOC,MAA0B,IAAkC;EAC1F,IAAI;IACAV,gBAAgB,CAACW,iBAAiB,CAACD,MAAM,CAACE,MAAM,CAAC;IACjD,MAAMC,QAAQ,GAAG,MAAMb,gBAAgB,CAACc,IAAI,CAAC,CAAC;IAC9C,IAAI,CAACD,QAAQ,EAAE;MACX,OAAO;QACHE,KAAK,EAAE,IAAIC,KAAK,CAAC,+BAA+B;MACpD,CAAC;IACL,CAAC,MAAM,IAAI,CAACH,QAAQ,CAACR,SAAS,EAAE;MAC5B,OAAO;QACHU,KAAK,EAAE,IAAIC,KAAK,CAAC,sCAAsC;MAC3D,CAAC;IACL;IAEA,MAAMC,MAAM,GAAG,MAAMd,MAAM,CAACe,cAAc,CAACL,QAAQ,CAAC;IACpD,IAAI,CAACI,MAAM,CAACE,OAAO,EAAE;MACjB,OAAO;QACHJ,KAAK,EAAEd,cAAc,CAACgB,MAAM,CAACF,KAAK;MACtC,CAAC;IACL;IAEA,OAAO;MACHK,IAAI,EAAEH,MAAM,CAACG,IAAI,CAACf;IACtB,CAAC;EACL,CAAC,CAAC,OAAOgB,EAAE,EAAE;IACT,OAAO;MACHN,KAAK,EAAEM;IACX,CAAC;EACL;AACJ,CAAC","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@webiny/api-scheduler",
3
+ "version": "0.0.0-unstable.61c048f412",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/webiny/webiny-js.git",
9
+ "directory": "packages/api-scheduler"
10
+ },
11
+ "keywords": [
12
+ "scheduler:base"
13
+ ],
14
+ "author": "Webiny Ltd",
15
+ "description": "A generic action scheduler.",
16
+ "license": "MIT",
17
+ "exports": {
18
+ "./features/ScheduleAction": "./features/ScheduleAction/index.js",
19
+ "./features/GetScheduledAction": "./features/GetScheduledAction/index.js",
20
+ "./features/ListScheduledActions": "./features/ListScheduledActions/index.js",
21
+ "./features/CancelScheduledAction": "./features/CancelScheduledAction/index.js",
22
+ "./features/ExecuteScheduledAction": "./features/ExecuteScheduledAction/index.js",
23
+ ".": "./index.js"
24
+ },
25
+ "dependencies": {
26
+ "@webiny/api": "0.0.0-unstable.61c048f412",
27
+ "@webiny/api-core": "0.0.0-unstable.61c048f412",
28
+ "@webiny/api-headless-cms": "0.0.0-unstable.61c048f412",
29
+ "@webiny/aws-sdk": "0.0.0-unstable.61c048f412",
30
+ "@webiny/error": "0.0.0-unstable.61c048f412",
31
+ "@webiny/feature": "0.0.0-unstable.61c048f412",
32
+ "@webiny/handler-graphql": "0.0.0-unstable.61c048f412",
33
+ "@webiny/plugins": "0.0.0-unstable.61c048f412",
34
+ "@webiny/utils": "0.0.0-unstable.61c048f412",
35
+ "zod": "3.25.76"
36
+ },
37
+ "devDependencies": {
38
+ "@webiny/build-tools": "0.0.0-unstable.61c048f412",
39
+ "@webiny/db-dynamodb": "0.0.0-unstable.61c048f412",
40
+ "@webiny/handler": "0.0.0-unstable.61c048f412",
41
+ "@webiny/handler-aws": "0.0.0-unstable.61c048f412",
42
+ "@webiny/project-utils": "0.0.0-unstable.61c048f412",
43
+ "@webiny/wcp": "0.0.0-unstable.61c048f412",
44
+ "aws-sdk-client-mock": "4.1.0",
45
+ "jest-dynalite": "3.6.1",
46
+ "rimraf": "6.1.2",
47
+ "typescript": "5.9.3",
48
+ "vitest": "3.2.4"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "directory": "dist"
53
+ },
54
+ "gitHead": "61c048f412d6b4aa70c1d105aab21e3fa69730f3"
55
+ }
@@ -0,0 +1,77 @@
1
+ import type { CmsModel } from "@webiny/api-headless-cms/types/model.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ /**
4
+ * Identity type - represents who scheduled an action
5
+ */
6
+ export interface Identity {
7
+ id: string;
8
+ type: string;
9
+ displayName: string;
10
+ }
11
+ /**
12
+ * Scheduled Action Record - The data stored for a scheduled action
13
+ */
14
+ export interface IScheduledAction<T extends GenericRecord> {
15
+ id: string;
16
+ namespace: string;
17
+ actionType: string;
18
+ targetId: string;
19
+ scheduledBy: Identity;
20
+ scheduledFor: string;
21
+ title?: string;
22
+ payload: T;
23
+ error?: string;
24
+ }
25
+ /**
26
+ * ScheduledActionHandler - Similar to EventHandler pattern
27
+ *
28
+ * Each application (CMS, Mailer, etc.) implements handlers for their actions.
29
+ * This is the ONLY action abstraction needed.
30
+ */
31
+ export interface IScheduledActionHandler {
32
+ /**
33
+ * Determines if this handler can handle the given action
34
+ *
35
+ * @param namespace - Resource scope (e.g., "Cms/Entry/Article")
36
+ * @param actionType - Operation type (e.g., "Publish")
37
+ */
38
+ canHandle(namespace: string, actionType: string): boolean;
39
+ /**
40
+ * Executes the scheduled action
41
+ */
42
+ handle(action: IScheduledAction<any>): Promise<void>;
43
+ }
44
+ export declare const ScheduledActionHandler: import("@webiny/di").Abstraction<IScheduledActionHandler>;
45
+ export declare namespace ScheduledActionHandler {
46
+ type Interface = IScheduledActionHandler;
47
+ }
48
+ /**
49
+ * SchedulerService - Cloud-agnostic scheduler service
50
+ *
51
+ * Abstracts the underlying scheduling infrastructure (AWS EventBridge, Azure Logic Apps, etc.)
52
+ */
53
+ export interface ISchedulerServiceCreateParams {
54
+ id: string;
55
+ scheduleFor: Date;
56
+ }
57
+ export interface ISchedulerServiceUpdateParams {
58
+ id: string;
59
+ scheduleFor: Date;
60
+ }
61
+ export interface ISchedulerService {
62
+ create(params: ISchedulerServiceCreateParams): Promise<void>;
63
+ update(params: ISchedulerServiceUpdateParams): Promise<void>;
64
+ delete(id: string): Promise<void>;
65
+ exists(id: string): Promise<boolean>;
66
+ }
67
+ export declare const SchedulerService: import("@webiny/di").Abstraction<ISchedulerService>;
68
+ export declare namespace SchedulerService {
69
+ type Interface = ISchedulerService;
70
+ }
71
+ /**
72
+ * ScheduledActionModel - A CMS model used by the scheduler for persistence.
73
+ */
74
+ export declare const ScheduledActionModel: import("@webiny/di").Abstraction<CmsModel>;
75
+ export declare namespace ScheduledActionModel {
76
+ type Interface = CmsModel;
77
+ }
@@ -0,0 +1,32 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+
3
+ /**
4
+ * Identity type - represents who scheduled an action
5
+ */
6
+
7
+ /**
8
+ * Scheduled Action Record - The data stored for a scheduled action
9
+ */
10
+
11
+ /**
12
+ * ScheduledActionHandler - Similar to EventHandler pattern
13
+ *
14
+ * Each application (CMS, Mailer, etc.) implements handlers for their actions.
15
+ * This is the ONLY action abstraction needed.
16
+ */
17
+
18
+ export const ScheduledActionHandler = createAbstraction("ScheduledActionHandler");
19
+
20
+ /**
21
+ * SchedulerService - Cloud-agnostic scheduler service
22
+ *
23
+ * Abstracts the underlying scheduling infrastructure (AWS EventBridge, Azure Logic Apps, etc.)
24
+ */
25
+
26
+ export const SchedulerService = createAbstraction("SchedulerService");
27
+ /**
28
+ * ScheduledActionModel - A CMS model used by the scheduler for persistence.
29
+ */
30
+ export const ScheduledActionModel = createAbstraction("ScheduledActionModel");
31
+
32
+ //# sourceMappingURL=abstractions.js.map