@webiny/api-scheduler 0.0.0-unstable.a4f3e4ea8b → 0.0.0-unstable.a85ef555b2
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/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 +12 -3
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +10 -12
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +1 -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 +8 -7
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +1 -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 +11 -3
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +8 -10
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +14 -3
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +9 -11
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -1
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +12 -3
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +11 -13
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- package/features/ScheduleAction/ScheduleActionUseCase.d.ts +6 -6
- package/features/ScheduleAction/ScheduleActionUseCase.js +10 -8
- package/features/ScheduleAction/ScheduleActionUseCase.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/permissions/SchedulerPermissionsResolver.d.ts +4 -2
- package/features/permissions/SchedulerPermissionsResolver.js +22 -3
- package/features/permissions/SchedulerPermissionsResolver.js.map +1 -1
- package/features/permissions/abstractions.d.ts +5 -1
- 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/index.d.ts +3 -2
- package/index.js +3 -2
- package/package.json +11 -11
- package/shared/abstractions.d.ts +11 -5
- package/shared/abstractions.js +2 -2
- package/shared/abstractions.js.map +1 -1
- package/context.d.ts +0 -3
- package/context.js +0 -39
- package/context.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ScheduledActionEventHandler } from "@webiny/event-handler-core";
|
|
2
|
+
import type { IScheduledActionEvent } from "@webiny/event-handler-core";
|
|
3
|
+
import type { IScheduledActionResult } from "@webiny/event-handler-core";
|
|
4
|
+
import type { EventContext, NextFunction } from "@webiny/event-handler-core";
|
|
5
|
+
import type { IExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/abstractions.js";
|
|
6
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/exports/api/tenancy.js";
|
|
8
|
+
declare class ScheduledActionLambdaHandlerImpl implements ScheduledActionEventHandler.Interface {
|
|
9
|
+
private executeScheduledAction;
|
|
10
|
+
private tenantContext;
|
|
11
|
+
private getTenantById;
|
|
12
|
+
constructor(executeScheduledAction: IExecuteScheduledActionUseCase, tenantContext: TenantContext.Interface, getTenantById: GetTenantByIdUseCase.Interface);
|
|
13
|
+
execute(eventCtx: EventContext<IScheduledActionEvent>, _next: NextFunction): Promise<IScheduledActionResult>;
|
|
14
|
+
}
|
|
15
|
+
export declare const ScheduledActionLambdaHandler: typeof ScheduledActionLambdaHandlerImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core/features/scheduledAction/ScheduledActionEventHandler").IScheduledActionEventHandler>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ScheduledActionEventHandler } from "@webiny/event-handler-core";
|
|
2
|
+
import { ExecuteScheduledActionUseCase } from "./features/ExecuteScheduledAction/index.js";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/exports/api/tenancy.js";
|
|
5
|
+
import { SCHEDULED_ACTION_EVENT_IDENTIFIER } from "./constants.js";
|
|
6
|
+
class ScheduledActionLambdaHandlerImpl {
|
|
7
|
+
constructor(executeScheduledAction, tenantContext, getTenantById){
|
|
8
|
+
this.executeScheduledAction = executeScheduledAction;
|
|
9
|
+
this.tenantContext = tenantContext;
|
|
10
|
+
this.getTenantById = getTenantById;
|
|
11
|
+
}
|
|
12
|
+
async execute(eventCtx, _next) {
|
|
13
|
+
const input = eventCtx.event[SCHEDULED_ACTION_EVENT_IDENTIFIER];
|
|
14
|
+
if (!input.tenant) input.tenant = this.tenantContext.getTenant().id;
|
|
15
|
+
const tenantResult = await this.getTenantById.execute(input.tenant);
|
|
16
|
+
if (tenantResult.isFail()) throw tenantResult.error;
|
|
17
|
+
const tenant = tenantResult.value;
|
|
18
|
+
return this.tenantContext.withTenant(tenant, async ()=>{
|
|
19
|
+
const result = await this.executeScheduledAction.execute(input);
|
|
20
|
+
if (result.isFail()) {
|
|
21
|
+
const error = result.error;
|
|
22
|
+
console.error(error.code, error.message);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
success: true
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const ScheduledActionLambdaHandler = ScheduledActionEventHandler.createImplementation({
|
|
32
|
+
implementation: ScheduledActionLambdaHandlerImpl,
|
|
33
|
+
dependencies: [
|
|
34
|
+
ExecuteScheduledActionUseCase,
|
|
35
|
+
TenantContext,
|
|
36
|
+
GetTenantByIdUseCase
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
export { ScheduledActionLambdaHandler };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=ScheduledActionLambdaHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScheduledActionLambdaHandler.js","sources":["../src/ScheduledActionLambdaHandler.ts"],"sourcesContent":["import { ScheduledActionEventHandler } from \"@webiny/event-handler-core\";\nimport type { IScheduledActionEvent } from \"@webiny/event-handler-core\";\nimport type { IScheduledActionResult } from \"@webiny/event-handler-core\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport { ExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/index.js\";\nimport type { IExecuteScheduledActionUseCase } from \"~/features/ExecuteScheduledAction/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/exports/api/tenancy.js\";\nimport { SCHEDULED_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\n\nclass ScheduledActionLambdaHandlerImpl implements ScheduledActionEventHandler.Interface {\n constructor(\n private executeScheduledAction: IExecuteScheduledActionUseCase,\n private tenantContext: TenantContext.Interface,\n private getTenantById: GetTenantByIdUseCase.Interface\n ) {}\n\n async execute(\n eventCtx: EventContext<IScheduledActionEvent>,\n _next: NextFunction\n ): Promise<IScheduledActionResult> {\n const input = eventCtx.event[SCHEDULED_ACTION_EVENT_IDENTIFIER];\n\n /**\n * Use the current tenant if the payload doesn't carry one — keeps backward compatibility\n * with scheduled actions created before `tenant` was added to the payload. The actual\n * per-request DynamoDB queries run inside withTenant() below.\n */\n if (!input.tenant) {\n input.tenant = this.tenantContext.getTenant().id;\n }\n\n const tenantResult = await this.getTenantById.execute(input.tenant);\n if (tenantResult.isFail()) {\n throw tenantResult.error;\n }\n const tenant = tenantResult.value;\n\n return this.tenantContext.withTenant(tenant, async () => {\n const result = await this.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\n return { success: true };\n });\n }\n}\n\nexport const ScheduledActionLambdaHandler = ScheduledActionEventHandler.createImplementation({\n implementation: ScheduledActionLambdaHandlerImpl,\n dependencies: [ExecuteScheduledActionUseCase, TenantContext, GetTenantByIdUseCase]\n});\n"],"names":["ScheduledActionLambdaHandlerImpl","executeScheduledAction","tenantContext","getTenantById","eventCtx","_next","input","SCHEDULED_ACTION_EVENT_IDENTIFIER","tenantResult","tenant","result","error","console","ScheduledActionLambdaHandler","ScheduledActionEventHandler","ExecuteScheduledActionUseCase","TenantContext","GetTenantByIdUseCase"],"mappings":";;;;;AAUA,MAAMA;IACF,YACYC,sBAAsD,EACtDC,aAAsC,EACtCC,aAA6C,CACvD;aAHUF,sBAAsB,GAAtBA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,QAA6C,EAC7CC,KAAmB,EACY;QAC/B,MAAMC,QAAQF,SAAS,KAAK,CAACG,kCAAkC;QAO/D,IAAI,CAACD,MAAM,MAAM,EACbA,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAGpD,MAAME,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACF,MAAM,MAAM;QAClE,IAAIE,aAAa,MAAM,IACnB,MAAMA,aAAa,KAAK;QAE5B,MAAMC,SAASD,aAAa,KAAK;QAEjC,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,CAACC,QAAQ;YACzC,MAAMC,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAACJ;YAEzD,IAAII,OAAO,MAAM,IAAI;gBACjB,MAAMC,QAAQD,OAAO,KAAK;gBAC1BE,QAAQ,KAAK,CAACD,MAAM,IAAI,EAAEA,MAAM,OAAO;gBACvC,MAAMA;YACV;YAEA,OAAO;gBAAE,SAAS;YAAK;QAC3B;IACJ;AACJ;AAEO,MAAME,+BAA+BC,4BAA4B,oBAAoB,CAAC;IACzF,gBAAgBd;IAChB,cAAc;QAACe;QAA+BC;QAAeC;KAAqB;AACtF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SchedulePrivateModel } from "./domain/SchedulePrivateModel.js";
|
|
3
|
+
import { SchedulerPermissionsResolver } from "./features/permissions/SchedulerPermissionsResolver.js";
|
|
4
|
+
import { SchedulerGraphQLFactoryFeature } from "./graphql/feature.js";
|
|
5
|
+
import { NamespaceHandlerExecutionerFeature } from "./features/NamespaceHandler/feature.js";
|
|
6
|
+
import { ScheduledActionModelProvider } from "./features/ScheduledActionModelProvider.js";
|
|
7
|
+
import { SchedulerFeature } from "./features/SchedulerFeature.js";
|
|
8
|
+
const SchedulerFeature_SchedulerFeature = createFeature({
|
|
9
|
+
name: "Scheduler",
|
|
10
|
+
register (container) {
|
|
11
|
+
container.register(SchedulePrivateModel);
|
|
12
|
+
container.register(SchedulerPermissionsResolver);
|
|
13
|
+
SchedulerGraphQLFactoryFeature.register(container);
|
|
14
|
+
NamespaceHandlerExecutionerFeature.register(container);
|
|
15
|
+
SchedulerFeature.register(container);
|
|
16
|
+
container.register(ScheduledActionModelProvider);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
export { SchedulerFeature_SchedulerFeature as SchedulerFeature };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=SchedulerFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchedulerFeature.js","sources":["../src/SchedulerFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { SchedulePrivateModel } from \"./domain/SchedulePrivateModel.js\";\nimport { SchedulerPermissionsResolver } from \"~/features/permissions/SchedulerPermissionsResolver.js\";\nimport { SchedulerGraphQLFactoryFeature } from \"~/graphql/feature.js\";\nimport { NamespaceHandlerExecutionerFeature } from \"~/features/NamespaceHandler/feature.js\";\nimport { ScheduledActionModelProvider } from \"~/features/ScheduledActionModelProvider.js\";\nimport { SchedulerFeature as SchedulerCoreFeature } from \"~/features/SchedulerFeature.js\";\n\nexport const SchedulerFeature = createFeature({\n name: \"Scheduler\",\n register(container: Container) {\n container.register(SchedulePrivateModel);\n container.register(SchedulerPermissionsResolver);\n SchedulerGraphQLFactoryFeature.register(container);\n NamespaceHandlerExecutionerFeature.register(container);\n SchedulerCoreFeature.register(container);\n container.register(ScheduledActionModelProvider);\n }\n});\n"],"names":["SchedulerFeature","createFeature","container","SchedulePrivateModel","SchedulerPermissionsResolver","SchedulerGraphQLFactoryFeature","NamespaceHandlerExecutionerFeature","SchedulerCoreFeature","ScheduledActionModelProvider"],"mappings":";;;;;;;AAQO,MAAMA,oCAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBC,+BAA+B,QAAQ,CAACH;QACxCI,mCAAmC,QAAQ,CAACJ;QAC5CK,iBAAAA,QAA6B,CAACL;QAC9BA,UAAU,QAAQ,CAACM;IACvB;AACJ"}
|
|
@@ -5,7 +5,8 @@ class SchedulePrivateModelImpl {
|
|
|
5
5
|
return [
|
|
6
6
|
builder.private({
|
|
7
7
|
modelId: SCHEDULE_MODEL_ID,
|
|
8
|
-
name: "Webiny CMS Schedule"
|
|
8
|
+
name: "Webiny CMS Schedule",
|
|
9
|
+
lifecycleEvents: false
|
|
9
10
|
}).fields((fields)=>({
|
|
10
11
|
namespace: fields.text().label("Namespace"),
|
|
11
12
|
actionType: fields.text().label("Action Type"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/SchedulePrivateModel.js","sources":["../../src/domain/SchedulePrivateModel.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nclass SchedulePrivateModelImpl implements ModelFactory.Interface {\n public async execute(builder: ModelFactory.Builder) {\n return [\n builder\n .private({\n modelId: SCHEDULE_MODEL_ID,\n name: \"Webiny CMS Schedule\"\n })\n .fields(fields => ({\n namespace: fields.text().label(\"Namespace\"),\n actionType: fields.text().label(\"Action Type\"),\n targetId: fields.text().label(\"Target ID\"),\n scheduledBy: fields\n .object()\n .label(\"Scheduled By\")\n .fields(fields => ({\n id: fields.text().label(\"Identity ID\"),\n displayName: fields.text().label(\"Display Name\"),\n type: fields.text().label(\"Type\")\n })),\n scheduledFor: fields.datetime().label(\"Scheduled For\"),\n title: fields.text().label(\"Title\"),\n error: fields.text().label(\"Error\"),\n payload: fields.json().label(\"Payload\")\n }))\n ];\n }\n}\n\nexport const SchedulePrivateModel = ModelFactory.createImplementation({\n implementation: SchedulePrivateModelImpl,\n dependencies: []\n});\n"],"names":["SchedulePrivateModelImpl","builder","SCHEDULE_MODEL_ID","fields","SchedulePrivateModel","ModelFactory"],"mappings":";;AAGA,MAAMA;IACF,MAAa,QAAQC,OAA6B,EAAE;QAChD,OAAO;YACHA,QACK,OAAO,CAAC;gBACL,SAASC;gBACT,MAAM;
|
|
1
|
+
{"version":3,"file":"domain/SchedulePrivateModel.js","sources":["../../src/domain/SchedulePrivateModel.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nclass SchedulePrivateModelImpl implements ModelFactory.Interface {\n public async execute(builder: ModelFactory.Builder) {\n return [\n builder\n .private({\n modelId: SCHEDULE_MODEL_ID,\n name: \"Webiny CMS Schedule\",\n lifecycleEvents: false\n })\n .fields(fields => ({\n namespace: fields.text().label(\"Namespace\"),\n actionType: fields.text().label(\"Action Type\"),\n targetId: fields.text().label(\"Target ID\"),\n scheduledBy: fields\n .object()\n .label(\"Scheduled By\")\n .fields(fields => ({\n id: fields.text().label(\"Identity ID\"),\n displayName: fields.text().label(\"Display Name\"),\n type: fields.text().label(\"Type\")\n })),\n scheduledFor: fields.datetime().label(\"Scheduled For\"),\n title: fields.text().label(\"Title\"),\n error: fields.text().label(\"Error\"),\n payload: fields.json().label(\"Payload\")\n }))\n ];\n }\n}\n\nexport const SchedulePrivateModel = ModelFactory.createImplementation({\n implementation: SchedulePrivateModelImpl,\n dependencies: []\n});\n"],"names":["SchedulePrivateModelImpl","builder","SCHEDULE_MODEL_ID","fields","SchedulePrivateModel","ModelFactory"],"mappings":";;AAGA,MAAMA;IACF,MAAa,QAAQC,OAA6B,EAAE;QAChD,OAAO;YACHA,QACK,OAAO,CAAC;gBACL,SAASC;gBACT,MAAM;gBACN,iBAAiB;YACrB,GACC,MAAM,CAACC,CAAAA,SAAW;oBACf,WAAWA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC/B,YAAYA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAChC,UAAUA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC9B,aAAaA,OACR,MAAM,GACN,KAAK,CAAC,gBACN,MAAM,CAACA,CAAAA,SAAW;4BACf,IAAIA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACxB,aAAaA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACjC,MAAMA,OAAO,IAAI,GAAG,KAAK,CAAC;wBAC9B;oBACJ,cAAcA,OAAO,QAAQ,GAAG,KAAK,CAAC;oBACtC,OAAOA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC3B,OAAOA,OAAO,IAAI,GAAG,KAAK,CAAC;oBAC3B,SAASA,OAAO,IAAI,GAAG,KAAK,CAAC;gBACjC;SACP;IACL;AACJ;AAEO,MAAMC,uBAAuBC,aAAa,oBAAoB,CAAC;IAClE,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
|
package/domain/errors.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class InvalidScheduleDateError extends BaseError<{
|
|
|
34
34
|
constructor(scheduleFor: Date);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Scheduler service error (
|
|
37
|
+
* Scheduler service error (scheduler backend / provider errors)
|
|
38
38
|
*/
|
|
39
39
|
export declare class SchedulerServiceError extends BaseError<{
|
|
40
40
|
originalError: Error;
|
package/domain/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Not authorized error when user lacks permissions to manage scheduled actions.\n */\nexport class NotAuthorizedError extends BaseError {\n override readonly code = \"Scheduler/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not authorized!\" });\n }\n}\n\n/**\n * Scheduled action not found error\n */\nexport class ScheduledActionNotFoundError extends BaseError<{ scheduleId: string }> {\n override readonly code = \"Scheduler/ScheduledAction/NotFound\" as const;\n\n constructor(scheduleId: string) {\n super({\n message: `Scheduled action \"${scheduleId}\" was not found.`,\n data: {\n scheduleId\n }\n });\n }\n}\n\n/**\n * Storage/persistence error when working with scheduled actions\n */\nexport class ScheduledActionPersistenceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/ScheduledAction/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message,\n data: { originalError: error }\n });\n }\n}\n\n/**\n * Invalid schedule date error (e.g., scheduling in the past)\n */\nexport class InvalidScheduleDateError extends BaseError<{ scheduleFor: string }> {\n override readonly code = \"Scheduler/ScheduledAction/InvalidDate\" as const;\n\n constructor(scheduleFor: Date) {\n super({\n message: \"Cannot schedule in the past\",\n data: {\n scheduleFor: scheduleFor.toISOString()\n }\n });\n }\n}\n\n/**\n * Scheduler service error (
|
|
1
|
+
{"version":3,"file":"domain/errors.js","sources":["../../src/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Not authorized error when user lacks permissions to manage scheduled actions.\n */\nexport class NotAuthorizedError extends BaseError {\n override readonly code = \"Scheduler/NotAuthorized\" as const;\n\n constructor() {\n super({ message: \"Not authorized!\" });\n }\n}\n\n/**\n * Scheduled action not found error\n */\nexport class ScheduledActionNotFoundError extends BaseError<{ scheduleId: string }> {\n override readonly code = \"Scheduler/ScheduledAction/NotFound\" as const;\n\n constructor(scheduleId: string) {\n super({\n message: `Scheduled action \"${scheduleId}\" was not found.`,\n data: {\n scheduleId\n }\n });\n }\n}\n\n/**\n * Storage/persistence error when working with scheduled actions\n */\nexport class ScheduledActionPersistenceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/ScheduledAction/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message,\n data: { originalError: error }\n });\n }\n}\n\n/**\n * Invalid schedule date error (e.g., scheduling in the past)\n */\nexport class InvalidScheduleDateError extends BaseError<{ scheduleFor: string }> {\n override readonly code = \"Scheduler/ScheduledAction/InvalidDate\" as const;\n\n constructor(scheduleFor: Date) {\n super({\n message: \"Cannot schedule in the past\",\n data: {\n scheduleFor: scheduleFor.toISOString()\n }\n });\n }\n}\n\n/**\n * Scheduler service error (scheduler backend / provider errors)\n */\nexport class SchedulerServiceError extends BaseError<{ originalError: Error }> {\n override readonly code = \"Scheduler/Service/Error\" as const;\n\n constructor(error: Error) {\n super({\n message: `Scheduler service error: ${error.message}`,\n data: { originalError: error }\n });\n }\n}\n\ninterface INamespaceHandlerNotFoundErrorData {\n namespace: string;\n}\n/**\n * Namespace handler not found error.\n */\nexport class NamespaceHandlerNotFoundError extends BaseError<INamespaceHandlerNotFoundErrorData> {\n override readonly code = \"Scheduler/NamespaceHandler/NotFound\" as const;\n\n constructor(namespace: string) {\n super({\n message: `Namespace handler for \"${namespace}\" was not found.`,\n data: {\n namespace\n }\n });\n }\n}\n"],"names":["NotAuthorizedError","BaseError","ScheduledActionNotFoundError","scheduleId","ScheduledActionPersistenceError","error","InvalidScheduleDateError","scheduleFor","SchedulerServiceError","NamespaceHandlerNotFoundError","namespace"],"mappings":";AAKO,MAAMA,2BAA2BC;IAGpC,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAkB,SAHrB,IAAI,GAAG;IAIzB;AACJ;AAKO,MAAMC,qCAAqCD;IAG9C,YAAYE,UAAkB,CAAE;QAC5B,KAAK,CAAC;YACF,SAAS,CAAC,kBAAkB,EAAEA,WAAW,gBAAgB,CAAC;YAC1D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAKO,MAAMC,wCAAwCH;IAGjD,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;YACtB,MAAM;gBAAE,eAAeA;YAAM;QACjC,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,iCAAiCL;IAG1C,YAAYM,WAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBACF,aAAaA,YAAY,WAAW;YACxC;QACJ,SARc,IAAI,GAAG;IASzB;AACJ;AAKO,MAAMC,8BAA8BP;IAGvC,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,yBAAyB,EAAEA,MAAM,OAAO,EAAE;YACpD,MAAM;gBAAE,eAAeA;YAAM;QACjC,SANc,IAAI,GAAG;IAOzB;AACJ;AAQO,MAAMI,sCAAsCR;IAG/C,YAAYS,SAAiB,CAAE;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,uBAAuB,EAAEA,UAAU,gBAAgB,CAAC;YAC9D,MAAM;gBACFA;YACJ;QACJ,SARc,IAAI,GAAG;IASzB;AACJ"}
|
|
@@ -6,5 +6,5 @@ export { CancelScheduledActionUseCase } from "../../features/CancelScheduledActi
|
|
|
6
6
|
export { ExecuteScheduledActionUseCase } from "../../features/ExecuteScheduledAction/index.js";
|
|
7
7
|
export { NamespaceHandler } from "../../features/NamespaceHandler/index.js";
|
|
8
8
|
export type { IScheduledAction, IScheduledActionEntry, ScheduledActionType } from "../../shared/abstractions.js";
|
|
9
|
-
export { SchedulerService,
|
|
9
|
+
export { SchedulerService, ScheduledActionHandler } from "../../shared/abstractions.js";
|
|
10
10
|
export { SCHEDULED_ACTION_PUBLISH as ScheduledActionTypePublish, SCHEDULED_ACTION_UNPUBLISH as ScheduledActionTypeUnpublish } from "../../constants.js";
|
package/exports/api/scheduler.js
CHANGED
|
@@ -4,5 +4,5 @@ export { ListScheduledActionsUseCase } from "../../features/ListScheduledActions
|
|
|
4
4
|
export { CancelScheduledActionUseCase } from "../../features/CancelScheduledAction/index.js";
|
|
5
5
|
export { ExecuteScheduledActionUseCase } from "../../features/ExecuteScheduledAction/index.js";
|
|
6
6
|
export { NamespaceHandler } from "../../features/NamespaceHandler/index.js";
|
|
7
|
-
export { ScheduledActionHandler,
|
|
7
|
+
export { ScheduledActionHandler, SchedulerService } from "../../shared/abstractions.js";
|
|
8
8
|
export { SCHEDULED_ACTION_PUBLISH as ScheduledActionTypePublish, SCHEDULED_ACTION_UNPUBLISH as ScheduledActionTypeUnpublish } from "../../constants.js";
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { CancelScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import { GetScheduledActionUseCase } from "../../features/GetScheduledAction/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider, SchedulerService } from "../../shared/abstractions.js";
|
|
5
5
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
6
|
import { SchedulerPermissionsResolver } from "../../features/permissions/abstractions.js";
|
|
7
|
+
/**
|
|
8
|
+
* Cancels a scheduled action
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* 1. Check if schedule exists
|
|
12
|
+
* 2. Delete scheduler timer
|
|
13
|
+
* 3. Delete CMS entry
|
|
14
|
+
* 4. If the scheduler delete fails, continue anyway (schedule might already be executed/deleted)
|
|
15
|
+
*/
|
|
7
16
|
declare class CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
17
|
private getScheduledActionUseCase;
|
|
9
18
|
private schedulerService;
|
|
10
19
|
private deleteEntryUseCase;
|
|
11
|
-
private
|
|
20
|
+
private modelProvider;
|
|
12
21
|
private permissionsResolver;
|
|
13
|
-
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, schedulerService: SchedulerService.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface,
|
|
22
|
+
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, schedulerService: SchedulerService.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, permissionsResolver: SchedulerPermissionsResolver.Interface);
|
|
14
23
|
execute(params: UseCaseAbstraction.Params): Promise<Result<boolean, UseCaseAbstraction.Error>>;
|
|
15
24
|
}
|
|
16
25
|
export declare const CancelScheduledActionUseCase: typeof CancelScheduledActionUseCaseImpl & {
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { CancelScheduledActionUseCase } from "./abstractions.js";
|
|
3
3
|
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider, SchedulerService } from "../../shared/abstractions.js";
|
|
5
5
|
import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
6
6
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
7
7
|
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
8
8
|
import { EntryNotFoundError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
9
9
|
import { SchedulerPermissionsResolver } from "../permissions/abstractions.js";
|
|
10
10
|
class CancelScheduledActionUseCaseImpl {
|
|
11
|
-
constructor(getScheduledActionUseCase, schedulerService, deleteEntryUseCase,
|
|
11
|
+
constructor(getScheduledActionUseCase, schedulerService, deleteEntryUseCase, modelProvider, permissionsResolver){
|
|
12
12
|
this.getScheduledActionUseCase = getScheduledActionUseCase;
|
|
13
13
|
this.schedulerService = schedulerService;
|
|
14
14
|
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
15
|
-
this.
|
|
15
|
+
this.modelProvider = modelProvider;
|
|
16
16
|
this.permissionsResolver = permissionsResolver;
|
|
17
17
|
}
|
|
18
18
|
async execute(params) {
|
|
19
19
|
const { id, namespace } = params;
|
|
20
20
|
const permissions = this.permissionsResolver.forNamespace(namespace);
|
|
21
|
-
if (permissions)
|
|
22
|
-
const hasPermission = await permissions.canRead();
|
|
23
|
-
if (!hasPermission) return Result.fail(new NotAuthorizedError());
|
|
24
|
-
}
|
|
21
|
+
if (!await permissions.canRead()) return Result.fail(new NotAuthorizedError());
|
|
25
22
|
const getResult = await this.getScheduledActionUseCase.execute(params);
|
|
26
23
|
if (getResult.isFail()) {
|
|
27
24
|
const error = getResult.error;
|
|
@@ -30,12 +27,13 @@ class CancelScheduledActionUseCaseImpl {
|
|
|
30
27
|
}
|
|
31
28
|
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
32
29
|
try {
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
30
|
+
const scheduleExists = await this.schedulerService.exists(params);
|
|
31
|
+
if (scheduleExists) await this.schedulerService.delete(params);
|
|
35
32
|
} catch (error) {
|
|
36
|
-
console.warn(`Failed to delete
|
|
33
|
+
console.warn(`Failed to delete the schedule: ${scheduleId}, tenant "${params.tenant}". Continuing with CMS entry deletion.`, error);
|
|
37
34
|
}
|
|
38
|
-
const
|
|
35
|
+
const model = await this.modelProvider.get();
|
|
36
|
+
const deleteResult = await this.deleteEntryUseCase.execute(model, getResult.value.id, {
|
|
39
37
|
force: true,
|
|
40
38
|
permanently: true
|
|
41
39
|
});
|
|
@@ -52,7 +50,7 @@ const CancelScheduledActionUseCase_CancelScheduledActionUseCase = CancelSchedule
|
|
|
52
50
|
GetScheduledActionUseCase,
|
|
53
51
|
SchedulerService,
|
|
54
52
|
DeleteEntryUseCase,
|
|
55
|
-
|
|
53
|
+
ScheduledActionModelProvider,
|
|
56
54
|
SchedulerPermissionsResolver
|
|
57
55
|
]
|
|
58
56
|
});
|
|
@@ -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 {
|
|
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 { ScheduledActionModelProvider, 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 { SchedulerPermissionsResolver } from \"~/features/permissions/abstractions.js\";\n\n/**\n * Cancels a scheduled action\n *\n * Flow:\n * 1. Check if schedule exists\n * 2. Delete scheduler timer\n * 3. Delete CMS entry\n * 4. If the scheduler 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 modelProvider: ScheduledActionModelProvider.Interface,\n private permissionsResolver: SchedulerPermissionsResolver.Interface\n ) {}\n\n async execute(\n params: UseCaseAbstraction.Params\n ): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n const { id, namespace } = params;\n const permissions = this.permissionsResolver.forNamespace(namespace);\n if (!(await permissions.canRead())) {\n return Result.fail(new NotAuthorizedError());\n }\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 the scheduler timer\n // Note: We continue even if this fails, as the schedule might already be executed/deleted\n try {\n const scheduleExists = await this.schedulerService.exists(params);\n /**\n * No point to even try deleting if it doesn't exist.\n */\n if (scheduleExists) {\n await this.schedulerService.delete(params);\n }\n } catch (error) {\n console.warn(\n `Failed to delete the schedule: ${scheduleId}, tenant \"${params.tenant}\". Continuing with CMS entry deletion.`,\n error\n );\n }\n\n // Delete CMS entry\n const model = await this.modelProvider.get();\n const deleteResult = await this.deleteEntryUseCase.execute(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 ScheduledActionModelProvider,\n SchedulerPermissionsResolver\n ]\n});\n"],"names":["CancelScheduledActionUseCaseImpl","getScheduledActionUseCase","schedulerService","deleteEntryUseCase","modelProvider","permissionsResolver","params","id","namespace","permissions","Result","NotAuthorizedError","getResult","error","ScheduledActionNotFoundError","scheduleId","ScheduledActionIdWithVersion","scheduleExists","console","model","deleteResult","EntryNotFoundError","ScheduledActionPersistenceError","Error","CancelScheduledActionUseCase","UseCaseAbstraction","GetScheduledActionUseCase","SchedulerService","DeleteEntryUseCase","ScheduledActionModelProvider","SchedulerPermissionsResolver"],"mappings":";;;;;;;;;AAuBA,MAAMA;IACF,YACYC,yBAA8D,EAC9DC,gBAA4C,EAC5CC,kBAAgD,EAChDC,aAAqD,EACrDC,mBAA2D,CACrE;aALUJ,yBAAyB,GAAzBA;aACAC,gBAAgB,GAAhBA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;IACT;IAEH,MAAM,QACFC,MAAiC,EACiB;QAClD,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGF;QAC1B,MAAMG,cAAc,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAACD;QAC1D,IAAI,CAAE,MAAMC,YAAY,OAAO,IAC3B,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,YAAY,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAACN;QAE/D,IAAIM,UAAU,MAAM,IAAI;YACpB,MAAMC,QAAQD,UAAU,KAAK;YAE7B,IAAIC,AAAe,yCAAfA,MAAM,IAAI,EACV,OAAOH,OAAO,IAAI,CAAC,IAAII,6BAA6BP;YAGxD,OAAOG,OAAO,IAAI,CAACG;QACvB;QAEA,MAAME,aAAaC,6BAA6B,IAAI,CAACT;QAIrD,IAAI;YACA,MAAMU,iBAAiB,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACX;YAI1D,IAAIW,gBACA,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACX;QAE3C,EAAE,OAAOO,OAAO;YACZK,QAAQ,IAAI,CACR,CAAC,+BAA+B,EAAEH,WAAW,UAAU,EAAET,OAAO,MAAM,CAAC,sCAAsC,CAAC,EAC9GO;QAER;QAGA,MAAMM,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG;QAC1C,MAAMC,eAAe,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACD,OAAOP,UAAU,KAAK,CAAC,EAAE,EAAE;YAClF,OAAO;YACP,aAAa;QACjB;QAEA,IAAIQ,aAAa,MAAM,IAAI;YAIvB,IAAIA,aAAa,KAAK,YAAYC,oBAC9B,OAAOX,OAAO,EAAE,CAAC;YAErB,OAAOA,OAAO,IAAI,CACd,IAAIY,gCAAgC,IAAIC,MAAMH,aAAa,KAAK,CAAC,OAAO;QAEhF;QAEA,OAAOV,OAAO,EAAE,CAAC;IACrB;AACJ;AAEO,MAAMc,4DAA+BC,6BAAAA,oBAAuC,CAAC;IAChF,gBAAgBzB;IAChB,cAAc;QACV0B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -3,7 +3,7 @@ import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersis
|
|
|
3
3
|
/**
|
|
4
4
|
* CancelScheduledActionUseCase - Cancel a scheduled action
|
|
5
5
|
*
|
|
6
|
-
* Cancels both the CMS entry and the
|
|
6
|
+
* Cancels both the CMS entry and the scheduler timer.
|
|
7
7
|
* Used when a user manually cancels a scheduled action or when business logic
|
|
8
8
|
* determines the action should no longer execute.
|
|
9
9
|
*/
|
|
@@ -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
|
|
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 scheduler timer.\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"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* CancelScheduledAction Feature
|
|
3
3
|
*
|
|
4
4
|
* Provides the ability to cancel a scheduled action.
|
|
5
|
-
* Removes both the
|
|
5
|
+
* Removes both the scheduler timer and the CMS entry.
|
|
6
6
|
*/
|
|
7
7
|
export declare const CancelScheduledActionFeature: {
|
|
8
8
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CancelScheduledAction/feature.js","sources":["../../../src/features/CancelScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CancelScheduledActionUseCase } from \"./CancelScheduledActionUseCase.js\";\n\n/**\n * CancelScheduledAction Feature\n *\n * Provides the ability to cancel a scheduled action.\n * Removes both the
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledAction/feature.js","sources":["../../../src/features/CancelScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CancelScheduledActionUseCase } from \"./CancelScheduledActionUseCase.js\";\n\n/**\n * CancelScheduledAction Feature\n *\n * Provides the ability to cancel a scheduled action.\n * Removes both the scheduler timer and the CMS entry.\n */\nexport const CancelScheduledActionFeature = createFeature({\n name: \"CancelScheduledAction\",\n register(container) {\n container.register(CancelScheduledActionUseCase);\n }\n});\n"],"names":["CancelScheduledActionFeature","createFeature","container","CancelScheduledActionUseCase"],"mappings":";;AASO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ExecuteScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import { GetScheduledActionUseCase } from "../../features/GetScheduledAction/abstractions.js";
|
|
4
|
-
import { ScheduledActionHandler,
|
|
4
|
+
import { ScheduledActionHandler, ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
6
|
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
|
|
7
7
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
@@ -21,9 +21,9 @@ declare class ExecuteScheduledActionUseCaseImpl implements UseCaseAbstraction.In
|
|
|
21
21
|
private actionHandler;
|
|
22
22
|
private deleteEntryUseCase;
|
|
23
23
|
private updateEntryUseCase;
|
|
24
|
-
private
|
|
24
|
+
private modelProvider;
|
|
25
25
|
private identityContext;
|
|
26
|
-
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, actionHandler: ScheduledActionHandler.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface,
|
|
26
|
+
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, actionHandler: ScheduledActionHandler.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, identityContext: IdentityContext.Interface);
|
|
27
27
|
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<void, UseCaseAbstraction.Error>>;
|
|
28
28
|
private executeAction;
|
|
29
29
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ExecuteScheduledActionUseCase, ExecutionFailedError, HandlerNotFoundError } from "./abstractions.js";
|
|
3
3
|
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
4
|
-
import { ScheduledActionHandler,
|
|
4
|
+
import { ScheduledActionHandler, ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
6
6
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
7
7
|
import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
|
|
8
8
|
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
9
9
|
import { AuthenticatedIdentity, IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
10
10
|
class ExecuteScheduledActionUseCaseImpl {
|
|
11
|
-
constructor(getScheduledActionUseCase, actionHandler, deleteEntryUseCase, updateEntryUseCase,
|
|
11
|
+
constructor(getScheduledActionUseCase, actionHandler, deleteEntryUseCase, updateEntryUseCase, modelProvider, identityContext){
|
|
12
12
|
this.getScheduledActionUseCase = getScheduledActionUseCase;
|
|
13
13
|
this.actionHandler = actionHandler;
|
|
14
14
|
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
15
15
|
this.updateEntryUseCase = updateEntryUseCase;
|
|
16
|
-
this.
|
|
16
|
+
this.modelProvider = modelProvider;
|
|
17
17
|
this.identityContext = identityContext;
|
|
18
18
|
}
|
|
19
19
|
async execute(params) {
|
|
@@ -21,6 +21,7 @@ class ExecuteScheduledActionUseCaseImpl {
|
|
|
21
21
|
}
|
|
22
22
|
async executeAction(params) {
|
|
23
23
|
const { id } = params;
|
|
24
|
+
const model = await this.modelProvider.get();
|
|
24
25
|
const getResult = await this.getScheduledActionUseCase.execute(params);
|
|
25
26
|
if (getResult.isFail()) {
|
|
26
27
|
const error = getResult.error;
|
|
@@ -40,7 +41,7 @@ class ExecuteScheduledActionUseCaseImpl {
|
|
|
40
41
|
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
41
42
|
if (!this.actionHandler.canHandle(scheduledAction.namespace, scheduledAction.actionType)) {
|
|
42
43
|
const error = new HandlerNotFoundError(scheduledAction.namespace, scheduledAction.actionType);
|
|
43
|
-
const updateResult = await this.updateEntryUseCase.execute(
|
|
44
|
+
const updateResult = await this.updateEntryUseCase.execute(model, scheduleId, {
|
|
44
45
|
values: {
|
|
45
46
|
error: error.message
|
|
46
47
|
}
|
|
@@ -53,7 +54,7 @@ class ExecuteScheduledActionUseCaseImpl {
|
|
|
53
54
|
}
|
|
54
55
|
try {
|
|
55
56
|
await this.actionHandler.handle(scheduledAction);
|
|
56
|
-
const deleteResult = await this.deleteEntryUseCase.execute(
|
|
57
|
+
const deleteResult = await this.deleteEntryUseCase.execute(model, scheduleId, {
|
|
57
58
|
force: true,
|
|
58
59
|
permanently: true
|
|
59
60
|
});
|
|
@@ -61,7 +62,7 @@ class ExecuteScheduledActionUseCaseImpl {
|
|
|
61
62
|
return Result.ok();
|
|
62
63
|
} catch (error) {
|
|
63
64
|
const executionError = new ExecutionFailedError(`Failed to execute scheduled action: ${error.message}`, error);
|
|
64
|
-
const updateResult = await this.updateEntryUseCase.execute(
|
|
65
|
+
const updateResult = await this.updateEntryUseCase.execute(model, scheduleId, {
|
|
65
66
|
values: {
|
|
66
67
|
error: executionError.message
|
|
67
68
|
}
|
|
@@ -81,7 +82,7 @@ const ExecuteScheduledActionUseCase_ExecuteScheduledActionUseCase = ExecuteSched
|
|
|
81
82
|
ScheduledActionHandler,
|
|
82
83
|
DeleteEntryUseCase,
|
|
83
84
|
UpdateEntryUseCase,
|
|
84
|
-
|
|
85
|
+
ScheduledActionModelProvider,
|
|
85
86
|
IdentityContext
|
|
86
87
|
]
|
|
87
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js","sources":["../../../src/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ExecuteScheduledActionUseCase as UseCaseAbstraction,\n ExecutionFailedError,\n HandlerNotFoundError\n} from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport {\n type IScheduledAction,\n ScheduledActionHandler,\n
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js","sources":["../../../src/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ExecuteScheduledActionUseCase as UseCaseAbstraction,\n ExecutionFailedError,\n HandlerNotFoundError\n} from \"./abstractions.js\";\nimport { GetScheduledActionUseCase } from \"~/features/GetScheduledAction/abstractions.js\";\nimport {\n type IScheduledAction,\n ScheduledActionHandler,\n ScheduledActionModelProvider\n} from \"~/shared/abstractions.js\";\nimport { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext\n} from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\n/**\n * Executes a scheduled action\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 (for debugging/audit)\n */\nclass ExecuteScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getScheduledActionUseCase: GetScheduledActionUseCase.Interface,\n private actionHandler: ScheduledActionHandler.Interface,\n private deleteEntryUseCase: DeleteEntryUseCase.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private modelProvider: ScheduledActionModelProvider.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n public async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n return this.identityContext.withoutAuthorization(async () => {\n return this.executeAction<T>(params);\n });\n }\n\n private async executeAction<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n const { id } = params;\n const model = await this.modelProvider.get();\n // Load scheduled action\n const getResult = await this.getScheduledActionUseCase.execute<T>(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 const scheduledAction = getResult.value;\n\n /**\n * When executing the scheduled action, we need a user which has access to perform the action.\n * We will set a user which created the scheduled action as the execution user.\n */\n const scheduledBy = scheduledAction.scheduledBy;\n this.identityContext.setIdentity(\n new AuthenticatedIdentity({\n id: scheduledBy.id,\n type: scheduledBy.type,\n displayName: scheduledBy.displayName ?? \"\",\n context: {\n canAccessTenant: true\n }\n })\n );\n\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n\n // Check if the handler can handle this action\n if (!this.actionHandler.canHandle(scheduledAction.namespace, scheduledAction.actionType)) {\n const error = new HandlerNotFoundError(\n scheduledAction.namespace,\n scheduledAction.actionType\n );\n\n // Update entry with error for debugging\n const updateResult = await this.updateEntryUseCase.execute<IScheduledAction<T>>(\n model,\n scheduleId,\n {\n values: {\n error: error.message\n }\n }\n );\n if (updateResult.isFail()) {\n return Result.fail({\n ...updateResult.error,\n message: `Failed to update error to a scheduled action (${scheduleId}): ${updateResult.error.message}`\n } as unknown as UseCaseAbstraction.Error);\n }\n\n return Result.fail(error);\n }\n\n // Execute handler\n try {\n await this.actionHandler.handle(scheduledAction);\n\n // Delete schedule entry on success\n const deleteResult = await this.deleteEntryUseCase.execute(model, scheduleId, {\n force: true,\n permanently: true\n });\n\n if (deleteResult.isFail()) {\n return Result.fail(\n new ScheduledActionPersistenceError(new Error(deleteResult.error.message))\n );\n }\n\n return Result.ok();\n } catch (error) {\n const executionError = new ExecutionFailedError(\n `Failed to execute scheduled action: ${(error as Error).message}`,\n error as Error\n );\n\n // Update entry with error for debugging\n const updateResult = await this.updateEntryUseCase.execute<IScheduledAction<T>>(\n model,\n scheduleId,\n {\n values: {\n error: executionError.message\n }\n }\n );\n if (updateResult.isFail()) {\n return Result.fail({\n ...updateResult.error,\n message: `Failed to update error to a scheduled action: ${updateResult.error.message}`\n } as unknown as UseCaseAbstraction.Error);\n }\n\n return Result.fail(executionError);\n }\n }\n}\n\nexport const ExecuteScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: ExecuteScheduledActionUseCaseImpl,\n dependencies: [\n GetScheduledActionUseCase,\n ScheduledActionHandler,\n DeleteEntryUseCase,\n UpdateEntryUseCase,\n ScheduledActionModelProvider,\n IdentityContext\n ]\n});\n"],"names":["ExecuteScheduledActionUseCaseImpl","getScheduledActionUseCase","actionHandler","deleteEntryUseCase","updateEntryUseCase","modelProvider","identityContext","params","id","model","getResult","error","Result","ScheduledActionNotFoundError","scheduledAction","scheduledBy","AuthenticatedIdentity","scheduleId","ScheduledActionIdWithVersion","HandlerNotFoundError","updateResult","deleteResult","ScheduledActionPersistenceError","Error","executionError","ExecutionFailedError","ExecuteScheduledActionUseCase","UseCaseAbstraction","GetScheduledActionUseCase","ScheduledActionHandler","DeleteEntryUseCase","UpdateEntryUseCase","ScheduledActionModelProvider","IdentityContext"],"mappings":";;;;;;;;;AAgCA,MAAMA;IACF,YACYC,yBAA8D,EAC9DC,aAA+C,EAC/CC,kBAAgD,EAChDC,kBAAgD,EAChDC,aAAqD,EACrDC,eAA0C,CACpD;aANUL,yBAAyB,GAAzBA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAa,QACTC,MAAiC,EACc;QAC/C,OAAO,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,UACtC,IAAI,CAAC,aAAa,CAAIA;IAErC;IAEA,MAAc,cACVA,MAAiC,EACc;QAC/C,MAAM,EAAEC,EAAE,EAAE,GAAGD;QACf,MAAME,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG;QAE1C,MAAMC,YAAY,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAIH;QAElE,IAAIG,UAAU,MAAM,IAAI;YACpB,MAAMC,QAAQD,UAAU,KAAK;YAE7B,IAAIC,AAAe,yCAAfA,MAAM,IAAI,EACV,OAAOC,OAAO,IAAI,CAAC,IAAIC,6BAA6BL;YAGxD,OAAOI,OAAO,IAAI,CAACD;QACvB;QACA,MAAMG,kBAAkBJ,UAAU,KAAK;QAMvC,MAAMK,cAAcD,gBAAgB,WAAW;QAC/C,IAAI,CAAC,eAAe,CAAC,WAAW,CAC5B,IAAIE,sBAAsB;YACtB,IAAID,YAAY,EAAE;YAClB,MAAMA,YAAY,IAAI;YACtB,aAAaA,YAAY,WAAW,IAAI;YACxC,SAAS;gBACL,iBAAiB;YACrB;QACJ;QAGJ,MAAME,aAAaC,6BAA6B,IAAI,CAACV;QAGrD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAACM,gBAAgB,SAAS,EAAEA,gBAAgB,UAAU,GAAG;YACtF,MAAMH,QAAQ,IAAIQ,qBACdL,gBAAgB,SAAS,EACzBA,gBAAgB,UAAU;YAI9B,MAAMM,eAAe,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CACtDX,OACAQ,YACA;gBACI,QAAQ;oBACJ,OAAON,MAAM,OAAO;gBACxB;YACJ;YAEJ,IAAIS,aAAa,MAAM,IACnB,OAAOR,OAAO,IAAI,CAAC;gBACf,GAAGQ,aAAa,KAAK;gBACrB,SAAS,CAAC,8CAA8C,EAAEH,WAAW,GAAG,EAAEG,aAAa,KAAK,CAAC,OAAO,EAAE;YAC1G;YAGJ,OAAOR,OAAO,IAAI,CAACD;QACvB;QAGA,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAACG;YAGhC,MAAMO,eAAe,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACZ,OAAOQ,YAAY;gBAC1E,OAAO;gBACP,aAAa;YACjB;YAEA,IAAII,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CACd,IAAIU,gCAAgC,IAAIC,MAAMF,aAAa,KAAK,CAAC,OAAO;YAIhF,OAAOT,OAAO,EAAE;QACpB,EAAE,OAAOD,OAAO;YACZ,MAAMa,iBAAiB,IAAIC,qBACvB,CAAC,oCAAoC,EAAGd,MAAgB,OAAO,EAAE,EACjEA;YAIJ,MAAMS,eAAe,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CACtDX,OACAQ,YACA;gBACI,QAAQ;oBACJ,OAAOO,eAAe,OAAO;gBACjC;YACJ;YAEJ,IAAIJ,aAAa,MAAM,IACnB,OAAOR,OAAO,IAAI,CAAC;gBACf,GAAGQ,aAAa,KAAK;gBACrB,SAAS,CAAC,8CAA8C,EAAEA,aAAa,KAAK,CAAC,OAAO,EAAE;YAC1F;YAGJ,OAAOR,OAAO,IAAI,CAACY;QACvB;IACJ;AACJ;AAEO,MAAME,8DAAgCC,8BAAAA,oBAAuC,CAAC;IACjF,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -3,7 +3,7 @@ import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersis
|
|
|
3
3
|
/**
|
|
4
4
|
* ExecuteScheduledActionUseCase - Execute a scheduled action
|
|
5
5
|
*
|
|
6
|
-
* This is triggered by
|
|
6
|
+
* This is triggered by the scheduler when a schedule fires.
|
|
7
7
|
* Finds the appropriate handler based on namespace + actionType and executes it.
|
|
8
8
|
*
|
|
9
9
|
* Flow:
|
|
@@ -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
|
|
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 the scheduler 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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ExecuteScheduledAction Feature
|
|
3
3
|
*
|
|
4
|
-
* Provides the ability to execute a scheduled action when
|
|
4
|
+
* Provides the ability to execute a scheduled action when the scheduler fires.
|
|
5
5
|
* Finds the appropriate handler and executes it, then cleans up the schedule entry.
|
|
6
6
|
*/
|
|
7
7
|
export declare const ExecuteScheduledActionFeature: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ExecuteScheduledAction/feature.js","sources":["../../../src/features/ExecuteScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ExecuteScheduledActionUseCase } from \"./ExecuteScheduledActionUseCase.js\";\nimport { ScheduledActionHandlerComposite } from \"~/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js\";\n\n/**\n * ExecuteScheduledAction Feature\n *\n * Provides the ability to execute a scheduled action when
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/feature.js","sources":["../../../src/features/ExecuteScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ExecuteScheduledActionUseCase } from \"./ExecuteScheduledActionUseCase.js\";\nimport { ScheduledActionHandlerComposite } from \"~/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js\";\n\n/**\n * ExecuteScheduledAction Feature\n *\n * Provides the ability to execute a scheduled action when the scheduler fires.\n * Finds the appropriate handler and executes it, then cleans up the schedule entry.\n */\nexport const ExecuteScheduledActionFeature = createFeature({\n name: \"ExecuteScheduledAction\",\n register(container) {\n container.register(ExecuteScheduledActionUseCase);\n container.registerComposite(ScheduledActionHandlerComposite);\n }\n});\n"],"names":["ExecuteScheduledActionFeature","createFeature","container","ExecuteScheduledActionUseCase","ScheduledActionHandlerComposite"],"mappings":";;;AAUO,MAAMA,gCAAgCC,cAAc;IACvD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,iBAAiB,CAACE;IAChC;AACJ"}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
6
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
7
7
|
import { SchedulerPermissionsResolver } from "../../features/permissions/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves a scheduled action by its ID
|
|
11
|
+
*
|
|
12
|
+
* Flow:
|
|
13
|
+
* 1. Fetch schedule entry from CMS storage by ID
|
|
14
|
+
* 2. Return null if not found
|
|
15
|
+
* 3. Transform CMS entry to IScheduledAction format
|
|
16
|
+
*/
|
|
9
17
|
declare class GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
10
18
|
private getEntryByIdUseCase;
|
|
11
|
-
private
|
|
19
|
+
private modelProvider;
|
|
12
20
|
private permissionsResolver;
|
|
13
21
|
private identityContext;
|
|
14
|
-
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface,
|
|
22
|
+
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, permissionsResolver: SchedulerPermissionsResolver.Interface, identityContext: IdentityContext.Interface);
|
|
15
23
|
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
|
|
16
24
|
}
|
|
17
25
|
export declare const GetScheduledActionUseCase: typeof GetScheduledActionUseCaseImpl & {
|