@webiny/api-headless-cms-scheduler 6.0.0-alpha.5 → 6.0.0-rc.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 (133) hide show
  1. package/README.md +11 -15
  2. package/context.d.ts +2 -7
  3. package/context.js +9 -64
  4. package/context.js.map +1 -1
  5. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.d.ts +20 -0
  6. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +51 -0
  7. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -0
  8. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.d.ts +19 -0
  9. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +48 -0
  10. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -0
  11. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.d.ts +19 -0
  12. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +47 -0
  13. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -0
  14. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.d.ts +19 -0
  15. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +48 -0
  16. package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js.map +1 -0
  17. package/features/CancelScheduledActionOnEntryChange/feature.d.ts +8 -0
  18. package/features/CancelScheduledActionOnEntryChange/feature.js +24 -0
  19. package/features/CancelScheduledActionOnEntryChange/feature.js.map +1 -0
  20. package/features/CancelScheduledEntryAction/CancelScheduledEntryActionUseCase.d.ts +15 -0
  21. package/features/CancelScheduledEntryAction/CancelScheduledEntryActionUseCase.js +25 -0
  22. package/features/CancelScheduledEntryAction/CancelScheduledEntryActionUseCase.js.map +1 -0
  23. package/features/CancelScheduledEntryAction/abstractions.d.ts +22 -0
  24. package/features/CancelScheduledEntryAction/abstractions.js +11 -0
  25. package/features/CancelScheduledEntryAction/abstractions.js.map +1 -0
  26. package/features/CancelScheduledEntryAction/feature.d.ts +6 -0
  27. package/features/CancelScheduledEntryAction/feature.js +16 -0
  28. package/features/CancelScheduledEntryAction/feature.js.map +1 -0
  29. package/features/CancelScheduledEntryAction/index.d.ts +1 -0
  30. package/features/CancelScheduledEntryAction/index.js +3 -0
  31. package/features/CancelScheduledEntryAction/index.js.map +1 -0
  32. package/features/ScheduleEntryAction/ScheduleEntryActionUseCase.d.ts +27 -0
  33. package/features/ScheduleEntryAction/ScheduleEntryActionUseCase.js +83 -0
  34. package/features/ScheduleEntryAction/ScheduleEntryActionUseCase.js.map +1 -0
  35. package/features/ScheduleEntryAction/abstractions.d.ts +45 -0
  36. package/features/ScheduleEntryAction/abstractions.js +15 -0
  37. package/features/ScheduleEntryAction/abstractions.js.map +1 -0
  38. package/features/ScheduleEntryAction/actionHandlers/PublishEntryActionHandler.d.ts +35 -0
  39. package/features/ScheduleEntryAction/actionHandlers/PublishEntryActionHandler.js +109 -0
  40. package/features/ScheduleEntryAction/actionHandlers/PublishEntryActionHandler.js.map +1 -0
  41. package/features/ScheduleEntryAction/actionHandlers/UnpublishEntryActionHandler.d.ts +29 -0
  42. package/features/ScheduleEntryAction/actionHandlers/UnpublishEntryActionHandler.js +92 -0
  43. package/features/ScheduleEntryAction/actionHandlers/UnpublishEntryActionHandler.js.map +1 -0
  44. package/features/ScheduleEntryAction/feature.d.ts +7 -0
  45. package/features/ScheduleEntryAction/feature.js +21 -0
  46. package/features/ScheduleEntryAction/feature.js.map +1 -0
  47. package/features/ScheduleEntryAction/index.d.ts +1 -0
  48. package/features/ScheduleEntryAction/index.js +3 -0
  49. package/features/ScheduleEntryAction/index.js.map +1 -0
  50. package/graphql/ActionMapper.d.ts +15 -0
  51. package/graphql/ActionMapper.js +18 -0
  52. package/graphql/ActionMapper.js.map +1 -0
  53. package/{scheduler → graphql}/dates.d.ts +1 -2
  54. package/graphql/dates.js +9 -0
  55. package/graphql/dates.js.map +1 -0
  56. package/graphql/index.d.ts +2 -2
  57. package/graphql/index.js +113 -71
  58. package/graphql/index.js.map +1 -1
  59. package/graphql/schema.d.ts +93 -148
  60. package/graphql/schema.js +51 -55
  61. package/graphql/schema.js.map +1 -1
  62. package/index.d.ts +3 -7
  63. package/index.js +5 -22
  64. package/index.js.map +1 -1
  65. package/package.json +20 -22
  66. package/constants.d.ts +0 -11
  67. package/constants.js +0 -19
  68. package/constants.js.map +0 -1
  69. package/handler/Handler.d.ts +0 -23
  70. package/handler/Handler.js +0 -74
  71. package/handler/Handler.js.map +0 -1
  72. package/handler/actions/PublishHandlerAction.d.ts +0 -13
  73. package/handler/actions/PublishHandlerAction.js +0 -64
  74. package/handler/actions/PublishHandlerAction.js.map +0 -1
  75. package/handler/actions/UnpublishHandlerAction.d.ts +0 -13
  76. package/handler/actions/UnpublishHandlerAction.js +0 -53
  77. package/handler/actions/UnpublishHandlerAction.js.map +0 -1
  78. package/handler/index.d.ts +0 -7
  79. package/handler/index.js +0 -64
  80. package/handler/index.js.map +0 -1
  81. package/handler/types.d.ts +0 -5
  82. package/handler/types.js +0 -7
  83. package/handler/types.js.map +0 -1
  84. package/hooks/index.d.ts +0 -7
  85. package/hooks/index.js +0 -58
  86. package/hooks/index.js.map +0 -1
  87. package/manifest.d.ts +0 -17
  88. package/manifest.js +0 -47
  89. package/manifest.js.map +0 -1
  90. package/scheduler/ScheduleExecutor.d.ts +0 -16
  91. package/scheduler/ScheduleExecutor.js +0 -55
  92. package/scheduler/ScheduleExecutor.js.map +0 -1
  93. package/scheduler/ScheduleFetcher.d.ts +0 -16
  94. package/scheduler/ScheduleFetcher.js +0 -51
  95. package/scheduler/ScheduleFetcher.js.map +0 -1
  96. package/scheduler/ScheduleRecord.d.ts +0 -31
  97. package/scheduler/ScheduleRecord.js +0 -57
  98. package/scheduler/ScheduleRecord.js.map +0 -1
  99. package/scheduler/Scheduler.d.ts +0 -14
  100. package/scheduler/Scheduler.js +0 -27
  101. package/scheduler/Scheduler.js.map +0 -1
  102. package/scheduler/actions/PublishScheduleAction.d.ts +0 -26
  103. package/scheduler/actions/PublishScheduleAction.js +0 -196
  104. package/scheduler/actions/PublishScheduleAction.js.map +0 -1
  105. package/scheduler/actions/UnpublishScheduleAction.d.ts +0 -26
  106. package/scheduler/actions/UnpublishScheduleAction.js +0 -194
  107. package/scheduler/actions/UnpublishScheduleAction.js.map +0 -1
  108. package/scheduler/createScheduleRecordId.d.ts +0 -2
  109. package/scheduler/createScheduleRecordId.js +0 -33
  110. package/scheduler/createScheduleRecordId.js.map +0 -1
  111. package/scheduler/createScheduler.d.ts +0 -12
  112. package/scheduler/createScheduler.js +0 -65
  113. package/scheduler/createScheduler.js.map +0 -1
  114. package/scheduler/dates.js +0 -27
  115. package/scheduler/dates.js.map +0 -1
  116. package/scheduler/model.d.ts +0 -1
  117. package/scheduler/model.js +0 -88
  118. package/scheduler/model.js.map +0 -1
  119. package/scheduler/types.d.ts +0 -88
  120. package/scheduler/types.js +0 -19
  121. package/scheduler/types.js.map +0 -1
  122. package/service/SchedulerService.d.ts +0 -23
  123. package/service/SchedulerService.js +0 -151
  124. package/service/SchedulerService.js.map +0 -1
  125. package/service/types.d.ts +0 -19
  126. package/service/types.js +0 -7
  127. package/service/types.js.map +0 -1
  128. package/types.d.ts +0 -11
  129. package/types.js +0 -7
  130. package/types.js.map +0 -1
  131. package/utils/dateInTheFuture.d.ts +0 -6
  132. package/utils/dateInTheFuture.js +0 -19
  133. package/utils/dateInTheFuture.js.map +0 -1
