@webiny/api-headless-cms-scheduler 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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/README.md +11 -15
- package/context.d.ts +2 -7
- package/context.js +15 -59
- package/context.js.map +1 -1
- package/exports/api/cms/scheduler.d.ts +2 -0
- package/exports/api/cms/scheduler.js +4 -0
- package/exports/api/cms/scheduler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.d.ts +20 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +54 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.d.ts +19 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +49 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.d.ts +19 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +48 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.d.ts +19 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +49 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/feature.d.ts +11 -0
- package/features/CancelScheduledActionOnEntryChange/feature.js +24 -0
- package/features/CancelScheduledActionOnEntryChange/feature.js.map +1 -0
- package/features/NamespaceHandler/NamespaceHandler.d.ts +15 -0
- package/features/NamespaceHandler/NamespaceHandler.js +50 -0
- package/features/NamespaceHandler/NamespaceHandler.js.map +1 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.d.ts +35 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.js +114 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.js.map +1 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.d.ts +15 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js +51 -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 +51 -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/UnpublishActionHandler/UnpublishEntryActionHandler.d.ts +30 -0
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js +97 -0
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js.map +1 -0
- package/index.d.ts +2 -10
- package/index.js +3 -26
- package/index.js.map +1 -1
- package/package.json +22 -23
- package/types.d.ts +3 -10
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/namespace.d.ts +4 -0
- package/utils/namespace.js +12 -0
- package/utils/namespace.js.map +1 -0
- package/constants.d.ts +0 -11
- package/constants.js +0 -19
- package/constants.js.map +0 -1
- package/graphql/index.d.ts +0 -3
- package/graphql/index.js +0 -204
- package/graphql/index.js.map +0 -1
- package/graphql/schema.d.ts +0 -217
- package/graphql/schema.js +0 -87
- package/graphql/schema.js.map +0 -1
- package/handler/Handler.d.ts +0 -23
- package/handler/Handler.js +0 -74
- package/handler/Handler.js.map +0 -1
- package/handler/actions/PublishHandlerAction.d.ts +0 -13
- package/handler/actions/PublishHandlerAction.js +0 -64
- package/handler/actions/PublishHandlerAction.js.map +0 -1
- package/handler/actions/UnpublishHandlerAction.d.ts +0 -13
- package/handler/actions/UnpublishHandlerAction.js +0 -53
- package/handler/actions/UnpublishHandlerAction.js.map +0 -1
- package/handler/index.d.ts +0 -7
- package/handler/index.js +0 -64
- package/handler/index.js.map +0 -1
- package/handler/types.d.ts +0 -5
- package/handler/types.js +0 -7
- package/handler/types.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -47
- package/manifest.js.map +0 -1
- package/scheduler/ScheduleExecutor.d.ts +0 -16
- package/scheduler/ScheduleExecutor.js +0 -55
- package/scheduler/ScheduleExecutor.js.map +0 -1
- package/scheduler/ScheduleFetcher.d.ts +0 -16
- package/scheduler/ScheduleFetcher.js +0 -51
- package/scheduler/ScheduleFetcher.js.map +0 -1
- package/scheduler/ScheduleRecord.d.ts +0 -33
- package/scheduler/ScheduleRecord.js +0 -56
- package/scheduler/ScheduleRecord.js.map +0 -1
- package/scheduler/Scheduler.d.ts +0 -14
- package/scheduler/Scheduler.js +0 -27
- package/scheduler/Scheduler.js.map +0 -1
- package/scheduler/actions/PublishScheduleAction.d.ts +0 -26
- package/scheduler/actions/PublishScheduleAction.js +0 -209
- package/scheduler/actions/PublishScheduleAction.js.map +0 -1
- package/scheduler/actions/UnpublishScheduleAction.d.ts +0 -26
- package/scheduler/actions/UnpublishScheduleAction.js +0 -199
- package/scheduler/actions/UnpublishScheduleAction.js.map +0 -1
- package/scheduler/createScheduleRecordId.d.ts +0 -2
- package/scheduler/createScheduleRecordId.js +0 -33
- package/scheduler/createScheduleRecordId.js.map +0 -1
- package/scheduler/createScheduler.d.ts +0 -12
- package/scheduler/createScheduler.js +0 -59
- package/scheduler/createScheduler.js.map +0 -1
- package/scheduler/dates.d.ts +0 -7
- package/scheduler/dates.js +0 -27
- package/scheduler/dates.js.map +0 -1
- package/scheduler/model.d.ts +0 -1
- package/scheduler/model.js +0 -88
- package/scheduler/model.js.map +0 -1
- package/scheduler/types.d.ts +0 -92
- package/scheduler/types.js +0 -19
- package/scheduler/types.js.map +0 -1
- package/service/SchedulerService.d.ts +0 -23
- package/service/SchedulerService.js +0 -151
- package/service/SchedulerService.js.map +0 -1
- package/service/types.d.ts +0 -19
- package/service/types.js +0 -7
- package/service/types.js.map +0 -1
- package/utils/dateInTheFuture.d.ts +0 -6
- package/utils/dateInTheFuture.js +0 -19
- package/utils/dateInTheFuture.js.map +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ScheduledActionHandler, ScheduledActionType, type IScheduledAction } 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 type { IScheduledActionPayload } from "../../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Handler for publishing CMS entries
|
|
12
|
+
*
|
|
13
|
+
* Handles the "Publish" action for CMS entries with namespace pattern: Cms/Entry/{modelId}
|
|
14
|
+
*
|
|
15
|
+
* Publishing logic:
|
|
16
|
+
* 1. If entry is not published -> publish it
|
|
17
|
+
* 2. If the same revision is already published -> republish it
|
|
18
|
+
* 3. If a different revision is published -> unpublish old, publish new
|
|
19
|
+
*/
|
|
20
|
+
declare class PublishEntryActionHandlerImpl implements ScheduledActionHandler.Interface {
|
|
21
|
+
private getModelUseCase;
|
|
22
|
+
private getEntryByIdUseCase;
|
|
23
|
+
private getPublishedEntriesByIdsUseCase;
|
|
24
|
+
private publishEntryUseCase;
|
|
25
|
+
private unpublishEntryUseCase;
|
|
26
|
+
private republishEntryUseCase;
|
|
27
|
+
private identityContext;
|
|
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: ScheduledActionType): boolean;
|
|
30
|
+
handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare const PublishEntryActionHandler: typeof PublishEntryActionHandlerImpl & {
|
|
33
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/shared/abstractions").IScheduledActionHandler>;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Handler for publishing CMS entries
|
|
13
|
+
*
|
|
14
|
+
* Handles the "Publish" action for CMS entries with namespace pattern: Cms/Entry/{modelId}
|
|
15
|
+
*
|
|
16
|
+
* Publishing logic:
|
|
17
|
+
* 1. If entry is not published -> publish it
|
|
18
|
+
* 2. If the same revision is already published -> republish it
|
|
19
|
+
* 3. If a different revision is published -> unpublish old, publish new
|
|
20
|
+
*/
|
|
21
|
+
class PublishEntryActionHandlerImpl {
|
|
22
|
+
constructor(getModelUseCase, getEntryByIdUseCase, getPublishedEntriesByIdsUseCase, publishEntryUseCase, unpublishEntryUseCase, republishEntryUseCase, identityContext) {
|
|
23
|
+
this.getModelUseCase = getModelUseCase;
|
|
24
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
25
|
+
this.getPublishedEntriesByIdsUseCase = getPublishedEntriesByIdsUseCase;
|
|
26
|
+
this.publishEntryUseCase = publishEntryUseCase;
|
|
27
|
+
this.unpublishEntryUseCase = unpublishEntryUseCase;
|
|
28
|
+
this.republishEntryUseCase = republishEntryUseCase;
|
|
29
|
+
this.identityContext = identityContext;
|
|
30
|
+
}
|
|
31
|
+
canHandle(namespace, actionType) {
|
|
32
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
33
|
+
if (!modelId) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return actionType === ScheduledActionTypePublish;
|
|
37
|
+
}
|
|
38
|
+
async handle(action) {
|
|
39
|
+
const {
|
|
40
|
+
payload
|
|
41
|
+
} = action;
|
|
42
|
+
const modelId = payload.modelId;
|
|
43
|
+
|
|
44
|
+
// Fetch the model
|
|
45
|
+
const modelResult = await this.getModelUseCase.execute(modelId);
|
|
46
|
+
if (modelResult.isFail()) {
|
|
47
|
+
console.error(`Failed to get model "${modelId}" for scheduled publish action:`, modelResult.error, {
|
|
48
|
+
identity: this.identityContext.getIdentity()
|
|
49
|
+
});
|
|
50
|
+
throw new Error(`Model not found: ${modelId}`);
|
|
51
|
+
}
|
|
52
|
+
const model = modelResult.value;
|
|
53
|
+
|
|
54
|
+
// Fetch the target entry
|
|
55
|
+
const targetEntryResult = await this.getEntryByIdUseCase.execute(model, action.targetId);
|
|
56
|
+
if (targetEntryResult.isFail()) {
|
|
57
|
+
console.error(`Failed to get entry "${action.targetId}" for scheduled publish action:`, targetEntryResult.error);
|
|
58
|
+
throw new Error(`Entry not found: ${action.targetId}`);
|
|
59
|
+
}
|
|
60
|
+
const targetEntry = targetEntryResult.value;
|
|
61
|
+
|
|
62
|
+
// Get published entries
|
|
63
|
+
const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute(model, [targetEntry.id]);
|
|
64
|
+
if (publishedEntriesResult.isFail()) {
|
|
65
|
+
console.error(`Failed to get published entries for "${targetEntry.id}":`, publishedEntriesResult.error);
|
|
66
|
+
throw new Error(`Failed to check published entries`);
|
|
67
|
+
}
|
|
68
|
+
const [publishedTargetEntry] = publishedEntriesResult.value;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Scenario 1: Entry has no published revision -> publish it
|
|
72
|
+
*/
|
|
73
|
+
if (!publishedTargetEntry) {
|
|
74
|
+
const publishResult = await this.publishEntryUseCase.execute(model, targetEntry.id);
|
|
75
|
+
if (publishResult.isFail()) {
|
|
76
|
+
console.error(`Failed to publish entry "${action.targetId}":`, publishResult.error);
|
|
77
|
+
throw new Error(`Failed to publish entry: ${action.targetId}`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Scenario 2: Target entry is already published (same revision) -> republish it
|
|
84
|
+
*/
|
|
85
|
+
if (publishedTargetEntry.id === targetEntry.id) {
|
|
86
|
+
const republishResult = await this.republishEntryUseCase.execute(model, targetEntry.id);
|
|
87
|
+
if (republishResult.isFail()) {
|
|
88
|
+
console.error(`Failed to republish entry "${action.targetId}":`, republishResult.error);
|
|
89
|
+
throw new Error(`Failed to republish entry: ${action.targetId}`);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Scenario 3: A different revision is published -> unpublish old, publish new
|
|
96
|
+
*/
|
|
97
|
+
const unpublishResult = await this.unpublishEntryUseCase.execute(model, publishedTargetEntry.id);
|
|
98
|
+
if (unpublishResult.isFail()) {
|
|
99
|
+
console.error(`Failed to unpublish old revision "${publishedTargetEntry.id}":`, unpublishResult.error);
|
|
100
|
+
throw new Error(`Failed to unpublish old revision: ${publishedTargetEntry.id}`);
|
|
101
|
+
}
|
|
102
|
+
const publishResult = await this.publishEntryUseCase.execute(model, targetEntry.id);
|
|
103
|
+
if (publishResult.isFail()) {
|
|
104
|
+
console.error(`Failed to publish entry "${action.targetId}":`, publishResult.error);
|
|
105
|
+
throw new Error(`Failed to publish entry: ${action.targetId}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export const PublishEntryActionHandler = ScheduledActionHandler.createImplementation({
|
|
110
|
+
implementation: PublishEntryActionHandlerImpl,
|
|
111
|
+
dependencies: [GetModelUseCase, GetEntryByIdUseCase, GetPublishedEntriesByIdsUseCase, PublishEntryUseCase, UnpublishEntryUseCase, RepublishEntryUseCase, IdentityContext]
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=PublishEntryActionHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ScheduledActionHandler","ScheduledActionTypePublish","GetModelUseCase","GetEntryByIdUseCase","GetPublishedEntriesByIdsUseCase","PublishEntryUseCase","UnpublishEntryUseCase","RepublishEntryUseCase","IdentityContext","extractModelIdFromNamespace","PublishEntryActionHandlerImpl","constructor","getModelUseCase","getEntryByIdUseCase","getPublishedEntriesByIdsUseCase","publishEntryUseCase","unpublishEntryUseCase","republishEntryUseCase","identityContext","canHandle","namespace","actionType","modelId","handle","action","payload","modelResult","execute","isFail","console","error","identity","getIdentity","Error","model","value","targetEntryResult","targetId","targetEntry","publishedEntriesResult","id","publishedTargetEntry","publishResult","republishResult","unpublishResult","PublishEntryActionHandler","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SACIA,sBAAsB,EAGtBC,0BAA0B,QACvB,gDAAgD;AACvD,SAASC,eAAe,QAAQ,yDAAyD;AACzF,SAASC,mBAAmB,QAAQ,6DAA6D;AACjG,SAASC,+BAA+B,QAAQ,yEAAyE;AACzH,SAASC,mBAAmB,QAAQ,6DAA6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AyB,GAAG7C,sBAAsB,CAAC8C,oBAAoB,CAAC;EACjFC,cAAc,EAAErC,6BAA6B;EAC7CsC,YAAY,EAAE,CACV9C,eAAe,EACfC,mBAAmB,EACnBC,+BAA+B,EAC/BC,mBAAmB,EACnBC,qBAAqB,EACrBC,qBAAqB,EACrBC,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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,51 @@
|
|
|
1
|
+
import { SchedulePublishEntryUseCase as UseCaseAbstraction } 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 {
|
|
16
|
+
model: initialModel,
|
|
17
|
+
scheduleFor,
|
|
18
|
+
id
|
|
19
|
+
} = params;
|
|
20
|
+
const modelResult = await this.getModelUseCase.execute(initialModel.modelId);
|
|
21
|
+
if (modelResult.isFail()) {
|
|
22
|
+
return Result.fail(modelResult.error);
|
|
23
|
+
}
|
|
24
|
+
const model = modelResult.value;
|
|
25
|
+
const canAccess = await this.accessControl.canAccessEntry({
|
|
26
|
+
model,
|
|
27
|
+
pw: "p"
|
|
28
|
+
});
|
|
29
|
+
if (!canAccess) {
|
|
30
|
+
return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
31
|
+
}
|
|
32
|
+
const scheduleResult = await this.scheduleAction.execute({
|
|
33
|
+
namespace: createNamespace(model),
|
|
34
|
+
actionType: ScheduledActionTypePublish,
|
|
35
|
+
scheduleFor,
|
|
36
|
+
targetId: id
|
|
37
|
+
});
|
|
38
|
+
if (scheduleResult.isFail()) {
|
|
39
|
+
return Result.fail(scheduleResult.error);
|
|
40
|
+
}
|
|
41
|
+
return Result.ok({
|
|
42
|
+
scheduledAction: scheduleResult.value
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const SchedulePublishEntryUseCase = UseCaseAbstraction.createImplementation({
|
|
47
|
+
implementation: SchedulePublishEntryUseCaseImpl,
|
|
48
|
+
dependencies: [ScheduleActionUseCase, AccessControl, GetModelUseCase]
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=SchedulePublishEntryUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SchedulePublishEntryUseCase","UseCaseAbstraction","ScheduleActionUseCase","ScheduledActionTypePublish","createNamespace","Result","EntryNotAuthorizedError","AccessControl","GetModelUseCase","SchedulePublishEntryUseCaseImpl","constructor","scheduleAction","accessControl","getModelUseCase","execute","params","model","initialModel","scheduleFor","id","modelResult","modelId","isFail","fail","error","value","canAccess","canAccessEntry","pw","fromModel","scheduleResult","namespace","actionType","targetId","ok","scheduledAction","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SAASA,2BAA2B,IAAIC,kBAAkB;AAC1D,SACIC,qBAAqB,EACrBC,0BAA0B,QACvB,gDAAgD;AACvD,SAASC,eAAe;AACxB,SAASC,MAAM,QAAQ,gCAAgC;AACvD,SAASC,uBAAuB,QAAQ,wDAAwD;AAChG,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,eAAe,QAAQ,kEAAkE;AAElG,MAAMC,+BAA+B,CAAyC;EACnEC,WAAWA,CACNC,cAA+C,EAC/CC,aAAsC,EACtCC,eAA0C,EACpD;IAAA,KAHUF,cAA+C,GAA/CA,cAA+C;IAAA,KAC/CC,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAaC,OAAOA,CAACC,MAAiC,EAA6B;IAC/E,MAAM;MAAEC,KAAK,EAAEC,YAAY;MAAEC,WAAW;MAAEC;IAAG,CAAC,GAAGJ,MAAM;IAEvD,MAAMK,WAAW,GAAG,MAAM,IAAI,CAACP,eAAe,CAACC,OAAO,CAACG,YAAY,CAACI,OAAO,CAAC;IAC5E,IAAID,WAAW,CAACE,MAAM,CAAC,CAAC,EAAE;MACtB,OAAOjB,MAAM,CAACkB,IAAI,CAACH,WAAW,CAACI,KAAY,CAAC;IAChD;IACA,MAAMR,KAAK,GAAGI,WAAW,CAACK,KAAK;IAE/B,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACd,aAAa,CAACe,cAAc,CAAC;MAAEX,KAAK;MAAEY,EAAE,EAAE;IAAI,CAAC,CAAC;IAC7E,IAAI,CAACF,SAAS,EAAE;MACZ,OAAOrB,MAAM,CAACkB,IAAI,CAACjB,uBAAuB,CAACuB,SAAS,CAACb,KAAK,CAAQ,CAAC;IACvE;IAEA,MAAMc,cAAc,GAAG,MAAM,IAAI,CAACnB,cAAc,CAACG,OAAO,CAAC;MACrDiB,SAAS,EAAE3B,eAAe,CAACY,KAAK,CAAC;MACjCgB,UAAU,EAAE7B,0BAA0B;MACtCe,WAAW;MACXe,QAAQ,EAAEd;IACd,CAAC,CAAC;IACF,IAAIW,cAAc,CAACR,MAAM,CAAC,CAAC,EAAE;MACzB,OAAOjB,MAAM,CAACkB,IAAI,CAACO,cAAc,CAACN,KAAK,CAAC;IAC5C;IACA,OAAOnB,MAAM,CAAC6B,EAAE,CAAC;MACbC,eAAe,EAAEL,cAAc,CAACL;IACpC,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMzB,2BAA2B,GAAGC,kBAAkB,CAACmC,oBAAoB,CAAC;EAC/EC,cAAc,EAAE5B,+BAA+B;EAC/C6B,YAAY,EAAE,CAACpC,qBAAqB,EAAEK,aAAa,EAAEC,eAAe;AACxE,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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,"names":["createAbstraction","Result","SchedulePublishEntryUseCase"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,MAAM,QAAQ,qBAAqB;AAyB/D;AACA,OAAO,MAAMC,2BAA2B,GAAGF,iBAAiB,CACxD,0CACJ,CAAC","ignoreList":[]}
|
|
@@ -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,51 @@
|
|
|
1
|
+
import { ScheduleUnpublishEntryUseCase as UseCaseAbstraction } 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 {
|
|
16
|
+
model: initialModel,
|
|
17
|
+
scheduleFor,
|
|
18
|
+
id
|
|
19
|
+
} = params;
|
|
20
|
+
const modelResult = await this.getModelUseCase.execute(initialModel.modelId);
|
|
21
|
+
if (modelResult.isFail()) {
|
|
22
|
+
return Result.fail(modelResult.error);
|
|
23
|
+
}
|
|
24
|
+
const model = modelResult.value;
|
|
25
|
+
const canAccess = await this.accessControl.canAccessEntry({
|
|
26
|
+
model,
|
|
27
|
+
pw: "u"
|
|
28
|
+
});
|
|
29
|
+
if (!canAccess) {
|
|
30
|
+
return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
31
|
+
}
|
|
32
|
+
const scheduleResult = await this.scheduleAction.execute({
|
|
33
|
+
namespace: createNamespace(model),
|
|
34
|
+
actionType: ScheduledActionTypeUnpublish,
|
|
35
|
+
scheduleFor,
|
|
36
|
+
targetId: id
|
|
37
|
+
});
|
|
38
|
+
if (scheduleResult.isFail()) {
|
|
39
|
+
return Result.fail(scheduleResult.error);
|
|
40
|
+
}
|
|
41
|
+
return Result.ok({
|
|
42
|
+
scheduledAction: scheduleResult.value
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const ScheduleUnpublishEntryUseCase = UseCaseAbstraction.createImplementation({
|
|
47
|
+
implementation: ScheduleUnpublishEntryUseCaseImpl,
|
|
48
|
+
dependencies: [ScheduleActionUseCase, AccessControl, GetModelUseCase]
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=ScheduleUnpublishEntryUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ScheduleUnpublishEntryUseCase","UseCaseAbstraction","ScheduleActionUseCase","ScheduledActionTypeUnpublish","createNamespace","Result","AccessControl","GetModelUseCase","EntryNotAuthorizedError","ScheduleUnpublishEntryUseCaseImpl","constructor","scheduleAction","accessControl","getModelUseCase","execute","params","model","initialModel","scheduleFor","id","modelResult","modelId","isFail","fail","error","value","canAccess","canAccessEntry","pw","fromModel","scheduleResult","namespace","actionType","targetId","ok","scheduledAction","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SAASA,6BAA6B,IAAIC,kBAAkB;AAC5D,SACIC,qBAAqB,EACrBC,4BAA4B,QACzB,gDAAgD;AACvD,SAASC,eAAe;AACxB,SAASC,MAAM,QAAQ,gCAAgC;AACvD,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,eAAe,QAAQ,kEAAkE;AAClG,SAASC,uBAAuB,QAAQ,wDAAwD;AAEhG,MAAMC,iCAAiC,CAAyC;EACrEC,WAAWA,CACNC,cAA+C,EAC/CC,aAAsC,EACtCC,eAA0C,EACpD;IAAA,KAHUF,cAA+C,GAA/CA,cAA+C;IAAA,KAC/CC,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAaC,OAAOA,CAACC,MAAiC,EAA6B;IAC/E,MAAM;MAAEC,KAAK,EAAEC,YAAY;MAAEC,WAAW;MAAEC;IAAG,CAAC,GAAGJ,MAAM;IAEvD,MAAMK,WAAW,GAAG,MAAM,IAAI,CAACP,eAAe,CAACC,OAAO,CAACG,YAAY,CAACI,OAAO,CAAC;IAC5E,IAAID,WAAW,CAACE,MAAM,CAAC,CAAC,EAAE;MACtB,OAAOjB,MAAM,CAACkB,IAAI,CAACH,WAAW,CAACI,KAAY,CAAC;IAChD;IACA,MAAMR,KAAK,GAAGI,WAAW,CAACK,KAAK;IAE/B,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACd,aAAa,CAACe,cAAc,CAAC;MAAEX,KAAK;MAAEY,EAAE,EAAE;IAAI,CAAC,CAAC;IAC7E,IAAI,CAACF,SAAS,EAAE;MACZ,OAAOrB,MAAM,CAACkB,IAAI,CAACf,uBAAuB,CAACqB,SAAS,CAACb,KAAK,CAAQ,CAAC;IACvE;IAEA,MAAMc,cAAc,GAAG,MAAM,IAAI,CAACnB,cAAc,CAACG,OAAO,CAAC;MACrDiB,SAAS,EAAE3B,eAAe,CAACY,KAAK,CAAC;MACjCgB,UAAU,EAAE7B,4BAA4B;MACxCe,WAAW;MACXe,QAAQ,EAAEd;IACd,CAAC,CAAC;IACF,IAAIW,cAAc,CAACR,MAAM,CAAC,CAAC,EAAE;MACzB,OAAOjB,MAAM,CAACkB,IAAI,CAACO,cAAc,CAACN,KAAK,CAAC;IAC5C;IACA,OAAOnB,MAAM,CAAC6B,EAAE,CAAC;MACbC,eAAe,EAAEL,cAAc,CAACL;IACpC,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMzB,6BAA6B,GAAGC,kBAAkB,CAACmC,oBAAoB,CAAC;EACjFC,cAAc,EAAE5B,iCAAiC;EACjD6B,YAAY,EAAE,CAACpC,qBAAqB,EAAEI,aAAa,EAAEC,eAAe;AACxE,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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,5 @@
|
|
|
1
|
+
import { createAbstraction, Result } from "@webiny/feature/api";
|
|
2
|
+
/** Schedule an entry for future unpublishing. */
|
|
3
|
+
export const ScheduleUnpublishEntryUseCase = createAbstraction("CmsScheduler/ScheduleUnpublishEntryUseCase");
|
|
4
|
+
|
|
5
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","Result","ScheduleUnpublishEntryUseCase"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,MAAM,QAAQ,qBAAqB;AAyB/D;AACA,OAAO,MAAMC,6BAA6B,GAAGF,iBAAiB,CAC1D,4CACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type IScheduledAction, ScheduledActionHandler } 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 type { IScheduledActionPayload } from "../../types.js";
|
|
7
|
+
import type { ScheduledActionType } from "@webiny/api-scheduler/shared/abstractions.js";
|
|
8
|
+
/**
|
|
9
|
+
* Handler for unpublishing CMS entries
|
|
10
|
+
*
|
|
11
|
+
* Handles the "Unpublish" action for CMS entries with namespace pattern: Cms/Entry/{modelId}
|
|
12
|
+
*
|
|
13
|
+
* Unpublishing logic:
|
|
14
|
+
* 1. If entry is not published -> nothing to do (warn)
|
|
15
|
+
* 2. If target entry is published (same revision) -> unpublish it
|
|
16
|
+
* 3. If a different revision is published -> unpublish it anyway
|
|
17
|
+
*/
|
|
18
|
+
declare class UnpublishEntryActionHandlerImpl implements ScheduledActionHandler.Interface {
|
|
19
|
+
private getModelUseCase;
|
|
20
|
+
private getEntryByIdUseCase;
|
|
21
|
+
private getPublishedEntriesByIdsUseCase;
|
|
22
|
+
private unpublishEntryUseCase;
|
|
23
|
+
constructor(getModelUseCase: GetModelUseCase.Interface, getEntryByIdUseCase: GetEntryByIdUseCase.Interface, getPublishedEntriesByIdsUseCase: GetPublishedEntriesByIdsUseCase.Interface, unpublishEntryUseCase: UnpublishEntryUseCase.Interface);
|
|
24
|
+
canHandle(namespace: string, actionType: ScheduledActionType): boolean;
|
|
25
|
+
handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare const UnpublishEntryActionHandler: typeof UnpublishEntryActionHandlerImpl & {
|
|
28
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/shared/abstractions.js").IScheduledActionHandler>;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Handler for unpublishing CMS entries
|
|
9
|
+
*
|
|
10
|
+
* Handles the "Unpublish" action for CMS entries with namespace pattern: Cms/Entry/{modelId}
|
|
11
|
+
*
|
|
12
|
+
* Unpublishing logic:
|
|
13
|
+
* 1. If entry is not published -> nothing to do (warn)
|
|
14
|
+
* 2. If target entry is published (same revision) -> unpublish it
|
|
15
|
+
* 3. If a different revision is published -> unpublish it anyway
|
|
16
|
+
*/
|
|
17
|
+
class UnpublishEntryActionHandlerImpl {
|
|
18
|
+
constructor(getModelUseCase, getEntryByIdUseCase, getPublishedEntriesByIdsUseCase, unpublishEntryUseCase) {
|
|
19
|
+
this.getModelUseCase = getModelUseCase;
|
|
20
|
+
this.getEntryByIdUseCase = getEntryByIdUseCase;
|
|
21
|
+
this.getPublishedEntriesByIdsUseCase = getPublishedEntriesByIdsUseCase;
|
|
22
|
+
this.unpublishEntryUseCase = unpublishEntryUseCase;
|
|
23
|
+
}
|
|
24
|
+
canHandle(namespace, actionType) {
|
|
25
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
26
|
+
if (!modelId) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return actionType === ScheduledActionTypeUnpublish;
|
|
30
|
+
}
|
|
31
|
+
async handle(action) {
|
|
32
|
+
const {
|
|
33
|
+
payload
|
|
34
|
+
} = action;
|
|
35
|
+
const modelId = payload.modelId;
|
|
36
|
+
|
|
37
|
+
// Fetch the model
|
|
38
|
+
const modelResult = await this.getModelUseCase.execute(modelId);
|
|
39
|
+
if (modelResult.isFail()) {
|
|
40
|
+
console.error(`Failed to get model "${modelId}" for scheduled unpublish action:`, modelResult.error);
|
|
41
|
+
throw new Error(`Model not found: ${modelId}`);
|
|
42
|
+
}
|
|
43
|
+
const model = modelResult.value;
|
|
44
|
+
|
|
45
|
+
// Fetch the target entry
|
|
46
|
+
const targetEntryResult = await this.getEntryByIdUseCase.execute(model, action.targetId);
|
|
47
|
+
if (targetEntryResult.isFail()) {
|
|
48
|
+
console.error(`Failed to get entry "${action.targetId}" for scheduled unpublish action:`, targetEntryResult.error);
|
|
49
|
+
throw new Error(`Entry not found: ${action.targetId}`);
|
|
50
|
+
}
|
|
51
|
+
const targetEntry = targetEntryResult.value;
|
|
52
|
+
|
|
53
|
+
// Get published entries
|
|
54
|
+
const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute(model, [targetEntry.id]);
|
|
55
|
+
if (publishedEntriesResult.isFail()) {
|
|
56
|
+
console.error(`Failed to get published entries for "${targetEntry.id}":`, publishedEntriesResult.error);
|
|
57
|
+
throw new Error(`Failed to check published entries`);
|
|
58
|
+
}
|
|
59
|
+
const [publishedTargetEntry] = publishedEntriesResult.value;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Scenario 1: Entry is not published -> nothing to do
|
|
63
|
+
*/
|
|
64
|
+
if (!publishedTargetEntry) {
|
|
65
|
+
console.warn(`Entry "${action.targetId}" is not published, nothing to unpublish.`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Scenario 2: Target entry is published (same revision) -> unpublish it
|
|
71
|
+
*/
|
|
72
|
+
if (publishedTargetEntry.id === action.targetId) {
|
|
73
|
+
const unpublishResult = await this.unpublishEntryUseCase.execute(model, action.targetId);
|
|
74
|
+
if (unpublishResult.isFail()) {
|
|
75
|
+
console.error(`Failed to unpublish entry "${action.targetId}":`, unpublishResult.error);
|
|
76
|
+
throw new Error(`Failed to unpublish entry: ${action.targetId}`);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Scenario 3: A different revision is published -> unpublish it anyway
|
|
83
|
+
* TODO: Determine if we really want to unpublish an entry which does not match the target ID
|
|
84
|
+
*/
|
|
85
|
+
const unpublishResult = await this.unpublishEntryUseCase.execute(model, publishedTargetEntry.id);
|
|
86
|
+
if (unpublishResult.isFail()) {
|
|
87
|
+
console.error(`Failed to unpublish published revision "${publishedTargetEntry.id}":`, unpublishResult.error);
|
|
88
|
+
throw new Error(`Failed to unpublish entry: ${publishedTargetEntry.id}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export const UnpublishEntryActionHandler = ScheduledActionHandler.createImplementation({
|
|
93
|
+
implementation: UnpublishEntryActionHandlerImpl,
|
|
94
|
+
dependencies: [GetModelUseCase, GetEntryByIdUseCase, GetPublishedEntriesByIdsUseCase, UnpublishEntryUseCase]
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=UnpublishEntryActionHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ScheduledActionHandler","ScheduledActionTypeUnpublish","GetModelUseCase","GetEntryByIdUseCase","GetPublishedEntriesByIdsUseCase","UnpublishEntryUseCase","extractModelIdFromNamespace","UnpublishEntryActionHandlerImpl","constructor","getModelUseCase","getEntryByIdUseCase","getPublishedEntriesByIdsUseCase","unpublishEntryUseCase","canHandle","namespace","actionType","modelId","handle","action","payload","modelResult","execute","isFail","console","error","Error","model","value","targetEntryResult","targetId","targetEntry","publishedEntriesResult","id","publishedTargetEntry","warn","unpublishResult","UnpublishEntryActionHandler","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SAEIA,sBAAsB,EACtBC,4BAA4B,QACzB,gDAAgD;AACvD,SAASC,eAAe,QAAQ,yDAAyD;AACzF,SAASC,mBAAmB,QAAQ,6DAA6D;AACjG,SAASC,+BAA+B,QAAQ,yEAAyE;AACzH,SAASC,qBAAqB,QAAQ,+DAA+D;AAErG,SAASC,2BAA2B;AAGpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,+BAA+B,CAA6C;EAC9EC,WAAWA,CACCC,eAA0C,EAC1CC,mBAAkD,EAClDC,+BAA0E,EAC1EC,qBAAsD,EAChE;IAAA,KAJUH,eAA0C,GAA1CA,eAA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AA8BQ,oBAAoB,CAACD,EAAE,EAAE,CAAC;IAC5E;EACJ;AACJ;AAEA,OAAO,MAAMI,2BAA2B,GAAGpC,sBAAsB,CAACqC,oBAAoB,CAAC;EACnFC,cAAc,EAAE/B,+BAA+B;EAC/CgC,YAAY,EAAE,CACVrC,eAAe,EACfC,mBAAmB,EACnBC,+BAA+B,EAC/BC,qBAAqB;AAE7B,CAAC,CAAC","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export interface ICreateHeadlessCmsScheduleParams extends ICreateHeadlessCmsSchedulerContextParams {
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* This will register both API and Handler plugins for the Headless CMS Scheduler.
|
|
7
|
-
* * Handler plugin will handle the scheduled CMS action event - a lambda call from the EventBridge Scheduler.
|
|
8
|
-
* * API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.
|
|
9
|
-
*/
|
|
10
|
-
export declare const createHeadlessCmsSchedule: (params: ICreateHeadlessCmsScheduleParams) => Plugin[];
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
|
2
|
+
export declare const createHeadlessCmsScheduler: () => ContextPlugin[];
|
package/index.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createHeadlessCmsSchedule = void 0;
|
|
7
|
-
var _context = require("./context.js");
|
|
8
|
-
var _model = require("./scheduler/model.js");
|
|
9
|
-
var _index = require("./graphql/index.js");
|
|
10
|
-
var _index2 = require("./handler/index.js");
|
|
11
|
-
/**
|
|
12
|
-
* This will register both API and Handler plugins for the Headless CMS Scheduler.
|
|
13
|
-
* * Handler plugin will handle the scheduled CMS action event - a lambda call from the EventBridge Scheduler.
|
|
14
|
-
* * API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.
|
|
15
|
-
*/
|
|
16
|
-
const createHeadlessCmsSchedule = params => {
|
|
17
|
-
return [
|
|
18
|
-
/**
|
|
19
|
-
* Handler for the Scheduled CMS Action Event.
|
|
20
|
-
*/
|
|
21
|
-
(0, _index2.createScheduledCmsActionEventHandler)(),
|
|
22
|
-
/**
|
|
23
|
-
* API side of the scheduler.
|
|
24
|
-
*/
|
|
25
|
-
(0, _model.createSchedulerModel)(), (0, _context.createHeadlessCmsScheduleContext)(params), (0, _index.createSchedulerGraphQL)()];
|
|
1
|
+
import { createHeadlessCmsScheduleContext } from "./context.js";
|
|
2
|
+
export const createHeadlessCmsScheduler = () => {
|
|
3
|
+
return [createHeadlessCmsScheduleContext()];
|
|
26
4
|
};
|
|
27
|
-
exports.createHeadlessCmsSchedule = createHeadlessCmsSchedule;
|
|
28
5
|
|
|
29
6
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHeadlessCmsScheduleContext","createHeadlessCmsScheduler"],"sources":["index.ts"],"sourcesContent":["import { createHeadlessCmsScheduleContext } from \"~/context.js\";\nimport { ContextPlugin } from \"@webiny/api\";\n\nexport const createHeadlessCmsScheduler = (): ContextPlugin[] => {\n return [createHeadlessCmsScheduleContext()];\n};\n"],"mappings":"AAAA,SAASA,gCAAgC;AAGzC,OAAO,MAAMC,0BAA0B,GAAGA,CAAA,KAAuB;EAC7D,OAAO,CAACD,gCAAgC,CAAC,CAAC,CAAC;AAC/C,CAAC","ignoreList":[]}
|