@webiny/api-headless-cms-scheduler 0.0.0-unstable.fdd9228b5d → 6.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/context.js CHANGED
@@ -12,6 +12,7 @@ var _createScheduler = require("./scheduler/createScheduler.js");
12
12
  var _handlerGraphql = require("@webiny/handler-graphql");
13
13
  var _constants = require("./constants.js");
14
14
  var _apiHeadlessCms = require("@webiny/api-headless-cms");
15
+ var _index2 = require("./hooks/index.js");
15
16
  const createHeadlessCmsScheduleContext = params => {
16
17
  return new _index.ContextPlugin(async context => {
17
18
  /**
@@ -38,9 +39,9 @@ const createHeadlessCmsScheduleContext = params => {
38
39
  roleArn: manifest.data.roleArn
39
40
  }
40
41
  });
41
- let scheduleModel;
42
+ let schedulerModel;
42
43
  try {
43
- scheduleModel = await context.cms.getModel(_constants.SCHEDULE_MODEL_ID);
44
+ schedulerModel = await context.cms.getModel(_constants.SCHEDULE_MODEL_ID);
44
45
  } catch (ex) {
45
46
  if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
46
47
  console.error(`Schedule model "${_constants.SCHEDULE_MODEL_ID}" not found.`);
@@ -50,11 +51,15 @@ const createHeadlessCmsScheduleContext = params => {
50
51
  console.log((0, _utils.convertException)(ex));
51
52
  return;
52
53
  }
54
+ (0, _index2.attachLifecycleHooks)({
55
+ cms: context.cms,
56
+ schedulerModel
57
+ });
53
58
  context.cms.scheduler = await (0, _createScheduler.createScheduler)({
54
59
  cms: context.cms,
55
60
  security: context.security,
56
61
  service,
57
- scheduleModel
62
+ schedulerModel
58
63
  });
59
64
  });
60
65
  };
package/context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_index","require","_SchedulerService","_manifest","_utils","_createScheduler","_handlerGraphql","_constants","_apiHeadlessCms","createHeadlessCmsScheduleContext","params","ContextPlugin","context","ready","isHeadlessCmsReady","manifest","getManifest","client","db","driver","getClient","error","console","message","log","convertException","info","service","createSchedulerService","config","lambdaArn","data","roleArn","scheduleModel","cms","getModel","SCHEDULE_MODEL_ID","ex","code","NotFoundError","scheduler","createScheduler","security","exports"],"sources":["context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api/index.js\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { createSchedulerService } from \"~/service/SchedulerService.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { ScheduleContext } from \"~/types.js\";\nimport { createScheduler } from \"./scheduler/createScheduler.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport { isHeadlessCmsReady } from \"@webiny/api-headless-cms\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createHeadlessCmsScheduleContext = (\n params: ICreateHeadlessCmsSchedulerContextParams\n) => {\n return new ContextPlugin<ScheduleContext>(async context => {\n /**\n * If the Headless CMS is not ready, it means the system is not fully installed yet.\n * We do not want to continue because it would break anyway.\n */\n const ready = await isHeadlessCmsReady(context);\n if (!ready) {\n return;\n }\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n if (manifest.error) {\n console.error(manifest.error.message);\n console.log(convertException(manifest.error, [\"message\"]));\n console.info(\"Scheduler not attached.\");\n return;\n }\n\n const service = createSchedulerService({\n getClient: params.getClient,\n config: {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n }\n });\n\n let scheduleModel: CmsModel;\n try {\n scheduleModel = await context.cms.getModel(SCHEDULE_MODEL_ID);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n console.error(`Schedule model \"${SCHEDULE_MODEL_ID}\" not found.`);\n return;\n }\n console.error(`Error while fetching schedule model \"${SCHEDULE_MODEL_ID}\".`);\n console.log(convertException(ex));\n return;\n }\n\n context.cms.scheduler = await createScheduler({\n cms: context.cms,\n security: context.security,\n service,\n scheduleModel\n });\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAJ,OAAA;AAEA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AAOO,MAAMQ,gCAAgC,GACzCC,MAAgD,IAC/C;EACD,OAAO,IAAIC,oBAAa,CAAkB,MAAMC,OAAO,IAAI;IACvD;AACR;AACA;AACA;IACQ,MAAMC,KAAK,GAAG,MAAM,IAAAC,kCAAkB,EAACF,OAAO,CAAC;IAC/C,IAAI,CAACC,KAAK,EAAE;MACR;IACJ;IACA,MAAME,QAAQ,GAAG,MAAM,IAAAC,qBAAW,EAAC;MAC/BC,MAAM,EAAEL,OAAO,CAACM,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC;IACxC,CAAC,CAAC;IACF,IAAIL,QAAQ,CAACM,KAAK,EAAE;MAChBC,OAAO,CAACD,KAAK,CAACN,QAAQ,CAACM,KAAK,CAACE,OAAO,CAAC;MACrCD,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACV,QAAQ,CAACM,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;MAC1DC,OAAO,CAACI,IAAI,CAAC,yBAAyB,CAAC;MACvC;IACJ;IAEA,MAAMC,OAAO,GAAG,IAAAC,wCAAsB,EAAC;MACnCR,SAAS,EAAEV,MAAM,CAACU,SAAS;MAC3BS,MAAM,EAAE;QACJC,SAAS,EAAEf,QAAQ,CAACgB,IAAI,CAACD,SAAS;QAClCE,OAAO,EAAEjB,QAAQ,CAACgB,IAAI,CAACC;MAC3B;IACJ,CAAC,CAAC;IAEF,IAAIC,aAAuB;IAC3B,IAAI;MACAA,aAAa,GAAG,MAAMrB,OAAO,CAACsB,GAAG,CAACC,QAAQ,CAACC,4BAAiB,CAAC;IACjE,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAIA,EAAE,CAACC,IAAI,KAAK,WAAW,IAAID,EAAE,YAAYE,6BAAa,EAAE;QACxDjB,OAAO,CAACD,KAAK,CAAC,mBAAmBe,4BAAiB,cAAc,CAAC;QACjE;MACJ;MACAd,OAAO,CAACD,KAAK,CAAC,wCAAwCe,4BAAiB,IAAI,CAAC;MAC5Ed,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACY,EAAE,CAAC,CAAC;MACjC;IACJ;IAEAzB,OAAO,CAACsB,GAAG,CAACM,SAAS,GAAG,MAAM,IAAAC,gCAAe,EAAC;MAC1CP,GAAG,EAAEtB,OAAO,CAACsB,GAAG;MAChBQ,QAAQ,EAAE9B,OAAO,CAAC8B,QAAQ;MAC1Bf,OAAO;MACPM;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACU,OAAA,CAAAlC,gCAAA,GAAAA,gCAAA","ignoreList":[]}
1
+ {"version":3,"names":["_index","require","_SchedulerService","_manifest","_utils","_createScheduler","_handlerGraphql","_constants","_apiHeadlessCms","_index2","createHeadlessCmsScheduleContext","params","ContextPlugin","context","ready","isHeadlessCmsReady","manifest","getManifest","client","db","driver","getClient","error","console","message","log","convertException","info","service","createSchedulerService","config","lambdaArn","data","roleArn","schedulerModel","cms","getModel","SCHEDULE_MODEL_ID","ex","code","NotFoundError","attachLifecycleHooks","scheduler","createScheduler","security","exports"],"sources":["context.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api/index.js\";\nimport type {\n SchedulerClient,\n SchedulerClientConfig\n} from \"@webiny/aws-sdk/client-scheduler/index.js\";\nimport { createSchedulerService } from \"~/service/SchedulerService.js\";\nimport { getManifest } from \"~/manifest.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { ScheduleContext } from \"~/types.js\";\nimport { createScheduler } from \"./scheduler/createScheduler.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { SCHEDULE_MODEL_ID } from \"./constants.js\";\nimport { isHeadlessCmsReady } from \"@webiny/api-headless-cms\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { attachLifecycleHooks } from \"~/hooks/index.js\";\n\nexport interface ICreateHeadlessCmsSchedulerContextParams {\n getClient(config?: SchedulerClientConfig): Pick<SchedulerClient, \"send\">;\n}\n\nexport const createHeadlessCmsScheduleContext = (\n params: ICreateHeadlessCmsSchedulerContextParams\n) => {\n return new ContextPlugin<ScheduleContext>(async context => {\n /**\n * If the Headless CMS is not ready, it means the system is not fully installed yet.\n * We do not want to continue because it would break anyway.\n */\n const ready = await isHeadlessCmsReady(context);\n if (!ready) {\n return;\n }\n const manifest = await getManifest({\n client: context.db.driver.getClient() as DynamoDBDocument\n });\n if (manifest.error) {\n console.error(manifest.error.message);\n console.log(convertException(manifest.error, [\"message\"]));\n console.info(\"Scheduler not attached.\");\n return;\n }\n\n const service = createSchedulerService({\n getClient: params.getClient,\n config: {\n lambdaArn: manifest.data.lambdaArn,\n roleArn: manifest.data.roleArn\n }\n });\n\n let schedulerModel: CmsModel;\n try {\n schedulerModel = await context.cms.getModel(SCHEDULE_MODEL_ID);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n console.error(`Schedule model \"${SCHEDULE_MODEL_ID}\" not found.`);\n return;\n }\n console.error(`Error while fetching schedule model \"${SCHEDULE_MODEL_ID}\".`);\n console.log(convertException(ex));\n return;\n }\n\n attachLifecycleHooks({\n cms: context.cms,\n schedulerModel\n });\n\n context.cms.scheduler = await createScheduler({\n cms: context.cms,\n security: context.security,\n service,\n schedulerModel\n });\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAJ,OAAA;AAEA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AAEA,IAAAQ,OAAA,GAAAR,OAAA;AAMO,MAAMS,gCAAgC,GACzCC,MAAgD,IAC/C;EACD,OAAO,IAAIC,oBAAa,CAAkB,MAAMC,OAAO,IAAI;IACvD;AACR;AACA;AACA;IACQ,MAAMC,KAAK,GAAG,MAAM,IAAAC,kCAAkB,EAACF,OAAO,CAAC;IAC/C,IAAI,CAACC,KAAK,EAAE;MACR;IACJ;IACA,MAAME,QAAQ,GAAG,MAAM,IAAAC,qBAAW,EAAC;MAC/BC,MAAM,EAAEL,OAAO,CAACM,EAAE,CAACC,MAAM,CAACC,SAAS,CAAC;IACxC,CAAC,CAAC;IACF,IAAIL,QAAQ,CAACM,KAAK,EAAE;MAChBC,OAAO,CAACD,KAAK,CAACN,QAAQ,CAACM,KAAK,CAACE,OAAO,CAAC;MACrCD,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACV,QAAQ,CAACM,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;MAC1DC,OAAO,CAACI,IAAI,CAAC,yBAAyB,CAAC;MACvC;IACJ;IAEA,MAAMC,OAAO,GAAG,IAAAC,wCAAsB,EAAC;MACnCR,SAAS,EAAEV,MAAM,CAACU,SAAS;MAC3BS,MAAM,EAAE;QACJC,SAAS,EAAEf,QAAQ,CAACgB,IAAI,CAACD,SAAS;QAClCE,OAAO,EAAEjB,QAAQ,CAACgB,IAAI,CAACC;MAC3B;IACJ,CAAC,CAAC;IAEF,IAAIC,cAAwB;IAC5B,IAAI;MACAA,cAAc,GAAG,MAAMrB,OAAO,CAACsB,GAAG,CAACC,QAAQ,CAACC,4BAAiB,CAAC;IAClE,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,IAAIA,EAAE,CAACC,IAAI,KAAK,WAAW,IAAID,EAAE,YAAYE,6BAAa,EAAE;QACxDjB,OAAO,CAACD,KAAK,CAAC,mBAAmBe,4BAAiB,cAAc,CAAC;QACjE;MACJ;MACAd,OAAO,CAACD,KAAK,CAAC,wCAAwCe,4BAAiB,IAAI,CAAC;MAC5Ed,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACY,EAAE,CAAC,CAAC;MACjC;IACJ;IAEA,IAAAG,4BAAoB,EAAC;MACjBN,GAAG,EAAEtB,OAAO,CAACsB,GAAG;MAChBD;IACJ,CAAC,CAAC;IAEFrB,OAAO,CAACsB,GAAG,CAACO,SAAS,GAAG,MAAM,IAAAC,gCAAe,EAAC;MAC1CR,GAAG,EAAEtB,OAAO,CAACsB,GAAG;MAChBS,QAAQ,EAAE/B,OAAO,CAAC+B,QAAQ;MAC1BhB,OAAO;MACPM;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACW,OAAA,CAAAnC,gCAAA,GAAAA,gCAAA","ignoreList":[]}
@@ -49,6 +49,7 @@ export declare const listScheduleSchema: zod.ZodObject<{
49
49
  }, "strip", zod.ZodTypeAny, {
50
50
  modelId: string;
51
51
  sort?: (`${string}_ASC` | `${string}_DESC`)[] | undefined;
52
+ limit?: number | undefined;
52
53
  after?: string | undefined;
53
54
  where?: {
54
55
  type?: ScheduleType | undefined;
@@ -61,10 +62,10 @@ export declare const listScheduleSchema: zod.ZodObject<{
61
62
  title_contains?: string | undefined;
62
63
  title_not_contains?: string | undefined;
63
64
  } | undefined;
64
- limit?: number | undefined;
65
65
  }, {
66
66
  modelId: string;
67
67
  sort?: string[] | undefined;
68
+ limit?: number | undefined;
68
69
  after?: string | undefined;
69
70
  where?: {
70
71
  type?: ScheduleType | undefined;
@@ -77,7 +78,6 @@ export declare const listScheduleSchema: zod.ZodObject<{
77
78
  title_contains?: string | undefined;
78
79
  title_not_contains?: string | undefined;
79
80
  } | undefined;
80
- limit?: number | undefined;
81
81
  }>;
82
82
  export declare const createScheduleSchema: zod.ZodObject<{
83
83
  modelId: zod.ZodString;
@@ -114,6 +114,7 @@ export declare const createScheduleSchema: zod.ZodObject<{
114
114
  dateOn?: Date | undefined;
115
115
  }>]>;
116
116
  }, "strip", zod.ZodTypeAny, {
117
+ id: string;
117
118
  input: {
118
119
  type: ScheduleType;
119
120
  immediately: true;
@@ -125,9 +126,9 @@ export declare const createScheduleSchema: zod.ZodObject<{
125
126
  immediately?: false | undefined;
126
127
  dateOn?: Date | undefined;
127
128
  };
128
- id: string;
129
129
  modelId: string;
130
130
  }, {
131
+ id: string;
131
132
  input: {
132
133
  type: ScheduleType;
133
134
  immediately: true;
@@ -139,7 +140,6 @@ export declare const createScheduleSchema: zod.ZodObject<{
139
140
  immediately?: false | undefined;
140
141
  dateOn?: Date | undefined;
141
142
  };
142
- id: string;
143
143
  modelId: string;
144
144
  }>;
145
145
  export declare const updateScheduleSchema: zod.ZodObject<{
@@ -177,6 +177,7 @@ export declare const updateScheduleSchema: zod.ZodObject<{
177
177
  dateOn?: Date | undefined;
178
178
  }>]>;
179
179
  }, "strip", zod.ZodTypeAny, {
180
+ id: string;
180
181
  input: {
181
182
  type: ScheduleType;
182
183
  immediately: true;
@@ -188,9 +189,9 @@ export declare const updateScheduleSchema: zod.ZodObject<{
188
189
  immediately?: false | undefined;
189
190
  dateOn?: Date | undefined;
190
191
  };
191
- id: string;
192
192
  modelId: string;
193
193
  }, {
194
+ id: string;
194
195
  input: {
195
196
  type: ScheduleType;
196
197
  immediately: true;
@@ -202,7 +203,6 @@ export declare const updateScheduleSchema: zod.ZodObject<{
202
203
  immediately?: false | undefined;
203
204
  dateOn?: Date | undefined;
204
205
  };
205
- id: string;
206
206
  modelId: string;
207
207
  }>;
208
208
  export declare const cancelScheduleSchema: zod.ZodObject<{
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,58 @@
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
@@ -0,0 +1 @@
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/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export interface ICreateHeadlessCmsScheduleParams extends ICreateHeadlessCmsSche
7
7
  * * Handler plugin will handle the scheduled CMS action event - a lambda call from the EventBridge Scheduler.
8
8
  * * API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.
9
9
  */
10
- export declare const createHeadlessCmsSchedule: (params: ICreateHeadlessCmsScheduleParams) => Plugin[];
10
+ export declare const createHeadlessCmsScheduler: (params: ICreateHeadlessCmsScheduleParams) => Plugin[];
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createHeadlessCmsSchedule = void 0;
6
+ exports.createHeadlessCmsScheduler = void 0;
7
7
  var _context = require("./context.js");
8
8
  var _model = require("./scheduler/model.js");
9
9
  var _index = require("./graphql/index.js");
@@ -13,7 +13,7 @@ var _index2 = require("./handler/index.js");
13
13
  * * Handler plugin will handle the scheduled CMS action event - a lambda call from the EventBridge Scheduler.
14
14
  * * API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.
15
15
  */
16
- const createHeadlessCmsSchedule = params => {
16
+ const createHeadlessCmsScheduler = params => {
17
17
  return [
18
18
  /**
19
19
  * Handler for the Scheduled CMS Action Event.
@@ -24,6 +24,6 @@ const createHeadlessCmsSchedule = params => {
24
24
  */
25
25
  (0, _model.createSchedulerModel)(), (0, _context.createHeadlessCmsScheduleContext)(params), (0, _index.createSchedulerGraphQL)()];
26
26
  };
27
- exports.createHeadlessCmsSchedule = createHeadlessCmsSchedule;
27
+ exports.createHeadlessCmsScheduler = createHeadlessCmsScheduler;
28
28
 
29
29
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_context","require","_model","_index","_index2","createHeadlessCmsSchedule","params","createScheduledCmsActionEventHandler","createSchedulerModel","createHeadlessCmsScheduleContext","createSchedulerGraphQL","exports"],"sources":["index.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { ICreateHeadlessCmsSchedulerContextParams } from \"~/context.js\";\nimport { createHeadlessCmsScheduleContext } from \"~/context.js\";\nimport { createSchedulerModel } from \"~/scheduler/model.js\";\nimport { createSchedulerGraphQL } from \"~/graphql/index.js\";\nimport { createScheduledCmsActionEventHandler } from \"~/handler/index.js\";\n\nexport interface ICreateHeadlessCmsScheduleParams extends ICreateHeadlessCmsSchedulerContextParams {\n //\n}\n\n/**\n * This will register both API and Handler plugins for the Headless CMS Scheduler.\n * * Handler plugin will handle the scheduled CMS action event - a lambda call from the EventBridge Scheduler.\n * * API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.\n */\nexport const createHeadlessCmsSchedule = (params: ICreateHeadlessCmsScheduleParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled CMS Action Event.\n */\n createScheduledCmsActionEventHandler(),\n /**\n * API side of the scheduler.\n */\n createSchedulerModel(),\n createHeadlessCmsScheduleContext(params),\n createSchedulerGraphQL()\n ];\n};\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAMA;AACA;AACA;AACA;AACA;AACO,MAAMI,yBAAyB,GAAIC,MAAwC,IAAe;EAC7F,OAAO;EACH;AACR;AACA;EACQ,IAAAC,4CAAoC,EAAC,CAAC;EACtC;AACR;AACA;EACQ,IAAAC,2BAAoB,EAAC,CAAC,EACtB,IAAAC,yCAAgC,EAACH,MAAM,CAAC,EACxC,IAAAI,6BAAsB,EAAC,CAAC,CAC3B;AACL,CAAC;AAACC,OAAA,CAAAN,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_context","require","_model","_index","_index2","createHeadlessCmsScheduler","params","createScheduledCmsActionEventHandler","createSchedulerModel","createHeadlessCmsScheduleContext","createSchedulerGraphQL","exports"],"sources":["index.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { ICreateHeadlessCmsSchedulerContextParams } from \"~/context.js\";\nimport { createHeadlessCmsScheduleContext } from \"~/context.js\";\nimport { createSchedulerModel } from \"~/scheduler/model.js\";\nimport { createSchedulerGraphQL } from \"~/graphql/index.js\";\nimport { createScheduledCmsActionEventHandler } from \"~/handler/index.js\";\n\nexport interface ICreateHeadlessCmsScheduleParams extends ICreateHeadlessCmsSchedulerContextParams {\n //\n}\n\n/**\n * This will register both API and Handler plugins for the Headless CMS Scheduler.\n * * Handler plugin will handle the scheduled CMS action event - a lambda call from the EventBridge Scheduler.\n * * API plugin will provide the GraphQL API and code for managing the scheduled CMS actions.\n */\nexport const createHeadlessCmsScheduler = (params: ICreateHeadlessCmsScheduleParams): Plugin[] => {\n return [\n /**\n * Handler for the Scheduled CMS Action Event.\n */\n createScheduledCmsActionEventHandler(),\n /**\n * API side of the scheduler.\n */\n createSchedulerModel(),\n createHeadlessCmsScheduleContext(params),\n createSchedulerGraphQL()\n ];\n};\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAMA;AACA;AACA;AACA;AACA;AACO,MAAMI,0BAA0B,GAAIC,MAAwC,IAAe;EAC9F,OAAO;EACH;AACR;AACA;EACQ,IAAAC,4CAAoC,EAAC,CAAC;EACtC;AACR;AACA;EACQ,IAAAC,2BAAoB,EAAC,CAAC,EACtB,IAAAC,yCAAgC,EAACH,MAAM,CAAC,EACxC,IAAAI,6BAAsB,EAAC,CAAC,CAC3B;AACL,CAAC;AAACC,OAAA,CAAAN,0BAAA,GAAAA,0BAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-scheduler",
3
- "version": "0.0.0-unstable.fdd9228b5d",
3
+ "version": "6.0.0-alpha.2",
4
4
  "main": "index.js",
5
5
  "description": "Schedule for Webiny Headless CMS",
6
6
  "keywords": [
@@ -13,23 +13,23 @@
13
13
  },
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@webiny/api": "0.0.0-unstable.fdd9228b5d",
17
- "@webiny/api-headless-cms": "0.0.0-unstable.fdd9228b5d",
18
- "@webiny/aws-sdk": "0.0.0-unstable.fdd9228b5d",
19
- "@webiny/error": "0.0.0-unstable.fdd9228b5d",
20
- "@webiny/handler-graphql": "0.0.0-unstable.fdd9228b5d",
21
- "@webiny/utils": "0.0.0-unstable.fdd9228b5d",
16
+ "@webiny/api": "6.0.0-alpha.2",
17
+ "@webiny/api-headless-cms": "6.0.0-alpha.2",
18
+ "@webiny/aws-sdk": "6.0.0-alpha.2",
19
+ "@webiny/error": "6.0.0-alpha.2",
20
+ "@webiny/handler-graphql": "6.0.0-alpha.2",
21
+ "@webiny/utils": "6.0.0-alpha.2",
22
22
  "zod": "3.23.8"
23
23
  },
24
24
  "devDependencies": {
25
- "@webiny/api-i18n": "0.0.0-unstable.fdd9228b5d",
26
- "@webiny/api-security": "0.0.0-unstable.fdd9228b5d",
27
- "@webiny/api-tenancy": "0.0.0-unstable.fdd9228b5d",
28
- "@webiny/api-wcp": "0.0.0-unstable.fdd9228b5d",
29
- "@webiny/handler": "0.0.0-unstable.fdd9228b5d",
30
- "@webiny/handler-aws": "0.0.0-unstable.fdd9228b5d",
31
- "@webiny/plugins": "0.0.0-unstable.fdd9228b5d",
32
- "@webiny/project-utils": "0.0.0-unstable.fdd9228b5d",
25
+ "@webiny/api-i18n": "6.0.0-alpha.2",
26
+ "@webiny/api-security": "6.0.0-alpha.2",
27
+ "@webiny/api-tenancy": "6.0.0-alpha.2",
28
+ "@webiny/api-wcp": "6.0.0-alpha.2",
29
+ "@webiny/handler": "6.0.0-alpha.2",
30
+ "@webiny/handler-aws": "6.0.0-alpha.2",
31
+ "@webiny/plugins": "6.0.0-alpha.2",
32
+ "@webiny/project-utils": "6.0.0-alpha.2",
33
33
  "aws-sdk-client-mock": "4.1.0",
34
34
  "typescript": "5.3.3"
35
35
  },
@@ -41,5 +41,5 @@
41
41
  "access": "public",
42
42
  "directory": "dist"
43
43
  },
44
- "gitHead": "fdd9228b5d2636463e8a34b6e0d26eea1e29c01d"
44
+ "gitHead": "7c9e8fbfd62a57ece5f880dbad6c864636b0355e"
45
45
  }
@@ -4,12 +4,12 @@ export type ScheduleFetcherCms = Pick<HeadlessCms, "getEntryById" | "listLatestE
4
4
  export interface IScheduleFetcherParams {
5
5
  cms: ScheduleFetcherCms;
6
6
  targetModel: CmsModel;
7
- scheduleModel: CmsModel;
7
+ schedulerModel: CmsModel;
8
8
  }
9
9
  export declare class ScheduleFetcher implements IScheduleFetcher {
10
10
  private readonly cms;
11
11
  private readonly targetModel;
12
- private readonly scheduleModel;
12
+ private readonly schedulerModel;
13
13
  constructor(params: IScheduleFetcherParams);
14
14
  getScheduled(targetId: string): Promise<IScheduleRecord | null>;
15
15
  listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;
@@ -11,13 +11,13 @@ var _utils = require("@webiny/utils");
11
11
  class ScheduleFetcher {
12
12
  constructor(params) {
13
13
  this.cms = params.cms;
14
- this.scheduleModel = params.scheduleModel;
14
+ this.schedulerModel = params.schedulerModel;
15
15
  this.targetModel = params.targetModel;
16
16
  }
17
17
  async getScheduled(targetId) {
18
18
  const scheduleRecordId = (0, _createScheduleRecordId.createScheduleRecordIdWithVersion)(targetId);
19
19
  try {
20
- const entry = await this.cms.getEntryById(this.scheduleModel, scheduleRecordId);
20
+ const entry = await this.cms.getEntryById(this.schedulerModel, scheduleRecordId);
21
21
  return (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, entry);
22
22
  } catch (ex) {
23
23
  if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
@@ -29,7 +29,7 @@ class ScheduleFetcher {
29
29
  }
30
30
  }
31
31
  async listScheduled(params) {
32
- const [data, meta] = await this.cms.listLatestEntries(this.scheduleModel, {
32
+ const [data, meta] = await this.cms.listLatestEntries(this.schedulerModel, {
33
33
  sort: params.sort,
34
34
  limit: params.limit,
35
35
  /**
@@ -1 +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":[]}
1
+ {"version":3,"names":["_handlerGraphql","require","_createScheduleRecordId","_ScheduleRecord","_utils","ScheduleFetcher","constructor","params","cms","schedulerModel","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 schedulerModel: CmsModel;\n}\n\nexport class ScheduleFetcher implements IScheduleFetcher {\n private readonly cms: ScheduleFetcherCms;\n private readonly targetModel: CmsModel;\n private readonly schedulerModel: CmsModel;\n\n constructor(params: IScheduleFetcherParams) {\n this.cms = params.cms;\n this.schedulerModel = params.schedulerModel;\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.schedulerModel,\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.schedulerModel,\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,cAAc,GAAGF,MAAM,CAACE,cAAc;IAC3C,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,cAAc,EACnBI,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,cAAc,EACnB;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":[]}
@@ -1,4 +1,4 @@
1
- import { type DateOnType, type IScheduleEntryValues, type IScheduleRecord, type ScheduledOnType, ScheduleType } from "./types.js";
1
+ import { type IScheduleEntryValues, type IScheduleRecord, type ScheduledOnType, ScheduleType } from "./types.js";
2
2
  import type { CmsEntry, CmsIdentity, CmsModel } from "@webiny/api-headless-cms/types/index.js";
3
3
  export interface IScheduleRecordParams {
4
4
  id: string;
@@ -13,7 +13,6 @@ export interface IScheduleRecordParams {
13
13
  * The date when the action is to be set as done.
14
14
  * User can set publishedOn (and other relevant dates) with this parameter.
15
15
  */
16
- dateOn: DateOnType | undefined;
17
16
  type: ScheduleType;
18
17
  title: string;
19
18
  }
@@ -24,7 +23,6 @@ export declare class ScheduleRecord implements IScheduleRecord {
24
23
  readonly scheduledBy: CmsIdentity;
25
24
  readonly publishOn: ScheduledOnType | undefined;
26
25
  readonly unpublishOn: ScheduledOnType | undefined;
27
- readonly dateOn: DateOnType | undefined;
28
26
  readonly type: ScheduleType;
29
27
  readonly title: string;
30
28
  constructor(record: IScheduleRecordParams);
@@ -6,14 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.transformScheduleEntry = exports.createScheduleRecord = exports.ScheduleRecord = void 0;
7
7
  var _types = require("./types.js");
8
8
  var _error = require("@webiny/error");
9
- var _dates = require("./dates.js");
10
9
  class ScheduleRecord {
10
+ // public readonly dateOn: DateOnType | undefined;
11
+
11
12
  constructor(record) {
12
13
  this.id = record.id;
13
14
  this.targetId = record.targetId;
14
15
  this.model = record.model;
15
16
  this.scheduledBy = record.scheduledBy;
16
- this.dateOn = record.dateOn;
17
+ // this.dateOn = record.dateOn;
17
18
  this.publishOn = record.type === _types.ScheduleType.publish ? record.scheduledOn : undefined;
18
19
  this.unpublishOn = record.type === _types.ScheduleType.unpublish ? record.scheduledOn : undefined;
19
20
  this.type = record.type;
@@ -46,7 +47,7 @@ const transformScheduleEntry = (targetModel, entry) => {
46
47
  title: entry.values.title,
47
48
  targetId: entry.values.targetId,
48
49
  scheduledOn: new Date(entry.values.scheduledOn),
49
- dateOn: (0, _dates.isoStringToDate)(entry.values.dateOn),
50
+ // dateOn: isoStringToDate(entry.values.dateOn),
50
51
  scheduledBy: entry.savedBy,
51
52
  model: targetModel
52
53
  });
@@ -1 +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":[]}
1
+ {"version":3,"names":["_types","require","_error","ScheduleRecord","constructor","record","id","targetId","model","scheduledBy","publishOn","type","ScheduleType","publish","scheduledOn","undefined","unpublishOn","unpublish","title","exports","createScheduleRecord","transformScheduleEntry","targetModel","entry","values","WebinyError","Date","savedBy"],"sources":["ScheduleRecord.ts"],"sourcesContent":["import {\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\";\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;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAoBO,MAAME,cAAc,CAA4B;EAOnD;;EAIOC,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;IACA,IAAI,CAACC,SAAS,GAAGL,MAAM,CAACM,IAAI,KAAKC,mBAAY,CAACC,OAAO,GAAGR,MAAM,CAACS,WAAW,GAAGC,SAAS;IACtF,IAAI,CAACC,WAAW,GAAGX,MAAM,CAACM,IAAI,KAAKC,mBAAY,CAACK,SAAS,GAAGZ,MAAM,CAACS,WAAW,GAAGC,SAAS;IAC1F,IAAI,CAACJ,IAAI,GAAGN,MAAM,CAACM,IAAI;IACvB,IAAI,CAACO,KAAK,GAAGb,MAAM,CAACa,KAAK;EAC7B;AACJ;AAACC,OAAA,CAAAhB,cAAA,GAAAA,cAAA;AAEM,MAAMiB,oBAAoB,GAAIf,MAA6B,IAAsB;EACpF,OAAO,IAAIF,cAAc,CAACE,MAAM,CAAC;AACrC,CAAC;AAACc,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;IACxBd,EAAE,EAAEiB,KAAK,CAACjB,EAAE;IACZK,IAAI;IACJO,KAAK,EAAEK,KAAK,CAACC,MAAM,CAACN,KAAK;IACzBX,QAAQ,EAAEgB,KAAK,CAACC,MAAM,CAACjB,QAAQ;IAC/BO,WAAW,EAAE,IAAIY,IAAI,CAACH,KAAK,CAACC,MAAM,CAACV,WAAW,CAAC;IAC/C;IACAL,WAAW,EAAEc,KAAK,CAACI,OAAO;IAC1BnB,KAAK,EAAEc;EACX,CAAC,CAAC;AACN,CAAC;AAACH,OAAA,CAAAE,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -1 +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":[]}
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 public 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;EAIlCC,WAAWA,CAACC,MAAwB,EAAE;IACzC,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":[]}
@@ -6,7 +6,7 @@ export interface IPublishScheduleActionParams {
6
6
  service: ISchedulerService;
7
7
  cms: PublishScheduleActionCms;
8
8
  targetModel: CmsModel;
9
- scheduleModel: CmsModel;
9
+ schedulerModel: CmsModel;
10
10
  getIdentity: () => CmsIdentity;
11
11
  fetcher: IScheduleFetcher;
12
12
  }
@@ -14,7 +14,7 @@ export declare class PublishScheduleAction implements IScheduleAction {
14
14
  private readonly service;
15
15
  private readonly cms;
16
16
  private readonly targetModel;
17
- private readonly scheduleModel;
17
+ private readonly schedulerModel;
18
18
  private readonly getIdentity;
19
19
  private readonly fetcher;
20
20
  constructor(params: IPublishScheduleActionParams);
@@ -22,5 +22,5 @@ export declare class PublishScheduleAction implements IScheduleAction {
22
22
  schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;
23
23
  reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;
24
24
  cancel(id: string): Promise<void>;
25
- private getUpdateableTargetEntry;
25
+ private getTargetEntry;
26
26
  }
@@ -10,14 +10,13 @@ var _utils = require("@webiny/utils");
10
10
  var _dates = require("../dates.js");
11
11
  var _handlerGraphql = require("@webiny/handler-graphql");
12
12
  var _dateInTheFuture = require("../../utils/dateInTheFuture.js");
13
- var _index = require("@webiny/error/index");
14
13
  var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
15
14
  class PublishScheduleAction {
16
15
  constructor(params) {
17
16
  this.service = params.service;
18
17
  this.cms = params.cms;
19
18
  this.targetModel = params.targetModel;
20
- this.scheduleModel = params.scheduleModel;
19
+ this.schedulerModel = params.schedulerModel;
21
20
  this.getIdentity = params.getIdentity;
22
21
  this.fetcher = params.fetcher;
23
22
  }
@@ -30,7 +29,7 @@ class PublishScheduleAction {
30
29
  input,
31
30
  scheduleRecordId
32
31
  } = params;
33
- const targetEntry = await this.getUpdateableTargetEntry(targetId);
32
+ const targetEntry = await this.getTargetEntry(targetId);
34
33
  const title = targetEntry.values[this.targetModel.titleFieldId] || "Unknown entry title";
35
34
  const identity = this.getIdentity();
36
35
  const currentDate = new Date();
@@ -46,7 +45,7 @@ class PublishScheduleAction {
46
45
  model: this.targetModel,
47
46
  scheduledBy: publishedEntry.savedBy,
48
47
  scheduledOn: new Date(publishedEntry.savedOn),
49
- dateOn: currentDate,
48
+ // dateOn: currentDate,
50
49
  type: _types.ScheduleType.publish,
51
50
  title
52
51
  });
@@ -73,7 +72,6 @@ class PublishScheduleAction {
73
72
  model: this.targetModel,
74
73
  scheduledBy: publishedEntry.savedBy,
75
74
  scheduledOn: currentDate,
76
- dateOn: input.dateOn,
77
75
  type: _types.ScheduleType.publish,
78
76
  title
79
77
  });
@@ -81,14 +79,13 @@ class PublishScheduleAction {
81
79
  const {
82
80
  id: scheduleEntryId
83
81
  } = (0, _parseIdentifier.parseIdentifier)(scheduleRecordId);
84
- const scheduleEntry = await this.cms.createEntry(this.scheduleModel, {
82
+ const scheduleEntry = await this.cms.createEntry(this.schedulerModel, {
85
83
  id: scheduleEntryId,
86
84
  targetId,
87
85
  targetModelId: this.targetModel.modelId,
88
86
  title,
89
87
  type: _types.ScheduleType.publish,
90
88
  scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
91
- dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined,
92
89
  scheduledBy: identity
93
90
  });
94
91
  try {
@@ -100,7 +97,7 @@ class PublishScheduleAction {
100
97
  console.error(`Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`);
101
98
  console.log((0, _utils.convertException)(ex));
102
99
  try {
103
- await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);
100
+ await this.cms.deleteEntry(this.schedulerModel, scheduleRecordId);
104
101
  } catch (err) {
105
102
  console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);
106
103
  console.log((0, _utils.convertException)(err));
@@ -113,7 +110,7 @@ class PublishScheduleAction {
113
110
  async reschedule(original, input) {
114
111
  const currentDate = new Date();
115
112
  const targetId = original.targetId;
116
- const targetEntry = await this.getUpdateableTargetEntry(targetId);
113
+ const targetEntry = await this.getTargetEntry(targetId);
117
114
 
118
115
  /**
119
116
  * There are two cases when we can immediately publish the entry:
@@ -121,11 +118,7 @@ class PublishScheduleAction {
121
118
  * 2. If the entry is scheduled for a date in the past.
122
119
  */
123
120
  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);
121
+ await this.cms.publishEntry(this.targetModel, targetEntry.id);
129
122
  /**
130
123
  * We can safely cancel the original schedule entry and the event.
131
124
  *
@@ -139,14 +132,15 @@ class PublishScheduleAction {
139
132
  return {
140
133
  ...original,
141
134
  publishOn: currentDate,
142
- unpublishOn: undefined,
143
- dateOn: publishedEntry.lastPublishedOn ? new Date(publishedEntry.lastPublishedOn) : undefined
135
+ unpublishOn: undefined
136
+ // dateOn: publishedEntry.lastPublishedOn
137
+ // ? new Date(publishedEntry.lastPublishedOn)
138
+ // : undefined
144
139
  };
145
140
  }
146
- await this.cms.updateEntry(this.scheduleModel, original.id, {
141
+ await this.cms.updateEntry(this.schedulerModel, original.id, {
147
142
  scheduledBy: this.getIdentity(),
148
- scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
149
- dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined
143
+ scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn)
150
144
  });
151
145
  try {
152
146
  await this.service.update({
@@ -159,8 +153,7 @@ class PublishScheduleAction {
159
153
  return {
160
154
  ...original,
161
155
  publishOn: new Date(),
162
- unpublishOn: undefined,
163
- dateOn: input.dateOn
156
+ unpublishOn: undefined
164
157
  };
165
158
  }
166
159
  async cancel(id) {
@@ -177,7 +170,7 @@ class PublishScheduleAction {
177
170
  return;
178
171
  }
179
172
  try {
180
- await this.cms.deleteEntry(this.scheduleModel, scheduleEntry.id);
173
+ await this.cms.deleteEntry(this.schedulerModel, scheduleEntry.id);
181
174
  } catch (ex) {
182
175
  if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
183
176
  return;
@@ -194,14 +187,8 @@ class PublishScheduleAction {
194
187
  throw ex;
195
188
  }
196
189
  }
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;
190
+ async getTargetEntry(id) {
191
+ return await this.cms.getEntryById(this.targetModel, id);
205
192
  }
206
193
  }
207
194
  exports.PublishScheduleAction = PublishScheduleAction;
@@ -1 +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;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAgBO,MAAMQ,qBAAqB,CAA4B;EAQnDC,WAAWA,CAACC,MAAoC,EAAE;IACrD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,GAAG,GAAGF,MAAM,CAACE,GAAG;IACrB,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;IACrC,IAAI,CAACC,aAAa,GAAGJ,MAAM,CAACI,aAAa;IACzC,IAAI,CAACC,WAAW,GAAGL,MAAM,CAACK,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGN,MAAM,CAACM,OAAO;EACjC;EAEOC,SAASA,CAACC,KAAsB,EAAW;IAC9C,OAAOA,KAAK,CAACC,IAAI,KAAKC,mBAAY,CAACC,OAAO;EAC9C;EAEA,MAAaC,QAAQA,CAACZ,MAAqC,EAA4B;IACnF,MAAM;MAAEa,QAAQ;MAAEL,KAAK;MAAEM;IAAiB,CAAC,GAAGd,MAAM;IAEpD,MAAMe,WAAW,GAAG,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;IACJ;IAEA,IAAI;MACA,MAAM,IAAI,CAAC1C,GAAG,CAACqD,WAAW,CAAC,IAAI,CAACnD,aAAa,EAAEwC,aAAa,CAACjB,EAAE,CAAC;IACpE,CAAC,CAAC,OAAOuB,EAAE,EAAE;MACT,IAAIA,EAAE,CAACiB,IAAI,KAAK,WAAW,IAAIjB,EAAE,YAAYkB,6BAAa,EAAE;QACxD;MACJ;MACAjB,OAAO,CAACC,KAAK,CAAC,wCAAwCR,aAAa,CAACjB,EAAE,GAAG,CAAC;MAC1EwB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,IAAI;MACA,MAAM,IAAI,CAACjD,OAAO,CAACoE,MAAM,CAACzB,aAAa,CAACjB,EAAE,CAAC;IAC/C,CAAC,CAAC,OAAOuB,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,0DAA0DR,aAAa,CAACjB,EAAE,GAC9E,CAAC;MACDwB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;EACJ;EAEA,MAAclC,wBAAwBA,CAAqBW,EAAU,EAAwB;IACzF,MAAM2C,KAAK,GAAG,MAAM,IAAI,CAACpE,GAAG,CAACqE,YAAY,CAAI,IAAI,CAACpE,WAAW,EAAEwB,EAAE,CAAC;IAClE,IAAI2C,KAAK,CAACE,MAAM,EAAE;MACd,MAAM,IAAIC,kBAAW,CACjB,+CAA+CH,KAAK,CAAC3C,EAAE,yBAAyB,EAChF,cAAc,EACd;QACI+C,OAAO,EAAEJ,KAAK,CAAC3C;MACnB,CACJ,CAAC;IACL;IACA,OAAO2C,KAAK;EAChB;AACJ;AAACK,OAAA,CAAA7E,qBAAA,GAAAA,qBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_types","require","_ScheduleRecord","_utils","_dates","_handlerGraphql","_dateInTheFuture","_parseIdentifier","PublishScheduleAction","constructor","params","service","cms","targetModel","schedulerModel","getIdentity","fetcher","canHandle","input","type","ScheduleType","publish","schedule","targetId","scheduleRecordId","targetEntry","getTargetEntry","title","values","titleFieldId","identity","currentDate","Date","immediately","publishedEntry","publishEntry","createScheduleRecord","id","model","scheduledBy","savedBy","scheduledOn","savedOn","dateInTheFuture","scheduleOn","updateEntry","firstPublishedBy","firstPublishedOn","dateToISOString","lastPublishedOn","lastPublishedBy","scheduleEntryId","parseIdentifier","scheduleEntry","createEntry","targetModelId","modelId","create","ex","console","error","log","convertException","deleteEntry","err","transformScheduleEntry","reschedule","original","cancel","publishOn","unpublishOn","undefined","update","getScheduled","code","NotFoundError","delete","getEntryById","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 { 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 schedulerModel: 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 schedulerModel: 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.schedulerModel = params.schedulerModel;\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.getTargetEntry(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 type: ScheduleType.publish,\n title\n });\n }\n\n const { id: scheduleEntryId } = parseIdentifier(scheduleRecordId);\n const scheduleEntry = await this.cms.createEntry<IScheduleEntryValues>(\n this.schedulerModel,\n {\n id: scheduleEntryId,\n targetId,\n targetModelId: this.targetModel.modelId,\n title,\n type: ScheduleType.publish,\n scheduledOn: dateToISOString(input.scheduleOn),\n scheduledBy: identity\n }\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.schedulerModel, 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.getTargetEntry(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 await this.cms.publishEntry(this.targetModel, targetEntry.id);\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<Pick<IScheduleEntryValues, \"scheduledOn\" | \"scheduledBy\">>(\n this.schedulerModel,\n original.id,\n {\n scheduledBy: this.getIdentity(),\n scheduledOn: dateToISOString(input.scheduleOn)\n }\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 };\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.schedulerModel, 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 getTargetEntry<T = CmsEntryValues>(id: string): Promise<CmsEntry<T>> {\n return await this.cms.getEntryById<T>(this.targetModel, id);\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;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AAgBO,MAAMO,qBAAqB,CAA4B;EAQnDC,WAAWA,CAACC,MAAoC,EAAE;IACrD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,GAAG,GAAGF,MAAM,CAACE,GAAG;IACrB,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;IACrC,IAAI,CAACC,cAAc,GAAGJ,MAAM,CAACI,cAAc;IAC3C,IAAI,CAACC,WAAW,GAAGL,MAAM,CAACK,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGN,MAAM,CAACM,OAAO;EACjC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ChB,EAAE,CAAC;IAC/C,CAAC,CAAC,OAAOqB,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,0DAA0DP,aAAa,CAAChB,EAAE,GAC9E,CAAC;MACDsB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;EACJ;EAEA,MAAchC,cAAcA,CAAqBW,EAAU,EAAwB;IAC/E,OAAO,MAAM,IAAI,CAACzB,GAAG,CAACiE,YAAY,CAAI,IAAI,CAAChE,WAAW,EAAEwB,EAAE,CAAC;EAC/D;AACJ;AAACyC,OAAA,CAAAtE,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -6,7 +6,7 @@ export interface IUnpublishScheduleActionParams {
6
6
  service: ISchedulerService;
7
7
  cms: UnpublishScheduleActionCms;
8
8
  targetModel: CmsModel;
9
- scheduleModel: CmsModel;
9
+ schedulerModel: CmsModel;
10
10
  getIdentity: () => CmsIdentity;
11
11
  fetcher: IScheduleFetcher;
12
12
  }
@@ -14,7 +14,7 @@ export declare class UnpublishScheduleAction implements IScheduleAction {
14
14
  private readonly service;
15
15
  private readonly cms;
16
16
  private readonly targetModel;
17
- private readonly scheduleModel;
17
+ private readonly schedulerModel;
18
18
  private readonly getIdentity;
19
19
  private readonly fetcher;
20
20
  constructor(params: IUnpublishScheduleActionParams);
@@ -22,5 +22,5 @@ export declare class UnpublishScheduleAction implements IScheduleAction {
22
22
  schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;
23
23
  reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;
24
24
  cancel(id: string): Promise<void>;
25
- private getUpdateableTargetEntry;
25
+ private getTargetEntry;
26
26
  }
@@ -10,14 +10,13 @@ var _utils = require("@webiny/utils");
10
10
  var _dates = require("../dates.js");
11
11
  var _handlerGraphql = require("@webiny/handler-graphql");
12
12
  var _dateInTheFuture = require("../../utils/dateInTheFuture.js");
13
- var _error = require("@webiny/error");
14
13
  var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
15
14
  class UnpublishScheduleAction {
16
15
  constructor(params) {
17
16
  this.service = params.service;
18
17
  this.cms = params.cms;
19
18
  this.targetModel = params.targetModel;
20
- this.scheduleModel = params.scheduleModel;
19
+ this.schedulerModel = params.schedulerModel;
21
20
  this.getIdentity = params.getIdentity;
22
21
  this.fetcher = params.fetcher;
23
22
  }
@@ -30,7 +29,7 @@ class UnpublishScheduleAction {
30
29
  input,
31
30
  scheduleRecordId
32
31
  } = params;
33
- const targetEntry = await this.getUpdateableTargetEntry(targetId);
32
+ const targetEntry = await this.getTargetEntry(targetId);
34
33
  const title = targetEntry.values[this.targetModel.titleFieldId] || "Unknown entry title";
35
34
  const identity = this.getIdentity();
36
35
  const currentDate = new Date();
@@ -45,7 +44,7 @@ class UnpublishScheduleAction {
45
44
  model: this.targetModel,
46
45
  scheduledBy: unpublishedEntry.savedBy,
47
46
  scheduledOn: currentDate,
48
- dateOn: currentDate,
47
+ // dateOn: currentDate,
49
48
  type: _types.ScheduleType.unpublish,
50
49
  title
51
50
  });
@@ -63,7 +62,7 @@ class UnpublishScheduleAction {
63
62
  model: this.targetModel,
64
63
  scheduledBy: identity,
65
64
  scheduledOn: input.scheduleOn,
66
- dateOn: input.dateOn,
65
+ // dateOn: input.dateOn,
67
66
  type: _types.ScheduleType.unpublish,
68
67
  title
69
68
  });
@@ -75,13 +74,13 @@ class UnpublishScheduleAction {
75
74
  const {
76
75
  id: scheduleEntryId
77
76
  } = (0, _parseIdentifier.parseIdentifier)(scheduleRecordId);
78
- const scheduleEntry = await this.cms.createEntry(this.scheduleModel, {
77
+ const scheduleEntry = await this.cms.createEntry(this.schedulerModel, {
79
78
  id: scheduleEntryId,
80
79
  targetId,
81
80
  targetModelId: this.targetModel.modelId,
82
81
  title,
83
82
  type: _types.ScheduleType.unpublish,
84
- dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined,
83
+ // dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined,
85
84
  scheduledBy: identity,
86
85
  scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn)
87
86
  });
@@ -94,7 +93,7 @@ class UnpublishScheduleAction {
94
93
  console.error(`Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`);
95
94
  console.log((0, _utils.convertException)(ex));
96
95
  try {
97
- await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);
96
+ await this.cms.deleteEntry(this.schedulerModel, scheduleRecordId);
98
97
  } catch (err) {
99
98
  console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);
100
99
  console.log((0, _utils.convertException)(err));
@@ -107,14 +106,14 @@ class UnpublishScheduleAction {
107
106
  async reschedule(original, input) {
108
107
  const currentDate = new Date();
109
108
  const targetId = original.targetId;
110
- const targetEntry = await this.getUpdateableTargetEntry(targetId);
109
+ const targetEntry = await this.getTargetEntry(targetId);
111
110
  /**
112
111
  * There are two cases when we can immediately publish the entry:
113
112
  * 1. If the user requested it.
114
113
  * 2. If the entry is scheduled for a date in the past.
115
114
  */
116
115
  if (input.immediately || (0, _dateInTheFuture.dateInTheFuture)(input.scheduleOn)) {
117
- const publishedEntry = await this.cms.unpublishEntry(this.targetModel, targetEntry.id);
116
+ await this.cms.unpublishEntry(this.targetModel, targetEntry.id);
118
117
  /**
119
118
  * We can safely cancel the original schedule entry and the event.
120
119
  *
@@ -128,13 +127,15 @@ class UnpublishScheduleAction {
128
127
  return {
129
128
  ...original,
130
129
  publishOn: undefined,
131
- unpublishOn: currentDate,
132
- dateOn: publishedEntry.lastPublishedOn ? new Date(publishedEntry.lastPublishedOn) : undefined
130
+ unpublishOn: currentDate
131
+ // dateOn: publishedEntry.lastPublishedOn
132
+ // ? new Date(publishedEntry.lastPublishedOn)
133
+ // : undefined
133
134
  };
134
135
  }
135
- await this.cms.updateEntry(this.scheduleModel, original.id, {
136
- scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
137
- dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined
136
+ await this.cms.updateEntry(this.schedulerModel, original.id, {
137
+ scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn)
138
+ // dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined
138
139
  });
139
140
  try {
140
141
  await this.service.update({
@@ -149,8 +150,8 @@ class UnpublishScheduleAction {
149
150
  return {
150
151
  ...original,
151
152
  publishOn: undefined,
152
- unpublishOn: currentDate,
153
- dateOn: input.dateOn
153
+ unpublishOn: currentDate
154
+ // dateOn: input.dateOn
154
155
  };
155
156
  }
156
157
  async cancel(id) {
@@ -167,7 +168,7 @@ class UnpublishScheduleAction {
167
168
  return;
168
169
  }
169
170
  try {
170
- await this.cms.deleteEntry(this.scheduleModel, scheduleRecord.id);
171
+ await this.cms.deleteEntry(this.schedulerModel, scheduleRecord.id);
171
172
  } catch (ex) {
172
173
  if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
173
174
  return;
@@ -184,14 +185,8 @@ class UnpublishScheduleAction {
184
185
  throw ex;
185
186
  }
186
187
  }
187
- async getUpdateableTargetEntry(id) {
188
- const entry = await this.cms.getEntryById(this.targetModel, id);
189
- if (entry.locked) {
190
- throw new _error.WebinyError(`Cannot schedule a unpublish action for entry "${entry.id}" because it is locked.`, "ENTRY_LOCKED", {
191
- entryId: entry.id
192
- });
193
- }
194
- return entry;
188
+ async getTargetEntry(id) {
189
+ return await this.cms.getEntryById(this.targetModel, id);
195
190
  }
196
191
  }
197
192
  exports.UnpublishScheduleAction = UnpublishScheduleAction;
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_ScheduleRecord","_utils","_dates","_handlerGraphql","_dateInTheFuture","_error","_parseIdentifier","UnpublishScheduleAction","constructor","params","service","cms","targetModel","scheduleModel","getIdentity","fetcher","canHandle","input","type","ScheduleType","unpublish","schedule","targetId","scheduleRecordId","targetEntry","getUpdateableTargetEntry","title","values","titleFieldId","identity","currentDate","Date","immediately","unpublishedEntry","unpublishEntry","createScheduleRecord","id","model","scheduledBy","savedBy","scheduledOn","dateOn","scheduleOn","scheduleEntryId","parseIdentifier","scheduleEntry","createEntry","targetModelId","modelId","dateToISOString","undefined","create","ex","console","error","log","convertException","deleteEntry","err","transformScheduleEntry","reschedule","original","dateInTheFuture","publishedEntry","cancel","publishOn","unpublishOn","lastPublishedOn","updateEntry","update","scheduleRecord","getScheduled","code","NotFoundError","delete","entry","getEntryById","locked","WebinyError","entryId","exports"],"sources":["UnpublishScheduleAction.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\";\nimport { parseIdentifier } from \"@webiny/utils/parseIdentifier.js\";\n\nexport type UnpublishScheduleActionCms = Pick<\n HeadlessCms,\n \"getEntryById\" | \"unpublishEntry\" | \"createEntry\" | \"deleteEntry\" | \"updateEntry\"\n>;\n\nexport interface IUnpublishScheduleActionParams {\n service: ISchedulerService;\n cms: UnpublishScheduleActionCms;\n targetModel: CmsModel;\n scheduleModel: CmsModel;\n getIdentity: () => CmsIdentity;\n fetcher: IScheduleFetcher;\n}\n\nexport class UnpublishScheduleAction implements IScheduleAction {\n private readonly service: ISchedulerService;\n private readonly cms: UnpublishScheduleActionCms;\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: IUnpublishScheduleActionParams) {\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.unpublish;\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 const title = targetEntry.values[this.targetModel.titleFieldId] || \"Unknown entry title\";\n const identity = this.getIdentity();\n\n const currentDate = new Date();\n /**\n * Immediately unpublish the entry if requested.\n */\n if (input.immediately) {\n const unpublishedEntry = await this.cms.unpublishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: unpublishedEntry.savedBy,\n scheduledOn: currentDate,\n dateOn: currentDate,\n type: ScheduleType.unpublish,\n title\n });\n }\n /**\n * If the entry is scheduled for a date in the past, we need to unpublish it immediately.\n * No need to create a schedule entry or the service event.\n */\n //\n else if (input.scheduleOn < currentDate) {\n await this.cms.unpublishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: identity,\n scheduledOn: input.scheduleOn,\n dateOn: input.dateOn,\n type: ScheduleType.unpublish,\n title\n });\n }\n /**\n * If the entry is scheduled for a future date, we need to create a schedule entry and a service event.\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.unpublish,\n dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined,\n scheduledBy: identity,\n scheduledOn: dateToISOString(input.scheduleOn)\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\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 * 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 || dateInTheFuture(input.scheduleOn)) {\n const publishedEntry = await this.cms.unpublishEntry(this.targetModel, targetEntry.id);\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: undefined,\n unpublishOn: currentDate,\n dateOn: publishedEntry.lastPublishedOn\n ? new Date(publishedEntry.lastPublishedOn)\n : undefined\n };\n }\n\n await this.cms.updateEntry<Pick<IScheduleEntryValues, \"scheduledOn\" | \"dateOn\">>(\n this.scheduleModel,\n original.id,\n {\n scheduledOn: dateToISOString(input.scheduleOn),\n dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined\n }\n );\n\n try {\n await this.service.update({\n id: original.id,\n scheduleOn: input.scheduleOn\n });\n } catch (ex) {\n console.error(`Could not update service event for schedule entry: ${original.id}.`);\n console.log(convertException(ex));\n throw ex;\n }\n\n return {\n ...original,\n publishOn: undefined,\n unpublishOn: currentDate,\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 scheduleRecord: IScheduleRecord | null = null;\n try {\n scheduleRecord = await this.fetcher.getScheduled(id);\n if (!scheduleRecord) {\n return;\n }\n } catch {\n return;\n }\n\n try {\n await this.cms.deleteEntry(this.scheduleModel, scheduleRecord.id);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n return;\n }\n console.error(`Error while deleting schedule entry: ${scheduleRecord.id}.`);\n console.log(convertException(ex));\n throw ex;\n }\n\n try {\n await this.service.delete(scheduleRecord.id);\n } catch (ex) {\n console.error(\n `Error while deleting service event for schedule entry: ${scheduleRecord.id}.`\n );\n console.log(convertException(ex));\n\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 unpublish 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;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAgBO,MAAMQ,uBAAuB,CAA4B;EAQrDC,WAAWA,CAACC,MAAsC,EAAE;IACvD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,GAAG,GAAGF,MAAM,CAACE,GAAG;IACrB,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;IACrC,IAAI,CAACC,aAAa,GAAGJ,MAAM,CAACI,aAAa;IACzC,IAAI,CAACC,WAAW,GAAGL,M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EAAE,GAAG,CAAC;MAC3EiB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,IAAI;MACA,MAAM,IAAI,CAAC1C,OAAO,CAACgE,MAAM,CAACJ,cAAc,CAAClC,EAAE,CAAC;IAChD,CAAC,CAAC,OAAOgB,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,0DAA0DgB,cAAc,CAAClC,EAAE,GAC/E,CAAC;MACDiB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MAEjC,MAAMA,EAAE;IACZ;EACJ;EAEA,MAAc3B,wBAAwBA,CAAqBW,EAAU,EAAwB;IACzF,MAAMuC,KAAK,GAAG,MAAM,IAAI,CAAChE,GAAG,CAACiE,YAAY,CAAI,IAAI,CAAChE,WAAW,EAAEwB,EAAE,CAAC;IAClE,IAAIuC,KAAK,CAACE,MAAM,EAAE;MACd,MAAM,IAAIC,kBAAW,CACjB,iDAAiDH,KAAK,CAACvC,EAAE,yBAAyB,EAClF,cAAc,EACd;QACI2C,OAAO,EAAEJ,KAAK,CAACvC;MACnB,CACJ,CAAC;IACL;IACA,OAAOuC,KAAK;EAChB;AACJ;AAACK,OAAA,CAAAzE,uBAAA,GAAAA,uBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_types","require","_ScheduleRecord","_utils","_dates","_handlerGraphql","_dateInTheFuture","_parseIdentifier","UnpublishScheduleAction","constructor","params","service","cms","targetModel","schedulerModel","getIdentity","fetcher","canHandle","input","type","ScheduleType","unpublish","schedule","targetId","scheduleRecordId","targetEntry","getTargetEntry","title","values","titleFieldId","identity","currentDate","Date","immediately","unpublishedEntry","unpublishEntry","createScheduleRecord","id","model","scheduledBy","savedBy","scheduledOn","scheduleOn","scheduleEntryId","parseIdentifier","scheduleEntry","createEntry","targetModelId","modelId","dateToISOString","create","ex","console","error","log","convertException","deleteEntry","err","transformScheduleEntry","reschedule","original","dateInTheFuture","cancel","publishOn","undefined","unpublishOn","updateEntry","update","scheduleRecord","getScheduled","code","NotFoundError","delete","getEntryById","exports"],"sources":["UnpublishScheduleAction.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 { parseIdentifier } from \"@webiny/utils/parseIdentifier.js\";\n\nexport type UnpublishScheduleActionCms = Pick<\n HeadlessCms,\n \"getEntryById\" | \"unpublishEntry\" | \"createEntry\" | \"deleteEntry\" | \"updateEntry\"\n>;\n\nexport interface IUnpublishScheduleActionParams {\n service: ISchedulerService;\n cms: UnpublishScheduleActionCms;\n targetModel: CmsModel;\n schedulerModel: CmsModel;\n getIdentity: () => CmsIdentity;\n fetcher: IScheduleFetcher;\n}\n\nexport class UnpublishScheduleAction implements IScheduleAction {\n private readonly service: ISchedulerService;\n private readonly cms: UnpublishScheduleActionCms;\n private readonly targetModel: CmsModel;\n private readonly schedulerModel: CmsModel;\n private readonly getIdentity: () => CmsIdentity;\n private readonly fetcher: IScheduleFetcher;\n\n public constructor(params: IUnpublishScheduleActionParams) {\n this.service = params.service;\n this.cms = params.cms;\n this.targetModel = params.targetModel;\n this.schedulerModel = params.schedulerModel;\n this.getIdentity = params.getIdentity;\n this.fetcher = params.fetcher;\n }\n\n public canHandle(input: ISchedulerInput): boolean {\n return input.type === ScheduleType.unpublish;\n }\n\n public async schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord> {\n const { targetId, input, scheduleRecordId } = params;\n\n const targetEntry = await this.getTargetEntry(targetId);\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 unpublish the entry if requested.\n */\n if (input.immediately) {\n const unpublishedEntry = await this.cms.unpublishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: unpublishedEntry.savedBy,\n scheduledOn: currentDate,\n // dateOn: currentDate,\n type: ScheduleType.unpublish,\n title\n });\n }\n /**\n * If the entry is scheduled for a date in the past, we need to unpublish it immediately.\n * No need to create a schedule entry or the service event.\n */\n //\n else if (input.scheduleOn < currentDate) {\n await this.cms.unpublishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: identity,\n scheduledOn: input.scheduleOn,\n // dateOn: input.dateOn,\n type: ScheduleType.unpublish,\n title\n });\n }\n /**\n * If the entry is scheduled for a future date, we need to create a schedule entry and a service event.\n */\n\n const { id: scheduleEntryId } = parseIdentifier(scheduleRecordId);\n const scheduleEntry = await this.cms.createEntry<IScheduleEntryValues>(\n this.schedulerModel,\n {\n id: scheduleEntryId,\n targetId,\n targetModelId: this.targetModel.modelId,\n title,\n type: ScheduleType.unpublish,\n // dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined,\n scheduledBy: identity,\n scheduledOn: dateToISOString(input.scheduleOn)\n }\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.schedulerModel, 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\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.getTargetEntry(targetId);\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 || dateInTheFuture(input.scheduleOn)) {\n await this.cms.unpublishEntry(this.targetModel, targetEntry.id);\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: undefined,\n unpublishOn: currentDate\n // dateOn: publishedEntry.lastPublishedOn\n // ? new Date(publishedEntry.lastPublishedOn)\n // : undefined\n };\n }\n\n await this.cms.updateEntry<Pick<IScheduleEntryValues, \"scheduledOn\">>(\n this.schedulerModel,\n original.id,\n {\n scheduledOn: dateToISOString(input.scheduleOn)\n // dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined\n }\n );\n\n try {\n await this.service.update({\n id: original.id,\n scheduleOn: input.scheduleOn\n });\n } catch (ex) {\n console.error(`Could not update service event for schedule entry: ${original.id}.`);\n console.log(convertException(ex));\n throw ex;\n }\n\n return {\n ...original,\n publishOn: undefined,\n unpublishOn: currentDate\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 scheduleRecord: IScheduleRecord | null = null;\n try {\n scheduleRecord = await this.fetcher.getScheduled(id);\n if (!scheduleRecord) {\n return;\n }\n } catch {\n return;\n }\n\n try {\n await this.cms.deleteEntry(this.schedulerModel, scheduleRecord.id);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n return;\n }\n console.error(`Error while deleting schedule entry: ${scheduleRecord.id}.`);\n console.log(convertException(ex));\n throw ex;\n }\n\n try {\n await this.service.delete(scheduleRecord.id);\n } catch (ex) {\n console.error(\n `Error while deleting service event for schedule entry: ${scheduleRecord.id}.`\n );\n console.log(convertException(ex));\n\n throw ex;\n }\n }\n\n private async getTargetEntry<T = CmsEntryValues>(id: string): Promise<CmsEntry<T>> {\n return await this.cms.getEntryById<T>(this.targetModel, id);\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;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AAgBO,MAAMO,uBAAuB,CAA4B;EAQrDC,WAAWA,CAACC,MAAsC,EAAE;IACvD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,GAAG,GAAGF,MAAM,CAACE,GAAG;IACrB,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;IACrC,IAAI,CAACC,cAAc,GAAGJ,MAAM,CAACI,cAAc;IAC3C,IAAI,CAACC,WAAW,GAAGL,MAAM,CAACK,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGN,MAAM,CAACM,OAAO;EACjC;EAEOC,SAASA,CAACC,KAAsB,EAAW;IAC9C,OAAOA,KAAK,CAACC,IAAI,KAAKC,mBAAY,CAACC,SAAS;EAChD;EAEA,MAAaC,QAAQA,CAACZ,MAAqC,EAA4B;IACnF,MAAM;MAAEa,QAAQ;MAAEL,KAAK;MAAEM;IAAiB,CAAC,GAAGd,MAAM;IAEpD,MAAMe,WAAW,GAAG,MAAM,IAAI,CAACC,cAAc,CAACH,QAAQ,CAAC;IACvD,MAAMI,KAAK,GAAGF,WAAW,CAACG,MAAM,CAAC,IAAI,C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,CAAChC,EAAE,CAAC;MACpD,IAAI,CAAC+B,cAAc,EAAE;QACjB;MACJ;IACJ,CAAC,CAAC,MAAM;MACJ;IACJ;IAEA,IAAI;MACA,MAAM,IAAI,CAACxD,GAAG,CAAC4C,WAAW,CAAC,IAAI,CAAC1C,cAAc,EAAEsD,cAAc,CAAC/B,EAAE,CAAC;IACtE,CAAC,CAAC,OAAOc,EAAE,EAAE;MACT,IAAIA,EAAE,CAACmB,IAAI,KAAK,WAAW,IAAInB,EAAE,YAAYoB,6BAAa,EAAE;QACxD;MACJ;MACAnB,OAAO,CAACC,KAAK,CAAC,wCAAwCe,cAAc,CAAC/B,EAAE,GAAG,CAAC;MAC3Ee,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,IAAI;MACA,MAAM,IAAI,CAACxC,OAAO,CAAC6D,MAAM,CAACJ,cAAc,CAAC/B,EAAE,CAAC;IAChD,CAAC,CAAC,OAAOc,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,0DAA0De,cAAc,CAAC/B,EAAE,GAC/E,CAAC;MACDe,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MAEjC,MAAMA,EAAE;IACZ;EACJ;EAEA,MAAczB,cAAcA,CAAqBW,EAAU,EAAwB;IAC/E,OAAO,MAAM,IAAI,CAACzB,GAAG,CAAC6D,YAAY,CAAI,IAAI,CAAC5D,WAAW,EAAEwB,EAAE,CAAC;EAC/D;AACJ;AAACqC,OAAA,CAAAlE,uBAAA,GAAAA,uBAAA","ignoreList":[]}
@@ -7,6 +7,6 @@ export interface ICreateSchedulerParams {
7
7
  security: Pick<CmsContext["security"], "getIdentity">;
8
8
  cms: ScheduleExecutorCms & ScheduleFetcherCms;
9
9
  service: ISchedulerService;
10
- scheduleModel: CmsModel;
10
+ schedulerModel: CmsModel;
11
11
  }
12
12
  export declare const createScheduler: (params: ICreateSchedulerParams) => Promise<CmsScheduleCallable>;
@@ -9,14 +9,20 @@ var _ScheduleFetcher = require("./ScheduleFetcher.js");
9
9
  var _ScheduleExecutor = require("./ScheduleExecutor.js");
10
10
  var _PublishScheduleAction = require("./actions/PublishScheduleAction.js");
11
11
  var _UnpublishScheduleAction = require("./actions/UnpublishScheduleAction.js");
12
+ var _error = require("@webiny/error");
12
13
  const createScheduler = async params => {
13
14
  const {
14
15
  cms,
15
16
  security,
16
- scheduleModel,
17
+ schedulerModel,
17
18
  service
18
19
  } = params;
19
20
  return targetModel => {
21
+ if (targetModel.isPrivate) {
22
+ throw new _error.WebinyError("Cannot create a scheduler for private models.", "PRIVATE_MODEL_ERROR", {
23
+ modelId: targetModel.modelId
24
+ });
25
+ }
20
26
  const getIdentity = () => {
21
27
  const identity = security.getIdentity();
22
28
  if (!identity) {
@@ -26,19 +32,19 @@ const createScheduler = async params => {
26
32
  };
27
33
  const fetcher = new _ScheduleFetcher.ScheduleFetcher({
28
34
  targetModel,
29
- scheduleModel,
35
+ schedulerModel,
30
36
  cms
31
37
  });
32
38
  const actions = [new _PublishScheduleAction.PublishScheduleAction({
33
39
  cms,
34
- scheduleModel,
40
+ schedulerModel,
35
41
  targetModel,
36
42
  service,
37
43
  getIdentity,
38
44
  fetcher
39
45
  }), new _UnpublishScheduleAction.UnpublishScheduleAction({
40
46
  cms,
41
- scheduleModel,
47
+ schedulerModel,
42
48
  targetModel,
43
49
  service,
44
50
  getIdentity,
@@ -1 +1 @@
1
- {"version":3,"names":["_Scheduler","require","_ScheduleFetcher","_ScheduleExecutor","_PublishScheduleAction","_UnpublishScheduleAction","createScheduler","params","cms","security","scheduleModel","service","targetModel","getIdentity","identity","Error","fetcher","ScheduleFetcher","actions","PublishScheduleAction","UnpublishScheduleAction","executor","ScheduleExecutor","Scheduler","exports"],"sources":["createScheduler.ts"],"sourcesContent":["import type { CmsScheduleCallable } from \"~/types.js\";\nimport type { ISchedulerService } from \"~/service/types.js\";\nimport type { CmsContext, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { IScheduler } from \"./types.js\";\nimport { Scheduler } from \"./Scheduler.js\";\nimport type { ScheduleFetcherCms } from \"./ScheduleFetcher.js\";\nimport { ScheduleFetcher } from \"./ScheduleFetcher.js\";\nimport type { ScheduleExecutorCms } from \"./ScheduleExecutor.js\";\nimport { ScheduleExecutor } from \"./ScheduleExecutor.js\";\nimport { PublishScheduleAction } from \"~/scheduler/actions/PublishScheduleAction.js\";\nimport { UnpublishScheduleAction } from \"~/scheduler/actions/UnpublishScheduleAction.js\";\n\nexport interface ICreateSchedulerParams {\n security: Pick<CmsContext[\"security\"], \"getIdentity\">;\n cms: ScheduleExecutorCms & ScheduleFetcherCms;\n service: ISchedulerService;\n scheduleModel: CmsModel;\n}\n\nexport const createScheduler = async (\n params: ICreateSchedulerParams\n): Promise<CmsScheduleCallable> => {\n const { cms, security, scheduleModel, service } = params;\n\n return (targetModel): IScheduler => {\n const getIdentity = () => {\n const identity = security.getIdentity();\n if (!identity) {\n throw new Error(\"No identity found in security context.\");\n }\n return identity;\n };\n\n const fetcher = new ScheduleFetcher({\n targetModel,\n scheduleModel,\n cms\n });\n\n const actions = [\n new PublishScheduleAction({\n cms,\n scheduleModel,\n targetModel,\n service,\n getIdentity,\n fetcher\n }),\n new UnpublishScheduleAction({\n cms,\n scheduleModel,\n targetModel,\n service,\n getIdentity,\n fetcher\n })\n ];\n\n const executor = new ScheduleExecutor({\n actions,\n fetcher\n });\n return new Scheduler({\n fetcher,\n executor\n });\n };\n};\n"],"mappings":";;;;;;AAIA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,wBAAA,GAAAJ,OAAA;AASO,MAAMK,eAAe,GAAG,MAC3BC,MAA8B,IACC;EAC/B,MAAM;IAAEC,GAAG;IAAEC,QAAQ;IAAEC,aAAa;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EAExD,OAAQK,WAAW,IAAiB;IAChC,MAAMC,WAAW,GAAGA,CAAA,KAAM;MACtB,MAAMC,QAAQ,GAAGL,QAAQ,CAACI,WAAW,CAAC,CAAC;MACvC,IAAI,CAACC,QAAQ,EAAE;QACX,MAAM,IAAIC,KAAK,CAAC,wCAAwC,CAAC;MAC7D;MACA,OAAOD,QAAQ;IACnB,CAAC;IAED,MAAME,OAAO,GAAG,IAAIC,gCAAe,CAAC;MAChCL,WAAW;MACXF,aAAa;MACbF;IACJ,CAAC,CAAC;IAEF,MAAMU,OAAO,GAAG,CACZ,IAAIC,4CAAqB,CAAC;MACtBX,GAAG;MACHE,aAAa;MACbE,WAAW;MACXD,OAAO;MACPE,WAAW;MACXG;IACJ,CAAC,CAAC,EACF,IAAII,gDAAuB,CAAC;MACxBZ,GAAG;MACHE,aAAa;MACbE,WAAW;MACXD,OAAO;MACPE,WAAW;MACXG;IACJ,CAAC,CAAC,CACL;IAED,MAAMK,QAAQ,GAAG,IAAIC,kCAAgB,CAAC;MAClCJ,OAAO;MACPF;IACJ,CAAC,CAAC;IACF,OAAO,IAAIO,oBAAS,CAAC;MACjBP,OAAO;MACPK;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACG,OAAA,CAAAlB,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"names":["_Scheduler","require","_ScheduleFetcher","_ScheduleExecutor","_PublishScheduleAction","_UnpublishScheduleAction","_error","createScheduler","params","cms","security","schedulerModel","service","targetModel","isPrivate","WebinyError","modelId","getIdentity","identity","Error","fetcher","ScheduleFetcher","actions","PublishScheduleAction","UnpublishScheduleAction","executor","ScheduleExecutor","Scheduler","exports"],"sources":["createScheduler.ts"],"sourcesContent":["import type { CmsScheduleCallable } from \"~/types.js\";\nimport type { ISchedulerService } from \"~/service/types.js\";\nimport type { CmsContext, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { IScheduler } from \"./types.js\";\nimport { Scheduler } from \"./Scheduler.js\";\nimport type { ScheduleFetcherCms } from \"./ScheduleFetcher.js\";\nimport { ScheduleFetcher } from \"./ScheduleFetcher.js\";\nimport type { ScheduleExecutorCms } from \"./ScheduleExecutor.js\";\nimport { ScheduleExecutor } from \"./ScheduleExecutor.js\";\nimport { PublishScheduleAction } from \"~/scheduler/actions/PublishScheduleAction.js\";\nimport { UnpublishScheduleAction } from \"~/scheduler/actions/UnpublishScheduleAction.js\";\nimport { WebinyError } from \"@webiny/error\";\n\nexport interface ICreateSchedulerParams {\n security: Pick<CmsContext[\"security\"], \"getIdentity\">;\n cms: ScheduleExecutorCms & ScheduleFetcherCms;\n service: ISchedulerService;\n schedulerModel: CmsModel;\n}\n\nexport const createScheduler = async (\n params: ICreateSchedulerParams\n): Promise<CmsScheduleCallable> => {\n const { cms, security, schedulerModel, service } = params;\n\n return (targetModel): IScheduler => {\n if (targetModel.isPrivate) {\n throw new WebinyError(\n \"Cannot create a scheduler for private models.\",\n \"PRIVATE_MODEL_ERROR\",\n {\n modelId: targetModel.modelId\n }\n );\n }\n const getIdentity = () => {\n const identity = security.getIdentity();\n if (!identity) {\n throw new Error(\"No identity found in security context.\");\n }\n return identity;\n };\n\n const fetcher = new ScheduleFetcher({\n targetModel,\n schedulerModel,\n cms\n });\n\n const actions = [\n new PublishScheduleAction({\n cms,\n schedulerModel,\n targetModel,\n service,\n getIdentity,\n fetcher\n }),\n new UnpublishScheduleAction({\n cms,\n schedulerModel,\n targetModel,\n service,\n getIdentity,\n fetcher\n })\n ];\n\n const executor = new ScheduleExecutor({\n actions,\n fetcher\n });\n return new Scheduler({\n fetcher,\n executor\n });\n };\n};\n"],"mappings":";;;;;;AAIA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AASO,MAAMM,eAAe,GAAG,MAC3BC,MAA8B,IACC;EAC/B,MAAM;IAAEC,GAAG;IAAEC,QAAQ;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EAEzD,OAAQK,WAAW,IAAiB;IAChC,IAAIA,WAAW,CAACC,SAAS,EAAE;MACvB,MAAM,IAAIC,kBAAW,CACjB,+CAA+C,EAC/C,qBAAqB,EACrB;QACIC,OAAO,EAAEH,WAAW,CAACG;MACzB,CACJ,CAAC;IACL;IACA,MAAMC,WAAW,GAAGA,CAAA,KAAM;MACtB,MAAMC,QAAQ,GAAGR,QAAQ,CAACO,WAAW,CAAC,CAAC;MACvC,IAAI,CAACC,QAAQ,EAAE;QACX,MAAM,IAAIC,KAAK,CAAC,wCAAwC,CAAC;MAC7D;MACA,OAAOD,QAAQ;IACnB,CAAC;IAED,MAAME,OAAO,GAAG,IAAIC,gCAAe,CAAC;MAChCR,WAAW;MACXF,cAAc;MACdF;IACJ,CAAC,CAAC;IAEF,MAAMa,OAAO,GAAG,CACZ,IAAIC,4CAAqB,CAAC;MACtBd,GAAG;MACHE,cAAc;MACdE,WAAW;MACXD,OAAO;MACPK,WAAW;MACXG;IACJ,CAAC,CAAC,EACF,IAAII,gDAAuB,CAAC;MACxBf,GAAG;MACHE,cAAc;MACdE,WAAW;MACXD,OAAO;MACPK,WAAW;MACXG;IACJ,CAAC,CAAC,CACL;IAED,MAAMK,QAAQ,GAAG,IAAIC,kCAAgB,CAAC;MAClCJ,OAAO;MACPF;IACJ,CAAC,CAAC;IACF,OAAO,IAAIO,oBAAS,CAAC;MACjBP,OAAO;MACPK;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACG,OAAA,CAAArB,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -15,13 +15,11 @@ export type DateOnType = Date;
15
15
  export interface ISchedulerInputImmediately {
16
16
  immediately: true;
17
17
  scheduleOn?: never;
18
- dateOn?: DateOnType;
19
18
  type: ScheduleType;
20
19
  }
21
20
  export interface ISchedulerInputScheduled {
22
21
  immediately?: false;
23
22
  scheduleOn: ScheduledOnType;
24
- dateOn?: DateOnType;
25
23
  type: ScheduleType;
26
24
  }
27
25
  export type ISchedulerInput = ISchedulerInputScheduled | ISchedulerInputImmediately;
@@ -30,7 +28,6 @@ export interface IScheduleRecord {
30
28
  targetId: string;
31
29
  model: CmsModel;
32
30
  scheduledBy: CmsIdentity;
33
- dateOn: DateOnType | undefined;
34
31
  publishOn: ScheduledOnType | undefined;
35
32
  unpublishOn: ScheduledOnType | undefined;
36
33
  type: ScheduleType;
@@ -65,7 +62,6 @@ export interface IScheduleEntryValues {
65
62
  targetId: string;
66
63
  targetModelId: string;
67
64
  scheduledBy: CmsIdentity;
68
- dateOn: DateISOString | undefined;
69
65
  scheduledOn: DateISOString;
70
66
  type: string;
71
67
  title: string;
@@ -1 +1 @@
1
- {"version":3,"names":["ScheduleType","exports"],"sources":["types.ts"],"sourcesContent":["import type {\n CmsEntryListSort,\n CmsEntryMeta,\n CmsIdentity,\n CmsModel\n} from \"@webiny/api-headless-cms/types/index.js\";\n\nexport enum ScheduleType {\n publish = \"publish\",\n unpublish = \"unpublish\"\n}\n\nexport type DateISOString =\n `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`;\n/**\n * A date when the action is to be scheduled.\n */\nexport type ScheduledOnType = Date;\n/**\n * A custom date when the action is to be set as done (publishedOn and related dates).\n */\nexport type DateOnType = Date;\n\nexport interface ISchedulerInputImmediately {\n immediately: true;\n scheduleOn?: never;\n dateOn?: DateOnType;\n type: ScheduleType;\n}\n\nexport interface ISchedulerInputScheduled {\n immediately?: false;\n scheduleOn: ScheduledOnType;\n dateOn?: DateOnType;\n type: ScheduleType;\n}\n\nexport type ISchedulerInput = ISchedulerInputScheduled | ISchedulerInputImmediately;\n\nexport interface IScheduleRecord {\n id: string;\n targetId: string;\n model: CmsModel;\n scheduledBy: CmsIdentity;\n dateOn: DateOnType | undefined;\n publishOn: ScheduledOnType | undefined;\n unpublishOn: ScheduledOnType | undefined;\n type: ScheduleType;\n title: string;\n}\n\nexport interface ISchedulerListResponse {\n data: IScheduleRecord[];\n meta: CmsEntryMeta;\n}\n\nexport interface ISchedulerListParamsWhere {\n targetId?: string;\n targetEntryId?: string;\n type?: ScheduleType;\n scheduledBy?: string;\n scheduledOn?: DateISOString;\n scheduledOn_gte?: DateISOString;\n scheduledOn_lte?: DateISOString;\n}\n\nexport interface ISchedulerListParams {\n where: ISchedulerListParamsWhere;\n sort: CmsEntryListSort | undefined;\n limit: number | undefined;\n after: string | undefined;\n}\n\nexport interface IScheduler {\n schedule(id: string, input: ISchedulerInput): Promise<IScheduleRecord>;\n cancel(id: string): Promise<IScheduleRecord>;\n getScheduled(id: string): Promise<IScheduleRecord | null>;\n listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;\n}\n\nexport interface IScheduleEntryValues {\n targetId: string;\n targetModelId: string;\n scheduledBy: CmsIdentity;\n dateOn: DateISOString | undefined;\n scheduledOn: DateISOString;\n type: string;\n title: string;\n error?: string;\n}\n\nexport interface IScheduleExecutor {\n schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord>;\n cancel(id: string): Promise<IScheduleRecord>;\n}\n\nexport interface IScheduleFetcher {\n getScheduled(targetId: string): Promise<IScheduleRecord | null>;\n listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;\n}\n\nexport interface IScheduleActionScheduleParams {\n targetId: string;\n scheduleRecordId: string;\n input: ISchedulerInput;\n}\nexport interface IScheduleAction {\n canHandle(input: Pick<ISchedulerInput, \"type\">): boolean;\n schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;\n cancel(id: string): Promise<void>;\n reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;\n}\n"],"mappings":";;;;;;IAOYA,YAAY,GAAAC,OAAA,CAAAD,YAAA,0BAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA;AAOxB;AACA;AACA;AAEA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["ScheduleType","exports"],"sources":["types.ts"],"sourcesContent":["import type {\n CmsEntryListSort,\n CmsEntryMeta,\n CmsIdentity,\n CmsModel\n} from \"@webiny/api-headless-cms/types/index.js\";\n\nexport enum ScheduleType {\n publish = \"publish\",\n unpublish = \"unpublish\"\n}\n\nexport type DateISOString =\n `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`;\n/**\n * A date when the action is to be scheduled.\n */\nexport type ScheduledOnType = Date;\n/**\n * A custom date when the action is to be set as done (publishedOn and related dates).\n */\nexport type DateOnType = Date;\n\nexport interface ISchedulerInputImmediately {\n immediately: true;\n scheduleOn?: never;\n type: ScheduleType;\n}\n\nexport interface ISchedulerInputScheduled {\n immediately?: false;\n scheduleOn: ScheduledOnType;\n type: ScheduleType;\n}\n\nexport type ISchedulerInput = ISchedulerInputScheduled | ISchedulerInputImmediately;\n\nexport interface IScheduleRecord {\n id: string;\n targetId: string;\n model: CmsModel;\n scheduledBy: CmsIdentity;\n // dateOn: DateOnType | undefined;\n publishOn: ScheduledOnType | undefined;\n unpublishOn: ScheduledOnType | undefined;\n type: ScheduleType;\n title: string;\n}\n\nexport interface ISchedulerListResponse {\n data: IScheduleRecord[];\n meta: CmsEntryMeta;\n}\n\nexport interface ISchedulerListParamsWhere {\n targetId?: string;\n targetEntryId?: string;\n type?: ScheduleType;\n scheduledBy?: string;\n scheduledOn?: DateISOString;\n scheduledOn_gte?: DateISOString;\n scheduledOn_lte?: DateISOString;\n}\n\nexport interface ISchedulerListParams {\n where: ISchedulerListParamsWhere;\n sort: CmsEntryListSort | undefined;\n limit: number | undefined;\n after: string | undefined;\n}\n\nexport interface IScheduler {\n schedule(id: string, input: ISchedulerInput): Promise<IScheduleRecord>;\n cancel(id: string): Promise<IScheduleRecord>;\n getScheduled(id: string): Promise<IScheduleRecord | null>;\n listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;\n}\n\nexport interface IScheduleEntryValues {\n targetId: string;\n targetModelId: string;\n scheduledBy: CmsIdentity;\n // dateOn: DateISOString | undefined;\n scheduledOn: DateISOString;\n type: string;\n title: string;\n error?: string;\n}\n\nexport interface IScheduleExecutor {\n schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord>;\n cancel(id: string): Promise<IScheduleRecord>;\n}\n\nexport interface IScheduleFetcher {\n getScheduled(targetId: string): Promise<IScheduleRecord | null>;\n listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;\n}\n\nexport interface IScheduleActionScheduleParams {\n targetId: string;\n scheduleRecordId: string;\n input: ISchedulerInput;\n}\nexport interface IScheduleAction {\n canHandle(input: Pick<ISchedulerInput, \"type\">): boolean;\n schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;\n cancel(id: string): Promise<void>;\n reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;\n}\n"],"mappings":";;;;;;IAOYA,YAAY,GAAAC,OAAA,CAAAD,YAAA,0BAAZA,YAAY;EAAZA,YAAY;EAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA;AAOxB;AACA;AACA;AAEA;AACA;AACA","ignoreList":[]}