@webiny/api-headless-cms-scheduler 6.3.0 → 6.4.0-beta.1

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.
Files changed (35) hide show
  1. package/context.js +9 -10
  2. package/context.js.map +1 -1
  3. package/exports/api/cms/scheduler.js +0 -2
  4. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +30 -44
  5. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -1
  6. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +25 -39
  7. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -1
  8. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +24 -38
  9. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -1
  10. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +25 -39
  11. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js.map +1 -1
  12. package/features/CancelScheduledActionOnEntryChange/feature.js +9 -16
  13. package/features/CancelScheduledActionOnEntryChange/feature.js.map +1 -1
  14. package/features/NamespaceHandler/NamespaceHandler.js +33 -39
  15. package/features/NamespaceHandler/NamespaceHandler.js.map +1 -1
  16. package/features/PublishActionHandler/PublishEntryActionHandler.js +75 -97
  17. package/features/PublishActionHandler/PublishEntryActionHandler.js.map +1 -1
  18. package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js +33 -38
  19. package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js.map +1 -1
  20. package/features/SchedulePublishEntryUseCase/abstractions.js +3 -3
  21. package/features/SchedulePublishEntryUseCase/abstractions.js.map +1 -1
  22. package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js +33 -38
  23. package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js.map +1 -1
  24. package/features/ScheduleUnpublishEntryUseCase/abstractions.js +3 -3
  25. package/features/ScheduleUnpublishEntryUseCase/abstractions.js.map +1 -1
  26. package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js +55 -83
  27. package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js.map +1 -1
  28. package/index.js +4 -3
  29. package/index.js.map +1 -1
  30. package/package.json +16 -16
  31. package/types.js +0 -3
  32. package/utils/namespace.js +6 -9
  33. package/utils/namespace.js.map +1 -1
  34. package/exports/api/cms/scheduler.js.map +0 -1
  35. package/types.js.map +0 -1
@@ -4,94 +4,66 @@ import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEn
4
4
  import { GetPublishedEntriesByIdsUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetPublishedEntriesByIds";
5
5
  import { UnpublishEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UnpublishEntry";
6
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
7
  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;
8
+ constructor(getModelUseCase, getEntryByIdUseCase, getPublishedEntriesByIdsUseCase, unpublishEntryUseCase){
9
+ this.getModelUseCase = getModelUseCase;
10
+ this.getEntryByIdUseCase = getEntryByIdUseCase;
11
+ this.getPublishedEntriesByIdsUseCase = getPublishedEntriesByIdsUseCase;
12
+ this.unpublishEntryUseCase = unpublishEntryUseCase;
28
13
  }
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`);
14
+ canHandle(namespace, actionType) {
15
+ const modelId = extractModelIdFromNamespace(namespace);
16
+ if (!modelId) return false;
17
+ return actionType === ScheduledActionTypeUnpublish;
58
18
  }
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}`);
19
+ async handle(action) {
20
+ const { payload } = action;
21
+ const modelId = payload.modelId;
22
+ const modelResult = await this.getModelUseCase.execute(modelId);
23
+ if (modelResult.isFail()) {
24
+ console.error(`Failed to get model "${modelId}" for scheduled unpublish action:`, modelResult.error);
25
+ throw new Error(`Model not found: ${modelId}`);
26
+ }
27
+ const model = modelResult.value;
28
+ const targetEntryResult = await this.getEntryByIdUseCase.execute(model, action.targetId);
29
+ if (targetEntryResult.isFail()) {
30
+ console.error(`Failed to get entry "${action.targetId}" for scheduled unpublish action:`, targetEntryResult.error);
31
+ throw new Error(`Entry not found: ${action.targetId}`);
32
+ }
33
+ const targetEntry = targetEntryResult.value;
34
+ const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute(model, [
35
+ targetEntry.id
36
+ ]);
37
+ if (publishedEntriesResult.isFail()) {
38
+ console.error(`Failed to get published entries for "${targetEntry.id}":`, publishedEntriesResult.error);
39
+ throw new Error("Failed to check published entries");
40
+ }
41
+ const [publishedTargetEntry] = publishedEntriesResult.value;
42
+ if (!publishedTargetEntry) return void console.warn(`Entry "${action.targetId}" is not published, nothing to unpublish.`);
43
+ if (publishedTargetEntry.id === action.targetId) {
44
+ const unpublishResult = await this.unpublishEntryUseCase.execute(model, action.targetId);
45
+ if (unpublishResult.isFail()) {
46
+ console.error(`Failed to unpublish entry "${action.targetId}":`, unpublishResult.error);
47
+ throw new Error(`Failed to unpublish entry: ${action.targetId}`);
48
+ }
49
+ return;
50
+ }
51
+ const unpublishResult = await this.unpublishEntryUseCase.execute(model, publishedTargetEntry.id);
52
+ if (unpublishResult.isFail()) {
53
+ console.error(`Failed to unpublish published revision "${publishedTargetEntry.id}":`, unpublishResult.error);
54
+ throw new Error(`Failed to unpublish entry: ${publishedTargetEntry.id}`);
55
+ }
89
56
  }
90
- }
91
57
  }
