@webiny/api-headless-cms-scheduler 0.0.0-unstable.3bc8100a7f

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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/constants.d.ts +11 -0
  4. package/constants.js +19 -0
  5. package/constants.js.map +1 -0
  6. package/context.d.ts +7 -0
  7. package/context.js +63 -0
  8. package/context.js.map +1 -0
  9. package/graphql/index.d.ts +3 -0
  10. package/graphql/index.js +204 -0
  11. package/graphql/index.js.map +1 -0
  12. package/graphql/schema.d.ts +217 -0
  13. package/graphql/schema.js +87 -0
  14. package/graphql/schema.js.map +1 -0
  15. package/handler/Handler.d.ts +23 -0
  16. package/handler/Handler.js +74 -0
  17. package/handler/Handler.js.map +1 -0
  18. package/handler/actions/PublishHandlerAction.d.ts +13 -0
  19. package/handler/actions/PublishHandlerAction.js +64 -0
  20. package/handler/actions/PublishHandlerAction.js.map +1 -0
  21. package/handler/actions/UnpublishHandlerAction.d.ts +13 -0
  22. package/handler/actions/UnpublishHandlerAction.js +53 -0
  23. package/handler/actions/UnpublishHandlerAction.js.map +1 -0
  24. package/handler/index.d.ts +7 -0
  25. package/handler/index.js +64 -0
  26. package/handler/index.js.map +1 -0
  27. package/handler/types.d.ts +5 -0
  28. package/handler/types.js +7 -0
  29. package/handler/types.js.map +1 -0
  30. package/index.d.ts +10 -0
  31. package/index.js +29 -0
  32. package/index.js.map +1 -0
  33. package/manifest.d.ts +17 -0
  34. package/manifest.js +47 -0
  35. package/manifest.js.map +1 -0
  36. package/package.json +45 -0
  37. package/scheduler/ScheduleExecutor.d.ts +16 -0
  38. package/scheduler/ScheduleExecutor.js +55 -0
  39. package/scheduler/ScheduleExecutor.js.map +1 -0
  40. package/scheduler/ScheduleFetcher.d.ts +16 -0
  41. package/scheduler/ScheduleFetcher.js +51 -0
  42. package/scheduler/ScheduleFetcher.js.map +1 -0
  43. package/scheduler/ScheduleRecord.d.ts +33 -0
  44. package/scheduler/ScheduleRecord.js +56 -0
  45. package/scheduler/ScheduleRecord.js.map +1 -0
  46. package/scheduler/Scheduler.d.ts +14 -0
  47. package/scheduler/Scheduler.js +27 -0
  48. package/scheduler/Scheduler.js.map +1 -0
  49. package/scheduler/actions/PublishScheduleAction.d.ts +26 -0
  50. package/scheduler/actions/PublishScheduleAction.js +209 -0
  51. package/scheduler/actions/PublishScheduleAction.js.map +1 -0
  52. package/scheduler/actions/UnpublishScheduleAction.d.ts +26 -0
  53. package/scheduler/actions/UnpublishScheduleAction.js +199 -0
  54. package/scheduler/actions/UnpublishScheduleAction.js.map +1 -0
  55. package/scheduler/createScheduleRecordId.d.ts +2 -0
  56. package/scheduler/createScheduleRecordId.js +33 -0
  57. package/scheduler/createScheduleRecordId.js.map +1 -0
  58. package/scheduler/createScheduler.d.ts +12 -0
  59. package/scheduler/createScheduler.js +59 -0
  60. package/scheduler/createScheduler.js.map +1 -0
  61. package/scheduler/dates.d.ts +7 -0
  62. package/scheduler/dates.js +27 -0
  63. package/scheduler/dates.js.map +1 -0
  64. package/scheduler/model.d.ts +1 -0
  65. package/scheduler/model.js +88 -0
  66. package/scheduler/model.js.map +1 -0
  67. package/scheduler/types.d.ts +92 -0
  68. package/scheduler/types.js +19 -0
  69. package/scheduler/types.js.map +1 -0
  70. package/service/SchedulerService.d.ts +23 -0
  71. package/service/SchedulerService.js +151 -0
  72. package/service/SchedulerService.js.map +1 -0
  73. package/service/types.d.ts +19 -0
  74. package/service/types.js +7 -0
  75. package/service/types.js.map +1 -0
  76. package/types.d.ts +11 -0
  77. package/types.js +7 -0
  78. package/types.js.map +1 -0
  79. package/utils/dateInTheFuture.d.ts +6 -0
  80. package/utils/dateInTheFuture.js +19 -0
  81. package/utils/dateInTheFuture.js.map +1 -0
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@webiny/api-headless-cms-scheduler",
3
+ "version": "0.0.0-unstable.3bc8100a7f",
4
+ "main": "index.js",
5
+ "description": "Schedule for Webiny Headless CMS",
6
+ "keywords": [
7
+ "api-headless-cms-scheduler:base"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/webiny/webiny-js.git",
12
+ "directory": "packages/api-headless-cms-scheduler"
13
+ },
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "@webiny/api": "0.0.0-unstable.3bc8100a7f",
17
+ "@webiny/api-headless-cms": "0.0.0-unstable.3bc8100a7f",
18
+ "@webiny/aws-sdk": "0.0.0-unstable.3bc8100a7f",
19
+ "@webiny/error": "0.0.0-unstable.3bc8100a7f",
20
+ "@webiny/handler-graphql": "0.0.0-unstable.3bc8100a7f",
21
+ "@webiny/utils": "0.0.0-unstable.3bc8100a7f",
22
+ "zod": "3.23.8"
23
+ },
24
+ "devDependencies": {
25
+ "@webiny/api-i18n": "0.0.0-unstable.3bc8100a7f",
26
+ "@webiny/api-security": "0.0.0-unstable.3bc8100a7f",
27
+ "@webiny/api-tenancy": "0.0.0-unstable.3bc8100a7f",
28
+ "@webiny/api-wcp": "0.0.0-unstable.3bc8100a7f",
29
+ "@webiny/handler": "0.0.0-unstable.3bc8100a7f",
30
+ "@webiny/handler-aws": "0.0.0-unstable.3bc8100a7f",
31
+ "@webiny/plugins": "0.0.0-unstable.3bc8100a7f",
32
+ "@webiny/project-utils": "0.0.0-unstable.3bc8100a7f",
33
+ "aws-sdk-client-mock": "4.1.0",
34
+ "typescript": "5.3.3"
35
+ },
36
+ "scripts": {
37
+ "build": "node ../cli/bin.js run build",
38
+ "watch": "node ../cli/bin.js run watch"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "directory": "dist"
43
+ },
44
+ "gitHead": "3bc8100a7f1fb3a8d6a3454a2765f8ef377c279e"
45
+ }
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,55 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_createScheduleRecordId","require","_error","ScheduleExecutor","constructor","params","actions","fetcher","schedule","targetId","input","scheduleRecordId","createScheduleRecordIdWithVersion","original","getScheduled","action","getAction","type","reschedule","cancel","initialId","id","WebinyError","find","canHandle","exports"],"sources":["ScheduleExecutor.ts"],"sourcesContent":["import type { ScheduleType } from \"~/scheduler/types.js\";\nimport {\n type IScheduleAction,\n type IScheduleExecutor,\n type IScheduleFetcher,\n type IScheduleRecord,\n type ISchedulerInput\n} from \"~/scheduler/types.js\";\nimport { createScheduleRecordIdWithVersion } from \"~/scheduler/createScheduleRecordId.js\";\nimport type { PublishScheduleActionCms } from \"~/scheduler/actions/PublishScheduleAction.js\";\nimport type { UnpublishScheduleActionCms } from \"~/scheduler/actions/UnpublishScheduleAction.js\";\nimport { WebinyError } from \"@webiny/error\";\n\nexport type ScheduleExecutorCms = UnpublishScheduleActionCms & PublishScheduleActionCms;\n\nexport interface IScheduleExecutorParams {\n actions: IScheduleAction[];\n fetcher: IScheduleFetcher;\n}\n\nexport class ScheduleExecutor implements IScheduleExecutor {\n private readonly actions: IScheduleAction[];\n private readonly fetcher: Pick<IScheduleFetcher, \"getScheduled\">;\n\n constructor(params: IScheduleExecutorParams) {\n this.actions = params.actions;\n this.fetcher = params.fetcher;\n }\n\n public async schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord> {\n const scheduleRecordId = createScheduleRecordIdWithVersion(targetId);\n const original = await this.fetcher.getScheduled(targetId);\n\n const action = this.getAction(input.type);\n\n if (original) {\n return action.reschedule(original, input);\n }\n\n return await action.schedule({\n scheduleRecordId,\n targetId,\n input\n });\n }\n\n public async cancel(initialId: string): Promise<IScheduleRecord> {\n const id = createScheduleRecordIdWithVersion(initialId);\n const original = await this.fetcher.getScheduled(id);\n if (!original) {\n throw new WebinyError(\n `No scheduled record found for ID \"${id}\".`,\n \"SCHEDULED_RECORD_NOT_FOUND\",\n {\n id\n }\n );\n }\n\n const action = this.getAction(original.type);\n await action.cancel(original.id);\n return original;\n }\n\n private getAction(type: ScheduleType): IScheduleAction {\n const action = this.actions.find(action => {\n return action.canHandle({\n type\n });\n });\n if (action) {\n return action;\n }\n throw new WebinyError(`No action found for input type \"${type}\".`, \"NO_ACTION_FOUND\", {\n type\n });\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,uBAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AASO,MAAME,gBAAgB,CAA8B;EAIvDC,WAAWA,CAACC,MAA+B,EAAE;IACzC,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;EACjC;EAEA,MAAaC,QAAQA,CAACC,QAAgB,EAAEC,KAAsB,EAA4B;IACtF,MAAMC,gBAAgB,GAAG,IAAAC,yDAAiC,EAACH,QAAQ,CAAC;IACpE,MAAMI,QAAQ,GAAG,MAAM,IAAI,CAACN,OAAO,CAACO,YAAY,CAACL,QAAQ,CAAC;IAE1D,MAAMM,MAAM,GAAG,IAAI,CAACC,SAAS,CAACN,KAAK,CAACO,IAAI,CAAC;IAEzC,IAAIJ,QAAQ,EAAE;MACV,OAAOE,MAAM,CAACG,UAAU,CAACL,QAAQ,EAAEH,KAAK,CAAC;IAC7C;IAEA,OAAO,MAAMK,MAAM,CAACP,QAAQ,CAAC;MACzBG,gBAAgB;MAChBF,QAAQ;MACRC;IACJ,CAAC,CAAC;EACN;EAEA,MAAaS,MAAMA,CAACC,SAAiB,EAA4B;IAC7D,MAAMC,EAAE,GAAG,IAAAT,yDAAiC,EAACQ,SAAS,CAAC;IACvD,MAAMP,QAAQ,GAAG,MAAM,IAAI,CAACN,OAAO,CAACO,YAAY,CAACO,EAAE,CAAC;IACpD,IAAI,CAACR,QAAQ,EAAE;MACX,MAAM,IAAIS,kBAAW,CACjB,qCAAqCD,EAAE,IAAI,EAC3C,4BAA4B,EAC5B;QACIA;MACJ,CACJ,CAAC;IACL;IAEA,MAAMN,MAAM,GAAG,IAAI,CAACC,SAAS,CAACH,QAAQ,CAACI,IAAI,CAAC;IAC5C,MAAMF,MAAM,CAACI,MAAM,CAACN,QAAQ,CAACQ,EAAE,CAAC;IAChC,OAAOR,QAAQ;EACnB;EAEQG,SAASA,CAACC,IAAkB,EAAmB;IACnD,MAAMF,MAAM,GAAG,IAAI,CAACT,OAAO,CAACiB,IAAI,CAACR,MAAM,IAAI;MACvC,OAAOA,MAAM,CAACS,SAAS,CAAC;QACpBP;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;IACF,IAAIF,MAAM,EAAE;MACR,OAAOA,MAAM;IACjB;IACA,MAAM,IAAIO,kBAAW,CAAC,mCAAmCL,IAAI,IAAI,EAAE,iBAAiB,EAAE;MAClFA;IACJ,CAAC,CAAC;EACN;AACJ;AAACQ,OAAA,CAAAtB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import type { CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
2
+ import type { IScheduleFetcher, IScheduleRecord, ISchedulerListParams, ISchedulerListResponse } from "./types.js";
3
+ export type ScheduleFetcherCms = Pick<HeadlessCms, "getEntryById" | "listLatestEntries">;
4
+ export interface IScheduleFetcherParams {
5
+ cms: ScheduleFetcherCms;
6
+ targetModel: CmsModel;
7
+ scheduleModel: CmsModel;
8
+ }
9
+ export declare class ScheduleFetcher implements IScheduleFetcher {
10
+ private readonly cms;
11
+ private readonly targetModel;
12
+ private readonly scheduleModel;
13
+ constructor(params: IScheduleFetcherParams);
14
+ getScheduled(targetId: string): Promise<IScheduleRecord | null>;
15
+ listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;
16
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScheduleFetcher = void 0;
7
+ var _handlerGraphql = require("@webiny/handler-graphql");
8
+ var _createScheduleRecordId = require("./createScheduleRecordId.js");
9
+ var _ScheduleRecord = require("./ScheduleRecord.js");
10
+ var _utils = require("@webiny/utils");
11
+ class ScheduleFetcher {
12
+ constructor(params) {
13
+ this.cms = params.cms;
14
+ this.scheduleModel = params.scheduleModel;
15
+ this.targetModel = params.targetModel;
16
+ }
17
+ async getScheduled(targetId) {
18
+ const scheduleRecordId = (0, _createScheduleRecordId.createScheduleRecordIdWithVersion)(targetId);
19
+ try {
20
+ const entry = await this.cms.getEntryById(this.scheduleModel, scheduleRecordId);
21
+ return (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, entry);
22
+ } catch (ex) {
23
+ if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
24
+ return null;
25
+ }
26
+ console.error(`Error while fetching scheduled record: ${targetId}.`);
27
+ console.log((0, _utils.convertException)(ex));
28
+ throw ex;
29
+ }
30
+ }
31
+ async listScheduled(params) {
32
+ const [data, meta] = await this.cms.listLatestEntries(this.scheduleModel, {
33
+ sort: params.sort,
34
+ limit: params.limit,
35
+ /**
36
+ * When params
37
+ */
38
+ where: {
39
+ ...params.where
40
+ },
41
+ after: params.after
42
+ });
43
+ return {
44
+ data: data.map(item => (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, item)),
45
+ meta
46
+ };
47
+ }
48
+ }
49
+ exports.ScheduleFetcher = ScheduleFetcher;
50
+
51
+ //# sourceMappingURL=ScheduleFetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_handlerGraphql","require","_createScheduleRecordId","_ScheduleRecord","_utils","ScheduleFetcher","constructor","params","cms","scheduleModel","targetModel","getScheduled","targetId","scheduleRecordId","createScheduleRecordIdWithVersion","entry","getEntryById","transformScheduleEntry","ex","code","NotFoundError","console","error","log","convertException","listScheduled","data","meta","listLatestEntries","sort","limit","where","after","map","item","exports"],"sources":["ScheduleFetcher.ts"],"sourcesContent":["import type { CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport type {\n IScheduleEntryValues,\n IScheduleFetcher,\n IScheduleRecord,\n ISchedulerListParams,\n ISchedulerListResponse\n} from \"~/scheduler/types.js\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createScheduleRecordIdWithVersion } from \"~/scheduler/createScheduleRecordId.js\";\nimport { transformScheduleEntry } from \"~/scheduler/ScheduleRecord.js\";\nimport { convertException } from \"@webiny/utils\";\n\nexport type ScheduleFetcherCms = Pick<HeadlessCms, \"getEntryById\" | \"listLatestEntries\">;\n\nexport interface IScheduleFetcherParams {\n cms: ScheduleFetcherCms;\n targetModel: CmsModel;\n scheduleModel: CmsModel;\n}\n\nexport class ScheduleFetcher implements IScheduleFetcher {\n private readonly cms: ScheduleFetcherCms;\n private readonly targetModel: CmsModel;\n private readonly scheduleModel: CmsModel;\n\n constructor(params: IScheduleFetcherParams) {\n this.cms = params.cms;\n this.scheduleModel = params.scheduleModel;\n this.targetModel = params.targetModel;\n }\n\n public async getScheduled(targetId: string): Promise<IScheduleRecord | null> {\n const scheduleRecordId = createScheduleRecordIdWithVersion(targetId);\n try {\n const entry = await this.cms.getEntryById<IScheduleEntryValues>(\n this.scheduleModel,\n scheduleRecordId\n );\n return transformScheduleEntry(this.targetModel, entry);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n return null;\n }\n console.error(`Error while fetching scheduled record: ${targetId}.`);\n console.log(convertException(ex));\n throw ex;\n }\n }\n\n public async listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse> {\n const [data, meta] = await this.cms.listLatestEntries<IScheduleEntryValues>(\n this.scheduleModel,\n {\n sort: params.sort,\n limit: params.limit,\n /**\n * When params\n */\n where: {\n ...params.where\n },\n after: params.after\n }\n );\n\n return {\n data: data.map(item => transformScheduleEntry(this.targetModel, item)),\n meta\n };\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAUO,MAAMI,eAAe,CAA6B;EAKrDC,WAAWA,CAACC,MAA8B,EAAE;IACxC,IAAI,CAACC,GAAG,GAAGD,MAAM,CAACC,GAAG;IACrB,IAAI,CAACC,aAAa,GAAGF,MAAM,CAACE,aAAa;IACzC,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;EAEA,MAAaC,YAAYA,CAACC,QAAgB,EAAmC;IACzE,MAAMC,gBAAgB,GAAG,IAAAC,yDAAiC,EAACF,QAAQ,CAAC;IACpE,IAAI;MACA,MAAMG,KAAK,GAAG,MAAM,IAAI,CAACP,GAAG,CAACQ,YAAY,CACrC,IAAI,CAACP,aAAa,EAClBI,gBACJ,CAAC;MACD,OAAO,IAAAI,sCAAsB,EAAC,IAAI,CAACP,WAAW,EAAEK,KAAK,CAAC;IAC1D,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,IAAIA,EAAE,CAACC,IAAI,KAAK,WAAW,IAAID,EAAE,YAAYE,6BAAa,EAAE;QACxD,OAAO,IAAI;MACf;MACAC,OAAO,CAACC,KAAK,CAAC,0CAA0CV,QAAQ,GAAG,CAAC;MACpES,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACN,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;EACJ;EAEA,MAAaO,aAAaA,CAAClB,MAA4B,EAAmC;IACtF,MAAM,CAACmB,IAAI,EAAEC,IAAI,CAAC,GAAG,MAAM,IAAI,CAACnB,GAAG,CAACoB,iBAAiB,CACjD,IAAI,CAACnB,aAAa,EAClB;MACIoB,IAAI,EAAEtB,MAAM,CAACsB,IAAI;MACjBC,KAAK,EAAEvB,MAAM,CAACuB,KAAK;MACnB;AAChB;AACA;MACgBC,KAAK,EAAE;QACH,GAAGxB,MAAM,CAACwB;MACd,CAAC;MACDC,KAAK,EAAEzB,MAAM,CAACyB;IAClB,CACJ,CAAC;IAED,OAAO;MACHN,IAAI,EAAEA,IAAI,CAACO,GAAG,CAACC,IAAI,IAAI,IAAAjB,sCAAsB,EAAC,IAAI,CAACP,WAAW,EAAEwB,IAAI,CAAC,CAAC;MACtEP;IACJ,CAAC;EACL;AACJ;AAACQ,OAAA,CAAA9B,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ import { type DateOnType, type IScheduleEntryValues, type IScheduleRecord, type ScheduledOnType, ScheduleType } from "./types.js";
2
+ import type { CmsEntry, CmsIdentity, CmsModel } from "@webiny/api-headless-cms/types/index.js";
3
+ export interface IScheduleRecordParams {
4
+ id: string;
5
+ targetId: string;
6
+ model: CmsModel;
7
+ scheduledBy: CmsIdentity;
8
+ /**
9
+ * The date when the schedule is to be executed.
10
+ */
11
+ scheduledOn: ScheduledOnType;
12
+ /**
13
+ * The date when the action is to be set as done.
14
+ * User can set publishedOn (and other relevant dates) with this parameter.
15
+ */
16
+ dateOn: DateOnType | undefined;
17
+ type: ScheduleType;
18
+ title: string;
19
+ }
20
+ export declare class ScheduleRecord implements IScheduleRecord {
21
+ readonly id: string;
22
+ readonly targetId: string;
23
+ readonly model: CmsModel;
24
+ readonly scheduledBy: CmsIdentity;
25
+ readonly publishOn: ScheduledOnType | undefined;
26
+ readonly unpublishOn: ScheduledOnType | undefined;
27
+ readonly dateOn: DateOnType | undefined;
28
+ readonly type: ScheduleType;
29
+ readonly title: string;
30
+ constructor(record: IScheduleRecordParams);
31
+ }
32
+ export declare const createScheduleRecord: (record: IScheduleRecordParams) => IScheduleRecord;
33
+ export declare const transformScheduleEntry: (targetModel: CmsModel, entry: CmsEntry<IScheduleEntryValues>) => IScheduleRecord;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.transformScheduleEntry = exports.createScheduleRecord = exports.ScheduleRecord = void 0;
7
+ var _types = require("./types.js");
8
+ var _error = require("@webiny/error");
9
+ var _dates = require("./dates.js");
10
+ class ScheduleRecord {
11
+ constructor(record) {
12
+ this.id = record.id;
13
+ this.targetId = record.targetId;
14
+ this.model = record.model;
15
+ this.scheduledBy = record.scheduledBy;
16
+ this.dateOn = record.dateOn;
17
+ this.publishOn = record.type === _types.ScheduleType.publish ? record.scheduledOn : undefined;
18
+ this.unpublishOn = record.type === _types.ScheduleType.unpublish ? record.scheduledOn : undefined;
19
+ this.type = record.type;
20
+ this.title = record.title;
21
+ }
22
+ }
23
+ exports.ScheduleRecord = ScheduleRecord;
24
+ const createScheduleRecord = record => {
25
+ return new ScheduleRecord(record);
26
+ };
27
+ exports.createScheduleRecord = createScheduleRecord;
28
+ const transformScheduleEntry = (targetModel, entry) => {
29
+ let type;
30
+ switch (entry.values.type) {
31
+ case _types.ScheduleType.publish:
32
+ type = _types.ScheduleType.publish;
33
+ break;
34
+ case _types.ScheduleType.unpublish:
35
+ type = _types.ScheduleType.unpublish;
36
+ break;
37
+ default:
38
+ throw new _error.WebinyError(`Unsupported schedule type "${entry.values.type}".`, "UNSUPPORTED_SCHEDULE_TYPE", {
39
+ type: entry.values.type,
40
+ entry
41
+ });
42
+ }
43
+ return createScheduleRecord({
44
+ id: entry.id,
45
+ type,
46
+ title: entry.values.title,
47
+ targetId: entry.values.targetId,
48
+ scheduledOn: new Date(entry.values.scheduledOn),
49
+ dateOn: (0, _dates.isoStringToDate)(entry.values.dateOn),
50
+ scheduledBy: entry.savedBy,
51
+ model: targetModel
52
+ });
53
+ };
54
+ exports.transformScheduleEntry = transformScheduleEntry;
55
+
56
+ //# sourceMappingURL=ScheduleRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_error","_dates","ScheduleRecord","constructor","record","id","targetId","model","scheduledBy","dateOn","publishOn","type","ScheduleType","publish","scheduledOn","undefined","unpublishOn","unpublish","title","exports","createScheduleRecord","transformScheduleEntry","targetModel","entry","values","WebinyError","Date","isoStringToDate","savedBy"],"sources":["ScheduleRecord.ts"],"sourcesContent":["import {\n type DateOnType,\n type IScheduleEntryValues,\n type IScheduleRecord,\n type ScheduledOnType,\n ScheduleType\n} from \"~/scheduler/types.js\";\nimport type { CmsEntry, CmsIdentity, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { isoStringToDate } from \"~/scheduler/dates.js\";\n\nexport interface IScheduleRecordParams {\n id: string;\n targetId: string;\n model: CmsModel;\n scheduledBy: CmsIdentity;\n /**\n * The date when the schedule is to be executed.\n */\n scheduledOn: ScheduledOnType;\n /**\n * The date when the action is to be set as done.\n * User can set publishedOn (and other relevant dates) with this parameter.\n */\n dateOn: DateOnType | undefined;\n type: ScheduleType;\n title: string;\n}\n\nexport class ScheduleRecord implements IScheduleRecord {\n public readonly id: string;\n public readonly targetId: string;\n public readonly model: CmsModel;\n public readonly scheduledBy: CmsIdentity;\n public readonly publishOn: ScheduledOnType | undefined;\n public readonly unpublishOn: ScheduledOnType | undefined;\n public readonly dateOn: DateOnType | undefined;\n public readonly type: ScheduleType;\n public readonly title: string;\n\n public constructor(record: IScheduleRecordParams) {\n this.id = record.id;\n this.targetId = record.targetId;\n this.model = record.model;\n this.scheduledBy = record.scheduledBy;\n this.dateOn = record.dateOn;\n this.publishOn = record.type === ScheduleType.publish ? record.scheduledOn : undefined;\n this.unpublishOn = record.type === ScheduleType.unpublish ? record.scheduledOn : undefined;\n this.type = record.type;\n this.title = record.title;\n }\n}\n\nexport const createScheduleRecord = (record: IScheduleRecordParams): IScheduleRecord => {\n return new ScheduleRecord(record);\n};\n\nexport const transformScheduleEntry = (\n targetModel: CmsModel,\n entry: CmsEntry<IScheduleEntryValues>\n): IScheduleRecord => {\n let type: ScheduleType;\n switch (entry.values.type) {\n case ScheduleType.publish:\n type = ScheduleType.publish;\n break;\n case ScheduleType.unpublish:\n type = ScheduleType.unpublish;\n break;\n default:\n throw new WebinyError(\n `Unsupported schedule type \"${entry.values.type}\".`,\n \"UNSUPPORTED_SCHEDULE_TYPE\",\n {\n type: entry.values.type,\n entry\n }\n );\n }\n return createScheduleRecord({\n id: entry.id,\n type,\n title: entry.values.title,\n targetId: entry.values.targetId,\n scheduledOn: new Date(entry.values.scheduledOn),\n dateOn: isoStringToDate(entry.values.dateOn),\n scheduledBy: entry.savedBy,\n model: targetModel\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAQA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAoBO,MAAMG,cAAc,CAA4B;EAW5CC,WAAWA,CAACC,MAA6B,EAAE;IAC9C,IAAI,CAACC,EAAE,GAAGD,MAAM,CAACC,EAAE;IACnB,IAAI,CAACC,QAAQ,GAAGF,MAAM,CAACE,QAAQ;IAC/B,IAAI,CAACC,KAAK,GAAGH,MAAM,CAACG,KAAK;IACzB,IAAI,CAACC,WAAW,GAAGJ,MAAM,CAACI,WAAW;IACrC,IAAI,CAACC,MAAM,GAAGL,MAAM,CAACK,MAAM;IAC3B,IAAI,CAACC,SAAS,GAAGN,MAAM,CAACO,IAAI,KAAKC,mBAAY,CAACC,OAAO,GAAGT,MAAM,CAACU,WAAW,GAAGC,SAAS;IACtF,IAAI,CAACC,WAAW,GAAGZ,MAAM,CAACO,IAAI,KAAKC,mBAAY,CAACK,SAAS,GAAGb,MAAM,CAACU,WAAW,GAAGC,SAAS;IAC1F,IAAI,CAACJ,IAAI,GAAGP,MAAM,CAACO,IAAI;IACvB,IAAI,CAACO,KAAK,GAAGd,MAAM,CAACc,KAAK;EAC7B;AACJ;AAACC,OAAA,CAAAjB,cAAA,GAAAA,cAAA;AAEM,MAAMkB,oBAAoB,GAAIhB,MAA6B,IAAsB;EACpF,OAAO,IAAIF,cAAc,CAACE,MAAM,CAAC;AACrC,CAAC;AAACe,OAAA,CAAAC,oBAAA,GAAAA,oBAAA;AAEK,MAAMC,sBAAsB,GAAGA,CAClCC,WAAqB,EACrBC,KAAqC,KACnB;EAClB,IAAIZ,IAAkB;EACtB,QAAQY,KAAK,CAACC,MAAM,CAACb,IAAI;IACrB,KAAKC,mBAAY,CAACC,OAAO;MACrBF,IAAI,GAAGC,mBAAY,CAACC,OAAO;MAC3B;IACJ,KAAKD,mBAAY,CAACK,SAAS;MACvBN,IAAI,GAAGC,mBAAY,CAACK,SAAS;MAC7B;IACJ;MACI,MAAM,IAAIQ,kBAAW,CACjB,8BAA8BF,KAAK,CAACC,MAAM,CAACb,IAAI,IAAI,EACnD,2BAA2B,EAC3B;QACIA,IAAI,EAAEY,KAAK,CAACC,MAAM,CAACb,IAAI;QACvBY;MACJ,CACJ,CAAC;EACT;EACA,OAAOH,oBAAoB,CAAC;IACxBf,EAAE,EAAEkB,KAAK,CAAClB,EAAE;IACZM,IAAI;IACJO,KAAK,EAAEK,KAAK,CAACC,MAAM,CAACN,KAAK;IACzBZ,QAAQ,EAAEiB,KAAK,CAACC,MAAM,CAAClB,QAAQ;IAC/BQ,WAAW,EAAE,IAAIY,IAAI,CAACH,KAAK,CAACC,MAAM,CAACV,WAAW,CAAC;IAC/CL,MAAM,EAAE,IAAAkB,sBAAe,EAACJ,KAAK,CAACC,MAAM,CAACf,MAAM,CAAC;IAC5CD,WAAW,EAAEe,KAAK,CAACK,OAAO;IAC1BrB,KAAK,EAAEe;EACX,CAAC,CAAC;AACN,CAAC;AAACH,OAAA,CAAAE,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import type { IScheduleExecutor, IScheduleFetcher, IScheduler, IScheduleRecord, ISchedulerInput, ISchedulerListParams, ISchedulerListResponse } from "./types.js";
2
+ export interface ISchedulerParams {
3
+ fetcher: IScheduleFetcher;
4
+ executor: IScheduleExecutor;
5
+ }
6
+ export declare class Scheduler implements IScheduler {
7
+ private readonly fetcher;
8
+ private readonly executor;
9
+ constructor(params: ISchedulerParams);
10
+ getScheduled(targetId: string): Promise<IScheduleRecord | null>;
11
+ listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;
12
+ schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord>;
13
+ cancel(id: string): Promise<IScheduleRecord>;
14
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Scheduler = void 0;
7
+ class Scheduler {
8
+ constructor(params) {
9
+ this.fetcher = params.fetcher;
10
+ this.executor = params.executor;
11
+ }
12
+ async getScheduled(targetId) {
13
+ return this.fetcher.getScheduled(targetId);
14
+ }
15
+ async listScheduled(params) {
16
+ return this.fetcher.listScheduled(params);
17
+ }
18
+ async schedule(targetId, input) {
19
+ return this.executor.schedule(targetId, input);
20
+ }
21
+ async cancel(id) {
22
+ return this.executor.cancel(id);
23
+ }
24
+ }
25
+ exports.Scheduler = Scheduler;
26
+
27
+ //# sourceMappingURL=Scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Scheduler","constructor","params","fetcher","executor","getScheduled","targetId","listScheduled","schedule","input","cancel","id","exports"],"sources":["Scheduler.ts"],"sourcesContent":["import type {\n IScheduleExecutor,\n IScheduleFetcher,\n IScheduler,\n IScheduleRecord,\n ISchedulerInput,\n ISchedulerListParams,\n ISchedulerListResponse\n} from \"~/scheduler/types.js\";\n\nexport interface ISchedulerParams {\n fetcher: IScheduleFetcher;\n executor: IScheduleExecutor;\n}\n\nexport class Scheduler implements IScheduler {\n private readonly fetcher: IScheduleFetcher;\n private readonly executor: IScheduleExecutor;\n\n constructor(params: ISchedulerParams) {\n this.fetcher = params.fetcher;\n this.executor = params.executor;\n }\n\n public async getScheduled(targetId: string): Promise<IScheduleRecord | null> {\n return this.fetcher.getScheduled(targetId);\n }\n\n public async listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse> {\n return this.fetcher.listScheduled(params);\n }\n\n public async schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord> {\n return this.executor.schedule(targetId, input);\n }\n\n public async cancel(id: string): Promise<IScheduleRecord> {\n return this.executor.cancel(id);\n }\n}\n"],"mappings":";;;;;;AAeO,MAAMA,SAAS,CAAuB;EAIzCC,WAAWA,CAACC,MAAwB,EAAE;IAClC,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,QAAQ,GAAGF,MAAM,CAACE,QAAQ;EACnC;EAEA,MAAaC,YAAYA,CAACC,QAAgB,EAAmC;IACzE,OAAO,IAAI,CAACH,OAAO,CAACE,YAAY,CAACC,QAAQ,CAAC;EAC9C;EAEA,MAAaC,aAAaA,CAACL,MAA4B,EAAmC;IACtF,OAAO,IAAI,CAACC,OAAO,CAACI,aAAa,CAACL,MAAM,CAAC;EAC7C;EAEA,MAAaM,QAAQA,CAACF,QAAgB,EAAEG,KAAsB,EAA4B;IACtF,OAAO,IAAI,CAACL,QAAQ,CAACI,QAAQ,CAACF,QAAQ,EAAEG,KAAK,CAAC;EAClD;EAEA,MAAaC,MAAMA,CAACC,EAAU,EAA4B;IACtD,OAAO,IAAI,CAACP,QAAQ,CAACM,MAAM,CAACC,EAAE,CAAC;EACnC;AACJ;AAACC,OAAA,CAAAZ,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import type { IScheduleAction, IScheduleActionScheduleParams, IScheduleFetcher, IScheduleRecord, ISchedulerInput } from "../types.js";
2
+ import type { CmsIdentity, CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
3
+ import type { ISchedulerService } from "../../service/types.js";
4
+ export type PublishScheduleActionCms = Pick<HeadlessCms, "getEntryById" | "publishEntry" | "createEntry" | "updateEntry" | "deleteEntry">;
5
+ export interface IPublishScheduleActionParams {
6
+ service: ISchedulerService;
7
+ cms: PublishScheduleActionCms;
8
+ targetModel: CmsModel;
9
+ scheduleModel: CmsModel;
10
+ getIdentity: () => CmsIdentity;
11
+ fetcher: IScheduleFetcher;
12
+ }
13
+ export declare class PublishScheduleAction implements IScheduleAction {
14
+ private readonly service;
15
+ private readonly cms;
16
+ private readonly targetModel;
17
+ private readonly scheduleModel;
18
+ private readonly getIdentity;
19
+ private readonly fetcher;
20
+ constructor(params: IPublishScheduleActionParams);
21
+ canHandle(input: ISchedulerInput): boolean;
22
+ schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;
23
+ reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;
24
+ cancel(id: string): Promise<void>;
25
+ private getUpdateableTargetEntry;
26
+ }
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PublishScheduleAction = void 0;
7
+ var _types = require("../types.js");
8
+ var _ScheduleRecord = require("../ScheduleRecord.js");
9
+ var _utils = require("@webiny/utils");
10
+ var _dates = require("../dates.js");
11
+ var _handlerGraphql = require("@webiny/handler-graphql");
12
+ var _dateInTheFuture = require("../../utils/dateInTheFuture.js");
13
+ var _index = require("@webiny/error/index");
14
+ var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
15
+ class PublishScheduleAction {
16
+ constructor(params) {
17
+ this.service = params.service;
18
+ this.cms = params.cms;
19
+ this.targetModel = params.targetModel;
20
+ this.scheduleModel = params.scheduleModel;
21
+ this.getIdentity = params.getIdentity;
22
+ this.fetcher = params.fetcher;
23
+ }
24
+ canHandle(input) {
25
+ return input.type === _types.ScheduleType.publish;
26
+ }
27
+ async schedule(params) {
28
+ const {
29
+ targetId,
30
+ input,
31
+ scheduleRecordId
32
+ } = params;
33
+ const targetEntry = await this.getUpdateableTargetEntry(targetId);
34
+ const title = targetEntry.values[this.targetModel.titleFieldId] || "Unknown entry title";
35
+ const identity = this.getIdentity();
36
+ const currentDate = new Date();
37
+ /**
38
+ * Immediately publish the entry if requested.
39
+ * No need to create a schedule entry or the service event.
40
+ */
41
+ if (input.immediately) {
42
+ const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);
43
+ return (0, _ScheduleRecord.createScheduleRecord)({
44
+ id: scheduleRecordId,
45
+ targetId,
46
+ model: this.targetModel,
47
+ scheduledBy: publishedEntry.savedBy,
48
+ scheduledOn: new Date(publishedEntry.savedOn),
49
+ dateOn: currentDate,
50
+ type: _types.ScheduleType.publish,
51
+ title
52
+ });
53
+ }
54
+ /**
55
+ * If the entry is scheduled for a date in the past, we need to update it with publish information, if user sent something.
56
+ * No need to create a schedule entry or the service event.
57
+ */
58
+ //
59
+ else if ((0, _dateInTheFuture.dateInTheFuture)(input.scheduleOn) === false) {
60
+ /**
61
+ * We need to update the entry with publish information because we cannot update it in the publishing process.
62
+ */
63
+ await this.cms.updateEntry(this.targetModel, targetId, {
64
+ firstPublishedBy: identity,
65
+ firstPublishedOn: (0, _dates.dateToISOString)(input.scheduleOn),
66
+ lastPublishedOn: (0, _dates.dateToISOString)(input.scheduleOn),
67
+ lastPublishedBy: identity
68
+ });
69
+ const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);
70
+ return (0, _ScheduleRecord.createScheduleRecord)({
71
+ id: scheduleRecordId,
72
+ targetId,
73
+ model: this.targetModel,
74
+ scheduledBy: publishedEntry.savedBy,
75
+ scheduledOn: currentDate,
76
+ dateOn: input.dateOn,
77
+ type: _types.ScheduleType.publish,
78
+ title
79
+ });
80
+ }
81
+ const {
82
+ id: scheduleEntryId
83
+ } = (0, _parseIdentifier.parseIdentifier)(scheduleRecordId);
84
+ const scheduleEntry = await this.cms.createEntry(this.scheduleModel, {
85
+ id: scheduleEntryId,
86
+ targetId,
87
+ targetModelId: this.targetModel.modelId,
88
+ title,
89
+ type: _types.ScheduleType.publish,
90
+ scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
91
+ dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined,
92
+ scheduledBy: identity
93
+ });
94
+ try {
95
+ await this.service.create({
96
+ id: scheduleRecordId,
97
+ scheduleOn: input.scheduleOn
98
+ });
99
+ } catch (ex) {
100
+ console.error(`Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`);
101
+ console.log((0, _utils.convertException)(ex));
102
+ try {
103
+ await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);
104
+ } catch (err) {
105
+ console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);
106
+ console.log((0, _utils.convertException)(err));
107
+ throw err;
108
+ }
109
+ throw ex;
110
+ }
111
+ return (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, scheduleEntry);
112
+ }
113
+ async reschedule(original, input) {
114
+ const currentDate = new Date();
115
+ const targetId = original.targetId;
116
+ const targetEntry = await this.getUpdateableTargetEntry(targetId);
117
+
118
+ /**
119
+ * There are two cases when we can immediately publish the entry:
120
+ * 1. If the user requested it.
121
+ * 2. If the entry is scheduled for a date in the past.
122
+ */
123
+ if (input.immediately || input.scheduleOn < currentDate) {
124
+ const updatedTargetEntry = await this.cms.updateEntry(this.targetModel, targetEntry.id, {
125
+ lastPublishedOn: input.dateOn ? input.dateOn.toISOString() : undefined,
126
+ lastPublishedBy: this.getIdentity()
127
+ });
128
+ const publishedEntry = await this.cms.publishEntry(this.targetModel, updatedTargetEntry.id);
129
+ /**
130
+ * We can safely cancel the original schedule entry and the event.
131
+ *
132
+ * // TODO determine if we want to ignore the error of the cancelation.
133
+ */
134
+ try {
135
+ await this.cancel(original.id);
136
+ } catch {
137
+ //
138
+ }
139
+ return {
140
+ ...original,
141
+ publishOn: currentDate,
142
+ unpublishOn: undefined,
143
+ dateOn: publishedEntry.lastPublishedOn ? new Date(publishedEntry.lastPublishedOn) : undefined
144
+ };
145
+ }
146
+ await this.cms.updateEntry(this.scheduleModel, original.id, {
147
+ scheduledBy: this.getIdentity(),
148
+ scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
149
+ dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined
150
+ });
151
+ try {
152
+ await this.service.update({
153
+ id: original.id,
154
+ scheduleOn: input.scheduleOn
155
+ });
156
+ } catch (ex) {
157
+ throw ex;
158
+ }
159
+ return {
160
+ ...original,
161
+ publishOn: new Date(),
162
+ unpublishOn: undefined,
163
+ dateOn: input.dateOn
164
+ };
165
+ }
166
+ async cancel(id) {
167
+ /**
168
+ * No need to do anything if the record does not exist.
169
+ */
170
+ let scheduleEntry = null;
171
+ try {
172
+ scheduleEntry = await this.fetcher.getScheduled(id);
173
+ if (!scheduleEntry) {
174
+ return;
175
+ }
176
+ } catch {
177
+ return;
178
+ }
179
+ try {
180
+ await this.cms.deleteEntry(this.scheduleModel, scheduleEntry.id);
181
+ } catch (ex) {
182
+ if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
183
+ return;
184
+ }
185
+ console.error(`Error while deleting schedule entry: ${scheduleEntry.id}.`);
186
+ console.log((0, _utils.convertException)(ex));
187
+ throw ex;
188
+ }
189
+ try {
190
+ await this.service.delete(scheduleEntry.id);
191
+ } catch (ex) {
192
+ console.error(`Error while deleting service event for schedule entry: ${scheduleEntry.id}.`);
193
+ console.log((0, _utils.convertException)(ex));
194
+ throw ex;
195
+ }
196
+ }
197
+ async getUpdateableTargetEntry(id) {
198
+ const entry = await this.cms.getEntryById(this.targetModel, id);
199
+ if (entry.locked) {
200
+ throw new _index.WebinyError(`Cannot schedule a publish action for entry "${entry.id}" because it is locked.`, "ENTRY_LOCKED", {
201
+ entryId: entry.id
202
+ });
203
+ }
204
+ return entry;
205
+ }
206
+ }
207
+ exports.PublishScheduleAction = PublishScheduleAction;
208
+
209
+ //# sourceMappingURL=PublishScheduleAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_ScheduleRecord","_utils","_dates","_handlerGraphql","_dateInTheFuture","_index","_parseIdentifier","PublishScheduleAction","constructor","params","service","cms","targetModel","scheduleModel","getIdentity","fetcher","canHandle","input","type","ScheduleType","publish","schedule","targetId","scheduleRecordId","targetEntry","getUpdateableTargetEntry","title","values","titleFieldId","identity","currentDate","Date","immediately","publishedEntry","publishEntry","createScheduleRecord","id","model","scheduledBy","savedBy","scheduledOn","savedOn","dateOn","dateInTheFuture","scheduleOn","updateEntry","firstPublishedBy","firstPublishedOn","dateToISOString","lastPublishedOn","lastPublishedBy","scheduleEntryId","parseIdentifier","scheduleEntry","createEntry","targetModelId","modelId","undefined","create","ex","console","error","log","convertException","deleteEntry","err","transformScheduleEntry","reschedule","original","updatedTargetEntry","toISOString","cancel","publishOn","unpublishOn","update","getScheduled","code","NotFoundError","delete","entry","getEntryById","locked","WebinyError","entryId","exports"],"sources":["PublishScheduleAction.ts"],"sourcesContent":["import type {\n IScheduleAction,\n IScheduleActionScheduleParams,\n IScheduleEntryValues,\n IScheduleFetcher,\n IScheduleRecord,\n ISchedulerInput\n} from \"~/scheduler/types.js\";\nimport { ScheduleType } from \"~/scheduler/types.js\";\nimport { createScheduleRecord, transformScheduleEntry } from \"~/scheduler/ScheduleRecord.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsIdentity,\n CmsModel,\n HeadlessCms\n} from \"@webiny/api-headless-cms/types\";\nimport type { ISchedulerService } from \"~/service/types.js\";\nimport { dateToISOString } from \"~/scheduler/dates.js\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { dateInTheFuture } from \"~/utils/dateInTheFuture.js\";\nimport { WebinyError } from \"@webiny/error/index\";\nimport { parseIdentifier } from \"@webiny/utils/parseIdentifier.js\";\n\nexport type PublishScheduleActionCms = Pick<\n HeadlessCms,\n \"getEntryById\" | \"publishEntry\" | \"createEntry\" | \"updateEntry\" | \"deleteEntry\"\n>;\n\nexport interface IPublishScheduleActionParams {\n service: ISchedulerService;\n cms: PublishScheduleActionCms;\n targetModel: CmsModel;\n scheduleModel: CmsModel;\n getIdentity: () => CmsIdentity;\n fetcher: IScheduleFetcher;\n}\n\nexport class PublishScheduleAction implements IScheduleAction {\n private readonly service: ISchedulerService;\n private readonly cms: PublishScheduleActionCms;\n private readonly targetModel: CmsModel;\n private readonly scheduleModel: CmsModel;\n private readonly getIdentity: () => CmsIdentity;\n private readonly fetcher: IScheduleFetcher;\n\n public constructor(params: IPublishScheduleActionParams) {\n this.service = params.service;\n this.cms = params.cms;\n this.targetModel = params.targetModel;\n this.scheduleModel = params.scheduleModel;\n this.getIdentity = params.getIdentity;\n this.fetcher = params.fetcher;\n }\n\n public canHandle(input: ISchedulerInput): boolean {\n return input.type === ScheduleType.publish;\n }\n\n public async schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord> {\n const { targetId, input, scheduleRecordId } = params;\n\n const targetEntry = await this.getUpdateableTargetEntry(targetId);\n\n const title = targetEntry.values[this.targetModel.titleFieldId] || \"Unknown entry title\";\n const identity = this.getIdentity();\n\n const currentDate = new Date();\n /**\n * Immediately publish the entry if requested.\n * No need to create a schedule entry or the service event.\n */\n if (input.immediately) {\n const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: publishedEntry.savedBy,\n scheduledOn: new Date(publishedEntry.savedOn),\n dateOn: currentDate,\n type: ScheduleType.publish,\n title\n });\n }\n /**\n * If the entry is scheduled for a date in the past, we need to update it with publish information, if user sent something.\n * No need to create a schedule entry or the service event.\n */\n //\n else if (dateInTheFuture(input.scheduleOn) === false) {\n /**\n * We need to update the entry with publish information because we cannot update it in the publishing process.\n */\n await this.cms.updateEntry(this.targetModel, targetId, {\n firstPublishedBy: identity,\n firstPublishedOn: dateToISOString(input.scheduleOn),\n lastPublishedOn: dateToISOString(input.scheduleOn),\n lastPublishedBy: identity\n });\n const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: publishedEntry.savedBy,\n scheduledOn: currentDate,\n dateOn: input.dateOn,\n type: ScheduleType.publish,\n title\n });\n }\n\n const { id: scheduleEntryId } = parseIdentifier(scheduleRecordId);\n const scheduleEntry = await this.cms.createEntry<IScheduleEntryValues>(this.scheduleModel, {\n id: scheduleEntryId,\n targetId,\n targetModelId: this.targetModel.modelId,\n title,\n type: ScheduleType.publish,\n scheduledOn: dateToISOString(input.scheduleOn),\n dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined,\n scheduledBy: identity\n });\n\n try {\n await this.service.create({\n id: scheduleRecordId,\n scheduleOn: input.scheduleOn\n });\n } catch (ex) {\n console.error(\n `Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`\n );\n console.log(convertException(ex));\n try {\n await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);\n } catch (err) {\n console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);\n console.log(convertException(err));\n throw err;\n }\n throw ex;\n }\n return transformScheduleEntry(this.targetModel, scheduleEntry);\n }\n\n public async reschedule(\n original: IScheduleRecord,\n input: ISchedulerInput\n ): Promise<IScheduleRecord> {\n const currentDate = new Date();\n const targetId = original.targetId;\n\n const targetEntry = await this.getUpdateableTargetEntry(targetId);\n\n /**\n * There are two cases when we can immediately publish the entry:\n * 1. If the user requested it.\n * 2. If the entry is scheduled for a date in the past.\n */\n if (input.immediately || input.scheduleOn < currentDate) {\n const updatedTargetEntry = await this.cms.updateEntry(\n this.targetModel,\n targetEntry.id,\n {\n lastPublishedOn: input.dateOn ? input.dateOn.toISOString() : undefined,\n lastPublishedBy: this.getIdentity()\n }\n );\n\n const publishedEntry = await this.cms.publishEntry(\n this.targetModel,\n updatedTargetEntry.id\n );\n /**\n * We can safely cancel the original schedule entry and the event.\n *\n * // TODO determine if we want to ignore the error of the cancelation.\n */\n try {\n await this.cancel(original.id);\n } catch {\n //\n }\n\n return {\n ...original,\n publishOn: currentDate,\n unpublishOn: undefined,\n dateOn: publishedEntry.lastPublishedOn\n ? new Date(publishedEntry.lastPublishedOn)\n : undefined\n };\n }\n\n await this.cms.updateEntry<\n Pick<IScheduleEntryValues, \"scheduledOn\" | \"dateOn\" | \"scheduledBy\">\n >(this.scheduleModel, original.id, {\n scheduledBy: this.getIdentity(),\n scheduledOn: dateToISOString(input.scheduleOn),\n dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined\n });\n\n try {\n await this.service.update({\n id: original.id,\n scheduleOn: input.scheduleOn\n });\n } catch (ex) {\n throw ex;\n }\n return {\n ...original,\n publishOn: new Date(),\n unpublishOn: undefined,\n dateOn: input.dateOn\n };\n }\n\n public async cancel(id: string): Promise<void> {\n /**\n * No need to do anything if the record does not exist.\n */\n let scheduleEntry: IScheduleRecord | null = null;\n try {\n scheduleEntry = await this.fetcher.getScheduled(id);\n if (!scheduleEntry) {\n return;\n }\n } catch {\n return;\n }\n\n try {\n await this.cms.deleteEntry(this.scheduleModel, scheduleEntry.id);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n return;\n }\n console.error(`Error while deleting schedule entry: ${scheduleEntry.id}.`);\n console.log(convertException(ex));\n throw ex;\n }\n\n try {\n await this.service.delete(scheduleEntry.id);\n } catch (ex) {\n console.error(\n `Error while deleting service event for schedule entry: ${scheduleEntry.id}.`\n );\n console.log(convertException(ex));\n throw ex;\n }\n }\n\n private async getUpdateableTargetEntry<T = CmsEntryValues>(id: string): Promise<CmsEntry<T>> {\n const entry = await this.cms.getEntryById<T>(this.targetModel, id);\n if (entry.locked) {\n throw new WebinyError(\n `Cannot schedule a publish action for entry \"${entry.id}\" because it is locked.`,\n \"ENTRY_LOCKED\",\n {\n entryId: entry.id\n }\n );\n }\n return entry;\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAC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