@webiny/api-headless-cms-scheduler 6.5.2-beta.2 → 6.5.2-beta.3
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/exports/api/cms/scheduler.d.ts +1 -0
- package/exports/api/cms/scheduler.js +1 -0
- package/features/NamespaceHandler/NamespaceHandler.d.ts +3 -1
- package/features/NamespaceHandler/NamespaceHandler.js +18 -2
- package/features/NamespaceHandler/NamespaceHandler.js.map +1 -1
- package/features/ScheduleEntryGuard/abstractions.d.ts +20 -0
- package/features/ScheduleEntryGuard/abstractions.js +5 -0
- package/features/ScheduleEntryGuard/abstractions.js.map +1 -0
- package/features/ScheduleEntryGuard/index.d.ts +1 -0
- package/features/ScheduleEntryGuard/index.js +1 -0
- package/package.json +14 -14
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { SchedulePublishEntryUseCase } from "../../../features/SchedulePublishEntryUseCase/abstractions.js";
|
|
2
2
|
export { ScheduleUnpublishEntryUseCase } from "../../../features/ScheduleUnpublishEntryUseCase/abstractions.js";
|
|
3
|
+
export { ScheduleEntryGuard } from "../../../features/ScheduleEntryGuard/index.js";
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { SchedulePublishEntryUseCase } from "../../../features/SchedulePublishEntryUseCase/abstractions.js";
|
|
2
2
|
export { ScheduleUnpublishEntryUseCase } from "../../../features/ScheduleUnpublishEntryUseCase/abstractions.js";
|
|
3
|
+
export { ScheduleEntryGuard } from "../../../features/ScheduleEntryGuard/index.js";
|
|
@@ -2,12 +2,14 @@ import { NamespaceHandler as NamespaceHandlerAbstraction } from "@webiny/api-sch
|
|
|
2
2
|
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
3
3
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
4
4
|
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
5
|
+
import { ScheduleEntryGuard } from "../../features/ScheduleEntryGuard/index.js";
|
|
5
6
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
6
7
|
declare class NamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {
|
|
7
8
|
private getModelUseCase;
|
|
8
9
|
private getEntryByIdUseCase;
|
|
9
10
|
private accessControl;
|
|
10
|
-
|
|
11
|
+
private scheduleEntryGuards;
|
|
12
|
+
constructor(getModelUseCase: GetModelUseCase.Interface, getEntryByIdUseCase: GetEntryByIdUseCase.Interface, accessControl: AccessControl.Interface, scheduleEntryGuards: ScheduleEntryGuard.Interface[]);
|
|
11
13
|
canHandle(namespace: string): boolean;
|
|
12
14
|
execute(params: NamespaceHandlerAbstraction.Params): NamespaceHandlerAbstraction.Response<GenericRecord>;
|
|
13
15
|
}
|
|
@@ -4,11 +4,13 @@ import { Result } from "@webiny/feature/exports/api.js";
|
|
|
4
4
|
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
5
5
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
6
|
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
|
+
import { ScheduleEntryGuard } from "../ScheduleEntryGuard/index.js";
|
|
7
8
|
class NamespaceHandlerImpl {
|
|
8
|
-
constructor(getModelUseCase, getEntryByIdUseCase, accessControl){
|
|
9
|
+
constructor(getModelUseCase, getEntryByIdUseCase, accessControl, scheduleEntryGuards){
|
|
9
10
|
this.getModelUseCase = getModelUseCase;
|
|
10
11
|
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
11
12
|
this.accessControl = accessControl;
|
|
13
|
+
this.scheduleEntryGuards = scheduleEntryGuards;
|
|
12
14
|
}
|
|
13
15
|
canHandle(namespace) {
|
|
14
16
|
const modelId = extractModelIdFromNamespace(namespace);
|
|
@@ -29,6 +31,14 @@ class NamespaceHandlerImpl {
|
|
|
29
31
|
pw: params.actionType === ScheduledActionTypePublish ? "p" : "u"
|
|
30
32
|
});
|
|
31
33
|
if (!canSchedule) return Result.fail(new SchedulerNotAuthorizedError());
|
|
34
|
+
for (const guard of this.scheduleEntryGuards){
|
|
35
|
+
const allowed = await guard.canSchedule({
|
|
36
|
+
model,
|
|
37
|
+
entry,
|
|
38
|
+
actionType: params.actionType
|
|
39
|
+
});
|
|
40
|
+
if (!allowed) return Result.fail(new SchedulerNotAuthorizedError());
|
|
41
|
+
}
|
|
32
42
|
const title = entry.values[model.titleFieldId] || "Unknown entry title";
|
|
33
43
|
return Result.ok({
|
|
34
44
|
namespace: params.namespace,
|
|
@@ -46,7 +56,13 @@ const NamespaceHandler_NamespaceHandler = NamespaceHandler.createImplementation(
|
|
|
46
56
|
dependencies: [
|
|
47
57
|
GetModelUseCase,
|
|
48
58
|
GetEntryByIdUseCase,
|
|
49
|
-
AccessControl
|
|
59
|
+
AccessControl,
|
|
60
|
+
[
|
|
61
|
+
ScheduleEntryGuard,
|
|
62
|
+
{
|
|
63
|
+
multiple: true
|
|
64
|
+
}
|
|
65
|
+
]
|
|
50
66
|
]
|
|
51
67
|
});
|
|
52
68
|
export { NamespaceHandler_NamespaceHandler as NamespaceHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/NamespaceHandler/NamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/NamespaceHandler.ts"],"sourcesContent":["import {\n NamespaceHandler as NamespaceHandlerAbstraction,\n SchedulerNotAuthorizedError,\n ScheduledActionTypePublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nclass NamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {\n public constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public canHandle(namespace: string): boolean {\n const modelId = extractModelIdFromNamespace(namespace);\n\n return !!modelId;\n }\n\n public async execute(\n params: NamespaceHandlerAbstraction.Params\n ): NamespaceHandlerAbstraction.Response<GenericRecord> {\n /**\n * We know that modelId is ok because of the canHandle() method, which is always called before execute() and must return true for this handler to be executed.\n */\n const modelId = extractModelIdFromNamespace(params.namespace)!;\n // Fetch the target model\n const modelResult = await this.getModelUseCase.execute(modelId);\n if (modelResult.isFail()) {\n return Result.fail(modelResult.error as any);\n }\n\n const model = modelResult.value;\n // Private models are internal and cannot be scheduled.\n if (model.isPrivate) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n\n // Fetch entry to get title\n const entryResult = await this.getEntryByIdUseCase.execute(model, params.targetId);\n if (entryResult.isFail()) {\n return Result.fail(entryResult.error as any);\n }\n\n const entry = entryResult.value;\n // Same check as publishing / unpublishing the entry directly, including \"own entries only\".\n const canSchedule = await this.accessControl.canAccessEntry({\n model,\n entry,\n pw: params.actionType === ScheduledActionTypePublish ? \"p\" : \"u\"\n });\n if (!canSchedule) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n const title = entry.values[model.titleFieldId] || \"Unknown entry title\";\n\n return Result.ok({\n namespace: params.namespace,\n title,\n modelId,\n actionType: params.actionType,\n targetId: params.targetId,\n scheduleId: params.scheduleId,\n immediately: params.immediately || false\n });\n }\n}\n\nexport const NamespaceHandler = NamespaceHandlerAbstraction.createImplementation({\n implementation: NamespaceHandlerImpl,\n dependencies: [GetModelUseCase
|
|
1
|
+
{"version":3,"file":"features/NamespaceHandler/NamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/NamespaceHandler.ts"],"sourcesContent":["import {\n NamespaceHandler as NamespaceHandlerAbstraction,\n SchedulerNotAuthorizedError,\n ScheduledActionTypePublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { ScheduleEntryGuard } from \"~/features/ScheduleEntryGuard/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nclass NamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {\n public constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private scheduleEntryGuards: ScheduleEntryGuard.Interface[]\n ) {}\n\n public canHandle(namespace: string): boolean {\n const modelId = extractModelIdFromNamespace(namespace);\n\n return !!modelId;\n }\n\n public async execute(\n params: NamespaceHandlerAbstraction.Params\n ): NamespaceHandlerAbstraction.Response<GenericRecord> {\n /**\n * We know that modelId is ok because of the canHandle() method, which is always called before execute() and must return true for this handler to be executed.\n */\n const modelId = extractModelIdFromNamespace(params.namespace)!;\n // Fetch the target model\n const modelResult = await this.getModelUseCase.execute(modelId);\n if (modelResult.isFail()) {\n return Result.fail(modelResult.error as any);\n }\n\n const model = modelResult.value;\n // Private models are internal and cannot be scheduled.\n if (model.isPrivate) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n\n // Fetch entry to get title\n const entryResult = await this.getEntryByIdUseCase.execute(model, params.targetId);\n if (entryResult.isFail()) {\n return Result.fail(entryResult.error as any);\n }\n\n const entry = entryResult.value;\n // Same check as publishing / unpublishing the entry directly, including \"own entries only\".\n const canSchedule = await this.accessControl.canAccessEntry({\n model,\n entry,\n pw: params.actionType === ScheduledActionTypePublish ? \"p\" : \"u\"\n });\n if (!canSchedule) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n for (const guard of this.scheduleEntryGuards) {\n const allowed = await guard.canSchedule({\n model,\n entry,\n actionType: params.actionType\n });\n if (!allowed) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n }\n const title = entry.values[model.titleFieldId] || \"Unknown entry title\";\n\n return Result.ok({\n namespace: params.namespace,\n title,\n modelId,\n actionType: params.actionType,\n targetId: params.targetId,\n scheduleId: params.scheduleId,\n immediately: params.immediately || false\n });\n }\n}\n\nexport const NamespaceHandler = NamespaceHandlerAbstraction.createImplementation({\n implementation: NamespaceHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetEntryByIdUseCase,\n AccessControl,\n [ScheduleEntryGuard, { multiple: true }]\n ]\n});\n"],"names":["NamespaceHandlerImpl","getModelUseCase","getEntryByIdUseCase","accessControl","scheduleEntryGuards","namespace","modelId","extractModelIdFromNamespace","params","modelResult","Result","model","SchedulerNotAuthorizedError","entryResult","entry","canSchedule","ScheduledActionTypePublish","guard","allowed","title","NamespaceHandler","NamespaceHandlerAbstraction","GetModelUseCase","GetEntryByIdUseCase","AccessControl","ScheduleEntryGuard"],"mappings":";;;;;;;AAaA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,mBAAkD,EAClDC,aAAsC,EACtCC,mBAAmD,CAC7D;aAJUH,eAAe,GAAfA;aACAC,mBAAmB,GAAnBA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;IACT;IAEI,UAAUC,SAAiB,EAAW;QACzC,MAAMC,UAAUC,4BAA4BF;QAE5C,OAAO,CAAC,CAACC;IACb;IAEA,MAAa,QACTE,MAA0C,EACS;QAInD,MAAMF,UAAUC,4BAA4BC,OAAO,SAAS;QAE5D,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACH;QACvD,IAAIG,YAAY,MAAM,IAClB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Type } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
/**
|
|
4
|
+
* An additional rule for scheduling an action on an entry, on top of the Headless CMS permissions.
|
|
5
|
+
* When any guard denies, the action cannot be scheduled or cancelled.
|
|
6
|
+
*/
|
|
7
|
+
export interface IScheduleEntryGuardParams {
|
|
8
|
+
model: CmsModel;
|
|
9
|
+
entry: CmsEntry;
|
|
10
|
+
actionType: ScheduledActionType;
|
|
11
|
+
}
|
|
12
|
+
export interface IScheduleEntryGuard {
|
|
13
|
+
/** May the current identity schedule the given action on the entry? */
|
|
14
|
+
canSchedule(params: IScheduleEntryGuardParams): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
export declare const ScheduleEntryGuard: import("@webiny/di").Abstraction<IScheduleEntryGuard>;
|
|
17
|
+
export declare namespace ScheduleEntryGuard {
|
|
18
|
+
type Interface = IScheduleEntryGuard;
|
|
19
|
+
type Params = IScheduleEntryGuardParams;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ScheduleEntryGuard/abstractions.js","sources":["../../../src/features/ScheduleEntryGuard/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ScheduledActionType } from \"@webiny/api-scheduler/exports/api/scheduler.js\";\n\n/**\n * An additional rule for scheduling an action on an entry, on top of the Headless CMS permissions.\n * When any guard denies, the action cannot be scheduled or cancelled.\n */\nexport interface IScheduleEntryGuardParams {\n model: CmsModel;\n entry: CmsEntry;\n actionType: ScheduledActionType;\n}\n\nexport interface IScheduleEntryGuard {\n /** May the current identity schedule the given action on the entry? */\n canSchedule(params: IScheduleEntryGuardParams): Promise<boolean>;\n}\n\nexport const ScheduleEntryGuard = createAbstraction<IScheduleEntryGuard>(\n \"HeadlessCmsScheduler/ScheduleEntryGuard\"\n);\n\nexport namespace ScheduleEntryGuard {\n export type Interface = IScheduleEntryGuard;\n export type Params = IScheduleEntryGuardParams;\n}\n"],"names":["ScheduleEntryGuard","createAbstraction"],"mappings":";AAmBO,MAAMA,qBAAqBC,kBAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ScheduleEntryGuard } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ScheduleEntryGuard } from "./abstractions.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-scheduler",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api": "6.5.2-beta.
|
|
21
|
-
"@webiny/api-headless-cms": "6.5.2-beta.
|
|
22
|
-
"@webiny/api-scheduler": "6.5.2-beta.
|
|
23
|
-
"@webiny/feature": "6.5.2-beta.
|
|
24
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
20
|
+
"@webiny/api": "6.5.2-beta.3",
|
|
21
|
+
"@webiny/api-headless-cms": "6.5.2-beta.3",
|
|
22
|
+
"@webiny/api-scheduler": "6.5.2-beta.3",
|
|
23
|
+
"@webiny/feature": "6.5.2-beta.3",
|
|
24
|
+
"@webiny/handler-graphql": "6.5.2-beta.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
28
|
-
"@webiny/api-opensearch": "6.5.2-beta.
|
|
29
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
30
|
-
"@webiny/handler": "6.5.2-beta.
|
|
31
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
32
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
33
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
34
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
27
|
+
"@webiny/api-core": "6.5.2-beta.3",
|
|
28
|
+
"@webiny/api-opensearch": "6.5.2-beta.3",
|
|
29
|
+
"@webiny/build-tools": "6.5.2-beta.3",
|
|
30
|
+
"@webiny/handler": "6.5.2-beta.3",
|
|
31
|
+
"@webiny/handler-aws": "6.5.2-beta.3",
|
|
32
|
+
"@webiny/plugins": "6.5.2-beta.3",
|
|
33
|
+
"@webiny/project-utils": "6.5.2-beta.3",
|
|
34
|
+
"@webiny/wcp": "6.5.2-beta.3",
|
|
35
35
|
"typescript": "7.0.2",
|
|
36
36
|
"vitest": "5.1.0"
|
|
37
37
|
},
|