@webiny/api-scheduler 6.0.0 → 6.1.0-beta.1
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 +6 -0
- package/constants.js.map +1 -1
- package/context.js +6 -0
- package/context.js.map +1 -1
- package/createEventHandler.d.ts +1 -0
- package/createEventHandler.js +1 -1
- package/createEventHandler.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 +27 -1
- package/domain/errors.js.map +1 -1
- package/domain/isValidDate.d.ts +1 -1
- package/domain/isValidDate.js +2 -2
- package/domain/isValidDate.js.map +1 -1
- package/domain/permissions.d.ts +45 -0
- package/domain/permissions.js +13 -0
- package/domain/permissions.js.map +1 -0
- package/exports/api/scheduler.d.ts +10 -0
- package/exports/api/scheduler.js +10 -0
- package/exports/api/scheduler.js.map +1 -0
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.d.ts +4 -2
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js +17 -8
- package/features/CancelScheduledAction/CancelScheduledActionUseCase.js.map +1 -1
- package/features/CancelScheduledAction/abstractions.d.ts +9 -2
- package/features/CancelScheduledAction/abstractions.js +2 -1
- package/features/CancelScheduledAction/abstractions.js.map +1 -1
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.d.ts +1 -1
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js +9 -6
- package/features/ExecuteScheduledAction/ExecuteScheduledActionUseCase.js.map +1 -1
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.d.ts +2 -2
- package/features/ExecuteScheduledAction/ScheduledActionHandlerComposite.js.map +1 -1
- package/features/ExecuteScheduledAction/abstractions.d.ts +9 -2
- package/features/ExecuteScheduledAction/abstractions.js +2 -1
- package/features/ExecuteScheduledAction/abstractions.js.map +1 -1
- package/features/GetScheduledAction/GetScheduledActionUseCase.d.ts +6 -2
- package/features/GetScheduledAction/GetScheduledActionUseCase.js +32 -15
- package/features/GetScheduledAction/GetScheduledActionUseCase.js.map +1 -1
- package/features/GetScheduledAction/abstractions.d.ts +9 -2
- package/features/GetScheduledAction/abstractions.js +2 -1
- package/features/GetScheduledAction/abstractions.js.map +1 -1
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.d.ts +32 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js +86 -0
- package/features/GetTargetScheduledAction/GetTargetScheduledActionUseCase.js.map +1 -0
- package/features/GetTargetScheduledAction/abstractions.d.ts +24 -0
- package/features/GetTargetScheduledAction/abstractions.js +4 -0
- package/features/GetTargetScheduledAction/abstractions.js.map +1 -0
- package/features/GetTargetScheduledAction/feature.d.ts +7 -0
- package/features/GetTargetScheduledAction/feature.js +17 -0
- package/features/GetTargetScheduledAction/feature.js.map +1 -0
- package/features/ListScheduledActions/ListScheduledActionsUseCase.d.ts +5 -1
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js +25 -24
- package/features/ListScheduledActions/ListScheduledActionsUseCase.js.map +1 -1
- package/features/ListScheduledActions/abstractions.d.ts +11 -3
- package/features/ListScheduledActions/abstractions.js +2 -1
- package/features/ListScheduledActions/abstractions.js.map +1 -1
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.d.ts +11 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.js +25 -0
- package/features/NamespaceHandler/NamespaceHandlerExecutioner.js.map +1 -0
- package/features/NamespaceHandler/abstractions.d.ts +50 -0
- package/features/NamespaceHandler/abstractions.js +16 -0
- package/features/NamespaceHandler/abstractions.js.map +1 -0
- package/features/NamespaceHandler/index.d.ts +1 -0
- package/features/NamespaceHandler/index.js +3 -0
- package/features/NamespaceHandler/index.js.map +1 -0
- package/features/ScheduleAction/ScheduleActionUseCase.d.ts +4 -4
- package/features/ScheduleAction/ScheduleActionUseCase.js +75 -16
- package/features/ScheduleAction/ScheduleActionUseCase.js.map +1 -1
- package/features/ScheduleAction/abstractions.d.ts +10 -10
- package/features/ScheduleAction/abstractions.js +2 -1
- package/features/ScheduleAction/abstractions.js.map +1 -1
- package/features/SchedulerFeature.js +2 -2
- package/features/SchedulerFeature.js.map +1 -1
- package/features/SchedulerService/EventBridgeSchedulerService.js +3 -1
- package/features/SchedulerService/EventBridgeSchedulerService.js.map +1 -1
- package/graphql/SchedulerGraphQLFactory.d.ts +8 -0
- package/graphql/SchedulerGraphQLFactory.js +248 -0
- package/graphql/SchedulerGraphQLFactory.js.map +1 -0
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +3 -0
- package/graphql/index.js.map +1 -0
- package/index.d.ts +0 -6
- package/index.js +0 -8
- package/index.js.map +1 -1
- package/package.json +20 -27
- package/shared/abstractions.d.ts +18 -6
- package/shared/abstractions.js +3 -0
- package/shared/abstractions.js.map +1 -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 → GetTargetScheduledAction}/index.d.ts +0 -0
- /package/features/{RunAction → GetTargetScheduledAction}/index.js +0 -0
- /package/features/{RunAction → GetTargetScheduledAction}/index.js.map +0 -0
|
@@ -2,8 +2,12 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/abstractions.js";
|
|
3
3
|
import { ListScheduledActionsUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
4
4
|
import { ScheduledActionModel } from "../../shared/abstractions.js";
|
|
5
|
-
import { ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
5
|
+
import { NotAuthorizedError, ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
6
6
|
import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
7
|
+
import { SchedulerPermissions } from "../../domain/permissions.js";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
9
|
+
import { ScheduledActionMapper } from "../../domain/ScheduledActionMapper.js";
|
|
10
|
+
|
|
7
11
|
/**
|
|
8
12
|
* Lists scheduled actions with optional filtering
|
|
9
13
|
*
|
|
@@ -14,29 +18,41 @@ import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
|
14
18
|
* 4. Return paginated results with metadata
|
|
15
19
|
*/
|
|
16
20
|
class ListScheduledActionsUseCaseImpl {
|
|
17
|
-
constructor(listEntriesUseCase, model, cmsWhereMapper, cmsSortMapper) {
|
|
21
|
+
constructor(listEntriesUseCase, model, cmsWhereMapper, cmsSortMapper, permissions, identityContext) {
|
|
18
22
|
this.listEntriesUseCase = listEntriesUseCase;
|
|
19
23
|
this.model = model;
|
|
20
24
|
this.cmsWhereMapper = cmsWhereMapper;
|
|
21
25
|
this.cmsSortMapper = cmsSortMapper;
|
|
26
|
+
this.permissions = permissions;
|
|
27
|
+
this.identityContext = identityContext;
|
|
22
28
|
}
|
|
23
29
|
async execute(params) {
|
|
30
|
+
const hasPermission = await this.permissions.canRead("action");
|
|
31
|
+
if (!hasPermission) {
|
|
32
|
+
return Result.fail(new NotAuthorizedError());
|
|
33
|
+
}
|
|
34
|
+
const ownRecordsOnly = await this.permissions.onlyOwnRecords("action");
|
|
24
35
|
const {
|
|
25
|
-
where,
|
|
36
|
+
where: initialWhere,
|
|
26
37
|
sort: sortInput,
|
|
27
38
|
limit,
|
|
28
39
|
after
|
|
29
40
|
} = params;
|
|
41
|
+
const where = this.cmsWhereMapper.map({
|
|
42
|
+
input: initialWhere || {},
|
|
43
|
+
fields: this.model.fields
|
|
44
|
+
});
|
|
45
|
+
if (ownRecordsOnly) {
|
|
46
|
+
const identity = this.identityContext.getIdentity();
|
|
47
|
+
where.createdBy = identity.id;
|
|
48
|
+
}
|
|
30
49
|
const sort = this.cmsSortMapper.map({
|
|
31
50
|
input: sortInput,
|
|
32
51
|
fields: this.model.fields
|
|
33
52
|
});
|
|
34
53
|
// List entries from CMS
|
|
35
54
|
const listResult = await this.listEntriesUseCase.execute(this.model, {
|
|
36
|
-
where
|
|
37
|
-
input: where,
|
|
38
|
-
fields: this.model.fields
|
|
39
|
-
}),
|
|
55
|
+
where,
|
|
40
56
|
sort,
|
|
41
57
|
limit,
|
|
42
58
|
after
|
|
@@ -48,30 +64,15 @@ class ListScheduledActionsUseCaseImpl {
|
|
|
48
64
|
entries,
|
|
49
65
|
meta
|
|
50
66
|
} = listResult.value;
|
|
51
|
-
|
|
52
|
-
// Transform entries to IScheduledAction format
|
|
53
|
-
const scheduledActions = entries.map(entry => {
|
|
54
|
-
return {
|
|
55
|
-
id: entry.entryId,
|
|
56
|
-
title: entry.values.title,
|
|
57
|
-
namespace: entry.values.namespace,
|
|
58
|
-
actionType: entry.values.actionType,
|
|
59
|
-
targetId: entry.values.targetId,
|
|
60
|
-
scheduledBy: entry.values.scheduledBy,
|
|
61
|
-
scheduledFor: entry.values.scheduledFor,
|
|
62
|
-
payload: entry.values.payload,
|
|
63
|
-
error: entry.values.error
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
67
|
return Result.ok({
|
|
67
|
-
items:
|
|
68
|
+
items: ScheduledActionMapper.toActions(entries),
|
|
68
69
|
meta
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
export const ListScheduledActionsUseCase = UseCaseAbstraction.createImplementation({
|
|
73
74
|
implementation: ListScheduledActionsUseCaseImpl,
|
|
74
|
-
dependencies: [ListLatestEntriesUseCase, ScheduledActionModel, CmsWhereMapper, CmsSortMapper]
|
|
75
|
+
dependencies: [ListLatestEntriesUseCase, ScheduledActionModel, CmsWhereMapper, CmsSortMapper, SchedulerPermissions.Abstraction, IdentityContext]
|
|
75
76
|
});
|
|
76
77
|
|
|
77
78
|
//# sourceMappingURL=ListScheduledActionsUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","ListLatestEntriesUseCase","ListScheduledActionsUseCase","UseCaseAbstraction","ScheduledActionModel","ScheduledActionPersistenceError","CmsSortMapper","CmsWhereMapper","ListScheduledActionsUseCaseImpl","constructor","listEntriesUseCase","model","cmsWhereMapper","cmsSortMapper","
|
|
1
|
+
{"version":3,"names":["Result","ListLatestEntriesUseCase","ListScheduledActionsUseCase","UseCaseAbstraction","ScheduledActionModel","NotAuthorizedError","ScheduledActionPersistenceError","CmsSortMapper","CmsWhereMapper","SchedulerPermissions","IdentityContext","ScheduledActionMapper","ListScheduledActionsUseCaseImpl","constructor","listEntriesUseCase","model","cmsWhereMapper","cmsSortMapper","permissions","identityContext","execute","params","hasPermission","canRead","fail","ownRecordsOnly","onlyOwnRecords","where","initialWhere","sort","sortInput","limit","after","map","input","fields","identity","getIdentity","createdBy","id","listResult","isFail","error","entries","meta","value","ok","items","toActions","createImplementation","implementation","dependencies","Abstraction"],"sources":["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 { ScheduledActionModel } 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 { SchedulerPermissions } from \"~/domain/permissions.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 model: ScheduledActionModel.Interface,\n private cmsWhereMapper: CmsWhereMapper.Interface,\n private cmsSortMapper: CmsSortMapper.Interface,\n private permissions: SchedulerPermissions.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 hasPermission = await this.permissions.canRead(\"action\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const ownRecordsOnly = await this.permissions.onlyOwnRecords(\"action\");\n\n const { where: initialWhere, sort: sortInput, limit, after } = params;\n\n const where = this.cmsWhereMapper.map({\n input: initialWhere || {},\n fields: this.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: this.model.fields\n });\n // List entries from CMS\n const listResult = await this.listEntriesUseCase.execute<IScheduledActionEntryValues<T>>(\n this.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 ScheduledActionModel,\n CmsWhereMapper,\n CmsSortMapper,\n SchedulerPermissions.Abstraction,\n IdentityContext\n ]\n});\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
3
|
-
import { ScheduledActionPersistenceError } from "../../domain/errors.js";
|
|
2
|
+
import type { IScheduledAction, ScheduledActionType } from "../../shared/abstractions.js";
|
|
3
|
+
import { ScheduledActionPersistenceError, NotAuthorizedError } from "../../domain/errors.js";
|
|
4
4
|
import type { CmsEntryListSort, CmsEntryMeta } from "@webiny/api-headless-cms/types/index.js";
|
|
5
5
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
6
6
|
/**
|
|
@@ -16,7 +16,7 @@ export type DateISOString = `${number}-${number}-${number}T${number}:${number}:$
|
|
|
16
16
|
export interface IListScheduledActionsWhere {
|
|
17
17
|
namespace?: string;
|
|
18
18
|
namespace_startsWith?: string;
|
|
19
|
-
actionType?:
|
|
19
|
+
actionType?: ScheduledActionType;
|
|
20
20
|
targetId?: string;
|
|
21
21
|
targetId_startsWith?: string;
|
|
22
22
|
scheduledBy?: string;
|
|
@@ -24,6 +24,7 @@ export interface IListScheduledActionsWhere {
|
|
|
24
24
|
scheduledFor_gte?: DateISOString;
|
|
25
25
|
scheduledFor_lte?: DateISOString;
|
|
26
26
|
}
|
|
27
|
+
export type IListScheduledActionsMeta = CmsEntryMeta;
|
|
27
28
|
export interface IListScheduledActionsParams {
|
|
28
29
|
where: IListScheduledActionsWhere;
|
|
29
30
|
sort?: CmsEntryListSort;
|
|
@@ -36,14 +37,21 @@ export interface IListScheduledActionsResponse<T extends GenericRecord> {
|
|
|
36
37
|
}
|
|
37
38
|
export interface IListScheduledActionsErrors {
|
|
38
39
|
persistence: ScheduledActionPersistenceError;
|
|
40
|
+
unauthorized: NotAuthorizedError;
|
|
39
41
|
}
|
|
40
42
|
type ListScheduledActionsError = IListScheduledActionsErrors[keyof IListScheduledActionsErrors];
|
|
41
43
|
export interface IListScheduledActionsUseCase {
|
|
42
44
|
execute<T extends GenericRecord>(params: IListScheduledActionsParams): Promise<Result<IListScheduledActionsResponse<T>, ListScheduledActionsError>>;
|
|
43
45
|
}
|
|
46
|
+
/** List scheduled actions. */
|
|
44
47
|
export declare const ListScheduledActionsUseCase: import("@webiny/di").Abstraction<IListScheduledActionsUseCase>;
|
|
45
48
|
export declare namespace ListScheduledActionsUseCase {
|
|
46
49
|
type Interface = IListScheduledActionsUseCase;
|
|
47
50
|
type Error = ListScheduledActionsError;
|
|
51
|
+
type Params = IListScheduledActionsParams;
|
|
52
|
+
type Where = IListScheduledActionsWhere;
|
|
53
|
+
type Sort = CmsEntryListSort;
|
|
54
|
+
type Meta = IListScheduledActionsMeta;
|
|
55
|
+
type Response<T extends GenericRecord> = IListScheduledActionsResponse<T>;
|
|
48
56
|
}
|
|
49
57
|
export {};
|
|
@@ -10,6 +10,7 @@ import { createAbstraction } from "@webiny/feature/api";
|
|
|
10
10
|
* (publish, unpublish, delete) for a specific content model.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** List scheduled actions. */
|
|
14
|
+
export const ListScheduledActionsUseCase = createAbstraction("Scheduler/ListScheduledActionsUseCase");
|
|
14
15
|
|
|
15
16
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAbstraction","ListScheduledActionsUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction } from \"~/shared/abstractions.js\";\nimport { ScheduledActionPersistenceError } from \"~/domain/errors.js\";\nimport type { CmsEntryListSort, CmsEntryMeta } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * ListScheduledActionsUseCase - List scheduled actions with optional filtering\n *\n * Used to retrieve all scheduled actions for a namespace (e.g., all actions for Article model)\n * or all actions of a specific type across namespaces.\n *\n * This is critical for CMS CRUD views where we need to show ALL scheduled actions\n * (publish, unpublish, delete) for a specific content model.\n */\n\nexport type DateISOString =\n `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`;\n\nexport interface IListScheduledActionsWhere {\n namespace?: string;\n namespace_startsWith?: string;\n actionType?:
|
|
1
|
+
{"version":3,"names":["createAbstraction","ListScheduledActionsUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { IScheduledAction, ScheduledActionType } from \"~/shared/abstractions.js\";\nimport { ScheduledActionPersistenceError, NotAuthorizedError } from \"~/domain/errors.js\";\nimport type { CmsEntryListSort, CmsEntryMeta } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\n/**\n * ListScheduledActionsUseCase - List scheduled actions with optional filtering\n *\n * Used to retrieve all scheduled actions for a namespace (e.g., all actions for Article model)\n * or all actions of a specific type across namespaces.\n *\n * This is critical for CMS CRUD views where we need to show ALL scheduled actions\n * (publish, unpublish, delete) for a specific content model.\n */\n\nexport type DateISOString =\n `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`;\n\nexport interface IListScheduledActionsWhere {\n namespace?: string;\n namespace_startsWith?: string;\n actionType?: ScheduledActionType;\n targetId?: string;\n targetId_startsWith?: string;\n scheduledBy?: string;\n scheduledFor?: DateISOString;\n scheduledFor_gte?: DateISOString;\n scheduledFor_lte?: DateISOString;\n}\n\nexport type IListScheduledActionsMeta = CmsEntryMeta;\n\nexport interface IListScheduledActionsParams {\n where: IListScheduledActionsWhere;\n sort?: CmsEntryListSort;\n limit?: number;\n after?: string;\n}\n\nexport interface IListScheduledActionsResponse<T extends GenericRecord> {\n items: IScheduledAction<T>[];\n meta: CmsEntryMeta;\n}\n\nexport interface IListScheduledActionsErrors {\n persistence: ScheduledActionPersistenceError;\n unauthorized: NotAuthorizedError;\n}\n\ntype ListScheduledActionsError = IListScheduledActionsErrors[keyof IListScheduledActionsErrors];\n\nexport interface IListScheduledActionsUseCase {\n execute<T extends GenericRecord>(\n params: IListScheduledActionsParams\n ): Promise<Result<IListScheduledActionsResponse<T>, ListScheduledActionsError>>;\n}\n\n/** List scheduled actions. */\nexport const ListScheduledActionsUseCase = createAbstraction<IListScheduledActionsUseCase>(\n \"Scheduler/ListScheduledActionsUseCase\"\n);\n\nexport namespace ListScheduledActionsUseCase {\n export type Interface = IListScheduledActionsUseCase;\n export type Error = ListScheduledActionsError;\n export type Params = IListScheduledActionsParams;\n export type Where = IListScheduledActionsWhere;\n export type Sort = CmsEntryListSort;\n export type Meta = IListScheduledActionsMeta;\n export type Response<T extends GenericRecord> = IListScheduledActionsResponse<T>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAOvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA4CA;AACA,OAAO,MAAMC,2BAA2B,GAAGD,iBAAiB,CACxD,uCACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NamespaceHandler, NamespaceHandlerExecutioner as NamespaceHandlerExecutionerAbstraction } from "./abstractions.js";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
|
+
declare class NamespaceHandlerExecutionerImpl implements NamespaceHandlerExecutionerAbstraction.Interface {
|
|
4
|
+
private readonly namespaceHandlers;
|
|
5
|
+
constructor(namespaceHandlers: NamespaceHandler.Interface<GenericRecord>[]);
|
|
6
|
+
execute(params: NamespaceHandlerExecutionerAbstraction.Params): NamespaceHandlerExecutionerAbstraction.Response;
|
|
7
|
+
}
|
|
8
|
+
export declare const NamespaceHandlerExecutioner: typeof NamespaceHandlerExecutionerImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").INamespaceHandlerExecutioner>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NamespaceHandler, NamespaceHandlerExecutioner as NamespaceHandlerExecutionerAbstraction } from "./abstractions.js";
|
|
2
|
+
import { Result } from "@webiny/feature/exports/api.js";
|
|
3
|
+
import { NamespaceHandlerNotFoundError } from "../../domain/errors.js";
|
|
4
|
+
class NamespaceHandlerExecutionerImpl {
|
|
5
|
+
constructor(namespaceHandlers) {
|
|
6
|
+
this.namespaceHandlers = namespaceHandlers;
|
|
7
|
+
}
|
|
8
|
+
async execute(params) {
|
|
9
|
+
for (const handler of this.namespaceHandlers) {
|
|
10
|
+
if (handler.canHandle(params.namespace) === false) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
return handler.execute(params);
|
|
14
|
+
}
|
|
15
|
+
return Result.fail(new NamespaceHandlerNotFoundError(params.namespace));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const NamespaceHandlerExecutioner = NamespaceHandlerExecutionerAbstraction.createImplementation({
|
|
19
|
+
implementation: NamespaceHandlerExecutionerImpl,
|
|
20
|
+
dependencies: [[NamespaceHandler, {
|
|
21
|
+
multiple: true
|
|
22
|
+
}]]
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=NamespaceHandlerExecutioner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NamespaceHandler","NamespaceHandlerExecutioner","NamespaceHandlerExecutionerAbstraction","Result","NamespaceHandlerNotFoundError","NamespaceHandlerExecutionerImpl","constructor","namespaceHandlers","execute","params","handler","canHandle","namespace","fail","createImplementation","implementation","dependencies","multiple"],"sources":["NamespaceHandlerExecutioner.ts"],"sourcesContent":["import {\n NamespaceHandler,\n NamespaceHandlerExecutioner as NamespaceHandlerExecutionerAbstraction\n} from \"./abstractions.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport { NamespaceHandlerNotFoundError } from \"~/domain/errors.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nclass NamespaceHandlerExecutionerImpl implements NamespaceHandlerExecutionerAbstraction.Interface {\n public constructor(\n private readonly namespaceHandlers: NamespaceHandler.Interface<GenericRecord>[]\n ) {}\n\n public async execute(\n params: NamespaceHandlerExecutionerAbstraction.Params\n ): NamespaceHandlerExecutionerAbstraction.Response {\n for (const handler of this.namespaceHandlers) {\n if (handler.canHandle(params.namespace) === false) {\n continue;\n }\n return handler.execute(params);\n }\n\n return Result.fail(new NamespaceHandlerNotFoundError(params.namespace));\n }\n}\n\nexport const NamespaceHandlerExecutioner =\n NamespaceHandlerExecutionerAbstraction.createImplementation({\n implementation: NamespaceHandlerExecutionerImpl,\n dependencies: [\n [\n NamespaceHandler,\n {\n multiple: true\n }\n ]\n ]\n });\n"],"mappings":"AAAA,SACIA,gBAAgB,EAChBC,2BAA2B,IAAIC,sCAAsC;AAEzE,SAASC,MAAM,QAAQ,gCAAgC;AACvD,SAASC,6BAA6B;AAGtC,MAAMC,+BAA+B,CAA6D;EACvFC,WAAWA,CACGC,iBAA8D,EACjF;IAAA,KADmBA,iBAA8D,GAA9DA,iBAA8D;EAChF;EAEH,MAAaC,OAAOA,CAChBC,MAAqD,EACN;IAC/C,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACH,iBAAiB,EAAE;MAC1C,IAAIG,OAAO,CAACC,SAAS,CAACF,MAAM,CAACG,SAAS,CAAC,KAAK,KAAK,EAAE;QAC/C;MACJ;MACA,OAAOF,OAAO,CAACF,OAAO,CAACC,MAAM,CAAC;IAClC;IAEA,OAAON,MAAM,CAACU,IAAI,CAAC,IAAIT,6BAA6B,CAACK,MAAM,CAACG,SAAS,CAAC,CAAC;EAC3E;AACJ;AAEA,OAAO,MAAMX,2BAA2B,GACpCC,sCAAsC,CAACY,oBAAoB,CAAC;EACxDC,cAAc,EAAEV,+BAA+B;EAC/CW,YAAY,EAAE,CACV,CACIhB,gBAAgB,EAChB;IACIiB,QAAQ,EAAE;EACd,CAAC,CACJ;AAET,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
|
+
import type { ScheduledActionType } from "../../shared/abstractions.js";
|
|
4
|
+
import { NamespaceHandlerNotFoundError } from "../../domain/errors.js";
|
|
5
|
+
export interface INamespaceHandlerErrors {
|
|
6
|
+
notFound: NamespaceHandlerNotFoundError;
|
|
7
|
+
}
|
|
8
|
+
type NamespaceHandlerError = INamespaceHandlerErrors[keyof INamespaceHandlerErrors];
|
|
9
|
+
/**
|
|
10
|
+
* Handling of specific app.
|
|
11
|
+
*/
|
|
12
|
+
export interface INamespaceHandlerParams {
|
|
13
|
+
scheduleId: string;
|
|
14
|
+
targetId: string;
|
|
15
|
+
actionType: ScheduledActionType;
|
|
16
|
+
namespace: string;
|
|
17
|
+
immediately: boolean | undefined;
|
|
18
|
+
scheduleFor: Date;
|
|
19
|
+
}
|
|
20
|
+
export type INamespaceHandlerResult<T extends GenericRecord = GenericRecord> = T & {
|
|
21
|
+
title: string;
|
|
22
|
+
targetId: string;
|
|
23
|
+
actionType: ScheduledActionType;
|
|
24
|
+
namespace: string;
|
|
25
|
+
scheduleId: string;
|
|
26
|
+
};
|
|
27
|
+
export interface INamespaceHandler<T extends GenericRecord = GenericRecord> {
|
|
28
|
+
canHandle(namespace: string): boolean;
|
|
29
|
+
execute(params: INamespaceHandlerParams): Promise<Result<INamespaceHandlerResult<T>, NamespaceHandlerError>>;
|
|
30
|
+
}
|
|
31
|
+
/** Handle namespace-specific scheduled action logic. */
|
|
32
|
+
export declare const NamespaceHandler: import("@webiny/di").Abstraction<INamespaceHandler<GenericRecord>>;
|
|
33
|
+
export declare namespace NamespaceHandler {
|
|
34
|
+
type Interface<T extends GenericRecord> = INamespaceHandler<T>;
|
|
35
|
+
type Response<T extends GenericRecord> = Promise<Result<INamespaceHandlerResult<T>, NamespaceHandlerError>>;
|
|
36
|
+
type Params = INamespaceHandlerParams;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Executioner of the app handlers.
|
|
40
|
+
*/
|
|
41
|
+
export interface INamespaceHandlerExecutioner {
|
|
42
|
+
execute<T extends GenericRecord = GenericRecord>(params: INamespaceHandlerParams): Promise<Result<INamespaceHandlerResult<T>, NamespaceHandlerError>>;
|
|
43
|
+
}
|
|
44
|
+
export declare const NamespaceHandlerExecutioner: import("@webiny/di").Abstraction<INamespaceHandlerExecutioner>;
|
|
45
|
+
export declare namespace NamespaceHandlerExecutioner {
|
|
46
|
+
type Interface = INamespaceHandlerExecutioner;
|
|
47
|
+
type Response = Promise<Result<INamespaceHandlerResult, NamespaceHandlerError>>;
|
|
48
|
+
type Params = INamespaceHandlerParams;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handling of specific app.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Handle namespace-specific scheduled action logic. */
|
|
8
|
+
export const NamespaceHandler = createAbstraction("Scheduler/NamespaceHandler");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Executioner of the app handlers.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const NamespaceHandlerExecutioner = createAbstraction("Scheduler/NamespaceHandlerExecutioner");
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","NamespaceHandler","NamespaceHandlerExecutioner"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { ScheduledActionType } from \"~/shared/abstractions.js\";\nimport { NamespaceHandlerNotFoundError } from \"~/domain/errors.js\";\n\nexport interface INamespaceHandlerErrors {\n notFound: NamespaceHandlerNotFoundError;\n}\n\ntype NamespaceHandlerError = INamespaceHandlerErrors[keyof INamespaceHandlerErrors];\n/**\n * Handling of specific app.\n */\nexport interface INamespaceHandlerParams {\n scheduleId: string;\n targetId: string;\n actionType: ScheduledActionType;\n namespace: string;\n immediately: boolean | undefined;\n scheduleFor: Date;\n}\n\nexport type INamespaceHandlerResult<T extends GenericRecord = GenericRecord> = T & {\n title: string;\n targetId: string;\n actionType: ScheduledActionType;\n namespace: string;\n scheduleId: string;\n};\n\nexport interface INamespaceHandler<T extends GenericRecord = GenericRecord> {\n canHandle(namespace: string): boolean;\n execute(\n params: INamespaceHandlerParams\n ): Promise<Result<INamespaceHandlerResult<T>, NamespaceHandlerError>>;\n}\n\n/** Handle namespace-specific scheduled action logic. */\nexport const NamespaceHandler = createAbstraction<INamespaceHandler>(\"Scheduler/NamespaceHandler\");\n\nexport namespace NamespaceHandler {\n export type Interface<T extends GenericRecord> = INamespaceHandler<T>;\n export type Response<T extends GenericRecord> = Promise<\n Result<INamespaceHandlerResult<T>, NamespaceHandlerError>\n >;\n export type Params = INamespaceHandlerParams;\n}\n\n/**\n * Executioner of the app handlers.\n */\n\nexport interface INamespaceHandlerExecutioner {\n execute<T extends GenericRecord = GenericRecord>(\n params: INamespaceHandlerParams\n ): Promise<Result<INamespaceHandlerResult<T>, NamespaceHandlerError>>;\n}\n\nexport const NamespaceHandlerExecutioner = createAbstraction<INamespaceHandlerExecutioner>(\n \"Scheduler/NamespaceHandlerExecutioner\"\n);\n\nexport namespace NamespaceHandlerExecutioner {\n export type Interface = INamespaceHandlerExecutioner;\n export type Response = Promise<Result<INamespaceHandlerResult, NamespaceHandlerError>>;\n export type Params = INamespaceHandlerParams;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;;AAU/D;AACA;AACA;;AAyBA;AACA,OAAO,MAAMC,gBAAgB,GAAGD,iBAAiB,CAAoB,4BAA4B,CAAC;;AAUlG;AACA;AACA;;AAQA,OAAO,MAAME,2BAA2B,GAAGF,iBAAiB,CACxD,uCACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NamespaceHandler } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NamespaceHandler"],"sources":["index.ts"],"sourcesContent":["export { NamespaceHandler } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,gBAAgB","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ import { GetScheduledActionUseCase } from "../../features/GetScheduledAction/abs
|
|
|
8
8
|
import type { IScheduledAction } from "../../shared/abstractions.js";
|
|
9
9
|
import { ScheduledActionModel, SchedulerService } from "../../shared/abstractions.js";
|
|
10
10
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
11
|
+
import { NamespaceHandlerExecutioner } from "../../features/NamespaceHandler/abstractions.js";
|
|
11
12
|
/**
|
|
12
13
|
* Schedules an action for future execution
|
|
13
14
|
*
|
|
@@ -17,8 +18,6 @@ import type { GenericRecord } from "@webiny/api/types.js";
|
|
|
17
18
|
* 3. If exists: UPDATE schedule entry + EventBridge schedule
|
|
18
19
|
* 4. If new: CREATE schedule entry + EventBridge schedule
|
|
19
20
|
* 5. Rollback schedule entry if EventBridge fails
|
|
20
|
-
*
|
|
21
|
-
* Note: Does NOT handle immediate execution - apps use direct use cases for that
|
|
22
21
|
*/
|
|
23
22
|
declare class ScheduleActionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
24
23
|
private identityContext;
|
|
@@ -28,8 +27,9 @@ declare class ScheduleActionUseCaseImpl implements UseCaseAbstraction.Interface
|
|
|
28
27
|
private createEntryUseCase;
|
|
29
28
|
private updateEntryUseCase;
|
|
30
29
|
private deleteEntryUseCase;
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
private namespaceHandlerExecutioner;
|
|
31
|
+
constructor(identityContext: IdentityContext.Interface, model: ScheduledActionModel.Interface, schedulerService: SchedulerService.Interface, getScheduledAction: GetScheduledActionUseCase.Interface, createEntryUseCase: CreateEntryUseCase.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, deleteEntryUseCase: DeleteEntryUseCase.Interface, namespaceHandlerExecutioner: NamespaceHandlerExecutioner.Interface);
|
|
32
|
+
execute<T extends GenericRecord>(params: UseCaseAbstraction.Params): Promise<Result<IScheduledAction<T>, UseCaseAbstraction.Error>>;
|
|
33
33
|
/**
|
|
34
34
|
* Creates a new schedule
|
|
35
35
|
*/
|
|
@@ -11,6 +11,7 @@ import { InvalidScheduleDateError, ScheduledActionPersistenceError, SchedulerSer
|
|
|
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
|
+
import { NamespaceHandlerExecutioner } from "../NamespaceHandler/abstractions.js";
|
|
14
15
|
/**
|
|
15
16
|
* Schedules an action for future execution
|
|
16
17
|
*
|
|
@@ -20,11 +21,9 @@ import { isValidDate } from "../../domain/isValidDate.js";
|
|
|
20
21
|
* 3. If exists: UPDATE schedule entry + EventBridge schedule
|
|
21
22
|
* 4. If new: CREATE schedule entry + EventBridge schedule
|
|
22
23
|
* 5. Rollback schedule entry if EventBridge fails
|
|
23
|
-
*
|
|
24
|
-
* Note: Does NOT handle immediate execution - apps use direct use cases for that
|
|
25
24
|
*/
|
|
26
25
|
class ScheduleActionUseCaseImpl {
|
|
27
|
-
constructor(identityContext, model, schedulerService, getScheduledAction, createEntryUseCase, updateEntryUseCase, deleteEntryUseCase) {
|
|
26
|
+
constructor(identityContext, model, schedulerService, getScheduledAction, createEntryUseCase, updateEntryUseCase, deleteEntryUseCase, namespaceHandlerExecutioner) {
|
|
28
27
|
this.identityContext = identityContext;
|
|
29
28
|
this.model = model;
|
|
30
29
|
this.schedulerService = schedulerService;
|
|
@@ -32,23 +31,61 @@ class ScheduleActionUseCaseImpl {
|
|
|
32
31
|
this.createEntryUseCase = createEntryUseCase;
|
|
33
32
|
this.updateEntryUseCase = updateEntryUseCase;
|
|
34
33
|
this.deleteEntryUseCase = deleteEntryUseCase;
|
|
34
|
+
this.namespaceHandlerExecutioner = namespaceHandlerExecutioner;
|
|
35
35
|
}
|
|
36
36
|
async execute(params) {
|
|
37
37
|
const identity = this.identityContext.getIdentity();
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let scheduleFor = params.scheduleFor;
|
|
39
|
+
/**
|
|
40
|
+
* Immediately - publish in past
|
|
41
|
+
*/
|
|
42
|
+
if (!params.immediately && !isValidDate(scheduleFor)) {
|
|
43
|
+
return Result.fail(new InvalidScheduleDateError(scheduleFor));
|
|
44
|
+
} else if (params.immediately) {
|
|
45
|
+
// If the action should be executed immediately, we set the scheduleFor to the current date.
|
|
46
|
+
// Calculate the soonest possible execution time.
|
|
47
|
+
// Add at least 90 seconds of buffer to ensure EventBridge can process the schedule.
|
|
48
|
+
scheduleFor = new Date(Date.now() + 90000);
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
// Generate unique schedule ID
|
|
43
|
-
const actionId = ScheduledActionId.from(
|
|
52
|
+
const actionId = ScheduledActionId.from({
|
|
53
|
+
namespace: params.namespace,
|
|
54
|
+
targetId: params.targetId,
|
|
55
|
+
actionType: params.actionType
|
|
56
|
+
});
|
|
44
57
|
const scheduleId = ScheduledActionIdWithVersion.from(actionId);
|
|
45
|
-
const existingResult = await this.getScheduledAction.execute(
|
|
58
|
+
const existingResult = await this.getScheduledAction.execute({
|
|
59
|
+
namespace: params.namespace,
|
|
60
|
+
id: scheduleId
|
|
61
|
+
});
|
|
62
|
+
const namespaceHandlerResult = await this.namespaceHandlerExecutioner.execute({
|
|
63
|
+
scheduleId: actionId,
|
|
64
|
+
immediately: params.immediately,
|
|
65
|
+
scheduleFor,
|
|
66
|
+
targetId: params.targetId,
|
|
67
|
+
actionType: params.actionType,
|
|
68
|
+
namespace: params.namespace
|
|
69
|
+
});
|
|
70
|
+
if (namespaceHandlerResult.isFail()) {
|
|
71
|
+
return Result.fail(namespaceHandlerResult.error);
|
|
72
|
+
}
|
|
73
|
+
const payload = namespaceHandlerResult.value;
|
|
46
74
|
if (existingResult.isFail()) {
|
|
47
75
|
const error = existingResult.error;
|
|
48
76
|
|
|
49
77
|
// NotFound means the action was not yet scheduled
|
|
50
78
|
if (error.code === "Scheduler/ScheduledAction/NotFound") {
|
|
51
|
-
return this.createSchedule(
|
|
79
|
+
return this.createSchedule({
|
|
80
|
+
scheduleId,
|
|
81
|
+
title: payload.title,
|
|
82
|
+
namespace: params.namespace,
|
|
83
|
+
actionType: params.actionType,
|
|
84
|
+
targetId: params.targetId,
|
|
85
|
+
scheduleFor,
|
|
86
|
+
identity,
|
|
87
|
+
payload
|
|
88
|
+
});
|
|
52
89
|
}
|
|
53
90
|
if (error.code === "Scheduler/ScheduledAction/PersistenceError") {
|
|
54
91
|
return Result.fail(error);
|
|
@@ -57,16 +94,26 @@ class ScheduleActionUseCaseImpl {
|
|
|
57
94
|
|
|
58
95
|
// Reschedule existing action
|
|
59
96
|
const scheduledAction = existingResult.value;
|
|
60
|
-
return this.reschedule(scheduledAction, params.scheduleFor, identity,
|
|
97
|
+
return this.reschedule(scheduledAction, params.scheduleFor, identity, payload);
|
|
61
98
|
}
|
|
62
99
|
|
|
63
100
|
/**
|
|
64
101
|
* Creates a new schedule
|
|
65
102
|
*/
|
|
66
|
-
async createSchedule(
|
|
103
|
+
async createSchedule(params) {
|
|
104
|
+
const {
|
|
105
|
+
scheduleId: initialId,
|
|
106
|
+
identity,
|
|
107
|
+
payload,
|
|
108
|
+
scheduleFor,
|
|
109
|
+
actionType,
|
|
110
|
+
targetId,
|
|
111
|
+
title,
|
|
112
|
+
namespace
|
|
113
|
+
} = params;
|
|
67
114
|
const {
|
|
68
115
|
id: scheduleId
|
|
69
|
-
} = parseIdentifier(
|
|
116
|
+
} = parseIdentifier(initialId);
|
|
70
117
|
const scheduledAction = {
|
|
71
118
|
id: scheduleId,
|
|
72
119
|
title,
|
|
@@ -79,13 +126,23 @@ class ScheduleActionUseCaseImpl {
|
|
|
79
126
|
displayName: identity.displayName
|
|
80
127
|
},
|
|
81
128
|
scheduledFor: scheduleFor,
|
|
82
|
-
payload
|
|
129
|
+
payload,
|
|
130
|
+
error: undefined
|
|
83
131
|
};
|
|
84
132
|
|
|
85
133
|
// Create CMS entry
|
|
86
134
|
const createResult = await this.createEntryUseCase.execute(this.model, {
|
|
87
135
|
id: scheduleId,
|
|
88
|
-
values:
|
|
136
|
+
values: {
|
|
137
|
+
scheduledFor: scheduleFor.toISOString(),
|
|
138
|
+
scheduledBy: scheduledAction.scheduledBy,
|
|
139
|
+
namespace,
|
|
140
|
+
title,
|
|
141
|
+
actionType,
|
|
142
|
+
targetId,
|
|
143
|
+
payload,
|
|
144
|
+
error: undefined
|
|
145
|
+
}
|
|
89
146
|
});
|
|
90
147
|
if (createResult.isFail()) {
|
|
91
148
|
return Result.fail(new ScheduledActionPersistenceError(new Error(createResult.error.message)));
|
|
@@ -95,6 +152,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
95
152
|
try {
|
|
96
153
|
await this.schedulerService.create({
|
|
97
154
|
id: scheduleId,
|
|
155
|
+
namespace,
|
|
98
156
|
scheduleFor: new Date(scheduleFor)
|
|
99
157
|
});
|
|
100
158
|
} catch (error) {
|
|
@@ -114,7 +172,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
114
172
|
*/
|
|
115
173
|
async reschedule(existing, scheduleFor, identity, payload) {
|
|
116
174
|
// Make sure we don't unset the existing payload.
|
|
117
|
-
if (!payload
|
|
175
|
+
if (!payload) {
|
|
118
176
|
payload = existing.payload;
|
|
119
177
|
}
|
|
120
178
|
|
|
@@ -127,7 +185,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
127
185
|
type: identity.type,
|
|
128
186
|
displayName: identity.displayName
|
|
129
187
|
},
|
|
130
|
-
scheduledFor: scheduleFor,
|
|
188
|
+
scheduledFor: scheduleFor.toISOString(),
|
|
131
189
|
payload
|
|
132
190
|
}
|
|
133
191
|
});
|
|
@@ -139,6 +197,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
139
197
|
try {
|
|
140
198
|
await this.schedulerService.update({
|
|
141
199
|
id: existing.id,
|
|
200
|
+
namespace: existing.namespace,
|
|
142
201
|
scheduleFor: new Date(scheduleFor)
|
|
143
202
|
});
|
|
144
203
|
} catch (error) {
|
|
@@ -158,7 +217,7 @@ class ScheduleActionUseCaseImpl {
|
|
|
158
217
|
}
|
|
159
218
|
export const ScheduleActionUseCase = UseCaseAbstraction.createImplementation({
|
|
160
219
|
implementation: ScheduleActionUseCaseImpl,
|
|
161
|
-
dependencies: [IdentityContext, ScheduledActionModel, SchedulerService, GetScheduledActionUseCase, CreateEntryUseCase, UpdateEntryUseCase, DeleteEntryUseCase]
|
|
220
|
+
dependencies: [IdentityContext, ScheduledActionModel, SchedulerService, GetScheduledActionUseCase, CreateEntryUseCase, UpdateEntryUseCase, DeleteEntryUseCase, NamespaceHandlerExecutioner]
|
|
162
221
|
});
|
|
163
222
|
|
|
164
223
|
//# sourceMappingURL=ScheduleActionUseCase.js.map
|