@openinc/parse-server-opendash 4.40.0 → 5.0.0
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/dist/features/config/helper/customOptions.js +1 -1
- package/dist/features/config/types/ConfigKeys.d.ts +0 -3
- package/dist/features/config/types/ConfigKeys.js +3 -23
- package/dist/features/openservice/index.d.ts +6 -27
- package/dist/features/openservice/index.js +7 -44
- package/dist/features/openservice/init.d.ts +5 -13
- package/dist/features/openservice/init.js +17 -46
- package/dist/features/openservice/serviceSchedules/calendarSync/Access.d.ts +9 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/CalendarManager.d.ts +71 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/CalendarManager.js +300 -0
- package/dist/features/openservice/{schedules → serviceSchedules}/calendarSync/Event.d.ts +0 -4
- package/dist/features/openservice/{types/Material.js → serviceSchedules/calendarSync/Event.js} +3 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/ServiceCalendarSyncPoller.d.ts +37 -53
- package/dist/features/openservice/serviceSchedules/calendarSync/ServiceCalendarSyncPoller.js +284 -187
- package/dist/features/openservice/serviceSchedules/calendarSync/ServiceSyncTypes.d.ts +17 -15
- package/dist/features/openservice/serviceSchedules/calendarSync/ServiceSyncTypes.js +4 -5
- package/dist/features/openservice/serviceSchedules/calendarSync/eventToPlan.d.ts +1 -1
- package/dist/features/openservice/serviceSchedules/calendarSync/inboundChanges.d.ts +65 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/inboundChanges.js +101 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/index.d.ts +2 -2
- package/dist/features/openservice/serviceSchedules/calendarSync/index.js +3 -1
- package/dist/features/openservice/serviceSchedules/calendarSync/outlookRecurrence.d.ts +1 -1
- package/dist/features/openservice/serviceSchedules/calendarSync/planLock.d.ts +11 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/planLock.js +48 -0
- package/dist/features/openservice/serviceSchedules/calendarSync/planToEvent.d.ts +1 -1
- package/dist/features/openservice/serviceSchedules/calendarSync/serviceCalendarMeta.d.ts +11 -32
- package/dist/features/openservice/serviceSchedules/calendarSync/serviceCalendarMeta.js +20 -22
- package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanExceptions.d.ts +4 -5
- package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanExceptions.js +2 -3
- package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanToCalendar.d.ts +10 -1
- package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanToCalendar.js +25 -2
- package/dist/features/openservice/serviceSchedules/initServiceSchedulesFeature.d.ts +6 -4
- package/dist/features/openservice/serviceSchedules/initServiceSchedulesFeature.js +24 -11
- package/dist/features/openware/index.d.ts +0 -1
- package/dist/features/permissions/types/Permissions.d.ts +0 -14
- package/dist/features/permissions/types/Permissions.js +0 -18
- package/dist/features/translations/services/initTranslation.js +1 -1
- package/dist/hooks/Config_open_service.js +0 -60
- package/dist/hooks/Meta_Entry.js +3 -6
- package/dist/hooks/Service_Schedule.js +14 -7
- package/dist/hooks/Service_Schedule_Execution.js +41 -14
- package/dist/index.js +2 -7
- package/dist/scripts/backfill-execution-snapshot.d.ts +1 -0
- package/dist/scripts/backfill-execution-snapshot.js +124 -0
- package/dist/scripts/migration/passes/18-calendar-links.js +6 -2
- package/package.json +4 -4
- package/pnpm-workspace.yaml +7 -0
- package/dist/features/openservice/functions/assignUsersAndRoles.d.ts +0 -13
- package/dist/features/openservice/functions/assignUsersAndRoles.js +0 -212
- package/dist/features/openservice/functions/getSourceMetaMap.d.ts +0 -13
- package/dist/features/openservice/functions/getSourceMetaMap.js +0 -52
- package/dist/features/openservice/functions/getTicketObject.d.ts +0 -9
- package/dist/features/openservice/functions/getTicketObject.js +0 -31
- package/dist/features/openservice/functions/saveDescription.d.ts +0 -9
- package/dist/features/openservice/functions/saveDescription.js +0 -12
- package/dist/features/openservice/functions/saveDowntime.d.ts +0 -8
- package/dist/features/openservice/functions/saveDowntime.js +0 -32
- package/dist/features/openservice/functions/saveDuedate.d.ts +0 -13
- package/dist/features/openservice/functions/saveDuedate.js +0 -39
- package/dist/features/openservice/functions/saveFrequency.d.ts +0 -8
- package/dist/features/openservice/functions/saveFrequency.js +0 -32
- package/dist/features/openservice/functions/saveIssuecategory.d.ts +0 -14
- package/dist/features/openservice/functions/saveIssuecategory.js +0 -53
- package/dist/features/openservice/functions/saveMaterial.d.ts +0 -9
- package/dist/features/openservice/functions/saveMaterial.js +0 -18
- package/dist/features/openservice/functions/saveMessage.d.ts +0 -10
- package/dist/features/openservice/functions/saveMessage.js +0 -54
- package/dist/features/openservice/functions/savePriority.d.ts +0 -8
- package/dist/features/openservice/functions/savePriority.js +0 -32
- package/dist/features/openservice/functions/saveProject.d.ts +0 -8
- package/dist/features/openservice/functions/saveProject.js +0 -98
- package/dist/features/openservice/functions/saveRestriction.d.ts +0 -8
- package/dist/features/openservice/functions/saveRestriction.js +0 -32
- package/dist/features/openservice/functions/saveSource.d.ts +0 -8
- package/dist/features/openservice/functions/saveSource.js +0 -32
- package/dist/features/openservice/functions/saveState.d.ts +0 -14
- package/dist/features/openservice/functions/saveState.js +0 -52
- package/dist/features/openservice/functions/saveTicketMeta.d.ts +0 -9
- package/dist/features/openservice/functions/saveTicketMeta.js +0 -32
- package/dist/features/openservice/functions/saveTicketTitle.d.ts +0 -8
- package/dist/features/openservice/functions/saveTicketTitle.js +0 -28
- package/dist/features/openservice/issuecategory/initIssuecategory.d.ts +0 -5
- package/dist/features/openservice/issuecategory/initIssuecategory.js +0 -42
- package/dist/features/openservice/kanbanState/initKanbanStates.d.ts +0 -21
- package/dist/features/openservice/kanbanState/initKanbanStates.js +0 -187
- package/dist/features/openservice/messages/initMessages.d.ts +0 -8
- package/dist/features/openservice/messages/initMessages.js +0 -466
- package/dist/features/openservice/messages/removeLatestMessage.d.ts +0 -9
- package/dist/features/openservice/messages/removeLatestMessage.js +0 -30
- package/dist/features/openservice/schedules/calendarSync/Access.d.ts +0 -12
- package/dist/features/openservice/schedules/calendarSync/CalendarManager.d.ts +0 -49
- package/dist/features/openservice/schedules/calendarSync/CalendarManager.js +0 -211
- package/dist/features/openservice/schedules/calendarSync/CalendarSyncPoller.d.ts +0 -25
- package/dist/features/openservice/schedules/calendarSync/CalendarSyncPoller.js +0 -202
- package/dist/features/openservice/schedules/calendarSync/ConfigValues.d.ts +0 -13
- package/dist/features/openservice/schedules/calendarSync/ConfigValues.js +0 -2
- package/dist/features/openservice/schedules/calendarSync/Event.js +0 -9
- package/dist/features/openservice/schedules/calendarSync/calendarMetaHelper.d.ts +0 -76
- package/dist/features/openservice/schedules/calendarSync/calendarMetaHelper.js +0 -119
- package/dist/features/openservice/schedules/calendarSync/eventToSchedule.d.ts +0 -37
- package/dist/features/openservice/schedules/calendarSync/eventToSchedule.js +0 -103
- package/dist/features/openservice/schedules/calendarSync/scheduleToEvent.d.ts +0 -9
- package/dist/features/openservice/schedules/calendarSync/scheduleToEvent.js +0 -122
- package/dist/features/openservice/schedules/checkStatus.d.ts +0 -9
- package/dist/features/openservice/schedules/checkStatus.js +0 -31
- package/dist/features/openservice/schedules/getScheduleLink.d.ts +0 -10
- package/dist/features/openservice/schedules/getScheduleLink.js +0 -32
- package/dist/features/openservice/schedules/initSchedulesFeature.d.ts +0 -5
- package/dist/features/openservice/schedules/initSchedulesFeature.js +0 -32
- package/dist/features/openservice/schedules/reassignScheduleExecutions.d.ts +0 -5
- package/dist/features/openservice/schedules/reassignScheduleExecutions.js +0 -39
- package/dist/features/openservice/ticket/getTicketLink.d.ts +0 -9
- package/dist/features/openservice/ticket/getTicketLink.js +0 -32
- package/dist/features/openservice/ticket/initTicket.d.ts +0 -4
- package/dist/features/openservice/ticket/initTicket.js +0 -56
- package/dist/features/openservice/types/FetchOptions.d.ts +0 -4
- package/dist/features/openservice/types/FetchOptions.js +0 -2
- package/dist/features/openservice/types/Material.d.ts +0 -10
- package/dist/features/openservice/types/OpenserviceTranslationKeys.d.ts +0 -102
- package/dist/features/openservice/types/OpenserviceTranslationKeys.js +0 -106
- package/dist/features/openservice/types/SaveValues.d.ts +0 -33
- package/dist/features/openservice/types/SaveValues.js +0 -2
- package/dist/features/openservice/types/TicketData.d.ts +0 -22
- package/dist/features/openservice/types/TicketData.js +0 -2
- package/dist/features/openware/types/OpenWareTicketObject.d.ts +0 -14
- package/dist/features/openware/types/OpenWareTicketObject.js +0 -2
- package/dist/functions/openinc-openservice-get-sourcemeta-map.d.ts +0 -1
- package/dist/functions/openinc-openservice-get-sourcemeta-map.js +0 -41
- package/dist/functions/openinc-openservice-save-ticket-data.d.ts +0 -6
- package/dist/functions/openinc-openservice-save-ticket-data.js +0 -517
- package/dist/functions/openinc-openservice-ticket-data.d.ts +0 -44
- package/dist/functions/openinc-openservice-ticket-data.js +0 -380
- package/dist/helper/removeShorltyPreviousEntry.d.ts +0 -2
- package/dist/helper/removeShorltyPreviousEntry.js +0 -31
- package/dist/hooks/Maintenance_Downtime.d.ts +0 -1
- package/dist/hooks/Maintenance_Downtime.js +0 -106
- package/dist/hooks/Maintenance_Duedate.d.ts +0 -1
- package/dist/hooks/Maintenance_Duedate.js +0 -128
- package/dist/hooks/Maintenance_Frequency.d.ts +0 -1
- package/dist/hooks/Maintenance_Frequency.js +0 -106
- package/dist/hooks/Maintenance_Issuecategory.d.ts +0 -1
- package/dist/hooks/Maintenance_Issuecategory.js +0 -19
- package/dist/hooks/Maintenance_Item.d.ts +0 -1
- package/dist/hooks/Maintenance_Item.js +0 -17
- package/dist/hooks/Maintenance_Kanban_State.d.ts +0 -1
- package/dist/hooks/Maintenance_Kanban_State.js +0 -17
- package/dist/hooks/Maintenance_Media.d.ts +0 -1
- package/dist/hooks/Maintenance_Media.js +0 -17
- package/dist/hooks/Maintenance_Message.d.ts +0 -1
- package/dist/hooks/Maintenance_Message.js +0 -20
- package/dist/hooks/Maintenance_Order.d.ts +0 -1
- package/dist/hooks/Maintenance_Order.js +0 -17
- package/dist/hooks/Maintenance_Priority.d.ts +0 -1
- package/dist/hooks/Maintenance_Priority.js +0 -110
- package/dist/hooks/Maintenance_Project.d.ts +0 -1
- package/dist/hooks/Maintenance_Project.js +0 -30
- package/dist/hooks/Maintenance_Restriction.d.ts +0 -1
- package/dist/hooks/Maintenance_Restriction.js +0 -113
- package/dist/hooks/Maintenance_Schedule.d.ts +0 -1
- package/dist/hooks/Maintenance_Schedule.js +0 -146
- package/dist/hooks/Maintenance_Schedule_Execution.d.ts +0 -1
- package/dist/hooks/Maintenance_Schedule_Execution.js +0 -118
- package/dist/hooks/Maintenance_Schedule_Execution_Step.d.ts +0 -1
- package/dist/hooks/Maintenance_Schedule_Execution_Step.js +0 -17
- package/dist/hooks/Maintenance_Schedule_Step.d.ts +0 -1
- package/dist/hooks/Maintenance_Schedule_Step.js +0 -26
- package/dist/hooks/Maintenance_Schedule_Template.d.ts +0 -1
- package/dist/hooks/Maintenance_Schedule_Template.js +0 -92
- package/dist/hooks/Maintenance_Source_File.d.ts +0 -1
- package/dist/hooks/Maintenance_Source_File.js +0 -17
- package/dist/hooks/Maintenance_Ticket.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket.js +0 -15
- package/dist/hooks/Maintenance_Ticket_Assignment.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Assignment.js +0 -17
- package/dist/hooks/Maintenance_Ticket_FormConfig.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_FormConfig.js +0 -17
- package/dist/hooks/Maintenance_Ticket_Issuecategory.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Issuecategory.js +0 -109
- package/dist/hooks/Maintenance_Ticket_Kanban_State.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Kanban_State.js +0 -134
- package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.js +0 -15
- package/dist/hooks/Maintenance_Ticket_Material.d.ts +0 -4
- package/dist/hooks/Maintenance_Ticket_Material.js +0 -104
- package/dist/hooks/Maintenance_Ticket_Project.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Project.js +0 -88
- package/dist/hooks/Maintenance_Ticket_QR_Code.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_QR_Code.js +0 -17
- package/dist/hooks/Maintenance_Ticket_Source.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Source.js +0 -124
- package/dist/hooks/Maintenance_Ticket_Title.d.ts +0 -1
- package/dist/hooks/Maintenance_Ticket_Title.js +0 -107
- package/dist/i18n/de-DE/maintenance.json +0 -16
- package/dist/i18n/en-US/maintenance.json +0 -16
- package/dist/scripts/seed-v1-testdata.d.ts +0 -43
- package/dist/scripts/seed-v1-testdata.js +0 -982
- /package/dist/features/openservice/{schedules → serviceSchedules}/calendarSync/Access.js +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { GraphEventResponse, Recurrence } from "./Event.js";
|
|
2
|
+
/**
|
|
3
|
+
* The event as we last wrote or saw it — the *base* of the comparison below.
|
|
4
|
+
*
|
|
5
|
+
* Also what an outbound update reads to keep what the user set in Outlook and a
|
|
6
|
+
* plan has no field for (the time of day above all — see `planToEvent`).
|
|
7
|
+
*/
|
|
8
|
+
export interface ServiceCalendarEventSnapshot {
|
|
9
|
+
id: string;
|
|
10
|
+
subject?: string;
|
|
11
|
+
start: {
|
|
12
|
+
dateTime: string;
|
|
13
|
+
timeZone: string;
|
|
14
|
+
};
|
|
15
|
+
end: {
|
|
16
|
+
dateTime: string;
|
|
17
|
+
timeZone: string;
|
|
18
|
+
};
|
|
19
|
+
isAllDay?: boolean;
|
|
20
|
+
isCancelled?: boolean;
|
|
21
|
+
recurrence?: GraphEventResponse["recurrence"];
|
|
22
|
+
/** Absent in snapshots written before reminders were compared. */
|
|
23
|
+
isReminderOn?: boolean;
|
|
24
|
+
reminderMinutesBeforeStart?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function toSnapshot(event: GraphEventResponse): ServiceCalendarEventSnapshot;
|
|
27
|
+
/** Which parts of a plan an Outlook-side change touches. */
|
|
28
|
+
export type InboundChanges = {
|
|
29
|
+
/** Subject → title and machine. */
|
|
30
|
+
subject: boolean;
|
|
31
|
+
/** Start, end, all-day, recurrence → cadence. */
|
|
32
|
+
timing: boolean;
|
|
33
|
+
/** Reminder → the sync's own notification rule. */
|
|
34
|
+
reminder: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare const NO_CHANGES: InboundChanges;
|
|
37
|
+
export declare function hasChanges(changes: InboundChanges): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* What changed in Outlook since we last wrote or saw the event.
|
|
40
|
+
*
|
|
41
|
+
* **This is what keeps the sync from looping.** The poller used to read the
|
|
42
|
+
* whole event back into the plan whenever its `changeKey` was not the stored
|
|
43
|
+
* one. But the `changeKey` moves for things that are not edits — Exchange
|
|
44
|
+
* touching the item after our own write, a race between our write and storing
|
|
45
|
+
* its key — and the mapping plan → event → plan is not lossless (the time of
|
|
46
|
+
* day, a reminder in minutes vs. a rule in days). So a change nobody made was
|
|
47
|
+
* read back as one, rewrote the plan, and on an unguarded path went back out.
|
|
48
|
+
*
|
|
49
|
+
* Compared against the snapshot instead, only what actually differs from our
|
|
50
|
+
* own last version is applied, aspect by aspect. Our own echo differs in
|
|
51
|
+
* nothing and is a no-op by construction, whatever its `changeKey`.
|
|
52
|
+
*
|
|
53
|
+
* Without a snapshot (an entry from before snapshots) nothing counts as
|
|
54
|
+
* changed: the caller records the event as the new base, and the next real
|
|
55
|
+
* edit is detected against it. Taking it all as an edit instead would rewrite
|
|
56
|
+
* every linked plan once, on the first pass after a deploy.
|
|
57
|
+
*/
|
|
58
|
+
export declare function inboundChanges(base: ServiceCalendarEventSnapshot | undefined, event: GraphEventResponse): InboundChanges;
|
|
59
|
+
/**
|
|
60
|
+
* A recurrence reduced to what it means. Graph fills in defaults on the way
|
|
61
|
+
* back (`firstDayOfWeek`, `index: "first"`, `month: 0`, a
|
|
62
|
+
* `recurrenceTimeZone`) that we never sent; comparing them would read our own
|
|
63
|
+
* series as edited.
|
|
64
|
+
*/
|
|
65
|
+
export declare function recurrenceKey(recurrence: Recurrence | null | undefined): string;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_CHANGES = void 0;
|
|
4
|
+
exports.toSnapshot = toSnapshot;
|
|
5
|
+
exports.hasChanges = hasChanges;
|
|
6
|
+
exports.inboundChanges = inboundChanges;
|
|
7
|
+
exports.recurrenceKey = recurrenceKey;
|
|
8
|
+
function toSnapshot(event) {
|
|
9
|
+
return {
|
|
10
|
+
id: event.id,
|
|
11
|
+
subject: event.subject,
|
|
12
|
+
start: event.start,
|
|
13
|
+
end: event.end,
|
|
14
|
+
isAllDay: event.isAllDay,
|
|
15
|
+
isCancelled: event.isCancelled,
|
|
16
|
+
recurrence: event.recurrence ?? undefined,
|
|
17
|
+
isReminderOn: event.isReminderOn ?? false,
|
|
18
|
+
reminderMinutesBeforeStart: event.reminderMinutesBeforeStart,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.NO_CHANGES = {
|
|
22
|
+
subject: false,
|
|
23
|
+
timing: false,
|
|
24
|
+
reminder: false,
|
|
25
|
+
};
|
|
26
|
+
function hasChanges(changes) {
|
|
27
|
+
return changes.subject || changes.timing || changes.reminder;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What changed in Outlook since we last wrote or saw the event.
|
|
31
|
+
*
|
|
32
|
+
* **This is what keeps the sync from looping.** The poller used to read the
|
|
33
|
+
* whole event back into the plan whenever its `changeKey` was not the stored
|
|
34
|
+
* one. But the `changeKey` moves for things that are not edits — Exchange
|
|
35
|
+
* touching the item after our own write, a race between our write and storing
|
|
36
|
+
* its key — and the mapping plan → event → plan is not lossless (the time of
|
|
37
|
+
* day, a reminder in minutes vs. a rule in days). So a change nobody made was
|
|
38
|
+
* read back as one, rewrote the plan, and on an unguarded path went back out.
|
|
39
|
+
*
|
|
40
|
+
* Compared against the snapshot instead, only what actually differs from our
|
|
41
|
+
* own last version is applied, aspect by aspect. Our own echo differs in
|
|
42
|
+
* nothing and is a no-op by construction, whatever its `changeKey`.
|
|
43
|
+
*
|
|
44
|
+
* Without a snapshot (an entry from before snapshots) nothing counts as
|
|
45
|
+
* changed: the caller records the event as the new base, and the next real
|
|
46
|
+
* edit is detected against it. Taking it all as an edit instead would rewrite
|
|
47
|
+
* every linked plan once, on the first pass after a deploy.
|
|
48
|
+
*/
|
|
49
|
+
function inboundChanges(base, event) {
|
|
50
|
+
if (!base)
|
|
51
|
+
return exports.NO_CHANGES;
|
|
52
|
+
return {
|
|
53
|
+
subject: (base.subject ?? "").trim() !== (event.subject ?? "").trim(),
|
|
54
|
+
timing: instant(base.start?.dateTime) !== instant(event.start?.dateTime) ||
|
|
55
|
+
instant(base.end?.dateTime) !== instant(event.end?.dateTime) ||
|
|
56
|
+
!!base.isAllDay !== !!event.isAllDay ||
|
|
57
|
+
recurrenceKey(base.recurrence) !== recurrenceKey(event.recurrence),
|
|
58
|
+
// Only comparable once the base knows the reminder at all.
|
|
59
|
+
reminder: base.isReminderOn !== undefined &&
|
|
60
|
+
reminderKey(base.isReminderOn, base.reminderMinutesBeforeStart) !==
|
|
61
|
+
reminderKey(event.isReminderOn, event.reminderMinutesBeforeStart),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Graph's `dateTime` to the second — it pads the fraction to seven digits, and
|
|
66
|
+
* answers an all-day date we sent as `YYYY-MM-DD` with midnight.
|
|
67
|
+
*/
|
|
68
|
+
function instant(value) {
|
|
69
|
+
const raw = value ?? "";
|
|
70
|
+
return (raw.length === 10 ? `${raw}T00:00:00` : raw).slice(0, 19);
|
|
71
|
+
}
|
|
72
|
+
function reminderKey(on, minutes) {
|
|
73
|
+
return on ? `on:${minutes ?? 0}` : "off";
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A recurrence reduced to what it means. Graph fills in defaults on the way
|
|
77
|
+
* back (`firstDayOfWeek`, `index: "first"`, `month: 0`, a
|
|
78
|
+
* `recurrenceTimeZone`) that we never sent; comparing them would read our own
|
|
79
|
+
* series as edited.
|
|
80
|
+
*/
|
|
81
|
+
function recurrenceKey(recurrence) {
|
|
82
|
+
if (!recurrence?.pattern)
|
|
83
|
+
return "";
|
|
84
|
+
const { pattern, range } = recurrence;
|
|
85
|
+
const relative = pattern.type === "relativeMonthly" || pattern.type === "relativeYearly";
|
|
86
|
+
const yearly = pattern.type === "absoluteYearly" || pattern.type === "relativeYearly";
|
|
87
|
+
const monthDay = pattern.type === "absoluteMonthly" || pattern.type === "absoluteYearly";
|
|
88
|
+
const weekly = pattern.type === "weekly" || relative;
|
|
89
|
+
return JSON.stringify([
|
|
90
|
+
pattern.type,
|
|
91
|
+
pattern.interval ?? 1,
|
|
92
|
+
weekly ? [...(pattern.daysOfWeek ?? [])].sort() : [],
|
|
93
|
+
monthDay ? (pattern.dayOfMonth ?? 0) : 0,
|
|
94
|
+
yearly ? (pattern.month ?? 0) : 0,
|
|
95
|
+
relative ? (pattern.index ?? "first") : "",
|
|
96
|
+
range?.type ?? "",
|
|
97
|
+
range?.startDate ?? "",
|
|
98
|
+
range?.type === "endDate" ? range.endDate : "",
|
|
99
|
+
range?.type === "numbered" ? range.numberOfOccurrences : 0,
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
@@ -3,6 +3,6 @@ export { buildRRule, cadenceToRecurrence, eventToCadence, parseRRule, } from "./
|
|
|
3
3
|
export { planToEvent } from "./planToEvent.js";
|
|
4
4
|
export { findMetaForEvent, findMetaForPlan, SERVICE_CALENDAR_SYNC_CONTEXT, ServiceCalendarMetaConfig, } from "./serviceCalendarMeta.js";
|
|
5
5
|
export { CALENDAR_SYNC_CONTEXT_FLAG, ServiceCalendarSyncPoller, } from "./ServiceCalendarSyncPoller.js";
|
|
6
|
-
export { connectionForTenant, syncPlanToCalendar, } from "./syncPlanToCalendar.js";
|
|
7
|
-
export { OUTLOOK_CONFIG_KEY } from "./ServiceSyncTypes.js";
|
|
6
|
+
export { connectionForTenant, queuePlanSync, syncPlanToCalendar, } from "./syncPlanToCalendar.js";
|
|
7
|
+
export { DEFAULT_IMPORT_CATEGORY, OUTLOOK_CONFIG_KEY, } from "./ServiceSyncTypes.js";
|
|
8
8
|
export type { ServiceCadence, ServiceNotificationRule, ServiceSyncConfigValues, } from "./ServiceSyncTypes.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OUTLOOK_CONFIG_KEY = exports.syncPlanToCalendar = exports.connectionForTenant = exports.ServiceCalendarSyncPoller = exports.CALENDAR_SYNC_CONTEXT_FLAG = exports.ServiceCalendarMetaConfig = exports.SERVICE_CALENDAR_SYNC_CONTEXT = exports.findMetaForPlan = exports.findMetaForEvent = exports.planToEvent = exports.parseRRule = exports.eventToCadence = exports.cadenceToRecurrence = exports.buildRRule = exports.parseSubject = exports.OUTLOOK_REMINDER_RULE_ID = exports.mergeReminderRule = exports.eventToPlanFields = void 0;
|
|
3
|
+
exports.OUTLOOK_CONFIG_KEY = exports.DEFAULT_IMPORT_CATEGORY = exports.syncPlanToCalendar = exports.queuePlanSync = exports.connectionForTenant = exports.ServiceCalendarSyncPoller = exports.CALENDAR_SYNC_CONTEXT_FLAG = exports.ServiceCalendarMetaConfig = exports.SERVICE_CALENDAR_SYNC_CONTEXT = exports.findMetaForPlan = exports.findMetaForEvent = exports.planToEvent = exports.parseRRule = exports.eventToCadence = exports.cadenceToRecurrence = exports.buildRRule = exports.parseSubject = exports.OUTLOOK_REMINDER_RULE_ID = exports.mergeReminderRule = exports.eventToPlanFields = void 0;
|
|
4
4
|
var eventToPlan_js_1 = require("./eventToPlan.js");
|
|
5
5
|
Object.defineProperty(exports, "eventToPlanFields", { enumerable: true, get: function () { return eventToPlan_js_1.eventToPlanFields; } });
|
|
6
6
|
Object.defineProperty(exports, "mergeReminderRule", { enumerable: true, get: function () { return eventToPlan_js_1.mergeReminderRule; } });
|
|
@@ -23,6 +23,8 @@ Object.defineProperty(exports, "CALENDAR_SYNC_CONTEXT_FLAG", { enumerable: true,
|
|
|
23
23
|
Object.defineProperty(exports, "ServiceCalendarSyncPoller", { enumerable: true, get: function () { return ServiceCalendarSyncPoller_js_1.ServiceCalendarSyncPoller; } });
|
|
24
24
|
var syncPlanToCalendar_js_1 = require("./syncPlanToCalendar.js");
|
|
25
25
|
Object.defineProperty(exports, "connectionForTenant", { enumerable: true, get: function () { return syncPlanToCalendar_js_1.connectionForTenant; } });
|
|
26
|
+
Object.defineProperty(exports, "queuePlanSync", { enumerable: true, get: function () { return syncPlanToCalendar_js_1.queuePlanSync; } });
|
|
26
27
|
Object.defineProperty(exports, "syncPlanToCalendar", { enumerable: true, get: function () { return syncPlanToCalendar_js_1.syncPlanToCalendar; } });
|
|
27
28
|
var ServiceSyncTypes_js_1 = require("./ServiceSyncTypes.js");
|
|
29
|
+
Object.defineProperty(exports, "DEFAULT_IMPORT_CATEGORY", { enumerable: true, get: function () { return ServiceSyncTypes_js_1.DEFAULT_IMPORT_CATEGORY; } });
|
|
28
30
|
Object.defineProperty(exports, "OUTLOOK_CONFIG_KEY", { enumerable: true, get: function () { return ServiceSyncTypes_js_1.OUTLOOK_CONFIG_KEY; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function withPlanLock<T>(planId: string, task: () => Promise<T>): Promise<T>;
|
|
2
|
+
/**
|
|
3
|
+
* Run `task` for the plan once the lock is free — and only once, however many
|
|
4
|
+
* times this is called before it starts.
|
|
5
|
+
*
|
|
6
|
+
* A plan saved five times in a second (the editor, the ACL sync, a relation
|
|
7
|
+
* change) needs one calendar write with its final state, not five racing ones.
|
|
8
|
+
* The task must load the plan itself, so it sees that final state. A call made
|
|
9
|
+
* while the task is already running queues one more run.
|
|
10
|
+
*/
|
|
11
|
+
export declare function coalescePlanTask(planId: string, task: () => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withPlanLock = withPlanLock;
|
|
4
|
+
exports.coalescePlanTask = coalescePlanTask;
|
|
5
|
+
/**
|
|
6
|
+
* One calendar operation per plan at a time.
|
|
7
|
+
*
|
|
8
|
+
* Both directions read and rewrite the same `Meta_Entry` — event id, snapshot,
|
|
9
|
+
* applied exceptions — as a whole object. Run side by side (the afterSave sync
|
|
10
|
+
* is not awaited, the poller runs on its own timer) the later save wins with a
|
|
11
|
+
* stale copy: after a series rebuild the entry pointed at the deleted series
|
|
12
|
+
* again, and the new one was imported as a duplicate plan. Serialised, each
|
|
13
|
+
* step reads what the previous one wrote.
|
|
14
|
+
*
|
|
15
|
+
* In-process only — one Parse Server per calendar connection is assumed (see
|
|
16
|
+
* the README). Two servers would need a lock in the database.
|
|
17
|
+
*/
|
|
18
|
+
const chains = new Map();
|
|
19
|
+
function withPlanLock(planId, task) {
|
|
20
|
+
const previous = chains.get(planId) ?? Promise.resolve();
|
|
21
|
+
const run = previous.then(task, task);
|
|
22
|
+
const tail = run.then(() => undefined, () => undefined);
|
|
23
|
+
chains.set(planId, tail);
|
|
24
|
+
void tail.then(() => {
|
|
25
|
+
if (chains.get(planId) === tail)
|
|
26
|
+
chains.delete(planId);
|
|
27
|
+
});
|
|
28
|
+
return run;
|
|
29
|
+
}
|
|
30
|
+
const queued = new Set();
|
|
31
|
+
/**
|
|
32
|
+
* Run `task` for the plan once the lock is free — and only once, however many
|
|
33
|
+
* times this is called before it starts.
|
|
34
|
+
*
|
|
35
|
+
* A plan saved five times in a second (the editor, the ACL sync, a relation
|
|
36
|
+
* change) needs one calendar write with its final state, not five racing ones.
|
|
37
|
+
* The task must load the plan itself, so it sees that final state. A call made
|
|
38
|
+
* while the task is already running queues one more run.
|
|
39
|
+
*/
|
|
40
|
+
function coalescePlanTask(planId, task) {
|
|
41
|
+
if (queued.has(planId))
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
queued.add(planId);
|
|
44
|
+
return withPlanLock(planId, async () => {
|
|
45
|
+
queued.delete(planId);
|
|
46
|
+
await task();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GraphEvent } from "
|
|
1
|
+
import type { GraphEvent } from "./Event.js";
|
|
2
2
|
import type { ServiceCalendarEventSnapshot } from "./serviceCalendarMeta.js";
|
|
3
3
|
import type { ServiceCadence, ServiceNotificationRule } from "./ServiceSyncTypes.js";
|
|
4
4
|
/** A step of the plan, as far as the calendar entry shows it. */
|
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
import type { MetaConfig } from "../../../../types/custom/MetaField.js";
|
|
2
2
|
import { Meta_Entry, Tenant } from "../../../../types/index.js";
|
|
3
|
-
import type { GraphEventResponse } from "
|
|
3
|
+
import type { GraphEventResponse } from "./Event.js";
|
|
4
|
+
import { type ServiceCalendarEventSnapshot } from "./inboundChanges.js";
|
|
4
5
|
import type { AppliedExceptions } from "./seriesExceptions.js";
|
|
6
|
+
export type { ServiceCalendarEventSnapshot };
|
|
5
7
|
/**
|
|
6
8
|
* Which calendar event belongs to which v2 maintenance plan.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* from echoing each other — see `ServiceCalendarSyncPoller`.
|
|
10
|
+
* A `Meta_Entry` per plan. Its own context, distinct from the one v1 used
|
|
11
|
+
* (`["schedule","sync","microsoft"]`, still read by the migration), so a v1
|
|
12
|
+
* link is never mistaken for a v2 one. The stored snapshot of the event is the
|
|
13
|
+
* base the poller compares against — see `inboundChanges.ts`.
|
|
13
14
|
*/
|
|
14
15
|
export declare const SERVICE_CALENDAR_SYNC_CONTEXT: string;
|
|
15
|
-
/**
|
|
16
|
-
* The last known state of the event, as far as the sync needs it.
|
|
17
|
-
*
|
|
18
|
-
* Kept so an outbound update can preserve what the user set in Outlook and this
|
|
19
|
-
* side has no field for — the event's times above all: a plan knows a due
|
|
20
|
-
* *date*, and writing that back must not turn someone's 9:00 appointment into
|
|
21
|
-
* an all-day block.
|
|
22
|
-
*/
|
|
23
|
-
export interface ServiceCalendarEventSnapshot {
|
|
24
|
-
id: string;
|
|
25
|
-
subject?: string;
|
|
26
|
-
start: {
|
|
27
|
-
dateTime: string;
|
|
28
|
-
timeZone: string;
|
|
29
|
-
};
|
|
30
|
-
end: {
|
|
31
|
-
dateTime: string;
|
|
32
|
-
timeZone: string;
|
|
33
|
-
};
|
|
34
|
-
isAllDay?: boolean;
|
|
35
|
-
isCancelled?: boolean;
|
|
36
|
-
recurrence?: GraphEventResponse["recurrence"];
|
|
37
|
-
}
|
|
38
16
|
export interface ServiceCalendarMetaValues {
|
|
39
17
|
microsoftCalendarEventId: string;
|
|
40
18
|
microsoftCalendarChangeKey?: string;
|
|
@@ -48,6 +26,8 @@ export interface ServiceCalendarMetaValues {
|
|
|
48
26
|
/** Shown by the meta plugin when the entry is inspected in the frontend. */
|
|
49
27
|
export declare const ServiceCalendarMetaConfig: MetaConfig;
|
|
50
28
|
export declare function findMetaForPlan(scheduleId: string): Promise<Meta_Entry | null>;
|
|
29
|
+
/** Every plan↔event link of a tenant — what the poller checks each pass. */
|
|
30
|
+
export declare function findMetasForTenant(tenant: Tenant | undefined): Promise<Meta_Entry[]>;
|
|
51
31
|
export declare function findMetaForEvent(eventId: string): Promise<Meta_Entry | null>;
|
|
52
32
|
/**
|
|
53
33
|
* The plan whose moved date the event stands in for.
|
|
@@ -60,9 +40,8 @@ export declare function saveMeta(scheduleId: string, eventId: string, changeKey?
|
|
|
60
40
|
/**
|
|
61
41
|
* Remember the `changeKey` of the version we just wrote.
|
|
62
42
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* extra round trip; writing the wrong one means an endless echo.
|
|
43
|
+
* Together with the snapshot: the key lets the poller skip an unchanged event
|
|
44
|
+
* cheaply, the snapshot is the base its change detection compares against.
|
|
66
45
|
*/
|
|
67
46
|
export declare function updateChangeKey(entry: Meta_Entry, changeKey: string, event?: GraphEventResponse): Promise<void>;
|
|
68
47
|
/**
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ServiceCalendarMetaConfig = exports.SERVICE_CALENDAR_SYNC_CONTEXT = void 0;
|
|
7
7
|
exports.findMetaForPlan = findMetaForPlan;
|
|
8
|
+
exports.findMetasForTenant = findMetasForTenant;
|
|
8
9
|
exports.findMetaForEvent = findMetaForEvent;
|
|
9
10
|
exports.findMetaForMovedEvent = findMetaForMovedEvent;
|
|
10
11
|
exports.saveMeta = saveMeta;
|
|
@@ -13,14 +14,14 @@ exports.updateExceptionsState = updateExceptionsState;
|
|
|
13
14
|
exports.metaValues = metaValues;
|
|
14
15
|
const node_1 = __importDefault(require("parse/node"));
|
|
15
16
|
const index_js_1 = require("../../../../types/index.js");
|
|
17
|
+
const inboundChanges_js_1 = require("./inboundChanges.js");
|
|
16
18
|
/**
|
|
17
19
|
* Which calendar event belongs to which v2 maintenance plan.
|
|
18
20
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* from echoing each other — see `ServiceCalendarSyncPoller`.
|
|
21
|
+
* A `Meta_Entry` per plan. Its own context, distinct from the one v1 used
|
|
22
|
+
* (`["schedule","sync","microsoft"]`, still read by the migration), so a v1
|
|
23
|
+
* link is never mistaken for a v2 one. The stored snapshot of the event is the
|
|
24
|
+
* base the poller compares against — see `inboundChanges.ts`.
|
|
24
25
|
*/
|
|
25
26
|
exports.SERVICE_CALENDAR_SYNC_CONTEXT = JSON.stringify([
|
|
26
27
|
"service",
|
|
@@ -43,17 +44,6 @@ exports.ServiceCalendarMetaConfig = {
|
|
|
43
44
|
},
|
|
44
45
|
],
|
|
45
46
|
};
|
|
46
|
-
function toSnapshot(event) {
|
|
47
|
-
return {
|
|
48
|
-
id: event.id,
|
|
49
|
-
subject: event.subject,
|
|
50
|
-
start: event.start,
|
|
51
|
-
end: event.end,
|
|
52
|
-
isAllDay: event.isAllDay,
|
|
53
|
-
isCancelled: event.isCancelled,
|
|
54
|
-
recurrence: event.recurrence ?? undefined,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
47
|
async function findMetaForPlan(scheduleId) {
|
|
58
48
|
return ((await new node_1.default.Query(index_js_1.Meta_Entry)
|
|
59
49
|
.equalTo("context", exports.SERVICE_CALENDAR_SYNC_CONTEXT)
|
|
@@ -61,6 +51,15 @@ async function findMetaForPlan(scheduleId) {
|
|
|
61
51
|
.equalTo("entryObjectId", scheduleId)
|
|
62
52
|
.first({ useMasterKey: true })) ?? null);
|
|
63
53
|
}
|
|
54
|
+
/** Every plan↔event link of a tenant — what the poller checks each pass. */
|
|
55
|
+
async function findMetasForTenant(tenant) {
|
|
56
|
+
const query = new node_1.default.Query(index_js_1.Meta_Entry)
|
|
57
|
+
.equalTo("context", exports.SERVICE_CALENDAR_SYNC_CONTEXT)
|
|
58
|
+
.equalTo("entryClassName", index_js_1.Service_Schedule.className);
|
|
59
|
+
if (tenant)
|
|
60
|
+
query.equalTo("tenant", tenant);
|
|
61
|
+
return query.findAll({ useMasterKey: true });
|
|
62
|
+
}
|
|
64
63
|
async function findMetaForEvent(eventId) {
|
|
65
64
|
return ((await new node_1.default.Query(index_js_1.Meta_Entry)
|
|
66
65
|
.equalTo("context", exports.SERVICE_CALENDAR_SYNC_CONTEXT)
|
|
@@ -103,22 +102,21 @@ async function saveMeta(scheduleId, eventId, changeKey, tenant, event) {
|
|
|
103
102
|
if (changeKey)
|
|
104
103
|
values.microsoftCalendarChangeKey = changeKey;
|
|
105
104
|
if (event)
|
|
106
|
-
values.microsoftCalendarEvent = toSnapshot(event);
|
|
105
|
+
values.microsoftCalendarEvent = (0, inboundChanges_js_1.toSnapshot)(event);
|
|
107
106
|
entry.set("values", values);
|
|
108
107
|
return entry.save(null, { useMasterKey: true });
|
|
109
108
|
}
|
|
110
109
|
/**
|
|
111
110
|
* Remember the `changeKey` of the version we just wrote.
|
|
112
111
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* extra round trip; writing the wrong one means an endless echo.
|
|
112
|
+
* Together with the snapshot: the key lets the poller skip an unchanged event
|
|
113
|
+
* cheaply, the snapshot is the base its change detection compares against.
|
|
116
114
|
*/
|
|
117
115
|
async function updateChangeKey(entry, changeKey, event) {
|
|
118
116
|
entry.set("values", {
|
|
119
117
|
...entry.get("values"),
|
|
120
118
|
microsoftCalendarChangeKey: changeKey,
|
|
121
|
-
...(event ? { microsoftCalendarEvent: toSnapshot(event) } : {}),
|
|
119
|
+
...(event ? { microsoftCalendarEvent: (0, inboundChanges_js_1.toSnapshot)(event) } : {}),
|
|
122
120
|
});
|
|
123
121
|
await entry.save(null, { useMasterKey: true });
|
|
124
122
|
}
|
|
@@ -138,7 +136,7 @@ async function updateExceptionsState(entry, state) {
|
|
|
138
136
|
...(state.event?.changeKey
|
|
139
137
|
? { microsoftCalendarChangeKey: state.event.changeKey }
|
|
140
138
|
: {}),
|
|
141
|
-
...(state.event ? { microsoftCalendarEvent: toSnapshot(state.event) } : {}),
|
|
139
|
+
...(state.event ? { microsoftCalendarEvent: (0, inboundChanges_js_1.toSnapshot)(state.event) } : {}),
|
|
142
140
|
microsoftCalendarExceptions: state.exceptions,
|
|
143
141
|
});
|
|
144
142
|
await entry.save(null, { useMasterKey: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CalendarManager } from "
|
|
2
|
-
import type { GraphEvent } from "
|
|
1
|
+
import type { CalendarManager } from "./CalendarManager.js";
|
|
2
|
+
import type { GraphEvent } from "./Event.js";
|
|
3
3
|
import type { Meta_Entry } from "../../../../types/index.js";
|
|
4
4
|
import { type PlanEventInput } from "./planToEvent.js";
|
|
5
5
|
import type { ServiceCadenceException } from "./ServiceSyncTypes.js";
|
|
@@ -10,9 +10,8 @@ import type { ServiceCadenceException } from "./ServiceSyncTypes.js";
|
|
|
10
10
|
* Called by `syncPlanToCalendar` after the series itself was written. Costs no
|
|
11
11
|
* Graph call for a plan that has no exceptions and never had any.
|
|
12
12
|
*
|
|
13
|
-
* Order matters in two places, both because of the poller, which
|
|
14
|
-
*
|
|
15
|
-
* that disappears:
|
|
13
|
+
* Order matters in two places, both because of the poller, which archives the
|
|
14
|
+
* plan of a linked series that disappears:
|
|
16
15
|
*
|
|
17
16
|
* - a rebuilt series is linked to the plan **before** the old one is deleted;
|
|
18
17
|
* - a stand-alone event for a moved date is linked right after it is created.
|
|
@@ -13,9 +13,8 @@ const serviceCalendarMeta_js_1 = require("./serviceCalendarMeta.js");
|
|
|
13
13
|
* Called by `syncPlanToCalendar` after the series itself was written. Costs no
|
|
14
14
|
* Graph call for a plan that has no exceptions and never had any.
|
|
15
15
|
*
|
|
16
|
-
* Order matters in two places, both because of the poller, which
|
|
17
|
-
*
|
|
18
|
-
* that disappears:
|
|
16
|
+
* Order matters in two places, both because of the poller, which archives the
|
|
17
|
+
* plan of a linked series that disappears:
|
|
19
18
|
*
|
|
20
19
|
* - a rebuilt series is linked to the plan **before** the old one is deleted;
|
|
21
20
|
* - a stand-alone event for a moved date is linked right after it is created.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CalendarManager } from "
|
|
1
|
+
import { CalendarManager } from "./CalendarManager.js";
|
|
2
2
|
import { Service_Schedule, Tenant } from "../../../../types/index.js";
|
|
3
3
|
import type { ServiceSyncConfigValues } from "./ServiceSyncTypes.js";
|
|
4
4
|
/**
|
|
@@ -23,6 +23,15 @@ import type { ServiceSyncConfigValues } from "./ServiceSyncTypes.js";
|
|
|
23
23
|
* (`syncPlanExceptions`) — the series alone would show them on their old dates.
|
|
24
24
|
*/
|
|
25
25
|
export declare function syncPlanToCalendar(plan: Service_Schedule): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Sync a plan after a save — the afterSave hook's entry point.
|
|
28
|
+
*
|
|
29
|
+
* Coalesced per plan (`planLock.ts`): saves that arrive while a sync for the
|
|
30
|
+
* plan is waiting share it, and the plan is loaded fresh when it runs, so the
|
|
31
|
+
* calendar gets the final state once instead of every intermediate one in a
|
|
32
|
+
* race.
|
|
33
|
+
*/
|
|
34
|
+
export declare function queuePlanSync(planId: string): Promise<void>;
|
|
26
35
|
export declare function connectionForTenant(tenant: Tenant | undefined): Promise<{
|
|
27
36
|
manager: CalendarManager;
|
|
28
37
|
values: ServiceSyncConfigValues;
|
|
@@ -4,15 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.syncPlanToCalendar = syncPlanToCalendar;
|
|
7
|
+
exports.queuePlanSync = queuePlanSync;
|
|
7
8
|
exports.connectionForTenant = connectionForTenant;
|
|
8
9
|
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
-
const CalendarManager_js_1 = require("
|
|
10
|
+
const CalendarManager_js_1 = require("./CalendarManager.js");
|
|
10
11
|
const index_js_1 = require("../../../../types/index.js");
|
|
11
12
|
const outlookRecurrence_js_1 = require("./outlookRecurrence.js");
|
|
12
13
|
const planToEvent_js_1 = require("./planToEvent.js");
|
|
13
14
|
const seriesExceptions_js_1 = require("./seriesExceptions.js");
|
|
14
15
|
const ServiceSyncTypes_js_1 = require("./ServiceSyncTypes.js");
|
|
15
16
|
const serviceCalendarMeta_js_1 = require("./serviceCalendarMeta.js");
|
|
17
|
+
const planLock_js_1 = require("./planLock.js");
|
|
16
18
|
const syncPlanExceptions_js_1 = require("./syncPlanExceptions.js");
|
|
17
19
|
/**
|
|
18
20
|
* Write a maintenance plan into the tenant's Outlook calendar.
|
|
@@ -35,7 +37,26 @@ const syncPlanExceptions_js_1 = require("./syncPlanExceptions.js");
|
|
|
35
37
|
* After 3 and 4 the plan's moved and skipped dates and its pause follow
|
|
36
38
|
* (`syncPlanExceptions`) — the series alone would show them on their old dates.
|
|
37
39
|
*/
|
|
38
|
-
|
|
40
|
+
function syncPlanToCalendar(plan) {
|
|
41
|
+
return (0, planLock_js_1.withPlanLock)(plan.id, () => writePlanToCalendar(plan));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Sync a plan after a save — the afterSave hook's entry point.
|
|
45
|
+
*
|
|
46
|
+
* Coalesced per plan (`planLock.ts`): saves that arrive while a sync for the
|
|
47
|
+
* plan is waiting share it, and the plan is loaded fresh when it runs, so the
|
|
48
|
+
* calendar gets the final state once instead of every intermediate one in a
|
|
49
|
+
* race.
|
|
50
|
+
*/
|
|
51
|
+
function queuePlanSync(planId) {
|
|
52
|
+
return (0, planLock_js_1.coalescePlanTask)(planId, async () => {
|
|
53
|
+
const plan = await new node_1.default.Query(index_js_1.Service_Schedule)
|
|
54
|
+
.include("equipment")
|
|
55
|
+
.get(planId, { useMasterKey: true });
|
|
56
|
+
await writePlanToCalendar(plan);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function writePlanToCalendar(plan) {
|
|
39
60
|
const connection = await connectionForTenant(plan.get("tenant"));
|
|
40
61
|
if (!connection)
|
|
41
62
|
return;
|
|
@@ -75,6 +96,8 @@ async function syncPlanToCalendar(plan) {
|
|
|
75
96
|
let entry = meta;
|
|
76
97
|
if (meta && eventId) {
|
|
77
98
|
const updated = await connection.manager.updateEvent(eventId, event);
|
|
99
|
+
// The response is the event as Outlook now holds it — the new base for
|
|
100
|
+
// the poller's comparison, so our own write never reads as an edit.
|
|
78
101
|
if (updated?.changeKey) {
|
|
79
102
|
await (0, serviceCalendarMeta_js_1.updateChangeKey)(meta, updated.changeKey, updated);
|
|
80
103
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Start the
|
|
2
|
+
* Start the Outlook → open.SERVICE side of the calendar sync — one poller per
|
|
3
|
+
* configured tenant. (The other direction needs no start: it runs from the
|
|
4
|
+
* `Service_Schedule` afterSave hook.)
|
|
3
5
|
*
|
|
4
|
-
* The connections are read once at boot
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
6
|
+
* The connections are read once at boot: a tenant that switches the sync on
|
|
7
|
+
* gets the inbound side after the next server start. Switching it off again
|
|
8
|
+
* (`inbound_disabled` in the row) takes effect on the next pass.
|
|
7
9
|
*/
|
|
8
10
|
export declare function initServiceSchedulesFeature(): Promise<void>;
|
|
9
11
|
/** Stop every poller — for tests and for a graceful shutdown. */
|
|
@@ -7,26 +7,39 @@ exports.initServiceSchedulesFeature = initServiceSchedulesFeature;
|
|
|
7
7
|
exports.stopServiceSchedulesFeature = stopServiceSchedulesFeature;
|
|
8
8
|
const node_1 = __importDefault(require("parse/node"));
|
|
9
9
|
const index_js_1 = require("../../../types/index.js");
|
|
10
|
+
const ServiceCalendarSyncPoller_js_1 = require("./calendarSync/ServiceCalendarSyncPoller.js");
|
|
10
11
|
const ServiceSyncTypes_js_1 = require("./calendarSync/ServiceSyncTypes.js");
|
|
11
|
-
/**
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* How often Outlook is read back. Each pass reads every linked event (20 per
|
|
14
|
+
* request) plus the categorised ones, so this is a trade-off between how soon
|
|
15
|
+
* an Outlook edit shows up and Graph's per-mailbox budget (10,000 requests per
|
|
16
|
+
* 10 minutes) — five minutes leaves that budget almost untouched.
|
|
17
|
+
*/
|
|
18
|
+
const POLL_INTERVAL_MS = 5 * 60 * 1000;
|
|
13
19
|
const pollers = [];
|
|
14
20
|
/**
|
|
15
|
-
* Start the
|
|
21
|
+
* Start the Outlook → open.SERVICE side of the calendar sync — one poller per
|
|
22
|
+
* configured tenant. (The other direction needs no start: it runs from the
|
|
23
|
+
* `Service_Schedule` afterSave hook.)
|
|
16
24
|
*
|
|
17
|
-
* The connections are read once at boot
|
|
18
|
-
* the
|
|
19
|
-
*
|
|
25
|
+
* The connections are read once at boot: a tenant that switches the sync on
|
|
26
|
+
* gets the inbound side after the next server start. Switching it off again
|
|
27
|
+
* (`inbound_disabled` in the row) takes effect on the next pass.
|
|
20
28
|
*/
|
|
21
29
|
async function initServiceSchedulesFeature() {
|
|
30
|
+
stopServiceSchedulesFeature();
|
|
22
31
|
const configs = await new node_1.default.Query(index_js_1.Config)
|
|
23
32
|
.equalTo("key", ServiceSyncTypes_js_1.OUTLOOK_CONFIG_KEY)
|
|
24
|
-
.includeAll()
|
|
25
33
|
.findAll({ useMasterKey: true });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
for (const config of configs) {
|
|
35
|
+
try {
|
|
36
|
+
pollers.push(new ServiceCalendarSyncPoller_js_1.ServiceCalendarSyncPoller(config).start(POLL_INTERVAL_MS));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// A row that is not JSON must not keep the other tenants from syncing.
|
|
40
|
+
console.error(`[ServiceCalendarSync] Config ${config.id} could not be read:`, error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
30
43
|
if (pollers.length > 0) {
|
|
31
44
|
console.log(`[ServiceCalendarSync] Started for ${pollers.length} calendar connection(s)`);
|
|
32
45
|
}
|
|
@@ -3,5 +3,4 @@ export { type DataItemInterface } from "./types/DataItemInterface.js";
|
|
|
3
3
|
export { type DataItemValueInterface } from "./types/DataItemValueInterface.js";
|
|
4
4
|
export { type DataItemValueTypeInterface } from "./types/DataItemValueTypeInterface.js";
|
|
5
5
|
export { type DataItemValueTypeTypeField } from "./types/DataItemValueTypeTypeField.js";
|
|
6
|
-
export { type OpenWareTicketObject } from "./types/OpenWareTicketObject.js";
|
|
7
6
|
export { publishDataItem } from "./services/publishDataItem.js";
|