@webiny/api-scheduler 0.0.0-unstable.ac6ebf63c6 → 0.0.0-unstable.b6d7105cee
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/constants.d.ts +5 -0
- package/constants.js +11 -8
- package/constants.js.map +1 -1
- package/context.d.ts +2 -6
- package/context.js +29 -31
- package/context.js.map +1 -1
- package/domain/SchedulePrivateModel.js +25 -22
- package/domain/SchedulePrivateModel.js.map +1 -1
- package/domain/ScheduledActionId.js +12 -4
- package/domain/ScheduledActionId.js.map +1 -1
- package/domain/ScheduledActionIdWithVersion.js +5 -6
- package/domain/ScheduledActionIdWithVersion.js.map +1 -1
- package/domain/ScheduledActionMapper.d.ts +16 -0
- package/domain/ScheduledActionMapper.js +37 -0
- package/domain/ScheduledActionMapper.js.map +1 -0
- package/domain/errors.d.ts +19 -1
- package/domain/errors.js +54 -56
- package/domain/errors.js.map +1 -1
- package/domain/isValidDate.d.ts +1 -1
- package/domain/isValidDate.js +4 -9
- package/domain/isValidDate.js.map +1 -1
- package/domain/permissionsSchema.d.ts +9 -0
- package/domain/permissionsSchema.js +18 -0
- package/domain/permissionsSchema.js.map +1 -0
- package/exports/api/scheduler.d.ts +10 -0
- package/exports/api/scheduler.js +8 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +4 -2
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +45 -61
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +10 -2
- package/features/CancelScheduledAction/abstractions.js +2 -10
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/CancelScheduledAction/feature.d.ts +4 -1
- package/features/CancelScheduledAction/feature.js +6 -12
- package/features/CancelScheduledAction/feature.js.map +1 -1
- package/features/CancelScheduledAction/index.js +0 -2
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +1 -1
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +65 -89
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +2 -2
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js +21 -25
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +10 -2
- package/features/ExecuteScheduledAction/abstractions.js +12 -36
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/feature.d.ts +4 -1
- package/features/ExecuteScheduledAction/feature.js +7 -13
- package/features/ExecuteScheduledAction/feature.js.map +1 -1
- package/features/ExecuteScheduledAction/index.js +0 -2
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +6 -2
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +38 -39
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetScheduledAction/abstractions.d.ts +9 -2
- package/features/GetScheduledAction/abstractions.js +2 -11
- package/features/GetScheduledAction/abstractions.js.map +1 -1
- package/features/GetScheduledAction/feature.d.ts +4 -1
- package/features/GetScheduledAction/feature.js +6 -12
- package/features/GetScheduledAction/feature.js.map +1 -1
- package/features/GetScheduledAction/index.js +0 -2
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +32 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +64 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -0
- package/features/GetTargetScheduledAction/abstractions.d.ts +24 -0
- package/features/GetTargetScheduledAction/abstractions.js +5 -0
- package/features/GetTargetScheduledAction/abstractions.js.map +1 -0
- package/features/GetTargetScheduledAction/feature.d.ts +10 -0
- package/features/GetTargetScheduledAction/feature.js +11 -0
- package/features/GetTargetScheduledAction/feature.js.map +1 -0
- package/features/{RunAction → GetTargetScheduledAction}/index.js +0 -2
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -1
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +53 -67
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- package/features/ListScheduledActions/abstractions.d.ts +11 -3
- package/features/ListScheduledActions/abstractions.js +2 -12
- package/features/ListScheduledActions/abstractions.js.map +1 -1
- package/features/ListScheduledActions/feature.d.ts +4 -1
- package/features/ListScheduledActions/feature.js +6 -12
- package/features/ListScheduledActions/feature.js.map +1 -1
- package/features/ListScheduledActions/index.js +0 -2
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.d.ts +11 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.js +26 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.js.map +1 -0
- package/features/NamespaceHandler/abstractions.d.ts +50 -0
- package/features/NamespaceHandler/abstractions.js +6 -0
- package/features/NamespaceHandler/abstractions.js.map +1 -0
- package/features/NamespaceHandler/feature.d.ts +4 -0
- package/features/NamespaceHandler/feature.js +11 -0
- package/features/NamespaceHandler/feature.js.map +1 -0
- package/features/NamespaceHandler/index.d.ts +1 -0
- package/features/NamespaceHandler/index.js +1 -0
- package/features/ScheduleAction/ScheduleActionUseCase.d.ts +4 -4
- package/features/ScheduleAction/ScheduleActionUseCase.js +150 -143
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduleAction/abstractions.d.ts +12 -11
- package/features/ScheduleAction/abstractions.js +2 -10
- package/features/ScheduleAction/abstractions.js.map +1 -1
- package/features/ScheduleAction/feature.d.ts +4 -1
- package/features/ScheduleAction/feature.js +6 -12
- package/features/ScheduleAction/feature.js.map +1 -1
- package/features/ScheduleAction/index.js +0 -2
- package/features/SchedulerFeature.d.ts +4 -1
- package/features/SchedulerFeature.js +12 -20
- package/features/SchedulerFeature.js.map +1 -1
- package/features/SchedulerService/VoidSchedulerService.d.ts +9 -9
- package/features/SchedulerService/VoidSchedulerService.js +17 -24
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
- package/features/permissions/abstractions.d.ts +14 -0
- package/features/permissions/abstractions.js +6 -0
- package/features/permissions/abstractions.js.map +1 -0
- package/features/permissions/feature.d.ts +4 -0
- package/features/permissions/feature.js +7 -0
- package/features/permissions/feature.js.map +1 -0
- package/graphql/SchedulerGraphQLFactory.d.ts +8 -0
- package/graphql/SchedulerGraphQLFactory.js +219 -0
- package/graphql/SchedulerGraphQLFactory.js.map +1 -0
- package/graphql/feature.d.ts +4 -0
- package/graphql/feature.js +11 -0
- package/graphql/feature.js.map +1 -0
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +1 -0
- package/index.d.ts +1 -7
- package/index.js +2 -12
- package/package.json +21 -33
- package/shared/abstractions.d.ts +38 -8
- package/shared/abstractions.js +4 -29
- package/shared/abstractions.js.map +1 -1
- package/createEventHandler.d.ts +0 -13
- package/createEventHandler.js +0 -50
- package/createEventHandler.js.map +0 -1
- package/createScheduler.d.ts +0 -6
- package/createScheduler.js +0 -11
- package/createScheduler.js.map +0 -1
- package/features/CancelScheduledAction/index.js.map +0 -1
- package/features/ExecuteScheduledAction/index.js.map +0 -1
- package/features/GetScheduledAction/index.js.map +0 -1
- package/features/ListScheduledActions/index.js.map +0 -1
- package/features/RunAction/RunActionUseCase.d.ts +0 -23
- package/features/RunAction/RunActionUseCase.js +0 -37
- package/features/RunAction/RunActionUseCase.js.map +0 -1
- package/features/RunAction/abstractions.d.ts +0 -35
- package/features/RunAction/abstractions.js +0 -15
- package/features/RunAction/abstractions.js.map +0 -1
- package/features/RunAction/feature.d.ts +0 -7
- package/features/RunAction/feature.js +0 -17
- package/features/RunAction/feature.js.map +0 -1
- package/features/RunAction/index.js.map +0 -1
- package/features/ScheduleAction/index.js.map +0 -1
- package/features/SchedulerService/EventBridgeSchedulerService.d.ts +0 -26
- package/features/SchedulerService/EventBridgeSchedulerService.js +0 -131
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +0 -1
- package/index.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -39
- package/manifest.js.map +0 -1
- /package/features/{RunAction → GetTargetScheduledAction}/index.d.ts +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ScheduleActionUseCase } from "../../features/ScheduleAction/index.js";
|
|
2
|
+
export type { ScheduleActionError } from "../../features/ScheduleAction/index.js";
|
|
3
|
+
export { GetScheduledActionUseCase } from "../../features/GetScheduledAction/index.js";
|
|
4
|
+
export { ListScheduledActionsUseCase } from "../../features/ListScheduledActions/index.js";
|
|
5
|
+
export { CancelScheduledActionUseCase } from "../../features/CancelScheduledAction/index.js";
|
|
6
|
+
export { ExecuteScheduledActionUseCase } from "../../features/ExecuteScheduledAction/index.js";
|
|
7
|
+
export { NamespaceHandler } from "../../features/NamespaceHandler/index.js";
|
|
8
|
+
export type { IScheduledAction, IScheduledActionEntry, ScheduledActionType } from "../../shared/abstractions.js";
|
|
9
|
+
export { SchedulerService, ScheduledActionModel, ScheduledActionHandler } from "../../shared/abstractions.js";
|
|
10
|
+
export { SCHEDULED_ACTION_PUBLISH as ScheduledActionTypePublish, SCHEDULED_ACTION_UNPUBLISH as ScheduledActionTypeUnpublish } from "../../constants.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ScheduleActionUseCase } from "../../features/ScheduleAction/index.js";
|
|
2
|
+
export { GetScheduledActionUseCase } from "../../features/GetScheduledAction/index.js";
|
|
3
|
+
export { ListScheduledActionsUseCase } from "../../features/ListScheduledActions/index.js";
|
|
4
|
+
export { CancelScheduledActionUseCase } from "../../features/CancelScheduledAction/index.js";
|
|
5
|
+
export { ExecuteScheduledActionUseCase } from "../../features/ExecuteScheduledAction/index.js";
|
|
6
|
+
export { NamespaceHandler } from "../../features/NamespaceHandler/index.js";
|
|
7
|
+
export { ScheduledActionHandler, ScheduledActionModel, SchedulerService } from "../../shared/abstractions.js";
|
|
8
|
+
export { SCHEDULED_ACTION_PUBLISH as ScheduledActionTypePublish, SCHEDULED_ACTION_UNPUBLISH as ScheduledActionTypeUnpublish } from "../../constants.js";
|
|
@@ -3,6 +3,7 @@ import { CancelScheduledActionUseCase as UseCaseAbstraction } from "./abstractio
|
|
|
3
3
|
import { GetScheduledActionUseCase } from "../../features/GetScheduledAction/abstractions.js";
|
|
4
4
|
import { ScheduledActionModel, SchedulerService } from "../../shared/abstractions.js";
|
|
5
5
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry/index.js";
|
|
6
|
+
import { SchedulerPermissions } from "../../features/permissions/abstractions.js";
|
|
6
7
|
/**
|
|
7
8
|
* Cancels a scheduled action
|
|
8
9
|
*
|
|
@@ -17,8 +18,9 @@ declare class CancelScheduledActionUseCaseImpl implements UseCaseAbstraction.Int
|
|
|
17
18
|
private schedulerService;
|
|
18
19
|
private deleteEntryUseCase;
|
|
19
20
|
private model;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
private permissions;
|
|
22
|
+
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, schedulerService: SchedulerService.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, model: ScheduledActionModel.Interface, permissions: SchedulerPermissions.Interface);
|
|
23
|
+
execute(params: UseCaseAbstraction.Params): Promise<Result<boolean, UseCaseAbstraction.Error>>;
|
|
22
24
|
}
|
|
23
25
|
export declare const CancelScheduledActionUseCase: typeof CancelScheduledActionUseCaseImpl & {
|
|
24
26
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICancelScheduledActionUseCase>;
|
|
@@ -1,74 +1,58 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { CancelScheduledActionUseCase
|
|
2
|
+
import { CancelScheduledActionUseCase } from "./abstractions.js";
|
|
3
3
|
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
4
4
|
import { ScheduledActionModel, SchedulerService } from "../../shared/abstractions.js";
|
|
5
|
-
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
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
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Cancels a scheduled action
|
|
12
|
-
*
|
|
13
|
-
* Flow:
|
|
14
|
-
* 1. Check if schedule exists
|
|
15
|
-
* 2. Delete EventBridge schedule
|
|
16
|
-
* 3. Delete CMS entry
|
|
17
|
-
* 4. If EventBridge delete fails, continue anyway (schedule might already be executed/deleted)
|
|
18
|
-
*/
|
|
9
|
+
import { SchedulerPermissions } from "../permissions/abstractions.js";
|
|
19
10
|
class CancelScheduledActionUseCaseImpl {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
async execute(id) {
|
|
27
|
-
// Check if scheduled action exists
|
|
28
|
-
const getResult = await this.getScheduledActionUseCase.execute(id);
|
|
29
|
-
if (getResult.isFail()) {
|
|
30
|
-
const error = getResult.error;
|
|
31
|
-
if (error.code === "Scheduler/ScheduledAction/NotFound") {
|
|
32
|
-
return Result.fail(new ScheduledActionNotFoundError(id));
|
|
33
|
-
}
|
|
34
|
-
return Result.fail(error);
|
|
35
|
-
}
|
|
36
|
-
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
37
|
-
|
|
38
|
-
// Delete EventBridge schedule
|
|
39
|
-
// Note: We continue even if this fails, as the schedule might already be executed/deleted
|
|
40
|
-
try {
|
|
41
|
-
const eventBridgeSchedule = await this.schedulerService.exists(id);
|
|
42
|
-
/**
|
|
43
|
-
* No point to even try deleting if it doesn't exist.
|
|
44
|
-
*/
|
|
45
|
-
if (eventBridgeSchedule) {
|
|
46
|
-
await this.schedulerService.delete(id);
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.warn(`Failed to delete EventBridge schedule: ${scheduleId}. Continuing with CMS entry deletion.`, error);
|
|
11
|
+
constructor(getScheduledActionUseCase, schedulerService, deleteEntryUseCase, model, permissions){
|
|
12
|
+
this.getScheduledActionUseCase = getScheduledActionUseCase;
|
|
13
|
+
this.schedulerService = schedulerService;
|
|
14
|
+
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
15
|
+
this.model = model;
|
|
16
|
+
this.permissions = permissions;
|
|
50
17
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
18
|
+
async execute(params) {
|
|
19
|
+
const hasPermission = await this.permissions.canRead("action");
|
|
20
|
+
if (!hasPermission) return Result.fail(new NotAuthorizedError());
|
|
21
|
+
const { id } = params;
|
|
22
|
+
const getResult = await this.getScheduledActionUseCase.execute(params);
|
|
23
|
+
if (getResult.isFail()) {
|
|
24
|
+
const error = getResult.error;
|
|
25
|
+
if ("Scheduler/ScheduledAction/NotFound" === error.code) return Result.fail(new ScheduledActionNotFoundError(id));
|
|
26
|
+
return Result.fail(error);
|
|
27
|
+
}
|
|
28
|
+
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
29
|
+
try {
|
|
30
|
+
const eventBridgeSchedule = await this.schedulerService.exists(params);
|
|
31
|
+
if (eventBridgeSchedule) await this.schedulerService.delete(params);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.warn(`Failed to delete EventBridge schedule: ${scheduleId}, tenant "${params.tenant}". Continuing with CMS entry deletion.`, error);
|
|
34
|
+
}
|
|
35
|
+
const deleteResult = await this.deleteEntryUseCase.execute(this.model, getResult.value.id, {
|
|
36
|
+
force: true,
|
|
37
|
+
permanently: true
|
|
38
|
+
});
|
|
39
|
+
if (deleteResult.isFail()) {
|
|
40
|
+
if (deleteResult.error instanceof EntryNotFoundError) return Result.ok(true);
|
|
41
|
+
return Result.fail(new ScheduledActionPersistenceError(new Error(deleteResult.error.message)));
|
|
42
|
+
}
|
|
43
|
+
return Result.ok(true);
|
|
65
44
|
}
|
|
66
|
-
return Result.ok();
|
|
67
|
-
}
|
|
68
45
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
46
|
+
const CancelScheduledActionUseCase_CancelScheduledActionUseCase = CancelScheduledActionUseCase.createImplementation({
|
|
47
|
+
implementation: CancelScheduledActionUseCaseImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
GetScheduledActionUseCase,
|
|
50
|
+
SchedulerService,
|
|
51
|
+
DeleteEntryUseCase,
|
|
52
|
+
ScheduledActionModel,
|
|
53
|
+
SchedulerPermissions
|
|
54
|
+
]
|
|
72
55
|
});
|
|
56
|
+
export { CancelScheduledActionUseCase_CancelScheduledActionUseCase as CancelScheduledActionUseCase };
|
|
73
57
|
|
|
74
58
|
//# sourceMappingURL=CancelScheduledActionUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACrD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAE3B,MAAM,EAAEC,EAAE,EAAE,GAAGJ;QAEf,MAAMK,YAAY,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAACL;QAE/D,IAAIK,UAAU,MAAM,IAAI;YACpB,MAAMC,QAAQD,UAAU,KAAK;YAE7B,IAAIC,AAAe,yCAAfA,MAAM,IAAI,EACV,OAAOJ,OAAO,IAAI,CAAC,IAAIK,6BAA6BH;YAGxD,OAAOF,OAAO,IAAI,CAACI;QACvB;QAEA,MAAME,aAAaC,6BAA6B,IAAI,CAACL;QAIrD,IAAI;YACA,MAAMM,sBAAsB,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACV;YAI/D,IAAIU,qBACA,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACV;QAE3C,EAAE,OAAOM,OAAO;YACZK,QAAQ,IAAI,CACR,CAAC,uCAAuC,EAAEH,WAAW,UAAU,EAAER,OAAO,MAAM,CAAC,sCAAsC,CAAC,EACtHM;QAER;QAGA,MAAMM,eAAe,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAEP,UAAU,KAAK,CAAC,EAAE,EAAE;YACvF,OAAO;YACP,aAAa;QACjB;QAEA,IAAIO,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,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError, SchedulerServiceError } from "../../domain/errors.js";
|
|
2
|
+
import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError, SchedulerServiceError } from "../../domain/errors.js";
|
|
3
3
|
/**
|
|
4
4
|
* CancelScheduledActionUseCase - Cancel a scheduled action
|
|
5
5
|
*
|
|
@@ -11,14 +11,22 @@ export interface ICancelScheduledActionErrors {
|
|
|
11
11
|
notFound: ScheduledActionNotFoundError;
|
|
12
12
|
persistence: ScheduledActionPersistenceError;
|
|
13
13
|
schedulerService: SchedulerServiceError;
|
|
14
|
+
unauthorized: NotAuthorizedError;
|
|
14
15
|
}
|
|
15
16
|
type CancelScheduledActionError = ICancelScheduledActionErrors[keyof ICancelScheduledActionErrors];
|
|
17
|
+
export interface ICancelScheduledActionUseCaseParams {
|
|
18
|
+
namespace: string;
|
|
19
|
+
id: string;
|
|
20
|
+
tenant: string;
|
|
21
|
+
}
|
|
16
22
|
export interface ICancelScheduledActionUseCase {
|
|
17
|
-
execute(
|
|
23
|
+
execute(params: ICancelScheduledActionUseCaseParams): Promise<Result<boolean, CancelScheduledActionError>>;
|
|
18
24
|
}
|
|
25
|
+
/** Cancel a scheduled action. */
|
|
19
26
|
export declare const CancelScheduledActionUseCase: import("@webiny/di").Abstraction<ICancelScheduledActionUseCase>;
|
|
20
27
|
export declare namespace CancelScheduledActionUseCase {
|
|
21
28
|
type Interface = ICancelScheduledActionUseCase;
|
|
22
29
|
type Error = CancelScheduledActionError;
|
|
30
|
+
type Params = ICancelScheduledActionUseCaseParams;
|
|
23
31
|
}
|
|
24
32
|
export {};
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* CancelScheduledActionUseCase - Cancel a scheduled action
|
|
5
|
-
*
|
|
6
|
-
* Cancels both the CMS entry and the EventBridge schedule.
|
|
7
|
-
* Used when a user manually cancels a scheduled action or when business logic
|
|
8
|
-
* determines the action should no longer execute.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const CancelScheduledActionUseCase = createAbstraction("CancelScheduledActionUseCase");
|
|
2
|
+
const CancelScheduledActionUseCase = createAbstraction("Scheduler/CancelScheduledActionUseCase");
|
|
3
|
+
export { CancelScheduledActionUseCase };
|
|
12
4
|
|
|
13
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -4,4 +4,7 @@
|
|
|
4
4
|
* Provides the ability to cancel a scheduled action.
|
|
5
5
|
* Removes both the EventBridge schedule and the CMS entry.
|
|
6
6
|
*/
|
|
7
|
-
export declare const CancelScheduledActionFeature:
|
|
7
|
+
export declare const CancelScheduledActionFeature: {
|
|
8
|
+
name: string;
|
|
9
|
+
register(container: import("@webiny/di").Container): void;
|
|
10
|
+
};
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { CancelScheduledActionUseCase } from "./CancelScheduledActionUseCase.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Removes both the EventBridge schedule and the CMS entry.
|
|
9
|
-
*/
|
|
10
|
-
export const CancelScheduledActionFeature = createFeature({
|
|
11
|
-
name: "CancelScheduledAction",
|
|
12
|
-
register(container) {
|
|
13
|
-
container.register(CancelScheduledActionUseCase);
|
|
14
|
-
}
|
|
3
|
+
const CancelScheduledActionFeature = createFeature({
|
|
4
|
+
name: "CancelScheduledAction",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CancelScheduledActionUseCase);
|
|
7
|
+
}
|
|
15
8
|
});
|
|
9
|
+
export { CancelScheduledActionFeature };
|
|
16
10
|
|
|
17
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 EventBridge schedule 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"}
|
|
@@ -24,7 +24,7 @@ declare class ExecuteScheduledActionUseCaseImpl implements UseCaseAbstraction.In
|
|
|
24
24
|
private model;
|
|
25
25
|
private identityContext;
|
|
26
26
|
constructor(getScheduledActionUseCase: GetScheduledActionUseCase.Interface, actionHandler: ScheduledActionHandler.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, model: ScheduledActionModel.Interface, identityContext: IdentityContext.Interface);
|
|
27
|
-
execute<T extends GenericRecord>(
|
|
27
|
+
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<void, UseCaseAbstraction.Error>>;
|
|
28
28
|
private executeAction;
|
|
29
29
|
}
|
|
30
30
|
export declare const ExecuteScheduledActionUseCase: typeof ExecuteScheduledActionUseCaseImpl & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { ExecuteScheduledActionUseCase
|
|
2
|
+
import { ExecuteScheduledActionUseCase, ExecutionFailedError, HandlerNotFoundError } from "./abstractions.js";
|
|
3
3
|
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
4
4
|
import { ScheduledActionHandler, ScheduledActionModel } from "../../shared/abstractions.js";
|
|
5
5
|
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
@@ -7,100 +7,76 @@ import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEnt
|
|
|
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
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Executes a scheduled action
|
|
13
|
-
*
|
|
14
|
-
* Flow:
|
|
15
|
-
* 1. Load scheduled action from CMS
|
|
16
|
-
* 2. Find registered handler for namespace + actionType
|
|
17
|
-
* 3. Execute handler
|
|
18
|
-
* 4. Delete schedule entry on success
|
|
19
|
-
* 5. Update entry with error on failure (for debugging/audit)
|
|
20
|
-
*/
|
|
21
10
|
class ExecuteScheduledActionUseCaseImpl {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
async execute(id) {
|
|
31
|
-
// return this.identityContext.withoutAuthorization(async () => {
|
|
32
|
-
return this.executeAction(id);
|
|
33
|
-
// });
|
|
34
|
-
}
|
|
35
|
-
async executeAction(id) {
|
|
36
|
-
// Load scheduled action
|
|
37
|
-
const getResult = await this.getScheduledActionUseCase.execute(id);
|
|
38
|
-
if (getResult.isFail()) {
|
|
39
|
-
const error = getResult.error;
|
|
40
|
-
if (error.code === "Scheduler/ScheduledAction/NotFound") {
|
|
41
|
-
return Result.fail(new ScheduledActionNotFoundError(id));
|
|
42
|
-
}
|
|
43
|
-
return Result.fail(error);
|
|
11
|
+
constructor(getScheduledActionUseCase, actionHandler, deleteEntryUseCase, updateEntryUseCase, model, identityContext){
|
|
12
|
+
this.getScheduledActionUseCase = getScheduledActionUseCase;
|
|
13
|
+
this.actionHandler = actionHandler;
|
|
14
|
+
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
15
|
+
this.updateEntryUseCase = updateEntryUseCase;
|
|
16
|
+
this.model = model;
|
|
17
|
+
this.identityContext = identityContext;
|
|
44
18
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* When executing the scheduled action, we need a user which has access to perform the action.
|
|
49
|
-
* We will set a user which created the scheduled action as the execution user.
|
|
50
|
-
*/
|
|
51
|
-
const scheduledBy = scheduledAction.scheduledBy;
|
|
52
|
-
this.identityContext.setIdentity(new AuthenticatedIdentity({
|
|
53
|
-
id: scheduledBy.id,
|
|
54
|
-
type: scheduledBy.type,
|
|
55
|
-
displayName: scheduledBy.displayName ?? "",
|
|
56
|
-
context: {
|
|
57
|
-
canAccessTenant: true
|
|
58
|
-
}
|
|
59
|
-
}));
|
|
60
|
-
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
61
|
-
|
|
62
|
-
// Check if the handler can handle this action
|
|
63
|
-
if (!this.actionHandler.canHandle(scheduledAction.namespace, scheduledAction.actionType)) {
|
|
64
|
-
const error = new HandlerNotFoundError(scheduledAction.namespace, scheduledAction.actionType);
|
|
65
|
-
|
|
66
|
-
// Update entry with error for debugging
|
|
67
|
-
await this.updateEntryUseCase.execute(this.model, scheduleId, {
|
|
68
|
-
values: {
|
|
69
|
-
error: error.message
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return Result.fail(error);
|
|
19
|
+
async execute(params) {
|
|
20
|
+
return this.identityContext.withoutAuthorization(async ()=>this.executeAction(params));
|
|
73
21
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
22
|
+
async executeAction(params) {
|
|
23
|
+
const { id } = params;
|
|
24
|
+
const getResult = await this.getScheduledActionUseCase.execute(params);
|
|
25
|
+
if (getResult.isFail()) {
|
|
26
|
+
const error = getResult.error;
|
|
27
|
+
if ("Scheduler/ScheduledAction/NotFound" === error.code) return Result.fail(new ScheduledActionNotFoundError(id));
|
|
28
|
+
return Result.fail(error);
|
|
29
|
+
}
|
|
30
|
+
const scheduledAction = getResult.value;
|
|
31
|
+
const scheduledBy = scheduledAction.scheduledBy;
|
|
32
|
+
this.identityContext.setIdentity(new AuthenticatedIdentity({
|
|
33
|
+
id: scheduledBy.id,
|
|
34
|
+
type: scheduledBy.type,
|
|
35
|
+
displayName: scheduledBy.displayName ?? "",
|
|
36
|
+
context: {
|
|
37
|
+
canAccessTenant: true
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
41
|
+
if (!this.actionHandler.canHandle(scheduledAction.namespace, scheduledAction.actionType)) {
|
|
42
|
+
const error = new HandlerNotFoundError(scheduledAction.namespace, scheduledAction.actionType);
|
|
43
|
+
await this.updateEntryUseCase.execute(this.model, scheduleId, {
|
|
44
|
+
values: {
|
|
45
|
+
error: error.message
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return Result.fail(error);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await this.actionHandler.handle(scheduledAction);
|
|
52
|
+
const deleteResult = await this.deleteEntryUseCase.execute(this.model, scheduleId, {
|
|
53
|
+
force: true,
|
|
54
|
+
permanently: true
|
|
55
|
+
});
|
|
56
|
+
if (deleteResult.isFail()) return Result.fail(new ScheduledActionPersistenceError(new Error(deleteResult.error.message)));
|
|
57
|
+
return Result.ok();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const executionError = new ExecutionFailedError(`Failed to execute scheduled action: ${error.message}`, error);
|
|
60
|
+
await this.updateEntryUseCase.execute(this.model, scheduleId, {
|
|
61
|
+
values: {
|
|
62
|
+
error: executionError.message
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return Result.fail(executionError);
|
|
95
66
|
}
|
|
96
|
-
});
|
|
97
|
-
return Result.fail(executionError);
|
|
98
67
|
}
|
|
99
|
-
}
|
|
100
68
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
69
|
+
const ExecuteScheduledActionUseCase_ExecuteScheduledActionUseCase = ExecuteScheduledActionUseCase.createImplementation({
|
|
70
|
+
implementation: ExecuteScheduledActionUseCaseImpl,
|
|
71
|
+
dependencies: [
|
|
72
|
+
GetScheduledActionUseCase,
|
|
73
|
+
ScheduledActionHandler,
|
|
74
|
+
DeleteEntryUseCase,
|
|
75
|
+
UpdateEntryUseCase,
|
|
76
|
+
ScheduledActionModel,
|
|
77
|
+
IdentityContext
|
|
78
|
+
]
|
|
104
79
|
});
|
|
80
|
+
export { ExecuteScheduledActionUseCase_ExecuteScheduledActionUseCase as ExecuteScheduledActionUseCase };
|
|
105
81
|
|
|
106
82
|
//# sourceMappingURL=ExecuteScheduledActionUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 ScheduledActionModel\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 model: ScheduledActionModel.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 // 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 await this.updateEntryUseCase.execute<IScheduledAction<T>>(this.model, scheduleId, {\n values: {\n error: error.message\n }\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(this.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 await this.updateEntryUseCase.execute<IScheduledAction<T>>(this.model, scheduleId, {\n values: {\n error: executionError.message\n }\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 ScheduledActionModel,\n IdentityContext\n ]\n});\n"],"names":["ExecuteScheduledActionUseCaseImpl","getScheduledActionUseCase","actionHandler","deleteEntryUseCase","updateEntryUseCase","model","identityContext","params","id","getResult","error","Result","ScheduledActionNotFoundError","scheduledAction","scheduledBy","AuthenticatedIdentity","scheduleId","ScheduledActionIdWithVersion","HandlerNotFoundError","deleteResult","ScheduledActionPersistenceError","Error","executionError","ExecutionFailedError","ExecuteScheduledActionUseCase","UseCaseAbstraction","GetScheduledActionUseCase","ScheduledActionHandler","DeleteEntryUseCase","UpdateEntryUseCase","ScheduledActionModel","IdentityContext"],"mappings":";;;;;;;;;AAgCA,MAAMA;IACF,YACYC,yBAA8D,EAC9DC,aAA+C,EAC/CC,kBAAgD,EAChDC,kBAAgD,EAChDC,KAAqC,EACrCC,eAA0C,CACpD;aANUL,yBAAyB,GAAzBA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,KAAK,GAALA;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;QAEf,MAAME,YAAY,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAIF;QAElE,IAAIE,UAAU,MAAM,IAAI;YACpB,MAAMC,QAAQD,UAAU,KAAK;YAE7B,IAAIC,AAAe,yCAAfA,MAAM,IAAI,EACV,OAAOC,OAAO,IAAI,CAAC,IAAIC,6BAA6BJ;YAGxD,OAAOG,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,CAACT;QAGrD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAACK,gBAAgB,SAAS,EAAEA,gBAAgB,UAAU,GAAG;YACtF,MAAMH,QAAQ,IAAIQ,qBACdL,gBAAgB,SAAS,EACzBA,gBAAgB,UAAU;YAI9B,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAsB,IAAI,CAAC,KAAK,EAAEG,YAAY;gBAC/E,QAAQ;oBACJ,OAAON,MAAM,OAAO;gBACxB;YACJ;YAEA,OAAOC,OAAO,IAAI,CAACD;QACvB;QAGA,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAACG;YAGhC,MAAMM,eAAe,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAEH,YAAY;gBAC/E,OAAO;gBACP,aAAa;YACjB;YAEA,IAAIG,aAAa,MAAM,IACnB,OAAOR,OAAO,IAAI,CACd,IAAIS,gCAAgC,IAAIC,MAAMF,aAAa,KAAK,CAAC,OAAO;YAIhF,OAAOR,OAAO,EAAE;QACpB,EAAE,OAAOD,OAAO;YACZ,MAAMY,iBAAiB,IAAIC,qBACvB,CAAC,oCAAoC,EAAGb,MAAgB,OAAO,EAAE,EACjEA;YAIJ,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAsB,IAAI,CAAC,KAAK,EAAEM,YAAY;gBAC/E,QAAQ;oBACJ,OAAOM,eAAe,OAAO;gBACjC;YACJ;YAEA,OAAOX,OAAO,IAAI,CAACW;QACvB;IACJ;AACJ;AAEO,MAAME,8DAAgCC,8BAAAA,oBAAuC,CAAC;IACjF,gBAAgBzB;IAChB,cAAc;QACV0B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IScheduledAction, ScheduledActionHandler } from "../../shared/abstractions.js";
|
|
1
|
+
import { IScheduledAction, ScheduledActionHandler, type ScheduledActionType } from "../../shared/abstractions.js";
|
|
2
2
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Composite handler that iterates through all registered handlers
|
|
@@ -10,7 +10,7 @@ import type { GenericRecord } from "@webiny/api/types.js";
|
|
|
10
10
|
declare class ScheduledActionHandlerCompositeImpl implements ScheduledActionHandler.Interface {
|
|
11
11
|
private handlers;
|
|
12
12
|
constructor(handlers: ScheduledActionHandler.Interface[]);
|
|
13
|
-
canHandle(namespace: string, actionType:
|
|
13
|
+
canHandle(namespace: string, actionType: ScheduledActionType): boolean;
|
|
14
14
|
handle<T extends GenericRecord>(action: IScheduledAction<T>): Promise<void>;
|
|
15
15
|
}
|
|
16
16
|
export declare const ScheduledActionHandlerComposite: typeof ScheduledActionHandlerCompositeImpl & {
|