@webiny/api-scheduler 6.4.2 → 6.4.3-beta.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/createEventHandler.d.ts +1 -0
- package/createEventHandler.js +20 -10
- package/createEventHandler.js.map +1 -1
- package/domain/ScheduledActionMapper.js +2 -1
- package/domain/ScheduledActionMapper.js.map +1 -1
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +3 -3
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +1 -0
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +1 -0
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/ScheduleAction/ScheduleActionUseCase.js +19 -15
- 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/SchedulerService/EventBridgeSchedulerService.d.ts +6 -5
- package/features/SchedulerService/EventBridgeSchedulerService.js +16 -9
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -1
- package/features/SchedulerService/VoidSchedulerService.d.ts +9 -9
- package/features/SchedulerService/VoidSchedulerService.js +4 -4
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
- package/package.json +18 -18
- package/shared/abstractions.d.ts +19 -2
- package/shared/abstractions.js.map +1 -1
package/createEventHandler.d.ts
CHANGED
package/createEventHandler.js
CHANGED
|
@@ -3,6 +3,8 @@ import { createSourceHandler } from "@webiny/handler-aws/sourceHandler.js";
|
|
|
3
3
|
import { createEventHandler, createHandler } from "@webiny/handler-aws/raw/index.js";
|
|
4
4
|
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
5
5
|
import { ExecuteScheduledActionUseCase } from "./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";
|
|
6
8
|
const canHandle = (event)=>{
|
|
7
9
|
if ("function" != typeof event?.hasOwnProperty) return false;
|
|
8
10
|
if (!event.hasOwnProperty(SCHEDULED_ACTION_EVENT_IDENTIFIER)) return false;
|
|
@@ -20,16 +22,24 @@ const createScheduledActionEventHandler = ()=>createEventHandler({
|
|
|
20
22
|
handle: async (params)=>{
|
|
21
23
|
const { payload, context } = params;
|
|
22
24
|
const input = payload[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
});
|
|
33
43
|
}
|
|
34
44
|
});
|
|
35
45
|
export { createScheduledActionEventHandler };
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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\";\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"}
|
|
@@ -12,7 +12,8 @@ class ScheduledActionMapper {
|
|
|
12
12
|
actionType: action.values.actionType,
|
|
13
13
|
title: action.values.title,
|
|
14
14
|
payload: action.values.payload,
|
|
15
|
-
error: action.values.error
|
|
15
|
+
error: action.values.error,
|
|
16
|
+
tenant: action.tenant
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
static toActions(actions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/ScheduledActionMapper.js","sources":["../../src/domain/ScheduledActionMapper.ts"],"sourcesContent":["import type { IScheduledAction, IScheduledActionEntry } from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\nexport class ScheduledActionMapper {\n static toAction<T extends GenericRecord = GenericRecord>(\n action: IScheduledActionEntry<T>\n ): IScheduledAction<T> {\n const { id: scheduleId } = parseIdentifier(action.id);\n return {\n id: scheduleId,\n targetId: action.values.targetId,\n namespace: action.values.namespace,\n scheduledBy: action.values.scheduledBy,\n scheduledFor: new Date(action.values.scheduledFor),\n actionType: action.values.actionType,\n title: action.values.title,\n payload: action.values.payload,\n error: action.values.error\n };\n }\n\n static toActions<T extends GenericRecord = GenericRecord>(\n actions: IScheduledActionEntry<T>[]\n ): IScheduledAction<T>[] {\n return actions.map(ScheduledActionMapper.toAction);\n }\n\n static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>) {\n return {\n id: action.id,\n targetId: action.targetId,\n namespace: action.namespace,\n scheduledBy: action.scheduledBy,\n publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,\n unpublishOn:\n action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,\n actionType: action.actionType,\n title: action.title\n };\n }\n}\n"],"names":["ScheduledActionMapper","action","scheduleId","parseIdentifier","Date","actions","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH"],"mappings":";;AAKO,MAAMA;IACT,OAAO,SACHC,MAAgC,EACb;QACnB,MAAM,EAAE,IAAIC,UAAU,EAAE,GAAGC,gBAAgBF,OAAO,EAAE;QACpD,OAAO;YACH,IAAIC;YACJ,UAAUD,OAAO,MAAM,CAAC,QAAQ;YAChC,WAAWA,OAAO,MAAM,CAAC,SAAS;YAClC,aAAaA,OAAO,MAAM,CAAC,WAAW;YACtC,cAAc,IAAIG,KAAKH,OAAO,MAAM,CAAC,YAAY;YACjD,YAAYA,OAAO,MAAM,CAAC,UAAU;YACpC,OAAOA,OAAO,MAAM,CAAC,KAAK;YAC1B,SAASA,OAAO,MAAM,CAAC,OAAO;YAC9B,OAAOA,OAAO,MAAM,CAAC,KAAK;
|
|
1
|
+
{"version":3,"file":"domain/ScheduledActionMapper.js","sources":["../../src/domain/ScheduledActionMapper.ts"],"sourcesContent":["import type { IScheduledAction, IScheduledActionEntry } from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\nexport class ScheduledActionMapper {\n static toAction<T extends GenericRecord = GenericRecord>(\n action: IScheduledActionEntry<T>\n ): IScheduledAction<T> {\n const { id: scheduleId } = parseIdentifier(action.id);\n return {\n id: scheduleId,\n targetId: action.values.targetId,\n namespace: action.values.namespace,\n scheduledBy: action.values.scheduledBy,\n scheduledFor: new Date(action.values.scheduledFor),\n actionType: action.values.actionType,\n title: action.values.title,\n payload: action.values.payload,\n error: action.values.error,\n tenant: action.tenant\n };\n }\n\n static toActions<T extends GenericRecord = GenericRecord>(\n actions: IScheduledActionEntry<T>[]\n ): IScheduledAction<T>[] {\n return actions.map(ScheduledActionMapper.toAction);\n }\n\n static toGraphQL<T extends GenericRecord = GenericRecord>(action: IScheduledAction<T>) {\n return {\n id: action.id,\n targetId: action.targetId,\n namespace: action.namespace,\n scheduledBy: action.scheduledBy,\n publishOn: action.actionType === SCHEDULED_ACTION_PUBLISH ? action.scheduledFor : null,\n unpublishOn:\n action.actionType === SCHEDULED_ACTION_UNPUBLISH ? action.scheduledFor : null,\n actionType: action.actionType,\n title: action.title\n };\n }\n}\n"],"names":["ScheduledActionMapper","action","scheduleId","parseIdentifier","Date","actions","SCHEDULED_ACTION_PUBLISH","SCHEDULED_ACTION_UNPUBLISH"],"mappings":";;AAKO,MAAMA;IACT,OAAO,SACHC,MAAgC,EACb;QACnB,MAAM,EAAE,IAAIC,UAAU,EAAE,GAAGC,gBAAgBF,OAAO,EAAE;QACpD,OAAO;YACH,IAAIC;YACJ,UAAUD,OAAO,MAAM,CAAC,QAAQ;YAChC,WAAWA,OAAO,MAAM,CAAC,SAAS;YAClC,aAAaA,OAAO,MAAM,CAAC,WAAW;YACtC,cAAc,IAAIG,KAAKH,OAAO,MAAM,CAAC,YAAY;YACjD,YAAYA,OAAO,MAAM,CAAC,UAAU;YACpC,OAAOA,OAAO,MAAM,CAAC,KAAK;YAC1B,SAASA,OAAO,MAAM,CAAC,OAAO;YAC9B,OAAOA,OAAO,MAAM,CAAC,KAAK;YAC1B,QAAQA,OAAO,MAAM;QACzB;IACJ;IAEA,OAAO,UACHI,OAAmC,EACd;QACrB,OAAOA,QAAQ,GAAG,CAACL,sBAAsB,QAAQ;IACrD;IAEA,OAAO,UAAmDC,MAA2B,EAAE;QACnF,OAAO;YACH,IAAIA,OAAO,EAAE;YACb,UAAUA,OAAO,QAAQ;YACzB,WAAWA,OAAO,SAAS;YAC3B,aAAaA,OAAO,WAAW;YAC/B,WAAWA,OAAO,UAAU,KAAKK,2BAA2BL,OAAO,YAAY,GAAG;YAClF,aACIA,OAAO,UAAU,KAAKM,6BAA6BN,OAAO,YAAY,GAAG;YAC7E,YAAYA,OAAO,UAAU;YAC7B,OAAOA,OAAO,KAAK;QACvB;IACJ;AACJ"}
|
|
@@ -27,10 +27,10 @@ class CancelScheduledActionUseCaseImpl {
|
|
|
27
27
|
}
|
|
28
28
|
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
29
29
|
try {
|
|
30
|
-
const eventBridgeSchedule = await this.schedulerService.exists(
|
|
31
|
-
if (eventBridgeSchedule) await this.schedulerService.delete(
|
|
30
|
+
const eventBridgeSchedule = await this.schedulerService.exists(params);
|
|
31
|
+
if (eventBridgeSchedule) await this.schedulerService.delete(params);
|
|
32
32
|
} catch (error) {
|
|
33
|
-
console.warn(`Failed to delete EventBridge schedule: ${scheduleId}. Continuing with CMS entry deletion.`, error);
|
|
33
|
+
console.warn(`Failed to delete EventBridge schedule: ${scheduleId}, tenant "${params.tenant}". Continuing with CMS entry deletion.`, error);
|
|
34
34
|
}
|
|
35
35
|
const deleteResult = await this.deleteEntryUseCase.execute(this.model, getResult.value.id, {
|
|
36
36
|
force: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CancelScheduledAction/CancelScheduledActionUseCase.js","sources":["../../../src/features/CancelScheduledAction/CancelScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { CancelScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { EntryNotFoundError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\nimport { SchedulerPermissions } from \"~/features/permissions/abstractions.js\";\n\n/**\n * Cancels a scheduled action\n *\n * Flow:\n * 1. Check if schedule exists\n * 2. Delete EventBridge schedule\n * 3. Delete CMS entry\n * 4. If EventBridge delete fails, continue anyway (schedule might already be executed/deleted)\n */\nclass CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getScheduledActionUseCase: GetScheduledActionUseCase.Interface,\n private schedulerService: SchedulerService.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private permissions: SchedulerPermissions.Interface\n ) {}\n\n async execute(\n params: UseCaseAbstraction.Params\n ): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n const { id } = params;\n // Check if scheduled action exists\n const getResult = await this.getScheduledActionUseCase.execute(params);\n\n if (getResult.isFail()) {\n const error = getResult.error;\n\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(error);\n }\n\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n\n // Delete EventBridge schedule\n // Note: We continue even if this fails, as the schedule might already be executed/deleted\n try {\n const eventBridgeSchedule = await this.schedulerService.exists(
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledAction/CancelScheduledActionUseCase.js","sources":["../../../src/features/CancelScheduledAction/CancelScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { CancelScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { EntryNotFoundError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\nimport { SchedulerPermissions } from \"~/features/permissions/abstractions.js\";\n\n/**\n * Cancels a scheduled action\n *\n * Flow:\n * 1. Check if schedule exists\n * 2. Delete EventBridge schedule\n * 3. Delete CMS entry\n * 4. If EventBridge delete fails, continue anyway (schedule might already be executed/deleted)\n */\nclass CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getScheduledActionUseCase: GetScheduledActionUseCase.Interface,\n private schedulerService: SchedulerService.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private permissions: SchedulerPermissions.Interface\n ) {}\n\n async execute(\n params: UseCaseAbstraction.Params\n ): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n const { id } = params;\n // Check if scheduled action exists\n const getResult = await this.getScheduledActionUseCase.execute(params);\n\n if (getResult.isFail()) {\n const error = getResult.error;\n\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(error);\n }\n\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n\n // Delete EventBridge schedule\n // Note: We continue even if this fails, as the schedule might already be executed/deleted\n try {\n const eventBridgeSchedule = await this.schedulerService.exists(params);\n /**\n * No point to even try deleting if it doesn't exist.\n */\n if (eventBridgeSchedule) {\n await this.schedulerService.delete(params);\n }\n } catch (error) {\n console.warn(\n `Failed to delete EventBridge schedule: ${scheduleId}, tenant \"${params.tenant}\". Continuing with CMS entry deletion.`,\n error\n );\n }\n\n // Delete CMS entry\n const deleteResult = await this.deleteEntryUseCase.execute(this.model, getResult.value.id, {\n force: true,\n permanently: true\n });\n\n if (deleteResult.isFail()) {\n /**\n * Some process could have already deleted the entry, in which case we can safely ignore this error.\n */\n if (deleteResult.error instanceof EntryNotFoundError) {\n return Result.ok(true);\n }\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(deleteResult.error.message))\n );\n }\n\n return Result.ok(true);\n }\n}\n\nexport const CancelScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: CancelScheduledActionUseCaseImpl,\n dependencies: [\n GetScheduledActionUseCase,\n SchedulerService,\n DeleteEntryUseCase,\n ScheduledActionModel,\n SchedulerPermissions\n ]\n});\n"],"names":["CancelScheduledActionUseCaseImpl","getScheduledActionUseCase","schedulerService","deleteEntryUseCase","model","permissions","params","hasPermission","Result","NotAuthorizedError","id","getResult","error","ScheduledActionNotFoundError","scheduleId","ScheduledActionIdWithVersion","eventBridgeSchedule","console","deleteResult","EntryNotFoundError","ScheduledActionPersistenceError","Error","CancelScheduledActionUseCase","UseCaseAbstraction","GetScheduledActionUseCase","SchedulerService","DeleteEntryUseCase","ScheduledActionModel","SchedulerPermissions"],"mappings":";;;;;;;;;AAuBA,MAAMA;IACF,YACYC,yBAA8D,EAC9DC,gBAA4C,EAC5CC,kBAAgD,EAChDC,KAAqC,EACrCC,WAA2C,CACrD;aALUJ,yBAAyB,GAAzBA;aACAC,gBAAgB,GAAhBA;aACAC,kBAAkB,GAAlBA;aACAC,KAAK,GAALA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,MAAiC,EACiB;QAClD,MAAMC,gBAAgB,MAA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type CancelScheduledActionError = ICancelScheduledActionErrors[keyof ICancelSche
|
|
|
17
17
|
export interface ICancelScheduledActionUseCaseParams {
|
|
18
18
|
namespace: string;
|
|
19
19
|
id: string;
|
|
20
|
+
tenant: string;
|
|
20
21
|
}
|
|
21
22
|
export interface ICancelScheduledActionUseCase {
|
|
22
23
|
execute(params: ICancelScheduledActionUseCaseParams): Promise<Result<boolean, CancelScheduledActionError>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CancelScheduledAction/abstractions.js","sources":["../../../src/features/CancelScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError,\n SchedulerServiceError\n} from \"~/domain/errors.js\";\n\n/**\n * CancelScheduledActionUseCase - Cancel a scheduled action\n *\n * Cancels both the CMS entry and the EventBridge schedule.\n * Used when a user manually cancels a scheduled action or when business logic\n * determines the action should no longer execute.\n */\n\nexport interface ICancelScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n schedulerService: SchedulerServiceError;\n unauthorized: NotAuthorizedError;\n}\n\ntype CancelScheduledActionError = ICancelScheduledActionErrors[keyof ICancelScheduledActionErrors];\nexport interface ICancelScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\nexport interface ICancelScheduledActionUseCase {\n execute(\n params: ICancelScheduledActionUseCaseParams\n ): Promise<Result<boolean, CancelScheduledActionError>>;\n}\n\n/** Cancel a scheduled action. */\nexport const CancelScheduledActionUseCase = createAbstraction<ICancelScheduledActionUseCase>(\n \"Scheduler/CancelScheduledActionUseCase\"\n);\n\nexport namespace CancelScheduledActionUseCase {\n export type Interface = ICancelScheduledActionUseCase;\n export type Error = CancelScheduledActionError;\n export type Params = ICancelScheduledActionUseCaseParams;\n}\n"],"names":["CancelScheduledActionUseCase","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledAction/abstractions.js","sources":["../../../src/features/CancelScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError,\n SchedulerServiceError\n} from \"~/domain/errors.js\";\n\n/**\n * CancelScheduledActionUseCase - Cancel a scheduled action\n *\n * Cancels both the CMS entry and the EventBridge schedule.\n * Used when a user manually cancels a scheduled action or when business logic\n * determines the action should no longer execute.\n */\n\nexport interface ICancelScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n schedulerService: SchedulerServiceError;\n unauthorized: NotAuthorizedError;\n}\n\ntype CancelScheduledActionError = ICancelScheduledActionErrors[keyof ICancelScheduledActionErrors];\nexport interface ICancelScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n tenant: string;\n}\nexport interface ICancelScheduledActionUseCase {\n execute(\n params: ICancelScheduledActionUseCaseParams\n ): Promise<Result<boolean, CancelScheduledActionError>>;\n}\n\n/** Cancel a scheduled action. */\nexport const CancelScheduledActionUseCase = createAbstraction<ICancelScheduledActionUseCase>(\n \"Scheduler/CancelScheduledActionUseCase\"\n);\n\nexport namespace CancelScheduledActionUseCase {\n export type Interface = ICancelScheduledActionUseCase;\n export type Error = CancelScheduledActionError;\n export type Params = ICancelScheduledActionUseCaseParams;\n}\n"],"names":["CancelScheduledActionUseCase","createAbstraction"],"mappings":";AAoCO,MAAMA,+BAA+BC,kBACxC"}
|
|
@@ -23,6 +23,7 @@ export interface IExecuteScheduledActionErrors {
|
|
|
23
23
|
type ExecuteScheduledActionError = IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];
|
|
24
24
|
export interface IExecuteScheduledActionUseCaseParams {
|
|
25
25
|
namespace: string;
|
|
26
|
+
tenant: string;
|
|
26
27
|
id: string;
|
|
27
28
|
}
|
|
28
29
|
export interface IExecuteScheduledActionUseCase {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ExecuteScheduledAction/abstractions.js","sources":["../../../src/features/ExecuteScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by EventBridge when a schedule fires.\n * Finds the appropriate handler based on namespace + actionType and executes it.\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure\n */\n\nexport interface IExecuteScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n handlerNotFound: HandlerNotFoundError;\n executionFailed: ExecutionFailedError;\n unauthorized: NotAuthorizedError;\n}\n\ntype ExecuteScheduledActionError =\n IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];\n\nexport interface IExecuteScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\n\nexport interface IExecuteScheduledActionUseCase {\n execute(\n params: IExecuteScheduledActionUseCaseParams\n ): Promise<Result<void, ExecuteScheduledActionError>>;\n}\n\n/** Execute a scheduled action immediately. */\nexport const ExecuteScheduledActionUseCase = createAbstraction<IExecuteScheduledActionUseCase>(\n \"Scheduler/ExecuteScheduledActionUseCase\"\n);\n\nexport namespace ExecuteScheduledActionUseCase {\n export type Interface = IExecuteScheduledActionUseCase;\n export type Error = ExecuteScheduledActionError;\n export type Params = IExecuteScheduledActionUseCaseParams;\n}\n\n/**\n * Handler not found error\n */\nexport class HandlerNotFoundError extends Error {\n readonly code = \"Scheduler/Handler/NotFound\" as const;\n\n constructor(namespace: string, actionType: string) {\n super(`No handler registered for namespace \"${namespace}\" and actionType \"${actionType}\"`);\n this.name = \"HandlerNotFoundError\";\n }\n}\n\n/**\n * Execution failed error\n */\nexport class ExecutionFailedError extends Error {\n readonly code = \"Scheduler/Execution/Failed\" as const;\n\n constructor(\n message: string,\n public readonly originalError?: Error\n ) {\n super(message);\n this.name = \"ExecutionFailedError\";\n }\n}\n"],"names":["ExecuteScheduledActionUseCase","createAbstraction","HandlerNotFoundError","Error","namespace","actionType","ExecutionFailedError","message","originalError"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/abstractions.js","sources":["../../../src/features/ExecuteScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by EventBridge when a schedule fires.\n * Finds the appropriate handler based on namespace + actionType and executes it.\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure\n */\n\nexport interface IExecuteScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n handlerNotFound: HandlerNotFoundError;\n executionFailed: ExecutionFailedError;\n unauthorized: NotAuthorizedError;\n}\n\ntype ExecuteScheduledActionError =\n IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];\n\nexport interface IExecuteScheduledActionUseCaseParams {\n namespace: string;\n tenant: string;\n id: string;\n}\n\nexport interface IExecuteScheduledActionUseCase {\n execute(\n params: IExecuteScheduledActionUseCaseParams\n ): Promise<Result<void, ExecuteScheduledActionError>>;\n}\n\n/** Execute a scheduled action immediately. */\nexport const ExecuteScheduledActionUseCase = createAbstraction<IExecuteScheduledActionUseCase>(\n \"Scheduler/ExecuteScheduledActionUseCase\"\n);\n\nexport namespace ExecuteScheduledActionUseCase {\n export type Interface = IExecuteScheduledActionUseCase;\n export type Error = ExecuteScheduledActionError;\n export type Params = IExecuteScheduledActionUseCaseParams;\n}\n\n/**\n * Handler not found error\n */\nexport class HandlerNotFoundError extends Error {\n readonly code = \"Scheduler/Handler/NotFound\" as const;\n\n constructor(namespace: string, actionType: string) {\n super(`No handler registered for namespace \"${namespace}\" and actionType \"${actionType}\"`);\n this.name = \"HandlerNotFoundError\";\n }\n}\n\n/**\n * Execution failed error\n */\nexport class ExecutionFailedError extends Error {\n readonly code = \"Scheduler/Execution/Failed\" as const;\n\n constructor(\n message: string,\n public readonly originalError?: Error\n ) {\n super(message);\n this.name = \"ExecutionFailedError\";\n }\n}\n"],"names":["ExecuteScheduledActionUseCase","createAbstraction","HandlerNotFoundError","Error","namespace","actionType","ExecutionFailedError","message","originalError"],"mappings":";AA8CO,MAAMA,gCAAgCC,kBACzC;AAYG,MAAMC,6BAA6BC;IAGtC,YAAYC,SAAiB,EAAEC,UAAkB,CAAE;QAC/C,KAAK,CAAC,CAAC,qCAAqC,EAAED,UAAU,kBAAkB,EAAEC,WAAW,CAAC,CAAC,QAHpF,IAAI,GAAG;QAIZ,IAAI,CAAC,IAAI,GAAG;IAChB;AACJ;AAKO,MAAMC,6BAA6BH;IAGtC,YACII,OAAe,EACCC,aAAqB,CACvC;QACE,KAAK,CAACD,UAAAA,IAAAA,CAFUC,aAAa,GAAbA,eAAAA,IAAAA,CAJX,IAAI,GAAG;QAOZ,IAAI,CAAC,IAAI,GAAG;IAChB;AACJ"}
|
|
@@ -68,26 +68,16 @@ class ScheduleActionUseCaseImpl {
|
|
|
68
68
|
async createSchedule(params) {
|
|
69
69
|
const { scheduleId: initialId, identity, payload, scheduleFor, actionType, targetId, title, namespace } = params;
|
|
70
70
|
const { id: scheduleId } = parseIdentifier(initialId);
|
|
71
|
-
const
|
|
72
|
-
id:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
actionType,
|
|
76
|
-
targetId,
|
|
77
|
-
scheduledBy: {
|
|
78
|
-
id: identity.id,
|
|
79
|
-
type: identity.type,
|
|
80
|
-
displayName: identity.displayName
|
|
81
|
-
},
|
|
82
|
-
scheduledFor: scheduleFor,
|
|
83
|
-
payload,
|
|
84
|
-
error: void 0
|
|
71
|
+
const scheduledBy = {
|
|
72
|
+
id: identity.id,
|
|
73
|
+
type: identity.type,
|
|
74
|
+
displayName: identity.displayName
|
|
85
75
|
};
|
|
86
76
|
const createResult = await this.createEntryUseCase.execute(this.model, {
|
|
87
77
|
id: scheduleId,
|
|
88
78
|
values: {
|
|
89
79
|
scheduledFor: scheduleFor.toISOString(),
|
|
90
|
-
scheduledBy
|
|
80
|
+
scheduledBy,
|
|
91
81
|
namespace,
|
|
92
82
|
title,
|
|
93
83
|
actionType,
|
|
@@ -97,9 +87,22 @@ class ScheduleActionUseCaseImpl {
|
|
|
97
87
|
}
|
|
98
88
|
});
|
|
99
89
|
if (createResult.isFail()) return Result.fail(new ScheduledActionPersistenceError(new Error(createResult.error.message)));
|
|
90
|
+
const scheduledAction = {
|
|
91
|
+
id: scheduleId,
|
|
92
|
+
tenant: createResult.value.tenant,
|
|
93
|
+
title,
|
|
94
|
+
namespace,
|
|
95
|
+
actionType,
|
|
96
|
+
targetId,
|
|
97
|
+
scheduledBy,
|
|
98
|
+
scheduledFor: scheduleFor,
|
|
99
|
+
payload,
|
|
100
|
+
error: void 0
|
|
101
|
+
};
|
|
100
102
|
try {
|
|
101
103
|
await this.schedulerService.create({
|
|
102
104
|
id: scheduleId,
|
|
105
|
+
tenant: createResult.value.tenant,
|
|
103
106
|
namespace,
|
|
104
107
|
scheduleFor: new Date(scheduleFor)
|
|
105
108
|
});
|
|
@@ -131,6 +134,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
131
134
|
try {
|
|
132
135
|
await this.schedulerService.update({
|
|
133
136
|
id: existing.id,
|
|
137
|
+
tenant: existing.tenant,
|
|
134
138
|
namespace: existing.namespace,
|
|
135
139
|
scheduleFor: new Date(scheduleFor)
|
|
136
140
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ScheduleAction/ScheduleActionUseCase.js","sources":["../../../src/features/ScheduleAction/ScheduleActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { ScheduleActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport type {\n Identity,\n IScheduledAction,\n IScheduledActionEntryValues,\n ScheduledActionType\n} from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport {\n InvalidScheduleDateError,\n ScheduledActionPersistenceError,\n SchedulerServiceError\n} from \"~/domain/errors.js\";\nimport { ScheduledActionId } from \"~/domain/ScheduledActionId.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { isValidDate } from \"~/domain/isValidDate.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { NamespaceHandlerExecutioner } from \"~/features/NamespaceHandler/abstractions.js\";\n\ninterface ICreateScheduleParams<T extends GenericRecord> {\n scheduleId: string;\n title: string;\n namespace: string;\n actionType: ScheduledActionType;\n targetId: string;\n scheduleFor: Date;\n identity: Identity;\n payload: T;\n}\n/**\n * Schedules an action for future execution\n *\n * Flow:\n * 1. Generate unique schedule ID from namespace+actionType+targetId\n * 2. Check if schedule already exists (for rescheduling logic)\n * 3. If exists: UPDATE schedule entry + EventBridge schedule\n * 4. If new: CREATE schedule entry + EventBridge schedule\n * 5. Rollback schedule entry if EventBridge fails\n */\nclass ScheduleActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private model: ScheduledActionModel.Interface,\n private schedulerService: SchedulerService.Interface,\n private getScheduledAction: GetScheduledActionUseCase.Interface,\n private createEntryUseCase: CreateEntryUseCase.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private namespaceHandlerExecutioner: NamespaceHandlerExecutioner.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const identity = this.identityContext.getIdentity();\n\n let scheduleFor = params.scheduleFor;\n /**\n * Immediately - publish in past\n */\n if (!params.immediately && !isValidDate(scheduleFor)) {\n return Result.fail(new InvalidScheduleDateError(scheduleFor));\n } else if (params.immediately) {\n // If the action should be executed immediately, we set the scheduleFor to the current date.\n // Calculate the soonest possible execution time.\n // Add at least 90 seconds of buffer to ensure EventBridge can process the schedule.\n scheduleFor = new Date(Date.now() + 90000);\n }\n\n // Generate unique schedule ID\n const actionId = ScheduledActionId.from({\n namespace: params.namespace,\n targetId: params.targetId,\n actionType: params.actionType\n });\n const scheduleId = ScheduledActionIdWithVersion.from(actionId);\n\n const existingResult = await this.getScheduledAction.execute({\n namespace: params.namespace,\n id: scheduleId\n });\n\n const namespaceHandlerResult = await this.namespaceHandlerExecutioner.execute<T>({\n scheduleId: actionId,\n immediately: params.immediately,\n scheduleFor,\n targetId: params.targetId,\n actionType: params.actionType,\n namespace: params.namespace\n });\n\n if (namespaceHandlerResult.isFail()) {\n return Result.fail(namespaceHandlerResult.error);\n }\n const payload = namespaceHandlerResult.value;\n\n if (existingResult.isFail()) {\n const error = existingResult.error;\n\n // NotFound means the action was not yet scheduled\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return this.createSchedule<T>({\n scheduleId,\n title: payload.title,\n namespace: params.namespace,\n actionType: params.actionType,\n targetId: params.targetId,\n scheduleFor,\n identity,\n payload\n });\n }\n\n if (error.code === \"Scheduler/ScheduledAction/PersistenceError\") {\n return Result.fail(error);\n }\n }\n\n // Reschedule existing action\n const scheduledAction = existingResult.value;\n\n return this.reschedule<T>(scheduledAction, params.scheduleFor, identity, payload);\n }\n\n /**\n * Creates a new schedule\n */\n private async createSchedule<T extends GenericRecord>(\n params: ICreateScheduleParams<T>\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const {\n scheduleId: initialId,\n identity,\n payload,\n scheduleFor,\n actionType,\n targetId,\n title,\n namespace\n } = params;\n const { id: scheduleId } = parseIdentifier(initialId);\n\n const scheduledAction: IScheduledAction<T> = {\n id: scheduleId,\n title,\n namespace,\n actionType,\n targetId,\n scheduledBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n scheduledFor: scheduleFor,\n payload,\n error: undefined\n };\n\n // Create CMS entry\n const createResult = await this.createEntryUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n {\n id: scheduleId,\n values: {\n scheduledFor: scheduleFor.toISOString(),\n scheduledBy: scheduledAction.scheduledBy,\n namespace,\n title,\n actionType,\n targetId,\n payload,\n error: undefined\n }\n }\n );\n\n if (createResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(createResult.error.message))\n );\n }\n\n // Create EventBridge schedule\n try {\n await this.schedulerService.create({\n id: scheduleId,\n namespace,\n scheduleFor: new Date(scheduleFor)\n });\n } catch (error) {\n // Rollback - delete CMS entry if EventBridge fails\n console.error(`Failed to create EventBridge schedule: ${scheduleId}. Rolling back...`);\n\n await this.deleteEntryUseCase.execute(this.model, scheduleId, {\n force: true,\n permanently: true\n });\n\n return Result.fail(new SchedulerServiceError(error as Error));\n }\n\n return Result.ok(scheduledAction);\n }\n\n /**\n * Updates an existing schedule (reschedule)\n */\n private async reschedule<T extends GenericRecord>(\n existing: IScheduledAction<T>,\n scheduleFor: Date,\n identity: Identity,\n payload?: T\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n // Make sure we don't unset the existing payload.\n if (!payload) {\n payload = existing.payload as T;\n }\n\n // Update CMS entry\n const existingEntryId = ScheduledActionIdWithVersion.from(existing.id);\n const updateResult = await this.updateEntryUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n existingEntryId,\n {\n values: {\n scheduledBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n scheduledFor: scheduleFor.toISOString(),\n payload\n }\n }\n );\n\n if (updateResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(updateResult.error.message))\n );\n }\n\n // Update EventBridge schedule\n try {\n await this.schedulerService.update({\n id: existing.id,\n namespace: existing.namespace,\n scheduleFor: new Date(scheduleFor)\n });\n } catch (error) {\n return Result.fail(new SchedulerServiceError(error as Error));\n }\n\n return Result.ok({\n ...existing,\n scheduledBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n scheduledFor: scheduleFor,\n payload\n });\n }\n}\n\nexport const ScheduleActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: ScheduleActionUseCaseImpl,\n dependencies: [\n IdentityContext,\n ScheduledActionModel,\n SchedulerService,\n GetScheduledActionUseCase,\n CreateEntryUseCase,\n UpdateEntryUseCase,\n DeleteEntryUseCase,\n NamespaceHandlerExecutioner\n ]\n});\n"],"names":["ScheduleActionUseCaseImpl","identityContext","model","schedulerService","getScheduledAction","createEntryUseCase","updateEntryUseCase","deleteEntryUseCase","namespaceHandlerExecutioner","params","identity","scheduleFor","isValidDate","Result","InvalidScheduleDateError","Date","actionId","ScheduledActionId","scheduleId","ScheduledActionIdWithVersion","existingResult","namespaceHandlerResult","payload","error","scheduledAction","initialId","actionType","targetId","title","namespace","parseIdentifier","undefined","createResult","ScheduledActionPersistenceError","Error","console","SchedulerServiceError","existing","existingEntryId","updateResult","ScheduleActionUseCase","UseCaseAbstraction","IdentityContext","ScheduledActionModel","Scheduler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AAO,IAAI,CAAC,IAAIuB,sBAAsBb;QACjD;QAEA,OAAOV,OAAO,EAAE,CAAC;YACb,GAAGwB,QAAQ;YACX,aAAa;gBACT,IAAI3B,SAAS,EAAE;gBACf,MAAMA,SAAS,IAAI;gBACnB,aAAaA,SAAS,WAAW;YACrC;YACA,cAAcC;YACdW;QACJ;IACJ;AACJ;AAEO,MAAMkB,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"features/ScheduleAction/ScheduleActionUseCase.js","sources":["../../../src/features/ScheduleAction/ScheduleActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { ScheduleActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport type {\n Identity,\n IScheduledAction,\n IScheduledActionEntryValues,\n ScheduledActionType\n} from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel, SchedulerService } from \"~/shared/abstractions.js\";\nimport {\n InvalidScheduleDateError,\n ScheduledActionPersistenceError,\n SchedulerServiceError\n} from \"~/domain/errors.js\";\nimport { ScheduledActionId } from \"~/domain/ScheduledActionId.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { isValidDate } from \"~/domain/isValidDate.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { NamespaceHandlerExecutioner } from \"~/features/NamespaceHandler/abstractions.js\";\n\ninterface ICreateScheduleParams<T extends GenericRecord> {\n scheduleId: string;\n title: string;\n namespace: string;\n actionType: ScheduledActionType;\n targetId: string;\n scheduleFor: Date;\n identity: Identity;\n payload: T;\n}\n/**\n * Schedules an action for future execution\n *\n * Flow:\n * 1. Generate unique schedule ID from namespace+actionType+targetId\n * 2. Check if schedule already exists (for rescheduling logic)\n * 3. If exists: UPDATE schedule entry + EventBridge schedule\n * 4. If new: CREATE schedule entry + EventBridge schedule\n * 5. Rollback schedule entry if EventBridge fails\n */\nclass ScheduleActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private model: ScheduledActionModel.Interface,\n private schedulerService: SchedulerService.Interface,\n private getScheduledAction: GetScheduledActionUseCase.Interface,\n private createEntryUseCase: CreateEntryUseCase.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private namespaceHandlerExecutioner: NamespaceHandlerExecutioner.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const identity = this.identityContext.getIdentity();\n\n let scheduleFor = params.scheduleFor;\n /**\n * Immediately - publish in past\n */\n if (!params.immediately && !isValidDate(scheduleFor)) {\n return Result.fail(new InvalidScheduleDateError(scheduleFor));\n } else if (params.immediately) {\n // If the action should be executed immediately, we set the scheduleFor to the current date.\n // Calculate the soonest possible execution time.\n // Add at least 90 seconds of buffer to ensure EventBridge can process the schedule.\n scheduleFor = new Date(Date.now() + 90000);\n }\n\n // Generate unique schedule ID\n const actionId = ScheduledActionId.from({\n namespace: params.namespace,\n targetId: params.targetId,\n actionType: params.actionType\n });\n const scheduleId = ScheduledActionIdWithVersion.from(actionId);\n\n const existingResult = await this.getScheduledAction.execute({\n namespace: params.namespace,\n id: scheduleId\n });\n\n const namespaceHandlerResult = await this.namespaceHandlerExecutioner.execute<T>({\n scheduleId: actionId,\n immediately: params.immediately,\n scheduleFor,\n targetId: params.targetId,\n actionType: params.actionType,\n namespace: params.namespace\n });\n\n if (namespaceHandlerResult.isFail()) {\n return Result.fail(namespaceHandlerResult.error);\n }\n const payload = namespaceHandlerResult.value;\n\n if (existingResult.isFail()) {\n const error = existingResult.error;\n\n // NotFound means the action was not yet scheduled\n if (error.code === \"Scheduler/ScheduledAction/NotFound\") {\n return this.createSchedule<T>({\n scheduleId,\n title: payload.title,\n namespace: params.namespace,\n actionType: params.actionType,\n targetId: params.targetId,\n scheduleFor,\n identity,\n payload\n });\n }\n\n if (error.code === \"Scheduler/ScheduledAction/PersistenceError\") {\n return Result.fail(error);\n }\n }\n\n // Reschedule existing action\n const scheduledAction = existingResult.value;\n\n return this.reschedule<T>(scheduledAction, params.scheduleFor, identity, payload);\n }\n\n /**\n * Creates a new schedule\n */\n private async createSchedule<T extends GenericRecord>(\n params: ICreateScheduleParams<T>\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const {\n scheduleId: initialId,\n identity,\n payload,\n scheduleFor,\n actionType,\n targetId,\n title,\n namespace\n } = params;\n const { id: scheduleId } = parseIdentifier(initialId);\n\n const scheduledBy: Identity = {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n };\n\n // Create CMS entry\n const createResult = await this.createEntryUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n {\n id: scheduleId,\n values: {\n scheduledFor: scheduleFor.toISOString(),\n scheduledBy,\n namespace,\n title,\n actionType,\n targetId,\n payload,\n error: undefined\n }\n }\n );\n\n if (createResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(createResult.error.message))\n );\n }\n\n const scheduledAction: IScheduledAction<T> = {\n id: scheduleId,\n tenant: createResult.value.tenant,\n title,\n namespace,\n actionType,\n targetId,\n scheduledBy,\n scheduledFor: scheduleFor,\n payload,\n error: undefined\n };\n\n // Create EventBridge schedule\n try {\n await this.schedulerService.create({\n id: scheduleId,\n tenant: createResult.value.tenant,\n namespace,\n scheduleFor: new Date(scheduleFor)\n });\n } catch (error) {\n // Rollback - delete CMS entry if EventBridge fails\n console.error(`Failed to create EventBridge schedule: ${scheduleId}. Rolling back...`);\n\n await this.deleteEntryUseCase.execute(this.model, scheduleId, {\n force: true,\n permanently: true\n });\n\n return Result.fail(new SchedulerServiceError(error as Error));\n }\n\n return Result.ok(scheduledAction);\n }\n\n /**\n * Updates an existing schedule (reschedule)\n */\n private async reschedule<T extends GenericRecord>(\n existing: IScheduledAction<T>,\n scheduleFor: Date,\n identity: Identity,\n payload?: T\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n // Make sure we don't unset the existing payload.\n if (!payload) {\n payload = existing.payload as T;\n }\n\n // Update CMS entry\n const existingEntryId = ScheduledActionIdWithVersion.from(existing.id);\n const updateResult = await this.updateEntryUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n existingEntryId,\n {\n values: {\n scheduledBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n scheduledFor: scheduleFor.toISOString(),\n payload\n }\n }\n );\n\n if (updateResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(updateResult.error.message))\n );\n }\n\n // Update EventBridge schedule\n try {\n await this.schedulerService.update({\n id: existing.id,\n tenant: existing.tenant,\n namespace: existing.namespace,\n scheduleFor: new Date(scheduleFor)\n });\n } catch (error) {\n return Result.fail(new SchedulerServiceError(error as Error));\n }\n\n return Result.ok({\n ...existing,\n scheduledBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n },\n scheduledFor: scheduleFor,\n payload\n });\n }\n}\n\nexport const ScheduleActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: ScheduleActionUseCaseImpl,\n dependencies: [\n IdentityContext,\n ScheduledActionModel,\n SchedulerService,\n GetScheduledActionUseCase,\n CreateEntryUseCase,\n UpdateEntryUseCase,\n DeleteEntryUseCase,\n NamespaceHandlerExecutioner\n ]\n});\n"],"names":["ScheduleActionUseCaseImpl","identityContext","model","schedulerService","getScheduledAction","createEntryUseCase","updateEntryUseCase","deleteEntryUseCase","namespaceHandlerExecutioner","params","identity","scheduleFor","isValidDate","Result","InvalidScheduleDateError","Date","actionId","ScheduledActionId","scheduleId","ScheduledActionIdWithVersion","existingResult","namespaceHandlerResult","payload","error","scheduledAction","initialId","actionType","targetId","title","namespace","parseIdentifier","scheduledBy","createResult","undefined","ScheduledActionPersistenceError","Error","console","SchedulerServiceError","existing","existingEntryId","updateResult","ScheduleActionUseCase","UseCaseAbstraction","IdentityContext","ScheduledActionModel","SchedulerService","GetScheduledActionUseCase","CreateEntryUseCase","UpdateEntryUseCase","DeleteEntryUseCase","NamespaceHandlerExecutioner"],"mappings":";;;;;;;;;;;;;;AA8CA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,KAAqC,EACrCC,gBAA4C,EAC5CC,kBAAuD,EACvDC,kBAAgD,EAChDC,kBAAgD,EAChDC,kBAAgD,EAChDC,2BAAkE,CAC5E;aARUP,eAAe,GAAfA;aACAC,KAAK,GAALA;aACAC,gBAAgB,GAAhBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,2BAA2B,GAA3BA;IACT;IAEH,MAAM,QACFC,MAAiC,EAC6B;QAC9D,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAEjD,IAAIC,cAAcF,OAAO,WAAW;QAIpC,IAAI,CAACA,OAAO,WAAW,IAAI,CAACG,YAAYD,cACpC,OAAOE,OAAO,IAAI,CAAC,IAAIC,yBAAyBH;QAC7C,IAAIF,OAAO,WAAW,EAIzBE,cAAc,IAAII,KAAKA,KAAK,GAAG,KAAK;QAIxC,MAAMC,WAAWC,kBAAkB,IAAI,CAAC;YACpC,WAAWR,OAAO,SAAS;YAC3B,UAAUA,OAAO,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,CACtD,IAAI,CAAC,KAAK,EACVD,iBACA;YACI,QAAQ;gBACJ,aAAa;oBACT,IAAI7B,SAAS,EAAE;oBACf,MAAMA,SAAS,IAAI;oBACnB,aAAaA,SAAS,WAAW;gBACrC;gBACA,cAAcC,YAAY,WAAW;gBACrCW;YACJ;QACJ;QAGJ,IAAIkB,aAAa,MAAM,IACnB,OAAO3B,OAAO,IAAI,CACd,IAAIqB,gCAAgC,IAAIC,MAAMK,aAAa,KAAK,CAAC,OAAO;QAKhF,IAAI;YACA,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;gBAC/B,IAAIF,SAAS,EAAE;gBACf,QAAQA,SAAS,MAAM;gBACvB,WAAWA,SAAS,SAAS;gBAC7B,aAAa,IAAIvB,KAAKJ;YAC1B;QACJ,EAAE,OAAOY,OAAO;YACZ,OAAOV,OAAO,IAAI,CAAC,IAAIwB,sBAAsBd;QACjD;QAEA,OAAOV,OAAO,EAAE,CAAC;YACb,GAAGyB,QAAQ;YACX,aAAa;gBACT,IAAI5B,SAAS,EAAE;gBACf,MAAMA,SAAS,IAAI;gBACnB,aAAaA,SAAS,WAAW;YACrC;YACA,cAAcC;YACdW;QACJ;IACJ;AACJ;AAEO,MAAMmB,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgB1C;IAChB,cAAc;QACV2C;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -17,6 +17,7 @@ export interface IScheduleActionErrors {
|
|
|
17
17
|
}
|
|
18
18
|
export type ScheduleActionError = IScheduleActionErrors[keyof IScheduleActionErrors];
|
|
19
19
|
export interface IScheduleActionParams {
|
|
20
|
+
tenant: string;
|
|
20
21
|
namespace: string;
|
|
21
22
|
targetId: string;
|
|
22
23
|
actionType: ScheduledActionType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ScheduleAction/abstractions.js","sources":["../../../src/features/ScheduleAction/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction, ScheduledActionType } from \"~/shared/abstractions.js\";\nimport {\n InvalidScheduleDateError,\n ScheduledActionPersistenceError,\n SchedulerServiceError,\n NamespaceHandlerNotFoundError\n} from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * ScheduleActionUseCase - Schedule an action for future execution\n *\n * Handles both new schedules and rescheduling (update) automatically:\n * - If no schedule exists for the namespace+actionType+targetId combination: creates new schedule\n * - If schedule already exists: updates the existing schedule (reschedule)\n */\n\nexport interface IScheduleActionErrors {\n namespaceHandlerNotFound: NamespaceHandlerNotFoundError;\n persistence: ScheduledActionPersistenceError;\n invalidDate: InvalidScheduleDateError;\n schedulerService: SchedulerServiceError;\n}\n\nexport type ScheduleActionError = IScheduleActionErrors[keyof IScheduleActionErrors];\n\nexport interface IScheduleActionParams {\n namespace: string;\n targetId: string;\n actionType: ScheduledActionType;\n scheduleFor: Date;\n immediately?: boolean;\n}\n\nexport interface IScheduleActionUseCase {\n execute<T extends GenericRecord>(\n params: IScheduleActionParams\n ): Promise<Result<IScheduledAction<T>, ScheduleActionError>>;\n}\n\n/** Schedule an action for future execution. */\nexport const ScheduleActionUseCase = createAbstraction<IScheduleActionUseCase>(\n \"Scheduler/ScheduleActionUseCase\"\n);\n\nexport namespace ScheduleActionUseCase {\n export type Interface = IScheduleActionUseCase;\n export type Params = IScheduleActionParams;\n export type Error = ScheduleActionError;\n}\n"],"names":["ScheduleActionUseCase","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/ScheduleAction/abstractions.js","sources":["../../../src/features/ScheduleAction/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction, ScheduledActionType } from \"~/shared/abstractions.js\";\nimport {\n InvalidScheduleDateError,\n ScheduledActionPersistenceError,\n SchedulerServiceError,\n NamespaceHandlerNotFoundError\n} from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * ScheduleActionUseCase - Schedule an action for future execution\n *\n * Handles both new schedules and rescheduling (update) automatically:\n * - If no schedule exists for the namespace+actionType+targetId combination: creates new schedule\n * - If schedule already exists: updates the existing schedule (reschedule)\n */\n\nexport interface IScheduleActionErrors {\n namespaceHandlerNotFound: NamespaceHandlerNotFoundError;\n persistence: ScheduledActionPersistenceError;\n invalidDate: InvalidScheduleDateError;\n schedulerService: SchedulerServiceError;\n}\n\nexport type ScheduleActionError = IScheduleActionErrors[keyof IScheduleActionErrors];\n\nexport interface IScheduleActionParams {\n tenant: string;\n namespace: string;\n targetId: string;\n actionType: ScheduledActionType;\n scheduleFor: Date;\n immediately?: boolean;\n}\n\nexport interface IScheduleActionUseCase {\n execute<T extends GenericRecord>(\n params: IScheduleActionParams\n ): Promise<Result<IScheduledAction<T>, ScheduleActionError>>;\n}\n\n/** Schedule an action for future execution. */\nexport const ScheduleActionUseCase = createAbstraction<IScheduleActionUseCase>(\n \"Scheduler/ScheduleActionUseCase\"\n);\n\nexport namespace ScheduleActionUseCase {\n export type Interface = IScheduleActionUseCase;\n export type Params = IScheduleActionParams;\n export type Error = ScheduleActionError;\n}\n"],"names":["ScheduleActionUseCase","createAbstraction"],"mappings":";AA2CO,MAAMA,wBAAwBC,kBACjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchedulerService } from "../../shared/abstractions.js";
|
|
2
2
|
import { type SchedulerClient } from "@webiny/aws-sdk/client-scheduler/index.js";
|
|
3
3
|
export interface ISchedulerConfig {
|
|
4
4
|
lambdaArn: string;
|
|
@@ -16,11 +16,12 @@ export declare class EventBridgeSchedulerService implements SchedulerService.Int
|
|
|
16
16
|
private getClient;
|
|
17
17
|
private config;
|
|
18
18
|
constructor(getClient: (config?: any) => Pick<SchedulerClient, "send">, config: ISchedulerConfig);
|
|
19
|
-
create(params:
|
|
20
|
-
update(params:
|
|
21
|
-
delete(
|
|
22
|
-
exists(
|
|
19
|
+
create(params: SchedulerService.CreateParams): Promise<void>;
|
|
20
|
+
update(params: SchedulerService.UpdateParams): Promise<void>;
|
|
21
|
+
delete(params: SchedulerService.DeleteParams): Promise<void>;
|
|
22
|
+
exists(params: SchedulerService.ExistsParams): Promise<boolean>;
|
|
23
23
|
private createScheduleExpression;
|
|
24
24
|
private createScheduledActionEventInput;
|
|
25
25
|
private createScheduledActionEventPayload;
|
|
26
|
+
private createScheduleName;
|
|
26
27
|
}
|
|
@@ -7,13 +7,14 @@ class EventBridgeSchedulerService {
|
|
|
7
7
|
this.config = config;
|
|
8
8
|
}
|
|
9
9
|
async create(params) {
|
|
10
|
-
const { id, scheduleFor } = params;
|
|
10
|
+
const { id, scheduleFor, tenant } = params;
|
|
11
11
|
if (scheduleFor <= new Date()) throw new WebinyError(`Cannot create a schedule for "${id}" with date in the past`, "INVALID_SCHEDULE_DATE", {
|
|
12
12
|
scheduleFor,
|
|
13
|
+
tenant,
|
|
13
14
|
id
|
|
14
15
|
});
|
|
15
16
|
const client = this.getClient();
|
|
16
|
-
const exists = await this.exists(
|
|
17
|
+
const exists = await this.exists(params);
|
|
17
18
|
if (exists) return this.update(params);
|
|
18
19
|
await client.send(new CreateScheduleCommand({
|
|
19
20
|
Name: id,
|
|
@@ -50,24 +51,26 @@ class EventBridgeSchedulerService {
|
|
|
50
51
|
ActionAfterCompletion: "DELETE"
|
|
51
52
|
}));
|
|
52
53
|
}
|
|
53
|
-
async delete(
|
|
54
|
+
async delete(params) {
|
|
54
55
|
const client = this.getClient();
|
|
55
|
-
const exists = await this.exists(
|
|
56
|
-
if (!exists) throw new WebinyError(`Cannot delete schedule "${id}" because it does not exist.`);
|
|
56
|
+
const exists = await this.exists(params);
|
|
57
|
+
if (!exists) throw new WebinyError(`Cannot delete schedule "${params.id}", tenant "${params.tenant}", because it does not exist.`);
|
|
58
|
+
const name = this.createScheduleName(params);
|
|
57
59
|
try {
|
|
58
60
|
await client.send(new DeleteScheduleCommand({
|
|
59
|
-
Name:
|
|
61
|
+
Name: name
|
|
60
62
|
}));
|
|
61
63
|
} catch (ex) {
|
|
62
64
|
if ("ResourceNotFoundException" === ex.name) return;
|
|
63
65
|
throw WebinyError.from(ex);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
async exists(
|
|
68
|
+
async exists(params) {
|
|
67
69
|
const client = this.getClient();
|
|
70
|
+
const name = this.createScheduleName(params);
|
|
68
71
|
try {
|
|
69
72
|
await client.send(new GetScheduleCommand({
|
|
70
|
-
Name:
|
|
73
|
+
Name: name
|
|
71
74
|
}));
|
|
72
75
|
return true;
|
|
73
76
|
} catch (ex) {
|
|
@@ -84,13 +87,17 @@ class EventBridgeSchedulerService {
|
|
|
84
87
|
});
|
|
85
88
|
}
|
|
86
89
|
createScheduledActionEventPayload(params) {
|
|
87
|
-
const { id, scheduleFor, namespace } = params;
|
|
90
|
+
const { id, scheduleFor, tenant, namespace } = params;
|
|
88
91
|
return {
|
|
89
92
|
id,
|
|
93
|
+
tenant,
|
|
90
94
|
namespace,
|
|
91
95
|
scheduleFor: scheduleFor.toISOString()
|
|
92
96
|
};
|
|
93
97
|
}
|
|
98
|
+
createScheduleName(params) {
|
|
99
|
+
return `schedule_${params.tenant}-${params.namespace}-${params.id}`;
|
|
100
|
+
}
|
|
94
101
|
}
|
|
95
102
|
export { EventBridgeSchedulerService };
|
|
96
103
|
|
|
@@ -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 \"~/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:
|
|
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: SchedulerService.CreateParams): Promise<void> {\n const { id, scheduleFor, tenant } = 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 tenant,\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(params);\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: SchedulerService.UpdateParams): 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(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 // 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: 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","Date","WebinyError","client","exists","CreateScheduleCommand","UpdateScheduleCommand","name","DeleteScheduleCommand","ex","GetScheduleCommand","JSON","SCHEDULED_ACTION_EVENT_IDENTIFIER","namespace"],"mappings":";;;AA6BO,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,EAAE,GAAGH;QAGpC,IAAIE,eAAe,IAAIE,QACnB,MAAM,IAAIC,YACN,CAAC,8BAA8B,EAAEJ,GAAG,uBAAuB,CAAC,EAC5D,yBACA;YACIC;YACAC;YACAF;QACJ;QAIR,MAAMK,SAAS,IAAI,CAAC,SAAS;QAG7B,MAAMC,SAAS,MAAM,IAAI,CAAC,MAAM,CAACP;QACjC,IAAIO,QACA,OAAO,IAAI,CAAC,MAA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AAK;QAC7D,EAAE,OAAOE,IAAI;YACT,IAAIA,AAAY,gCAAZA,GAAG,IAAI,EACP;YAEJ,MAAMP,YAAY,IAAI,CAACO;QAC3B;IACJ;IAEA,MAAa,OAAOZ,MAAqC,EAAoB;QACzE,MAAMM,SAAS,IAAI,CAAC,SAAS;QAE7B,MAAMI,OAAO,IAAI,CAAC,kBAAkB,CAACV;QAErC,IAAI;YACA,MAAMM,OAAO,IAAI,CAAC,IAAIO,mBAAmB;gBAAE,MAAMH;YAAK;YACtD,OAAO;QACX,EAAE,OAAOE,IAAI;YACT,IAAIA,AAAY,gCAAZA,GAAG,IAAI,EACP,OAAO;YAEX,MAAMA;QACV;IACJ;IAEQ,yBAAyBV,WAAiB,EAAU;QAExD,OAAO,CAAC,GAAG,EAAEA,YAAY,WAAW,GAAG,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;IACtE;IAEQ,gCACJF,MAAqE,EAC/D;QACN,OAAOc,KAAK,SAAS,CAAC;YAClB,CAACC,kCAAkC,EAAE,IAAI,CAAC,iCAAiC,CAACf;QAChF;IACJ;IAEQ,kCACJA,MAAqE,EACzC;QAC5B,MAAM,EAAEC,EAAE,EAAEC,WAAW,EAAEC,MAAM,EAAEa,SAAS,EAAE,GAAGhB;QAE/C,OAAO;YACHC;YACAE;YACAa;YACA,aAAad,YAAY,WAAW;QACxC;IACJ;IAEQ,mBAAmBF,MAAqC,EAAU;QACtE,OAAO,CAAC,SAAS,EAAEA,OAAO,MAAM,CAAC,CAAC,EAAEA,OAAO,SAAS,CAAC,CAAC,EAAEA,OAAO,EAAE,EAAE;IACvE;AACJ"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { SchedulerService } from "../../shared/abstractions.js";
|
|
2
2
|
export interface IVoidSchedulerServiceParams {
|
|
3
|
-
create?: (params:
|
|
4
|
-
update?: (params:
|
|
5
|
-
delete?: (
|
|
6
|
-
exists?: (
|
|
3
|
+
create?: (params: SchedulerService.CreateParams) => Promise<void>;
|
|
4
|
+
update?: (params: SchedulerService.UpdateParams) => Promise<void>;
|
|
5
|
+
delete?: (params: SchedulerService.DeleteParams) => Promise<void>;
|
|
6
|
+
exists?: (params: SchedulerService.ExistsParams) => Promise<boolean>;
|
|
7
7
|
}
|
|
8
8
|
export declare class VoidSchedulerService implements SchedulerService.Interface {
|
|
9
9
|
private readonly callbacks;
|
|
10
10
|
constructor(callbacks?: IVoidSchedulerServiceParams);
|
|
11
|
-
create(params:
|
|
12
|
-
update(params:
|
|
13
|
-
delete(
|
|
14
|
-
exists(
|
|
11
|
+
create(params: SchedulerService.CreateParams): Promise<void>;
|
|
12
|
+
update(params: SchedulerService.UpdateParams): Promise<void>;
|
|
13
|
+
delete(params: SchedulerService.DeleteParams): Promise<void>;
|
|
14
|
+
exists(params: SchedulerService.ExistsParams): Promise<boolean>;
|
|
15
15
|
}
|
|
@@ -10,13 +10,13 @@ class VoidSchedulerService {
|
|
|
10
10
|
if (!this.callbacks?.update) return;
|
|
11
11
|
return this.callbacks?.update(params);
|
|
12
12
|
}
|
|
13
|
-
async delete(
|
|
13
|
+
async delete(params) {
|
|
14
14
|
if (!this.callbacks?.delete) return;
|
|
15
|
-
return this.callbacks
|
|
15
|
+
return this.callbacks.delete(params);
|
|
16
16
|
}
|
|
17
|
-
async exists(
|
|
17
|
+
async exists(params) {
|
|
18
18
|
if (!this.callbacks?.exists) return false;
|
|
19
|
-
return this.callbacks
|
|
19
|
+
return this.callbacks.exists(params);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export { VoidSchedulerService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/SchedulerService/VoidSchedulerService.js","sources":["../../../src/features/SchedulerService/VoidSchedulerService.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"features/SchedulerService/VoidSchedulerService.js","sources":["../../../src/features/SchedulerService/VoidSchedulerService.ts"],"sourcesContent":["import type { SchedulerService } from \"~/shared/abstractions.js\";\n\nexport interface IVoidSchedulerServiceParams {\n create?: (params: SchedulerService.CreateParams) => Promise<void>;\n update?: (params: SchedulerService.UpdateParams) => Promise<void>;\n delete?: (params: SchedulerService.DeleteParams) => Promise<void>;\n exists?: (params: SchedulerService.ExistsParams) => Promise<boolean>;\n}\n\nexport class VoidSchedulerService implements SchedulerService.Interface {\n private readonly callbacks: IVoidSchedulerServiceParams | undefined;\n\n public constructor(callbacks?: IVoidSchedulerServiceParams) {\n this.callbacks = callbacks;\n }\n\n public async create(params: SchedulerService.CreateParams): Promise<void> {\n if (!this.callbacks?.create) {\n return;\n }\n return this.callbacks?.create(params);\n }\n\n public async update(params: SchedulerService.UpdateParams): Promise<void> {\n if (!this.callbacks?.update) {\n return;\n }\n return this.callbacks?.update(params);\n }\n\n public async delete(params: SchedulerService.DeleteParams): Promise<void> {\n if (!this.callbacks?.delete) {\n return;\n }\n return this.callbacks.delete(params);\n }\n\n public async exists(params: SchedulerService.ExistsParams): Promise<boolean> {\n if (!this.callbacks?.exists) {\n return false;\n }\n return this.callbacks.exists(params);\n }\n}\n"],"names":["VoidSchedulerService","callbacks","params"],"mappings":"AASO,MAAMA;IAGT,YAAmBC,SAAuC,CAAE;QACxD,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,MAAa,OAAOC,MAAqC,EAAiB;QACtE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QACjB;QAEJ,OAAO,IAAI,CAAC,SAAS,EAAE,OAAOA;IAClC;IAEA,MAAa,OAAOA,MAAqC,EAAiB;QACtE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QACjB;QAEJ,OAAO,IAAI,CAAC,SAAS,EAAE,OAAOA;IAClC;IAEA,MAAa,OAAOA,MAAqC,EAAiB;QACtE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QACjB;QAEJ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;IACjC;IAEA,MAAa,OAAOA,MAAqC,EAAoB;QACzE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QACjB,OAAO;QAEX,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;IACjC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-scheduler",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.3-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,30 +18,30 @@
|
|
|
18
18
|
"description": "A generic action scheduler.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@webiny/api": "6.4.
|
|
22
|
-
"@webiny/api-core": "6.4.
|
|
23
|
-
"@webiny/api-headless-cms": "6.4.
|
|
24
|
-
"@webiny/aws-sdk": "6.4.
|
|
25
|
-
"@webiny/error": "6.4.
|
|
26
|
-
"@webiny/feature": "6.4.
|
|
27
|
-
"@webiny/handler-graphql": "6.4.
|
|
28
|
-
"@webiny/plugins": "6.4.
|
|
29
|
-
"@webiny/utils": "6.4.
|
|
21
|
+
"@webiny/api": "6.4.3-beta.0",
|
|
22
|
+
"@webiny/api-core": "6.4.3-beta.0",
|
|
23
|
+
"@webiny/api-headless-cms": "6.4.3-beta.0",
|
|
24
|
+
"@webiny/aws-sdk": "6.4.3-beta.0",
|
|
25
|
+
"@webiny/error": "6.4.3-beta.0",
|
|
26
|
+
"@webiny/feature": "6.4.3-beta.0",
|
|
27
|
+
"@webiny/handler-graphql": "6.4.3-beta.0",
|
|
28
|
+
"@webiny/plugins": "6.4.3-beta.0",
|
|
29
|
+
"@webiny/utils": "6.4.3-beta.0",
|
|
30
30
|
"zod": "4.4.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@webiny/build-tools": "6.4.
|
|
34
|
-
"@webiny/db-dynamodb": "6.4.
|
|
35
|
-
"@webiny/handler": "6.4.
|
|
36
|
-
"@webiny/handler-aws": "6.4.
|
|
37
|
-
"@webiny/project-utils": "6.4.
|
|
38
|
-
"@webiny/testing": "6.4.
|
|
39
|
-
"@webiny/wcp": "6.4.
|
|
33
|
+
"@webiny/build-tools": "6.4.3-beta.0",
|
|
34
|
+
"@webiny/db-dynamodb": "6.4.3-beta.0",
|
|
35
|
+
"@webiny/handler": "6.4.3-beta.0",
|
|
36
|
+
"@webiny/handler-aws": "6.4.3-beta.0",
|
|
37
|
+
"@webiny/project-utils": "6.4.3-beta.0",
|
|
38
|
+
"@webiny/testing": "6.4.3-beta.0",
|
|
39
|
+
"@webiny/wcp": "6.4.3-beta.0",
|
|
40
40
|
"aws-sdk-client-mock": "4.1.0",
|
|
41
41
|
"jest-dynalite": "3.6.1",
|
|
42
42
|
"rimraf": "6.1.3",
|
|
43
43
|
"typescript": "6.0.3",
|
|
44
|
-
"vitest": "4.1.
|
|
44
|
+
"vitest": "4.1.8"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
package/shared/abstractions.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface IScheduledActionEntry<T extends GenericRecord = GenericRecord>
|
|
|
28
28
|
}
|
|
29
29
|
export interface IScheduledAction<T extends GenericRecord = GenericRecord> extends Omit<IScheduledActionEntryValues<T>, "scheduledFor"> {
|
|
30
30
|
id: string;
|
|
31
|
+
tenant: string;
|
|
31
32
|
scheduledFor: Date;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
@@ -61,24 +62,40 @@ export declare namespace ScheduledActionHandler {
|
|
|
61
62
|
*/
|
|
62
63
|
export interface ISchedulerServiceCreateParams {
|
|
63
64
|
id: string;
|
|
65
|
+
tenant: string;
|
|
64
66
|
namespace: string;
|
|
65
67
|
scheduleFor: Date;
|
|
66
68
|
}
|
|
67
69
|
export interface ISchedulerServiceUpdateParams {
|
|
68
70
|
id: string;
|
|
71
|
+
tenant: string;
|
|
69
72
|
namespace: string;
|
|
70
73
|
scheduleFor: Date;
|
|
71
74
|
}
|
|
75
|
+
export interface ISchedulerServiceDeleteParams {
|
|
76
|
+
id: string;
|
|
77
|
+
namespace: string;
|
|
78
|
+
tenant: string;
|
|
79
|
+
}
|
|
80
|
+
export interface ISchedulerServiceExistsParams {
|
|
81
|
+
id: string;
|
|
82
|
+
namespace: string;
|
|
83
|
+
tenant: string;
|
|
84
|
+
}
|
|
72
85
|
export interface ISchedulerService {
|
|
73
86
|
create(params: ISchedulerServiceCreateParams): Promise<void>;
|
|
74
87
|
update(params: ISchedulerServiceUpdateParams): Promise<void>;
|
|
75
|
-
delete(
|
|
76
|
-
exists(
|
|
88
|
+
delete(params: ISchedulerServiceDeleteParams): Promise<void>;
|
|
89
|
+
exists(params: ISchedulerServiceExistsParams): Promise<boolean>;
|
|
77
90
|
}
|
|
78
91
|
/** Core service for managing scheduled actions. */
|
|
79
92
|
export declare const SchedulerService: import("@webiny/di").Abstraction<ISchedulerService>;
|
|
80
93
|
export declare namespace SchedulerService {
|
|
81
94
|
type Interface = ISchedulerService;
|
|
95
|
+
type CreateParams = ISchedulerServiceCreateParams;
|
|
96
|
+
type UpdateParams = ISchedulerServiceUpdateParams;
|
|
97
|
+
type DeleteParams = ISchedulerServiceDeleteParams;
|
|
98
|
+
type ExistsParams = ISchedulerServiceExistsParams;
|
|
82
99
|
}
|
|
83
100
|
/**
|
|
84
101
|
* ScheduledActionModel - A CMS model used by the scheduler for persistence.
|
|
@@ -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 * ScheduledActionModel - A CMS model used by the scheduler for persistence.\n */\n/** Content model definition for scheduled actions. */\nexport const ScheduledActionModel = createAbstraction<CmsModel>(\"ScheduledActionModel\");\n\nexport namespace ScheduledActionModel {\n export type Interface = CmsModel;\n}\n"],"names":["ScheduledActionHandler","createAbstraction","SchedulerService","ScheduledActionModel"],"mappings":";AAoEO,MAAMA,yBACTC,kBAA2C;AA6CxC,MAAMC,mBAAmBD,kBAAqC;AAc9D,MAAME,uBAAuBF,kBAA4B"}
|