package/constants.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SCHEDULE_MODEL_ID = exports.SCHEDULE_MIN_FUTURE_SECONDS = exports.SCHEDULE_ID_PREFIX = exports.SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER = void 0;
7
- const SCHEDULE_MODEL_ID = exports.SCHEDULE_MODEL_ID = "webinyCmsSchedule";
8
- const SCHEDULE_ID_PREFIX = exports.SCHEDULE_ID_PREFIX = "wby-schedule-";
9
- /**
10
- * Minimum number of seconds in the future that a schedule can be set.
11
- * Everything else will result in immediately running the action.
12
- */
13
- const SCHEDULE_MIN_FUTURE_SECONDS = exports.SCHEDULE_MIN_FUTURE_SECONDS = 65;
14
- /**
15
- *
16
- */
17
- const SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER = exports.SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER = "WebinyScheduledCmsAction";
18
-
19
- //# sourceMappingURL=constants.js.map
package/constants.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["SCHEDULE_MODEL_ID","exports","SCHEDULE_ID_PREFIX","SCHEDULE_MIN_FUTURE_SECONDS","SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER"],"sources":["constants.ts"],"sourcesContent":["export const SCHEDULE_MODEL_ID = \"webinyCmsSchedule\";\nexport const SCHEDULE_ID_PREFIX = \"wby-schedule-\";\n/**\n * Minimum number of seconds in the future that a schedule can be set.\n * Everything else will result in immediately running the action.\n */\nexport const SCHEDULE_MIN_FUTURE_SECONDS = 65;\n/**\n *\n */\nexport const SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER = \"WebinyScheduledCmsAction\";\n"],"mappings":";;;;;;AAAO,MAAMA,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,mBAAmB;AAC7C,MAAME,kBAAkB,GAAAD,OAAA,CAAAC,kBAAA,GAAG,eAAe;AACjD;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAAF,OAAA,CAAAE,2BAAA,GAAG,EAAE;AAC7C;AACA;AACA;AACO,MAAMC,qCAAqC,GAAAH,OAAA,CAAAG,qCAAA,GAAG,0BAA0B","ignoreList":[]}
@@ -1,23 +0,0 @@
1
- import { SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER } from "../constants.js";
2
- import type { IHandlerAction } from "./types.js";
3
- import type { ScheduleContext } from "../types.js";
4
- export interface IHandlerParams {
5
- actions: IHandlerAction[];
6
- }
7
- export interface IHandlerHandleParams {
8
- payload: IWebinyScheduledCmsActionEvent;
9
- cms: Pick<ScheduleContext["cms"], "scheduler" | "getEntryManager" | "getModel">;
10
- security: Pick<ScheduleContext["security"], "setIdentity" | "withoutAuthorization">;
11
- }
12
- export interface IWebinyScheduledCmsActionEventValues {
13
- id: string;
14
- scheduleOn: string;
15
- }
16
- export interface IWebinyScheduledCmsActionEvent {
17
- [SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER]: IWebinyScheduledCmsActionEventValues;
18
- }
19
- export declare class Handler {
20
- private readonly actions;
21
- constructor(params: IHandlerParams);
22
- handle(params: IHandlerHandleParams): Promise<void>;
23
- }
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Handler = void 0;
7
- var _index = require("@webiny/error/index");
8
- var _constants = require("../constants.js");
9
- var _createIdentifier = require("@webiny/utils/createIdentifier.js");
10
- class Handler {
11
- constructor(params) {
12
- this.actions = params.actions;
13
- }
14
- async handle(params) {
15
- const {
16
- payload,
17
- cms,
18
- security
19
- } = params;
20
- const values = payload[_constants.SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER];
21
- const scheduleEntryManager = await security.withoutAuthorization(async () => {
22
- return cms.getEntryManager(_constants.SCHEDULE_MODEL_ID);
23
- });
24
- const scheduleEntryId = (0, _createIdentifier.createIdentifier)({
25
- id: values.id,
26
- version: 1
27
- });
28
- /**
29
- * Just fetch the schedule entry so we know the model it is targeting.
30
- */
31
- const scheduleEntry = await security.withoutAuthorization(async () => {
32
- return scheduleEntryManager.get(scheduleEntryId);
33
- });
34
- /**
35
- * We want to mock the identity of the user that scheduled this record.
36
- */
37
- security.setIdentity(scheduleEntry.createdBy);
38
- const targetModel = await cms.getModel(scheduleEntry.values.targetModelId);
39
- /**
40
- * We want a formatted schedule record to be used later.
41
- */
42
- const scheduler = cms.scheduler(targetModel);
43
- const scheduleRecord = await scheduler.getScheduled(scheduleEntryId);
44
- /**
45
- * Should not happen as we fetched it a few lines up, just in different format.
46
- */
47
- if (!scheduleRecord) {
48
- throw new _index.WebinyError(`No schedule record found for ID: ${scheduleEntryId}`, "SCHEDULE_RECORD_NOT_FOUND", values);
49
- }
50
- const action = this.actions.find(action => action.canHandle(scheduleRecord));
51
- if (!action) {
52
- await scheduleEntryManager.update(scheduleEntryId, {
53
- error: `No action found for schedule record ID.`
54
- });
55
- throw new _index.WebinyError(`No action found for schedule record ID: ${scheduleEntryId}`, "NO_ACTION_FOUND", scheduleRecord);
56
- }
57
- try {
58
- await action.handle(scheduleRecord);
59
- } catch (ex) {
60
- console.error(`Error while handling schedule record ID: ${scheduleEntryId}`);
61
- await scheduleEntryManager.update(scheduleEntryId, {
62
- error: ex.message
63
- });
64
- throw ex;
65
- }
66
- /**
67
- * Everything is ok. Delete the schedule record.
68
- */
69
- await scheduleEntryManager.delete(scheduleEntryId);
70
- }
71
- }
72
- exports.Handler = Handler;
73
-
74
- //# sourceMappingURL=Handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_index","require","_constants","_createIdentifier","Handler","constructor","params","actions","handle","payload","cms","security","values","SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER","scheduleEntryManager","withoutAuthorization","getEntryManager","SCHEDULE_MODEL_ID","scheduleEntryId","createIdentifier","id","version","scheduleEntry","get","setIdentity","createdBy","targetModel","getModel","targetModelId","scheduler","scheduleRecord","getScheduled","WebinyError","action","find","canHandle","update","error","ex","console","message","delete","exports"],"sources":["Handler.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error/index\";\nimport { SCHEDULE_MODEL_ID, SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport type { IHandlerAction } from \"~/handler/types.js\";\nimport type { IScheduleEntryValues } from \"~/scheduler/types.js\";\nimport type { ScheduleContext } from \"~/types.js\";\nimport { createIdentifier } from \"@webiny/utils/createIdentifier.js\";\n\nexport interface IHandlerParams {\n actions: IHandlerAction[];\n}\n\nexport interface IHandlerHandleParams {\n payload: IWebinyScheduledCmsActionEvent;\n cms: Pick<ScheduleContext[\"cms\"], \"scheduler\" | \"getEntryManager\" | \"getModel\">;\n security: Pick<ScheduleContext[\"security\"], \"setIdentity\" | \"withoutAuthorization\">;\n}\n\nexport interface IWebinyScheduledCmsActionEventValues {\n id: string; // id of the schedule record\n scheduleOn: string;\n}\n\nexport interface IWebinyScheduledCmsActionEvent {\n [SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER]: IWebinyScheduledCmsActionEventValues;\n}\n\nexport class Handler {\n private readonly actions: IHandlerAction[];\n\n public constructor(params: IHandlerParams) {\n this.actions = params.actions;\n }\n public async handle(params: IHandlerHandleParams): Promise<void> {\n const { payload, cms, security } = params;\n\n const values = payload[SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER];\n const scheduleEntryManager = await security.withoutAuthorization(async () => {\n return cms.getEntryManager<IScheduleEntryValues>(SCHEDULE_MODEL_ID);\n });\n\n const scheduleEntryId = createIdentifier({\n id: values.id,\n version: 1\n });\n /**\n * Just fetch the schedule entry so we know the model it is targeting.\n */\n const scheduleEntry = await security.withoutAuthorization(async () => {\n return scheduleEntryManager.get(scheduleEntryId);\n });\n /**\n * We want to mock the identity of the user that scheduled this record.\n */\n security.setIdentity(scheduleEntry.createdBy);\n\n const targetModel = await cms.getModel(scheduleEntry.values.targetModelId);\n /**\n * We want a formatted schedule record to be used later.\n */\n const scheduler = cms.scheduler(targetModel);\n const scheduleRecord = await scheduler.getScheduled(scheduleEntryId);\n /**\n * Should not happen as we fetched it a few lines up, just in different format.\n */\n if (!scheduleRecord) {\n throw new WebinyError(\n `No schedule record found for ID: ${scheduleEntryId}`,\n \"SCHEDULE_RECORD_NOT_FOUND\",\n values\n );\n }\n\n const action = this.actions.find(action => action.canHandle(scheduleRecord));\n if (!action) {\n await scheduleEntryManager.update(scheduleEntryId, {\n error: `No action found for schedule record ID.`\n });\n throw new WebinyError(\n `No action found for schedule record ID: ${scheduleEntryId}`,\n \"NO_ACTION_FOUND\",\n scheduleRecord\n );\n }\n\n try {\n await action.handle(scheduleRecord);\n } catch (ex) {\n console.error(`Error while handling schedule record ID: ${scheduleEntryId}`);\n await scheduleEntryManager.update(scheduleEntryId, {\n error: ex.message\n });\n throw ex;\n }\n /**\n * Everything is ok. Delete the schedule record.\n */\n await scheduleEntryManager.delete(scheduleEntryId);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAIA,IAAAE,iBAAA,GAAAF,OAAA;AAqBO,MAAMG,OAAO,CAAC;EAGVC,WAAWA,CAACC,MAAsB,EAAE;IACvC,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;EACjC;EACA,MAAaC,MAAMA,CAACF,MAA4B,EAAiB;IAC7D,MAAM;MAAEG,OAAO;MAAEC,GAAG;MAAEC;IAAS,CAAC,GAAGL,MAAM;IAEzC,MAAMM,MAAM,GAAGH,OAAO,CAACI,gDAAqC,CAAC;IAC7D,MAAMC,oBAAoB,GAAG,MAAMH,QAAQ,CAACI,oBAAoB,CAAC,YAAY;MACzE,OAAOL,GAAG,CAACM,eAAe,CAAuBC,4BAAiB,CAAC;IACvE,CAAC,CAAC;IAEF,MAAMC,eAAe,GAAG,IAAAC,kCAAgB,EAAC;MACrCC,EAAE,EAAER,MAAM,CAACQ,EAAE;MACbC,OAAO,EAAE;IACb,CAAC,CAAC;IACF;AACR;AACA;IACQ,MAAMC,aAAa,GAAG,MAAMX,QAAQ,CAACI,oBAAoB,CAAC,YAAY;MAClE,OAAOD,oBAAoB,CAACS,GAAG,CAACL,eAAe,CAAC;IACpD,CAAC,CAAC;IACF;AACR;AACA;IACQP,QAAQ,CAACa,WAAW,CAACF,aAAa,CAACG,SAAS,CAAC;IAE7C,MAAMC,WAAW,GAAG,MAAMhB,GAAG,CAACiB,QAAQ,CAACL,aAAa,CAACV,MAAM,CAACgB,aAAa,CAAC;IAC1E;AACR;AACA;IACQ,MAAMC,SAAS,GAAGnB,GAAG,CAACmB,SAAS,CAACH,WAAW,CAAC;IAC5C,MAAMI,cAAc,GAAG,MAAMD,SAAS,CAACE,YAAY,CAACb,eAAe,CAAC;IACpE;AACR;AACA;IACQ,IAAI,CAACY,cAAc,EAAE;MACjB,MAAM,IAAIE,kBAAW,CACjB,oCAAoCd,eAAe,EAAE,EACrD,2BAA2B,EAC3BN,MACJ,CAAC;IACL;IAEA,MAAMqB,MAAM,GAAG,IAAI,CAAC1B,OAAO,CAAC2B,IAAI,CAACD,MAAM,IAAIA,MAAM,CAACE,SAAS,CAACL,cAAc,CAAC,CAAC;IAC5E,IAAI,CAACG,MAAM,EAAE;MACT,MAAMnB,oBAAoB,CAACsB,MAAM,CAAClB,eAAe,EAAE;QAC/CmB,KAAK,EAAE;MACX,CAAC,CAAC;MACF,MAAM,IAAIL,kBAAW,CACjB,2CAA2Cd,eAAe,EAAE,EAC5D,iBAAiB,EACjBY,cACJ,CAAC;IACL;IAEA,IAAI;MACA,MAAMG,MAAM,CAACzB,MAAM,CAACsB,cAAc,CAAC;IACvC,CAAC,CAAC,OAAOQ,EAAE,EAAE;MACTC,OAAO,CAACF,KAAK,CAAC,4CAA4CnB,eAAe,EAAE,CAAC;MAC5E,MAAMJ,oBAAoB,CAACsB,MAAM,CAAClB,eAAe,EAAE;QAC/CmB,KAAK,EAAEC,EAAE,CAACE;MACd,CAAC,CAAC;MACF,MAAMF,EAAE;IACZ;IACA;AACR;AACA;IACQ,MAAMxB,oBAAoB,CAAC2B,MAAM,CAACvB,eAAe,CAAC;EACtD;AACJ;AAACwB,OAAA,CAAAtC,OAAA,GAAAA,OAAA","ignoreList":[]}
@@ -1,13 +0,0 @@
1
- import type { IHandlerAction } from "../types.js";
2
- import type { IScheduleRecord } from "../../scheduler/types.js";
3
- import type { ScheduleContext } from "../../types.js";
4
- export type IPublishHandlerActionParamsCms = Pick<ScheduleContext["cms"], "getEntryById" | "getPublishedEntriesByIds" | "publishEntry" | "unpublishEntry" | "republishEntry">;
5
- export interface IPublishHandlerActionParams {
6
- cms: IPublishHandlerActionParamsCms;
7
- }
8
- export declare class PublishHandlerAction implements IHandlerAction {
9
- private readonly cms;
10
- constructor(params: IPublishHandlerActionParams);
11
- canHandle(record: Pick<IScheduleRecord, "type">): boolean;
12
- handle(record: Pick<IScheduleRecord, "targetId" | "model">): Promise<void>;
13
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PublishHandlerAction = void 0;
7
- var _types = require("../../scheduler/types.js");
8
- class PublishHandlerAction {
9
- constructor(params) {
10
- this.cms = params.cms;
11
- }
12
- canHandle(record) {
13
- return record.type === _types.ScheduleType.publish;
14
- }
15
- async handle(record) {
16
- const {
17
- targetId,
18
- model
19
- } = record;
20
- const targetEntry = await this.cms.getEntryById(model, targetId);
21
- const [publishedTargetEntry] = await this.cms.getPublishedEntriesByIds(model, [targetEntry.id]);
22
- /**
23
- * There are few scenarios we must handle:
24
- * 1. target entry is not published
25
- * 2. target entry is already published, same revision published
26
- * 3. target entry has a published revision, which is different that the target
27
- */
28
-
29
- /**
30
- * 1. Has no published revision, so we can publish it.
31
- */
32
- if (!publishedTargetEntry) {
33
- try {
34
- await this.cms.publishEntry(model, targetEntry.id);
35
- return;
36
- } catch (error) {
37
- console.error(`Failed to publish entry "${targetId}":`, error);
38
- throw error;
39
- }
40
- }
41
- /**
42
- * 2. Target entry is already published.
43
- */
44
- //
45
- else if (publishedTargetEntry.id === targetEntry.id) {
46
- /**
47
- * Already published, nothing to do.
48
- * Maybe republish?
49
- * TODO Do we throw an error here?
50
- */
51
- await this.cms.republishEntry(model, targetEntry.id);
52
- return;
53
- }
54
- /**
55
- * 3. Target entry has a published revision, which is different from the target.
56
- */
57
- //
58
- await this.cms.unpublishEntry(model, publishedTargetEntry.id);
59
- await this.cms.publishEntry(model, targetEntry.id);
60
- }
61
- }
62
- exports.PublishHandlerAction = PublishHandlerAction;
63
-
64
- //# sourceMappingURL=PublishHandlerAction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_types","require","PublishHandlerAction","constructor","params","cms","canHandle","record","type","ScheduleType","publish","handle","targetId","model","targetEntry","getEntryById","publishedTargetEntry","getPublishedEntriesByIds","id","publishEntry","error","console","republishEntry","unpublishEntry","exports"],"sources":["PublishHandlerAction.ts"],"sourcesContent":["import type { IHandlerAction } from \"~/handler/types.js\";\nimport type { IScheduleRecord } from \"~/scheduler/types.js\";\nimport { ScheduleType } from \"~/scheduler/types.js\";\nimport type { ScheduleContext } from \"~/types.js\";\n\nexport type IPublishHandlerActionParamsCms = Pick<\n ScheduleContext[\"cms\"],\n | \"getEntryById\"\n | \"getPublishedEntriesByIds\"\n | \"publishEntry\"\n | \"unpublishEntry\"\n | \"republishEntry\"\n>;\n\nexport interface IPublishHandlerActionParams {\n cms: IPublishHandlerActionParamsCms;\n}\n\nexport class PublishHandlerAction implements IHandlerAction {\n private readonly cms: IPublishHandlerActionParamsCms;\n\n public constructor(params: IPublishHandlerActionParams) {\n this.cms = params.cms;\n }\n\n public canHandle(record: Pick<IScheduleRecord, \"type\">): boolean {\n return record.type === ScheduleType.publish;\n }\n\n public async handle(record: Pick<IScheduleRecord, \"targetId\" | \"model\">): Promise<void> {\n const { targetId, model } = record;\n const targetEntry = await this.cms.getEntryById(model, targetId);\n const [publishedTargetEntry] = await this.cms.getPublishedEntriesByIds(model, [\n targetEntry.id\n ]);\n /**\n * There are few scenarios we must handle:\n * 1. target entry is not published\n * 2. target entry is already published, same revision published\n * 3. target entry has a published revision, which is different that the target\n */\n\n /**\n * 1. Has no published revision, so we can publish it.\n */\n if (!publishedTargetEntry) {\n try {\n await this.cms.publishEntry(model, targetEntry.id);\n return;\n } catch (error) {\n console.error(`Failed to publish entry \"${targetId}\":`, error);\n throw error;\n }\n }\n /**\n * 2. Target entry is already published.\n */\n //\n else if (publishedTargetEntry.id === targetEntry.id) {\n /**\n * Already published, nothing to do.\n * Maybe republish?\n * TODO Do we throw an error here?\n */\n await this.cms.republishEntry(model, targetEntry.id);\n return;\n }\n /**\n * 3. Target entry has a published revision, which is different from the target.\n */\n //\n await this.cms.unpublishEntry(model, publishedTargetEntry.id);\n await this.cms.publishEntry(model, targetEntry.id);\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAgBO,MAAMC,oBAAoB,CAA2B;EAGjDC,WAAWA,CAACC,MAAmC,EAAE;IACpD,IAAI,CAACC,GAAG,GAAGD,MAAM,CAACC,GAAG;EACzB;EAEOC,SAASA,CAACC,MAAqC,EAAW;IAC7D,OAAOA,MAAM,CAACC,IAAI,KAAKC,mBAAY,CAACC,OAAO;EAC/C;EAEA,MAAaC,MAAMA,CAACJ,MAAmD,EAAiB;IACpF,MAAM;MAAEK,QAAQ;MAAEC;IAAM,CAAC,GAAGN,MAAM;IAClC,MAAMO,WAAW,GAAG,MAAM,IAAI,CAACT,GAAG,CAACU,YAAY,CAACF,KAAK,EAAED,QAAQ,CAAC;IAChE,MAAM,CAACI,oBAAoB,CAAC,GAAG,MAAM,IAAI,CAACX,GAAG,CAACY,wBAAwB,CAACJ,KAAK,EAAE,CAC1EC,WAAW,CAACI,EAAE,CACjB,CAAC;IACF;AACR;AACA;AACA;AACA;AACA;;IAEQ;AACR;AACA;IACQ,IAAI,CAACF,oBAAoB,EAAE;MACvB,IAAI;QACA,MAAM,IAAI,CAACX,GAAG,CAACc,YAAY,CAACN,KAAK,EAAEC,WAAW,CAACI,EAAE,CAAC;QAClD;MACJ,CAAC,CAAC,OAAOE,KAAK,EAAE;QACZC,OAAO,CAACD,KAAK,CAAC,4BAA4BR,QAAQ,IAAI,EAAEQ,KAAK,CAAC;QAC9D,MAAMA,KAAK;MACf;IACJ;IACA;AACR;AACA;IACQ;IAAA,KACK,IAAIJ,oBAAoB,CAACE,EAAE,KAAKJ,WAAW,CAACI,EAAE,EAAE;MACjD;AACZ;AACA;AACA;AACA;MACY,MAAM,IAAI,CAACb,GAAG,CAACiB,cAAc,CAACT,KAAK,EAAEC,WAAW,CAACI,EAAE,CAAC;MACpD;IACJ;IACA;AACR;AACA;IACQ;IACA,MAAM,IAAI,CAACb,GAAG,CAACkB,cAAc,CAACV,KAAK,EAAEG,oBAAoB,CAACE,EAAE,CAAC;IAC7D,MAAM,IAAI,CAACb,GAAG,CAACc,YAAY,CAACN,KAAK,EAAEC,WAAW,CAACI,EAAE,CAAC;EACtD;AACJ;AAACM,OAAA,CAAAtB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -1,13 +0,0 @@
1
- import type { IHandlerAction } from "../types.js";
2
- import type { IScheduleRecord } from "../../scheduler/types.js";
3
- import type { ScheduleContext } from "../../types.js";
4
- export type IUnpublishHandlerActionParamsCms = Pick<ScheduleContext["cms"], "getEntryById" | "getPublishedEntriesByIds" | "unpublishEntry">;
5
- export interface IUnpublishHandlerActionParams {
6
- cms: IUnpublishHandlerActionParamsCms;
7
- }
8
- export declare class UnpublishHandlerAction implements IHandlerAction {
9
- private readonly cms;
10
- constructor(params: IUnpublishHandlerActionParams);
11
- canHandle(record: Pick<IScheduleRecord, "type">): boolean;
12
- handle(record: Pick<IScheduleRecord, "targetId" | "model">): Promise<void>;
13
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UnpublishHandlerAction = void 0;
7
- var _types = require("../../scheduler/types.js");
8
- class UnpublishHandlerAction {
9
- constructor(params) {
10
- this.cms = params.cms;
11
- }
12
- canHandle(record) {
13
- return record.type === _types.ScheduleType.unpublish;
14
- }
15
- async handle(record) {
16
- const {
17
- targetId,
18
- model
19
- } = record;
20
- /**
21
- * We need to handle the following scenarios:
22
- * * 1. Target entry is not published, nothing to do.
23
- * * 2. Target entry is published, so we can unpublish it.
24
- * * 3. Target entry is published, but it's a different revision than the target.
25
- */
26
- const targetEntry = await this.cms.getEntryById(model, targetId);
27
- const [publishedTargetEntry] = await this.cms.getPublishedEntriesByIds(model, [targetEntry.id]);
28
-
29
- /**
30
- * 1. Target entry is not published, nothing to do.
31
- */
32
- if (!publishedTargetEntry) {
33
- console.warn(`Entry "${targetId}" is not published, nothing to unpublish.`);
34
- return;
35
- }
36
- /**
37
- * 2. Target entry is published, so we can unpublish it.
38
- */
39
- //
40
- else if (publishedTargetEntry.id === targetId) {
41
- await this.cms.unpublishEntry(model, targetId);
42
- return;
43
- }
44
- /**
45
- * 3. Target entry is published, but it's a different revision than the target.
46
- * TODO determine if we really want to unpublish an entry which does not match the target ID.
47
- */
48
- await this.cms.unpublishEntry(model, publishedTargetEntry.id);
49
- }
50
- }
51
- exports.UnpublishHandlerAction = UnpublishHandlerAction;
52
-
53
- //# sourceMappingURL=UnpublishHandlerAction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_types","require","UnpublishHandlerAction","constructor","params","cms","canHandle","record","type","ScheduleType","unpublish","handle","targetId","model","targetEntry","getEntryById","publishedTargetEntry","getPublishedEntriesByIds","id","console","warn","unpublishEntry","exports"],"sources":["UnpublishHandlerAction.ts"],"sourcesContent":["import type { IHandlerAction } from \"~/handler/types.js\";\nimport type { IScheduleRecord } from \"~/scheduler/types.js\";\nimport { ScheduleType } from \"~/scheduler/types.js\";\nimport type { ScheduleContext } from \"~/types.js\";\n\nexport type IUnpublishHandlerActionParamsCms = Pick<\n ScheduleContext[\"cms\"],\n \"getEntryById\" | \"getPublishedEntriesByIds\" | \"unpublishEntry\"\n>;\n\nexport interface IUnpublishHandlerActionParams {\n cms: IUnpublishHandlerActionParamsCms;\n}\n\nexport class UnpublishHandlerAction implements IHandlerAction {\n private readonly cms: IUnpublishHandlerActionParamsCms;\n\n public constructor(params: IUnpublishHandlerActionParams) {\n this.cms = params.cms;\n }\n\n public canHandle(record: Pick<IScheduleRecord, \"type\">): boolean {\n return record.type === ScheduleType.unpublish;\n }\n public async handle(record: Pick<IScheduleRecord, \"targetId\" | \"model\">): Promise<void> {\n const { targetId, model } = record;\n /**\n * We need to handle the following scenarios:\n * * 1. Target entry is not published, nothing to do.\n * * 2. Target entry is published, so we can unpublish it.\n * * 3. Target entry is published, but it's a different revision than the target.\n */\n const targetEntry = await this.cms.getEntryById(model, targetId);\n const [publishedTargetEntry] = await this.cms.getPublishedEntriesByIds(model, [\n targetEntry.id\n ]);\n\n /**\n * 1. Target entry is not published, nothing to do.\n */\n if (!publishedTargetEntry) {\n console.warn(`Entry \"${targetId}\" is not published, nothing to unpublish.`);\n return;\n }\n /**\n * 2. Target entry is published, so we can unpublish it.\n */\n //\n else if (publishedTargetEntry.id === targetId) {\n await this.cms.unpublishEntry(model, targetId);\n return;\n }\n /**\n * 3. Target entry is published, but it's a different revision than the target.\n * TODO determine if we really want to unpublish an entry which does not match the target ID.\n */\n await this.cms.unpublishEntry(model, publishedTargetEntry.id);\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAYO,MAAMC,sBAAsB,CAA2B;EAGnDC,WAAWA,CAACC,MAAqC,EAAE;IACtD,IAAI,CAACC,GAAG,GAAGD,MAAM,CAACC,GAAG;EACzB;EAEOC,SAASA,CAACC,MAAqC,EAAW;IAC7D,OAAOA,MAAM,CAACC,IAAI,KAAKC,mBAAY,CAACC,SAAS;EACjD;EACA,MAAaC,MAAMA,CAACJ,MAAmD,EAAiB;IACpF,MAAM;MAAEK,QAAQ;MAAEC;IAAM,CAAC,GAAGN,MAAM;IAClC;AACR;AACA;AACA;AACA;AACA;IACQ,MAAMO,WAAW,GAAG,MAAM,IAAI,CAACT,GAAG,CAACU,YAAY,CAACF,KAAK,EAAED,QAAQ,CAAC;IAChE,MAAM,CAACI,oBAAoB,CAAC,GAAG,MAAM,IAAI,CAACX,GAAG,CAACY,wBAAwB,CAACJ,KAAK,EAAE,CAC1EC,WAAW,CAACI,EAAE,CACjB,CAAC;;IAEF;AACR;AACA;IACQ,IAAI,CAACF,oBAAoB,EAAE;MACvBG,OAAO,CAACC,IAAI,CAAC,UAAUR,QAAQ,2CAA2C,CAAC;MAC3E;IACJ;IACA;AACR;AACA;IACQ;IAAA,KACK,IAAII,oBAAoB,CAACE,EAAE,KAAKN,QAAQ,EAAE;MAC3C,MAAM,IAAI,CAACP,GAAG,CAACgB,cAAc,CAACR,KAAK,EAAED,QAAQ,CAAC;MAC9C;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAM,IAAI,CAACP,GAAG,CAACgB,cAAc,CAACR,KAAK,EAAEG,oBAAoB,CAACE,EAAE,CAAC;EACjE;AACJ;AAACI,OAAA,CAAApB,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
2
- import type { IWebinyScheduledCmsActionEvent } from "./Handler.js";
3
- import type { ScheduleContext } from "../types.js";
4
- export interface HandlerParams extends HandlerFactoryParams {
5
- debug?: boolean;
6
- }
7
- export declare const createScheduledCmsActionEventHandler: () => import("@webiny/handler-aws/raw/index.js").RawEventHandler<IWebinyScheduledCmsActionEvent, ScheduleContext, any>;
package/handler/index.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createScheduledCmsActionEventHandler = void 0;
7
- var _registry = require("@webiny/handler-aws/registry.js");
8
- var _sourceHandler = require("@webiny/handler-aws/sourceHandler.js");
9
- var _index = require("@webiny/handler-aws/raw/index.js");
10
- var _constants = require("../constants.js");
11
- var _Handler = require("./Handler.js");
12
- var _PublishHandlerAction = require("./actions/PublishHandlerAction.js");
13
- var _UnpublishHandlerAction = require("./actions/UnpublishHandlerAction.js");
14
- const canHandle = event => {
15
- if (typeof event?.hasOwnProperty !== "function") {
16
- return false;
17
- } else if (!event.hasOwnProperty(_constants.SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER)) {
18
- return false;
19
- }
20
- const value = event[_constants.SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER];
21
- return !!(value?.id && value?.scheduleOn);
22
- };
23
- const handler = (0, _sourceHandler.createSourceHandler)({
24
- name: "handler-aws-event-bridge-scheduled-cms-action-event",
25
- canUse: event => {
26
- return canHandle(event);
27
- },
28
- handle: async ({
29
- params,
30
- event,
31
- context
32
- }) => {
33
- return (0, _index.createHandler)(params)(event, context);
34
- }
35
- });
36
- _registry.registry.register(handler);
37
- const createScheduledCmsActionEventHandler = () => {
38
- return (0, _index.createEventHandler)({
39
- canHandle: event => {
40
- return canHandle(event);
41
- },
42
- handle: async params => {
43
- const {
44
- payload,
45
- context
46
- } = params;
47
- const handler = new _Handler.Handler({
48
- actions: [new _PublishHandlerAction.PublishHandlerAction({
49
- cms: context.cms
50
- }), new _UnpublishHandlerAction.UnpublishHandlerAction({
51
- cms: context.cms
52
- })]
53
- });
54
- return handler.handle({
55
- payload,
56
- cms: context.cms,
57
- security: context.security
58
- });
59
- }
60
- });
61
- };
62
- exports.createScheduledCmsActionEventHandler = createScheduledCmsActionEventHandler;
63
-
64
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_registry","require","_sourceHandler","_index","_constants","_Handler","_PublishHandlerAction","_UnpublishHandlerAction","canHandle","event","hasOwnProperty","SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER","value","id","scheduleOn","handler","createSourceHandler","name","canUse","handle","params","context","createHandler","registry","register","createScheduledCmsActionEventHandler","createEventHandler","payload","Handler","actions","PublishHandlerAction","cms","UnpublishHandlerAction","security","exports"],"sources":["index.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws/sourceHandler.js\";\nimport { createEventHandler, createHandler } from \"@webiny/handler-aws/raw/index.js\";\nimport { SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER } from \"~/constants.js\";\nimport type { IWebinyScheduledCmsActionEvent } from \"./Handler.js\";\nimport { Handler } from \"./Handler.js\";\nimport type { ScheduleContext } from \"~/types.js\";\nimport { PublishHandlerAction } from \"./actions/PublishHandlerAction.js\";\nimport { UnpublishHandlerAction } from \"./actions/UnpublishHandlerAction.js\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst canHandle = (event: Partial<IWebinyScheduledCmsActionEvent>): boolean => {\n if (typeof event?.hasOwnProperty !== \"function\") {\n return false;\n } else if (!event.hasOwnProperty(SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER)) {\n return false;\n }\n\n const value = event[SCHEDULED_CMS_ACTION_EVENT_IDENTIFIER];\n return !!(value?.id && value?.scheduleOn);\n};\n\nconst handler = createSourceHandler<IWebinyScheduledCmsActionEvent, HandlerParams>({\n name: \"handler-aws-event-bridge-scheduled-cms-action-event\",\n canUse: event => {\n return canHandle(event);\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n\nexport const createScheduledCmsActionEventHandler = () => {\n return createEventHandler<IWebinyScheduledCmsActionEvent, ScheduleContext>({\n canHandle: event => {\n return canHandle(event);\n },\n handle: async params => {\n const { payload, context } = params;\n\n const handler = new Handler({\n actions: [\n new PublishHandlerAction({\n cms: context.cms\n }),\n new UnpublishHandlerAction({\n cms: context.cms\n })\n ]\n });\n\n return handler.handle({\n payload,\n cms: context.cms,\n security: context.security\n });\n }\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AAEA,IAAAK,qBAAA,GAAAL,OAAA;AACA,IAAAM,uBAAA,GAAAN,OAAA;AAMA,MAAMO,SAAS,GAAIC,KAA8C,IAAc;EAC3E,IAAI,OAAOA,KAAK,EAAEC,cAAc,KAAK,UAAU,EAAE;IAC7C,OAAO,KAAK;EAChB,CAAC,MAAM,IAAI,CAACD,KAAK,CAACC,cAAc,CAACC,gDAAqC,CAAC,EAAE;IACrE,OAAO,KAAK;EAChB;EAEA,MAAMC,KAAK,GAAGH,KAAK,CAACE,gDAAqC,CAAC;EAC1D,OAAO,CAAC,EAAEC,KAAK,EAAEC,EAAE,IAAID,KAAK,EAAEE,UAAU,CAAC;AAC7C,CAAC;AAED,MAAMC,OAAO,GAAG,IAAAC,kCAAmB,EAAgD;EAC/EC,IAAI,EAAE,qDAAqD;EAC3DC,MAAM,EAAET,KAAK,IAAI;IACb,OAAOD,SAAS,CAACC,KAAK,CAAC;EAC3B,CAAC;EACDU,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAEX,KAAK;IAAEY;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACX,KAAK,EAAEY,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACT,OAAO,CAAC;AAEnB,MAAMU,oCAAoC,GAAGA,CAAA,KAAM;EACtD,OAAO,IAAAC,yBAAkB,EAAkD;IACvElB,SAAS,EAAEC,KAAK,IAAI;MAChB,OAAOD,SAAS,CAACC,KAAK,CAAC;IAC3B,CAAC;IACDU,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEO,OAAO;QAAEN;MAAQ,CAAC,GAAGD,MAAM;MAEnC,MAAML,OAAO,GAAG,IAAIa,gBAAO,CAAC;QACxBC,OAAO,EAAE,CACL,IAAIC,0CAAoB,CAAC;UACrBC,GAAG,EAAEV,OAAO,CAACU;QACjB,CAAC,CAAC,EACF,IAAIC,8CAAsB,CAAC;UACvBD,GAAG,EAAEV,OAAO,CAACU;QACjB,CAAC,CAAC;MAEV,CAAC,CAAC;MAEF,OAAOhB,OAAO,CAACI,MAAM,CAAC;QAClBQ,OAAO;QACPI,GAAG,EAAEV,OAAO,CAACU,GAAG;QAChBE,QAAQ,EAAEZ,OAAO,CAACY;MACtB,CAAC,CAAC;IACN;EACJ,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAT,oCAAA,GAAAA,oCAAA","ignoreList":[]}
@@ -1,5 +0,0 @@
1
- import type { IScheduleRecord } from "../scheduler/types.js";
2
- export interface IHandlerAction {
3
- canHandle(record: IScheduleRecord): boolean;
4
- handle(record: IScheduleRecord): Promise<void>;
5
- }
package/handler/types.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IScheduleRecord } from \"~/scheduler/types.js\";\n\nexport interface IHandlerAction {\n canHandle(record: IScheduleRecord): boolean;\n handle(record: IScheduleRecord): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
package/hooks/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { CmsModel } from "@webiny/api-headless-cms/types/model.js";
2
- import type { ScheduleContext } from "../types.js";
3
- export interface IAttachLifecycleHookParams {
4
- cms: ScheduleContext["cms"];
5
- schedulerModel: Pick<CmsModel, "modelId">;
6
- }
7
- export declare const attachLifecycleHooks: (params: IAttachLifecycleHookParams) => void;
package/hooks/index.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.attachLifecycleHooks = void 0;
7
- const attachLifecycleHooks = params => {
8
- const {
9
- cms,
10
- schedulerModel
11
- } = params;
12
- const shouldContinue = model => {
13
- if (model.modelId === schedulerModel.modelId) {
14
- return false;
15
- }
16
- // TODO maybe change with a list of private models which are allowed?
17
- else if (model.isPrivate) {
18
- return false;
19
- }
20
- return true;
21
- };
22
- const cancel = async (model, target) => {
23
- if (shouldContinue(model) === false) {
24
- return;
25
- }
26
- const scheduler = cms.scheduler(model);
27
- const entry = await scheduler.getScheduled(target.id);
28
- if (!entry) {
29
- return;
30
- }
31
- try {
32
- await scheduler.cancel(entry.id);
33
- } catch {
34
- // does not matter
35
- }
36
- };
37
- cms.onEntryAfterPublish.subscribe(async ({
38
- entry,
39
- model
40
- }) => {
41
- return cancel(model, entry);
42
- });
43
- cms.onEntryAfterUnpublish.subscribe(async ({
44
- entry,
45
- model
46
- }) => {
47
- return cancel(model, entry);
48
- });
49
- cms.onEntryAfterDelete.subscribe(async ({
50
- entry,
51
- model
52
- }) => {
53
- return cancel(model, entry);
54
- });
55
- };
56
- exports.attachLifecycleHooks = attachLifecycleHooks;
57
-
58
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["attachLifecycleHooks","params","cms","schedulerModel","shouldContinue","model","modelId","isPrivate","cancel","target","scheduler","entry","getScheduled","id","onEntryAfterPublish","subscribe","onEntryAfterUnpublish","onEntryAfterDelete","exports"],"sources":["index.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types/model.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/types.js\";\nimport type { ScheduleContext } from \"~/types.js\";\n\nexport interface IAttachLifecycleHookParams {\n cms: ScheduleContext[\"cms\"];\n schedulerModel: Pick<CmsModel, \"modelId\">;\n}\n\nexport const attachLifecycleHooks = (params: IAttachLifecycleHookParams): void => {\n const { cms, schedulerModel } = params;\n\n const shouldContinue = (model: Pick<CmsModel, \"modelId\" | \"isPrivate\">): boolean => {\n if (model.modelId === schedulerModel.modelId) {\n return false;\n }\n // TODO maybe change with a list of private models which are allowed?\n else if (model.isPrivate) {\n return false;\n }\n\n return true;\n };\n\n const cancel = async (model: CmsModel, target: Pick<CmsEntry, \"id\">): Promise<void> => {\n if (shouldContinue(model) === false) {\n return;\n }\n const scheduler = cms.scheduler(model);\n\n const entry = await scheduler.getScheduled(target.id);\n if (!entry) {\n return;\n }\n try {\n await scheduler.cancel(entry.id);\n } catch {\n // does not matter\n }\n };\n\n cms.onEntryAfterPublish.subscribe(async ({ entry, model }) => {\n return cancel(model, entry);\n });\n cms.onEntryAfterUnpublish.subscribe(async ({ entry, model }) => {\n return cancel(model, entry);\n });\n cms.onEntryAfterDelete.subscribe(async ({ entry, model }) => {\n return cancel(model, entry);\n });\n};\n"],"mappings":";;;;;;AASO,MAAMA,oBAAoB,GAAIC,MAAkC,IAAW;EAC9E,MAAM;IAAEC,GAAG;IAAEC;EAAe,CAAC,GAAGF,MAAM;EAEtC,MAAMG,cAAc,GAAIC,KAA8C,IAAc;IAChF,IAAIA,KAAK,CAACC,OAAO,KAAKH,cAAc,CAACG,OAAO,EAAE;MAC1C,OAAO,KAAK;IAChB;IACA;IAAA,KACK,IAAID,KAAK,CAACE,SAAS,EAAE;MACtB,OAAO,KAAK;IAChB;IAEA,OAAO,IAAI;EACf,CAAC;EAED,MAAMC,MAAM,GAAG,MAAAA,CAAOH,KAAe,EAAEI,MAA4B,KAAoB;IACnF,IAAIL,cAAc,CAACC,KAAK,CAAC,KAAK,KAAK,EAAE;MACjC;IACJ;IACA,MAAMK,SAAS,GAAGR,GAAG,CAACQ,SAAS,CAACL,KAAK,CAAC;IAEtC,MAAMM,KAAK,GAAG,MAAMD,SAAS,CAACE,YAAY,CAACH,MAAM,CAACI,EAAE,CAAC;IACrD,IAAI,CAACF,KAAK,EAAE;MACR;IACJ;IACA,IAAI;MACA,MAAMD,SAAS,CAACF,MAAM,CAACG,KAAK,CAACE,EAAE,CAAC;IACpC,CAAC,CAAC,MAAM;MACJ;IAAA;EAER,CAAC;EAEDX,GAAG,CAACY,mBAAmB,CAACC,SAAS,CAAC,OAAO;IAAEJ,KAAK;IAAEN;EAAM,CAAC,KAAK;IAC1D,OAAOG,MAAM,CAACH,KAAK,EAAEM,KAAK,CAAC;EAC/B,CAAC,CAAC;EACFT,GAAG,CAACc,qBAAqB,CAACD,SAAS,CAAC,OAAO;IAAEJ,KAAK;IAAEN;EAAM,CAAC,KAAK;IAC5D,OAAOG,MAAM,CAACH,KAAK,EAAEM,KAAK,CAAC;EAC/B,CAAC,CAAC;EACFT,GAAG,CAACe,kBAAkB,CAACF,SAAS,CAAC,OAAO;IAAEJ,KAAK;IAAEN;EAAM,CAAC,KAAK;IACzD,OAAOG,MAAM,CAACH,KAAK,EAAEM,KAAK,CAAC;EAC/B,CAAC,CAAC;AACN,CAAC;AAACO,OAAA,CAAAlB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
package/manifest.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
2
- export interface IGetManifestErrorResult {
3
- error: Error;
4
- data?: never;
5
- }
6
- export interface IGetManifestSuccessResult {
7
- data: {
8
- lambdaArn: string;
9
- roleArn: string;
10
- };
11
- error?: never;
12
- }
13
- export type IGetManifestResult = IGetManifestSuccessResult | IGetManifestErrorResult;
14
- export interface IGetManifestParams {
15
- client: DynamoDBDocument;
16
- }
17
- export declare const getManifest: (params: IGetManifestParams) => Promise<IGetManifestResult>;
package/manifest.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getManifest = void 0;
8
- var _api = require("@webiny/api");
9
- var _utils = require("@webiny/utils");
10
- var _zod = _interopRequireDefault(require("zod"));
11
- const schema = _zod.default.object({
12
- scheduler: _zod.default.object({
13
- lambdaArn: _zod.default.string(),
14
- roleArn: _zod.default.string()
15
- })
16
- });
17
- const getManifest = async params => {
18
- try {
19
- _api.ServiceDiscovery.setDocumentClient(params.client);
20
- const manifest = await _api.ServiceDiscovery.load();
21
- if (!manifest) {
22
- return {
23
- error: new Error("Manifest could not be loaded.")
24
- };
25
- } else if (!manifest.scheduler) {
26
- return {
27
- error: new Error("Scheduler not found in the Manifest.")
28
- };
29
- }
30
- const result = await schema.safeParseAsync(manifest);
31
- if (!result.success) {
32
- return {
33
- error: (0, _utils.createZodError)(result.error)
34
- };
35
- }
36
- return {
37
- data: result.data.scheduler
38
- };
39
- } catch (ex) {
40
- return {
41
- error: ex
42
- };
43
- }
44
- };
45
- exports.getManifest = getManifest;
46
-
47
- //# sourceMappingURL=manifest.js.map
package/manifest.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["_api","require","_utils","_zod","_interopRequireDefault","schema","zod","object","scheduler","lambdaArn","string","roleArn","getManifest","params","ServiceDiscovery","setDocumentClient","client","manifest","load","error","Error","result","safeParseAsync","success","createZodError","data","ex","exports"],"sources":["manifest.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { createZodError } from \"@webiny/utils\";\nimport zod from \"zod\";\n\nconst schema = zod.object({\n scheduler: zod.object({\n lambdaArn: zod.string(),\n roleArn: zod.string()\n })\n});\n\nexport interface IGetManifestErrorResult {\n error: Error;\n data?: never;\n}\n\nexport interface IGetManifestSuccessResult {\n data: {\n lambdaArn: string;\n roleArn: string;\n };\n error?: never;\n}\n\nexport type IGetManifestResult = IGetManifestSuccessResult | IGetManifestErrorResult;\n\nexport interface IGetManifestParams {\n client: DynamoDBDocument;\n}\n\nexport const getManifest = async (params: IGetManifestParams): Promise<IGetManifestResult> => {\n try {\n ServiceDiscovery.setDocumentClient(params.client);\n const manifest = await ServiceDiscovery.load();\n if (!manifest) {\n return {\n error: new Error(\"Manifest could not be loaded.\")\n };\n } else if (!manifest.scheduler) {\n return {\n error: new Error(\"Scheduler not found in the Manifest.\")\n };\n }\n\n const result = await schema.safeParseAsync(manifest);\n if (!result.success) {\n return {\n error: createZodError(result.error)\n };\n }\n\n return {\n data: result.data.scheduler\n };\n } catch (ex) {\n return {\n error: ex\n };\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,MAAM,GAAGC,YAAG,CAACC,MAAM,CAAC;EACtBC,SAAS,EAAEF,YAAG,CAACC,MAAM,CAAC;IAClBE,SAAS,EAAEH,YAAG,CAACI,MAAM,CAAC,CAAC;IACvBC,OAAO,EAAEL,YAAG,CAACI,MAAM,CAAC;EACxB,CAAC;AACL,CAAC,CAAC;AAqBK,MAAME,WAAW,GAAG,MAAOC,MAA0B,IAAkC;EAC1F,IAAI;IACAC,qBAAgB,CAACC,iBAAiB,CAACF,MAAM,CAACG,MAAM,CAAC;IACjD,MAAMC,QAAQ,GAAG,MAAMH,qBAAgB,CAACI,IAAI,CAAC,CAAC;IAC9C,IAAI,CAACD,QAAQ,EAAE;MACX,OAAO;QACHE,KAAK,EAAE,IAAIC,KAAK,CAAC,+BAA+B;MACpD,CAAC;IACL,CAAC,MAAM,IAAI,CAACH,QAAQ,CAACT,SAAS,EAAE;MAC5B,OAAO;QACHW,KAAK,EAAE,IAAIC,KAAK,CAAC,sCAAsC;MAC3D,CAAC;IACL;IAEA,MAAMC,MAAM,GAAG,MAAMhB,MAAM,CAACiB,cAAc,CAACL,QAAQ,CAAC;IACpD,IAAI,CAACI,MAAM,CAACE,OAAO,EAAE;MACjB,OAAO;QACHJ,KAAK,EAAE,IAAAK,qBAAc,EAACH,MAAM,CAACF,KAAK;MACtC,CAAC;IACL;IAEA,OAAO;MACHM,IAAI,EAAEJ,MAAM,CAACI,IAAI,CAACjB;IACtB,CAAC;EACL,CAAC,CAAC,OAAOkB,EAAE,EAAE;IACT,OAAO;MACHP,KAAK,EAAEO;IACX,CAAC;EACL;AACJ,CAAC;AAACC,OAAA,CAAAf,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -1,16 +0,0 @@
1
- import { type IScheduleAction, type IScheduleExecutor, type IScheduleFetcher, type IScheduleRecord, type ISchedulerInput } from "./types.js";
2
- import type { PublishScheduleActionCms } from "./actions/PublishScheduleAction.js";
3
- import type { UnpublishScheduleActionCms } from "./actions/UnpublishScheduleAction.js";
4
- export type ScheduleExecutorCms = UnpublishScheduleActionCms & PublishScheduleActionCms;
5
- export interface IScheduleExecutorParams {
6
- actions: IScheduleAction[];
7
- fetcher: IScheduleFetcher;
8
- }
9
- export declare class ScheduleExecutor implements IScheduleExecutor {
10
- private readonly actions;
11
- private readonly fetcher;
12
- constructor(params: IScheduleExecutorParams);
13
- schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord>;
14
- cancel(initialId: string): Promise<IScheduleRecord>;
15
- private getAction;
16
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ScheduleExecutor = void 0;
7
- var _createScheduleRecordId = require("./createScheduleRecordId.js");
8
- var _error = require("@webiny/error");
9
- class ScheduleExecutor {
10
- constructor(params) {
11
- this.actions = params.actions;
12
- this.fetcher = params.fetcher;
13
- }
14
- async schedule(targetId, input) {
15
- const scheduleRecordId = (0, _createScheduleRecordId.createScheduleRecordIdWithVersion)(targetId);
16
- const original = await this.fetcher.getScheduled(targetId);
17
- const action = this.getAction(input.type);
18
- if (original) {
19
- return action.reschedule(original, input);
20
- }
21
- return await action.schedule({
22
- scheduleRecordId,
23
- targetId,
24
- input
25
- });
26
- }
27
- async cancel(initialId) {
28
- const id = (0, _createScheduleRecordId.createScheduleRecordIdWithVersion)(initialId);
29
- const original = await this.fetcher.getScheduled(id);
30
- if (!original) {
31
- throw new _error.WebinyError(`No scheduled record found for ID "${id}".`, "SCHEDULED_RECORD_NOT_FOUND", {
32
- id
33
- });
34
- }
35
- const action = this.getAction(original.type);
36
- await action.cancel(original.id);
37
- return original;
38
- }
39
- getAction(type) {
40
- const action = this.actions.find(action => {
41
- return action.canHandle({
42
- type
43
- });
44
- });
45
- if (action) {
46
- return action;
47
- }
48
- throw new _error.WebinyError(`No action found for input type "${type}".`, "NO_ACTION_FOUND", {
49
- type
50
- });
51
- }
52
- }
53
- exports.ScheduleExecutor = ScheduleExecutor;
54
-
55
- //# sourceMappingURL=ScheduleExecutor.js.map