@webiny/api-headless-cms-scheduler 6.3.0 → 6.4.0-beta.0
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 +9 -10
- package/context.js.map +1 -1
- package/exports/api/cms/scheduler.js +0 -2
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +30 -44
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +25 -39
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +24 -38
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +25 -39
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnEntryChange/feature.js +9 -16
- package/features/CancelScheduledActionOnEntryChange/feature.js.map +1 -1
- package/features/NamespaceHandler/NamespaceHandler.js +33 -39
- package/features/NamespaceHandler/NamespaceHandler.js.map +1 -1
- package/features/PublishActionHandler/PublishEntryActionHandler.js +75 -97
- package/features/PublishActionHandler/PublishEntryActionHandler.js.map +1 -1
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js +33 -38
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js.map +1 -1
- package/features/SchedulePublishEntryUseCase/abstractions.js +3 -3
- package/features/SchedulePublishEntryUseCase/abstractions.js.map +1 -1
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js +33 -38
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js.map +1 -1
- package/features/ScheduleUnpublishEntryUseCase/abstractions.js +3 -3
- package/features/ScheduleUnpublishEntryUseCase/abstractions.js.map +1 -1
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js +55 -83
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js.map +1 -1
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/package.json +16 -16
- package/types.js +0 -3
- package/utils/namespace.js +6 -9
- package/utils/namespace.js.map +1 -1
- package/exports/api/cms/scheduler.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -7,108 +7,86 @@ import { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/content
|
|
|
7
7
|
import { RepublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/RepublishEntry";
|
|
8
8
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
9
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
10
|
class PublishEntryActionHandlerImpl {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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;
|
|
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;
|
|
80
19
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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}`);
|
|
20
|
+
canHandle(namespace, actionType) {
|
|
21
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
22
|
+
if (!modelId) return false;
|
|
23
|
+
return actionType === ScheduledActionTypePublish;
|
|
101
24
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
}
|
|
106
76
|
}
|
|
107
|
-
}
|
|
108
77
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
]
|
|
112
89
|
});
|
|
90
|
+
export { PublishEntryActionHandler };
|
|
113
91
|
|
|
114
92
|
//# sourceMappingURL=PublishEntryActionHandler.js.map
|
|
@@ -1 +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,6DAA6D;AACjG,SAASC,qBAAqB,QAAQ,+DAA+D;AACrG,SAASC,qBAAqB,QAAQ,+DAA+D;AACrG,SAASC,eAAe,QAAQ,6DAA6D;AAE7F,SAASC,2BAA2B;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,6BAA6B,CAA6C;EAC5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AAC","ignoreList":[]}
|
|
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,e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AAc,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchedulePublishEntryUseCase
|
|
1
|
+
import { SchedulePublishEntryUseCase } from "./abstractions.js";
|
|
2
2
|
import { ScheduleActionUseCase, ScheduledActionTypePublish } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
3
|
import { createNamespace } from "../../utils/namespace.js";
|
|
4
4
|
import { Result } from "@webiny/feature/exports/api.js";
|
|
@@ -6,46 +6,41 @@ import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/content
|
|
|
6
6
|
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
7
7
|
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
8
8
|
class SchedulePublishEntryUseCaseImpl {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
|
9
|
+
constructor(scheduleAction, accessControl, getModelUseCase){
|
|
10
|
+
this.scheduleAction = scheduleAction;
|
|
11
|
+
this.accessControl = accessControl;
|
|
12
|
+
this.getModelUseCase = getModelUseCase;
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
});
|
|
31
34
|
}
|
|
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
35
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
const SchedulePublishEntryUseCase_SchedulePublishEntryUseCase = SchedulePublishEntryUseCase.createImplementation({
|
|
37
|
+
implementation: SchedulePublishEntryUseCaseImpl,
|
|
38
|
+
dependencies: [
|
|
39
|
+
ScheduleActionUseCase,
|
|
40
|
+
AccessControl,
|
|
41
|
+
GetModelUseCase
|
|
42
|
+
]
|
|
49
43
|
});
|
|
44
|
+
export { SchedulePublishEntryUseCase_SchedulePublishEntryUseCase as SchedulePublishEntryUseCase };
|
|
50
45
|
|
|
51
46
|
//# sourceMappingURL=SchedulePublishEntryUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createAbstraction
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const SchedulePublishEntryUseCase = createAbstraction("CmsScheduler/SchedulePublishEntryUseCase");
|
|
3
|
+
export { SchedulePublishEntryUseCase };
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScheduleUnpublishEntryUseCase
|
|
1
|
+
import { ScheduleUnpublishEntryUseCase } from "./abstractions.js";
|
|
2
2
|
import { ScheduleActionUseCase, ScheduledActionTypeUnpublish } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
3
|
import { createNamespace } from "../../utils/namespace.js";
|
|
4
4
|
import { Result } from "@webiny/feature/exports/api.js";
|
|
@@ -6,46 +6,41 @@ import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstract
|
|
|
6
6
|
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
7
7
|
import { EntryNotAuthorizedError } from "@webiny/api-headless-cms/domain/contentEntry/errors.js";
|
|
8
8
|
class ScheduleUnpublishEntryUseCaseImpl {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
|
9
|
+
constructor(scheduleAction, accessControl, getModelUseCase){
|
|
10
|
+
this.scheduleAction = scheduleAction;
|
|
11
|
+
this.accessControl = accessControl;
|
|
12
|
+
this.getModelUseCase = getModelUseCase;
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
});
|
|
31
34
|
}
|
|
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
35
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
const ScheduleUnpublishEntryUseCase_ScheduleUnpublishEntryUseCase = ScheduleUnpublishEntryUseCase.createImplementation({
|
|
37
|
+
implementation: ScheduleUnpublishEntryUseCaseImpl,
|
|
38
|
+
dependencies: [
|
|
39
|
+
ScheduleActionUseCase,
|
|
40
|
+
AccessControl,
|
|
41
|
+
GetModelUseCase
|
|
42
|
+
]
|
|
49
43
|
});
|
|
44
|
+
export { ScheduleUnpublishEntryUseCase_ScheduleUnpublishEntryUseCase as ScheduleUnpublishEntryUseCase };
|
|
50
45
|
|
|
51
46
|
//# sourceMappingURL=ScheduleUnpublishEntryUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createAbstraction
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const ScheduleUnpublishEntryUseCase = createAbstraction("CmsScheduler/ScheduleUnpublishEntryUseCase");
|
|
3
|
+
export { ScheduleUnpublishEntryUseCase };
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|