@webiny/api-scheduler-aws 0.0.0-unstable.b6d7105cee → 6.6.0-alpha.1
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 +12 -3
- package/context.js +3 -20
- package/context.js.map +1 -1
- package/createEventHandler.d.ts +0 -5
- package/createEventHandler.js +0 -47
- package/features/SchedulerService/LazySchedulerService.d.ts +4 -0
- package/features/SchedulerService/LazySchedulerService.js +32 -0
- package/features/SchedulerService/LazySchedulerService.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +22 -18
- 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,16 @@
|
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* `SchedulerService` is bound at register time to a lazy implementation that reads the deployed
|
|
10
|
+
* scheduler manifest on first use and delegates to either the EventBridge service or the no-op Void
|
|
11
|
+
* service. Previously this was a per-request `RequestContextInitializer`, because the manifest read
|
|
12
|
+
* is async and DI resolution is not — along with a `getTenant()` guard, since a fixed-time hook can
|
|
13
|
+
* fire before the tenant is established. Neither is needed once the async work moves into the
|
|
14
|
+
* methods, which were already async.
|
|
15
|
+
*/
|
|
16
|
+
export declare const registerSchedulerAwsExtension: (container: Container, params: IRegisterSchedulerAwsExtensionParams) => void;
|
package/context.js
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
import { getManifest } from "./manifest.js";
|
|
2
1
|
import { SchedulerService } from "@webiny/api-scheduler/shared/abstractions.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { ContextPlugin } from "@webiny/api";
|
|
7
|
-
import { createScheduledActionEventHandler } from "./createEventHandler.js";
|
|
8
|
-
const registerSchedulerAwsExtension = (params)=>{
|
|
9
|
-
const plugin = new ContextPlugin(async (context)=>{
|
|
10
|
-
context.plugins.register(createScheduledActionEventHandler());
|
|
11
|
-
const tenantContext = context.container.resolve(TenantContext);
|
|
12
|
-
if (!tenantContext.getTenant()) return;
|
|
13
|
-
const manifest = await getManifest();
|
|
14
|
-
if (manifest.error) context.container.registerInstance(SchedulerService, new VoidSchedulerService());
|
|
15
|
-
else context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
|
|
16
|
-
lambdaArn: manifest.data.lambdaArn,
|
|
17
|
-
roleArn: manifest.data.roleArn
|
|
18
|
-
}));
|
|
19
|
-
});
|
|
20
|
-
plugin.name = "scheduler.aws.extension";
|
|
21
|
-
return plugin;
|
|
2
|
+
import { createLazySchedulerService } from "./features/SchedulerService/LazySchedulerService.js";
|
|
3
|
+
const registerSchedulerAwsExtension = (container, params)=>{
|
|
4
|
+
container.registerInstance(SchedulerService, createLazySchedulerService(params.getClient));
|
|
22
5
|
};
|
|
23
6
|
export { registerSchedulerAwsExtension };
|
|
24
7
|
|
package/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { SchedulerService } from \"@webiny/api-scheduler/shared/abstractions.js\";\nimport { createLazySchedulerService } from \"~/features/SchedulerService/LazySchedulerService.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.\n *\n * `SchedulerService` is bound at register time to a lazy implementation that reads the deployed\n * scheduler manifest on first use and delegates to either the EventBridge service or the no-op Void\n * service. Previously this was a per-request `RequestContextInitializer`, because the manifest read\n * is async and DI resolution is not — along with a `getTenant()` guard, since a fixed-time hook can\n * fire before the tenant is established. Neither is needed once the async work moves into the\n * methods, which were already async.\n */\nexport const registerSchedulerAwsExtension = (\n container: Container,\n params: IRegisterSchedulerAwsExtensionParams\n) => {\n container.registerInstance(SchedulerService, createLazySchedulerService(params.getClient));\n};\n"],"names":["registerSchedulerAwsExtension","container","params","SchedulerService","createLazySchedulerService"],"mappings":";;AAsBO,MAAMA,gCAAgC,CACzCC,WACAC;IAEAD,UAAU,gBAAgB,CAACE,kBAAkBC,2BAA2BF,OAAO,SAAS;AAC5F"}
|
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
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
2
|
+
import { SchedulerService } from "@webiny/api-scheduler/shared/abstractions.js";
|
|
3
|
+
export type GetSchedulerClient = (config?: SchedulerClientConfig) => Pick<SchedulerClient, "send">;
|
|
4
|
+
export declare const createLazySchedulerService: (getClient: GetSchedulerClient) => SchedulerService.Interface;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VoidSchedulerService } from "@webiny/api-scheduler/features/SchedulerService/VoidSchedulerService.js";
|
|
2
|
+
import { getManifest } from "../../manifest.js";
|
|
3
|
+
import { EventBridgeSchedulerService } from "./EventBridgeSchedulerService.js";
|
|
4
|
+
class LazySchedulerServiceImpl {
|
|
5
|
+
constructor(getClient){
|
|
6
|
+
this.getClient = getClient;
|
|
7
|
+
}
|
|
8
|
+
async service() {
|
|
9
|
+
const manifest = await getManifest();
|
|
10
|
+
if (manifest.error) return new VoidSchedulerService();
|
|
11
|
+
return new EventBridgeSchedulerService(this.getClient, {
|
|
12
|
+
lambdaArn: manifest.data.lambdaArn,
|
|
13
|
+
roleArn: manifest.data.roleArn
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async create(params) {
|
|
17
|
+
return (await this.service()).create(params);
|
|
18
|
+
}
|
|
19
|
+
async update(params) {
|
|
20
|
+
return (await this.service()).update(params);
|
|
21
|
+
}
|
|
22
|
+
async delete(params) {
|
|
23
|
+
return (await this.service()).delete(params);
|
|
24
|
+
}
|
|
25
|
+
async exists(params) {
|
|
26
|
+
return (await this.service()).exists(params);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const createLazySchedulerService = (getClient)=>new LazySchedulerServiceImpl(getClient);
|
|
30
|
+
export { createLazySchedulerService };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=LazySchedulerService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SchedulerService/LazySchedulerService.js","sources":["../../../src/features/SchedulerService/LazySchedulerService.ts"],"sourcesContent":["import type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { SchedulerService } from \"@webiny/api-scheduler/shared/abstractions.js\";\nimport { VoidSchedulerService } from \"@webiny/api-scheduler/features/SchedulerService/VoidSchedulerService.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport { EventBridgeSchedulerService } from \"./EventBridgeSchedulerService.js\";\n\nexport type GetSchedulerClient = (config?: SchedulerClientConfig) => Pick<SchedulerClient, \"send\">;\n\n/**\n * Picks the real EventBridge service or the no-op Void service, deciding on first use rather than\n * up front.\n *\n * The choice depends on the deployed scheduler manifest, and reading it is async — which is why\n * this used to be a per-request `RequestContextInitializer` that resolved the manifest and then\n * registered whichever service it implied. Every method here is already async, so the decision can\n * simply be awaited at the point of use instead.\n *\n * No memoization: `ServiceDiscovery.load()` caches the manifest in a process-wide static, so\n * `getManifest()` is cheap after the first call.\n */\nclass LazySchedulerServiceImpl implements SchedulerService.Interface {\n constructor(private getClient: GetSchedulerClient) {}\n\n private async service(): Promise<SchedulerService.Interface> {\n const manifest = await getManifest();\n\n if (manifest.error) {\n return new VoidSchedulerService();\n }\n\n return new EventBridgeSchedulerService(this.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n });\n }\n\n async create(params: SchedulerService.CreateParams): Promise<void> {\n return (await this.service()).create(params);\n }\n\n async update(params: SchedulerService.UpdateParams): Promise<void> {\n return (await this.service()).update(params);\n }\n\n async delete(params: SchedulerService.DeleteParams): Promise<void> {\n return (await this.service()).delete(params);\n }\n\n async exists(params: SchedulerService.ExistsParams): Promise<boolean> {\n return (await this.service()).exists(params);\n }\n}\n\nexport const createLazySchedulerService = (\n getClient: GetSchedulerClient\n): SchedulerService.Interface => new LazySchedulerServiceImpl(getClient);\n"],"names":["LazySchedulerServiceImpl","getClient","manifest","getManifest","VoidSchedulerService","EventBridgeSchedulerService","params","createLazySchedulerService"],"mappings":";;;AAuBA,MAAMA;IACF,YAAoBC,SAA6B,CAAE;aAA/BA,SAAS,GAATA;IAAgC;IAEpD,MAAc,UAA+C;QACzD,MAAMC,WAAW,MAAMC;QAEvB,IAAID,SAAS,KAAK,EACd,OAAO,IAAIE;QAGf,OAAO,IAAIC,4BAA4B,IAAI,CAAC,SAAS,EAAE;YACnD,WAAWH,SAAS,IAAI,CAAC,SAAS;YAClC,SAASA,SAAS,IAAI,CAAC,OAAO;QAClC;IACJ;IAEA,MAAM,OAAOI,MAAqC,EAAiB;QAC/D,OAAQ,OAAM,IAAI,CAAC,OAAO,EAAC,EAAG,MAAM,CAACA;IACzC;IAEA,MAAM,OAAOA,MAAqC,EAAiB;QAC/D,OAAQ,OAAM,IAAI,CAAC,OAAO,EAAC,EAAG,MAAM,CAACA;IACzC;IAEA,MAAM,OAAOA,MAAqC,EAAiB;QAC/D,OAAQ,OAAM,IAAI,CAAC,OAAO,EAAC,EAAG,MAAM,CAACA;IACzC;IAEA,MAAM,OAAOA,MAAqC,EAAoB;QAClE,OAAQ,OAAM,IAAI,CAAC,OAAO,EAAC,EAAG,MAAM,CAACA;IACzC;AACJ;AAEO,MAAMC,6BAA6B,CACtCN,YAC6B,IAAID,yBAAyBC"}
|
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.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,28 +18,32 @@
|
|
|
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.b6d7105cee",
|
|
29
|
-
"@webiny/plugins": "0.0.0-unstable.b6d7105cee",
|
|
30
|
-
"@webiny/utils": "0.0.0-unstable.b6d7105cee",
|
|
21
|
+
"@webiny/api": "6.6.0-alpha.1",
|
|
22
|
+
"@webiny/api-core": "6.6.0-alpha.1",
|
|
23
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.1",
|
|
24
|
+
"@webiny/api-scheduler": "6.6.0-alpha.1",
|
|
25
|
+
"@webiny/aws-sdk": "6.6.0-alpha.1",
|
|
26
|
+
"@webiny/error": "6.6.0-alpha.1",
|
|
27
|
+
"@webiny/utils": "6.6.0-alpha.1",
|
|
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.1",
|
|
32
|
+
"@webiny/api-core-testing": "6.6.0-alpha.1",
|
|
33
|
+
"@webiny/api-graphql": "6.6.0-alpha.1",
|
|
34
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.1",
|
|
35
|
+
"@webiny/build-tools": "6.6.0-alpha.1",
|
|
36
|
+
"@webiny/db-dynamodb": "6.6.0-alpha.1",
|
|
37
|
+
"@webiny/di": "1.1.0",
|
|
38
|
+
"@webiny/event-handler-aws": "6.6.0-alpha.1",
|
|
39
|
+
"@webiny/event-handler-core": "6.6.0-alpha.1",
|
|
40
|
+
"@webiny/feature": "6.6.0-alpha.1",
|
|
41
|
+
"@webiny/handler": "6.6.0-alpha.1",
|
|
42
|
+
"@webiny/wcp": "6.6.0-alpha.1",
|
|
40
43
|
"aws-sdk-client-mock": "4.1.0",
|
|
44
|
+
"graphql": "16.14.2",
|
|
41
45
|
"typescript": "7.0.2",
|
|
42
|
-
"vitest": "4.1.
|
|
46
|
+
"vitest": "4.1.11"
|
|
43
47
|
},
|
|
44
48
|
"publishConfig": {
|
|
45
49
|
"access": "public"
|
|
@@ -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","tenantResult","tenant","executeScheduledAction","ExecuteScheduledActionUseCase","result","error","console"],"mappings":";;;;;;;AAwBA,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,gBAAgBP,QAAQ,SAAS,CAAC,OAAO,CAACQ;YAKhD,IAAI,CAACF,MAAM,MAAM,EACbA,MAAM,MAAM,GAAGC,cAAc,SAAS,GAAG,EAAE;YAE/C,MAAME,uBAAuBT,QAAQ,SAAS,CAAC,OAAO,CAACU;YACvD,MAAMC,eAAe,MAAMF,qBAAqB,OAAO,CAACH,MAAM,MAAM;YACpE,IAAIK,aAAa,MAAM,IACnB,MAAMA,aAAa,KAAK;YAE5B,MAAMC,SAASD,aAAa,KAAK;YAEjC,OAAOJ,cAAc,UAAU,CAACK,QAAQ;gBACpC,MAAMC,yBAAyBb,QAAQ,SAAS,CAAC,OAAO,CACpDc;gBAEJ,MAAMC,SAAS,MAAMF,uBAAuB,OAAO,CAACP;gBAEpD,IAAIS,OAAO,MAAM,IAAI;oBACjB,MAAMC,QAAQD,OAAO,KAAK;oBAC1BE,QAAQ,KAAK,CAACD,MAAM,IAAI,EAAEA,MAAM,OAAO;oBACvC,MAAMA;gBACV;gBACA,OAAO;oBACH,SAAS;gBACb;YACJ;QACJ;IACJ"}
|