@webiny/api-scheduler-aws 0.0.0-unstable.5387e5f7c8 → 0.0.0-unstable.7c2def32a7
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.
|
@@ -10,6 +10,8 @@ export declare class EventBridgeSchedulerService implements SchedulerService.Int
|
|
|
10
10
|
constructor(getClient: (config?: any) => Pick<SchedulerClient, "send">, config: ISchedulerConfig);
|
|
11
11
|
create(params: SchedulerService.CreateParams): Promise<void>;
|
|
12
12
|
update(params: SchedulerService.UpdateParams): Promise<void>;
|
|
13
|
+
private sendCreate;
|
|
14
|
+
private sendUpdate;
|
|
13
15
|
delete(params: SchedulerService.DeleteParams): Promise<void>;
|
|
14
16
|
exists(params: SchedulerService.ExistsParams): Promise<boolean>;
|
|
15
17
|
private createScheduleExpression;
|
|
@@ -13,16 +13,29 @@ class EventBridgeSchedulerService {
|
|
|
13
13
|
tenant,
|
|
14
14
|
id
|
|
15
15
|
});
|
|
16
|
-
const client = this.getClient();
|
|
17
16
|
const exists = await this.exists({
|
|
18
17
|
id,
|
|
19
18
|
tenant,
|
|
20
19
|
namespace
|
|
21
20
|
});
|
|
22
|
-
if (exists) return this.
|
|
21
|
+
if (exists) return this.sendUpdate(params);
|
|
22
|
+
return this.sendCreate(params);
|
|
23
|
+
}
|
|
24
|
+
async update(params) {
|
|
25
|
+
const { id, scheduleFor } = params;
|
|
26
|
+
if (scheduleFor <= new Date()) throw new WebinyError(`Cannot update an existing schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
|
|
27
|
+
scheduleFor,
|
|
28
|
+
id
|
|
29
|
+
});
|
|
30
|
+
const exists = await this.exists(params);
|
|
31
|
+
if (!exists) return this.sendCreate(params);
|
|
32
|
+
return this.sendUpdate(params);
|
|
33
|
+
}
|
|
34
|
+
async sendCreate(params) {
|
|
35
|
+
const client = this.getClient();
|
|
23
36
|
await client.send(new CreateScheduleCommand({
|
|
24
37
|
Name: this.createScheduleName(params),
|
|
25
|
-
ScheduleExpression: this.createScheduleExpression(scheduleFor),
|
|
38
|
+
ScheduleExpression: this.createScheduleExpression(params.scheduleFor),
|
|
26
39
|
FlexibleTimeWindow: {
|
|
27
40
|
Mode: "OFF"
|
|
28
41
|
},
|
|
@@ -34,16 +47,11 @@ class EventBridgeSchedulerService {
|
|
|
34
47
|
ActionAfterCompletion: "DELETE"
|
|
35
48
|
}));
|
|
36
49
|
}
|
|
37
|
-
async
|
|
38
|
-
const { id, scheduleFor } = params;
|
|
39
|
-
if (scheduleFor <= new Date()) throw new WebinyError(`Cannot update an existing schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
|
|
40
|
-
scheduleFor,
|
|
41
|
-
id
|
|
42
|
-
});
|
|
50
|
+
async sendUpdate(params) {
|
|
43
51
|
const client = this.getClient();
|
|
44
52
|
await client.send(new UpdateScheduleCommand({
|
|
45
53
|
Name: this.createScheduleName(params),
|
|
46
|
-
ScheduleExpression: this.createScheduleExpression(scheduleFor),
|
|
54
|
+
ScheduleExpression: this.createScheduleExpression(params.scheduleFor),
|
|
47
55
|
FlexibleTimeWindow: {
|
|
48
56
|
Mode: "OFF"
|
|
49
57
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SchedulerService/EventBridgeSchedulerService.js","sources":["../../../src/features/SchedulerService/EventBridgeSchedulerService.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport {\n type ISchedulerServiceCreateParams,\n type ISchedulerServiceUpdateParams,\n SchedulerService\n} from \"@webiny/api-scheduler/shared/abstractions.js\";\nimport {\n CreateScheduleCommand,\n DeleteScheduleCommand,\n GetScheduleCommand,\n type SchedulerClient,\n UpdateScheduleCommand\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"@webiny/api-scheduler/constants.js\";\nimport type { IScheduledActionEventPayload } from \"~/createEventHandler.js\";\n\nexport interface ISchedulerConfig {\n lambdaArn: string;\n roleArn: string;\n}\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: SchedulerService.CreateParams): Promise<void> {\n const { id, scheduleFor, tenant, namespace } = params;\n\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 tenant,\n id\n }\n );\n }\n\n const
|
|
1
|
+
{"version":3,"file":"features/SchedulerService/EventBridgeSchedulerService.js","sources":["../../../src/features/SchedulerService/EventBridgeSchedulerService.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport {\n type ISchedulerServiceCreateParams,\n type ISchedulerServiceUpdateParams,\n SchedulerService\n} from \"@webiny/api-scheduler/shared/abstractions.js\";\nimport {\n CreateScheduleCommand,\n DeleteScheduleCommand,\n GetScheduleCommand,\n type SchedulerClient,\n UpdateScheduleCommand\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"@webiny/api-scheduler/constants.js\";\nimport type { IScheduledActionEventPayload } from \"~/createEventHandler.js\";\n\nexport interface ISchedulerConfig {\n lambdaArn: string;\n roleArn: string;\n}\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: SchedulerService.CreateParams): Promise<void> {\n const { id, scheduleFor, tenant, namespace } = params;\n\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 tenant,\n id\n }\n );\n }\n\n const exists = await this.exists({\n id,\n tenant,\n namespace\n });\n if (exists) {\n return this.sendUpdate(params);\n }\n\n return this.sendCreate(params);\n }\n\n public async update(params: SchedulerService.UpdateParams): Promise<void> {\n const { id, scheduleFor } = params;\n\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 /*\n * The schedule can be gone while the scheduled action still exists, for example after a\n * failed or manual cleanup. UpdateScheduleCommand would then fail, so create it instead.\n */\n const exists = await this.exists(params);\n if (!exists) {\n return this.sendCreate(params);\n }\n\n return this.sendUpdate(params);\n }\n\n private async sendCreate(params: SchedulerService.CreateParams): Promise<void> {\n const client = this.getClient();\n\n await client.send(\n new CreateScheduleCommand({\n Name: this.createScheduleName(params),\n ScheduleExpression: this.createScheduleExpression(params.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 private async sendUpdate(params: SchedulerService.UpdateParams): Promise<void> {\n const client = this.getClient();\n\n await client.send(\n new UpdateScheduleCommand({\n Name: this.createScheduleName(params),\n ScheduleExpression: this.createScheduleExpression(params.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(params: SchedulerService.DeleteParams): Promise<void> {\n const client = this.getClient();\n\n const exists = await this.exists(params);\n if (!exists) {\n throw new WebinyError(\n `Cannot delete schedule \"${params.id}\", tenant \"${params.tenant}\", because it does not exist.`\n );\n }\n\n const name = this.createScheduleName(params);\n\n try {\n await client.send(new DeleteScheduleCommand({ Name: name }));\n } catch (ex) {\n if (ex.name === \"ResourceNotFoundException\") {\n return;\n }\n throw WebinyError.from(ex);\n }\n }\n\n public async exists(params: SchedulerService.ExistsParams): Promise<boolean> {\n const client = this.getClient();\n\n const name = this.createScheduleName(params);\n\n try {\n await client.send(new GetScheduleCommand({ Name: name }));\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 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: SchedulerService.CreateParams | SchedulerService.UpdateParams\n ): IScheduledActionEventPayload {\n const { id, scheduleFor, tenant, namespace } = params;\n\n return {\n id,\n tenant,\n namespace,\n scheduleFor: scheduleFor.toISOString()\n };\n }\n\n private createScheduleName(params: SchedulerService.ExistsParams): string {\n // AWS EventBridge Scheduler names must match [0-9a-zA-Z-_.]+ and be <= 64 chars. `id`\n // (ScheduledActionId: \"wby-schedule-<hash>\") already satisfies both and is unique per\n // namespace + action type + target, so use it verbatim. Do NOT interpolate `namespace`\n // (contains \"/\", e.g. \"Cms/Entry/<modelId>\") or `tenant` — that produced names with illegal\n // characters that exceeded the length limit (ValidationException).\n return params.id;\n }\n}\n"],"names":["EventBridgeSchedulerService","getClient","config","params","id","scheduleFor","tenant","namespace","Date","WebinyError","exists","client","CreateScheduleCommand","UpdateScheduleCommand","name","DeleteScheduleCommand","ex","GetScheduleCommand","JSON","SCHEDULED_ACTION_EVENT_IDENTIFIER"],"mappings":";;;AAqBO,MAAMA;IACT,YACYC,SAA0D,EAC1DC,MAAwB,CAClC;aAFUD,SAAS,GAATA;aACAC,MAAM,GAANA;IACT;IAEH,MAAa,OAAOC,MAAqC,EAAiB;QACtE,MAAM,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGJ;Q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YAClB,CAACC,kCAAkC,EAAE,IAAI,CAAC,iCAAiC,CAAChB;QAChF;IACJ;IAEQ,kCACJA,MAAqE,EACzC;QAC5B,MAAM,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGJ;QAE/C,OAAO;YACHC;YACAE;YACAC;YACA,aAAaF,YAAY,WAAW;QACxC;IACJ;IAEQ,mBAAmBF,MAAqC,EAAU;QAMtE,OAAOA,OAAO,EAAE;IACpB;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-scheduler-aws",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.7c2def32a7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,28 +18,28 @@
|
|
|
18
18
|
"description": "AWS EventBridge implementation for the Webiny action scheduler.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api": "0.0.0-unstable.
|
|
22
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
23
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
24
|
-
"@webiny/api-scheduler": "0.0.0-unstable.
|
|
25
|
-
"@webiny/aws-sdk": "0.0.0-unstable.
|
|
26
|
-
"@webiny/error": "0.0.0-unstable.
|
|
27
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
21
|
+
"@webiny/api": "0.0.0-unstable.7c2def32a7",
|
|
22
|
+
"@webiny/api-core": "0.0.0-unstable.7c2def32a7",
|
|
23
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.7c2def32a7",
|
|
24
|
+
"@webiny/api-scheduler": "0.0.0-unstable.7c2def32a7",
|
|
25
|
+
"@webiny/aws-sdk": "0.0.0-unstable.7c2def32a7",
|
|
26
|
+
"@webiny/error": "0.0.0-unstable.7c2def32a7",
|
|
27
|
+
"@webiny/utils": "0.0.0-unstable.7c2def32a7",
|
|
28
28
|
"zod": "4.4.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
32
|
-
"@webiny/api-core-testing": "0.0.0-unstable.
|
|
33
|
-
"@webiny/api-graphql": "0.0.0-unstable.
|
|
34
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
35
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
36
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
|
31
|
+
"@webiny/api-core": "0.0.0-unstable.7c2def32a7",
|
|
32
|
+
"@webiny/api-core-testing": "0.0.0-unstable.7c2def32a7",
|
|
33
|
+
"@webiny/api-graphql": "0.0.0-unstable.7c2def32a7",
|
|
34
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.7c2def32a7",
|
|
35
|
+
"@webiny/build-tools": "0.0.0-unstable.7c2def32a7",
|
|
36
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.7c2def32a7",
|
|
37
37
|
"@webiny/di": "2.0.0",
|
|
38
|
-
"@webiny/event-handler-aws": "0.0.0-unstable.
|
|
39
|
-
"@webiny/event-handler-core": "0.0.0-unstable.
|
|
40
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
41
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
42
|
-
"@webiny/wcp": "0.0.0-unstable.
|
|
38
|
+
"@webiny/event-handler-aws": "0.0.0-unstable.7c2def32a7",
|
|
39
|
+
"@webiny/event-handler-core": "0.0.0-unstable.7c2def32a7",
|
|
40
|
+
"@webiny/feature": "0.0.0-unstable.7c2def32a7",
|
|
41
|
+
"@webiny/handler": "0.0.0-unstable.7c2def32a7",
|
|
42
|
+
"@webiny/wcp": "0.0.0-unstable.7c2def32a7",
|
|
43
43
|
"aws-sdk-client-mock": "4.1.0",
|
|
44
44
|
"graphql": "16.14.2",
|
|
45
45
|
"typescript": "7.0.2",
|