@webiny/api-headless-cms-scheduler 0.0.0-unstable.3bc8100a7f → 0.0.0-unstable.3fddf667ea
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/CmsSchedulerFeature.d.ts +4 -0
- package/CmsSchedulerFeature.js +23 -0
- package/CmsSchedulerFeature.js.map +1 -0
- package/README.md +11 -15
- package/exports/api/cms/scheduler.d.ts +2 -0
- package/exports/api/cms/scheduler.js +2 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.d.ts +22 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js +49 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnEntryDeleteEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.d.ts +21 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js +41 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnPublishEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.d.ts +21 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js +40 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnRevisionDeleteEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.d.ts +21 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js +41 -0
- package/features/CancelScheduledActionOnEntryChange/CancelScheduledActionOnUnpublishEventHandler.js.map +1 -0
- package/features/CancelScheduledActionOnEntryChange/feature.d.ts +11 -0
- package/features/CancelScheduledActionOnEntryChange/feature.js +17 -0
- package/features/CancelScheduledActionOnEntryChange/feature.js.map +1 -0
- package/features/NamespaceHandler/NamespaceHandler.d.ts +15 -0
- package/features/NamespaceHandler/NamespaceHandler.js +44 -0
- package/features/NamespaceHandler/NamespaceHandler.js.map +1 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.d.ts +35 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.js +92 -0
- package/features/PublishActionHandler/PublishEntryActionHandler.js.map +1 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.d.ts +15 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js +47 -0
- package/features/SchedulePublishEntryUseCase/SchedulePublishEntryUseCase.js.map +1 -0
- package/features/SchedulePublishEntryUseCase/abstractions.d.ts +24 -0
- package/features/SchedulePublishEntryUseCase/abstractions.js +5 -0
- package/features/SchedulePublishEntryUseCase/abstractions.js.map +1 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.d.ts +15 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js +47 -0
- package/features/ScheduleUnpublishEntryUseCase/ScheduleUnpublishEntryUseCase.js.map +1 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.d.ts +24 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.js +5 -0
- package/features/ScheduleUnpublishEntryUseCase/abstractions.js.map +1 -0
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.d.ts +30 -0
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js +69 -0
- package/features/UnpublishActionHandler/UnpublishEntryActionHandler.js.map +1 -0
- package/features/permissions/CmsSchedulerPermissions.d.ts +13 -0
- package/features/permissions/CmsSchedulerPermissions.js +31 -0
- package/features/permissions/CmsSchedulerPermissions.js.map +1 -0
- package/index.d.ts +1 -10
- package/index.js +1 -29
- package/package.json +21 -26
- package/types.d.ts +3 -10
- package/types.js +0 -7
- package/utils/namespace.d.ts +4 -0
- package/utils/namespace.js +9 -0
- package/utils/namespace.js.map +1 -0
- package/constants.d.ts +0 -11
- package/constants.js +0 -19
- package/constants.js.map +0 -1
- package/context.d.ts +0 -7
- package/context.js +0 -63
- package/context.js.map +0 -1
- package/graphql/index.d.ts +0 -3
- package/graphql/index.js +0 -204
- package/graphql/index.js.map +0 -1
- package/graphql/schema.d.ts +0 -217
- package/graphql/schema.js +0 -87
- package/graphql/schema.js.map +0 -1
- package/handler/Handler.d.ts +0 -23
- package/handler/Handler.js +0 -74
- package/handler/Handler.js.map +0 -1
- package/handler/actions/PublishHandlerAction.d.ts +0 -13
- package/handler/actions/PublishHandlerAction.js +0 -64
- package/handler/actions/PublishHandlerAction.js.map +0 -1
- package/handler/actions/UnpublishHandlerAction.d.ts +0 -13
- package/handler/actions/UnpublishHandlerAction.js +0 -53
- package/handler/actions/UnpublishHandlerAction.js.map +0 -1
- package/handler/index.d.ts +0 -7
- package/handler/index.js +0 -64
- package/handler/index.js.map +0 -1
- package/handler/types.d.ts +0 -5
- package/handler/types.js +0 -7
- package/handler/types.js.map +0 -1
- package/index.js.map +0 -1
- package/manifest.d.ts +0 -17
- package/manifest.js +0 -47
- package/manifest.js.map +0 -1
- package/scheduler/ScheduleExecutor.d.ts +0 -16
- package/scheduler/ScheduleExecutor.js +0 -55
- package/scheduler/ScheduleExecutor.js.map +0 -1
- package/scheduler/ScheduleFetcher.d.ts +0 -16
- package/scheduler/ScheduleFetcher.js +0 -51
- package/scheduler/ScheduleFetcher.js.map +0 -1
- package/scheduler/ScheduleRecord.d.ts +0 -33
- package/scheduler/ScheduleRecord.js +0 -56
- package/scheduler/ScheduleRecord.js.map +0 -1
- package/scheduler/Scheduler.d.ts +0 -14
- package/scheduler/Scheduler.js +0 -27
- package/scheduler/Scheduler.js.map +0 -1
- package/scheduler/actions/PublishScheduleAction.d.ts +0 -26
- package/scheduler/actions/PublishScheduleAction.js +0 -209
- package/scheduler/actions/PublishScheduleAction.js.map +0 -1
- package/scheduler/actions/UnpublishScheduleAction.d.ts +0 -26
- package/scheduler/actions/UnpublishScheduleAction.js +0 -199
- package/scheduler/actions/UnpublishScheduleAction.js.map +0 -1
- package/scheduler/createScheduleRecordId.d.ts +0 -2
- package/scheduler/createScheduleRecordId.js +0 -33
- package/scheduler/createScheduleRecordId.js.map +0 -1
- package/scheduler/createScheduler.d.ts +0 -12
- package/scheduler/createScheduler.js +0 -59
- package/scheduler/createScheduler.js.map +0 -1
- package/scheduler/dates.d.ts +0 -7
- package/scheduler/dates.js +0 -27
- package/scheduler/dates.js.map +0 -1
- package/scheduler/model.d.ts +0 -1
- package/scheduler/model.js +0 -88
- package/scheduler/model.js.map +0 -1
- package/scheduler/types.d.ts +0 -92
- package/scheduler/types.js +0 -19
- package/scheduler/types.js.map +0 -1
- package/service/SchedulerService.d.ts +0 -23
- package/service/SchedulerService.js +0 -151
- package/service/SchedulerService.js.map +0 -1
- package/service/types.d.ts +0 -19
- package/service/types.js +0 -7
- package/service/types.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/dateInTheFuture.d.ts +0 -6
- package/utils/dateInTheFuture.js +0 -19
- package/utils/dateInTheFuture.js.map +0 -1
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PublishScheduleAction = void 0;
|
|
7
|
-
var _types = require("../types.js");
|
|
8
|
-
var _ScheduleRecord = require("../ScheduleRecord.js");
|
|
9
|
-
var _utils = require("@webiny/utils");
|
|
10
|
-
var _dates = require("../dates.js");
|
|
11
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
12
|
-
var _dateInTheFuture = require("../../utils/dateInTheFuture.js");
|
|
13
|
-
var _index = require("@webiny/error/index");
|
|
14
|
-
var _parseIdentifier = require("@webiny/utils/parseIdentifier.js");
|
|
15
|
-
class PublishScheduleAction {
|
|
16
|
-
constructor(params) {
|
|
17
|
-
this.service = params.service;
|
|
18
|
-
this.cms = params.cms;
|
|
19
|
-
this.targetModel = params.targetModel;
|
|
20
|
-
this.scheduleModel = params.scheduleModel;
|
|
21
|
-
this.getIdentity = params.getIdentity;
|
|
22
|
-
this.fetcher = params.fetcher;
|
|
23
|
-
}
|
|
24
|
-
canHandle(input) {
|
|
25
|
-
return input.type === _types.ScheduleType.publish;
|
|
26
|
-
}
|
|
27
|
-
async schedule(params) {
|
|
28
|
-
const {
|
|
29
|
-
targetId,
|
|
30
|
-
input,
|
|
31
|
-
scheduleRecordId
|
|
32
|
-
} = params;
|
|
33
|
-
const targetEntry = await this.getUpdateableTargetEntry(targetId);
|
|
34
|
-
const title = targetEntry.values[this.targetModel.titleFieldId] || "Unknown entry title";
|
|
35
|
-
const identity = this.getIdentity();
|
|
36
|
-
const currentDate = new Date();
|
|
37
|
-
/**
|
|
38
|
-
* Immediately publish the entry if requested.
|
|
39
|
-
* No need to create a schedule entry or the service event.
|
|
40
|
-
*/
|
|
41
|
-
if (input.immediately) {
|
|
42
|
-
const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);
|
|
43
|
-
return (0, _ScheduleRecord.createScheduleRecord)({
|
|
44
|
-
id: scheduleRecordId,
|
|
45
|
-
targetId,
|
|
46
|
-
model: this.targetModel,
|
|
47
|
-
scheduledBy: publishedEntry.savedBy,
|
|
48
|
-
scheduledOn: new Date(publishedEntry.savedOn),
|
|
49
|
-
dateOn: currentDate,
|
|
50
|
-
type: _types.ScheduleType.publish,
|
|
51
|
-
title
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* If the entry is scheduled for a date in the past, we need to update it with publish information, if user sent something.
|
|
56
|
-
* No need to create a schedule entry or the service event.
|
|
57
|
-
*/
|
|
58
|
-
//
|
|
59
|
-
else if ((0, _dateInTheFuture.dateInTheFuture)(input.scheduleOn) === false) {
|
|
60
|
-
/**
|
|
61
|
-
* We need to update the entry with publish information because we cannot update it in the publishing process.
|
|
62
|
-
*/
|
|
63
|
-
await this.cms.updateEntry(this.targetModel, targetId, {
|
|
64
|
-
firstPublishedBy: identity,
|
|
65
|
-
firstPublishedOn: (0, _dates.dateToISOString)(input.scheduleOn),
|
|
66
|
-
lastPublishedOn: (0, _dates.dateToISOString)(input.scheduleOn),
|
|
67
|
-
lastPublishedBy: identity
|
|
68
|
-
});
|
|
69
|
-
const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);
|
|
70
|
-
return (0, _ScheduleRecord.createScheduleRecord)({
|
|
71
|
-
id: scheduleRecordId,
|
|
72
|
-
targetId,
|
|
73
|
-
model: this.targetModel,
|
|
74
|
-
scheduledBy: publishedEntry.savedBy,
|
|
75
|
-
scheduledOn: currentDate,
|
|
76
|
-
dateOn: input.dateOn,
|
|
77
|
-
type: _types.ScheduleType.publish,
|
|
78
|
-
title
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
const {
|
|
82
|
-
id: scheduleEntryId
|
|
83
|
-
} = (0, _parseIdentifier.parseIdentifier)(scheduleRecordId);
|
|
84
|
-
const scheduleEntry = await this.cms.createEntry(this.scheduleModel, {
|
|
85
|
-
id: scheduleEntryId,
|
|
86
|
-
targetId,
|
|
87
|
-
targetModelId: this.targetModel.modelId,
|
|
88
|
-
title,
|
|
89
|
-
type: _types.ScheduleType.publish,
|
|
90
|
-
scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
|
|
91
|
-
dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined,
|
|
92
|
-
scheduledBy: identity
|
|
93
|
-
});
|
|
94
|
-
try {
|
|
95
|
-
await this.service.create({
|
|
96
|
-
id: scheduleRecordId,
|
|
97
|
-
scheduleOn: input.scheduleOn
|
|
98
|
-
});
|
|
99
|
-
} catch (ex) {
|
|
100
|
-
console.error(`Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`);
|
|
101
|
-
console.log((0, _utils.convertException)(ex));
|
|
102
|
-
try {
|
|
103
|
-
await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);
|
|
106
|
-
console.log((0, _utils.convertException)(err));
|
|
107
|
-
throw err;
|
|
108
|
-
}
|
|
109
|
-
throw ex;
|
|
110
|
-
}
|
|
111
|
-
return (0, _ScheduleRecord.transformScheduleEntry)(this.targetModel, scheduleEntry);
|
|
112
|
-
}
|
|
113
|
-
async reschedule(original, input) {
|
|
114
|
-
const currentDate = new Date();
|
|
115
|
-
const targetId = original.targetId;
|
|
116
|
-
const targetEntry = await this.getUpdateableTargetEntry(targetId);
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* There are two cases when we can immediately publish the entry:
|
|
120
|
-
* 1. If the user requested it.
|
|
121
|
-
* 2. If the entry is scheduled for a date in the past.
|
|
122
|
-
*/
|
|
123
|
-
if (input.immediately || input.scheduleOn < currentDate) {
|
|
124
|
-
const updatedTargetEntry = await this.cms.updateEntry(this.targetModel, targetEntry.id, {
|
|
125
|
-
lastPublishedOn: input.dateOn ? input.dateOn.toISOString() : undefined,
|
|
126
|
-
lastPublishedBy: this.getIdentity()
|
|
127
|
-
});
|
|
128
|
-
const publishedEntry = await this.cms.publishEntry(this.targetModel, updatedTargetEntry.id);
|
|
129
|
-
/**
|
|
130
|
-
* We can safely cancel the original schedule entry and the event.
|
|
131
|
-
*
|
|
132
|
-
* // TODO determine if we want to ignore the error of the cancelation.
|
|
133
|
-
*/
|
|
134
|
-
try {
|
|
135
|
-
await this.cancel(original.id);
|
|
136
|
-
} catch {
|
|
137
|
-
//
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
...original,
|
|
141
|
-
publishOn: currentDate,
|
|
142
|
-
unpublishOn: undefined,
|
|
143
|
-
dateOn: publishedEntry.lastPublishedOn ? new Date(publishedEntry.lastPublishedOn) : undefined
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
await this.cms.updateEntry(this.scheduleModel, original.id, {
|
|
147
|
-
scheduledBy: this.getIdentity(),
|
|
148
|
-
scheduledOn: (0, _dates.dateToISOString)(input.scheduleOn),
|
|
149
|
-
dateOn: input.dateOn ? (0, _dates.dateToISOString)(input.dateOn) : undefined
|
|
150
|
-
});
|
|
151
|
-
try {
|
|
152
|
-
await this.service.update({
|
|
153
|
-
id: original.id,
|
|
154
|
-
scheduleOn: input.scheduleOn
|
|
155
|
-
});
|
|
156
|
-
} catch (ex) {
|
|
157
|
-
throw ex;
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
...original,
|
|
161
|
-
publishOn: new Date(),
|
|
162
|
-
unpublishOn: undefined,
|
|
163
|
-
dateOn: input.dateOn
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
async cancel(id) {
|
|
167
|
-
/**
|
|
168
|
-
* No need to do anything if the record does not exist.
|
|
169
|
-
*/
|
|
170
|
-
let scheduleEntry = null;
|
|
171
|
-
try {
|
|
172
|
-
scheduleEntry = await this.fetcher.getScheduled(id);
|
|
173
|
-
if (!scheduleEntry) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
} catch {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
await this.cms.deleteEntry(this.scheduleModel, scheduleEntry.id);
|
|
181
|
-
} catch (ex) {
|
|
182
|
-
if (ex.code === "NOT_FOUND" || ex instanceof _handlerGraphql.NotFoundError) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
console.error(`Error while deleting schedule entry: ${scheduleEntry.id}.`);
|
|
186
|
-
console.log((0, _utils.convertException)(ex));
|
|
187
|
-
throw ex;
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
await this.service.delete(scheduleEntry.id);
|
|
191
|
-
} catch (ex) {
|
|
192
|
-
console.error(`Error while deleting service event for schedule entry: ${scheduleEntry.id}.`);
|
|
193
|
-
console.log((0, _utils.convertException)(ex));
|
|
194
|
-
throw ex;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async getUpdateableTargetEntry(id) {
|
|
198
|
-
const entry = await this.cms.getEntryById(this.targetModel, id);
|
|
199
|
-
if (entry.locked) {
|
|
200
|
-
throw new _index.WebinyError(`Cannot schedule a publish action for entry "${entry.id}" because it is locked.`, "ENTRY_LOCKED", {
|
|
201
|
-
entryId: entry.id
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return entry;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
exports.PublishScheduleAction = PublishScheduleAction;
|
|
208
|
-
|
|
209
|
-
//# sourceMappingURL=PublishScheduleAction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","_ScheduleRecord","_utils","_dates","_handlerGraphql","_dateInTheFuture","_index","_parseIdentifier","PublishScheduleAction","constructor","params","service","cms","targetModel","scheduleModel","getIdentity","fetcher","canHandle","input","type","ScheduleType","publish","schedule","targetId","scheduleRecordId","targetEntry","getUpdateableTargetEntry","title","values","titleFieldId","identity","currentDate","Date","immediately","publishedEntry","publishEntry","createScheduleRecord","id","model","scheduledBy","savedBy","scheduledOn","savedOn","dateOn","dateInTheFuture","scheduleOn","updateEntry","firstPublishedBy","firstPublishedOn","dateToISOString","lastPublishedOn","lastPublishedBy","scheduleEntryId","parseIdentifier","scheduleEntry","createEntry","targetModelId","modelId","undefined","create","ex","console","error","log","convertException","deleteEntry","err","transformScheduleEntry","reschedule","original","updatedTargetEntry","toISOString","cancel","publishOn","unpublishOn","update","getScheduled","code","NotFoundError","delete","entry","getEntryById","locked","WebinyError","entryId","exports"],"sources":["PublishScheduleAction.ts"],"sourcesContent":["import type {\n IScheduleAction,\n IScheduleActionScheduleParams,\n IScheduleEntryValues,\n IScheduleFetcher,\n IScheduleRecord,\n ISchedulerInput\n} from \"~/scheduler/types.js\";\nimport { ScheduleType } from \"~/scheduler/types.js\";\nimport { createScheduleRecord, transformScheduleEntry } from \"~/scheduler/ScheduleRecord.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsIdentity,\n CmsModel,\n HeadlessCms\n} from \"@webiny/api-headless-cms/types\";\nimport type { ISchedulerService } from \"~/service/types.js\";\nimport { dateToISOString } from \"~/scheduler/dates.js\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { dateInTheFuture } from \"~/utils/dateInTheFuture.js\";\nimport { WebinyError } from \"@webiny/error/index\";\nimport { parseIdentifier } from \"@webiny/utils/parseIdentifier.js\";\n\nexport type PublishScheduleActionCms = Pick<\n HeadlessCms,\n \"getEntryById\" | \"publishEntry\" | \"createEntry\" | \"updateEntry\" | \"deleteEntry\"\n>;\n\nexport interface IPublishScheduleActionParams {\n service: ISchedulerService;\n cms: PublishScheduleActionCms;\n targetModel: CmsModel;\n scheduleModel: CmsModel;\n getIdentity: () => CmsIdentity;\n fetcher: IScheduleFetcher;\n}\n\nexport class PublishScheduleAction implements IScheduleAction {\n private readonly service: ISchedulerService;\n private readonly cms: PublishScheduleActionCms;\n private readonly targetModel: CmsModel;\n private readonly scheduleModel: CmsModel;\n private readonly getIdentity: () => CmsIdentity;\n private readonly fetcher: IScheduleFetcher;\n\n public constructor(params: IPublishScheduleActionParams) {\n this.service = params.service;\n this.cms = params.cms;\n this.targetModel = params.targetModel;\n this.scheduleModel = params.scheduleModel;\n this.getIdentity = params.getIdentity;\n this.fetcher = params.fetcher;\n }\n\n public canHandle(input: ISchedulerInput): boolean {\n return input.type === ScheduleType.publish;\n }\n\n public async schedule(params: IScheduleActionScheduleParams): Promise<IScheduleRecord> {\n const { targetId, input, scheduleRecordId } = params;\n\n const targetEntry = await this.getUpdateableTargetEntry(targetId);\n\n const title = targetEntry.values[this.targetModel.titleFieldId] || \"Unknown entry title\";\n const identity = this.getIdentity();\n\n const currentDate = new Date();\n /**\n * Immediately publish the entry if requested.\n * No need to create a schedule entry or the service event.\n */\n if (input.immediately) {\n const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: publishedEntry.savedBy,\n scheduledOn: new Date(publishedEntry.savedOn),\n dateOn: currentDate,\n type: ScheduleType.publish,\n title\n });\n }\n /**\n * If the entry is scheduled for a date in the past, we need to update it with publish information, if user sent something.\n * No need to create a schedule entry or the service event.\n */\n //\n else if (dateInTheFuture(input.scheduleOn) === false) {\n /**\n * We need to update the entry with publish information because we cannot update it in the publishing process.\n */\n await this.cms.updateEntry(this.targetModel, targetId, {\n firstPublishedBy: identity,\n firstPublishedOn: dateToISOString(input.scheduleOn),\n lastPublishedOn: dateToISOString(input.scheduleOn),\n lastPublishedBy: identity\n });\n const publishedEntry = await this.cms.publishEntry(this.targetModel, targetId);\n return createScheduleRecord({\n id: scheduleRecordId,\n targetId,\n model: this.targetModel,\n scheduledBy: publishedEntry.savedBy,\n scheduledOn: currentDate,\n dateOn: input.dateOn,\n type: ScheduleType.publish,\n title\n });\n }\n\n const { id: scheduleEntryId } = parseIdentifier(scheduleRecordId);\n const scheduleEntry = await this.cms.createEntry<IScheduleEntryValues>(this.scheduleModel, {\n id: scheduleEntryId,\n targetId,\n targetModelId: this.targetModel.modelId,\n title,\n type: ScheduleType.publish,\n scheduledOn: dateToISOString(input.scheduleOn),\n dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined,\n scheduledBy: identity\n });\n\n try {\n await this.service.create({\n id: scheduleRecordId,\n scheduleOn: input.scheduleOn\n });\n } catch (ex) {\n console.error(\n `Could not create service event for schedule entry: ${scheduleRecordId}. Deleting the schedule entry...`\n );\n console.log(convertException(ex));\n try {\n await this.cms.deleteEntry(this.scheduleModel, scheduleRecordId);\n } catch (err) {\n console.error(`Error while deleting schedule entry: ${scheduleRecordId}.`);\n console.log(convertException(err));\n throw err;\n }\n throw ex;\n }\n return transformScheduleEntry(this.targetModel, scheduleEntry);\n }\n\n public async reschedule(\n original: IScheduleRecord,\n input: ISchedulerInput\n ): Promise<IScheduleRecord> {\n const currentDate = new Date();\n const targetId = original.targetId;\n\n const targetEntry = await this.getUpdateableTargetEntry(targetId);\n\n /**\n * There are two cases when we can immediately publish the entry:\n * 1. If the user requested it.\n * 2. If the entry is scheduled for a date in the past.\n */\n if (input.immediately || input.scheduleOn < currentDate) {\n const updatedTargetEntry = await this.cms.updateEntry(\n this.targetModel,\n targetEntry.id,\n {\n lastPublishedOn: input.dateOn ? input.dateOn.toISOString() : undefined,\n lastPublishedBy: this.getIdentity()\n }\n );\n\n const publishedEntry = await this.cms.publishEntry(\n this.targetModel,\n updatedTargetEntry.id\n );\n /**\n * We can safely cancel the original schedule entry and the event.\n *\n * // TODO determine if we want to ignore the error of the cancelation.\n */\n try {\n await this.cancel(original.id);\n } catch {\n //\n }\n\n return {\n ...original,\n publishOn: currentDate,\n unpublishOn: undefined,\n dateOn: publishedEntry.lastPublishedOn\n ? new Date(publishedEntry.lastPublishedOn)\n : undefined\n };\n }\n\n await this.cms.updateEntry<\n Pick<IScheduleEntryValues, \"scheduledOn\" | \"dateOn\" | \"scheduledBy\">\n >(this.scheduleModel, original.id, {\n scheduledBy: this.getIdentity(),\n scheduledOn: dateToISOString(input.scheduleOn),\n dateOn: input.dateOn ? dateToISOString(input.dateOn) : undefined\n });\n\n try {\n await this.service.update({\n id: original.id,\n scheduleOn: input.scheduleOn\n });\n } catch (ex) {\n throw ex;\n }\n return {\n ...original,\n publishOn: new Date(),\n unpublishOn: undefined,\n dateOn: input.dateOn\n };\n }\n\n public async cancel(id: string): Promise<void> {\n /**\n * No need to do anything if the record does not exist.\n */\n let scheduleEntry: IScheduleRecord | null = null;\n try {\n scheduleEntry = await this.fetcher.getScheduled(id);\n if (!scheduleEntry) {\n return;\n }\n } catch {\n return;\n }\n\n try {\n await this.cms.deleteEntry(this.scheduleModel, scheduleEntry.id);\n } catch (ex) {\n if (ex.code === \"NOT_FOUND\" || ex instanceof NotFoundError) {\n return;\n }\n console.error(`Error while deleting schedule entry: ${scheduleEntry.id}.`);\n console.log(convertException(ex));\n throw ex;\n }\n\n try {\n await this.service.delete(scheduleEntry.id);\n } catch (ex) {\n console.error(\n `Error while deleting service event for schedule entry: ${scheduleEntry.id}.`\n );\n console.log(convertException(ex));\n throw ex;\n }\n }\n\n private async getUpdateableTargetEntry<T = CmsEntryValues>(id: string): Promise<CmsEntry<T>> {\n const entry = await this.cms.getEntryById<T>(this.targetModel, id);\n if (entry.locked) {\n throw new WebinyError(\n `Cannot schedule a publish action for entry \"${entry.id}\" because it is locked.`,\n \"ENTRY_LOCKED\",\n {\n entryId: entry.id\n }\n );\n }\n return entry;\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAgBO,MAAMQ,qBAAqB,CAA4B;EAQnDC,WAAWA,CAACC,MAAoC,EAAE;IACrD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,GAAG,GAAGF,MAAM,CAACE,GAAG;IACrB,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;IACrC,IAAI,CAACC,aAAa,GAAGJ,MAAM,CAACI,aAAa;IACzC,IAAI,CAACC,WAAW,GAAGL,MAAM,CAACK,WAAW;IACrC,IAAI,CAACC,OAAO,GAAGN,MAAM,CAACM,OAAO;EACjC;EAEOC,SAASA,CAACC,KAAsB,EAAW;IAC9C,OAAOA,KAAK,CAACC,IAAI,KAAKC,mBAAY,CAACC,OAAO;EAC9C;EAEA,MAAaC,QAAQA,CAACZ,MAAqC,EAA4B;IACnF,MAAM;MAAEa,QAAQ;MAAEL,KAAK;MAAEM;IAAiB,CAAC,GAAGd,MAAM;IAEpD,MAAMe,WAAW,GAAG,MAAM,IAAI,CAACC,wBAAw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,MAAM,IAAI,CAAC1C,GAAG,CAACqD,WAAW,CAAC,IAAI,CAACnD,aAAa,EAAEwC,aAAa,CAACjB,EAAE,CAAC;IACpE,CAAC,CAAC,OAAOuB,EAAE,EAAE;MACT,IAAIA,EAAE,CAACiB,IAAI,KAAK,WAAW,IAAIjB,EAAE,YAAYkB,6BAAa,EAAE;QACxD;MACJ;MACAjB,OAAO,CAACC,KAAK,CAAC,wCAAwCR,aAAa,CAACjB,EAAE,GAAG,CAAC;MAC1EwB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,IAAI;MACA,MAAM,IAAI,CAACjD,OAAO,CAACoE,MAAM,CAACzB,aAAa,CAACjB,EAAE,CAAC;IAC/C,CAAC,CAAC,OAAOuB,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,0DAA0DR,aAAa,CAACjB,EAAE,GAC9E,CAAC;MACDwB,OAAO,CAACE,GAAG,CAAC,IAAAC,uBAAgB,EAACJ,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;EACJ;EAEA,MAAclC,wBAAwBA,CAAqBW,EAAU,EAAwB;IACzF,MAAM2C,KAAK,GAAG,MAAM,IAAI,CAACpE,GAAG,CAACqE,YAAY,CAAI,IAAI,CAACpE,WAAW,EAAEwB,EAAE,CAAC;IAClE,IAAI2C,KAAK,CAACE,MAAM,EAAE;MACd,MAAM,IAAIC,kBAAW,CACjB,+CAA+CH,KAAK,CAAC3C,EAAE,yBAAyB,EAChF,cAAc,EACd;QACI+C,OAAO,EAAEJ,KAAK,CAAC3C;MACnB,CACJ,CAAC;IACL;IACA,OAAO2C,KAAK;EAChB;AACJ;AAACK,OAAA,CAAA7E,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,O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MACnB,CACJ,CAAC;IACL;IACA,OAAOuC,KAAK;EAChB;AACJ;AAACK,OAAA,CAAAzE,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
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>;
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
package/scheduler/dates.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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;
|