@webiny/api-scheduler 0.0.0-unstable.7be00a75a9 → 0.0.0-unstable.7c2def32a7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ScheduledActionLambdaHandler.d.ts +18 -0
- package/ScheduledActionLambdaHandler.js +41 -0
- package/ScheduledActionLambdaHandler.js.map +1 -0
- package/SchedulerFeature.d.ts +5 -0
- package/SchedulerFeature.js +21 -0
- package/SchedulerFeature.js.map +1 -0
- package/domain/SchedulePrivateModel.js +2 -1
- package/domain/SchedulePrivateModel.js.map +1 -1
- package/domain/ScheduledActionMapper.js +8 -2
- package/domain/ScheduledActionMapper.js.map +1 -1
- package/domain/errors.d.ts +1 -1
- package/domain/errors.js.map +1 -1
- package/exports/api/scheduler.d.ts +1 -1
- package/exports/api/scheduler.js +1 -1
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +7 -7
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +15 -14
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +2 -1
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/CancelScheduledAction/feature.d.ts +1 -1
- package/features/CancelScheduledAction/feature.js.map +1 -1
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +3 -3
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +16 -7
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +2 -1
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/feature.d.ts +1 -1
- package/features/ExecuteScheduledAction/feature.js.map +1 -1
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +5 -5
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +12 -11
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +5 -5
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +13 -12
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -1
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -5
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +15 -13
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- 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/ScheduleAction/ScheduleActionUseCase.d.ts +6 -6
- package/features/ScheduleAction/ScheduleActionUseCase.js +31 -23
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduleAction/abstractions.d.ts +1 -0
- package/features/ScheduleAction/abstractions.js.map +1 -1
- package/features/ScheduledActionModelProvider.d.ts +26 -0
- package/features/ScheduledActionModelProvider.js +22 -0
- package/features/ScheduledActionModelProvider.js.map +1 -0
- package/features/SchedulerService/VoidSchedulerService.d.ts +9 -9
- package/features/SchedulerService/VoidSchedulerService.js +4 -4
- package/features/SchedulerService/VoidSchedulerService.js.map +1 -1
- package/features/permissions/SchedulerPermissionsResolver.d.ts +12 -0
- package/features/permissions/SchedulerPermissionsResolver.js +42 -0
- package/features/permissions/SchedulerPermissionsResolver.js.map +1 -0
- package/features/permissions/abstractions.d.ts +18 -12
- package/features/permissions/abstractions.js +4 -4
- package/features/permissions/abstractions.js.map +1 -1
- package/graphql/SchedulerGraphQLFactory.d.ts +4 -3
- package/graphql/SchedulerGraphQLFactory.js +6 -2
- package/graphql/SchedulerGraphQLFactory.js.map +1 -1
- package/{features/permissions → graphql}/feature.d.ts +1 -1
- package/graphql/feature.js +11 -0
- package/graphql/feature.js.map +1 -0
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/package.json +12 -22
- package/shared/abstractions.d.ts +30 -7
- package/shared/abstractions.js +2 -2
- package/shared/abstractions.js.map +1 -1
- package/context.d.ts +0 -7
- package/context.js +0 -47
- package/context.js.map +0 -1
- package/createEventHandler.d.ts +0 -14
- package/createEventHandler.js +0 -37
- package/createEventHandler.js.map +0 -1
- package/createScheduler.d.ts +0 -6
- package/createScheduler.js +0 -9
- package/createScheduler.js.map +0 -1
- package/domain/permissionsSchema.d.ts +0 -9
- package/domain/permissionsSchema.js +0 -18
- package/domain/permissionsSchema.js.map +0 -1
- package/features/SchedulerService/EventBridgeSchedulerService.d.ts +0 -26
- package/features/SchedulerService/EventBridgeSchedulerService.js +0 -97
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +0 -1
- package/features/permissions/feature.js +0 -7
- package/features/permissions/feature.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -35
- package/manifest.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ExecuteScheduledAction/abstractions.js","sources":["../../../src/features/ExecuteScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/abstractions.js","sources":["../../../src/features/ExecuteScheduledAction/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\n NotAuthorizedError,\n ScheduledActionNotFoundError,\n ScheduledActionPersistenceError\n} from \"~/domain/errors.js\";\n\n/**\n * ExecuteScheduledActionUseCase - Execute a scheduled action\n *\n * This is triggered by the scheduler when a schedule fires.\n * Finds the appropriate handler based on namespace + actionType and executes it.\n *\n * Flow:\n * 1. Load scheduled action from CMS\n * 2. Find registered handler for namespace + actionType\n * 3. Execute handler\n * 4. Delete schedule entry on success\n * 5. Update entry with error on failure\n */\n\nexport interface IExecuteScheduledActionErrors {\n notFound: ScheduledActionNotFoundError;\n persistence: ScheduledActionPersistenceError;\n handlerNotFound: HandlerNotFoundError;\n executionFailed: ExecutionFailedError;\n unauthorized: NotAuthorizedError;\n}\n\ntype ExecuteScheduledActionError =\n IExecuteScheduledActionErrors[keyof IExecuteScheduledActionErrors];\n\nexport interface IExecuteScheduledActionUseCaseParams {\n namespace: string;\n tenant: string;\n id: string;\n}\n\nexport interface IExecuteScheduledActionUseCase {\n execute(\n params: IExecuteScheduledActionUseCaseParams\n ): Promise<Result<void, ExecuteScheduledActionError>>;\n}\n\n/** Execute a scheduled action immediately. */\nexport const ExecuteScheduledActionUseCase = createAbstraction<IExecuteScheduledActionUseCase>(\n \"Scheduler/ExecuteScheduledActionUseCase\"\n);\n\nexport namespace ExecuteScheduledActionUseCase {\n export type Interface = IExecuteScheduledActionUseCase;\n export type Error = ExecuteScheduledActionError;\n export type Params = IExecuteScheduledActionUseCaseParams;\n}\n\n/**\n * Handler not found error\n */\nexport class HandlerNotFoundError extends Error {\n readonly code = \"Scheduler/Handler/NotFound\" as const;\n\n constructor(namespace: string, actionType: string) {\n super(`No handler registered for namespace \"${namespace}\" and actionType \"${actionType}\"`);\n this.name = \"HandlerNotFoundError\";\n }\n}\n\n/**\n * Execution failed error\n */\nexport class ExecutionFailedError extends Error {\n readonly code = \"Scheduler/Execution/Failed\" as const;\n\n constructor(\n message: string,\n public readonly originalError?: Error\n ) {\n super(message);\n this.name = \"ExecutionFailedError\";\n }\n}\n"],"names":["ExecuteScheduledActionUseCase","createAbstraction","HandlerNotFoundError","Error","namespace","actionType","ExecutionFailedError","message","originalError"],"mappings":";AA8CO,MAAMA,gCAAgCC,kBACzC;AAYG,MAAMC,6BAA6BC;IAGtC,YAAYC,SAAiB,EAAEC,UAAkB,CAAE;QAC/C,KAAK,CAAC,CAAC,qCAAqC,EAAED,UAAU,kBAAkB,EAAEC,WAAW,CAAC,CAAC,QAHpF,IAAI,GAAG;QAIZ,IAAI,CAAC,IAAI,GAAG;IAChB;AACJ;AAKO,MAAMC,6BAA6BH;IAGtC,YACII,OAAe,EACCC,aAAqB,CACvC;QACE,KAAK,CAACD,UAAAA,IAAAA,CAFUC,aAAa,GAAbA,eAAAA,IAAAA,CAJX,IAAI,GAAG;QAOZ,IAAI,CAAC,IAAI,GAAG;IAChB;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ExecuteScheduledAction Feature
|
|
3
3
|
*
|
|
4
|
-
* Provides the ability to execute a scheduled action when
|
|
4
|
+
* Provides the ability to execute a scheduled action when the scheduler fires.
|
|
5
5
|
* Finds the appropriate handler and executes it, then cleans up the schedule entry.
|
|
6
6
|
*/
|
|
7
7
|
export declare const ExecuteScheduledActionFeature: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ExecuteScheduledAction/feature.js","sources":["../../../src/features/ExecuteScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ExecuteScheduledActionUseCase } from \"./ExecuteScheduledActionUseCase.js\";\nimport { ScheduledActionHandlerComposite } from \"~/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js\";\n\n/**\n * ExecuteScheduledAction Feature\n *\n * Provides the ability to execute a scheduled action when
|
|
1
|
+
{"version":3,"file":"features/ExecuteScheduledAction/feature.js","sources":["../../../src/features/ExecuteScheduledAction/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ExecuteScheduledActionUseCase } from \"./ExecuteScheduledActionUseCase.js\";\nimport { ScheduledActionHandlerComposite } from \"~/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js\";\n\n/**\n * ExecuteScheduledAction Feature\n *\n * Provides the ability to execute a scheduled action when the scheduler fires.\n * Finds the appropriate handler and executes it, then cleans up the schedule entry.\n */\nexport const ExecuteScheduledActionFeature = createFeature({\n name: \"ExecuteScheduledAction\",\n register(container) {\n container.register(ExecuteScheduledActionUseCase);\n container.registerComposite(ScheduledActionHandlerComposite);\n }\n});\n"],"names":["ExecuteScheduledActionFeature","createFeature","container","ExecuteScheduledActionUseCase","ScheduledActionHandlerComposite"],"mappings":";;;AAUO,MAAMA,gCAAgCC,cAAc;IACvD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,iBAAiB,CAACE;IAChC;AACJ"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
6
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
7
|
-
import {
|
|
7
|
+
import { SchedulerPermissionsResolver } from "../../features/permissions/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
9
|
/**
|
|
10
10
|
* Retrieves a scheduled action by its ID
|
|
@@ -16,10 +16,10 @@ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
|
16
16
|
*/
|
|
17
17
|
declare class GetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
18
18
|
private getEntryByIdUseCase;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
19
|
+
private modelProvider;
|
|
20
|
+
private permissionsResolver;
|
|
21
21
|
private identityContext;
|
|
22
|
-
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface,
|
|
22
|
+
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, permissionsResolver: SchedulerPermissionsResolver.Interface, identityContext: IdentityContext.Interface);
|
|
23
23
|
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
|
|
24
24
|
}
|
|
25
25
|
export declare const GetScheduledActionUseCase: typeof GetScheduledActionUseCaseImpl & {
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetScheduledActionUseCase } from "./abstractions.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
4
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
|
-
import {
|
|
7
|
+
import { SchedulerPermissionsResolver } from "../permissions/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
9
|
import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
|
|
10
10
|
class GetScheduledActionUseCaseImpl {
|
|
11
|
-
constructor(getEntryByIdUseCase,
|
|
11
|
+
constructor(getEntryByIdUseCase, modelProvider, permissionsResolver, identityContext){
|
|
12
12
|
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
13
|
+
this.modelProvider = modelProvider;
|
|
14
|
+
this.permissionsResolver = permissionsResolver;
|
|
15
15
|
this.identityContext = identityContext;
|
|
16
16
|
}
|
|
17
17
|
async execute(params) {
|
|
18
|
-
const hasPermission = await this.permissions.canRead("action");
|
|
19
|
-
if (!hasPermission) return Result.fail(new NotAuthorizedError());
|
|
20
18
|
const { id, namespace } = params;
|
|
19
|
+
const permissions = this.permissionsResolver.forNamespace(namespace);
|
|
20
|
+
if (!await permissions.canRead()) return Result.fail(new NotAuthorizedError());
|
|
21
|
+
const model = await this.modelProvider.get();
|
|
21
22
|
const scheduleId = ScheduledActionIdWithVersion.from(id);
|
|
22
|
-
const entryResult = await this.getEntryByIdUseCase.execute(
|
|
23
|
+
const entryResult = await this.getEntryByIdUseCase.execute(model, scheduleId);
|
|
23
24
|
if (entryResult.isFail()) {
|
|
24
25
|
if ("Cms/Entry/NotFound" === entryResult.error.code) return Result.fail(new ScheduledActionNotFoundError(scheduleId));
|
|
25
26
|
return Result.fail(new ScheduledActionPersistenceError(entryResult.error));
|
|
26
27
|
}
|
|
27
|
-
const ownRecordsOnly = await
|
|
28
|
+
const ownRecordsOnly = await permissions.onlyOwnRecords();
|
|
28
29
|
if (ownRecordsOnly) {
|
|
29
30
|
if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) return Result.fail(new NotAuthorizedError());
|
|
30
31
|
}
|
|
@@ -38,8 +39,8 @@ const GetScheduledActionUseCase_GetScheduledActionUseCase = GetScheduledActionUs
|
|
|
38
39
|
implementation: GetScheduledActionUseCaseImpl,
|
|
39
40
|
dependencies: [
|
|
40
41
|
GetEntryByIdUseCase,
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
ScheduledActionModelProvider,
|
|
43
|
+
SchedulerPermissionsResolver,
|
|
43
44
|
IdentityContext
|
|
44
45
|
]
|
|
45
46
|
});
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { ScheduledActionModelProvider } 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 { SchedulerPermissionsResolver } 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 modelProvider: ScheduledActionModelProvider.Interface,\n private permissionsResolver: SchedulerPermissionsResolver.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 { id, namespace } = params;\n const permissions = this.permissionsResolver.forNamespace(namespace);\n if (!(await permissions.canRead())) {\n return Result.fail(new NotAuthorizedError());\n }\n const model = await this.modelProvider.get();\n // Get entry from CMS\n const scheduleId = ScheduledActionIdWithVersion.from(id);\n const entryResult = await this.getEntryByIdUseCase.execute<IScheduledActionEntryValues<T>>(\n 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 permissions.onlyOwnRecords();\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: [\n GetEntryByIdUseCase,\n ScheduledActionModelProvider,\n SchedulerPermissionsResolver,\n IdentityContext\n ]\n});\n"],"names":["GetScheduledActionUseCaseImpl","getEntryByIdUseCase","modelProvider","permissionsResolver","identityContext","params","id","namespace","permissions","Result","NotAuthorizedError","model","scheduleId","ScheduledActionIdWithVersion","entryResult","ScheduledActionNotFoundError","ScheduledActionPersistenceError","ownRecordsOnly","entry","action","ScheduledActionMapper","GetScheduledActionUseCase","UseCaseAbstraction","GetEntryByIdUseCase","ScheduledActionModelProvider","SchedulerPermissionsResolver","IdentityContext"],"mappings":";;;;;;;;;AAwBA,MAAMA;IACF,YACYC,mBAAkD,EAClDC,aAAqD,EACrDC,mBAA2D,EAC3DC,eAA0C,CACpD;aAJUH,mBAAmB,GAAnBA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,MAAiC,EAC6B;QAC9D,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGF;QAC1B,MAAMG,cAAc,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAACD;QAC1D,IAAI,CAAE,MAAMC,YAAY,OAAO,IAC3B,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAE3B,MAAMC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG;QAE1C,MAAMC,aAAaC,6BAA6B,IAAI,CAACP;QACrD,MAAMQ,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CACtDH,OACAC;QAGJ,IAAIE,YAAY,MAAM,IAAI;YACtB,IAAIA,AAA2B,yBAA3BA,YAAY,KAAK,CAAC,IAAI,EACtB,OAAOL,OAAO,IAAI,CAAC,IAAIM,6BAA6BH;YAGxD,OAAOH,OAAO,IAAI,CAAC,IAAIO,gCAAgCF,YAAY,KAAK;QAC5E;QAEA,MAAMG,iBAAiB,MAAMT,YAAY,cAAc;QACvD,IAAIS,gBACA;YAAA,IAAIH,YAAY,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,EACxE,OAAOL,OAAO,IAAI,CAAC,IAAIC;QAC3B;QAGJ,MAAMQ,QAAQJ,YAAY,KAAK;QAI/B,IAAII,MAAM,MAAM,CAAC,SAAS,KAAKX,WAC3B,OAAOE,OAAO,IAAI,CAAC,IAAIM,6BAA6BH;QAExD,MAAMO,SAASC,sBAAsB,QAAQ,CAAIF;QAEjD,OAAOT,OAAO,EAAE,CAACU;IACrB;AACJ;AAEO,MAAME,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetTargetScheduledActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
6
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
7
|
-
import {
|
|
7
|
+
import { SchedulerPermissionsResolver } from "../../features/permissions/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
9
|
/**
|
|
10
10
|
* Retrieves a scheduled action by its ID
|
|
@@ -16,10 +16,10 @@ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
|
16
16
|
*/
|
|
17
17
|
declare class GetTargetScheduledActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
18
18
|
private getEntryByIdUseCase;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
19
|
+
private modelProvider;
|
|
20
|
+
private permissionsResolver;
|
|
21
21
|
private identityContext;
|
|
22
|
-
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface,
|
|
22
|
+
constructor(getEntryByIdUseCase: GetEntryByIdUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, permissionsResolver: SchedulerPermissionsResolver.Interface, identityContext: IdentityContext.Interface);
|
|
23
23
|
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
|
|
24
24
|
/**
|
|
25
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.
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetTargetScheduledActionUseCase } from "./abstractions.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
4
4
|
import { NotAuthorizedError, ScheduledActionNotFoundError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
5
5
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { SchedulerPermissionsResolver } from "../permissions/abstractions.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
8
8
|
import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
|
|
9
9
|
import { ScheduledActionId } from "../../domain/ScheduledActionId.js";
|
|
10
10
|
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
11
11
|
import { SCHEDULED_ACTION_PUBLISH, SCHEDULED_ACTION_UNPUBLISH } from "../../constants.js";
|
|
12
12
|
class GetTargetScheduledActionUseCaseImpl {
|
|
13
|
-
constructor(getEntryByIdUseCase,
|
|
13
|
+
constructor(getEntryByIdUseCase, modelProvider, permissionsResolver, identityContext){
|
|
14
14
|
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
15
|
+
this.modelProvider = modelProvider;
|
|
16
|
+
this.permissionsResolver = permissionsResolver;
|
|
17
17
|
this.identityContext = identityContext;
|
|
18
18
|
}
|
|
19
19
|
async execute(params) {
|
|
20
|
-
const hasPermission = await this.permissions.canRead("action");
|
|
21
|
-
if (!hasPermission) return Result.fail(new NotAuthorizedError());
|
|
22
20
|
const { id, namespace } = params;
|
|
21
|
+
const permissions = this.permissionsResolver.forNamespace(namespace);
|
|
22
|
+
if (!await permissions.canRead()) return Result.fail(new NotAuthorizedError());
|
|
23
23
|
const entryResult = await this.getRecord(params);
|
|
24
24
|
if (entryResult.isFail()) {
|
|
25
25
|
if ("Cms/Entry/NotFound" === entryResult.error.code) return Result.fail(new ScheduledActionNotFoundError(id));
|
|
26
26
|
return Result.fail(new ScheduledActionPersistenceError(entryResult.error));
|
|
27
27
|
}
|
|
28
|
-
const ownRecordsOnly = await
|
|
28
|
+
const ownRecordsOnly = await permissions.onlyOwnRecords();
|
|
29
29
|
if (ownRecordsOnly) {
|
|
30
30
|
if (entryResult.value.createdBy.id !== this.identityContext.getIdentity().id) return Result.fail(new NotAuthorizedError());
|
|
31
31
|
}
|
|
@@ -35,27 +35,28 @@ class GetTargetScheduledActionUseCaseImpl {
|
|
|
35
35
|
return Result.ok(action);
|
|
36
36
|
}
|
|
37
37
|
async getRecord(params) {
|
|
38
|
+
const model = await this.modelProvider.get();
|
|
38
39
|
const schedulePublishId = ScheduledActionId.from({
|
|
39
40
|
namespace: params.namespace,
|
|
40
41
|
targetId: params.id,
|
|
41
42
|
actionType: SCHEDULED_ACTION_PUBLISH
|
|
42
43
|
});
|
|
43
|
-
const publishResult = await this.getEntryByIdUseCase.execute(
|
|
44
|
+
const publishResult = await this.getEntryByIdUseCase.execute(model, ScheduledActionIdWithVersion.from(schedulePublishId));
|
|
44
45
|
if (publishResult.isOk()) return publishResult;
|
|
45
46
|
const scheduleUnpublishId = ScheduledActionId.from({
|
|
46
47
|
namespace: params.namespace,
|
|
47
48
|
targetId: params.id,
|
|
48
49
|
actionType: SCHEDULED_ACTION_UNPUBLISH
|
|
49
50
|
});
|
|
50
|
-
return this.getEntryByIdUseCase.execute(
|
|
51
|
+
return this.getEntryByIdUseCase.execute(model, ScheduledActionIdWithVersion.from(scheduleUnpublishId));
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
const GetTargetScheduledActionUseCase_GetTargetScheduledActionUseCase = GetTargetScheduledActionUseCase.createImplementation({
|
|
54
55
|
implementation: GetTargetScheduledActionUseCaseImpl,
|
|
55
56
|
dependencies: [
|
|
56
57
|
GetEntryByIdUseCase,
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
ScheduledActionModelProvider,
|
|
59
|
+
SchedulerPermissionsResolver,
|
|
59
60
|
IdentityContext
|
|
60
61
|
]
|
|
61
62
|
});
|
|
@@ -1 +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 {
|
|
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 { ScheduledActionModelProvider } 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 { SchedulerPermissionsResolver } 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 modelProvider: ScheduledActionModelProvider.Interface,\n private permissionsResolver: SchedulerPermissionsResolver.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 { id, namespace } = params;\n const permissions = this.permissionsResolver.forNamespace(namespace);\n if (!(await permissions.canRead())) {\n return Result.fail(new NotAuthorizedError());\n }\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 permissions.onlyOwnRecords();\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 model = await this.modelProvider.get();\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 >(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 model,\n ScheduledActionIdWithVersion.from(scheduleUnpublishId)\n );\n }\n}\n\nexport const GetTargetScheduledActionUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetTargetScheduledActionUseCaseImpl,\n dependencies: [\n GetEntryByIdUseCase,\n ScheduledActionModelProvider,\n SchedulerPermissionsResolver,\n IdentityContext\n ]\n});\n"],"names":["GetTargetScheduledActionUseCaseImpl","getEntryByIdUseCase","modelProvider","permissionsResolver","identityContext","params","id","namespace","permissions","Result","NotAuthorizedError","entryResult","ScheduledActionNotFoundError","ScheduledActionPersistenceError","ownRecordsOnly","entry","action","ScheduledActionMapper","model","schedulePublishId","ScheduledActionId","SCHEDULED_ACTION_PUBLISH","publishResult","ScheduledActionIdWithVersion","scheduleUnpublishId","SCHEDULED_ACTION_UNPUBLISH","GetTargetScheduledActionUseCase","UseCaseAbstraction","GetEntryByIdUseCase","ScheduledActionModelProvider","SchedulerPermissionsResolver","IdentityContext"],"mappings":";;;;;;;;;;;AA0BA,MAAMA;IACF,YACYC,mBAAkD,EAClDC,aAAqD,EACrDC,mBAA2D,EAC3DC,eAA0C,CACpD;aAJUH,mBAAmB,GAAnBA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,MAAiC,EAC6B;QAC9D,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGF;QAC1B,MAAMG,cAAc,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAACD;QAC1D,IAAI,CAAE,MAAMC,YAAY,OAAO,IAC3B,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,cAAc,MAAM,IAAI,CAAC,SAAS,CAAIN;QAE5C,IAAIM,YAAY,MAAM,IAAI;YACtB,IAAIA,AAA2B,yBAA3BA,YAAY,KAAK,CAAC,IAAI,EACtB,OAAOF,OAAO,IAAI,CAAC,IAAIG,6BAA6BN;YAGxD,OAAOG,OAAO,IAAI,CAAC,IAAII,gCAAgCF,YAAY,KAAK;QAC5E;QAEA,MAAMG,iBAAiB,MAAMN,YAAY,cAAc;QACvD,IAAIM,gBACA;YAAA,IAAIH,YAAY,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE,EACxE,OAAOF,OAAO,IAAI,CAAC,IAAIC;QAC3B;QAGJ,MAAMK,QAAQJ,YAAY,KAAK;QAI/B,IAAII,MAAM,MAAM,CAAC,SAAS,KAAKR,WAC3B,OAAOE,OAAO,IAAI,CAAC,IAAIG,6BAA6BN;QAExD,MAAMU,SAASC,sBAAsB,QAAQ,CAAIF;QACjD,OAAON,OAAO,EAAE,CAACO;IACrB;IAIA,MAAc,UAAmCX,MAAiC,EAAE;QAChF,MAAMa,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG;QAC1C,MAAMC,oBAAoBC,kBAAkB,IAAI,CAAC;YAC7C,WAAWf,OAAO,SAAS;YAC3B,UAAUA,OAAO,EAAE;YACnB,YAAYgB;QAChB;QACA,MAAMC,gBAAgB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAE1DJ,OAAOK,6BAA6B,IAAI,CAACJ;QAC3C,IAAIG,cAAc,IAAI,IAClB,OAAOA;QAEX,MAAME,sBAAsBJ,kBAAkB,IAAI,CAAC;YAC/C,WAAWf,OAAO,SAAS;YAC3B,UAAUA,OAAO,EAAE;YACnB,YAAYoB;QAChB;QACA,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,CACnCP,OACAK,6BAA6B,IAAI,CAACC;IAE1C;AACJ;AAEO,MAAME,kEAAkCC,gCAAAA,oBAAuC,CAAC;IACnF,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/abstractions.js";
|
|
3
3
|
import { IListScheduledActionsParams, IListScheduledActionsResponse, ListScheduledActionsUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
6
6
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
7
|
-
import {
|
|
7
|
+
import { SchedulerPermissionsResolver } from "../../features/permissions/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
9
|
/**
|
|
10
10
|
* Lists scheduled actions with optional filtering
|
|
@@ -17,12 +17,12 @@ import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
|
17
17
|
*/
|
|
18
18
|
declare class ListScheduledActionsUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
19
19
|
private listEntriesUseCase;
|
|
20
|
-
private
|
|
20
|
+
private modelProvider;
|
|
21
21
|
private cmsWhereMapper;
|
|
22
22
|
private cmsSortMapper;
|
|
23
|
-
private
|
|
23
|
+
private permissionsResolver;
|
|
24
24
|
private identityContext;
|
|
25
|
-
constructor(listEntriesUseCase: ListLatestEntriesUseCase.Interface,
|
|
25
|
+
constructor(listEntriesUseCase: ListLatestEntriesUseCase.Interface, modelProvider: ScheduledActionModelProvider.Interface, cmsWhereMapper: CmsWhereMapper.Interface, cmsSortMapper: CmsSortMapper.Interface, permissionsResolver: SchedulerPermissionsResolver.Interface, identityContext: IdentityContext.Interface);
|
|
26
26
|
execute<T extends GenericRecord>(params: IListScheduledActionsParams): Promise<Result<IListScheduledActionsResponse<T>, UseCaseAbstraction.Error>>;
|
|
27
27
|
}
|
|
28
28
|
export declare const ListScheduledActionsUseCase: typeof ListScheduledActionsUseCaseImpl & {
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/abstractions.js";
|
|
3
3
|
import { ListScheduledActionsUseCase } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScheduledActionModelProvider } from "../../shared/abstractions.js";
|
|
5
5
|
import { NotAuthorizedError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
6
6
|
import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
7
|
-
import {
|
|
7
|
+
import { SchedulerPermissionsResolver } from "../permissions/abstractions.js";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
9
|
import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
|
|
10
10
|
class ListScheduledActionsUseCaseImpl {
|
|
11
|
-
constructor(listEntriesUseCase,
|
|
11
|
+
constructor(listEntriesUseCase, modelProvider, cmsWhereMapper, cmsSortMapper, permissionsResolver, identityContext){
|
|
12
12
|
this.listEntriesUseCase = listEntriesUseCase;
|
|
13
|
-
this.
|
|
13
|
+
this.modelProvider = modelProvider;
|
|
14
14
|
this.cmsWhereMapper = cmsWhereMapper;
|
|
15
15
|
this.cmsSortMapper = cmsSortMapper;
|
|
16
|
-
this.
|
|
16
|
+
this.permissionsResolver = permissionsResolver;
|
|
17
17
|
this.identityContext = identityContext;
|
|
18
18
|
}
|
|
19
19
|
async execute(params) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const namespace = params.where?.namespace || params.where?.namespace_startsWith;
|
|
21
|
+
const permissions = this.permissionsResolver.forNamespace(namespace);
|
|
22
|
+
if (!await permissions.canRead()) return Result.fail(new NotAuthorizedError());
|
|
23
|
+
const ownRecordsOnly = await permissions.onlyOwnRecords();
|
|
23
24
|
const { where: initialWhere, sort: sortInput, limit, after } = params;
|
|
25
|
+
const model = await this.modelProvider.get();
|
|
24
26
|
const where = this.cmsWhereMapper.map({
|
|
25
27
|
input: initialWhere || {},
|
|
26
|
-
fields:
|
|
28
|
+
fields: model.fields
|
|
27
29
|
});
|
|
28
30
|
if (ownRecordsOnly) {
|
|
29
31
|
const identity = this.identityContext.getIdentity();
|
|
@@ -31,9 +33,9 @@ class ListScheduledActionsUseCaseImpl {
|
|
|
31
33
|
}
|
|
32
34
|
const sort = this.cmsSortMapper.map({
|
|
33
35
|
input: sortInput,
|
|
34
|
-
fields:
|
|
36
|
+
fields: model.fields
|
|
35
37
|
});
|
|
36
|
-
const listResult = await this.listEntriesUseCase.execute(
|
|
38
|
+
const listResult = await this.listEntriesUseCase.execute(model, {
|
|
37
39
|
where,
|
|
38
40
|
sort,
|
|
39
41
|
limit,
|
|
@@ -51,10 +53,10 @@ const ListScheduledActionsUseCase_ListScheduledActionsUseCase = ListScheduledAct
|
|
|
51
53
|
implementation: ListScheduledActionsUseCaseImpl,
|
|
52
54
|
dependencies: [
|
|
53
55
|
ListLatestEntriesUseCase,
|
|
54
|
-
|
|
56
|
+
ScheduledActionModelProvider,
|
|
55
57
|
CmsWhereMapper,
|
|
56
58
|
CmsSortMapper,
|
|
57
|
-
|
|
59
|
+
SchedulerPermissionsResolver,
|
|
58
60
|
IdentityContext
|
|
59
61
|
]
|
|
60
62
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ListScheduledActions/ListScheduledActionsUseCase.js","sources":["../../../src/features/ListScheduledActions/ListScheduledActionsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/abstractions.js\";\nimport {\n IListScheduledActionsParams,\n IListScheduledActionsResponse,\n ListScheduledActionsUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport type { IScheduledActionEntryValues } from \"~/shared/abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/ListScheduledActions/ListScheduledActionsUseCase.js","sources":["../../../src/features/ListScheduledActions/ListScheduledActionsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/abstractions.js\";\nimport {\n IListScheduledActionsParams,\n IListScheduledActionsResponse,\n ListScheduledActionsUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport type { IScheduledActionEntryValues } from \"~/shared/abstractions.js\";\nimport { ScheduledActionModelProvider } from \"~/shared/abstractions.js\";\nimport { NotAuthorizedError, ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport { CmsSortMapper, CmsWhereMapper } from \"@webiny/api-headless-cms\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SchedulerPermissionsResolver } from \"~/features/permissions/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { ScheduledActionMapper } from \"~/domain/ScheduledActionMapper.js\";\n\n/**\n * Lists scheduled actions with optional filtering\n *\n * Flow:\n * 1. Build query filters based on where params (namespace, actionType, targetId, etc.)\n * 2. Fetch entries from CMS storage with pagination and sorting\n * 3. Transform CMS entries to IScheduledAction format\n * 4. Return paginated results with metadata\n */\nclass ListScheduledActionsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private listEntriesUseCase: ListLatestEntriesUseCase.Interface,\n private modelProvider: ScheduledActionModelProvider.Interface,\n private cmsWhereMapper: CmsWhereMapper.Interface,\n private cmsSortMapper: CmsSortMapper.Interface,\n private permissionsResolver: SchedulerPermissionsResolver.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute<T extends GenericRecord>(\n params: IListScheduledActionsParams\n ): Promise<Result<IListScheduledActionsResponse<T>, UseCaseAbstraction.Error>> {\n const namespace = params.where?.namespace || params.where?.namespace_startsWith;\n const permissions = this.permissionsResolver.forNamespace(namespace);\n\n if (!(await permissions.canRead())) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const ownRecordsOnly = await permissions.onlyOwnRecords();\n\n const { where: initialWhere, sort: sortInput, limit, after } = params;\n const model = await this.modelProvider.get();\n\n const where = this.cmsWhereMapper.map({\n input: initialWhere || {},\n fields: model.fields\n });\n\n if (ownRecordsOnly) {\n const identity = this.identityContext.getIdentity();\n where!.createdBy = identity.id;\n }\n\n const sort = this.cmsSortMapper.map({\n input: sortInput,\n fields: model.fields\n });\n // List entries from CMS\n const listResult = await this.listEntriesUseCase.execute<IScheduledActionEntryValues<T>>(\n model,\n {\n where,\n sort,\n limit,\n after\n }\n );\n\n if (listResult.isFail()) {\n return Result.fail(new ScheduledActionPersistenceError(listResult.error));\n }\n\n const { entries, meta } = listResult.value;\n\n return Result.ok({\n items: ScheduledActionMapper.toActions<T>(entries),\n meta\n });\n }\n}\n\nexport const ListScheduledActionsUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListScheduledActionsUseCaseImpl,\n dependencies: [\n ListLatestEntriesUseCase,\n ScheduledActionModelProvider,\n CmsWhereMapper,\n CmsSortMapper,\n SchedulerPermissionsResolver,\n IdentityContext\n ]\n});\n"],"names":["ListScheduledActionsUseCaseImpl","listEntriesUseCase","modelProvider","cmsWhereMapper","cmsSortMapper","permissionsResolver","identityContext","params","namespace","permissions","Result","NotAuthorizedError","ownRecordsOnly","initialWhere","sortInput","limit","after","model","where","identity","sort","listResult","ScheduledActionPersistenceError","entries","meta","ScheduledActionMapper","ListScheduledActionsUseCase","UseCaseAbstraction","ListLatestEntriesUseCase","ScheduledActionModelProvider","CmsWhereMapper","CmsSortMapper","SchedulerPermissionsResolver","IdentityContext"],"mappings":";;;;;;;;;AAyBA,MAAMA;IACF,YACYC,kBAAsD,EACtDC,aAAqD,EACrDC,cAAwC,EACxCC,aAAsC,EACtCC,mBAA2D,EAC3DC,eAA0C,CACpD;aANUL,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,MAAmC,EACwC;QAC3E,MAAMC,YAAYD,OAAO,KAAK,EAAE,aAAaA,OAAO,KAAK,EAAE;QAC3D,MAAME,cAAc,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAACD;QAE1D,IAAI,CAAE,MAAMC,YAAY,OAAO,IAC3B,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,iBAAiB,MAAMH,YAAY,cAAc;QAEvD,MAAM,EAAE,OAAOI,YAAY,EAAE,MAAMC,SAAS,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGT;QAC/D,MAAMU,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG;QAE1C,MAAMC,QAAQ,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;YAClC,OAAOL,gBAAgB,CAAC;YACxB,QAAQI,MAAM,MAAM;QACxB;QAEA,IAAIL,gBAAgB;YAChB,MAAMO,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;YACjDD,MAAO,SAAS,GAAGC,SAAS,EAAE;QAClC;QAEA,MAAMC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;YAChC,OAAON;YACP,QAAQG,MAAM,MAAM;QACxB;QAEA,MAAMI,aAAa,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CACpDJ,OACA;YACIC;YACAE;YACAL;YACAC;QACJ;QAGJ,IAAIK,WAAW,MAAM,IACjB,OAAOX,OAAO,IAAI,CAAC,IAAIY,gCAAgCD,WAAW,KAAK;QAG3E,MAAM,EAAEE,OAAO,EAAEC,IAAI,EAAE,GAAGH,WAAW,KAAK;QAE1C,OAAOX,OAAO,EAAE,CAAC;YACb,OAAOe,sBAAsB,SAAS,CAAIF;YAC1CC;QACJ;IACJ;AACJ;AAEO,MAAME,0DAA8BC,4BAAAA,oBAAuC,CAAC;IAC/E,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { NamespaceHandlerExecutioner } from "./NamespaceHandlerExecutioner.js";
|
|
3
|
+
const NamespaceHandlerExecutionerFeature = createFeature({
|
|
4
|
+
name: "NamespaceHandlerExecutioner",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(NamespaceHandlerExecutioner);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { NamespaceHandlerExecutionerFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/NamespaceHandler/feature.js","sources":["../../../src/features/NamespaceHandler/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { NamespaceHandlerExecutioner } from \"./NamespaceHandlerExecutioner.js\";\n\nexport const NamespaceHandlerExecutionerFeature = createFeature({\n name: \"NamespaceHandlerExecutioner\",\n register(container) {\n container.register(NamespaceHandlerExecutioner);\n }\n});\n"],"names":["NamespaceHandlerExecutionerFeature","createFeature","container","NamespaceHandlerExecutioner"],"mappings":";;AAGO,MAAMA,qCAAqCC,cAAc;IAC5D,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -6,7 +6,7 @@ import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEnt
|
|
|
6
6
|
import { ScheduleActionUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
7
7
|
import { GetScheduledActionUseCase } from "../../features/GetScheduledAction/abstractions.js";
|
|
8
8
|
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ScheduledActionModelProvider, SchedulerService } from "../../shared/abstractions.js";
|
|
10
10
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
11
11
|
import { NamespaceHandlerExecutioner } from "../../features/NamespaceHandler/abstractions.js";
|
|
12
12
|
/**
|
|
@@ -15,20 +15,20 @@ import { NamespaceHandlerExecutioner } from "../../features/NamespaceHandler/abs
|
|
|
15
15
|
* Flow:
|
|
16
16
|
* 1. Generate unique schedule ID from namespace+actionType+targetId
|
|
17
17
|
* 2. Check if schedule already exists (for rescheduling logic)
|
|
18
|
-
* 3. If exists: UPDATE schedule entry +
|
|
19
|
-
* 4. If new: CREATE schedule entry +
|
|
20
|
-
* 5. Rollback schedule entry if
|
|
18
|
+
* 3. If exists: UPDATE schedule entry + scheduler timer
|
|
19
|
+
* 4. If new: CREATE schedule entry + scheduler timer
|
|
20
|
+
* 5. Rollback schedule entry if the scheduler fails
|
|
21
21
|
*/
|
|
22
22
|
declare class ScheduleActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
23
23
|
private identityContext;
|
|
24
|
-
private
|
|
24
|
+
private modelProvider;
|
|
25
25
|
private schedulerService;
|
|
26
26
|
private getScheduledAction;
|
|
27
27
|
private createEntryUseCase;
|
|
28
28
|
private updateEntryUseCase;
|
|
29
29
|
private deleteEntryUseCase;
|
|
30
30
|
private namespaceHandlerExecutioner;
|
|
31
|
-
constructor(identityContext: IdentityContext.Interface,
|
|
31
|
+
constructor(identityContext: IdentityContext.Interface, modelProvider: ScheduledActionModelProvider.Interface, schedulerService: SchedulerService.Interface, getScheduledAction: GetScheduledActionUseCase.Interface, createEntryUseCase: CreateEntryUseCase.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, namespaceHandlerExecutioner: NamespaceHandlerExecutioner.Interface);
|
|
32
32
|
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
|
|
33
33
|
/**
|
|
34
34
|
* Creates a new schedule
|
|
@@ -6,16 +6,16 @@ import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEnt
|
|
|
6
6
|
import { parseIdentifier } from "@webiny/utils";
|
|
7
7
|
import { ScheduleActionUseCase } from "./abstractions.js";
|
|
8
8
|
import { GetScheduledActionUseCase } from "../GetScheduledAction/abstractions.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ScheduledActionModelProvider, SchedulerService } from "../../shared/abstractions.js";
|
|
10
10
|
import { InvalidScheduleDateError, ScheduledActionPersistenceError, SchedulerServiceError } from "../../domain/errors.js";
|
|
11
11
|
import { ScheduledActionId } from "../../domain/ScheduledActionId.js";
|
|
12
12
|
import { ScheduledActionIdWithVersion } from "../../domain/ScheduledActionIdWithVersion.js";
|
|
13
13
|
import { isValidDate } from "../../domain/isValidDate.js";
|
|
14
14
|
import { NamespaceHandlerExecutioner } from "../NamespaceHandler/abstractions.js";
|
|
15
15
|
class ScheduleActionUseCaseImpl {
|
|
16
|
-
constructor(identityContext,
|
|
16
|
+
constructor(identityContext, modelProvider, schedulerService, getScheduledAction, createEntryUseCase, updateEntryUseCase, deleteEntryUseCase, namespaceHandlerExecutioner){
|
|
17
17
|
this.identityContext = identityContext;
|
|
18
|
-
this.
|
|
18
|
+
this.modelProvider = modelProvider;
|
|
19
19
|
this.schedulerService = schedulerService;
|
|
20
20
|
this.getScheduledAction = getScheduledAction;
|
|
21
21
|
this.createEntryUseCase = createEntryUseCase;
|
|
@@ -68,26 +68,19 @@ class ScheduleActionUseCaseImpl {
|
|
|
68
68
|
async createSchedule(params) {
|
|
69
69
|
const { scheduleId: initialId, identity, payload, scheduleFor, actionType, targetId, title, namespace } = params;
|
|
70
70
|
const { id: scheduleId } = parseIdentifier(initialId);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
targetId,
|
|
77
|
-
scheduledBy: {
|
|
78
|
-
id: identity.id,
|
|
79
|
-
type: identity.type,
|
|
80
|
-
displayName: identity.displayName
|
|
81
|
-
},
|
|
82
|
-
scheduledFor: scheduleFor,
|
|
83
|
-
payload,
|
|
84
|
-
error: void 0
|
|
71
|
+
const model = await this.modelProvider.get();
|
|
72
|
+
const scheduledBy = {
|
|
73
|
+
id: identity.id,
|
|
74
|
+
type: identity.type,
|
|
75
|
+
displayName: identity.displayName
|
|
85
76
|
};
|
|
86
|
-
const createResult = await this.createEntryUseCase.execute(
|
|
77
|
+
const createResult = await this.createEntryUseCase.execute(model, {
|
|
87
78
|
id: scheduleId,
|
|
88
79
|
values: {
|
|
89
80
|
scheduledFor: scheduleFor.toISOString(),
|
|
90
|
-
scheduledBy:
|
|
81
|
+
scheduledBy: {
|
|
82
|
+
...scheduledBy
|
|
83
|
+
},
|
|
91
84
|
namespace,
|
|
92
85
|
title,
|
|
93
86
|
actionType,
|
|
@@ -97,15 +90,28 @@ class ScheduleActionUseCaseImpl {
|
|
|
97
90
|
}
|
|
98
91
|
});
|
|
99
92
|
if (createResult.isFail()) return Result.fail(new ScheduledActionPersistenceError(new Error(createResult.error.message)));
|
|
93
|
+
const scheduledAction = {
|
|
94
|
+
id: scheduleId,
|
|
95
|
+
tenant: createResult.value.tenant,
|
|
96
|
+
title,
|
|
97
|
+
namespace,
|
|
98
|
+
actionType,
|
|
99
|
+
targetId,
|
|
100
|
+
scheduledBy,
|
|
101
|
+
scheduledFor: scheduleFor,
|
|
102
|
+
payload,
|
|
103
|
+
error: void 0
|
|
104
|
+
};
|
|
100
105
|
try {
|
|
101
106
|
await this.schedulerService.create({
|
|
102
107
|
id: scheduleId,
|
|
108
|
+
tenant: createResult.value.tenant,
|
|
103
109
|
namespace,
|
|
104
110
|
scheduleFor: new Date(scheduleFor)
|
|
105
111
|
});
|
|
106
112
|
} catch (error) {
|
|
107
|
-
console.error(`Failed to create
|
|
108
|
-
await this.deleteEntryUseCase.execute(
|
|
113
|
+
console.error(`Failed to create the schedule: ${scheduleId}. Rolling back...`);
|
|
114
|
+
await this.deleteEntryUseCase.execute(model, scheduleId, {
|
|
109
115
|
force: true,
|
|
110
116
|
permanently: true
|
|
111
117
|
});
|
|
@@ -115,8 +121,9 @@ class ScheduleActionUseCaseImpl {
|
|
|
115
121
|
}
|
|
116
122
|
async reschedule(existing, scheduleFor, identity, payload) {
|
|
117
123
|
if (!payload) payload = existing.payload;
|
|
124
|
+
const model = await this.modelProvider.get();
|
|
118
125
|
const existingEntryId = ScheduledActionIdWithVersion.from(existing.id);
|
|
119
|
-
const updateResult = await this.updateEntryUseCase.execute(
|
|
126
|
+
const updateResult = await this.updateEntryUseCase.execute(model, existingEntryId, {
|
|
120
127
|
values: {
|
|
121
128
|
scheduledBy: {
|
|
122
129
|
id: identity.id,
|
|
@@ -131,6 +138,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
131
138
|
try {
|
|
132
139
|
await this.schedulerService.update({
|
|
133
140
|
id: existing.id,
|
|
141
|
+
tenant: existing.tenant,
|
|
134
142
|
namespace: existing.namespace,
|
|
135
143
|
scheduleFor: new Date(scheduleFor)
|
|
136
144
|
});
|
|
@@ -153,7 +161,7 @@ const ScheduleActionUseCase_ScheduleActionUseCase = ScheduleActionUseCase.create
|
|
|
153
161
|
implementation: ScheduleActionUseCaseImpl,
|
|
154
162
|
dependencies: [
|
|
155
163
|
IdentityContext,
|
|
156
|
-
|
|
164
|
+
ScheduledActionModelProvider,
|
|
157
165
|
SchedulerService,
|
|
158
166
|
GetScheduledActionUseCase,
|
|
159
167
|
CreateEntryUseCase,
|