@webiny/api-scheduler 0.0.0-unstable.7be00a75a9 → 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.
- package/ScheduledActionLambdaHandler.d.ts +18 -0
- package/ScheduledActionLambdaHandler.js +41 -0
- package/ScheduledActionLambdaHandler.js.map +1 -0
- package/SchedulerFeature.d.ts +5 -0
- package/SchedulerFeature.js +21 -0
- package/SchedulerFeature.js.map +1 -0
- package/domain/SchedulePrivateModel.js +2 -1
- package/domain/SchedulePrivateModel.js.map +1 -1
- package/domain/ScheduledActionMapper.js +8 -2
- package/domain/ScheduledActionMapper.js.map +1 -1
- package/domain/errors.d.ts +1 -1
- package/domain/errors.js.map +1 -1
- package/exports/api/scheduler.d.ts +1 -1
- package/exports/api/scheduler.js +1 -1
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +7 -7
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +15 -14
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +2 -1
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/CancelScheduledAction/feature.d.ts +1 -1
- package/features/CancelScheduledAction/feature.js.map +1 -1
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +3 -3
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +16 -7
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +2 -1
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/feature.d.ts +1 -1
- package/features/ExecuteScheduledAction/feature.js.map +1 -1
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +5 -5
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +12 -11
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +5 -5
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +13 -12
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -1
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -5
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +15 -13
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- package/features/NamespaceHandler/feature.d.ts +4 -0
- package/features/NamespaceHandler/feature.js +11 -0
- package/features/NamespaceHandler/feature.js.map +1 -0
- package/features/ScheduleAction/ScheduleActionUseCase.d.ts +6 -6
- package/features/ScheduleAction/ScheduleActionUseCase.js +31 -23
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduleAction/abstractions.d.ts +1 -0
- package/features/ScheduleAction/abstractions.js.map +1 -1
- package/features/ScheduledActionModelProvider.d.ts +26 -0
- package/features/ScheduledActionModelProvider.js +22 -0
- package/features/ScheduledActionModelProvider.js.map +1 -0
- package/features/SchedulerService/VoidSchedulerService.d.ts +9 -9
- package/features/SchedulerService/VoidSchedulerService.js +4 -4
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
- package/features/permissions/SchedulerPermissionsResolver.d.ts +12 -0
- package/features/permissions/SchedulerPermissionsResolver.js +42 -0
- package/features/permissions/SchedulerPermissionsResolver.js.map +1 -0
- package/features/permissions/abstractions.d.ts +18 -12
- package/features/permissions/abstractions.js +4 -4
- package/features/permissions/abstractions.js.map +1 -1
- package/graphql/SchedulerGraphQLFactory.d.ts +4 -3
- package/graphql/SchedulerGraphQLFactory.js +6 -2
- package/graphql/SchedulerGraphQLFactory.js.map +1 -1
- package/{features/permissions → graphql}/feature.d.ts +1 -1
- package/graphql/feature.js +11 -0
- package/graphql/feature.js.map +1 -0
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/package.json +12 -22
- package/shared/abstractions.d.ts +30 -7
- package/shared/abstractions.js +2 -2
- package/shared/abstractions.js.map +1 -1
- package/context.d.ts +0 -7
- package/context.js +0 -47
- package/context.js.map +0 -1
- package/createEventHandler.d.ts +0 -14
- package/createEventHandler.js +0 -37
- package/createEventHandler.js.map +0 -1
- package/createScheduler.d.ts +0 -6
- package/createScheduler.js +0 -9
- package/createScheduler.js.map +0 -1
- package/domain/permissionsSchema.d.ts +0 -9
- package/domain/permissionsSchema.js +0 -18
- package/domain/permissionsSchema.js.map +0 -1
- package/features/SchedulerService/EventBridgeSchedulerService.d.ts +0 -26
- package/features/SchedulerService/EventBridgeSchedulerService.js +0 -97
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +0 -1
- package/features/permissions/feature.js +0 -7
- package/features/permissions/feature.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -35
- package/manifest.js.map +0 -1
package/shared/abstractions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const ScheduledActionHandler = createAbstraction("ScheduledActionHandler");
|
|
3
3
|
const SchedulerService = createAbstraction("SchedulerService");
|
|
4
|
-
const
|
|
5
|
-
export { ScheduledActionHandler,
|
|
4
|
+
const ScheduledActionModelProvider = createAbstraction("ScheduledActionModelProvider");
|
|
5
|
+
export { ScheduledActionHandler, ScheduledActionModelProvider, SchedulerService };
|
|
6
6
|
|
|
7
7
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared/abstractions.js","sources":["../../src/shared/abstractions.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/model.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\n/**\n * Identity type - represents who scheduled an action\n */\nexport interface Identity {\n id: string;\n type: string;\n displayName: string;\n}\n\nexport type ScheduledActionType =\n | typeof SCHEDULED_ACTION_PUBLISH\n | typeof SCHEDULED_ACTION_UNPUBLISH;\n/**\n * Scheduled Action Record - The data stored for a scheduled action\n */\n\nexport interface IScheduledActionEntryValues<T> {\n namespace: string; // Resource scope: \"Cms/Entry/Article\", \"Mailer/Email\"\n actionType: ScheduledActionType;\n targetId: string; // Resource identifier (entry ID, email ID, etc.)\n scheduledBy: Identity;\n scheduledFor: string;\n title: string;\n payload: T; // Action-specific data\n error: string | undefined; // Error if execution failed\n}\n\nexport interface IScheduledActionEntry<T extends GenericRecord = GenericRecord> extends CmsEntry<\n IScheduledActionEntryValues<T>\n> {}\n\nexport interface IScheduledAction<T extends GenericRecord = GenericRecord> extends Omit<\n IScheduledActionEntryValues<T>,\n \"scheduledFor\"\n> {\n id: string;\n scheduledFor: Date;\n}\n\n/**\n * ScheduledActionHandler - Similar to EventHandler pattern\n *\n * Each application (CMS, Mailer, etc.) implements handlers for their actions.\n * This is the ONLY action abstraction needed.\n */\nexport interface IScheduledActionHandler {\n /**\n * Determines if this handler can handle the given action\n *\n * @param namespace - Resource scope (e.g., \"Cms/Entry/Article\")\n * @param actionType - Operation type (e.g., \"Publish\")\n */\n canHandle(namespace: string, actionType: ScheduledActionType): boolean;\n\n /**\n * Executes the scheduled action\n */\n handle(action: IScheduledAction<any>): Promise<void>;\n}\n\n/** Handle execution of a scheduled action. */\nexport const ScheduledActionHandler =\n createAbstraction<IScheduledActionHandler>(\"ScheduledActionHandler\");\n\nexport namespace ScheduledActionHandler {\n export type Interface = IScheduledActionHandler;\n}\n\n/**\n * SchedulerService - Cloud-agnostic scheduler service\n *\n * Abstracts the underlying scheduling infrastructure (AWS EventBridge, Azure Logic Apps, etc.)\n */\n\nexport interface ISchedulerServiceCreateParams {\n id: string;\n namespace: string;\n scheduleFor: Date;\n}\nexport interface ISchedulerServiceUpdateParams {\n id: string;\n namespace: string;\n scheduleFor: Date;\n}\n\nexport interface ISchedulerService {\n create(params: ISchedulerServiceCreateParams): Promise<void>;\n update(params: ISchedulerServiceUpdateParams): Promise<void>;\n delete(
|
|
1
|
+
{"version":3,"file":"shared/abstractions.js","sources":["../../src/shared/abstractions.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/model.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\n/**\n * Identity type - represents who scheduled an action\n */\nexport interface Identity {\n id: string;\n type: string;\n displayName: string;\n}\n\nexport type ScheduledActionType =\n | typeof SCHEDULED_ACTION_PUBLISH\n | typeof SCHEDULED_ACTION_UNPUBLISH;\n/**\n * Scheduled Action Record - The data stored for a scheduled action\n */\n\nexport interface IScheduledActionEntryValues<T> {\n namespace: string; // Resource scope: \"Cms/Entry/Article\", \"Mailer/Email\"\n actionType: ScheduledActionType;\n targetId: string; // Resource identifier (entry ID, email ID, etc.)\n scheduledBy: Identity;\n scheduledFor: string;\n title: string;\n payload: T; // Action-specific data\n error: string | undefined; // Error if execution failed\n}\n\nexport interface IScheduledActionEntry<T extends GenericRecord = GenericRecord> extends CmsEntry<\n IScheduledActionEntryValues<T>\n> {}\n\nexport interface IScheduledAction<T extends GenericRecord = GenericRecord> extends Omit<\n IScheduledActionEntryValues<T>,\n \"scheduledFor\"\n> {\n id: string;\n tenant: string;\n scheduledFor: Date;\n}\n\n/**\n * ScheduledActionHandler - Similar to EventHandler pattern\n *\n * Each application (CMS, Mailer, etc.) implements handlers for their actions.\n * This is the ONLY action abstraction needed.\n */\nexport interface IScheduledActionHandler {\n /**\n * Determines if this handler can handle the given action\n *\n * @param namespace - Resource scope (e.g., \"Cms/Entry/Article\")\n * @param actionType - Operation type (e.g., \"Publish\")\n */\n canHandle(namespace: string, actionType: ScheduledActionType): boolean;\n\n /**\n * Executes the scheduled action\n */\n handle(action: IScheduledAction<any>): Promise<void>;\n}\n\n/** Handle execution of a scheduled action. */\nexport const ScheduledActionHandler =\n createAbstraction<IScheduledActionHandler>(\"ScheduledActionHandler\");\n\nexport namespace ScheduledActionHandler {\n export type Interface = IScheduledActionHandler;\n}\n\n/**\n * SchedulerService - Cloud-agnostic scheduler service\n *\n * Abstracts the underlying scheduling infrastructure (AWS EventBridge, Azure Logic Apps, etc.)\n */\n\nexport interface ISchedulerServiceCreateParams {\n id: string;\n tenant: string;\n namespace: string;\n scheduleFor: Date;\n}\nexport interface ISchedulerServiceUpdateParams {\n id: string;\n tenant: string;\n namespace: string;\n scheduleFor: Date;\n}\n\nexport interface ISchedulerServiceDeleteParams {\n id: string;\n namespace: string;\n tenant: string;\n}\n\nexport interface ISchedulerServiceExistsParams {\n id: string;\n namespace: string;\n tenant: string;\n}\n\nexport interface ISchedulerService {\n create(params: ISchedulerServiceCreateParams): Promise<void>;\n update(params: ISchedulerServiceUpdateParams): Promise<void>;\n delete(params: ISchedulerServiceDeleteParams): Promise<void>;\n exists(params: ISchedulerServiceExistsParams): Promise<boolean>;\n}\n\n/** Core service for managing scheduled actions. */\nexport const SchedulerService = createAbstraction<ISchedulerService>(\"SchedulerService\");\n\nexport namespace SchedulerService {\n export type Interface = ISchedulerService;\n export type CreateParams = ISchedulerServiceCreateParams;\n export type UpdateParams = ISchedulerServiceUpdateParams;\n export type DeleteParams = ISchedulerServiceDeleteParams;\n export type ExistsParams = ISchedulerServiceExistsParams;\n}\n\n/**\n * Provides the scheduler's CMS model for the current request's tenant.\n *\n * A provider rather than the model itself: fetching a model is asynchronous and tenant-dependent,\n * and DI resolution is synchronous — so an already-resolved `CmsModel` could only be supplied by a\n * per-request hook running before every consumer. Consumers `await get()` at the point of use.\n */\nexport interface IScheduledActionModelProvider {\n get(): Promise<CmsModel>;\n}\n\nexport const ScheduledActionModelProvider = createAbstraction<IScheduledActionModelProvider>(\n \"ScheduledActionModelProvider\"\n);\n\nexport namespace ScheduledActionModelProvider {\n export type Interface = IScheduledActionModelProvider;\n}\n"],"names":["ScheduledActionHandler","createAbstraction","SchedulerService","ScheduledActionModelProvider"],"mappings":";AAoEO,MAAMA,yBACTC,kBAA2C;AA6CxC,MAAMC,mBAAmBD,kBAAqC;AAqB9D,MAAME,+BAA+BF,kBACxC"}
|
package/context.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import type { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
-
import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
-
export interface ICreateHeadlessCmsSchedulerContextParams {
|
|
5
|
-
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
6
|
-
}
|
|
7
|
-
export declare const createSchedulerContext: (params: ICreateHeadlessCmsSchedulerContextParams) => (ContextPlugin<CmsContext> | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>)[];
|
package/context.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import { getManifest } from "./manifest.js";
|
|
3
|
-
import { SCHEDULE_MODEL_ID } from "./constants.js";
|
|
4
|
-
import { ScheduledActionModel, SchedulerService } from "./shared/abstractions.js";
|
|
5
|
-
import { EventBridgeSchedulerService } from "./features/SchedulerService/EventBridgeSchedulerService.js";
|
|
6
|
-
import { VoidSchedulerService } from "./features/SchedulerService/VoidSchedulerService.js";
|
|
7
|
-
import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
|
|
8
|
-
import { SchedulerFeature } from "./features/SchedulerFeature.js";
|
|
9
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
10
|
-
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
11
|
-
import { SchedulerGraphQLFactory } from "./graphql/index.js";
|
|
12
|
-
import { SchedulerPermissionsFeature } from "./features/permissions/feature.js";
|
|
13
|
-
import { NamespaceHandlerExecutioner } from "./features/NamespaceHandler/NamespaceHandlerExecutioner.js";
|
|
14
|
-
import { createRegisterExtensionPlugin } from "@webiny/handler";
|
|
15
|
-
const createSchedulerContext = (params)=>{
|
|
16
|
-
const modelsPlugin = createRegisterExtensionPlugin((context)=>{
|
|
17
|
-
context.container.register(SchedulePrivateModel);
|
|
18
|
-
});
|
|
19
|
-
const schedulerContextPlugin = new ContextPlugin(async (context)=>{
|
|
20
|
-
const tenantContext = context.container.resolve(TenantContext);
|
|
21
|
-
const getModel = context.container.resolve(GetModelUseCase);
|
|
22
|
-
if (!tenantContext.getTenant()) return;
|
|
23
|
-
const manifest = await getManifest({
|
|
24
|
-
client: context.db.driver.getClient()
|
|
25
|
-
});
|
|
26
|
-
if (manifest.error) context.container.registerInstance(SchedulerService, new VoidSchedulerService());
|
|
27
|
-
else context.container.registerInstance(SchedulerService, new EventBridgeSchedulerService(params.getClient, {
|
|
28
|
-
lambdaArn: manifest.data.lambdaArn,
|
|
29
|
-
roleArn: manifest.data.roleArn
|
|
30
|
-
}));
|
|
31
|
-
SchedulerPermissionsFeature.register(context.container);
|
|
32
|
-
context.container.register(SchedulerGraphQLFactory);
|
|
33
|
-
context.container.register(NamespaceHandlerExecutioner);
|
|
34
|
-
await context.security.withoutAuthorization(async ()=>{
|
|
35
|
-
const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);
|
|
36
|
-
context.container.registerInstance(ScheduledActionModel, schedulerModel.value);
|
|
37
|
-
});
|
|
38
|
-
SchedulerFeature.register(context.container);
|
|
39
|
-
});
|
|
40
|
-
return [
|
|
41
|
-
schedulerContextPlugin,
|
|
42
|
-
modelsPlugin
|
|
43
|
-
];
|
|
44
|
-
};
|
|
45
|
-
export { createSchedulerContext };
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=context.js.map
|
package/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport type { CmsContext } from \"@webiny/api-headless-cms/types/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport { EventBridgeSchedulerService } from \"~/features/SchedulerService/EventBridgeSchedulerService.js\";\nimport { VoidSchedulerService } from \"~/features/SchedulerService/VoidSchedulerService.js\";\nimport { SchedulePrivateModel } from \"~/domain/SchedulePrivateModel.js\";\nimport { SchedulerFeature } from \"./features/SchedulerFeature.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { SchedulerGraphQLFactory } from \"~/graphql/index.js\";\nimport { SchedulerPermissionsFeature } from \"~/features/permissions/feature.js\";\nimport { NamespaceHandlerExecutioner } from \"~/features/NamespaceHandler/NamespaceHandlerExecutioner.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createSchedulerContext = (params: ICreateHeadlessCmsSchedulerContextParams) => {\n const modelsPlugin = createRegisterExtensionPlugin(context => {\n context.container.register(SchedulePrivateModel);\n });\n\n const schedulerContextPlugin = new ContextPlugin<CmsContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const getModel = context.container.resolve(GetModelUseCase);\n\n if (!tenantContext.getTenant()) {\n return;\n }\n\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n\n if (manifest.error) {\n context.container.registerInstance(SchedulerService, new VoidSchedulerService());\n } else {\n // TODO: in the future, extract AWS specific implementation into a separate package\n context.container.registerInstance(\n SchedulerService,\n new EventBridgeSchedulerService(params.getClient, {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n })\n );\n }\n\n SchedulerPermissionsFeature.register(context.container);\n context.container.register(SchedulerGraphQLFactory);\n context.container.register(NamespaceHandlerExecutioner);\n\n await context.security.withoutAuthorization(async () => {\n const schedulerModel = await getModel.execute(SCHEDULE_MODEL_ID);\n context.container.registerInstance(ScheduledActionModel, schedulerModel.value);\n });\n\n // Register all features\n SchedulerFeature.register(context.container);\n });\n\n return [schedulerContextPlugin, modelsPlugin];\n};\n"],"names":["createSchedulerContext","params","modelsPlugin","createRegisterExtensionPlugin","context","SchedulePrivateModel","schedulerContextPlugin","ContextPlugin","tenantContext","TenantContext","getModel","GetModelUseCase","manifest","getManifest","SchedulerService","VoidSchedulerService","EventBridgeSchedulerService","SchedulerPermissionsFeature","SchedulerGraphQLFactory","NamespaceHandlerExecutioner","schedulerModel","SCHEDULE_MODEL_ID","ScheduledActionModel","SchedulerFeature"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA,yBAAyB,CAACC;IACnC,MAAMC,eAAeC,8BAA8BC,CAAAA;QAC/CA,QAAQ,SAAS,CAAC,QAAQ,CAACC;IAC/B;IAEA,MAAMC,yBAAyB,IAAIC,cAA0B,OAAMH;QAC/D,MAAMI,gBAAgBJ,QAAQ,SAAS,CAAC,OAAO,CAACK;QAChD,MAAMC,WAAWN,QAAQ,SAAS,CAAC,OAAO,CAACO;QAE3C,IAAI,CAACH,cAAc,SAAS,IACxB;QAGJ,MAAMI,WAAW,MAAMC,YAAY;YAC/B,QAAQT,QAAQ,EAAE,CAAC,MAAM,CAAC,SAAS;QACvC;QAEA,IAAIQ,SAAS,KAAK,EACdR,QAAQ,SAAS,CAAC,gBAAgB,CAACU,kBAAkB,IAAIC;aAGzDX,QAAQ,SAAS,CAAC,gBAAgB,CAC9BU,kBACA,IAAIE,4BAA4Bf,OAAO,SAAS,EAAE;YAC9C,WAAWW,SAAS,IAAI,CAAC,SAAS;YAClC,SAASA,SAAS,IAAI,CAAC,OAAO;QAClC;QAIRK,4BAA4B,QAAQ,CAACb,QAAQ,SAAS;QACtDA,QAAQ,SAAS,CAAC,QAAQ,CAACc;QAC3Bd,QAAQ,SAAS,CAAC,QAAQ,CAACe;QAE3B,MAAMf,QAAQ,QAAQ,CAAC,oBAAoB,CAAC;YACxC,MAAMgB,iBAAiB,MAAMV,SAAS,OAAO,CAACW;YAC9CjB,QAAQ,SAAS,CAAC,gBAAgB,CAACkB,sBAAsBF,eAAe,KAAK;QACjF;QAGAG,iBAAiB,QAAQ,CAACnB,QAAQ,SAAS;IAC/C;IAEA,OAAO;QAACE;QAAwBJ;KAAa;AACjD"}
|
package/createEventHandler.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
|
|
2
|
-
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
3
|
-
export interface IScheduledActionEventPayload {
|
|
4
|
-
namespace: string;
|
|
5
|
-
id: string;
|
|
6
|
-
scheduleFor: string;
|
|
7
|
-
}
|
|
8
|
-
export interface IScheduledActionEvent {
|
|
9
|
-
[SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;
|
|
10
|
-
}
|
|
11
|
-
export interface HandlerParams extends HandlerFactoryParams {
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare const createScheduledActionEventHandler: () => import("@webiny/handler-aws/raw/index.js").RawEventHandler<IScheduledActionEvent, import("@webiny/handler/types").Context, any>;
|
package/createEventHandler.js
DELETED
|
@@ -1,37 +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 "./constants.js";
|
|
5
|
-
import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
|
|
6
|
-
const canHandle = (event)=>{
|
|
7
|
-
if ("function" != typeof event?.hasOwnProperty) return false;
|
|
8
|
-
if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) return false;
|
|
9
|
-
const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
10
|
-
return !!(value?.id && value?.scheduleFor);
|
|
11
|
-
};
|
|
12
|
-
const handler = createSourceHandler({
|
|
13
|
-
name: "handler-aws-event-bridge-scheduled-cms-action-event",
|
|
14
|
-
canUse: canHandle,
|
|
15
|
-
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
16
|
-
});
|
|
17
|
-
registry.register(handler);
|
|
18
|
-
const createScheduledActionEventHandler = ()=>createEventHandler({
|
|
19
|
-
canHandle: canHandle,
|
|
20
|
-
handle: async (params)=>{
|
|
21
|
-
const { payload, context } = params;
|
|
22
|
-
const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
23
|
-
const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);
|
|
24
|
-
const result = await executeScheduledAction.execute(input);
|
|
25
|
-
if (result.isFail()) {
|
|
26
|
-
const error = result.error;
|
|
27
|
-
console.error(error.code, error.message);
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
success: true
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
export { createScheduledActionEventHandler };
|
|
36
|
-
|
|
37
|
-
//# sourceMappingURL=createEventHandler.js.map
|
|
@@ -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 \"~/constants.js\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\n\nexport interface IScheduledActionEventPayload {\n namespace: string;\n id: string;\n scheduleFor: string;\n}\n\nexport interface IScheduledActionEvent {\n [SCHEDULED_ACTION_EVENT_IDENTIFIER]: IScheduledActionEventPayload;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst canHandle = (event: Partial<IScheduledActionEvent>): boolean => {\n if (typeof event?.hasOwnProperty !== \"function\") {\n return false;\n } else if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) {\n return false;\n }\n\n const value = event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n return !!(value?.id && value?.scheduleFor);\n};\n\nconst handler = createSourceHandler<IScheduledActionEvent, HandlerParams>({\n name: \"handler-aws-event-bridge-scheduled-cms-action-event\",\n canUse: canHandle,\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n\nexport const createScheduledActionEventHandler = () => {\n return createEventHandler<IScheduledActionEvent>({\n canHandle,\n handle: async params => {\n const { payload, context } = params;\n const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n const executeScheduledAction = context.container.resolve(ExecuteScheduledActionUseCase);\n const result = await executeScheduledAction.execute(input);\n\n if (result.isFail()) {\n const error = result.error;\n console.error(error.code, error.message);\n throw error;\n }\n return {\n success: true\n };\n }\n });\n};\n"],"names":["canHandle","event","SCHEDULED_ACTION_EVENT_IDENTIFIER","value","handler","createSourceHandler","params","context","createHandler","registry","createScheduledActionEventHandler","createEventHandler","payload","input","executeScheduledAction","ExecuteScheduledActionUseCase","result","error","console"],"mappings":";;;;;AAqBA,MAAMA,YAAY,CAACC;IACf,IAAI,AAAiC,cAAjC,OAAOA,OAAO,gBACd,OAAO;IACJ,IAAI,CAACA,MAAM,cAAc,CAACC,oCAC7B,OAAO;IAGX,MAAMC,QAAQF,KAAK,CAACC,kCAAkC;IACtD,OAAO,CAAC,CAAEC,CAAAA,OAAO,MAAMA,OAAO,WAAU;AAC5C;AAEA,MAAMC,UAAUC,oBAA0D;IACtE,MAAM;IACN,QAAQL;IACR,QAAQ,OAAO,EAAEM,MAAM,EAAEL,KAAK,EAAEM,OAAO,EAAE,GAC9BC,cAAcF,QAAQL,OAAOM;AAE5C;AAEAE,SAAS,QAAQ,CAACL;AAEX,MAAMM,oCAAoC,IACtCC,mBAA0C;QAC7CX,WAAAA;QACA,QAAQ,OAAMM;YACV,MAAM,EAAEM,OAAO,EAAEL,OAAO,EAAE,GAAGD;YAC7B,MAAMO,QAAQD,OAAO,CAACV,kCAAkC;YAExD,MAAMY,yBAAyBP,QAAQ,SAAS,CAAC,OAAO,CAACQ;YACzD,MAAMC,SAAS,MAAMF,uBAAuB,OAAO,CAACD;YAEpD,IAAIG,OAAO,MAAM,IAAI;gBACjB,MAAMC,QAAQD,OAAO,KAAK;gBAC1BE,QAAQ,KAAK,CAACD,MAAM,IAAI,EAAEA,MAAM,OAAO;gBACvC,MAAMA;YACV;YACA,OAAO;gBACH,SAAS;YACb;QACJ;IACJ"}
|
package/createScheduler.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "@webiny/plugins/types.js";
|
|
2
|
-
import { SchedulerClient, SchedulerClientConfig } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
-
export interface ICreateSchedulerParams {
|
|
4
|
-
getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, "send">;
|
|
5
|
-
}
|
|
6
|
-
export declare const createScheduler: (params: ICreateSchedulerParams) => Plugin[];
|
package/createScheduler.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createSchedulerContext } from "./context.js";
|
|
2
|
-
import { createScheduledActionEventHandler } from "./createEventHandler.js";
|
|
3
|
-
const createScheduler = (params)=>[
|
|
4
|
-
createScheduledActionEventHandler(),
|
|
5
|
-
...createSchedulerContext(params)
|
|
6
|
-
];
|
|
7
|
-
export { createScheduler };
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=createScheduler.js.map
|
package/createScheduler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createScheduler.js","sources":["../src/createScheduler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport { SchedulerClient, SchedulerClientConfig } from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { createSchedulerContext } from \"~/context.js\";\nimport { createScheduledActionEventHandler } from \"~/createEventHandler.js\";\n\nexport interface ICreateSchedulerParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\nexport const createScheduler = (params: ICreateSchedulerParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled Action Event.\n */\n createScheduledActionEventHandler(),\n ...createSchedulerContext(params)\n ];\n};\n"],"names":["createScheduler","params","createScheduledActionEventHandler","createSchedulerContext"],"mappings":";;AAQO,MAAMA,kBAAkB,CAACC,SACrB;QAIHC;WACGC,uBAAuBF;KAC7B"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const SCHEDULER_PERMISSIONS_SCHEMA: {
|
|
2
|
-
readonly prefix: "scheduler";
|
|
3
|
-
readonly fullAccess: true;
|
|
4
|
-
readonly entities: readonly [{
|
|
5
|
-
readonly id: "action";
|
|
6
|
-
readonly permission: "scheduler.action";
|
|
7
|
-
readonly scopes: readonly ["full", "own"];
|
|
8
|
-
}];
|
|
9
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { createPermissionSchema } from "@webiny/api-core/exports/api/security.js";
|
|
2
|
-
const SCHEDULER_PERMISSIONS_SCHEMA = createPermissionSchema({
|
|
3
|
-
prefix: "scheduler",
|
|
4
|
-
fullAccess: true,
|
|
5
|
-
entities: [
|
|
6
|
-
{
|
|
7
|
-
id: "action",
|
|
8
|
-
permission: "scheduler.action",
|
|
9
|
-
scopes: [
|
|
10
|
-
"full",
|
|
11
|
-
"own"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
});
|
|
16
|
-
export { SCHEDULER_PERMISSIONS_SCHEMA };
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=permissionsSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"domain/permissionsSchema.js","sources":["../../src/domain/permissionsSchema.ts"],"sourcesContent":["import { createPermissionSchema } from \"@webiny/api-core/exports/api/security.js\";\n\nexport const SCHEDULER_PERMISSIONS_SCHEMA = createPermissionSchema({\n prefix: \"scheduler\",\n fullAccess: true,\n entities: [\n {\n id: \"action\",\n permission: \"scheduler.action\",\n scopes: [\"full\", \"own\"]\n }\n ]\n});\n"],"names":["SCHEDULER_PERMISSIONS_SCHEMA","createPermissionSchema"],"mappings":";AAEO,MAAMA,+BAA+BC,uBAAuB;IAC/D,QAAQ;IACR,YAAY;IACZ,UAAU;QACN;YACI,IAAI;YACJ,YAAY;YACZ,QAAQ;gBAAC;gBAAQ;aAAM;QAC3B;KACH;AACL"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type ISchedulerServiceCreateParams, type ISchedulerServiceUpdateParams, SchedulerService } from "../../shared/abstractions.js";
|
|
2
|
-
import { type SchedulerClient } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
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
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import { CreateScheduleCommand, DeleteScheduleCommand, GetScheduleCommand, UpdateScheduleCommand } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
|
-
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "../../constants.js";
|
|
4
|
-
class EventBridgeSchedulerService {
|
|
5
|
-
constructor(getClient, config){
|
|
6
|
-
this.getClient = getClient;
|
|
7
|
-
this.config = config;
|
|
8
|
-
}
|
|
9
|
-
async create(params) {
|
|
10
|
-
const { id, scheduleFor } = params;
|
|
11
|
-
if (scheduleFor <= new Date()) throw new WebinyError(`Cannot create a schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
|
|
12
|
-
scheduleFor,
|
|
13
|
-
id
|
|
14
|
-
});
|
|
15
|
-
const client = this.getClient();
|
|
16
|
-
const exists = await this.exists(id);
|
|
17
|
-
if (exists) return this.update(params);
|
|
18
|
-
await client.send(new CreateScheduleCommand({
|
|
19
|
-
Name: id,
|
|
20
|
-
ScheduleExpression: this.createScheduleExpression(scheduleFor),
|
|
21
|
-
FlexibleTimeWindow: {
|
|
22
|
-
Mode: "OFF"
|
|
23
|
-
},
|
|
24
|
-
Target: {
|
|
25
|
-
Arn: this.config.lambdaArn,
|
|
26
|
-
RoleArn: this.config.roleArn,
|
|
27
|
-
Input: this.createScheduledActionEventInput(params)
|
|
28
|
-
},
|
|
29
|
-
ActionAfterCompletion: "DELETE"
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
async update(params) {
|
|
33
|
-
const { id, scheduleFor } = params;
|
|
34
|
-
if (scheduleFor <= new Date()) throw new WebinyError(`Cannot update an existing schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
|
|
35
|
-
scheduleFor,
|
|
36
|
-
id
|
|
37
|
-
});
|
|
38
|
-
const client = this.getClient();
|
|
39
|
-
await client.send(new UpdateScheduleCommand({
|
|
40
|
-
Name: id,
|
|
41
|
-
ScheduleExpression: this.createScheduleExpression(scheduleFor),
|
|
42
|
-
FlexibleTimeWindow: {
|
|
43
|
-
Mode: "OFF"
|
|
44
|
-
},
|
|
45
|
-
Target: {
|
|
46
|
-
Arn: this.config.lambdaArn,
|
|
47
|
-
RoleArn: this.config.roleArn,
|
|
48
|
-
Input: this.createScheduledActionEventInput(params)
|
|
49
|
-
},
|
|
50
|
-
ActionAfterCompletion: "DELETE"
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
async delete(id) {
|
|
54
|
-
const client = this.getClient();
|
|
55
|
-
const exists = await this.exists(id);
|
|
56
|
-
if (!exists) throw new WebinyError(`Cannot delete schedule "${id}" because it does not exist.`);
|
|
57
|
-
try {
|
|
58
|
-
await client.send(new DeleteScheduleCommand({
|
|
59
|
-
Name: id
|
|
60
|
-
}));
|
|
61
|
-
} catch (ex) {
|
|
62
|
-
if ("ResourceNotFoundException" === ex.name) return;
|
|
63
|
-
throw WebinyError.from(ex);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async exists(id) {
|
|
67
|
-
const client = this.getClient();
|
|
68
|
-
try {
|
|
69
|
-
await client.send(new GetScheduleCommand({
|
|
70
|
-
Name: id
|
|
71
|
-
}));
|
|
72
|
-
return true;
|
|
73
|
-
} catch (ex) {
|
|
74
|
-
if ("ResourceNotFoundException" === ex.name) return false;
|
|
75
|
-
throw ex;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
createScheduleExpression(scheduleFor) {
|
|
79
|
-
return `at(${scheduleFor.toISOString().replace(/\.\d{3}Z$/, "")})`;
|
|
80
|
-
}
|
|
81
|
-
createScheduledActionEventInput(params) {
|
|
82
|
-
return JSON.stringify({
|
|
83
|
-
[SCHEDULED_ACTION_EVENT_IDENTIFIER]: this.createScheduledActionEventPayload(params)
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
createScheduledActionEventPayload(params) {
|
|
87
|
-
const { id, scheduleFor, namespace } = params;
|
|
88
|
-
return {
|
|
89
|
-
id,
|
|
90
|
-
namespace,
|
|
91
|
-
scheduleFor: scheduleFor.toISOString()
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export { EventBridgeSchedulerService };
|
|
96
|
-
|
|
97
|
-
//# sourceMappingURL=EventBridgeSchedulerService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 \"~/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 \"~/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, namespace } = params;\n\n return {\n id,\n namespace,\n scheduleFor: scheduleFor.toISOString()\n };\n }\n}\n"],"names":["EventBridgeSchedulerService","getClient","config","params","id","scheduleFor","Date","WebinyError","client","exists","CreateScheduleCommand","UpdateScheduleCommand","DeleteScheduleCommand","ex","GetScheduleCommand","JSON","SCHEDULED_ACTION_EVENT_IDENTIFIER","namespace"],"mappings":"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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createPermissionsFeature } from "@webiny/api-core/exports/api/security.js";
|
|
2
|
-
import { SCHEDULER_PERMISSIONS_SCHEMA } from "../../domain/permissionsSchema.js";
|
|
3
|
-
import { SchedulerPermissions } from "./abstractions.js";
|
|
4
|
-
const SchedulerPermissionsFeature = createPermissionsFeature(SCHEDULER_PERMISSIONS_SCHEMA, SchedulerPermissions);
|
|
5
|
-
export { SchedulerPermissionsFeature };
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/permissions/feature.js","sources":["../../../src/features/permissions/feature.ts"],"sourcesContent":["import { createPermissionsFeature } from \"@webiny/api-core/exports/api/security.js\";\nimport { SCHEDULER_PERMISSIONS_SCHEMA } from \"~/domain/permissionsSchema.js\";\nimport { SchedulerPermissions } from \"./abstractions.js\";\n\nexport const SchedulerPermissionsFeature = createPermissionsFeature(\n SCHEDULER_PERMISSIONS_SCHEMA,\n SchedulerPermissions\n);\n"],"names":["SchedulerPermissionsFeature","createPermissionsFeature","SCHEDULER_PERMISSIONS_SCHEMA","SchedulerPermissions"],"mappings":";;;AAIO,MAAMA,8BAA8BC,yBACvCC,8BACAC"}
|
package/manifest.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
const getManifest = async (params)=>{
|
|
11
|
-
try {
|
|
12
|
-
ServiceDiscovery.setDocumentClient(params.client);
|
|
13
|
-
const manifest = await ServiceDiscovery.load();
|
|
14
|
-
if (!manifest) return {
|
|
15
|
-
error: new Error("Manifest could not be loaded.")
|
|
16
|
-
};
|
|
17
|
-
if (!manifest.scheduler) return {
|
|
18
|
-
error: new Error("Scheduler not found in the Manifest.")
|
|
19
|
-
};
|
|
20
|
-
const result = await schema.safeParseAsync(manifest);
|
|
21
|
-
if (!result.success) return {
|
|
22
|
-
error: createZodError(result.error)
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
data: result.data.scheduler
|
|
26
|
-
};
|
|
27
|
-
} catch (ex) {
|
|
28
|
-
return {
|
|
29
|
-
error: ex
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
export { getManifest };
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=manifest.js.map
|
package/manifest.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sources":["../src/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"],"names":["schema","zod","getManifest","params","ServiceDiscovery","manifest","Error","result","createZodError","ex"],"mappings":";;;AAKA,MAAMA,SAASC,IAAI,MAAM,CAAC;IACtB,WAAWA,IAAI,MAAM,CAAC;QAClB,WAAWA,IAAI,MAAM;QACrB,SAASA,IAAI,MAAM;IACvB;AACJ;AAqBO,MAAMC,cAAc,OAAOC;IAC9B,IAAI;QACAC,iBAAiB,iBAAiB,CAACD,OAAO,MAAM;QAChD,MAAME,WAAW,MAAMD,iBAAiB,IAAI;QAC5C,IAAI,CAACC,UACD,OAAO;YACH,OAAO,IAAIC,MAAM;QACrB;QACG,IAAI,CAACD,SAAS,SAAS,EAC1B,OAAO;YACH,OAAO,IAAIC,MAAM;QACrB;QAGJ,MAAMC,SAAS,MAAMP,OAAO,cAAc,CAACK;QAC3C,IAAI,CAACE,OAAO,OAAO,EACf,OAAO;YACH,OAAOC,eAAeD,OAAO,KAAK;QACtC;QAGJ,OAAO;YACH,MAAMA,OAAO,IAAI,CAAC,SAAS;QAC/B;IACJ,EAAE,OAAOE,IAAI;QACT,OAAO;YACH,OAAOA;QACX;IACJ;AACJ"}
|