92
- export const UnpublishEntryActionHandler = ScheduledActionHandler.createImplementation({
93
- implementation: UnpublishEntryActionHandlerImpl,
94
- dependencies: [GetModelUseCase, GetEntryByIdUseCase, GetPublishedEntriesByIdsUseCase, UnpublishEntryUseCase]
58
+ const UnpublishEntryActionHandler = ScheduledActionHandler.createImplementation({
59
+ implementation: UnpublishEntryActionHandlerImpl,
60
+ dependencies: [
61
+ GetModelUseCase,
62
+ GetEntryByIdUseCase,
63
+ GetPublishedEntriesByIdsUseCase,
64
+ UnpublishEntryUseCase
65
+ ]
95
66
  });
67
+ export { UnpublishEntryActionHandler };
96
68
 
97
69
  //# sourceMappingURL=UnpublishEntryActionHandler.js.map
@@ -1 +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 GetPubl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8BN,MAAM,CAACW,QAAQ,IAAI,EACjDM,eAAe,CAACX,KACpB,CAAC;QACD,MAAM,IAAIC,KAAK,CAAC,8BAA8BP,MAAM,CAACW,QAAQ,EAAE,CAAC;MACpE;MACA;IACJ;;IAEA;AACR;AACA;AACA;IACQ,MAAMM,eAAe,GAAG,MAAM,IAAI,CAACvB,qBAAqB,CAACS,OAAO,CAE9DK,KAAK,EAAEO,oBAAoB,CAACD,EAAE,CAAC;IACjC,IAAIG,eAAe,CAACb,MAAM,CAAC,CAAC,EAAE;MAC1BC,OAAO,CAACC,KAAK,CACT,2CAA2CS,oBAAoB,CAACD,EAAE,IAAI,EACtEG,eAAe,CAACX,KACpB,CAAC;MACD,MAAM,IAAIC,KAAK,CAAC,8BAA8BQ,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":[]}
1
+ {"version":3,"file":"features/UnpublishActionHandler/UnpublishEntryActionHandler.js","sources":["../../../src/features/UnpublishActionHandler/UnpublishEntryActionHandler.ts"],"sourcesContent":["import {\n type IScheduledAction,\n ScheduledActionHandler,\n ScheduledActionTypeUnpublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { GetPublishedEntriesByIdsUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetPublishedEntriesByIds\";\nimport { UnpublishEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UnpublishEntry\";\nimport type { IScheduledActionPayload } from \"~/types.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\nimport type { ScheduledActionType } from \"@webiny/api-scheduler/shared/abstractions.js\";\n\n/**\n * Handler for unpublishing CMS entries\n *\n * Handles the \"Unpublish\" action for CMS entries with namespace pattern: Cms/Entry/{modelId}\n *\n * Unpublishing logic:\n * 1. If entry is not published -> nothing to do (warn)\n * 2. If target entry is published (same revision) -> unpublish it\n * 3. If a different revision is published -> unpublish it anyway\n */\nclass UnpublishEntryActionHandlerImpl implements ScheduledActionHandler.Interface {\n constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private getEntryByIdUseCase: GetEntryByIdUseCase.Interface,\n private getPublishedEntriesByIdsUseCase: GetPublishedEntriesByIdsUseCase.Interface,\n private unpublishEntryUseCase: UnpublishEntryUseCase.Interface\n ) {}\n\n canHandle(namespace: string, actionType: ScheduledActionType): boolean {\n const modelId = extractModelIdFromNamespace(namespace);\n if (!modelId) {\n return false;\n }\n return actionType === ScheduledActionTypeUnpublish;\n }\n\n async handle(action: IScheduledAction<IScheduledActionPayload>): Promise<void> {\n const { payload } = action;\n\n const modelId = payload.modelId as string;\n\n // Fetch the model\n const modelResult = await this.getModelUseCase.execute(modelId);\n if (modelResult.isFail()) {\n console.error(\n `Failed to get model \"${modelId}\" for scheduled unpublish action:`,\n modelResult.error\n );\n throw new Error(`Model not found: ${modelId}`);\n }\n\n const model = modelResult.value;\n\n // Fetch the target entry\n const targetEntryResult = await this.getEntryByIdUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, action.targetId);\n if (targetEntryResult.isFail()) {\n console.error(\n `Failed to get entry \"${action.targetId}\" for scheduled unpublish action:`,\n targetEntryResult.error\n );\n throw new Error(`Entry not found: ${action.targetId}`);\n }\n\n const targetEntry = targetEntryResult.value;\n\n // Get published entries\n const publishedEntriesResult = await this.getPublishedEntriesByIdsUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, [targetEntry.id]);\n\n if (publishedEntriesResult.isFail()) {\n console.error(\n `Failed to get published entries for \"${targetEntry.id}\":`,\n publishedEntriesResult.error\n );\n throw new Error(`Failed to check published entries`);\n }\n\n const [publishedTargetEntry] = publishedEntriesResult.value;\n\n /**\n * Scenario 1: Entry is not published -> nothing to do\n */\n if (!publishedTargetEntry) {\n console.warn(`Entry \"${action.targetId}\" is not published, nothing to unpublish.`);\n return;\n }\n\n /**\n * Scenario 2: Target entry is published (same revision) -> unpublish it\n */\n if (publishedTargetEntry.id === action.targetId) {\n const unpublishResult = await this.unpublishEntryUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, action.targetId);\n if (unpublishResult.isFail()) {\n console.error(\n `Failed to unpublish entry \"${action.targetId}\":`,\n unpublishResult.error\n );\n throw new Error(`Failed to unpublish entry: ${action.targetId}`);\n }\n return;\n }\n\n /**\n * Scenario 3: A different revision is published -> unpublish it anyway\n * TODO: Determine if we really want to unpublish an entry which does not match the target ID\n */\n const unpublishResult = await this.unpublishEntryUseCase.execute<\n IScheduledAction<IScheduledActionPayload>\n >(model, publishedTargetEntry.id);\n if (unpublishResult.isFail()) {\n console.error(\n `Failed to unpublish published revision \"${publishedTargetEntry.id}\":`,\n unpublishResult.error\n );\n throw new Error(`Failed to unpublish entry: ${publishedTargetEntry.id}`);\n }\n }\n}\n\nexport const UnpublishEntryActionHandler = ScheduledActionHandler.createImplementation({\n implementation: UnpublishEntryActionHandlerImpl,\n dependencies: [\n GetModelUseCase,\n GetEntryByIdUseCase,\n GetPublishedEntriesByIdsUseCase,\n UnpublishEntryUseCase\n ]\n});\n"],"names":["UnpublishEntryActionHandlerImpl","getModelUseCase","getEntryByIdUseCase","getPublishedEntriesByIdsUseCase","unpublishEntryUseCase","namespace","actionType","modelId","extractModelIdFromNamespace","ScheduledActionTypeUnpublish","action","payload","modelResult","console","Error","model","targetEntryResult","targetEntry","publishedEntriesResult","publishedTargetEntry","unpublishResult","UnpublishEntryActionHandler","ScheduledActionHandler","GetModelUseCase","GetEntryByIdUseCase","GetPublishedEntriesByIdsUseCase","Un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AAEI,YAAY,EAAE,CAAC,EAAE,CAAC,EAC1DC,uBAAuB,KAAK;YAEhC,MAAM,IAAIJ,MAAM;QACpB;QAEA,MAAM,CAACK,qBAAqB,GAAGD,uBAAuB,KAAK;QAK3D,IAAI,CAACC,sBAAsB,YACvBN,QAAQ,IAAI,CAAC,CAAC,OAAO,EAAEH,OAAO,QAAQ,CAAC,yCAAyC,CAAC;QAOrF,IAAIS,qBAAqB,EAAE,KAAKT,OAAO,QAAQ,EAAE;YAC7C,MAAMU,kBAAkB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAE9DL,OAAOL,OAAO,QAAQ;YACxB,IAAIU,gBAAgB,MAAM,IAAI;gBAC1BP,QAAQ,KAAK,CACT,CAAC,2BAA2B,EAAEH,OAAO,QAAQ,CAAC,EAAE,CAAC,EACjDU,gBAAgB,KAAK;gBAEzB,MAAM,IAAIN,MAAM,CAAC,2BAA2B,EAAEJ,OAAO,QAAQ,EAAE;YACnE;YACA;QACJ;QAMA,MAAMU,kBAAkB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAE9DL,OAAOI,qBAAqB,EAAE;QAChC,IAAIC,gBAAgB,MAAM,IAAI;YAC1BP,QAAQ,KAAK,CACT,CAAC,wCAAwC,EAAEM,qBAAqB,EAAE,CAAC,EAAE,CAAC,EACtEC,gBAAgB,KAAK;YAEzB,MAAM,IAAIN,MAAM,CAAC,2BAA2B,EAAEK,qBAAqB,EAAE,EAAE;QAC3E;IACJ;AACJ;AAEO,MAAME,8BAA8BC,uBAAuB,oBAAoB,CAAC;IACnF,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;KACH;AACL"}
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHeadlessCmsScheduleContext } from "./context.js";
2
- export const createHeadlessCmsScheduler = () => {
3
- return [createHeadlessCmsScheduleContext()];
4
- };
2
+ const createHeadlessCmsScheduler = ()=>[
3
+ createHeadlessCmsScheduleContext()
4
+ ];
5
+ export { createHeadlessCmsScheduler };
5
6
 
6
7
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createHeadlessCmsScheduleContext } from \"~/context.js\";\nimport { ContextPlugin } from \"@webiny/api\";\n\nexport const createHeadlessCmsScheduler = (): ContextPlugin[] => {\n return [createHeadlessCmsScheduleContext()];\n};\n"],"names":["createHeadlessCmsScheduler","createHeadlessCmsScheduleContext"],"mappings":";AAGO,MAAMA,6BAA6B,IAC/B;QAACC;KAAmC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-scheduler",
3
- "version": "6.3.0",
3
+ "version": "6.4.0-beta.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -17,28 +17,28 @@
17
17
  },
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@webiny/api": "6.3.0",
21
- "@webiny/api-headless-cms": "6.3.0",
22
- "@webiny/api-scheduler": "6.3.0",
23
- "@webiny/feature": "6.3.0",
24
- "@webiny/handler-graphql": "6.3.0"
20
+ "@webiny/api": "6.4.0-beta.1",
21
+ "@webiny/api-headless-cms": "6.4.0-beta.1",
22
+ "@webiny/api-scheduler": "6.4.0-beta.1",
23
+ "@webiny/feature": "6.4.0-beta.1",
24
+ "@webiny/handler-graphql": "6.4.0-beta.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@webiny/api-core": "6.3.0",
28
- "@webiny/aws-sdk": "6.3.0",
29
- "@webiny/build-tools": "6.3.0",
30
- "@webiny/handler": "6.3.0",
31
- "@webiny/handler-aws": "6.3.0",
32
- "@webiny/plugins": "6.3.0",
33
- "@webiny/project-utils": "6.3.0",
34
- "@webiny/wcp": "6.3.0",
27
+ "@webiny/api-core": "6.4.0-beta.1",
28
+ "@webiny/aws-sdk": "6.4.0-beta.1",
29
+ "@webiny/build-tools": "6.4.0-beta.1",
30
+ "@webiny/handler": "6.4.0-beta.1",
31
+ "@webiny/handler-aws": "6.4.0-beta.1",
32
+ "@webiny/plugins": "6.4.0-beta.1",
33
+ "@webiny/project-utils": "6.4.0-beta.1",
34
+ "@webiny/wcp": "6.4.0-beta.1",
35
35
  "aws-sdk-client-mock": "4.1.0",
