@webiny/api-headless-cms-scheduler 0.0.0-unstable.6844005670 → 0.0.0-unstable.7be00a75a9
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/context.js +14 -9
- package/context.js.map +1 -1
- package/exports/api/cms/scheduler.d.ts +2 -0
- package/exports/api/cms/scheduler.js +2 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.d.ts +4 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +32 -43
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.d.ts +4 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +27 -40
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.d.ts +4 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +26 -39
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.d.ts +4 -4
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +27 -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 +15 -0
- package/features/NamespaceHandler/NamespaceHandler.js +44 -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/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.d.ts +15 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js +46 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js.map +1 -0
- package/features/SchedulePublishEntryUseCase/abstractions.d.ts +23 -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 +46 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js.map +1 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.d.ts +23 -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/index.d.ts +2 -6
- package/index.js +4 -9
- package/index.js.map +1 -1
- package/package.json +24 -22
- 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/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
|
@@ -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,15 @@
|
|
|
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 type { GenericRecord } from "@webiny/api/types.js";
|
|
5
|
+
declare class NamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {
|
|
6
|
+
private getModelUseCase;
|
|
7
|
+
private getEntryByIdUseCase;
|
|
8
|
+
constructor(getModelUseCase: GetModelUseCase.Interface, getEntryByIdUseCase: GetEntryByIdUseCase.Interface);
|
|
9
|
+
canHandle(namespace: string): boolean;
|
|
10
|
+
execute(params: NamespaceHandlerAbstraction.Params): NamespaceHandlerAbstraction.Response<GenericRecord>;
|
|
11
|
+
}
|
|
12
|
+
export declare const NamespaceHandler: typeof NamespaceHandlerImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/features/NamespaceHandler/abstractions").INamespaceHandler<GenericRecord>>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { NamespaceHandler } 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
|
+
class NamespaceHandlerImpl {
|
|
7
|
+
constructor(getModelUseCase, getEntryByIdUseCase){
|
|
8
|
+
this.getModelUseCase = getModelUseCase;
|
|
9
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
10
|
+
}
|
|
11
|
+
canHandle(namespace) {
|
|
12
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
13
|
+
return !!modelId;
|
|
14
|
+
}
|
|
15
|
+
async execute(params) {
|
|
16
|
+
const modelId = extractModelIdFromNamespace(params.namespace);
|
|
17
|
+
const modelResult = await this.getModelUseCase.execute(modelId);
|
|
18
|
+
if (modelResult.isFail()) return Result.fail(modelResult.error);
|
|
19
|
+
const model = modelResult.value;
|
|
20
|
+
const entryResult = await this.getEntryByIdUseCase.execute(model, params.targetId);
|
|
21
|
+
if (entryResult.isFail()) return Result.fail(entryResult.error);
|
|
22
|
+
const entry = entryResult.value;
|
|
23
|
+
const title = entry.values[model.titleFieldId] || "Unknown entry title";
|
|
24
|
+
return Result.ok({
|
|
25
|
+
namespace: params.namespace,
|
|
26
|
+
title,
|
|
27
|
+
modelId,
|
|
28
|
+
actionType: params.actionType,
|
|
29
|
+
targetId: params.targetId,
|
|
30
|
+
scheduleId: params.scheduleId,
|
|
31
|
+
immediately: params.immediately || false
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const NamespaceHandler_NamespaceHandler = NamespaceHandler.createImplementation({
|
|
36
|
+
implementation: NamespaceHandlerImpl,
|
|
37
|
+
dependencies: [
|
|
38
|
+
GetModelUseCase,
|
|
39
|
+
GetEntryByIdUseCase
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
export { NamespaceHandler_NamespaceHandler as NamespaceHandler };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=NamespaceHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/NamespaceHandler/NamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/NamespaceHandler.ts"],"sourcesContent":["import { NamespaceHandler as NamespaceHandlerAbstraction } 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 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 ) {}\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\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 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, GetEntryByIdUseCase]\n});\n"],"names":["NamespaceHandlerImpl","getModelUseCase","getEntryByIdUseCase","namespace","modelId","extractModelIdFromNamespace","params","modelResult","Result","model","entryResult","entry","title","NamespaceHandler","NamespaceHandlerAbstraction","GetModelUseCase","GetEntryByIdUseCase"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,mBAAkD,CAC5D;aAFUD,eAAe,GAAfA;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;QAG/B,MAAMG,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAACD,OAAOH,OAAO,QAAQ;QACjF,IAAII,YAAY,MAAM,IAClB,OAAOF,OAAO,IAAI,CAACE,YAAY,KAAK;QAGxC,MAAMC,QAAQD,YAAY,KAAK;QAC/B,MAAME,QAAQD,MAAM,MAAM,CAACF,MAAM,YAAY,CAAC,IAAI;QAElD,OAAOD,OAAO,EAAE,CAAC;YACb,WAAWF,OAAO,SAAS;YAC3BM;YACAR;YACA,YAAYE,OAAO,UAAU;YAC7B,UAAUA,OAAO,QAAQ;YACzB,YAAYA,OAAO,UAAU;YAC7B,aAAaA,OAAO,WAAW,IAAI;QACvC;IACJ;AACJ;AAEO,MAAMO,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBd;IAChB,cAAc;QAACe;QAAiBC;KAAoB;AACxD"}
|
|
@@ -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,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,46 @@
|
|
|
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, 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
|
+
targetId: id
|
|
29
|
+
});
|
|
30
|
+
if (scheduleResult.isFail()) return Result.fail(scheduleResult.error);
|
|
31
|
+
return Result.ok({
|
|
32
|
+
scheduledAction: scheduleResult.value
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const SchedulePublishEntryUseCase_SchedulePublishEntryUseCase = SchedulePublishEntryUseCase.createImplementation({
|
|
37
|
+
implementation: SchedulePublishEntryUseCaseImpl,
|
|
38
|
+
dependencies: [
|
|
39
|
+
ScheduleActionUseCase,
|
|
40
|
+
AccessControl,
|
|
41
|
+
GetModelUseCase
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
export { SchedulePublishEntryUseCase_SchedulePublishEntryUseCase as SchedulePublishEntryUseCase };
|
|
45
|
+
|
|
46
|
+
//# 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, 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 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","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,WAAW,EAAEC,EAAE,EAAE,GAAGH;QAEjD,MAAMI,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACH,aAAa,OAAO;QAC3E,IAAIG,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;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,0DAA8BC,4BAAAA,oBAAuC,CAAC;IAC/E,gBAAgBjB;IAChB,cAAc;QAACkB;QAAuBC;QAAeC;KAAgB;AACzE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
scheduleFor: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface ISchedulePublishEntryUseCaseResult {
|
|
10
|
+
scheduledAction: IScheduledAction;
|
|
11
|
+
}
|
|
12
|
+
export type ISchedulePublishEntryUseCaseResponse = Promise<Result<ISchedulePublishEntryUseCaseResult, ScheduleActionError>>;
|
|
13
|
+
export interface ISchedulePublishEntryUseCase {
|
|
14
|
+
execute(params: ISchedulePublishEntryUseCaseParams): ISchedulePublishEntryUseCaseResponse;
|
|
15
|
+
}
|
|
16
|
+
/** Schedule an entry for future publishing. */
|
|
17
|
+
export declare const SchedulePublishEntryUseCase: import("@webiny/di").Abstraction<ISchedulePublishEntryUseCase>;
|
|
18
|
+
export declare namespace SchedulePublishEntryUseCase {
|
|
19
|
+
type Interface = ISchedulePublishEntryUseCase;
|
|
20
|
+
type Error = ScheduleActionError;
|
|
21
|
+
type Params = ISchedulePublishEntryUseCaseParams;
|
|
22
|
+
type Result = ISchedulePublishEntryUseCaseResponse;
|
|
23
|
+
}
|
|
@@ -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 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":";AA0BO,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,46 @@
|
|
|
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, 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
|
+
targetId: id
|
|
29
|
+
});
|
|
30
|
+
if (scheduleResult.isFail()) return Result.fail(scheduleResult.error);
|
|
31
|
+
return Result.ok({
|
|
32
|
+
scheduledAction: scheduleResult.value
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const ScheduleUnpublishEntryUseCase_ScheduleUnpublishEntryUseCase = ScheduleUnpublishEntryUseCase.createImplementation({
|
|
37
|
+
implementation: ScheduleUnpublishEntryUseCaseImpl,
|
|
38
|
+
dependencies: [
|
|
39
|
+
ScheduleActionUseCase,
|
|
40
|
+
AccessControl,
|
|
41
|
+
GetModelUseCase
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
export { ScheduleUnpublishEntryUseCase_ScheduleUnpublishEntryUseCase as ScheduleUnpublishEntryUseCase };
|
|
45
|
+
|
|
46
|
+
//# 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, 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 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","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,EAAE,EAAE,GAAGH;QAEjD,MAAMI,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACH,aAAa,OAAO;QAC3E,IAAIG,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;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,gBAAgBjB;IAChB,cAAc;QAACkB;QAAuBC;QAAeC;KAAgB;AACzE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
scheduleFor: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface IScheduleUnpublishEntryUseCaseResult {
|
|
10
|
+
scheduledAction: IScheduledAction;
|
|
11
|
+
}
|
|
12
|
+
export type IScheduleUnpublishEntryUseCaseResponse = Promise<Result<IScheduleUnpublishEntryUseCaseResult, ScheduleActionError>>;
|
|
13
|
+
export interface IScheduleUnpublishEntryUseCase {
|
|
14
|
+
execute(params: IScheduleUnpublishEntryUseCaseParams): IScheduleUnpublishEntryUseCaseResponse;
|
|
15
|
+
}
|
|
16
|
+
/** Schedule an entry for future unpublishing. */
|
|
17
|
+
export declare const ScheduleUnpublishEntryUseCase: import("@webiny/di").Abstraction<IScheduleUnpublishEntryUseCase>;
|
|
18
|
+
export declare namespace ScheduleUnpublishEntryUseCase {
|
|
19
|
+
type Interface = IScheduleUnpublishEntryUseCase;
|
|
20
|
+
type Error = ScheduleActionError;
|
|
21
|
+
type Params = IScheduleUnpublishEntryUseCaseParams;
|
|
22
|
+
type Result = IScheduleUnpublishEntryUseCaseResponse;
|
|
23
|
+
}
|
|
@@ -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 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":";AA0BO,MAAMA,gCAAgCC,kBACzC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ScheduledActionHandler } from "@webiny/api-scheduler";
|
|
1
|
+
import { type IScheduledAction, ScheduledActionHandler } 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 { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UnpublishEntry";
|
|
6
|
-
import type {
|
|
6
|
+
import type { IScheduledActionPayload } from "../../types.js";
|
|
7
|
+
import type { ScheduledActionType } from "@webiny/api-scheduler/shared/abstractions.js";
|
|
7
8
|
/**
|
|
8
9
|
* Handler for unpublishing CMS entries
|
|
9
10
|
*
|
|
@@ -20,10 +21,10 @@ declare class UnpublishEntryActionHandlerImpl implements ScheduledActionHandler.
|
|
|
20
21
|
private getPublishedEntriesByIdsUseCase;
|
|
21
22
|
private unpublishEntryUseCase;
|
|
22
23
|
constructor(getModelUseCase: GetModelUseCase.Interface, getEntryByIdUseCase: GetEntryByIdUseCase.Interface, getPublishedEntriesByIdsUseCase: GetPublishedEntriesByIdsUseCase.Interface, unpublishEntryUseCase: UnpublishEntryUseCase.Interface);
|
|
23
|
-
canHandle(namespace: string, actionType:
|
|
24
|
-
handle(action:
|
|
24
|
+
canHandle(namespace: string, actionType: ScheduledActionType): boolean;
|
|
25
|
+
handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void>;
|
|
25
26
|
}
|
|
26
27
|
export declare const UnpublishEntryActionHandler: typeof UnpublishEntryActionHandlerImpl & {
|
|
27
|
-
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/shared/abstractions").IScheduledActionHandler>;
|
|
28
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/shared/abstractions.js").IScheduledActionHandler>;
|
|
28
29
|
};
|
|
29
30
|
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ScheduledActionHandler, ScheduledActionTypeUnpublish } 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 { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UnpublishEntry";
|
|
6
|
+
import { extractModelIdFromNamespace } from "../../utils/namespace.js";
|
|
7
|
+
class UnpublishEntryActionHandlerImpl {
|
|
8
|
+
constructor(getModelUseCase, getEntryByIdUseCase, getPublishedEntriesByIdsUseCase, unpublishEntryUseCase){
|
|
9
|
+
this.getModelUseCase = getModelUseCase;
|
|
10
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
11
|
+
this.getPublishedEntriesByIdsUseCase = getPublishedEntriesByIdsUseCase;
|
|
12
|
+
this.unpublishEntryUseCase = unpublishEntryUseCase;
|
|
13
|
+
}
|
|
14
|
+
canHandle(namespace, actionType) {
|
|
15
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
16
|
+
if (!modelId) return false;
|
|
17
|
+
return actionType === ScheduledActionTypeUnpublish;
|
|
18
|
+
}
|
|
19
|
+
async handle(action) {
|
|
20
|
+
const { payload } = action;
|
|
21
|
+
const modelId = payload.modelId;
|
|
22
|
+
const modelResult = await this.getModelUseCase.execute(modelId);
|
|
23
|
+
if (modelResult.isFail()) {
|
|
24
|
+
console.error(`Failed to get model "${modelId}" for scheduled unpublish action:`, modelResult.error);
|
|
25
|
+
throw new Error(`Model not found: ${modelId}`);
|
|
26
|
+
}
|
|
27
|
+
const model = modelResult.value;
|
|
28
|
+
const targetEntryResult = await this.getEntryByIdUseCase.execute(model, action.targetId);
|
|
29
|
+
if (targetEntryResult.isFail()) {
|
|
30
|
+
console.error(`Failed to get entry "${action.targetId}" for scheduled unpublish action:`, targetEntryResult.error);
|
|
31
|
+
throw new Error(`Entry not found: ${action.targetId}`);
|
|
32
|
+
}
|
|
33
|
+
const targetEntry = targetEntryResult.value;
|
|
34
|
+
const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute(model, [
|
|
35
|
+
targetEntry.id
|
|
36
|
+
]);
|
|
37
|
+
if (publishedEntriesResult.isFail()) {
|
|
38
|
+
console.error(`Failed to get published entries for "${targetEntry.id}":`, publishedEntriesResult.error);
|
|
39
|
+
throw new Error("Failed to check published entries");
|
|
40
|
+
}
|
|
41
|
+
const [publishedTargetEntry] = publishedEntriesResult.value;
|
|
42
|
+
if (!publishedTargetEntry) return void console.warn(`Entry "${action.targetId}" is not published, nothing to unpublish.`);
|
|
43
|
+
if (publishedTargetEntry.id === action.targetId) {
|
|
44
|
+
const unpublishResult = await this.unpublishEntryUseCase.execute(model, action.targetId);
|
|
45
|
+
if (unpublishResult.isFail()) {
|
|
46
|
+
console.error(`Failed to unpublish entry "${action.targetId}":`, unpublishResult.error);
|
|
47
|
+
throw new Error(`Failed to unpublish entry: ${action.targetId}`);
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const unpublishResult = await this.unpublishEntryUseCase.execute(model, publishedTargetEntry.id);
|
|
52
|
+
if (unpublishResult.isFail()) {
|
|
53
|
+
console.error(`Failed to unpublish published revision "${publishedTargetEntry.id}":`, unpublishResult.error);
|
|
54
|
+
throw new Error(`Failed to unpublish entry: ${publishedTargetEntry.id}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const UnpublishEntryActionHandler = ScheduledActionHandler.createImplementation({
|
|
59
|
+
implementation: UnpublishEntryActionHandlerImpl,
|
|
60
|
+
dependencies: [
|
|
61
|
+
GetModelUseCase,
|
|
62
|
+
GetEntryByIdUseCase,
|
|
63
|
+
GetPublishedEntriesByIdsUseCase,
|
|
64
|
+
UnpublishEntryUseCase
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
export { UnpublishEntryActionHandler };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=UnpublishEntryActionHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/UnpublishActionHandler/UnpublishEntryActionHandler.js","sources":["../../../src/features/UnpublishActionHandler/UnpublishEntryActionHandler.ts"],"sourcesContent":["import {\n type IScheduledAction,\n ScheduledActionHandler,\n ScheduledActionTypeUnpublish\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 { UnpublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry\";\nimport type { IScheduledActionPayload } from \"~/types.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\nimport type { ScheduledActionType } from \"@webiny/api-scheduler/shared/abstractions.js\";\n\n/**\n * Handler for unpublishing CMS entries\n *\n * Handles the \"Unpublish\" action for CMS entries with namespace pattern: Cms/Entry/{modelId}\n *\n * Unpublishing logic:\n * 1. If entry is not published -> nothing to do (warn)\n * 2. If target entry is published (same revision) -> unpublish it\n * 3. If a different revision is published -> unpublish it anyway\n */\nclass UnpublishEntryActionHandlerImpl implements ScheduledActionHandler.Interface {\n constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private getPublishedEntriesByIdsUseCase: GetPublishedEntriesByIdsUseCase.Interface,\n private unpublishEntryUseCase: UnpublishEntryUseCase.Interface\n ) {}\n\n canHandle(namespace: string, actionType: ScheduledActionType): boolean {\n const modelId = extractModelIdFromNamespace(namespace);\n if (!modelId) {\n return false;\n }\n return actionType === ScheduledActionTypeUnpublish;\n }\n\n async handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void> {\n const { payload } = action;\n\n const modelId = payload.modelId as string;\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 unpublish action:`,\n modelResult.error\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 unpublish 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 is not published -> nothing to do\n */\n if (!publishedTargetEntry) {\n console.warn(`Entry \"${action.targetId}\" is not published, nothing to unpublish.`);\n return;\n }\n\n /**\n * Scenario 2: Target entry is published (same revision) -> unpublish it\n */\n if (publishedTargetEntry.id === action.targetId) {\n const unpublishResult = await this.unpublishEntryUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, action.targetId);\n if (unpublishResult.isFail()) {\n console.error(\n `Failed to unpublish entry \"${action.targetId}\":`,\n unpublishResult.error\n );\n throw new Error(`Failed to unpublish entry: ${action.targetId}`);\n }\n return;\n }\n\n /**\n * Scenario 3: A different revision is published -> unpublish it anyway\n * TODO: Determine if we really want to unpublish an entry which does not match the target ID\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 published revision \"${publishedTargetEntry.id}\":`,\n unpublishResult.error\n );\n throw new Error(`Failed to unpublish entry: ${publishedTargetEntry.id}`);\n }\n }\n}\n\nexport const UnpublishEntryActionHandler = ScheduledActionHandler.createImplementation({\n implementation: UnpublishEntryActionHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetEntryByIdUseCase,\n GetPublishedEntriesByIdsUseCase,\n UnpublishEntryUseCase\n ]\n});\n"],"names":["UnpublishEntryActionHandlerImpl","getModelUseCase","getEntryByIdUseCase","getPublishedEntriesByIdsUseCase","unpublishEntryUseCase","namespace","actionType","modelId","extractModelIdFromNamespace","ScheduledActionTypeUnpublish","action","payload","modelResult","console","Error","model","targetEntryResult","targetEntry","publishedEntriesResult","publishedTargetEntry","unpublishResult","UnpublishEntryActionHandler","ScheduledActionHandler","GetModelUseCase","GetEntryByIdUseCase","GetPublishedEntriesByIdsUseCase","UnpublishEntryUseCase"],"mappings":";;;;;;AAuBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,mBAAkD,EAClDC,+BAA0E,EAC1EC,qBAAsD,CAChE;aAJUH,eAAe,GAAfA;aACAC,mBAAmB,GAAnBA;aACAC,+BAA+B,GAA/BA;aACAC,qBAAqB,GAArBA;IACT;IAEH,UAAUC,SAAiB,EAAEC,UAA+B,EAAW;QACnE,MAAMC,UAAUC,4BAA4BH;QAC5C,IAAI,CAACE,SACD,OAAO;QAEX,OAAOD,eAAeG;IAC1B;IAEA,MAAM,OAAOC,MAAiD,EAAiB;QAC3E,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,iCAAiC,CAAC,EAClEK,YAAY,KAAK;YAErB,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,iCAAiC,CAAC,EAC1EM,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,YACvBN,QAAQ,IAAI,CAAC,CAAC,OAAO,EAAEH,OAAO,QAAQ,CAAC,yCAAyC,CAAC;QAOrF,IAAIS,qBAAqB,EAAE,KAAKT,OAAO,QAAQ,EAAE;YAC7C,MAAMU,kBAAkB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAE9DL,OAAOL,OAAO,QAAQ;YACxB,IAAIU,gBAAgB,MAAM,IAAI;gBAC1BP,QAAQ,KAAK,CACT,CAAC,2BAA2B,EAAEH,OAAO,QAAQ,CAAC,EAAE,CAAC,EACjDU,gBAAgB,KAAK;gBAEzB,MAAM,IAAIN,MAAM,CAAC,2BAA2B,EAAEJ,OAAO,QAAQ,EAAE;YACnE;YACA;QACJ;QAMA,MAAMU,kBAAkB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAE9DL,OAAOI,qBAAqB,EAAE;QAChC,IAAIC,gBAAgB,MAAM,IAAI;YAC1BP,QAAQ,KAAK,CACT,CAAC,wCAAwC,EAAEM,qBAAqB,EAAE,CAAC,EAAE,CAAC,EACtEC,gBAAgB,KAAK;YAEzB,MAAM,IAAIN,MAAM,CAAC,2BAA2B,EAAEK,qBAAqB,EAAE,EAAE;QAC3E;IACJ;AACJ;AAEO,MAAME,8BAA8BC,uBAAuB,oBAAoB,CAAC;IACnF,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;KACH;AACL"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
* This will register both API and Handler plugins for the Headless CMS Scheduler.
|
|
4
|
-
* API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.
|
|
5
|
-
*/
|
|
6
|
-
export declare const createHeadlessCmsScheduler: () => PluginCollection;
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
|
2
|
+
export declare const createHeadlessCmsScheduler: () => ContextPlugin[];
|
package/index.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { createHeadlessCmsScheduleContext } from "./context.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.
|
|
7
|
-
*/
|
|
8
|
-
export const createHeadlessCmsScheduler = () => {
|
|
9
|
-
return [createHeadlessCmsScheduleContext(), createSchedulerGraphQL()];
|
|
10
|
-
};
|
|
2
|
+
const createHeadlessCmsScheduler = ()=>[
|
|
3
|
+
createHeadlessCmsScheduleContext()
|
|
4
|
+
];
|
|
5
|
+
export { createHeadlessCmsScheduler };
|
|
11
6
|
|
|
12
7
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createHeadlessCmsScheduleContext } from \"~/context.js\";\nimport { ContextPlugin } from \"@webiny/api\";\n\nexport const createHeadlessCmsScheduler = (): ContextPlugin[] => {\n return [createHeadlessCmsScheduleContext()];\n};\n"],"names":["createHeadlessCmsScheduler","createHeadlessCmsScheduleContext"],"mappings":";AAGO,MAAMA,6BAA6B,IAC/B;QAACC;KAAmC"}
|