@webiny/api-headless-cms-scheduler 0.0.0-unstable.06b2ede40f
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/LICENSE +21 -0
- package/README.md +15 -0
- package/constants.d.ts +11 -0
- package/constants.js +19 -0
- package/constants.js.map +1 -0
- package/context.d.ts +7 -0
- package/context.js +68 -0
- package/context.js.map +1 -0
- package/graphql/index.d.ts +3 -0
- package/graphql/index.js +204 -0
- package/graphql/index.js.map +1 -0
- package/graphql/schema.d.ts +217 -0
- package/graphql/schema.js +87 -0
- package/graphql/schema.js.map +1 -0
- package/handler/Handler.d.ts +23 -0
- package/handler/Handler.js +74 -0
- package/handler/Handler.js.map +1 -0
- package/handler/actions/PublishHandlerAction.d.ts +13 -0
- package/handler/actions/PublishHandlerAction.js +64 -0
- package/handler/actions/PublishHandlerAction.js.map +1 -0
- package/handler/actions/UnpublishHandlerAction.d.ts +13 -0
- package/handler/actions/UnpublishHandlerAction.js +53 -0
- package/handler/actions/UnpublishHandlerAction.js.map +1 -0
- package/handler/index.d.ts +7 -0
- package/handler/index.js +64 -0
- package/handler/index.js.map +1 -0
- package/handler/types.d.ts +5 -0
- package/handler/types.js +7 -0
- package/handler/types.js.map +1 -0
- package/hooks/index.d.ts +7 -0
- package/hooks/index.js +58 -0
- package/hooks/index.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +29 -0
- package/index.js.map +1 -0
- package/manifest.d.ts +17 -0
- package/manifest.js +47 -0
- package/manifest.js.map +1 -0
- package/package.json +45 -0
- package/scheduler/ScheduleExecutor.d.ts +16 -0
- package/scheduler/ScheduleExecutor.js +55 -0
- package/scheduler/ScheduleExecutor.js.map +1 -0
- package/scheduler/ScheduleFetcher.d.ts +16 -0
- package/scheduler/ScheduleFetcher.js +51 -0
- package/scheduler/ScheduleFetcher.js.map +1 -0
- package/scheduler/ScheduleRecord.d.ts +31 -0
- package/scheduler/ScheduleRecord.js +57 -0
- package/scheduler/ScheduleRecord.js.map +1 -0
- package/scheduler/Scheduler.d.ts +14 -0
- package/scheduler/Scheduler.js +27 -0
- package/scheduler/Scheduler.js.map +1 -0
- package/scheduler/actions/PublishScheduleAction.d.ts +26 -0
- package/scheduler/actions/PublishScheduleAction.js +196 -0
- package/scheduler/actions/PublishScheduleAction.js.map +1 -0
- package/scheduler/actions/UnpublishScheduleAction.d.ts +26 -0
- package/scheduler/actions/UnpublishScheduleAction.js +194 -0
- package/scheduler/actions/UnpublishScheduleAction.js.map +1 -0
- package/scheduler/createScheduleRecordId.d.ts +2 -0
- package/scheduler/createScheduleRecordId.js +33 -0
- package/scheduler/createScheduleRecordId.js.map +1 -0
- package/scheduler/createScheduler.d.ts +12 -0
- package/scheduler/createScheduler.js +65 -0
- package/scheduler/createScheduler.js.map +1 -0
- package/scheduler/dates.d.ts +7 -0
- package/scheduler/dates.js +27 -0
- package/scheduler/dates.js.map +1 -0
- package/scheduler/model.d.ts +1 -0
- package/scheduler/model.js +88 -0
- package/scheduler/model.js.map +1 -0
- package/scheduler/types.d.ts +88 -0
- package/scheduler/types.js +19 -0
- package/scheduler/types.js.map +1 -0
- package/service/SchedulerService.d.ts +23 -0
- package/service/SchedulerService.js +151 -0
- package/service/SchedulerService.js.map +1 -0
- package/service/types.d.ts +19 -0
- package/service/types.js +7 -0
- package/service/types.js.map +1 -0
- package/types.d.ts +11 -0
- package/types.js +7 -0
- package/types.js.map +1 -0
- package/utils/dateInTheFuture.d.ts +6 -0
- package/utils/dateInTheFuture.js +19 -0
- package/utils/dateInTheFuture.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
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;EAEOC,SAASA,CAACC,KAAsB,EAAW;IAC9C,OAAOA,KAAK,CAACC,IAAI,KAAKC,mBAAY,CAACC,OAAO;EAC9C;EAEA,MAAaC,QAAQA,CAACZ,MAAqC,EAA4B;IACnF,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AG,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":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IScheduleAction, IScheduleActionScheduleParams, IScheduleFetcher, IScheduleRecord, ISchedulerInput } from "../types.js";
|
|
2
|
+
import type { CmsIdentity, CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import type { ISchedulerService } from "../../service/types.js";
|
|
4
|
+
export type UnpublishScheduleActionCms = Pick<HeadlessCms, "getEntryById" | "unpublishEntry" | "createEntry" | "deleteEntry" | "updateEntry">;
|
|
5
|
+
export interface IUnpublishScheduleActionParams {
|
|
6
|
+
service: ISchedulerService;
|
|
7
|
+
cms: UnpublishScheduleActionCms;
|
|
8
|
+
targetModel: CmsModel;
|
|
9
|
+
schedulerModel: CmsModel;
|
|
10
|
+
getIdentity: () => CmsIdentity;
|
|
11
|
+
fetcher: IScheduleFetcher;
|
|
12
|
+
}
|
|
13
|
+
export declare class UnpublishScheduleAction implements IScheduleAction {
|
|
14
|
+
private readonly service;
|
|
15
|
+
private readonly cms;
|
|
16
|
+
private readonly targetModel;
|
|
17
|
+
private readonly schedulerModel;
|
|
18
|
+
private readonly getIdentity;
|
|
19
|
+
private readonly fetcher;
|
|
20
|
+
constructor(params: IUnpublishScheduleActionParams);
|
|
21
|
+
canHandle(input: ISchedulerInput): boolean;
|
|
22
|
+
schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;
|
|
23
|
+
reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;
|
|
24
|
+
cancel(id: string): Promise<void>;
|
|
25
|
+
private getTargetEntry;
|
|
26
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnpublishScheduleAction = void 0;
|
|
7
|
+
var _types = require("../types.js");
|
|
8
|
+
var _ScheduleRecord = require("../ScheduleRecord.js");
|
|
9
|
+
var _utils = require("@webiny/utils");
|
|
10
|
+
var _dates = require("../dates.js");
|
|
11
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
12
|
+
var _dateInTheFuture = require("../../utils/dateInTheFuture.js");
|
|
13
|
+
var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
|
|
14
|
+
class UnpublishScheduleAction {
|
|
15
|
+
constructor(params) {
|
|
16
|
+
this.service = params.service;
|
|
17
|
+
this.cms = params.cms;
|
|
18
|
+
this.targetModel = params.targetModel;
|
|
19
|
+
this.schedulerModel = params.schedulerModel;
|
|
20
|
+
this.getIdentity = params.getIdentity;
|
|
21
|
+
this.fetcher = params.fetcher;
|
|
22
|
+
}
|
|
23
|
+
canHandle(input) {
|
|
24
|
+
return input.type === _types.ScheduleType.unpublish;
|
|
25
|
+
}
|
|
26
|
+
async schedule(params) {
|
|
27
|
+
const {
|
|
28
|
+
targetId,
|
|
29
|
+
input,
|
|
30
|
+
scheduleRecordId
|
|
31
|
+
} = params;
|
|
32
|
+
const targetEntry = await this.getTargetEntry(targetId);
|
|
33
|
+
const title = targetEntry.values[this.targetModel.titleFieldId] || "Unknown entry title";
|
|
34
|
+
const identity = this.getIdentity();
|
|
35
|
+
const currentDate = new Date();
|
|
36
|
+
/**
|
|
37
|
+
* Immediately unpublish the entry if requested.
|
|
38
|
+
*/
|
|
39
|
+
if (input.immediately) {
|
|
40
|
+
const unpublishedEntry = await this.cms.unpublishEntry(this.targetModel, targetId);
|
|
41
|
+
return (0, _ScheduleRecord.createScheduleRecord)({
|
|
42
|
+
id: scheduleRecordId,
|
|
43
|
+
targetId,
|
|
44
|
+
model: this.targetModel,
|
|
45
|
+
scheduledBy: unpublishedEntry.savedBy,
|
|
46
|
+
scheduledOn: currentDate,
|
|
47
|
+
// dateOn: currentDate,
|
|
48
|
+
type: _types.ScheduleType.unpublish,
|
|
49
|
+
title
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* If the entry is scheduled for a date in the past, we need to unpublish it immediately.
|
|
54
|
+
* No need to create a schedule entry or the service event.
|
|
55
|
+
*/
|
|
56
|
+
//
|
|
57
|
+
else if (input.scheduleOn < currentDate) {
|
|
58
|
+
await this.cms.unpublishEntry(this.targetModel, targetId);
|
|
59
|
+
return (0, _ScheduleRecord.createScheduleRecord)({
|
|
60
|
+
id: scheduleRecordId,
|
|
61
|
+
targetId,
|
|
62
|
+
model: this.targetModel,
|
|
63
|
+
scheduledBy: identity,
|
|
64
|
+
scheduledOn: input.scheduleOn,
|
|
65
|
+
// dateOn: input.dateOn,
|
|
66
|
+
type: _types.ScheduleType.unpublish,
|
|
67
|
+
title
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* If the entry is scheduled for a future date, we need to create a schedule entry and a service event.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
const {
|
|
75
|
+
id: scheduleEntryId
|
|
76
|
+
} = (0, _parseIdentifier.parseIdentifier)(scheduleRecordId);
|
|
77
|
+
const scheduleEntry = await this.cms.createEntry(this.schedulerModel, {
|
|
78
|
+
id: scheduleEntryId,
|
|
79
|
+
targetId,
|
|
80
|
+
targetModelId: this.targetModel.modelId,
|
|
81
|
+
title,
|
|
82
|
+
type: _types.ScheduleType.unpublish,
|
|
83
|
+
// dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined,
|
|
84
|
+
scheduledBy: identity,
|
|
85
|
+
scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn)
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
await this.service.create({
|
|
89
|
+
id: scheduleRecordId,
|
|
90
|
+
scheduleOn: input.scheduleOn
|
|
91
|
+
});
|
|
92
|
+
} catch (ex) {
|
|
93
|
+
console.error(`Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`);
|
|
94
|
+
console.log((0, _utils.convertException)(ex));
|
|
95
|
+
try {
|
|
96
|
+
await this.cms.deleteEntry(this.schedulerModel, scheduleRecordId);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);
|
|
99
|
+
console.log((0, _utils.convertException)(err));
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
throw ex;
|
|
103
|
+
}
|
|
104
|
+
return (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, scheduleEntry);
|
|
105
|
+
}
|
|
106
|
+
async reschedule(original, input) {
|
|
107
|
+
const currentDate = new Date();
|
|
108
|
+
const targetId = original.targetId;
|
|
109
|
+
const targetEntry = await this.getTargetEntry(targetId);
|
|
110
|
+
/**
|
|
111
|
+
* There are two cases when we can immediately publish the entry:
|
|
112
|
+
* 1. If the user requested it.
|
|
113
|
+
* 2. If the entry is scheduled for a date in the past.
|
|
114
|
+
*/
|
|
115
|
+
if (input.immediately || (0, _dateInTheFuture.dateInTheFuture)(input.scheduleOn)) {
|
|
116
|
+
await this.cms.unpublishEntry(this.targetModel, targetEntry.id);
|
|
117
|
+
/**
|
|
118
|
+
* We can safely cancel the original schedule entry and the event.
|
|
119
|
+
*
|
|
120
|
+
* // TODO determine if we want to ignore the error of the cancelation.
|
|
121
|
+
*/
|
|
122
|
+
try {
|
|
123
|
+
await this.cancel(original.id);
|
|
124
|
+
} catch {
|
|
125
|
+
//
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
...original,
|
|
129
|
+
publishOn: undefined,
|
|
130
|
+
unpublishOn: currentDate
|
|
131
|
+
// dateOn: publishedEntry.lastPublishedOn
|
|
132
|
+
// ? new Date(publishedEntry.lastPublishedOn)
|
|
133
|
+
// : undefined
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
await this.cms.updateEntry(this.schedulerModel, original.id, {
|
|
137
|
+
scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn)
|
|
138
|
+
// dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined
|
|
139
|
+
});
|
|
140
|
+
try {
|
|
141
|
+
await this.service.update({
|
|
142
|
+
id: original.id,
|
|
143
|
+
scheduleOn: input.scheduleOn
|
|
144
|
+
});
|
|
145
|
+
} catch (ex) {
|
|
146
|
+
console.error(`Could not update service event for schedule entry: ${original.id}.`);
|
|
147
|
+
console.log((0, _utils.convertException)(ex));
|
|
148
|
+
throw ex;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
...original,
|
|
152
|
+
publishOn: undefined,
|
|
153
|
+
unpublishOn: currentDate
|
|
154
|
+
// dateOn: input.dateOn
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async cancel(id) {
|
|
158
|
+
/**
|
|
159
|
+
* No need to do anything if the record does not exist.
|
|
160
|
+
*/
|
|
161
|
+
let scheduleRecord = null;
|
|
162
|
+
try {
|
|
163
|
+
scheduleRecord = await this.fetcher.getScheduled(id);
|
|
164
|
+
if (!scheduleRecord) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
await this.cms.deleteEntry(this.schedulerModel, scheduleRecord.id);
|
|
172
|
+
} catch (ex) {
|
|
173
|
+
if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
console.error(`Error while deleting schedule entry: ${scheduleRecord.id}.`);
|
|
177
|
+
console.log((0, _utils.convertException)(ex));
|
|
178
|
+
throw ex;
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
await this.service.delete(scheduleRecord.id);
|
|
182
|
+
} catch (ex) {
|
|
183
|
+
console.error(`Error while deleting service event for schedule entry: ${scheduleRecord.id}.`);
|
|
184
|
+
console.log((0, _utils.convertException)(ex));
|
|
185
|
+
throw ex;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async getTargetEntry(id) {
|
|
189
|
+
return await this.cms.getEntryById(this.targetModel, id);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.UnpublishScheduleAction = UnpublishScheduleAction;
|
|
193
|
+
|
|
194
|
+
//# sourceMappingURL=UnpublishScheduleAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;A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Ee,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":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createScheduleRecordIdWithVersion = exports.createScheduleRecordId = void 0;
|
|
7
|
+
var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
|
|
8
|
+
var _constants = require("../constants.js");
|
|
9
|
+
var _zeroPad = require("@webiny/utils/zeroPad.js");
|
|
10
|
+
const createScheduleRecordIdWithVersion = input => {
|
|
11
|
+
const recordId = createScheduleRecordId(input);
|
|
12
|
+
const {
|
|
13
|
+
id
|
|
14
|
+
} = (0, _parseIdentifier.parseIdentifier)(recordId);
|
|
15
|
+
return `${id}#0001`;
|
|
16
|
+
};
|
|
17
|
+
exports.createScheduleRecordIdWithVersion = createScheduleRecordIdWithVersion;
|
|
18
|
+
const createScheduleRecordId = input => {
|
|
19
|
+
/**
|
|
20
|
+
* A possibility that the input is already a schedule record ID?
|
|
21
|
+
*/
|
|
22
|
+
if (input.includes(_constants.SCHEDULE_ID_PREFIX)) {
|
|
23
|
+
return input;
|
|
24
|
+
}
|
|
25
|
+
const {
|
|
26
|
+
id,
|
|
27
|
+
version
|
|
28
|
+
} = (0, _parseIdentifier.parseIdentifier)(input);
|
|
29
|
+
return `${_constants.SCHEDULE_ID_PREFIX}${id}-${(0, _zeroPad.zeroPad)(version || 1)}`;
|
|
30
|
+
};
|
|
31
|
+
exports.createScheduleRecordId = createScheduleRecordId;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=createScheduleRecordId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_parseIdentifier","require","_constants","_zeroPad","createScheduleRecordIdWithVersion","input","recordId","createScheduleRecordId","id","parseIdentifier","exports","includes","SCHEDULE_ID_PREFIX","version","zeroPad"],"sources":["createScheduleRecordId.ts"],"sourcesContent":["import { parseIdentifier } from \"@webiny/utils/parseIdentifier.js\";\nimport { SCHEDULE_ID_PREFIX } from \"~/constants.js\";\nimport { zeroPad } from \"@webiny/utils/zeroPad.js\";\n\nexport const createScheduleRecordIdWithVersion = (input: string): string => {\n const recordId = createScheduleRecordId(input);\n const { id } = parseIdentifier(recordId);\n\n return `${id}#0001`;\n};\n\nexport const createScheduleRecordId = (input: string): string => {\n /**\n * A possibility that the input is already a schedule record ID?\n */\n if (input.includes(SCHEDULE_ID_PREFIX)) {\n return input;\n }\n\n const { id, version } = parseIdentifier(input);\n return `${SCHEDULE_ID_PREFIX}${id}-${zeroPad(version || 1)}`;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEO,MAAMG,iCAAiC,GAAIC,KAAa,IAAa;EACxE,MAAMC,QAAQ,GAAGC,sBAAsB,CAACF,KAAK,CAAC;EAC9C,MAAM;IAAEG;EAAG,CAAC,GAAG,IAAAC,gCAAe,EAACH,QAAQ,CAAC;EAExC,OAAO,GAAGE,EAAE,OAAO;AACvB,CAAC;AAACE,OAAA,CAAAN,iCAAA,GAAAA,iCAAA;AAEK,MAAMG,sBAAsB,GAAIF,KAAa,IAAa;EAC7D;AACJ;AACA;EACI,IAAIA,KAAK,CAACM,QAAQ,CAACC,6BAAkB,CAAC,EAAE;IACpC,OAAOP,KAAK;EAChB;EAEA,MAAM;IAAEG,EAAE;IAAEK;EAAQ,CAAC,GAAG,IAAAJ,gCAAe,EAACJ,KAAK,CAAC;EAC9C,OAAO,GAAGO,6BAAkB,GAAGJ,EAAE,IAAI,IAAAM,gBAAO,EAACD,OAAO,IAAI,CAAC,CAAC,EAAE;AAChE,CAAC;AAACH,OAAA,CAAAH,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CmsScheduleCallable } from "../types.js";
|
|
2
|
+
import type { ISchedulerService } from "../service/types.js";
|
|
3
|
+
import type { CmsContext, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
import type { ScheduleFetcherCms } from "./ScheduleFetcher.js";
|
|
5
|
+
import type { ScheduleExecutorCms } from "./ScheduleExecutor.js";
|
|
6
|
+
export interface ICreateSchedulerParams {
|
|
7
|
+
security: Pick<CmsContext["security"], "getIdentity">;
|
|
8
|
+
cms: ScheduleExecutorCms & ScheduleFetcherCms;
|
|
9
|
+
service: ISchedulerService;
|
|
10
|
+
schedulerModel: CmsModel;
|
|
11
|
+
}
|
|
12
|
+
export declare const createScheduler: (params: ICreateSchedulerParams) => Promise<CmsScheduleCallable>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createScheduler = void 0;
|
|
7
|
+
var _Scheduler = require("./Scheduler.js");
|
|
8
|
+
var _ScheduleFetcher = require("./ScheduleFetcher.js");
|
|
9
|
+
var _ScheduleExecutor = require("./ScheduleExecutor.js");
|
|
10
|
+
var _PublishScheduleAction = require("./actions/PublishScheduleAction.js");
|
|
11
|
+
var _UnpublishScheduleAction = require("./actions/UnpublishScheduleAction.js");
|
|
12
|
+
var _error = require("@webiny/error");
|
|
13
|
+
const createScheduler = async params => {
|
|
14
|
+
const {
|
|
15
|
+
cms,
|
|
16
|
+
security,
|
|
17
|
+
schedulerModel,
|
|
18
|
+
service
|
|
19
|
+
} = params;
|
|
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
|
+
}
|
|
26
|
+
const getIdentity = () => {
|
|
27
|
+
const identity = security.getIdentity();
|
|
28
|
+
if (!identity) {
|
|
29
|
+
throw new Error("No identity found in security context.");
|
|
30
|
+
}
|
|
31
|
+
return identity;
|
|
32
|
+
};
|
|
33
|
+
const fetcher = new _ScheduleFetcher.ScheduleFetcher({
|
|
34
|
+
targetModel,
|
|
35
|
+
schedulerModel,
|
|
36
|
+
cms
|
|
37
|
+
});
|
|
38
|
+
const actions = [new _PublishScheduleAction.PublishScheduleAction({
|
|
39
|
+
cms,
|
|
40
|
+
schedulerModel,
|
|
41
|
+
targetModel,
|
|
42
|
+
service,
|
|
43
|
+
getIdentity,
|
|
44
|
+
fetcher
|
|
45
|
+
}), new _UnpublishScheduleAction.UnpublishScheduleAction({
|
|
46
|
+
cms,
|
|
47
|
+
schedulerModel,
|
|
48
|
+
targetModel,
|
|
49
|
+
service,
|
|
50
|
+
getIdentity,
|
|
51
|
+
fetcher
|
|
52
|
+
})];
|
|
53
|
+
const executor = new _ScheduleExecutor.ScheduleExecutor({
|
|
54
|
+
actions,
|
|
55
|
+
fetcher
|
|
56
|
+
});
|
|
57
|
+
return new _Scheduler.Scheduler({
|
|
58
|
+
fetcher,
|
|
59
|
+
executor
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.createScheduler = createScheduler;
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=createScheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DateISOString } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* We can safely cast the result of `toISOString()` to `DateISOString` type,
|
|
4
|
+
* We need this to ensure that no malformed date strings are used in the scheduler.
|
|
5
|
+
*/
|
|
6
|
+
export declare const dateToISOString: (value: Date) => DateISOString;
|
|
7
|
+
export declare const isoStringToDate: (value: DateISOString | undefined) => Date | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isoStringToDate = exports.dateToISOString = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* We can safely cast the result of `toISOString()` to `DateISOString` type,
|
|
9
|
+
* We need this to ensure that no malformed date strings are used in the scheduler.
|
|
10
|
+
*/
|
|
11
|
+
const dateToISOString = value => {
|
|
12
|
+
return value.toISOString();
|
|
13
|
+
};
|
|
14
|
+
exports.dateToISOString = dateToISOString;
|
|
15
|
+
const isoStringToDate = value => {
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
try {
|
|
18
|
+
return new Date(value);
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
exports.isoStringToDate = isoStringToDate;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["dateToISOString","value","toISOString","exports","isoStringToDate","Date","undefined"],"sources":["dates.ts"],"sourcesContent":["import type { DateISOString } from \"~/scheduler/types.js\";\n\n/**\n * We can safely cast the result of `toISOString()` to `DateISOString` type,\n * We need this to ensure that no malformed date strings are used in the scheduler.\n */\nexport const dateToISOString = (value: Date): DateISOString => {\n return value.toISOString() as DateISOString;\n};\n\nexport const isoStringToDate = (value: DateISOString | undefined): Date | undefined => {\n if (typeof value === \"string\") {\n try {\n return new Date(value);\n } catch {\n return undefined;\n }\n }\n return undefined;\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,eAAe,GAAIC,KAAW,IAAoB;EAC3D,OAAOA,KAAK,CAACC,WAAW,CAAC,CAAC;AAC9B,CAAC;AAACC,OAAA,CAAAH,eAAA,GAAAA,eAAA;AAEK,MAAMI,eAAe,GAAIH,KAAgC,IAAuB;EACnF,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,IAAI;MACA,OAAO,IAAII,IAAI,CAACJ,KAAK,CAAC;IAC1B,CAAC,CAAC,MAAM;MACJ,OAAOK,SAAS;IACpB;EACJ;EACA,OAAOA,SAAS;AACpB,CAAC;AAACH,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createSchedulerModel: () => import("@webiny/api-headless-cms/plugins/CmsModelPlugin").CmsModelPlugin;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSchedulerModel = void 0;
|
|
7
|
+
var _index = require("@webiny/api-headless-cms/plugins/index.js");
|
|
8
|
+
var _constants = require("../constants.js");
|
|
9
|
+
const createSchedulerModel = () => {
|
|
10
|
+
return (0, _index.createPrivateModelPlugin)({
|
|
11
|
+
noValidate: true,
|
|
12
|
+
modelId: _constants.SCHEDULE_MODEL_ID,
|
|
13
|
+
name: "Webiny CMS Schedule",
|
|
14
|
+
fields: [{
|
|
15
|
+
id: "targetId",
|
|
16
|
+
fieldId: "targetId",
|
|
17
|
+
storageId: "text@targetId",
|
|
18
|
+
type: "text",
|
|
19
|
+
label: "Target ID"
|
|
20
|
+
}, {
|
|
21
|
+
id: "targetModelId",
|
|
22
|
+
fieldId: "targetModelId",
|
|
23
|
+
storageId: "text@targetModelId",
|
|
24
|
+
type: "text",
|
|
25
|
+
label: "Target Model ID"
|
|
26
|
+
}, {
|
|
27
|
+
id: "scheduledBy",
|
|
28
|
+
fieldId: "scheduledBy",
|
|
29
|
+
storageId: "text@scheduledBy",
|
|
30
|
+
type: "object",
|
|
31
|
+
label: "Scheduled By",
|
|
32
|
+
settings: {
|
|
33
|
+
fields: [{
|
|
34
|
+
id: "id",
|
|
35
|
+
fieldId: "id",
|
|
36
|
+
storageId: "text@id",
|
|
37
|
+
type: "text",
|
|
38
|
+
label: "Identity ID"
|
|
39
|
+
}, {
|
|
40
|
+
id: "displayName",
|
|
41
|
+
fieldId: "displayName",
|
|
42
|
+
storageId: "text@displayName",
|
|
43
|
+
type: "text",
|
|
44
|
+
label: "Display Name"
|
|
45
|
+
}, {
|
|
46
|
+
id: "type",
|
|
47
|
+
fieldId: "type",
|
|
48
|
+
storageId: "text@type",
|
|
49
|
+
type: "text",
|
|
50
|
+
label: "Type"
|
|
51
|
+
}]
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
id: "scheduledOn",
|
|
55
|
+
fieldId: "scheduledOn",
|
|
56
|
+
storageId: "date@scheduledOn",
|
|
57
|
+
type: "datetime",
|
|
58
|
+
label: "Scheduled On"
|
|
59
|
+
}, {
|
|
60
|
+
id: "dateOn",
|
|
61
|
+
fieldId: "dateOn",
|
|
62
|
+
storageId: "date@dateOn",
|
|
63
|
+
type: "datetime",
|
|
64
|
+
label: "Date On"
|
|
65
|
+
}, {
|
|
66
|
+
id: "type",
|
|
67
|
+
fieldId: "type",
|
|
68
|
+
storageId: "text@type",
|
|
69
|
+
type: "text",
|
|
70
|
+
label: "Type"
|
|
71
|
+
}, {
|
|
72
|
+
id: "title",
|
|
73
|
+
fieldId: "title",
|
|
74
|
+
storageId: "text@title",
|
|
75
|
+
type: "text",
|
|
76
|
+
label: "Title"
|
|
77
|
+
}, {
|
|
78
|
+
id: "error",
|
|
79
|
+
fieldId: "error",
|
|
80
|
+
storageId: "text@error",
|
|
81
|
+
type: "text",
|
|
82
|
+
label: "Error"
|
|
83
|
+
}]
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
exports.createSchedulerModel = createSchedulerModel;
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_index","require","_constants","createSchedulerModel","createPrivateModelPlugin","noValidate","modelId","SCHEDULE_MODEL_ID","name","fields","id","fieldId","storageId","type","label","settings","exports"],"sources":["model.ts"],"sourcesContent":["import { createPrivateModelPlugin } from \"@webiny/api-headless-cms/plugins/index.js\";\nimport { SCHEDULE_MODEL_ID } from \"~/constants.js\";\n\nexport const createSchedulerModel = () => {\n return createPrivateModelPlugin({\n noValidate: true,\n modelId: SCHEDULE_MODEL_ID,\n name: \"Webiny CMS Schedule\",\n fields: [\n {\n id: \"targetId\",\n fieldId: \"targetId\",\n storageId: \"text@targetId\",\n type: \"text\",\n label: \"Target ID\"\n },\n {\n id: \"targetModelId\",\n fieldId: \"targetModelId\",\n storageId: \"text@targetModelId\",\n type: \"text\",\n label: \"Target Model ID\"\n },\n {\n id: \"scheduledBy\",\n fieldId: \"scheduledBy\",\n storageId: \"text@scheduledBy\",\n type: \"object\",\n label: \"Scheduled By\",\n settings: {\n fields: [\n {\n id: \"id\",\n fieldId: \"id\",\n storageId: \"text@id\",\n type: \"text\",\n label: \"Identity ID\"\n },\n {\n id: \"displayName\",\n fieldId: \"displayName\",\n storageId: \"text@displayName\",\n type: \"text\",\n label: \"Display Name\"\n },\n {\n id: \"type\",\n fieldId: \"type\",\n storageId: \"text@type\",\n type: \"text\",\n label: \"Type\"\n }\n ]\n }\n },\n {\n id: \"scheduledOn\",\n fieldId: \"scheduledOn\",\n storageId: \"date@scheduledOn\",\n type: \"datetime\",\n label: \"Scheduled On\"\n },\n {\n id: \"dateOn\",\n fieldId: \"dateOn\",\n storageId: \"date@dateOn\",\n type: \"datetime\",\n label: \"Date On\"\n },\n {\n id: \"type\",\n fieldId: \"type\",\n storageId: \"text@type\",\n type: \"text\",\n label: \"Type\"\n },\n {\n id: \"title\",\n fieldId: \"title\",\n storageId: \"text@title\",\n type: \"text\",\n label: \"Title\"\n },\n {\n id: \"error\",\n fieldId: \"error\",\n storageId: \"text@error\",\n type: \"text\",\n label: \"Error\"\n }\n ]\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEO,MAAME,oBAAoB,GAAGA,CAAA,KAAM;EACtC,OAAO,IAAAC,+BAAwB,EAAC;IAC5BC,UAAU,EAAE,IAAI;IAChBC,OAAO,EAAEC,4BAAiB;IAC1BC,IAAI,EAAE,qBAAqB;IAC3BC,MAAM,EAAE,CACJ;MACIC,EAAE,EAAE,UAAU;MACdC,OAAO,EAAE,UAAU;MACnBC,SAAS,EAAE,eAAe;MAC1BC,IAAI,EAAE,MAAM;MACZC,KAAK,EAAE;IACX,CAAC,EACD;MACIJ,EAAE,EAAE,eAAe;MACnBC,OAAO,EAAE,eAAe;MACxBC,SAAS,EAAE,oBAAoB;MAC/BC,IAAI,EAAE,MAAM;MACZC,KAA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