36
36
  "typescript": "6.0.3",
37
- "vitest": "4.1.5"
37
+ "vitest": "4.1.6"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public",
41
41
  "directory": "dist"
42
42
  },
43
- "gitHead": "7cefe15431dbd65504e1f58147dc9e55bcbfa693"
43
+ "gitHead": "73237b8243693038c072bae1c0b783387448cbbe"
44
44
  }
package/types.js CHANGED
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1,12 +1,9 @@
1
- export const CMS_NAMESPACE = "Cms/Entry/";
2
- export const createNamespace = model => {
3
- return `${CMS_NAMESPACE}${model.modelId}`;
4
- };
5
- export const extractModelIdFromNamespace = namespace => {
6
- if (!namespace.startsWith(CMS_NAMESPACE)) {
7
- return null;
8
- }
9
- return namespace.substring(CMS_NAMESPACE.length) || null;
1
+ const CMS_NAMESPACE = "Cms/Entry/";
2
+ const createNamespace = (model)=>`${CMS_NAMESPACE}${model.modelId}`;
3
+ const extractModelIdFromNamespace = (namespace)=>{
4
+ if (!namespace.startsWith(CMS_NAMESPACE)) return null;
5
+ return namespace.substring(CMS_NAMESPACE.length) || null;
10
6
  };
7
+ export { CMS_NAMESPACE, createNamespace, extractModelIdFromNamespace };
11
8
 
12
9
  //# sourceMappingURL=namespace.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["CMS_NAMESPACE","createNamespace","model","modelId","extractModelIdFromNamespace","namespace","startsWith","substring","length"],"sources":["namespace.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport const CMS_NAMESPACE = \"Cms/Entry/\";\n\nexport const createNamespace = (model: Pick<CmsModel, \"modelId\">) => {\n return `${CMS_NAMESPACE}${model.modelId}`;\n};\n\nexport const extractModelIdFromNamespace = (namespace: string): string | null => {\n if (!namespace.startsWith(CMS_NAMESPACE)) {\n return null;\n }\n return namespace.substring(CMS_NAMESPACE.length) || null;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,aAAa,GAAG,YAAY;AAEzC,OAAO,MAAMC,eAAe,GAAIC,KAAgC,IAAK;EACjE,OAAO,GAAGF,aAAa,GAAGE,KAAK,CAACC,OAAO,EAAE;AAC7C,CAAC;AAED,OAAO,MAAMC,2BAA2B,GAAIC,SAAiB,IAAoB;EAC7E,IAAI,CAACA,SAAS,CAACC,UAAU,CAACN,aAAa,CAAC,EAAE;IACtC,OAAO,IAAI;EACf;EACA,OAAOK,SAAS,CAACE,SAAS,CAACP,aAAa,CAACQ,MAAM,CAAC,IAAI,IAAI;AAC5D,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/namespace.js","sources":["../../src/utils/namespace.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport const CMS_NAMESPACE = \"Cms/Entry/\";\n\nexport const createNamespace = (model: Pick<CmsModel, \"modelId\">) => {\n return `${CMS_NAMESPACE}${model.modelId}`;\n};\n\nexport const extractModelIdFromNamespace = (namespace: string): string | null => {\n if (!namespace.startsWith(CMS_NAMESPACE)) {\n return null;\n }\n return namespace.substring(CMS_NAMESPACE.length) || null;\n};\n"],"names":["CMS_NAMESPACE","createNamespace","model","extractModelIdFromNamespace","namespace"],"mappings":"AAEO,MAAMA,gBAAgB;AAEtB,MAAMC,kBAAkB,CAACC,QACrB,GAAGF,gBAAgBE,MAAM,OAAO,EAAE;AAGtC,MAAMC,8BAA8B,CAACC;IACxC,IAAI,CAACA,UAAU,UAAU,CAACJ,gBACtB,OAAO;IAEX,OAAOI,UAAU,SAAS,CAACJ,cAAc,MAAM,KAAK;AACxD"}
@@ -1 +0,0 @@
1
- {"version":3,"names":["SchedulePublishEntryUseCase","ScheduleUnpublishEntryUseCase"],"sources":["scheduler.ts"],"sourcesContent":["export { SchedulePublishEntryUseCase } from \"~/features/SchedulePublishEntryUseCase/abstractions.js\";\nexport { ScheduleUnpublishEntryUseCase } from \"~/features/ScheduleUnpublishEntryUseCase/abstractions.js\";\n"],"mappings":"AAAA,SAASA,2BAA2B;AACpC,SAASC,6BAA6B","ignoreList":[]}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { INamespaceHandlerResult } from \"@webiny/api-scheduler/features/NamespaceHandler/abstractions.js\";\n\nexport interface IScheduledActionPayload extends INamespaceHandlerResult {\n modelId: string;\n}\n"],"mappings":"","ignoreList":[]}