@webiny/api-scheduler-aws 0.0.0-unstable.9f53ea597d → 6.6.0-alpha.0
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.
- package/SchedulerAwsFeature.d.ts +10 -0
- package/SchedulerAwsFeature.js +14 -0
- package/SchedulerAwsFeature.js.map +1 -0
- package/context.d.ts +7 -3
- package/context.js +13 -15
- package/context.js.map +1 -1
- package/createEventHandler.d.ts +0 -5
- package/createEventHandler.js +0 -47
- package/features/SchedulerService/EventBridgeSchedulerService.js +3 -3
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +22 -17
- package/createEventHandler.js.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS (EventBridge Scheduler) transport. Wraps `registerSchedulerAwsExtension` with the default
|
|
3
|
+
* scheduler client so the handler's `transports` wiring reads uniformly
|
|
4
|
+
* (`SchedulerAwsFeature.register(c)`), matching the other transport adapters. Callers that need a
|
|
5
|
+
* custom client can still use `registerSchedulerAwsExtension` directly.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SchedulerAwsFeature: {
|
|
8
|
+
name: string;
|
|
9
|
+
register(container: import("@webiny/di").Container): void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { createSchedulerClient } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
+
import { registerSchedulerAwsExtension } from "./context.js";
|
|
4
|
+
const SchedulerAwsFeature = createFeature({
|
|
5
|
+
name: "SchedulerAws",
|
|
6
|
+
register (container) {
|
|
7
|
+
registerSchedulerAwsExtension(container, {
|
|
8
|
+
getClient: (config)=>createSchedulerClient(config)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
export { SchedulerAwsFeature };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=SchedulerAwsFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchedulerAwsFeature.js","sources":["../src/SchedulerAwsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createSchedulerClient } from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { registerSchedulerAwsExtension } from \"./context.js\";\n\n/**\n * AWS (EventBridge Scheduler) transport. Wraps `registerSchedulerAwsExtension` with the default\n * scheduler client so the handler's `transports` wiring reads uniformly\n * (`SchedulerAwsFeature.register(c)`), matching the other transport adapters. Callers that need a\n * custom client can still use `registerSchedulerAwsExtension` directly.\n */\nexport const SchedulerAwsFeature = createFeature({\n name: \"SchedulerAws\",\n register(container) {\n registerSchedulerAwsExtension(container, {\n getClient: config => createSchedulerClient(config)\n });\n }\n});\n"],"names":["SchedulerAwsFeature","createFeature","container","registerSchedulerAwsExtension","config","createSchedulerClient"],"mappings":";;;AAUO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdC,8BAA8BD,WAAW;YACrC,WAAWE,CAAAA,SAAUC,sBAAsBD;QAC/C;IACJ;AACJ"}
|
package/context.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
1
2
|
import type { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
2
|
-
import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
-
import { ContextPlugin } from "@webiny/api";
|
|
4
3
|
export interface IRegisterSchedulerAwsExtensionParams {
|
|
5
4
|
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
6
5
|
}
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Registers the AWS (EventBridge Scheduler) transport for the scheduler. Binds `SchedulerService`
|
|
8
|
+
* per-request via a RequestContextInitializer (post-tenant): resolves the deployed scheduler
|
|
9
|
+
* manifest and picks the EventBridge service, or a no-op Void service when the manifest is missing.
|
|
10
|
+
*/
|
|
11
|
+
export declare const registerSchedulerAwsExtension: (container: Container, params: IRegisterSchedulerAwsExtensionParams) => void;
|
package/context.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
+
import { RequestContextInitializer } from "@webiny/event-handler-core";
|
|
1
2
|
import { getManifest } from "./manifest.js";
|
|
2
3
|
import { SchedulerService } from "@webiny/api-scheduler/shared/abstractions.js";
|
|
3
4
|
import { EventBridgeSchedulerService } from "./features/SchedulerService/EventBridgeSchedulerService.js";
|
|
4
5
|
import { VoidSchedulerService } from "@webiny/api-scheduler/features/SchedulerService/VoidSchedulerService.js";
|
|
5
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}));
|
|
7
|
+
const registerSchedulerAwsExtension = (container, params)=>{
|
|
8
|
+
container.registerInstance(RequestContextInitializer, {
|
|
9
|
+
async init (ctx) {
|
|
10
|
+
const requestContainer = ctx.container;
|
|
11
|
+
if (!requestContainer.resolve(TenantContext).getTenant()) return;
|
|
12
|
+
const manifest = await getManifest();
|
|
13
|
+
if (manifest.error) requestContainer.registerInstance(SchedulerService, new VoidSchedulerService());
|
|
14
|
+
else requestContainer.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
|
|
15
|
+
lambdaArn: manifest.data.lambdaArn,
|
|
16
|
+
roleArn: manifest.data.roleArn
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
19
|
});
|
|
20
|
-
plugin.name = "scheduler.aws.extension";
|
|
21
|
-
return plugin;
|
|
22
20
|
};
|
|
23
21
|
export { registerSchedulerAwsExtension };
|
|
24
22
|
|
package/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { RequestContextInitializer } from \"@webiny/event-handler-core\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport { SchedulerService } from \"@webiny/api-scheduler/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"@webiny/api-scheduler/features/SchedulerService/VoidSchedulerService.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\n\nexport interface IRegisterSchedulerAwsExtensionParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\n/**\n * Registers the AWS (EventBridge Scheduler) transport for the scheduler. Binds `SchedulerService`\n * per-request via a RequestContextInitializer (post-tenant): resolves the deployed scheduler\n * manifest and picks the EventBridge service, or a no-op Void service when the manifest is missing.\n */\nexport const registerSchedulerAwsExtension = (\n container: Container,\n params: IRegisterSchedulerAwsExtensionParams\n) => {\n container.registerInstance(RequestContextInitializer, {\n async init(ctx: Record<string, any>) {\n const requestContainer = ctx.container as Container;\n\n if (!requestContainer.resolve(TenantContext).getTenant()) {\n return;\n }\n\n const manifest = await getManifest();\n\n if (manifest.error) {\n requestContainer.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n requestContainer.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n }\n });\n};\n"],"names":["registerSchedulerAwsExtension","container","params","RequestContextInitializer","ctx","requestContainer","TenantContext","manifest","getManifest","SchedulerService","VoidSchedulerService","EventBridgeSchedulerService"],"mappings":";;;;;;AAqBO,MAAMA,gCAAgC,CACzCC,WACAC;IAEAD,UAAU,gBAAgB,CAACE,2BAA2B;QAClD,MAAM,MAAKC,GAAwB;YAC/B,MAAMC,mBAAmBD,IAAI,SAAS;YAEtC,IAAI,CAACC,iBAAiB,OAAO,CAACC,eAAe,SAAS,IAClD;YAGJ,MAAMC,WAAW,MAAMC;YAEvB,IAAID,SAAS,KAAK,EACdF,iBAAiB,gBAAgB,CAACI,kBAAkB,IAAIC;iBAExDL,iBAAiB,gBAAgB,CAC7BI,kBACA,IAAIE,4BAA4BT,OAAO,SAAS,EAAE;gBAC9C,WAAWK,SAAS,IAAI,CAAC,SAAS;gBAClC,SAASA,SAAS,IAAI,CAAC,OAAO;YAClC;QAGZ;IACJ;AACJ"}
|
package/createEventHandler.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
|
|
2
1
|
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "@webiny/api-scheduler/constants.js";
|
|
3
2
|
export interface IScheduledActionEventPayload {
|
|
4
3
|
namespace: string;
|
|
@@ -9,7 +8,3 @@ export interface IScheduledActionEventPayload {
|
|
|
9
8
|
export interface IScheduledActionEvent {
|
|
10
9
|
[SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;
|
|
11
10
|
}
|
|
12
|
-
export interface HandlerParams extends HandlerFactoryParams {
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare const createScheduledActionEventHandler: () => import("@webiny/handler-aws/raw/index.js").RawEventHandler<IScheduledActionEvent, import("@webiny/handler/types").Context, any>;
|
package/createEventHandler.js
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { registry } from "@webiny/handler-aws/registry.js";
|
|
2
|
-
import { createSourceHandler } from "@webiny/handler-aws/sourceHandler.js";
|
|
3
|
-
import { createEventHandler, createHandler } from "@webiny/handler-aws/raw/index.js";
|
|
4
|
-
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "@webiny/api-scheduler/constants.js";
|
|
5
|
-
import { ExecuteScheduledActionUseCase } from "@webiny/api-scheduler/features/ExecuteScheduledAction/index.js";
|
|
6
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
-
import { GetTenantByIdUseCase } from "@webiny/api-core/exports/api/tenancy.js";
|
|
8
|
-
const canHandle = (event)=>{
|
|
9
|
-
if ("function" != typeof event?.hasOwnProperty) return false;
|
|
10
|
-
if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) return false;
|
|
11
|
-
const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
12
|
-
return !!(value?.id && value?.scheduleFor);
|
|
13
|
-
};
|
|
14
|
-
const handler = createSourceHandler({
|
|
15
|
-
name: "handler-aws-event-bridge-scheduled-cms-action-event",
|
|
16
|
-
canUse: canHandle,
|
|
17
|
-
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
18
|
-
});
|
|
19
|
-
registry.register(handler);
|
|
20
|
-
const createScheduledActionEventHandler = ()=>createEventHandler({
|
|
21
|
-
canHandle: canHandle,
|
|
22
|
-
handle: async (params)=>{
|
|
23
|
-
const { payload, context } = params;
|
|
24
|
-
const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
25
|
-
const tenantContext = context.container.resolve(TenantContext);
|
|
26
|
-
if (!input.tenant) input.tenant = tenantContext.getTenant().id;
|
|
27
|
-
const getTenantByIdUseCase = context.container.resolve(GetTenantByIdUseCase);
|
|
28
|
-
const tenantResult = await getTenantByIdUseCase.execute(input.tenant);
|
|
29
|
-
if (tenantResult.isFail()) throw tenantResult.error;
|
|
30
|
-
const tenant = tenantResult.value;
|
|
31
|
-
return tenantContext.withTenant(tenant, async ()=>{
|
|
32
|
-
const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);
|
|
33
|
-
const result = await executeScheduledAction.execute(input);
|
|
34
|
-
if (result.isFail()) {
|
|
35
|
-
const error = result.error;
|
|
36
|
-
console.error(error.code, error.message);
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
success: true
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
export { createScheduledActionEventHandler };
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=createEventHandler.js.map
|
|
@@ -21,7 +21,7 @@ class EventBridgeSchedulerService {
|
|
|
21
21
|
});
|
|
22
22
|
if (exists) return this.update(params);
|
|
23
23
|
await client.send(new CreateScheduleCommand({
|
|
24
|
-
Name:
|
|
24
|
+
Name: id,
|
|
25
25
|
ScheduleExpression: this.createScheduleExpression(scheduleFor),
|
|
26
26
|
FlexibleTimeWindow: {
|
|
27
27
|
Mode: "OFF"
|
|
@@ -42,7 +42,7 @@ class EventBridgeSchedulerService {
|
|
|
42
42
|
});
|
|
43
43
|
const client = this.getClient();
|
|
44
44
|
await client.send(new UpdateScheduleCommand({
|
|
45
|
-
Name:
|
|
45
|
+
Name: id,
|
|
46
46
|
ScheduleExpression: this.createScheduleExpression(scheduleFor),
|
|
47
47
|
FlexibleTimeWindow: {
|
|
48
48
|
Mode: "OFF"
|
|
@@ -100,7 +100,7 @@ class EventBridgeSchedulerService {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
createScheduleName(params) {
|
|
103
|
-
return params.id
|
|
103
|
+
return `schedule_${params.tenant}-${params.namespace}-${params.id}`;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
export { EventBridgeSchedulerService };
|
|
@@ -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 client = this.getClient();\n\n const exists = await this.exists({\n id,\n tenant,\n namespace\n });\n if (exists) {\n return this.update(params);\n }\n\n await client.send(\n new CreateScheduleCommand({\n Name:
|
|
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 client = this.getClient();\n\n const exists = await this.exists({\n id,\n tenant,\n namespace\n });\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\"\n })\n );\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 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(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 return `schedule_${params.tenant}-${params.namespace}-${params.id}`;\n }\n}\n"],"names":["EventBridgeSchedulerService","getClient","config","params","id","scheduleFor","tenant","namespace","Date","WebinyError","client","exists","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;QAE/C,IAAIE,eAA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AEA,OAAO,EAAE,EAAE;IACvE;AACJ"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-scheduler-aws",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.6.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,26 +18,31 @@
|
|
|
18
18
|
"description": "AWS EventBridge implementation for the Webiny action scheduler.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api": "
|
|
22
|
-
"@webiny/api-core": "
|
|
23
|
-
"@webiny/api-headless-cms": "
|
|
24
|
-
"@webiny/api-scheduler": "
|
|
25
|
-
"@webiny/aws-sdk": "
|
|
26
|
-
"@webiny/error": "
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/handler-aws": "0.0.0-unstable.9f53ea597d",
|
|
29
|
-
"@webiny/plugins": "0.0.0-unstable.9f53ea597d",
|
|
30
|
-
"@webiny/utils": "0.0.0-unstable.9f53ea597d",
|
|
21
|
+
"@webiny/api": "6.6.0-alpha.0",
|
|
22
|
+
"@webiny/api-core": "6.6.0-alpha.0",
|
|
23
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.0",
|
|
24
|
+
"@webiny/api-scheduler": "6.6.0-alpha.0",
|
|
25
|
+
"@webiny/aws-sdk": "6.6.0-alpha.0",
|
|
26
|
+
"@webiny/error": "6.6.0-alpha.0",
|
|
27
|
+
"@webiny/utils": "6.6.0-alpha.0",
|
|
31
28
|
"zod": "4.4.3"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@webiny/
|
|
35
|
-
"@webiny/
|
|
36
|
-
"@webiny/
|
|
37
|
-
"@webiny/
|
|
38
|
-
"@webiny/
|
|
39
|
-
"@webiny/
|
|
31
|
+
"@webiny/api-core": "6.6.0-alpha.0",
|
|
32
|
+
"@webiny/api-core-testing": "6.6.0-alpha.0",
|
|
33
|
+
"@webiny/api-graphql": "6.6.0-alpha.0",
|
|
34
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.0",
|
|
35
|
+
"@webiny/build-tools": "6.6.0-alpha.0",
|
|
36
|
+
"@webiny/db-dynamodb": "6.6.0-alpha.0",
|
|
37
|
+
"@webiny/di": "1.0.2",
|
|
38
|
+
"@webiny/event-handler-aws": "6.6.0-alpha.0",
|
|
39
|
+
"@webiny/event-handler-core": "6.6.0-alpha.0",
|
|
40
|
+
"@webiny/feature": "6.6.0-alpha.0",
|
|
41
|
+
"@webiny/handler": "6.6.0-alpha.0",
|
|
42
|
+
"@webiny/project-utils": "6.6.0-alpha.0",
|
|
43
|
+
"@webiny/wcp": "6.6.0-alpha.0",
|
|
40
44
|
"aws-sdk-client-mock": "4.1.0",
|
|
45
|
+
"graphql": "16.14.2",
|
|
41
46
|
"typescript": "7.0.2",
|
|
42
47
|
"vitest": "4.1.10"
|
|
43
48
|
},
|
|
@@ -1 +0,0 @@
|
|
|
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 \"@webiny/api-scheduler/constants.js\";\nimport { ExecuteScheduledActionUseCase } from \"@webiny/api-scheduler/features/ExecuteScheduledAction/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/exports/api/tenancy.js\";\n\nexport interface IScheduledActionEventPayload {\n namespace: string;\n id: string;\n scheduleFor: string;\n tenant: 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 tenantContext = context.container.resolve(TenantContext);\n /**\n * Use default tenant if tenant is not provided in the payload.\n * This allows backward compatibility with existing scheduled actions that do not have tenant information in their payload.\n */\n if (!input.tenant) {\n input.tenant = tenantContext.getTenant().id;\n }\n const getTenantByIdUseCase = context.container.resolve(GetTenantByIdUseCase);\n const tenantResult = await getTenantByIdUseCase.execute(input.tenant);\n if (tenantResult.isFail()) {\n throw tenantResult.error;\n }\n const tenant = tenantResult.value;\n\n return tenantContext.withTenant(tenant, async () => {\n const executeScheduledAction = context.container.resolve(\n ExecuteScheduledActionUseCase\n );\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};\n"],"names":["canHandle","event","SCHEDULED_ACTION_EVENT_IDENTIFIER","value","handler","createSourceHandler","params","context","createHandler","registry","createScheduledActionEventHandler","createEventHandler","payload","input","tenantContext","TenantContext","getTenantByIdUseCase","GetTenantByIdUseCase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