@webiny/api-headless-cms-scheduler 0.0.0-unstable.e53eceafb5
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 +63 -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/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 +33 -0
- package/scheduler/ScheduleRecord.js +56 -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 +209 -0
- package/scheduler/actions/PublishScheduleAction.js.map +1 -0
- package/scheduler/actions/UnpublishScheduleAction.d.ts +26 -0
- package/scheduler/actions/UnpublishScheduleAction.js +199 -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 +59 -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 +92 -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,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
|
+
scheduleModel: 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 scheduleModel;
|
|
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 getUpdateableTargetEntry;
|
|
26
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 _error = require("@webiny/error");
|
|
14
|
+
var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
|
|
15
|
+
class UnpublishScheduleAction {
|
|
16
|
+
constructor(params) {
|
|
17
|
+
this.service = params.service;
|
|
18
|
+
this.cms = params.cms;
|
|
19
|
+
this.targetModel = params.targetModel;
|
|
20
|
+
this.scheduleModel = params.scheduleModel;
|
|
21
|
+
this.getIdentity = params.getIdentity;
|
|
22
|
+
this.fetcher = params.fetcher;
|
|
23
|
+
}
|
|
24
|
+
canHandle(input) {
|
|
25
|
+
return input.type === _types.ScheduleType.unpublish;
|
|
26
|
+
}
|
|
27
|
+
async schedule(params) {
|
|
28
|
+
const {
|
|
29
|
+
targetId,
|
|
30
|
+
input,
|
|
31
|
+
scheduleRecordId
|
|
32
|
+
} = params;
|
|
33
|
+
const targetEntry = await this.getUpdateableTargetEntry(targetId);
|
|
34
|
+
const title = targetEntry.values[this.targetModel.titleFieldId] || "Unknown entry title";
|
|
35
|
+
const identity = this.getIdentity();
|
|
36
|
+
const currentDate = new Date();
|
|
37
|
+
/**
|
|
38
|
+
* Immediately unpublish the entry if requested.
|
|
39
|
+
*/
|
|
40
|
+
if (input.immediately) {
|
|
41
|
+
const unpublishedEntry = await this.cms.unpublishEntry(this.targetModel, targetId);
|
|
42
|
+
return (0, _ScheduleRecord.createScheduleRecord)({
|
|
43
|
+
id: scheduleRecordId,
|
|
44
|
+
targetId,
|
|
45
|
+
model: this.targetModel,
|
|
46
|
+
scheduledBy: unpublishedEntry.savedBy,
|
|
47
|
+
scheduledOn: currentDate,
|
|
48
|
+
dateOn: currentDate,
|
|
49
|
+
type: _types.ScheduleType.unpublish,
|
|
50
|
+
title
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* If the entry is scheduled for a date in the past, we need to unpublish it immediately.
|
|
55
|
+
* No need to create a schedule entry or the service event.
|
|
56
|
+
*/
|
|
57
|
+
//
|
|
58
|
+
else if (input.scheduleOn < currentDate) {
|
|
59
|
+
await this.cms.unpublishEntry(this.targetModel, targetId);
|
|
60
|
+
return (0, _ScheduleRecord.createScheduleRecord)({
|
|
61
|
+
id: scheduleRecordId,
|
|
62
|
+
targetId,
|
|
63
|
+
model: this.targetModel,
|
|
64
|
+
scheduledBy: identity,
|
|
65
|
+
scheduledOn: input.scheduleOn,
|
|
66
|
+
dateOn: input.dateOn,
|
|
67
|
+
type: _types.ScheduleType.unpublish,
|
|
68
|
+
title
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* If the entry is scheduled for a future date, we need to create a schedule entry and a service event.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
const {
|
|
76
|
+
id: scheduleEntryId
|
|
77
|
+
} = (0, _parseIdentifier.parseIdentifier)(scheduleRecordId);
|
|
78
|
+
const scheduleEntry = await this.cms.createEntry(this.scheduleModel, {
|
|
79
|
+
id: scheduleEntryId,
|
|
80
|
+
targetId,
|
|
81
|
+
targetModelId: this.targetModel.modelId,
|
|
82
|
+
title,
|
|
83
|
+
type: _types.ScheduleType.unpublish,
|
|
84
|
+
dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined,
|
|
85
|
+
scheduledBy: identity,
|
|
86
|
+
scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn)
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
await this.service.create({
|
|
90
|
+
id: scheduleRecordId,
|
|
91
|
+
scheduleOn: input.scheduleOn
|
|
92
|
+
});
|
|
93
|
+
} catch (ex) {
|
|
94
|
+
console.error(`Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`);
|
|
95
|
+
console.log((0, _utils.convertException)(ex));
|
|
96
|
+
try {
|
|
97
|
+
await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);
|
|
100
|
+
console.log((0, _utils.convertException)(err));
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
throw ex;
|
|
104
|
+
}
|
|
105
|
+
return (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, scheduleEntry);
|
|
106
|
+
}
|
|
107
|
+
async reschedule(original, input) {
|
|
108
|
+
const currentDate = new Date();
|
|
109
|
+
const targetId = original.targetId;
|
|
110
|
+
const targetEntry = await this.getUpdateableTargetEntry(targetId);
|
|
111
|
+
/**
|
|
112
|
+
* There are two cases when we can immediately publish the entry:
|
|
113
|
+
* 1. If the user requested it.
|
|
114
|
+
* 2. If the entry is scheduled for a date in the past.
|
|
115
|
+
*/
|
|
116
|
+
if (input.immediately || (0, _dateInTheFuture.dateInTheFuture)(input.scheduleOn)) {
|
|
117
|
+
const publishedEntry = await this.cms.unpublishEntry(this.targetModel, targetEntry.id);
|
|
118
|
+
/**
|
|
119
|
+
* We can safely cancel the original schedule entry and the event.
|
|
120
|
+
*
|
|
121
|
+
* // TODO determine if we want to ignore the error of the cancelation.
|
|
122
|
+
*/
|
|
123
|
+
try {
|
|
124
|
+
await this.cancel(original.id);
|
|
125
|
+
} catch {
|
|
126
|
+
//
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
...original,
|
|
130
|
+
publishOn: undefined,
|
|
131
|
+
unpublishOn: currentDate,
|
|
132
|
+
dateOn: publishedEntry.lastPublishedOn ? new Date(publishedEntry.lastPublishedOn) : undefined
|
|
133
|
+
};
|
|
134
|
+
}
|
|
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
|
|
138
|
+
});
|
|
139
|
+
try {
|
|
140
|
+
await this.service.update({
|
|
141
|
+
id: original.id,
|
|
142
|
+
scheduleOn: input.scheduleOn
|
|
143
|
+
});
|
|
144
|
+
} catch (ex) {
|
|
145
|
+
console.error(`Could not update service event for schedule entry: ${original.id}.`);
|
|
146
|
+
console.log((0, _utils.convertException)(ex));
|
|
147
|
+
throw ex;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
...original,
|
|
151
|
+
publishOn: undefined,
|
|
152
|
+
unpublishOn: currentDate,
|
|
153
|
+
dateOn: input.dateOn
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async cancel(id) {
|
|
157
|
+
/**
|
|
158
|
+
* No need to do anything if the record does not exist.
|
|
159
|
+
*/
|
|
160
|
+
let scheduleRecord = null;
|
|
161
|
+
try {
|
|
162
|
+
scheduleRecord = await this.fetcher.getScheduled(id);
|
|
163
|
+
if (!scheduleRecord) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
await this.cms.deleteEntry(this.scheduleModel, scheduleRecord.id);
|
|
171
|
+
} catch (ex) {
|
|
172
|
+
if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
console.error(`Error while deleting schedule entry: ${scheduleRecord.id}.`);
|
|
176
|
+
console.log((0, _utils.convertException)(ex));
|
|
177
|
+
throw ex;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
await this.service.delete(scheduleRecord.id);
|
|
181
|
+
} catch (ex) {
|
|
182
|
+
console.error(`Error while deleting service event for schedule entry: ${scheduleRecord.id}.`);
|
|
183
|
+
console.log((0, _utils.convertException)(ex));
|
|
184
|
+
throw ex;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
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;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.UnpublishScheduleAction = UnpublishScheduleAction;
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=UnpublishScheduleAction.js.map
|
|
@@ -0,0 +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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|
|
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
|
+
scheduleModel: CmsModel;
|
|
11
|
+
}
|
|
12
|
+
export declare const createScheduler: (params: ICreateSchedulerParams) => Promise<CmsScheduleCallable>;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
const createScheduler = async params => {
|
|
13
|
+
const {
|
|
14
|
+
cms,
|
|
15
|
+
security,
|
|
16
|
+
scheduleModel,
|
|
17
|
+
service
|
|
18
|
+
} = params;
|
|
19
|
+
return targetModel => {
|
|
20
|
+
const getIdentity = () => {
|
|
21
|
+
const identity = security.getIdentity();
|
|
22
|
+
if (!identity) {
|
|
23
|
+
throw new Error("No identity found in security context.");
|
|
24
|
+
}
|
|
25
|
+
return identity;
|
|
26
|
+
};
|
|
27
|
+
const fetcher = new _ScheduleFetcher.ScheduleFetcher({
|
|
28
|
+
targetModel,
|
|
29
|
+
scheduleModel,
|
|
30
|
+
cms
|
|
31
|
+
});
|
|
32
|
+
const actions = [new _PublishScheduleAction.PublishScheduleAction({
|
|
33
|
+
cms,
|
|
34
|
+
scheduleModel,
|
|
35
|
+
targetModel,
|
|
36
|
+
service,
|
|
37
|
+
getIdentity,
|
|
38
|
+
fetcher
|
|
39
|
+
}), new _UnpublishScheduleAction.UnpublishScheduleAction({
|
|
40
|
+
cms,
|
|
41
|
+
scheduleModel,
|
|
42
|
+
targetModel,
|
|
43
|
+
service,
|
|
44
|
+
getIdentity,
|
|
45
|
+
fetcher
|
|
46
|
+
})];
|
|
47
|
+
const executor = new _ScheduleExecutor.ScheduleExecutor({
|
|
48
|
+
actions,
|
|
49
|
+
fetcher
|
|
50
|
+
});
|
|
51
|
+
return new _Scheduler.Scheduler({
|
|
52
|
+
fetcher,
|
|
53
|
+
executor
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.createScheduler = createScheduler;
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=createScheduler.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -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,KAAK,EAAE;IACX,CAA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AAE,MAAM;MACZC,KAAK,EAAE;IACX,CAAC;EAET,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAb,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { CmsEntryListSort, CmsEntryMeta, CmsIdentity, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
export declare enum ScheduleType {
|
|
3
|
+
publish = "publish",
|
|
4
|
+
unpublish = "unpublish"
|
|
5
|
+
}
|
|
6
|
+
export type DateISOString = `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`;
|
|
7
|
+
/**
|
|
8
|
+
* A date when the action is to be scheduled.
|
|
9
|
+
*/
|
|
10
|
+
export type ScheduledOnType = Date;
|
|
11
|
+
/**
|
|
12
|
+
* A custom date when the action is to be set as done (publishedOn and related dates).
|
|
13
|
+
*/
|
|
14
|
+
export type DateOnType = Date;
|
|
15
|
+
export interface ISchedulerInputImmediately {
|
|
16
|
+
immediately: true;
|
|
17
|
+
scheduleOn?: never;
|
|
18
|
+
dateOn?: DateOnType;
|
|
19
|
+
type: ScheduleType;
|
|
20
|
+
}
|
|
21
|
+
export interface ISchedulerInputScheduled {
|
|
22
|
+
immediately?: false;
|
|
23
|
+
scheduleOn: ScheduledOnType;
|
|
24
|
+
dateOn?: DateOnType;
|
|
25
|
+
type: ScheduleType;
|
|
26
|
+
}
|
|
27
|
+
export type ISchedulerInput = ISchedulerInputScheduled | ISchedulerInputImmediately;
|
|
28
|
+
export interface IScheduleRecord {
|
|
29
|
+
id: string;
|
|
30
|
+
targetId: string;
|
|
31
|
+
model: CmsModel;
|
|
32
|
+
scheduledBy: CmsIdentity;
|
|
33
|
+
dateOn: DateOnType | undefined;
|
|
34
|
+
publishOn: ScheduledOnType | undefined;
|
|
35
|
+
unpublishOn: ScheduledOnType | undefined;
|
|
36
|
+
type: ScheduleType;
|
|
37
|
+
title: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ISchedulerListResponse {
|
|
40
|
+
data: IScheduleRecord[];
|
|
41
|
+
meta: CmsEntryMeta;
|
|
42
|
+
}
|
|
43
|
+
export interface ISchedulerListParamsWhere {
|
|
44
|
+
targetId?: string;
|
|
45
|
+
targetEntryId?: string;
|
|
46
|
+
type?: ScheduleType;
|
|
47
|
+
scheduledBy?: string;
|
|
48
|
+
scheduledOn?: DateISOString;
|
|
49
|
+
scheduledOn_gte?: DateISOString;
|
|
50
|
+
scheduledOn_lte?: DateISOString;
|
|
51
|
+
}
|
|
52
|
+
export interface ISchedulerListParams {
|
|
53
|
+
where: ISchedulerListParamsWhere;
|
|
54
|
+
sort: CmsEntryListSort | undefined;
|
|
55
|
+
limit: number | undefined;
|
|
56
|
+
after: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
export interface IScheduler {
|
|
59
|
+
schedule(id: string, input: ISchedulerInput): Promise<IScheduleRecord>;
|
|
60
|
+
cancel(id: string): Promise<IScheduleRecord>;
|
|
61
|
+
getScheduled(id: string): Promise<IScheduleRecord | null>;
|
|
62
|
+
listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;
|
|
63
|
+
}
|
|
64
|
+
export interface IScheduleEntryValues {
|
|
65
|
+
targetId: string;
|
|
66
|
+
targetModelId: string;
|
|
67
|
+
scheduledBy: CmsIdentity;
|
|
68
|
+
dateOn: DateISOString | undefined;
|
|
69
|
+
scheduledOn: DateISOString;
|
|
70
|
+
type: string;
|
|
71
|
+
title: string;
|
|
72
|
+
error?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface IScheduleExecutor {
|
|
75
|
+
schedule(targetId: string, input: ISchedulerInput): Promise<IScheduleRecord>;
|
|
76
|
+
cancel(id: string): Promise<IScheduleRecord>;
|
|
77
|
+
}
|
|
78
|
+
export interface IScheduleFetcher {
|
|
79
|
+
getScheduled(targetId: string): Promise<IScheduleRecord | null>;
|
|
80
|
+
listScheduled(params: ISchedulerListParams): Promise<ISchedulerListResponse>;
|
|
81
|
+
}
|
|
82
|
+
export interface IScheduleActionScheduleParams {
|
|
83
|
+
targetId: string;
|
|
84
|
+
scheduleRecordId: string;
|
|
85
|
+
input: ISchedulerInput;
|
|
86
|
+
}
|
|
87
|
+
export interface IScheduleAction {
|
|
88
|
+
canHandle(input: Pick<ISchedulerInput, "type">): boolean;
|
|
89
|
+
schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord>;
|
|
90
|
+
cancel(id: string): Promise<void>;
|
|
91
|
+
reschedule(original: IScheduleRecord, input: ISchedulerInput): Promise<IScheduleRecord>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScheduleType = void 0;
|
|
7
|
+
let ScheduleType = exports.ScheduleType = /*#__PURE__*/function (ScheduleType) {
|
|
8
|
+
ScheduleType["publish"] = "publish";
|
|
9
|
+
ScheduleType["unpublish"] = "unpublish";
|
|
10
|
+
return ScheduleType;
|
|
11
|
+
}({});
|
|
12
|
+
/**
|
|
13
|
+
* A date when the action is to be scheduled.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* A custom date when the action is to be set as done (publishedOn and related dates).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +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":[]}
|