@webiny/api-headless-cms-scheduler 0.0.0-unstable.df7a8bb475 → 0.0.0-unstable.e1999482d0
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/CmsSchedulerFeature.d.ts +4 -0
- package/CmsSchedulerFeature.js +23 -0
- package/CmsSchedulerFeature.js.map +1 -0
- package/exports/api/cms/scheduler.d.ts +3 -0
- package/exports/api/cms/scheduler.js +3 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.d.ts +8 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +44 -43
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.d.ts +6 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +33 -40
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.d.ts +8 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +35 -39
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.d.ts +6 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +33 -40
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/feature.d.ts +4 -1
- package/features/CancelScheduledActionOnEntryChange/feature.js +9 -16
- package/features/CancelScheduledActionOnEntryChange/feature.js.map +1 -1
- package/features/NamespaceHandler/NamespaceHandler.d.ts +19 -0
- package/features/NamespaceHandler/NamespaceHandler.js +70 -0
- package/features/NamespaceHandler/NamespaceHandler.js.map +1 -0
- package/features/{ScheduleEntryAction/actionHandlers → PublishActionHandler}/PublishEntryActionHandler.d.ts +4 -4
- package/features/PublishActionHandler/PublishEntryActionHandler.js +92 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.js.map +1 -0
- 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/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.d.ts +15 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js +47 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js.map +1 -0
- package/features/SchedulePublishEntryUseCase/abstractions.d.ts +24 -0
- package/features/SchedulePublishEntryUseCase/abstractions.js +5 -0
- package/features/SchedulePublishEntryUseCase/abstractions.js.map +1 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.d.ts +15 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js +47 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js.map +1 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.d.ts +24 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.js +5 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.js.map +1 -0
- package/features/{ScheduleEntryAction/actionHandlers → UnpublishActionHandler}/UnpublishEntryActionHandler.d.ts +6 -5
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js +69 -0
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js.map +1 -0
- package/features/permissions/CmsSchedulerPermissions.d.ts +27 -0
- package/features/permissions/CmsSchedulerPermissions.js +62 -0
- package/features/permissions/CmsSchedulerPermissions.js.map +1 -0
- package/index.d.ts +1 -6
- package/index.js +1 -12
- package/package.json +20 -23
- package/types.d.ts +4 -0
- package/types.js +0 -0
- package/utils/namespace.d.ts +4 -0
- package/utils/namespace.js +9 -0
- package/utils/namespace.js.map +1 -0
- package/context.d.ts +0 -2
- package/context.js +0 -13
- package/context.js.map +0 -1
- package/features/CancelScheduledEntryAction/CancelScheduledEntryActionUseCase.d.ts +0 -15
- package/features/CancelScheduledEntryAction/CancelScheduledEntryActionUseCase.js +0 -25
- package/features/CancelScheduledEntryAction/CancelScheduledEntryActionUseCase.js.map +0 -1
- package/features/CancelScheduledEntryAction/abstractions.d.ts +0 -22
- package/features/CancelScheduledEntryAction/abstractions.js +0 -11
- package/features/CancelScheduledEntryAction/abstractions.js.map +0 -1
- package/features/CancelScheduledEntryAction/feature.d.ts +0 -6
- package/features/CancelScheduledEntryAction/feature.js +0 -16
- package/features/CancelScheduledEntryAction/feature.js.map +0 -1
- package/features/CancelScheduledEntryAction/index.d.ts +0 -1
- package/features/CancelScheduledEntryAction/index.js +0 -3
- package/features/CancelScheduledEntryAction/index.js.map +0 -1
- package/features/ScheduleEntryAction/ScheduleEntryActionUseCase.d.ts +0 -27
- package/features/ScheduleEntryAction/ScheduleEntryActionUseCase.js +0 -83
- package/features/ScheduleEntryAction/ScheduleEntryActionUseCase.js.map +0 -1
- package/features/ScheduleEntryAction/abstractions.d.ts +0 -45
- package/features/ScheduleEntryAction/abstractions.js +0 -15
- package/features/ScheduleEntryAction/abstractions.js.map +0 -1
- package/features/ScheduleEntryAction/actionHandlers/PublishEntryActionHandler.js +0 -109
- package/features/ScheduleEntryAction/actionHandlers/PublishEntryActionHandler.js.map +0 -1
- package/features/ScheduleEntryAction/actionHandlers/UnpublishEntryActionHandler.js +0 -92
- package/features/ScheduleEntryAction/actionHandlers/UnpublishEntryActionHandler.js.map +0 -1
- package/features/ScheduleEntryAction/feature.d.ts +0 -7
- package/features/ScheduleEntryAction/feature.js +0 -21
- package/features/ScheduleEntryAction/feature.js.map +0 -1
- package/features/ScheduleEntryAction/index.d.ts +0 -1
- package/features/ScheduleEntryAction/index.js +0 -3
- package/features/ScheduleEntryAction/index.js.map +0 -1
- package/graphql/ActionMapper.d.ts +0 -15
- package/graphql/ActionMapper.js +0 -18
- package/graphql/ActionMapper.js.map +0 -1
- package/graphql/dates.d.ts +0 -6
- package/graphql/dates.js +0 -9
- package/graphql/dates.js.map +0 -1
- package/graphql/index.d.ts +0 -3
- package/graphql/index.js +0 -246
- package/graphql/index.js.map +0 -1
- package/graphql/schema.d.ts +0 -162
- package/graphql/schema.js +0 -83
- package/graphql/schema.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js","sources":["../../../src/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.ts"],"sourcesContent":["import { EntryAfterUnpublishEventHandler } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry/events\";\nimport {\n CancelScheduledActionUseCase,\n ListScheduledActionsUseCase,\n ScheduledActionTypeUnpublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\n\n/**\n * Cancels scheduled action when an entry is manually unpublished\n *\n * When a user manually unpublishes an entry revision, any scheduled unpublish\n * action for that revision should be canceled since the manual action\n * takes precedence.\n */\nclass CancelScheduledActionOnUnpublishHandlerImpl\n implements EntryAfterUnpublishEventHandler.Interface\n{\n constructor(\n private listScheduledActions: ListScheduledActionsUseCase.Interface,\n private cancelScheduledAction: CancelScheduledActionUseCase.Interface,\n private logger: Logger.Interface\n ) {}\n\n async handle(event: EntryAfterUnpublishEventHandler.Event): Promise<void> {\n const { entry, model } = event.payload;\n\n // Skip private models\n if (model.isPrivate) {\n return;\n }\n\n const actionsResult = await this.listScheduledActions.execute({\n where: {\n namespace: createNamespace(model),\n actionType: ScheduledActionTypeUnpublish,\n targetId: entry.id\n }\n });\n\n if (actionsResult.isFail()) {\n this.logger.error(\n { error: actionsResult.error },\n \"Could not list scheduled actions to cancel.\"\n );\n return;\n }\n\n const actions = actionsResult.value.items;\n\n for (const action of actions) {\n const cancelRes = await this.cancelScheduledAction.execute(action);\n if (cancelRes.isFail()) {\n // Silently ignore errors - this is non-critical cleanup.\n // Entry was unpublished successfully, cancelling scheduled actions is best-effort.\n }\n }\n }\n}\n\nexport const CancelScheduledActionOnUnpublishEventHandler =\n EntryAfterUnpublishEventHandler.createImplementation({\n implementation: CancelScheduledActionOnUnpublishHandlerImpl,\n dependencies: [ListScheduledActionsUseCase, CancelScheduledActionUseCase, Logger]\n });\n"],"names":["CancelScheduledActionOnUnpublishHandlerImpl","listScheduledActions","cancelScheduledAction","logger","event","entry","model","actionsResult","createNamespace","ScheduledActionTypeUnpublish","actions","action","cancelRes","CancelScheduledActionOnUnpublishEventHandler","EntryAfterUnpublishEventHandler","ListScheduledActionsUseCase","CancelScheduledActionUseCase","Logger"],"mappings":";;;;AAgBA,MAAMA;IAGF,YACYC,oBAA2D,EAC3DC,qBAA6D,EAC7DC,MAAwB,CAClC;aAHUF,oBAAoB,GAApBA;aACAC,qBAAqB,GAArBA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,OAAOC,KAA4C,EAAiB;QACtE,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF,MAAM,OAAO;QAGtC,IAAIE,MAAM,SAAS,EACf;QAGJ,MAAMC,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;YAC1D,OAAO;gBACH,WAAWC,gBAAgBF;gBAC3B,YAAYG;gBACZ,UAAUJ,MAAM,EAAE;YACtB;QACJ;QAEA,IAAIE,cAAc,MAAM,IAAI,YACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;YAAE,OAAOA,cAAc,KAAK;QAAC,GAC7B;QAKR,MAAMG,UAAUH,cAAc,KAAK,CAAC,KAAK;QAEzC,KAAK,MAAMI,UAAUD,QAAS;YAC1B,MAAME,YAAY,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACD;YACvDC,UAAU,MAAM;QAIxB;IACJ;AACJ;AAEO,MAAMC,+CACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBd;IAChB,cAAc;QAACe;QAA6BC;QAA8BC;KAAO;AACrF"}
|
|
@@ -5,4 +5,7 @@
|
|
|
5
5
|
* published, unpublished, or deleted. This ensures scheduled actions
|
|
6
6
|
* don't execute after a user has already performed the action manually.
|
|
7
7
|
*/
|
|
8
|
-
export declare const CancelScheduledActionOnEntryChangeFeature:
|
|
8
|
+
export declare const CancelScheduledActionOnEntryChangeFeature: {
|
|
9
|
+
name: string;
|
|
10
|
+
register(container: import("@webiny/di").Container): void;
|
|
11
|
+
};
|
|
@@ -3,22 +3,15 @@ import { CancelScheduledActionOnPublishEventHandler } from "./CancelScheduledAct
|
|
|
3
3
|
import { CancelScheduledActionOnUnpublishEventHandler } from "./CancelScheduledActionOnUnpublishEventHandler.js";
|
|
4
4
|
import { CancelScheduledActionOnEntryDeleteEventHandler } from "./CancelScheduledActionOnEntryDeleteEventHandler.js";
|
|
5
5
|
import { CancelScheduledActionOnRevisionDeleteEventHandler } from "./CancelScheduledActionOnRevisionDeleteEventHandler.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const CancelScheduledActionOnEntryChangeFeature = createFeature({
|
|
15
|
-
name: "CancelScheduledActionOnEntryChange",
|
|
16
|
-
register(container) {
|
|
17
|
-
container.register(CancelScheduledActionOnPublishEventHandler);
|
|
18
|
-
container.register(CancelScheduledActionOnUnpublishEventHandler);
|
|
19
|
-
container.register(CancelScheduledActionOnEntryDeleteEventHandler);
|
|
20
|
-
container.register(CancelScheduledActionOnRevisionDeleteEventHandler);
|
|
21
|
-
}
|
|
6
|
+
const CancelScheduledActionOnEntryChangeFeature = createFeature({
|
|
7
|
+
name: "CancelScheduledActionOnEntryChange",
|
|
8
|
+
register (container) {
|
|
9
|
+
container.register(CancelScheduledActionOnPublishEventHandler);
|
|
10
|
+
container.register(CancelScheduledActionOnUnpublishEventHandler);
|
|
11
|
+
container.register(CancelScheduledActionOnEntryDeleteEventHandler);
|
|
12
|
+
container.register(CancelScheduledActionOnRevisionDeleteEventHandler);
|
|
13
|
+
}
|
|
22
14
|
});
|
|
15
|
+
export { CancelScheduledActionOnEntryChangeFeature };
|
|
23
16
|
|
|
24
17
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledActionOnEntryChange/feature.js","sources":["../../../src/features/CancelScheduledActionOnEntryChange/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CancelScheduledActionOnPublishEventHandler } from \"./CancelScheduledActionOnPublishEventHandler.js\";\nimport { CancelScheduledActionOnUnpublishEventHandler } from \"./CancelScheduledActionOnUnpublishEventHandler.js\";\nimport { CancelScheduledActionOnEntryDeleteEventHandler } from \"./CancelScheduledActionOnEntryDeleteEventHandler.js\";\nimport { CancelScheduledActionOnRevisionDeleteEventHandler } from \"./CancelScheduledActionOnRevisionDeleteEventHandler.js\";\n\n/**\n * CancelScheduledActionOnEntryChange Feature\n *\n * Automatically cancels scheduled actions when entries are manually\n * published, unpublished, or deleted. This ensures scheduled actions\n * don't execute after a user has already performed the action manually.\n */\nexport const CancelScheduledActionOnEntryChangeFeature = createFeature({\n name: \"CancelScheduledActionOnEntryChange\",\n register(container) {\n container.register(CancelScheduledActionOnPublishEventHandler);\n container.register(CancelScheduledActionOnUnpublishEventHandler);\n container.register(CancelScheduledActionOnEntryDeleteEventHandler);\n container.register(CancelScheduledActionOnRevisionDeleteEventHandler);\n }\n});\n"],"names":["CancelScheduledActionOnEntryChangeFeature","createFeature","container","CancelScheduledActionOnPublishEventHandler","CancelScheduledActionOnUnpublishEventHandler","CancelScheduledActionOnEntryDeleteEventHandler","CancelScheduledActionOnRevisionDeleteEventHandler"],"mappings":";;;;;AAaO,MAAMA,4CAA4CC,cAAc;IACnE,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;IACvB;AACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NamespaceHandler as NamespaceHandlerAbstraction } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
3
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
4
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
5
|
+
import { ScheduleEntryGuard } from "../../features/ScheduleEntryGuard/index.js";
|
|
6
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
7
|
+
declare class NamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {
|
|
8
|
+
private getModelUseCase;
|
|
9
|
+
private getEntryByIdUseCase;
|
|
10
|
+
private accessControl;
|
|
11
|
+
private scheduleEntryGuards;
|
|
12
|
+
constructor(getModelUseCase: GetModelUseCase.Interface, getEntryByIdUseCase: GetEntryByIdUseCase.Interface, accessControl: AccessControl.Interface, scheduleEntryGuards: ScheduleEntryGuard.Interface[]);
|
|
13
|
+
canHandle(namespace: string): boolean;
|
|
14
|
+
execute(params: NamespaceHandlerAbstraction.Params): NamespaceHandlerAbstraction.Response<GenericRecord>;
|
|
15
|
+
}
|
|
16
|
+
export declare const NamespaceHandler: typeof NamespaceHandlerImpl & {
|
|
17
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/features/NamespaceHandler/abstractions").INamespaceHandler<GenericRecord>>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { NamespaceHandler, ScheduledActionTypePublish, SchedulerNotAuthorizedError } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { extractModelIdFromNamespace } from "../../utils/namespace.js";
|
|
3
|
+
import { Result } from "@webiny/feature/exports/api.js";
|
|
4
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
5
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById/index.js";
|
|
6
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
|
+
import { ScheduleEntryGuard } from "../ScheduleEntryGuard/index.js";
|
|
8
|
+
class NamespaceHandlerImpl {
|
|
9
|
+
constructor(getModelUseCase, getEntryByIdUseCase, accessControl, scheduleEntryGuards){
|
|
10
|
+
this.getModelUseCase = getModelUseCase;
|
|
11
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
12
|
+
this.accessControl = accessControl;
|
|
13
|
+
this.scheduleEntryGuards = scheduleEntryGuards;
|
|
14
|
+
}
|
|
15
|
+
canHandle(namespace) {
|
|
16
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
17
|
+
return !!modelId;
|
|
18
|
+
}
|
|
19
|
+
async execute(params) {
|
|
20
|
+
const modelId = extractModelIdFromNamespace(params.namespace);
|
|
21
|
+
const modelResult = await this.getModelUseCase.execute(modelId);
|
|
22
|
+
if (modelResult.isFail()) return Result.fail(modelResult.error);
|
|
23
|
+
const model = modelResult.value;
|
|
24
|
+
if (model.isPrivate) return Result.fail(new SchedulerNotAuthorizedError());
|
|
25
|
+
const entryResult = await this.getEntryByIdUseCase.execute(model, params.targetId);
|
|
26
|
+
if (entryResult.isFail()) return Result.fail(entryResult.error);
|
|
27
|
+
const entry = entryResult.value;
|
|
28
|
+
const canSchedule = await this.accessControl.canAccessEntry({
|
|
29
|
+
model,
|
|
30
|
+
entry,
|
|
31
|
+
pw: params.actionType === ScheduledActionTypePublish ? "p" : "u"
|
|
32
|
+
});
|
|
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
|
+
}
|
|
42
|
+
const title = entry.values[model.titleFieldId] || "Unknown entry title";
|
|
43
|
+
return Result.ok({
|
|
44
|
+
namespace: params.namespace,
|
|
45
|
+
title,
|
|
46
|
+
modelId,
|
|
47
|
+
actionType: params.actionType,
|
|
48
|
+
targetId: params.targetId,
|
|
49
|
+
scheduleId: params.scheduleId,
|
|
50
|
+
immediately: params.immediately || false
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const NamespaceHandler_NamespaceHandler = NamespaceHandler.createImplementation({
|
|
55
|
+
implementation: NamespaceHandlerImpl,
|
|
56
|
+
dependencies: [
|
|
57
|
+
GetModelUseCase,
|
|
58
|
+
GetEntryByIdUseCase,
|
|
59
|
+
AccessControl,
|
|
60
|
+
[
|
|
61
|
+
ScheduleEntryGuard,
|
|
62
|
+
{
|
|
63
|
+
multiple: true
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
export { NamespaceHandler_NamespaceHandler as NamespaceHandler };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=NamespaceHandler.js.map
|
|
@@ -0,0 +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 { 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,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAGxC,MAAME,QAAQF,YAAY,KAAK;QAE/B,IAAIE,MAAM,SAAS,EACf,OAAOD,OAAO,IAAI,CAAC,IAAIE;QAI3B,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAACF,OAAOH,OAAO,QAAQ;QACjF,IAAIK,YAAY,MAAM,IAClB,OAAOH,OAAO,IAAI,CAACG,YAAY,KAAK;QAGxC,MAAMC,QAAQD,YAAY,KAAK;QAE/B,MAAME,cAAc,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YACxDJ;YACAG;YACA,IAAIN,OAAO,UAAU,KAAKQ,6BAA6B,MAAM;QACjE;QACA,IAAI,CAACD,aACD,OAAOL,OAAO,IAAI,CAAC,IAAIE;QAE3B,KAAK,MAAMK,SAAS,IAAI,CAAC,mBAAmB,CAAE;YAC1C,MAAMC,UAAU,MAAMD,MAAM,WAAW,CAAC;gBACpCN;gBACAG;gBACA,YAAYN,OAAO,UAAU;YACjC;YACA,IAAI,CAACU,SACD,OAAOR,OAAO,IAAI,CAAC,IAAIE;QAE/B;QACA,MAAMO,QAAQL,MAAM,MAAM,CAACH,MAAM,YAAY,CAAC,IAAI;QAElD,OAAOD,OAAO,EAAE,CAAC;YACb,WAAWF,OAAO,SAAS;YAC3BW;YACAb;YACA,YAAYE,OAAO,UAAU;YAC7B,UAAUA,OAAO,QAAQ;YACzB,YAAYA,OAAO,UAAU;YAC7B,aAAaA,OAAO,WAAW,IAAI;QACvC;IACJ;AACJ;AAEO,MAAMY,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBrB;IAChB,cAAc;QACVsB;QACAC;QACAC;QACA;YAACC;YAAoB;gBAAE,UAAU;YAAK;SAAE;KAC3C;AACL"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ScheduledActionHandler } from "@webiny/api-scheduler";
|
|
1
|
+
import { ScheduledActionHandler, ScheduledActionType, type IScheduledAction } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
2
|
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel";
|
|
3
3
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
4
4
|
import { GetPublishedEntriesByIdsUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetPublishedEntriesByIds";
|
|
5
5
|
import { PublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/PublishEntry";
|
|
6
6
|
import { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UnpublishEntry";
|
|
7
7
|
import { RepublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/RepublishEntry";
|
|
8
|
-
import type { IScheduleActionWithPayload } from "../../../features/ScheduleEntryAction/index.js";
|
|
9
8
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
9
|
+
import type { IScheduledActionPayload } from "../../types.js";
|
|
10
10
|
/**
|
|
11
11
|
* Handler for publishing CMS entries
|
|
12
12
|
*
|
|
@@ -26,8 +26,8 @@ declare class PublishEntryActionHandlerImpl implements ScheduledActionHandler.In
|
|
|
26
26
|
private republishEntryUseCase;
|
|
27
27
|
private identityContext;
|
|
28
28
|
constructor(getModelUseCase: GetModelUseCase.Interface, getEntryByIdUseCase: GetEntryByIdUseCase.Interface, getPublishedEntriesByIdsUseCase: GetPublishedEntriesByIdsUseCase.Interface, publishEntryUseCase: PublishEntryUseCase.Interface, unpublishEntryUseCase: UnpublishEntryUseCase.Interface, republishEntryUseCase: RepublishEntryUseCase.Interface, identityContext: IdentityContext.Interface);
|
|
29
|
-
canHandle(namespace: string, actionType:
|
|
30
|
-
handle(action:
|
|
29
|
+
canHandle(namespace: string, actionType: ScheduledActionType): boolean;
|
|
30
|
+
handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void>;
|
|
31
31
|
}
|
|
32
32
|
export declare const PublishEntryActionHandler: typeof PublishEntryActionHandlerImpl & {
|
|
33
33
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/shared/abstractions").IScheduledActionHandler>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ScheduledActionHandler, ScheduledActionTypePublish } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel";
|
|
3
|
+
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
4
|
+
import { GetPublishedEntriesByIdsUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetPublishedEntriesByIds";
|
|
5
|
+
import { PublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/PublishEntry";
|
|
6
|
+
import { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UnpublishEntry";
|
|
7
|
+
import { RepublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/RepublishEntry";
|
|
8
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
9
|
+
import { extractModelIdFromNamespace } from "../../utils/namespace.js";
|
|
10
|
+
class PublishEntryActionHandlerImpl {
|
|
11
|
+
constructor(getModelUseCase, getEntryByIdUseCase, getPublishedEntriesByIdsUseCase, publishEntryUseCase, unpublishEntryUseCase, republishEntryUseCase, identityContext){
|
|
12
|
+
this.getModelUseCase = getModelUseCase;
|
|
13
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
14
|
+
this.getPublishedEntriesByIdsUseCase = getPublishedEntriesByIdsUseCase;
|
|
15
|
+
this.publishEntryUseCase = publishEntryUseCase;
|
|
16
|
+
this.unpublishEntryUseCase = unpublishEntryUseCase;
|
|
17
|
+
this.republishEntryUseCase = republishEntryUseCase;
|
|
18
|
+
this.identityContext = identityContext;
|
|
19
|
+
}
|
|
20
|
+
canHandle(namespace, actionType) {
|
|
21
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
22
|
+
if (!modelId) return false;
|
|
23
|
+
return actionType === ScheduledActionTypePublish;
|
|
24
|
+
}
|
|
25
|
+
async handle(action) {
|
|
26
|
+
const { payload } = action;
|
|
27
|
+
const modelId = payload.modelId;
|
|
28
|
+
const modelResult = await this.getModelUseCase.execute(modelId);
|
|
29
|
+
if (modelResult.isFail()) {
|
|
30
|
+
console.error(`Failed to get model "${modelId}" for scheduled publish action:`, modelResult.error, {
|
|
31
|
+
identity: this.identityContext.getIdentity()
|
|
32
|
+
});
|
|
33
|
+
throw new Error(`Model not found: ${modelId}`);
|
|
34
|
+
}
|
|
35
|
+
const model = modelResult.value;
|
|
36
|
+
const targetEntryResult = await this.getEntryByIdUseCase.execute(model, action.targetId);
|
|
37
|
+
if (targetEntryResult.isFail()) {
|
|
38
|
+
console.error(`Failed to get entry "${action.targetId}" for scheduled publish action:`, targetEntryResult.error);
|
|
39
|
+
throw new Error(`Entry not found: ${action.targetId}`);
|
|
40
|
+
}
|
|
41
|
+
const targetEntry = targetEntryResult.value;
|
|
42
|
+
const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute(model, [
|
|
43
|
+
targetEntry.id
|
|
44
|
+
]);
|
|
45
|
+
if (publishedEntriesResult.isFail()) {
|
|
46
|
+
console.error(`Failed to get published entries for "${targetEntry.id}":`, publishedEntriesResult.error);
|
|
47
|
+
throw new Error("Failed to check published entries");
|
|
48
|
+
}
|
|
49
|
+
const [publishedTargetEntry] = publishedEntriesResult.value;
|
|
50
|
+
if (!publishedTargetEntry) {
|
|
51
|
+
const publishResult = await this.publishEntryUseCase.execute(model, targetEntry.id);
|
|
52
|
+
if (publishResult.isFail()) {
|
|
53
|
+
console.error(`Failed to publish entry "${action.targetId}":`, publishResult.error);
|
|
54
|
+
throw new Error(`Failed to publish entry: ${action.targetId}`);
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (publishedTargetEntry.id === targetEntry.id) {
|
|
59
|
+
const republishResult = await this.republishEntryUseCase.execute(model, targetEntry.id);
|
|
60
|
+
if (republishResult.isFail()) {
|
|
61
|
+
console.error(`Failed to republish entry "${action.targetId}":`, republishResult.error);
|
|
62
|
+
throw new Error(`Failed to republish entry: ${action.targetId}`);
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const unpublishResult = await this.unpublishEntryUseCase.execute(model, publishedTargetEntry.id);
|
|
67
|
+
if (unpublishResult.isFail()) {
|
|
68
|
+
console.error(`Failed to unpublish old revision "${publishedTargetEntry.id}":`, unpublishResult.error);
|
|
69
|
+
throw new Error(`Failed to unpublish old revision: ${publishedTargetEntry.id}`);
|
|
70
|
+
}
|
|
71
|
+
const publishResult = await this.publishEntryUseCase.execute(model, targetEntry.id);
|
|
72
|
+
if (publishResult.isFail()) {
|
|
73
|
+
console.error(`Failed to publish entry "${action.targetId}":`, publishResult.error);
|
|
74
|
+
throw new Error(`Failed to publish entry: ${action.targetId}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const PublishEntryActionHandler = ScheduledActionHandler.createImplementation({
|
|
79
|
+
implementation: PublishEntryActionHandlerImpl,
|
|
80
|
+
dependencies: [
|
|
81
|
+
GetModelUseCase,
|
|
82
|
+
GetEntryByIdUseCase,
|
|
83
|
+
GetPublishedEntriesByIdsUseCase,
|
|
84
|
+
PublishEntryUseCase,
|
|
85
|
+
UnpublishEntryUseCase,
|
|
86
|
+
RepublishEntryUseCase,
|
|
87
|
+
IdentityContext
|
|
88
|
+
]
|
|
89
|
+
});
|
|
90
|
+
export { PublishEntryActionHandler };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=PublishEntryActionHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/PublishActionHandler/PublishEntryActionHandler.js","sources":["../../../src/features/PublishActionHandler/PublishEntryActionHandler.ts"],"sourcesContent":["import {\n ScheduledActionHandler,\n ScheduledActionType,\n type IScheduledAction,\n ScheduledActionTypePublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { GetPublishedEntriesByIdsUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetPublishedEntriesByIds\";\nimport { PublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/PublishEntry\";\nimport { UnpublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry\";\nimport { RepublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/RepublishEntry\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { IScheduledActionPayload } from \"~/types.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\n\n/**\n * Handler for publishing CMS entries\n *\n * Handles the \"Publish\" action for CMS entries with namespace pattern: Cms/Entry/{modelId}\n *\n * Publishing logic:\n * 1. If entry is not published -> publish it\n * 2. If the same revision is already published -> republish it\n * 3. If a different revision is published -> unpublish old, publish new\n */\nclass PublishEntryActionHandlerImpl implements ScheduledActionHandler.Interface {\n constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private getPublishedEntriesByIdsUseCase: GetPublishedEntriesByIdsUseCase.Interface,\n private publishEntryUseCase: PublishEntryUseCase.Interface,\n private unpublishEntryUseCase: UnpublishEntryUseCase.Interface,\n private republishEntryUseCase: RepublishEntryUseCase.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n public canHandle(namespace: string, actionType: ScheduledActionType): boolean {\n const modelId = extractModelIdFromNamespace(namespace);\n if (!modelId) {\n return false;\n }\n return actionType === ScheduledActionTypePublish;\n }\n\n public async handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void> {\n const { payload } = action;\n\n const modelId = payload.modelId;\n\n // Fetch the model\n const modelResult = await this.getModelUseCase.execute(modelId);\n if (modelResult.isFail()) {\n console.error(\n `Failed to get model \"${modelId}\" for scheduled publish action:`,\n modelResult.error,\n {\n identity: this.identityContext.getIdentity()\n }\n );\n throw new Error(`Model not found: ${modelId}`);\n }\n\n const model = modelResult.value;\n\n // Fetch the target entry\n const targetEntryResult = await this.getEntryByIdUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, action.targetId);\n if (targetEntryResult.isFail()) {\n console.error(\n `Failed to get entry \"${action.targetId}\" for scheduled publish action:`,\n targetEntryResult.error\n );\n throw new Error(`Entry not found: ${action.targetId}`);\n }\n\n const targetEntry = targetEntryResult.value;\n\n // Get published entries\n const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, [targetEntry.id]);\n\n if (publishedEntriesResult.isFail()) {\n console.error(\n `Failed to get published entries for \"${targetEntry.id}\":`,\n publishedEntriesResult.error\n );\n throw new Error(`Failed to check published entries`);\n }\n\n const [publishedTargetEntry] = publishedEntriesResult.value;\n\n /**\n * Scenario 1: Entry has no published revision -> publish it\n */\n if (!publishedTargetEntry) {\n const publishResult = await this.publishEntryUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, targetEntry.id);\n if (publishResult.isFail()) {\n console.error(`Failed to publish entry \"${action.targetId}\":`, publishResult.error);\n throw new Error(`Failed to publish entry: ${action.targetId}`);\n }\n return;\n }\n\n /**\n * Scenario 2: Target entry is already published (same revision) -> republish it\n */\n if (publishedTargetEntry.id === targetEntry.id) {\n const republishResult = await this.republishEntryUseCase.execute(model, targetEntry.id);\n if (republishResult.isFail()) {\n console.error(\n `Failed to republish entry \"${action.targetId}\":`,\n republishResult.error\n );\n throw new Error(`Failed to republish entry: ${action.targetId}`);\n }\n return;\n }\n\n /**\n * Scenario 3: A different revision is published -> unpublish old, publish new\n */\n const unpublishResult = await this.unpublishEntryUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, publishedTargetEntry.id);\n if (unpublishResult.isFail()) {\n console.error(\n `Failed to unpublish old revision \"${publishedTargetEntry.id}\":`,\n unpublishResult.error\n );\n throw new Error(`Failed to unpublish old revision: ${publishedTargetEntry.id}`);\n }\n\n const publishResult = await this.publishEntryUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, targetEntry.id);\n if (publishResult.isFail()) {\n console.error(`Failed to publish entry \"${action.targetId}\":`, publishResult.error);\n throw new Error(`Failed to publish entry: ${action.targetId}`);\n }\n }\n}\n\nexport const PublishEntryActionHandler = ScheduledActionHandler.createImplementation({\n implementation: PublishEntryActionHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetEntryByIdUseCase,\n GetPublishedEntriesByIdsUseCase,\n PublishEntryUseCase,\n UnpublishEntryUseCase,\n RepublishEntryUseCase,\n IdentityContext\n ]\n});\n"],"names":["PublishEntryActionHandlerImpl","getModelUseCase","getEntryByIdUseCase","getPublishedEntriesByIdsUseCase","publishEntryUseCase","unpublishEntryUseCase","republishEntryUseCase","identityContext","namespace","actionType","modelId","extractModelIdFromNamespace","ScheduledActionTypePublish","action","payload","modelResult","console","Error","model","targetEntryResult","targetEntry","publishedEntriesResult","publishedTargetEntry","publishResult","republishResult","unpublishResult","PublishEntryActionHandler","ScheduledActionHandler","GetModelUseCase","GetEntryByIdUseCase","GetPublishedEntriesByIdsUseCase","PublishEntryUseCase","UnpublishEntryUseCase","RepublishEntryUseCase","IdentityContext"],"mappings":";;;;;;;;;AA0BA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,mBAAkD,EAClDC,+BAA0E,EAC1EC,mBAAkD,EAClDC,qBAAsD,EACtDC,qBAAsD,EACtDC,eAA0C,CACpD;aAPUN,eAAe,GAAfA;aACAC,mBAAmB,GAAnBA;aACAC,+BAA+B,GAA/BA;aACAC,mBAAmB,GAAnBA;aACAC,qBAAqB,GAArBA;aACAC,qBAAqB,GAArBA;aACAC,eAAe,GAAfA;IACT;IAEI,UAAUC,SAAiB,EAAEC,UAA+B,EAAW;QAC1E,MAAMC,UAAUC,4BAA4BH;QAC5C,IAAI,CAACE,SACD,OAAO;QAEX,OAAOD,eAAeG;IAC1B;IAEA,MAAa,OAAOC,MAAiD,EAAiB;QAClF,MAAM,EAAEC,OAAO,EAAE,GAAGD;QAEpB,MAAMH,UAAUI,QAAQ,OAAO;QAG/B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QACvD,IAAIK,YAAY,MAAM,IAAI;YACtBC,QAAQ,KAAK,CACT,CAAC,qBAAqB,EAAEN,QAAQ,+BAA+B,CAAC,EAChEK,YAAY,KAAK,EACjB;gBACI,UAAU,IAAI,CAAC,eAAe,CAAC,WAAW;YAC9C;YAEJ,MAAM,IAAIE,MAAM,CAAC,iBAAiB,EAAEP,SAAS;QACjD;QAEA,MAAMQ,QAAQH,YAAY,KAAK;QAG/B,MAAMI,oBAAoB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAE9DD,OAAOL,OAAO,QAAQ;QACxB,IAAIM,kBAAkB,MAAM,IAAI;YAC5BH,QAAQ,KAAK,CACT,CAAC,qBAAqB,EAAEH,OAAO,QAAQ,CAAC,+BAA+B,CAAC,EACxEM,kBAAkB,KAAK;YAE3B,MAAM,IAAIF,MAAM,CAAC,iBAAiB,EAAEJ,OAAO,QAAQ,EAAE;QACzD;QAEA,MAAMO,cAAcD,kBAAkB,KAAK;QAG3C,MAAME,yBAAyB,MAAM,IAAI,CAAC,+BAA+B,CAAC,OAAO,CAE/EH,OAAO;YAACE,YAAY,EAAE;SAAC;QAEzB,IAAIC,uBAAuB,MAAM,IAAI;YACjCL,QAAQ,KAAK,CACT,CAAC,qCAAqC,EAAEI,YAAY,EAAE,CAAC,EAAE,CAAC,EAC1DC,uBAAuB,KAAK;YAEhC,MAAM,IAAIJ,MAAM;QACpB;QAEA,MAAM,CAACK,qBAAqB,GAAGD,uBAAuB,KAAK;QAK3D,IAAI,CAACC,sBAAsB;YACvB,MAAMC,gBAAgB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAE1DL,OAAOE,YAAY,EAAE;YACvB,IAAIG,cAAc,MAAM,IAAI;gBACxBP,QAAQ,KAAK,CAAC,CAAC,yBAAyB,EAAEH,OAAO,QAAQ,CAAC,EAAE,CAAC,EAAEU,cAAc,KAAK;gBAClF,MAAM,IAAIN,MAAM,CAAC,yBAAyB,EAAEJ,OAAO,QAAQ,EAAE;YACjE;YACA;QACJ;QAKA,IAAIS,qBAAqB,EAAE,KAAKF,YAAY,EAAE,EAAE;YAC5C,MAAMI,kBAAkB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACN,OAAOE,YAAY,EAAE;YACtF,IAAII,gBAAgB,MAAM,IAAI;gBAC1BR,QAAQ,KAAK,CACT,CAAC,2BAA2B,EAAEH,OAAO,QAAQ,CAAC,EAAE,CAAC,EACjDW,gBAAgB,KAAK;gBAEzB,MAAM,IAAIP,MAAM,CAAC,2BAA2B,EAAEJ,OAAO,QAAQ,EAAE;YACnE;YACA;QACJ;QAKA,MAAMY,kBAAkB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAE9DP,OAAOI,qBAAqB,EAAE;QAChC,IAAIG,gBAAgB,MAAM,IAAI;YAC1BT,QAAQ,KAAK,CACT,CAAC,kCAAkC,EAAEM,qBAAqB,EAAE,CAAC,EAAE,CAAC,EAChEG,gBAAgB,KAAK;YAEzB,MAAM,IAAIR,MAAM,CAAC,kCAAkC,EAAEK,qBAAqB,EAAE,EAAE;QAClF;QAEA,MAAMC,gBAAgB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAE1DL,OAAOE,YAAY,EAAE;QACvB,IAAIG,cAAc,MAAM,IAAI;YACxBP,QAAQ,KAAK,CAAC,CAAC,yBAAyB,EAAEH,OAAO,QAAQ,CAAC,EAAE,CAAC,EAAEU,cAAc,KAAK;YAClF,MAAM,IAAIN,MAAM,CAAC,yBAAyB,EAAEJ,OAAO,QAAQ,EAAE;QACjE;IACJ;AACJ;AAEO,MAAMa,4BAA4BC,uBAAuB,oBAAoB,CAAC;IACjF,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { ScheduledActionType } 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";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SchedulePublishEntryUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
|
+
import { ScheduleActionUseCase } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
4
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
5
|
+
declare class SchedulePublishEntryUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private scheduleAction;
|
|
7
|
+
private accessControl;
|
|
8
|
+
private getModelUseCase;
|
|
9
|
+
constructor(scheduleAction: ScheduleActionUseCase.Interface, accessControl: AccessControl.Interface, getModelUseCase: GetModelUseCase.Interface);
|
|
10
|
+
execute(params: UseCaseAbstraction.Params): UseCaseAbstraction.Result;
|
|
11
|
+
}
|
|
12
|
+
export declare const SchedulePublishEntryUseCase: typeof SchedulePublishEntryUseCaseImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISchedulePublishEntryUseCase>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SchedulePublishEntryUseCase } from "./abstractions.js";
|
|
2
|
+
import { ScheduleActionUseCase, ScheduledActionTypePublish } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
import { createNamespace } from "../../utils/namespace.js";
|
|
4
|
+
import { Result } from "@webiny/feature/exports/api.js";
|
|
5
|
+
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
6
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
8
|
+
class SchedulePublishEntryUseCaseImpl {
|
|
9
|
+
constructor(scheduleAction, accessControl, getModelUseCase){
|
|
10
|
+
this.scheduleAction = scheduleAction;
|
|
11
|
+
this.accessControl = accessControl;
|
|
12
|
+
this.getModelUseCase = getModelUseCase;
|
|
13
|
+
}
|
|
14
|
+
async execute(params) {
|
|
15
|
+
const { model: initialModel, tenant, scheduleFor, id } = params;
|
|
16
|
+
const modelResult = await this.getModelUseCase.execute(initialModel.modelId);
|
|
17
|
+
if (modelResult.isFail()) return Result.fail(modelResult.error);
|
|
18
|
+
const model = modelResult.value;
|
|
19
|
+
const canAccess = await this.accessControl.canAccessEntry({
|
|
20
|
+
model,
|
|
21
|
+
pw: "p"
|
|
22
|
+
});
|
|
23
|
+
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
24
|
+
const scheduleResult = await this.scheduleAction.execute({
|
|
25
|
+
namespace: createNamespace(model),
|
|
26
|
+
actionType: ScheduledActionTypePublish,
|
|
27
|
+
scheduleFor,
|
|
28
|
+
tenant,
|
|
29
|
+
targetId: id
|
|
30
|
+
});
|
|
31
|
+
if (scheduleResult.isFail()) return Result.fail(scheduleResult.error);
|
|
32
|
+
return Result.ok({
|
|
33
|
+
scheduledAction: scheduleResult.value
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const SchedulePublishEntryUseCase_SchedulePublishEntryUseCase = SchedulePublishEntryUseCase.createImplementation({
|
|
38
|
+
implementation: SchedulePublishEntryUseCaseImpl,
|
|
39
|
+
dependencies: [
|
|
40
|
+
ScheduleActionUseCase,
|
|
41
|
+
AccessControl,
|
|
42
|
+
GetModelUseCase
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
export { SchedulePublishEntryUseCase_SchedulePublishEntryUseCase as SchedulePublishEntryUseCase };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=SchedulePublishEntryUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js","sources":["../../../src/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.ts"],"sourcesContent":["import { SchedulePublishEntryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport {\n ScheduleActionUseCase,\n ScheduledActionTypePublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\n\nclass SchedulePublishEntryUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private scheduleAction: ScheduleActionUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private getModelUseCase: GetModelUseCase.Interface\n ) {}\n\n public async execute(params: UseCaseAbstraction.Params): UseCaseAbstraction.Result {\n const { model: initialModel, tenant, scheduleFor, id } = params;\n\n const modelResult = await this.getModelUseCase.execute(initialModel.modelId);\n if (modelResult.isFail()) {\n return Result.fail(modelResult.error as any);\n }\n const model = modelResult.value;\n\n const canAccess = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model) as any);\n }\n\n const scheduleResult = await this.scheduleAction.execute({\n namespace: createNamespace(model),\n actionType: ScheduledActionTypePublish,\n scheduleFor,\n tenant,\n targetId: id\n });\n if (scheduleResult.isFail()) {\n return Result.fail(scheduleResult.error);\n }\n return Result.ok({\n scheduledAction: scheduleResult.value\n });\n }\n}\n\nexport const SchedulePublishEntryUseCase = UseCaseAbstraction.createImplementation({\n implementation: SchedulePublishEntryUseCaseImpl,\n dependencies: [ScheduleActionUseCase, AccessControl, GetModelUseCase]\n});\n"],"names":["SchedulePublishEntryUseCaseImpl","scheduleAction","accessControl","getModelUseCase","params","initialModel","tenant","scheduleFor","id","modelResult","Result","model","canAccess","EntryNotAuthorizedError","scheduleResult","createNamespace","ScheduledActionTypePublish","SchedulePublishEntryUseCase","UseCaseAbstraction","ScheduleActionUseCase","AccessControl","GetModelUseCase"],"mappings":";;;;;;;AAWA,MAAMA;IACF,YACYC,cAA+C,EAC/CC,aAAsC,EACtCC,eAA0C,CACpD;aAHUF,cAAc,GAAdA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAa,QAAQC,MAAiC,EAA6B;QAC/E,MAAM,EAAE,OAAOC,YAAY,EAAEC,MAAM,EAAEC,WAAW,EAAEC,EAAE,EAAE,GAAGJ;QAEzD,MAAMK,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ,aAAa,OAAO;QAC3E,IAAII,YAAY,MAAM,IAClB,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAExC,MAAME,QAAQF,YAAY,KAAK;QAE/B,MAAMG,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAED;YAAO,IAAI;QAAI;QAC3E,IAAI,CAACC,WACD,OAAOF,OAAO,IAAI,CAACG,wBAAwB,SAAS,CAACF;QAGzD,MAAMG,iBAAiB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YACrD,WAAWC,gBAAgBJ;YAC3B,YAAYK;YACZT;YACAD;YACA,UAAUE;QACd;QACA,IAAIM,eAAe,MAAM,IACrB,OAAOJ,OAAO,IAAI,CAACI,eAAe,KAAK;QAE3C,OAAOJ,OAAO,EAAE,CAAC;YACb,iBAAiBI,eAAe,KAAK;QACzC;IACJ;AACJ;AAEO,MAAMG,0DAA8BC,4BAAAA,oBAAuC,CAAC;IAC/E,gBAAgBlB;IAChB,cAAc;QAACmB;QAAuBC;QAAeC;KAAgB;AACzE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { IScheduledAction, ScheduleActionError } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
export interface ISchedulePublishEntryUseCaseParams {
|
|
5
|
+
id: string;
|
|
6
|
+
model: Pick<CmsModel, "modelId">;
|
|
7
|
+
tenant: string;
|
|
8
|
+
scheduleFor: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface ISchedulePublishEntryUseCaseResult {
|
|
11
|
+
scheduledAction: IScheduledAction;
|
|
12
|
+
}
|
|
13
|
+
export type ISchedulePublishEntryUseCaseResponse = Promise<Result<ISchedulePublishEntryUseCaseResult, ScheduleActionError>>;
|
|
14
|
+
export interface ISchedulePublishEntryUseCase {
|
|
15
|
+
execute(params: ISchedulePublishEntryUseCaseParams): ISchedulePublishEntryUseCaseResponse;
|
|
16
|
+
}
|
|
17
|
+
/** Schedule an entry for future publishing. */
|
|
18
|
+
export declare const SchedulePublishEntryUseCase: import("@webiny/di").Abstraction<ISchedulePublishEntryUseCase>;
|
|
19
|
+
export declare namespace SchedulePublishEntryUseCase {
|
|
20
|
+
type Interface = ISchedulePublishEntryUseCase;
|
|
21
|
+
type Error = ScheduleActionError;
|
|
22
|
+
type Params = ISchedulePublishEntryUseCaseParams;
|
|
23
|
+
type Result = ISchedulePublishEntryUseCaseResponse;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/SchedulePublishEntryUseCase/abstractions.js","sources":["../../../src/features/SchedulePublishEntryUseCase/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type {\n IScheduledAction,\n ScheduleActionError\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport interface ISchedulePublishEntryUseCaseParams {\n id: string;\n model: Pick<CmsModel, \"modelId\">;\n tenant: string;\n scheduleFor: Date;\n}\n\nexport interface ISchedulePublishEntryUseCaseResult {\n scheduledAction: IScheduledAction;\n}\n\nexport type ISchedulePublishEntryUseCaseResponse = Promise<\n Result<ISchedulePublishEntryUseCaseResult, ScheduleActionError>\n>;\n\nexport interface ISchedulePublishEntryUseCase {\n execute(params: ISchedulePublishEntryUseCaseParams): ISchedulePublishEntryUseCaseResponse;\n}\n\n/** Schedule an entry for future publishing. */\nexport const SchedulePublishEntryUseCase = createAbstraction<ISchedulePublishEntryUseCase>(\n \"CmsScheduler/SchedulePublishEntryUseCase\"\n);\n\nexport namespace SchedulePublishEntryUseCase {\n export type Interface = ISchedulePublishEntryUseCase;\n export type Error = ScheduleActionError;\n export type Params = ISchedulePublishEntryUseCaseParams;\n export type Result = ISchedulePublishEntryUseCaseResponse;\n}\n"],"names":["SchedulePublishEntryUseCase","createAbstraction"],"mappings":";AA2BO,MAAMA,8BAA8BC,kBACvC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ScheduleUnpublishEntryUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
|
+
import { ScheduleActionUseCase } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
4
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
5
|
+
declare class ScheduleUnpublishEntryUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private scheduleAction;
|
|
7
|
+
private accessControl;
|
|
8
|
+
private getModelUseCase;
|
|
9
|
+
constructor(scheduleAction: ScheduleActionUseCase.Interface, accessControl: AccessControl.Interface, getModelUseCase: GetModelUseCase.Interface);
|
|
10
|
+
execute(params: UseCaseAbstraction.Params): UseCaseAbstraction.Result;
|
|
11
|
+
}
|
|
12
|
+
export declare const ScheduleUnpublishEntryUseCase: typeof ScheduleUnpublishEntryUseCaseImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IScheduleUnpublishEntryUseCase>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ScheduleUnpublishEntryUseCase } from "./abstractions.js";
|
|
2
|
+
import { ScheduleActionUseCase, ScheduledActionTypeUnpublish } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
import { createNamespace } from "../../utils/namespace.js";
|
|
4
|
+
import { Result } from "@webiny/feature/exports/api.js";
|
|
5
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
7
|
+
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
8
|
+
class ScheduleUnpublishEntryUseCaseImpl {
|
|
9
|
+
constructor(scheduleAction, accessControl, getModelUseCase){
|
|
10
|
+
this.scheduleAction = scheduleAction;
|
|
11
|
+
this.accessControl = accessControl;
|
|
12
|
+
this.getModelUseCase = getModelUseCase;
|
|
13
|
+
}
|
|
14
|
+
async execute(params) {
|
|
15
|
+
const { model: initialModel, scheduleFor, tenant, id } = params;
|
|
16
|
+
const modelResult = await this.getModelUseCase.execute(initialModel.modelId);
|
|
17
|
+
if (modelResult.isFail()) return Result.fail(modelResult.error);
|
|
18
|
+
const model = modelResult.value;
|
|
19
|
+
const canAccess = await this.accessControl.canAccessEntry({
|
|
20
|
+
model,
|
|
21
|
+
pw: "u"
|
|
22
|
+
});
|
|
23
|
+
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
24
|
+
const scheduleResult = await this.scheduleAction.execute({
|
|
25
|
+
namespace: createNamespace(model),
|
|
26
|
+
actionType: ScheduledActionTypeUnpublish,
|
|
27
|
+
scheduleFor,
|
|
28
|
+
tenant,
|
|
29
|
+
targetId: id
|
|
30
|
+
});
|
|
31
|
+
if (scheduleResult.isFail()) return Result.fail(scheduleResult.error);
|
|
32
|
+
return Result.ok({
|
|
33
|
+
scheduledAction: scheduleResult.value
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const ScheduleUnpublishEntryUseCase_ScheduleUnpublishEntryUseCase = ScheduleUnpublishEntryUseCase.createImplementation({
|
|
38
|
+
implementation: ScheduleUnpublishEntryUseCaseImpl,
|
|
39
|
+
dependencies: [
|
|
40
|
+
ScheduleActionUseCase,
|
|
41
|
+
AccessControl,
|
|
42
|
+
GetModelUseCase
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
export { ScheduleUnpublishEntryUseCase_ScheduleUnpublishEntryUseCase as ScheduleUnpublishEntryUseCase };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=ScheduleUnpublishEntryUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js","sources":["../../../src/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.ts"],"sourcesContent":["import { ScheduleUnpublishEntryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport {\n ScheduleActionUseCase,\n ScheduledActionTypeUnpublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { EntryNotAuthorizedError } from \"@webiny/api-headless-cms/domain/contentEntry/errors.js\";\n\nclass ScheduleUnpublishEntryUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private scheduleAction: ScheduleActionUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private getModelUseCase: GetModelUseCase.Interface\n ) {}\n\n public async execute(params: UseCaseAbstraction.Params): UseCaseAbstraction.Result {\n const { model: initialModel, scheduleFor, tenant, id } = params;\n\n const modelResult = await this.getModelUseCase.execute(initialModel.modelId);\n if (modelResult.isFail()) {\n return Result.fail(modelResult.error as any);\n }\n const model = modelResult.value;\n\n const canAccess = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model) as any);\n }\n\n const scheduleResult = await this.scheduleAction.execute({\n namespace: createNamespace(model),\n actionType: ScheduledActionTypeUnpublish,\n scheduleFor,\n tenant,\n targetId: id\n });\n if (scheduleResult.isFail()) {\n return Result.fail(scheduleResult.error);\n }\n return Result.ok({\n scheduledAction: scheduleResult.value\n });\n }\n}\n\nexport const ScheduleUnpublishEntryUseCase = UseCaseAbstraction.createImplementation({\n implementation: ScheduleUnpublishEntryUseCaseImpl,\n dependencies: [ScheduleActionUseCase, AccessControl, GetModelUseCase]\n});\n"],"names":["ScheduleUnpublishEntryUseCaseImpl","scheduleAction","accessControl","getModelUseCase","params","initialModel","scheduleFor","tenant","id","modelResult","Result","model","canAccess","EntryNotAuthorizedError","scheduleResult","createNamespace","ScheduledActionTypeUnpublish","ScheduleUnpublishEntryUseCase","UseCaseAbstraction","ScheduleActionUseCase","AccessControl","GetModelUseCase"],"mappings":";;;;;;;AAWA,MAAMA;IACF,YACYC,cAA+C,EAC/CC,aAAsC,EACtCC,eAA0C,CACpD;aAHUF,cAAc,GAAdA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAa,QAAQC,MAAiC,EAA6B;QAC/E,MAAM,EAAE,OAAOC,YAAY,EAAEC,WAAW,EAAEC,MAAM,EAAEC,EAAE,EAAE,GAAGJ;QAEzD,MAAMK,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ,aAAa,OAAO;QAC3E,IAAII,YAAY,MAAM,IAClB,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAExC,MAAME,QAAQF,YAAY,KAAK;QAE/B,MAAMG,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAED;YAAO,IAAI;QAAI;QAC3E,IAAI,CAACC,WACD,OAAOF,OAAO,IAAI,CAACG,wBAAwB,SAAS,CAACF;QAGzD,MAAMG,iBAAiB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YACrD,WAAWC,gBAAgBJ;YAC3B,YAAYK;YACZV;YACAC;YACA,UAAUC;QACd;QACA,IAAIM,eAAe,MAAM,IACrB,OAAOJ,OAAO,IAAI,CAACI,eAAe,KAAK;QAE3C,OAAOJ,OAAO,EAAE,CAAC;YACb,iBAAiBI,eAAe,KAAK;QACzC;IACJ;AACJ;AAEO,MAAMG,8DAAgCC,8BAAAA,oBAAuC,CAAC;IACjF,gBAAgBlB;IAChB,cAAc;QAACmB;QAAuBC;QAAeC;KAAgB;AACzE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { IScheduledAction, ScheduleActionError } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
export interface IScheduleUnpublishEntryUseCaseParams {
|
|
5
|
+
id: string;
|
|
6
|
+
model: Pick<CmsModel, "modelId">;
|
|
7
|
+
tenant: string;
|
|
8
|
+
scheduleFor: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface IScheduleUnpublishEntryUseCaseResult {
|
|
11
|
+
scheduledAction: IScheduledAction;
|
|
12
|
+
}
|
|
13
|
+
export type IScheduleUnpublishEntryUseCaseResponse = Promise<Result<IScheduleUnpublishEntryUseCaseResult, ScheduleActionError>>;
|
|
14
|
+
export interface IScheduleUnpublishEntryUseCase {
|
|
15
|
+
execute(params: IScheduleUnpublishEntryUseCaseParams): IScheduleUnpublishEntryUseCaseResponse;
|
|
16
|
+
}
|
|
17
|
+
/** Schedule an entry for future unpublishing. */
|
|
18
|
+
export declare const ScheduleUnpublishEntryUseCase: import("@webiny/di").Abstraction<IScheduleUnpublishEntryUseCase>;
|
|
19
|
+
export declare namespace ScheduleUnpublishEntryUseCase {
|
|
20
|
+
type Interface = IScheduleUnpublishEntryUseCase;
|
|
21
|
+
type Error = ScheduleActionError;
|
|
22
|
+
type Params = IScheduleUnpublishEntryUseCaseParams;
|
|
23
|
+
type Result = IScheduleUnpublishEntryUseCaseResponse;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ScheduleUnpublishEntryUseCase/abstractions.js","sources":["../../../src/features/ScheduleUnpublishEntryUseCase/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type {\n IScheduledAction,\n ScheduleActionError\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport interface IScheduleUnpublishEntryUseCaseParams {\n id: string;\n model: Pick<CmsModel, \"modelId\">;\n tenant: string;\n scheduleFor: Date;\n}\n\nexport interface IScheduleUnpublishEntryUseCaseResult {\n scheduledAction: IScheduledAction;\n}\n\nexport type IScheduleUnpublishEntryUseCaseResponse = Promise<\n Result<IScheduleUnpublishEntryUseCaseResult, ScheduleActionError>\n>;\n\nexport interface IScheduleUnpublishEntryUseCase {\n execute(params: IScheduleUnpublishEntryUseCaseParams): IScheduleUnpublishEntryUseCaseResponse;\n}\n\n/** Schedule an entry for future unpublishing. */\nexport const ScheduleUnpublishEntryUseCase = createAbstraction<IScheduleUnpublishEntryUseCase>(\n \"CmsScheduler/ScheduleUnpublishEntryUseCase\"\n);\n\nexport namespace ScheduleUnpublishEntryUseCase {\n export type Interface = IScheduleUnpublishEntryUseCase;\n export type Error = ScheduleActionError;\n export type Params = IScheduleUnpublishEntryUseCaseParams;\n export type Result = IScheduleUnpublishEntryUseCaseResponse;\n}\n"],"names":["ScheduleUnpublishEntryUseCase","createAbstraction"],"mappings":";AA2BO,MAAMA,gCAAgCC,kBACzC"}
|