@webiny/api-scheduler 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9
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 +1 -1
- package/context.js +32 -26
- package/context.js.map +1 -1
- package/createEventHandler.d.ts +1 -0
- package/createEventHandler.js +26 -39
- package/createEventHandler.js.map +1 -1
- package/createScheduler.d.ts +1 -1
- package/createScheduler.js +5 -7
- package/createScheduler.js.map +1 -1
- package/domain/SchedulePrivateModel.js +25 -19
- 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 +36 -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 +9 -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 +9 -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/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 +146 -143
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduleAction/abstractions.d.ts +11 -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/EventBridgeSchedulerService.d.ts +1 -1
- package/features/SchedulerService/EventBridgeSchedulerService.js +86 -120
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -1
- 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/index.d.ts +1 -0
- package/graphql/index.js +1 -0
- package/index.d.ts +0 -6
- package/index.js +1 -11
- package/manifest.js +26 -30
- package/manifest.js.map +1 -1
- package/package.json +30 -32
- package/shared/abstractions.d.ts +19 -6
- package/shared/abstractions.js +4 -29
- package/shared/abstractions.js.map +1 -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/index.js.map +0 -1
- /package/features/{RunAction → GetTargetScheduledAction}/index.d.ts +0 -0
|
@@ -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 & {
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
import { ScheduledActionHandler } from "../../shared/abstractions.js";
|
|
2
|
-
/**
|
|
3
|
-
* Composite handler that iterates through all registered handlers
|
|
4
|
-
* to find one that can handle the given namespace + actionType combination.
|
|
5
|
-
*
|
|
6
|
-
* This is registered as a composite via container.registerComposite(),
|
|
7
|
-
* and the DI container will automatically inject all registered handlers.
|
|
8
|
-
*/
|
|
9
2
|
class ScheduledActionHandlerCompositeImpl {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return;
|
|
3
|
+
constructor(handlers){
|
|
4
|
+
this.handlers = handlers;
|
|
5
|
+
}
|
|
6
|
+
canHandle(namespace, actionType) {
|
|
7
|
+
return this.handlers.some((handler)=>handler.canHandle(namespace, actionType));
|
|
8
|
+
}
|
|
9
|
+
async handle(action) {
|
|
10
|
+
const handler = this.handlers.find((h)=>h.canHandle(action.namespace, action.actionType));
|
|
11
|
+
if (!handler) return void console.log(`No handler found for namespace "${action.namespace}" and actionType "${action.actionType}"`);
|
|
12
|
+
await handler.handle(action);
|
|
21
13
|
}
|
|
22
|
-
await handler.handle(action);
|
|
23
|
-
}
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
const ScheduledActionHandlerComposite = ScheduledActionHandler.createComposite({
|
|
16
|
+
implementation: ScheduledActionHandlerCompositeImpl,
|
|
17
|
+
dependencies: [
|
|
18
|
+
[
|
|
19
|
+
ScheduledActionHandler,
|
|
20
|
+
{
|
|
21
|
+
multiple: true
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
]
|
|
30
25
|
});
|
|
26
|
+
export { ScheduledActionHandlerComposite };
|
|
31
27
|
|
|
32
28
|
//# sourceMappingURL=ScheduledActionHandlerComposite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js","sources":["../../../src/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.ts"],"sourcesContent":["import {\n IScheduledAction,\n ScheduledActionHandler,\n type ScheduledActionType\n} from \"~/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * Composite handler that iterates through all registered handlers\n * to find one that can handle the given namespace + actionType combination.\n *\n * This is registered as a composite via container.registerComposite(),\n * and the DI container will automatically inject all registered handlers.\n */\nclass ScheduledActionHandlerCompositeImpl implements ScheduledActionHandler.Interface {\n public constructor(private handlers: ScheduledActionHandler.Interface[]) {}\n\n public canHandle(namespace: string, actionType: ScheduledActionType): boolean {\n return this.handlers.some(handler => handler.canHandle(namespace, actionType));\n }\n\n public async handle<T extends GenericRecord>(action: IScheduledAction<T>): Promise<void> {\n const handler = this.handlers.find(h => h.canHandle(action.namespace, action.actionType));\n\n if (!handler) {\n console.log(\n `No handler found for namespace \"${action.namespace}\" and actionType \"${action.actionType}\"`\n );\n return;\n }\n\n await handler.handle(action);\n }\n}\n\nexport const ScheduledActionHandlerComposite = ScheduledActionHandler.createComposite({\n implementation: ScheduledActionHandlerCompositeImpl,\n dependencies: [[ScheduledActionHandler, { multiple: true }]]\n});\n"],"names":["ScheduledActionHandlerCompositeImpl","handlers","namespace","actionType","handler","action","h","console","ScheduledActionHandlerComposite","ScheduledActionHandler"],"mappings":";AAcA,MAAMA;IACF,YAA2BC,QAA4C,CAAE;aAA9CA,QAAQ,GAARA;IAA+C;IAEnE,UAAUC,SAAiB,EAAEC,UAA+B,EAAW;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACC,CAAAA,UAAWA,QAAQ,SAAS,CAACF,WAAWC;IACtE;IAEA,MAAa,OAAgCE,MAA2B,EAAiB;QACrF,MAAMD,UAAU,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACE,CAAAA,IAAKA,EAAE,SAAS,CAACD,OAAO,SAAS,EAAEA,OAAO,UAAU;QAEvF,IAAI,CAACD,SAAS,YACVG,QAAQ,GAAG,CACP,CAAC,gCAAgC,EAAEF,OAAO,SAAS,CAAC,kBAAkB,EAAEA,OAAO,UAAU,CAAC,CAAC,CAAC;QAKpG,MAAMD,QAAQ,MAAM,CAACC;IACzB;AACJ;AAEO,MAAMG,kCAAkCC,uBAAuB,eAAe,CAAC;IAClF,gBAAgBT;IAChB,cAAc;QAAC;YAACS;YAAwB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAChE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
2
|
+
import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
3
3
|
/**
|
|
4
4
|
* ExecuteScheduledActionUseCase - Execute a scheduled action
|
|
5
5
|
*
|
|
@@ -18,15 +18,22 @@ export interface IExecuteScheduledActionErrors {
|
|
|
18
18
|
persistence: ScheduledActionPersistenceError;
|
|
19
19
|
handlerNotFound: HandlerNotFoundError;
|
|
20
20
|
executionFailed: ExecutionFailedError;
|
|
21
|
+
unauthorized: NotAuthorizedError;
|
|
21
22
|
}
|
|
22
23
|
type ExecuteScheduledActionError = IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];
|
|
24
|
+
export interface IExecuteScheduledActionUseCaseParams {
|
|
25
|
+
namespace: string;
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
23
28
|
export interface IExecuteScheduledActionUseCase {
|
|
24
|
-
execute(
|
|
29
|
+
execute(params: IExecuteScheduledActionUseCaseParams): Promise<Result<void, ExecuteScheduledActionError>>;
|
|
25
30
|
}
|
|
31
|
+
/** Execute a scheduled action immediately. */
|
|
26
32
|
export declare const ExecuteScheduledActionUseCase: import("@webiny/di").Abstraction<IExecuteScheduledActionUseCase>;
|
|
27
33
|
export declare namespace ExecuteScheduledActionUseCase {
|
|
28
34
|
type Interface = IExecuteScheduledActionUseCase;
|
|
29
35
|
type Error = ExecuteScheduledActionError;
|
|
36
|
+
type Params = IExecuteScheduledActionUseCaseParams;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* Handler not found error
|
|
@@ -1,41 +1,17 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Flow:
|
|
10
|
-
* 1. Load scheduled action from CMS
|
|
11
|
-
* 2. Find registered handler for namespace + actionType
|
|
12
|
-
* 3. Execute handler
|
|
13
|
-
* 4. Delete schedule entry on success
|
|
14
|
-
* 5. Update entry with error on failure
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export const ExecuteScheduledActionUseCase = createAbstraction("ExecuteScheduledActionUseCase");
|
|
18
|
-
/**
|
|
19
|
-
* Handler not found error
|
|
20
|
-
*/
|
|
21
|
-
export class HandlerNotFoundError extends Error {
|
|
22
|
-
code = "Scheduler/Handler/NotFound";
|
|
23
|
-
constructor(namespace, actionType) {
|
|
24
|
-
super(`No handler registered for namespace "${namespace}" and actionType "${actionType}"`);
|
|
25
|
-
this.name = "HandlerNotFoundError";
|
|
26
|
-
}
|
|
2
|
+
const ExecuteScheduledActionUseCase = createAbstraction("Scheduler/ExecuteScheduledActionUseCase");
|
|
3
|
+
class HandlerNotFoundError extends Error {
|
|
4
|
+
constructor(namespace, actionType){
|
|
5
|
+
super(`No handler registered for namespace "${namespace}" and actionType "${actionType}"`), this.code = "Scheduler/Handler/NotFound";
|
|
6
|
+
this.name = "HandlerNotFoundError";
|
|
7
|
+
}
|
|
27
8
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
code = "Scheduler/Execution/Failed";
|
|
34
|
-
constructor(message, originalError) {
|
|
35
|
-
super(message);
|
|
36
|
-
this.originalError = originalError;
|
|
37
|
-
this.name = "ExecutionFailedError";
|
|
38
|
-
}
|
|
9
|
+
class ExecutionFailedError extends Error {
|
|
10
|
+
constructor(message, originalError){
|
|
11
|
+
super(message), this.originalError = originalError, this.code = "Scheduler/Execution/Failed";
|
|
12
|
+
this.name = "ExecutionFailedError";
|
|
13
|
+
}
|
|
39
14
|
}
|
|
15
|
+
export { ExecuteScheduledActionUseCase, ExecutionFailedError, HandlerNotFoundError };
|
|
40
16
|
|
|
41
17
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/abstractions.js","sources":["../../../src/features/ExecuteScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by EventBridge when a schedule fires.\n * Finds the appropriate handler based on namespace + actionType and executes it.\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure\n */\n\nexport interface IExecuteScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n handlerNotFound: HandlerNotFoundError;\n executionFailed: ExecutionFailedError;\n unauthorized: NotAuthorizedError;\n}\n\ntype ExecuteScheduledActionError =\n IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];\n\nexport interface IExecuteScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\n\nexport interface IExecuteScheduledActionUseCase {\n execute(\n params: IExecuteScheduledActionUseCaseParams\n ): Promise<Result<void, ExecuteScheduledActionError>>;\n}\n\n/** Execute a scheduled action immediately. */\nexport const ExecuteScheduledActionUseCase = createAbstraction<IExecuteScheduledActionUseCase>(\n \"Scheduler/ExecuteScheduledActionUseCase\"\n);\n\nexport namespace ExecuteScheduledActionUseCase {\n export type Interface = IExecuteScheduledActionUseCase;\n export type Error = ExecuteScheduledActionError;\n export type Params = IExecuteScheduledActionUseCaseParams;\n}\n\n/**\n * Handler not found error\n */\nexport class HandlerNotFoundError extends Error {\n readonly code = \"Scheduler/Handler/NotFound\" as const;\n\n constructor(namespace: string, actionType: string) {\n super(`No handler registered for namespace \"${namespace}\" and actionType \"${actionType}\"`);\n this.name = \"HandlerNotFoundError\";\n }\n}\n\n/**\n * Execution failed error\n */\nexport class ExecutionFailedError extends Error {\n readonly code = \"Scheduler/Execution/Failed\" as const;\n\n constructor(\n message: string,\n public readonly originalError?: Error\n ) {\n super(message);\n this.name = \"ExecutionFailedError\";\n }\n}\n"],"names":["ExecuteScheduledActionUseCase","createAbstraction","HandlerNotFoundError","Error","namespace","actionType","ExecutionFailedError","message","originalError"],"mappings":";AA6CO,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"}
|
|
@@ -4,4 +4,7 @@
|
|
|
4
4
|
* Provides the ability to execute a scheduled action when triggered by EventBridge.
|
|
5
5
|
* Finds the appropriate handler and executes it, then cleans up the schedule entry.
|
|
6
6
|
*/
|
|
7
|
-
export declare const ExecuteScheduledActionFeature:
|
|
7
|
+
export declare const ExecuteScheduledActionFeature: {
|
|
8
|
+
name: string;
|
|
9
|
+
register(container: import("@webiny/di").Container): void;
|
|
10
|
+
};
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { ExecuteScheduledActionUseCase } from "./ExecuteScheduledActionUseCase.js";
|
|
3
3
|
import { ScheduledActionHandlerComposite } from "./ScheduledActionHandlerComposite.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export const ExecuteScheduledActionFeature = createFeature({
|
|
12
|
-
name: "ExecuteScheduledAction",
|
|
13
|
-
register(container) {
|
|
14
|
-
container.register(ExecuteScheduledActionUseCase);
|
|
15
|
-
container.registerComposite(ScheduledActionHandlerComposite);
|
|
16
|
-
}
|
|
4
|
+
const ExecuteScheduledActionFeature = createFeature({
|
|
5
|
+
name: "ExecuteScheduledAction",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(ExecuteScheduledActionUseCase);
|
|
8
|
+
container.registerComposite(ScheduledActionHandlerComposite);
|
|
9
|
+
}
|
|
17
10
|
});
|
|
11
|
+
export { ExecuteScheduledActionFeature };
|
|
18
12
|
|
|
19
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 triggered by EventBridge.\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"}
|
|
@@ -4,6 +4,8 @@ import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
|
4
4
|
import { ScheduledActionModel } 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
|
+
import { SchedulerPermissions } from "../../features/permissions/abstractions.js";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
7
9
|
/**
|
|
8
10
|
* Retrieves a scheduled action by its ID
|
|
9
11
|
*
|
|
@@ -15,8 +17,10 @@ import type { GenericRecord } from "@webiny/api/types.js";
|
|
|
15
17
|
declare class GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
16
18
|
private getEntryByIdUseCase;
|
|
17
19
|
private model;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
private permissions;
|
|
21
|
+
private identityContext;
|
|
22
|
+
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, model: ScheduledActionModel.Interface, permissions: SchedulerPermissions.Interface, identityContext: IdentityContext.Interface);
|
|
23
|
+
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
|
|
20
24
|
}
|
|
21
25
|
export declare const GetScheduledActionUseCase: typeof GetScheduledActionUseCaseImpl & {
|
|
22
26
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetScheduledActionUseCase>;
|
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { GetScheduledActionUseCase
|
|
2
|
+
import { GetScheduledActionUseCase } from "./abstractions.js";
|
|
3
3
|
import { ScheduledActionModel } from "../../shared/abstractions.js";
|
|
4
|
-
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
4
|
+
import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
5
5
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
6
|
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Flow:
|
|
11
|
-
* 1. Fetch schedule entry from CMS storage by ID
|
|
12
|
-
* 2. Return null if not found
|
|
13
|
-
* 3. Transform CMS entry to IScheduledAction format
|
|
14
|
-
*/
|
|
7
|
+
import { SchedulerPermissions } from "../permissions/abstractions.js";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
|
+
import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
|
|
15
10
|
class GetScheduledActionUseCaseImpl {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
constructor(getEntryByIdUseCase, model, permissions, identityContext){
|
|
12
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
13
|
+
this.model = model;
|
|
14
|
+
this.permissions = permissions;
|
|
15
|
+
this.identityContext = identityContext;
|
|
16
|
+
}
|
|
17
|
+
async execute(params) {
|
|
18
|
+
const hasPermission = await this.permissions.canRead("action");
|
|
19
|
+
if (!hasPermission) return Result.fail(new NotAuthorizedError());
|
|
20
|
+
const { id, namespace } = params;
|
|
21
|
+
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
22
|
+
const entryResult = await this.getEntryByIdUseCase.execute(this.model, scheduleId);
|
|
23
|
+
if (entryResult.isFail()) {
|
|
24
|
+
if ("Cms/Entry/NotFound" === entryResult.error.code) return Result.fail(new ScheduledActionNotFoundError(scheduleId));
|
|
25
|
+
return Result.fail(new ScheduledActionPersistenceError(entryResult.error));
|
|
26
|
+
}
|
|
27
|
+
const ownRecordsOnly = await this.permissions.onlyOwnRecords("action");
|
|
28
|
+
if (ownRecordsOnly) {
|
|
29
|
+
if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) return Result.fail(new NotAuthorizedError());
|
|
30
|
+
}
|
|
31
|
+
const entry = entryResult.value;
|
|
32
|
+
if (entry.values.namespace !== namespace) return Result.fail(new ScheduledActionNotFoundError(scheduleId));
|
|
33
|
+
const action = ScheduledActionMapper.toAction(entry);
|
|
34
|
+
return Result.ok(action);
|
|
29
35
|
}
|
|
30
|
-
const entry = entryResult.value;
|
|
31
|
-
return Result.ok({
|
|
32
|
-
id: entry.entryId,
|
|
33
|
-
namespace: entry.values.namespace,
|
|
34
|
-
actionType: entry.values.actionType,
|
|
35
|
-
targetId: entry.values.targetId,
|
|
36
|
-
scheduledBy: entry.values.scheduledBy,
|
|
37
|
-
scheduledFor: entry.values.scheduledFor,
|
|
38
|
-
payload: entry.values.payload,
|
|
39
|
-
title: entry.values.title,
|
|
40
|
-
error: entry.values.error
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
const GetScheduledActionUseCase_GetScheduledActionUseCase = GetScheduledActionUseCase.createImplementation({
|
|
38
|
+
implementation: GetScheduledActionUseCaseImpl,
|
|
39
|
+
dependencies: [
|
|
40
|
+
GetEntryByIdUseCase,
|
|
41
|
+
ScheduledActionModel,
|
|
42
|
+
SchedulerPermissions,
|
|
43
|
+
IdentityContext
|
|
44
|
+
]
|
|
47
45
|
});
|
|
46
|
+
export { GetScheduledActionUseCase_GetScheduledActionUseCase as GetScheduledActionUseCase };
|
|
48
47
|
|
|
49
48
|
//# sourceMappingURL=GetScheduledActionUseCase.js.map
|