@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
|
@@ -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,23 @@ 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
|
+
tenant: string;
|
|
27
|
+
id: string;
|
|
28
|
+
}
|
|
23
29
|
export interface IExecuteScheduledActionUseCase {
|
|
24
|
-
execute(
|
|
30
|
+
execute(params: IExecuteScheduledActionUseCaseParams): Promise<Result<void, ExecuteScheduledActionError>>;
|
|
25
31
|
}
|
|
32
|
+
/** Execute a scheduled action immediately. */
|
|
26
33
|
export declare const ExecuteScheduledActionUseCase: import("@webiny/di").Abstraction<IExecuteScheduledActionUseCase>;
|
|
27
34
|
export declare namespace ExecuteScheduledActionUseCase {
|
|
28
35
|
type Interface = IExecuteScheduledActionUseCase;
|
|
29
36
|
type Error = ExecuteScheduledActionError;
|
|
37
|
+
type Params = IExecuteScheduledActionUseCaseParams;
|
|
30
38
|
}
|
|
31
39
|
/**
|
|
32
40
|
* 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 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"}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GetScheduledAction/GetScheduledActionUseCase.js","sources":["../../../src/features/GetScheduledAction/GetScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { IScheduledAction, IScheduledActionEntryValues } from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel } from \"~/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SchedulerPermissions } from \"~/features/permissions/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\n\n/**\n * Retrieves a scheduled action by its ID\n *\n * Flow:\n * 1. Fetch schedule entry from CMS storage by ID\n * 2. Return null if not found\n * 3. Transform CMS entry to IScheduledAction format\n */\nclass GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private permissions: SchedulerPermissions.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n const { id, namespace } = params;\n // Get entry from CMS\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n const entryResult = await this.getEntryByIdUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n scheduleId\n );\n\n if (entryResult.isFail()) {\n if (entryResult.error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(scheduleId));\n }\n\n return Result.fail(new ScheduledActionPersistenceError(entryResult.error));\n }\n\n const ownRecordsOnly = await this.permissions.onlyOwnRecords(\"action\");\n if (ownRecordsOnly) {\n if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) {\n return Result.fail(new NotAuthorizedError());\n }\n }\n\n const entry = entryResult.value;\n /**\n * Always check if the namespace is correct because entry is loaded directly, not via filtering.\n */\n if (entry.values.namespace !== namespace) {\n return Result.fail(new ScheduledActionNotFoundError(scheduleId));\n }\n const action = ScheduledActionMapper.toAction<T>(entry);\n\n return Result.ok(action);\n }\n}\n\nexport const GetScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetScheduledActionUseCaseImpl,\n dependencies: [GetEntryByIdUseCase, ScheduledActionModel, SchedulerPermissions, IdentityContext]\n});\n"],"names":["GetScheduledActionUseCaseImpl","getEntryByIdUseCase","model","permissions","identityContext","params","hasPermission","Result","NotAuthorizedError","id","namespace","scheduleId","ScheduledActionIdWithVersion","entryResult","ScheduledActionNotFoundError","ScheduledActionPersistenceError","ownRecordsOnly","entry","action","ScheduledActionMapper","GetScheduledActionUseCase","UseCaseAbstraction","GetEntryByIdUseCase","ScheduledActionModel","SchedulerPermissions","IdentityContext"],"mappings":";;;;;;;;;AAwBA,MAAMA;IACF,YACYC,mBAAkD,EAClDC,KAAqC,EACrCC,WAA2C,EAC3CC,eAA0C,CACpD;aAJUH,mBAAmB,GAAnBA;aACAC,KAAK,GAALA;aACAC,WAAW,GAAXA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,MAAiC,EAC6B;QAC9D,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACrD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAE3B,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGL;QAE1B,MAAMM,aAAaC,6BAA6B,IAAI,CAACH;QACrD,MAAMI,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CACtD,IAAI,CAAC,KAAK,EACVF;QAGJ,IAAIE,YAAY,MAAM,IAAI;YACtB,IAAIA,AAA2B,yBAA3BA,YAAY,KAAK,CAAC,IAAI,EACtB,OAAON,OAAO,IAAI,CAAC,IAAIO,6BAA6BH;YAGxD,OAAOJ,OAAO,IAAI,CAAC,IAAIQ,gCAAgCF,YAAY,KAAK;QAC5E;QAEA,MAAMG,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;QAC7D,IAAIA,gBACA;YAAA,IAAIH,YAAY,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,EACxE,OAAON,OAAO,IAAI,CAAC,IAAIC;QAC3B;QAGJ,MAAMS,QAAQJ,YAAY,KAAK;QAI/B,IAAII,MAAM,MAAM,CAAC,SAAS,KAAKP,WAC3B,OAAOH,OAAO,IAAI,CAAC,IAAIO,6BAA6BH;QAExD,MAAMO,SAASC,sBAAsB,QAAQ,CAAIF;QAEjD,OAAOV,OAAO,EAAE,CAACW;IACrB;AACJ;AAEO,MAAME,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBrB;IAChB,cAAc;QAACsB;QAAqBC;QAAsBC;QAAsBC;KAAgB;AACpG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
3
|
-
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
3
|
+
import { ScheduledActionNotFoundError, ScheduledActionPersistenceError, NotAuthorizedError } from "../../domain/errors.js";
|
|
4
4
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
5
5
|
/**
|
|
6
6
|
* GetScheduledActionUseCase - Retrieve a scheduled action by ID
|
|
@@ -13,14 +13,21 @@ import type { GenericRecord } from "@webiny/api/types.js";
|
|
|
13
13
|
export interface IGetScheduledActionErrors {
|
|
14
14
|
persistence: ScheduledActionPersistenceError;
|
|
15
15
|
notFound: ScheduledActionNotFoundError;
|
|
16
|
+
unauthorized: NotAuthorizedError;
|
|
16
17
|
}
|
|
17
18
|
type GetScheduledActionError = IGetScheduledActionErrors[keyof IGetScheduledActionErrors];
|
|
19
|
+
export interface IGetScheduledActionUseCaseParams {
|
|
20
|
+
namespace: string;
|
|
21
|
+
id: string;
|
|
22
|
+
}
|
|
18
23
|
export interface IGetScheduledActionUseCase {
|
|
19
|
-
execute<T extends GenericRecord>(
|
|
24
|
+
execute<T extends GenericRecord>(params: IGetScheduledActionUseCaseParams): Promise<Result<IScheduledAction<T>, GetScheduledActionError>>;
|
|
20
25
|
}
|
|
26
|
+
/** Retrieve a scheduled action. */
|
|
21
27
|
export declare const GetScheduledActionUseCase: import("@webiny/di").Abstraction<IGetScheduledActionUseCase>;
|
|
22
28
|
export declare namespace GetScheduledActionUseCase {
|
|
23
29
|
type Interface = IGetScheduledActionUseCase;
|
|
24
30
|
type Error = GetScheduledActionError;
|
|
31
|
+
type Params = IGetScheduledActionUseCaseParams;
|
|
25
32
|
}
|
|
26
33
|
export {};
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* GetScheduledActionUseCase - Retrieve a scheduled action by ID
|
|
5
|
-
*
|
|
6
|
-
* Used to check if a schedule exists (for reschedule logic) and to retrieve
|
|
7
|
-
* schedule details for display/management purposes.
|
|
8
|
-
*
|
|
9
|
-
* Returns null value (Result.ok(null)) if schedule not found.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export const GetScheduledActionUseCase = createAbstraction("GetScheduledActionUseCase");
|
|
2
|
+
const GetScheduledActionUseCase = createAbstraction("Scheduler/GetScheduledActionUseCase");
|
|
3
|
+
export { GetScheduledActionUseCase };
|
|
13
4
|
|
|
14
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GetScheduledAction/abstractions.js","sources":["../../../src/features/GetScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport {\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError,\n NotAuthorizedError\n} from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * GetScheduledActionUseCase - Retrieve a scheduled action by ID\n *\n * Used to check if a schedule exists (for reschedule logic) and to retrieve\n * schedule details for display/management purposes.\n *\n * Returns null value (Result.ok(null)) if schedule not found.\n */\n\nexport interface IGetScheduledActionErrors {\n persistence: ScheduledActionPersistenceError;\n notFound: ScheduledActionNotFoundError;\n unauthorized: NotAuthorizedError;\n}\n\ntype GetScheduledActionError = IGetScheduledActionErrors[keyof IGetScheduledActionErrors];\n\nexport interface IGetScheduledActionUseCaseParams {\n namespace: string;\n id: string;\n}\n\nexport interface IGetScheduledActionUseCase {\n execute<T extends GenericRecord>(\n params: IGetScheduledActionUseCaseParams\n ): Promise<Result<IScheduledAction<T>, GetScheduledActionError>>;\n}\n\n/** Retrieve a scheduled action. */\nexport const GetScheduledActionUseCase = createAbstraction<IGetScheduledActionUseCase>(\n \"Scheduler/GetScheduledActionUseCase\"\n);\n\nexport namespace GetScheduledActionUseCase {\n export type Interface = IGetScheduledActionUseCase;\n export type Error = GetScheduledActionError;\n export type Params = IGetScheduledActionUseCaseParams;\n}\n"],"names":["GetScheduledActionUseCase","createAbstraction"],"mappings":";AAsCO,MAAMA,4BAA4BC,kBACrC"}
|
|
@@ -4,4 +4,7 @@
|
|
|
4
4
|
* Provides the ability to retrieve a scheduled action by ID.
|
|
5
5
|
* Used for checking if schedules exist and displaying schedule details.
|
|
6
6
|
*/
|
|
7
|
-
export declare const GetScheduledActionFeature:
|
|
7
|
+
export declare const GetScheduledActionFeature: {
|
|
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 { GetScheduledActionUseCase } from "./GetScheduledActionUseCase.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Used for checking if schedules exist and displaying schedule details.
|
|
9
|
-
*/
|
|
10
|
-
export const GetScheduledActionFeature = createFeature({
|
|
11
|
-
name: "GetScheduledAction",
|
|
12
|
-
register(container) {
|
|
13
|
-
container.register(GetScheduledActionUseCase);
|
|
14
|
-
}
|
|
3
|
+
const GetScheduledActionFeature = createFeature({
|
|
4
|
+
name: "GetScheduledAction",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetScheduledActionUseCase);
|
|
7
|
+
}
|
|
15
8
|
});
|
|
9
|
+
export { GetScheduledActionFeature };
|
|
16
10
|
|
|
17
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/GetScheduledAction/feature.js","sources":["../../../src/features/GetScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetScheduledActionUseCase } from \"./GetScheduledActionUseCase.js\";\n\n/**\n * GetScheduledAction Feature\n *\n * Provides the ability to retrieve a scheduled action by ID.\n * Used for checking if schedules exist and displaying schedule details.\n */\nexport const GetScheduledActionFeature = createFeature({\n name: \"GetScheduledAction\",\n register(container) {\n container.register(GetScheduledActionUseCase);\n }\n});\n"],"names":["GetScheduledActionFeature","createFeature","container","GetScheduledActionUseCase"],"mappings":";;AASO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GetTargetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
|
+
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
4
|
+
import { ScheduledActionModel } from "../../shared/abstractions.js";
|
|
5
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
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";
|
|
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
|
+
*/
|
|
17
|
+
declare class GetTargetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
18
|
+
private getEntryByIdUseCase;
|
|
19
|
+
private model;
|
|
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>>;
|
|
24
|
+
/**
|
|
25
|
+
* We always need to fetch both publish and unpublish actions because we don't know the type of the action that is being searched for.
|
|
26
|
+
*/
|
|
27
|
+
private getRecord;
|
|
28
|
+
}
|
|
29
|
+
export declare const GetTargetScheduledActionUseCase: typeof GetTargetScheduledActionUseCaseImpl & {
|
|
30
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetTargetScheduledActionUseCase>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GetTargetScheduledActionUseCase } from "./abstractions.js";
|
|
3
|
+
import { ScheduledActionModel } from "../../shared/abstractions.js";
|
|
4
|
+
import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
5
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
|
+
import { SchedulerPermissions } from "../permissions/abstractions.js";
|
|
7
|
+
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
8
|
+
import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
|
|
9
|
+
import { ScheduledActionId } from "../../domain/ScheduledActionId.js";
|
|
10
|
+
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
11
|
+
import { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from "../../constants.js";
|
|
12
|
+
class GetTargetScheduledActionUseCaseImpl {
|
|
13
|
+
constructor(getEntryByIdUseCase, model, permissions, identityContext){
|
|
14
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
15
|
+
this.model = model;
|
|
16
|
+
this.permissions = permissions;
|
|
17
|
+
this.identityContext = identityContext;
|
|
18
|
+
}
|
|
19
|
+
async execute(params) {
|
|
20
|
+
const hasPermission = await this.permissions.canRead("action");
|
|
21
|
+
if (!hasPermission) return Result.fail(new NotAuthorizedError());
|
|
22
|
+
const { id, namespace } = params;
|
|
23
|
+
const entryResult = await this.getRecord(params);
|
|
24
|
+
if (entryResult.isFail()) {
|
|
25
|
+
if ("Cms/Entry/NotFound" === entryResult.error.code) return Result.fail(new ScheduledActionNotFoundError(id));
|
|
26
|
+
return Result.fail(new ScheduledActionPersistenceError(entryResult.error));
|
|
27
|
+
}
|
|
28
|
+
const ownRecordsOnly = await this.permissions.onlyOwnRecords("action");
|
|
29
|
+
if (ownRecordsOnly) {
|
|
30
|
+
if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) return Result.fail(new NotAuthorizedError());
|
|
31
|
+
}
|
|
32
|
+
const entry = entryResult.value;
|
|
33
|
+
if (entry.values.namespace !== namespace) return Result.fail(new ScheduledActionNotFoundError(id));
|
|
34
|
+
const action = ScheduledActionMapper.toAction(entry);
|
|
35
|
+
return Result.ok(action);
|
|
36
|
+
}
|
|
37
|
+
async getRecord(params) {
|
|
38
|
+
const schedulePublishId = ScheduledActionId.from({
|
|
39
|
+
namespace: params.namespace,
|
|
40
|
+
targetId: params.id,
|
|
41
|
+
actionType: SCHEDULED_ACTION_PUBLISH
|
|
42
|
+
});
|
|
43
|
+
const publishResult = await this.getEntryByIdUseCase.execute(this.model, ScheduledActionIdWithVersion.from(schedulePublishId));
|
|
44
|
+
if (publishResult.isOk()) return publishResult;
|
|
45
|
+
const scheduleUnpublishId = ScheduledActionId.from({
|
|
46
|
+
namespace: params.namespace,
|
|
47
|
+
targetId: params.id,
|
|
48
|
+
actionType: SCHEDULED_ACTION_UNPUBLISH
|
|
49
|
+
});
|
|
50
|
+
return this.getEntryByIdUseCase.execute(this.model, ScheduledActionIdWithVersion.from(scheduleUnpublishId));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const GetTargetScheduledActionUseCase_GetTargetScheduledActionUseCase = GetTargetScheduledActionUseCase.createImplementation({
|
|
54
|
+
implementation: GetTargetScheduledActionUseCaseImpl,
|
|
55
|
+
dependencies: [
|
|
56
|
+
GetEntryByIdUseCase,
|
|
57
|
+
ScheduledActionModel,
|
|
58
|
+
SchedulerPermissions,
|
|
59
|
+
IdentityContext
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
export { GetTargetScheduledActionUseCase_GetTargetScheduledActionUseCase as GetTargetScheduledActionUseCase };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=GetTargetScheduledActionUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js","sources":["../../../src/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetTargetScheduledActionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { IScheduledAction, IScheduledActionEntryValues } from \"~/shared/abstractions.js\";\nimport { ScheduledActionModel } from \"~/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SchedulerPermissions } from \"~/features/permissions/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\nimport { ScheduledActionId } from \"~/domain/ScheduledActionId.js\";\nimport { ScheduledActionIdWithVersion } from \"~/domain/ScheduledActionIdWithVersion.js\";\nimport { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from \"~/constants.js\";\n\n/**\n * Retrieves a scheduled action by its ID\n *\n * Flow:\n * 1. Fetch schedule entry from CMS storage by ID\n * 2. Return null if not found\n * 3. Transform CMS entry to IScheduledAction format\n */\nclass GetTargetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private model: ScheduledActionModel.Interface,\n private permissions: SchedulerPermissions.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: UseCaseAbstraction.Params\n ): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n const { id, namespace } = params;\n\n const entryResult = await this.getRecord<T>(params);\n\n if (entryResult.isFail()) {\n if (entryResult.error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n\n return Result.fail(new ScheduledActionPersistenceError(entryResult.error));\n }\n\n const ownRecordsOnly = await this.permissions.onlyOwnRecords(\"action\");\n if (ownRecordsOnly) {\n if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) {\n return Result.fail(new NotAuthorizedError());\n }\n }\n\n const entry = entryResult.value;\n /**\n * Always check if the namespace is correct because entry is loaded directly, not via filtering.\n */\n if (entry.values.namespace !== namespace) {\n return Result.fail(new ScheduledActionNotFoundError(id));\n }\n const action = ScheduledActionMapper.toAction<T>(entry);\n return Result.ok(action);\n }\n /**\n * We always need to fetch both publish and unpublish actions because we don't know the type of the action that is being searched for.\n */\n private async getRecord<T extends GenericRecord>(params: UseCaseAbstraction.Params) {\n const schedulePublishId = ScheduledActionId.from({\n namespace: params.namespace,\n targetId: params.id,\n actionType: SCHEDULED_ACTION_PUBLISH\n });\n const publishResult = await this.getEntryByIdUseCase.execute<\n IScheduledActionEntryValues<T>\n >(this.model, ScheduledActionIdWithVersion.from(schedulePublishId));\n if (publishResult.isOk()) {\n return publishResult;\n }\n const scheduleUnpublishId = ScheduledActionId.from({\n namespace: params.namespace,\n targetId: params.id,\n actionType: SCHEDULED_ACTION_UNPUBLISH\n });\n return this.getEntryByIdUseCase.execute<IScheduledActionEntryValues<T>>(\n this.model,\n ScheduledActionIdWithVersion.from(scheduleUnpublishId)\n );\n }\n}\n\nexport const GetTargetScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetTargetScheduledActionUseCaseImpl,\n dependencies: [GetEntryByIdUseCase, ScheduledActionModel, SchedulerPermissions, IdentityContext]\n});\n"],"names":["GetTargetScheduledActionUseCaseImpl","getEntryByIdUseCase","model","permissions","identityContext","params","hasPermission","Result","NotAuthorizedError","id","namespace","entryResult","ScheduledActionNotFoundError","ScheduledActionPersistenceError","ownRecordsOnly","entry","action","ScheduledActionMapper","schedulePublishId","ScheduledActionId","SCHEDULED_ACTION_PUBLISH","publishResult","ScheduledActionIdWithVersion","scheduleUnpublishId","SCHEDULED_ACTION_UNPUBLISH","GetTargetScheduledActionUseCase","UseCaseAbstraction","GetEntryByIdUseCase","ScheduledActionModel","SchedulerPermissions","IdentityContext"],"mappings":";;;;;;;;;;;AA0BA,MAAMA;IACF,YACYC,mBAAkD,EAClDC,KAAqC,EACrCC,WAA2C,EAC3CC,eAA0C,CACpD;aAJUH,mBAAmB,GAAnBA;aACAC,KAAK,GAALA;aACAC,WAAW,GAAXA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,MAAiC,EAC6B;QAC9D,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACrD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAE3B,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGL;QAE1B,MAAMM,cAAc,MAAM,IAAI,CAAC,SAAS,CAAIN;QAE5C,IAAIM,YAAY,MAAM,IAAI;YACtB,IAAIA,AAA2B,yBAA3BA,YAAY,KAAK,CAAC,IAAI,EACtB,OAAOJ,OAAO,IAAI,CAAC,IAAIK,6BAA6BH;YAGxD,OAAOF,OAAO,IAAI,CAAC,IAAIM,gCAAgCF,YAAY,KAAK;QAC5E;QAEA,MAAMG,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;QAC7D,IAAIA,gBACA;YAAA,IAAIH,YAAY,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,EACxE,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAC3B;QAGJ,MAAMO,QAAQJ,YAAY,KAAK;QAI/B,IAAII,MAAM,MAAM,CAAC,SAAS,KAAKL,WAC3B,OAAOH,OAAO,IAAI,CAAC,IAAIK,6BAA6BH;QAExD,MAAMO,SAASC,sBAAsB,QAAQ,CAAIF;QACjD,OAAOR,OAAO,EAAE,CAACS;IACrB;IAIA,MAAc,UAAmCX,MAAiC,EAAE;QAChF,MAAMa,oBAAoBC,kBAAkB,IAAI,CAAC;YAC7C,WAAWd,OAAO,SAAS;YAC3B,UAAUA,OAAO,EAAE;YACnB,YAAYe;QAChB;QACA,MAAMC,gBAAgB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAE1D,IAAI,CAAC,KAAK,EAAEC,6BAA6B,IAAI,CAACJ;QAChD,IAAIG,cAAc,IAAI,IAClB,OAAOA;QAEX,MAAME,sBAAsBJ,kBAAkB,IAAI,CAAC;YAC/C,WAAWd,OAAO,SAAS;YAC3B,UAAUA,OAAO,EAAE;YACnB,YAAYmB;QAChB;QACA,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,CACnC,IAAI,CAAC,KAAK,EACVF,6BAA6B,IAAI,CAACC;IAE1C;AACJ;AAEO,MAAME,kEAAkCC,gCAAAA,oBAAuC,CAAC;IACnF,gBAAgB1B;IAChB,cAAc;QAAC2B;QAAqBC;QAAsBC;QAAsBC;KAAgB;AACpG"}
|