@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
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CalendarManager = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Manager for calendar operations via Microsoft Graph API.
|
|
6
|
-
*
|
|
7
|
-
* Model-free and therefore **not** deprecated with the rest of this folder:
|
|
8
|
-
* `serviceSchedules/calendarSync` shares it, because a second Graph client
|
|
9
|
-
* would only mean two places to break when the API or the credential flow
|
|
10
|
-
* changes. If v1 goes, this moves rather than dies.
|
|
11
|
-
*/
|
|
12
|
-
class CalendarManager {
|
|
13
|
-
tenantID;
|
|
14
|
-
clientID;
|
|
15
|
-
clientSecret;
|
|
16
|
-
userMail;
|
|
17
|
-
constructor(config) {
|
|
18
|
-
this.tenantID = config.tenantId;
|
|
19
|
-
this.clientID = config.clientID;
|
|
20
|
-
this.clientSecret = config.clientSecret;
|
|
21
|
-
this.userMail = config.userMail;
|
|
22
|
-
}
|
|
23
|
-
get isValid() {
|
|
24
|
-
if (!this.tenantID)
|
|
25
|
-
return "Missing Microsoft Tenant ID";
|
|
26
|
-
if (!this.clientID)
|
|
27
|
-
return "Missing Microsoft Client ID";
|
|
28
|
-
if (!this.clientSecret)
|
|
29
|
-
return "Missing Microsoft Client Secret";
|
|
30
|
-
if (!this.userMail)
|
|
31
|
-
return "Missing Microsoft User Email";
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
async getAccess() {
|
|
35
|
-
if (this.isValid !== true)
|
|
36
|
-
return null;
|
|
37
|
-
try {
|
|
38
|
-
const params = new URLSearchParams();
|
|
39
|
-
params.append("client_id", this.clientID);
|
|
40
|
-
params.append("client_secret", this.clientSecret);
|
|
41
|
-
params.append("scope", "https://graph.microsoft.com/.default");
|
|
42
|
-
params.append("grant_type", "client_credentials");
|
|
43
|
-
const response = await fetch(`https://login.microsoftonline.com/${this.tenantID}/oauth2/v2.0/token`, {
|
|
44
|
-
method: "POST",
|
|
45
|
-
headers: {
|
|
46
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
47
|
-
},
|
|
48
|
-
body: params.toString(),
|
|
49
|
-
});
|
|
50
|
-
const data = await response.json();
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
console.error(`[CalendarManager] Failed to obtain access token: HTTP ${response.status}`);
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error("[CalendarManager] Error fetching access token:", error);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async createEvent(event) {
|
|
63
|
-
if (!this.userMail ||
|
|
64
|
-
!this.tenantID ||
|
|
65
|
-
!this.clientID ||
|
|
66
|
-
!this.clientSecret)
|
|
67
|
-
return;
|
|
68
|
-
const accessData = await this.getAccess();
|
|
69
|
-
if (!accessData?.access_token)
|
|
70
|
-
return;
|
|
71
|
-
const res = await fetch(`https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events`, {
|
|
72
|
-
method: "POST",
|
|
73
|
-
headers: {
|
|
74
|
-
Authorization: `Bearer ${accessData.access_token}`,
|
|
75
|
-
"Content-Type": "application/json",
|
|
76
|
-
},
|
|
77
|
-
body: JSON.stringify(event),
|
|
78
|
-
});
|
|
79
|
-
if (!res.ok) {
|
|
80
|
-
console.error(`[CalendarManager] Failed to create event: HTTP ${res.status}`);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
return (await res.json());
|
|
84
|
-
}
|
|
85
|
-
async updateEvent(eventId, event) {
|
|
86
|
-
const accessData = await this.getAccess();
|
|
87
|
-
if (!accessData?.access_token)
|
|
88
|
-
return;
|
|
89
|
-
const res = await fetch(`https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events/${eventId}`, {
|
|
90
|
-
method: "PATCH",
|
|
91
|
-
headers: {
|
|
92
|
-
Authorization: `Bearer ${accessData.access_token}`,
|
|
93
|
-
"Content-Type": "application/json",
|
|
94
|
-
},
|
|
95
|
-
body: JSON.stringify(event),
|
|
96
|
-
});
|
|
97
|
-
if (!res.ok) {
|
|
98
|
-
console.error(`[CalendarManager] Failed to update event ${eventId}: HTTP ${res.status}`);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
return (await res.json());
|
|
102
|
-
}
|
|
103
|
-
async deleteEvent(eventId) {
|
|
104
|
-
const accessData = await this.getAccess();
|
|
105
|
-
if (!accessData?.access_token)
|
|
106
|
-
return;
|
|
107
|
-
// on successful deletion, Microsoft Graph returns 204 No Content, so no JSON to parse
|
|
108
|
-
const res = await fetch(`https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events/${eventId}`, {
|
|
109
|
-
method: "DELETE",
|
|
110
|
-
headers: {
|
|
111
|
-
Authorization: `Bearer ${accessData.access_token}`,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
if (!res.ok) {
|
|
115
|
-
console.error(`[CalendarManager] Failed to delete event ${eventId}: HTTP ${res.status}`);
|
|
116
|
-
}
|
|
117
|
-
return res.ok;
|
|
118
|
-
}
|
|
119
|
-
async fetchEvent(eventId) {
|
|
120
|
-
const accessData = await this.getAccess();
|
|
121
|
-
if (!accessData?.access_token)
|
|
122
|
-
return null;
|
|
123
|
-
const res = await fetch(`https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events/${eventId}`, { headers: { Authorization: `Bearer ${accessData.access_token}` } });
|
|
124
|
-
if (!res.ok) {
|
|
125
|
-
console.error(`[CalendarManager] Failed to fetch event ${eventId}: HTTP ${res.status}`);
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
return (await res.json());
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* The occurrences of a series between two instants — moved ones (exceptions)
|
|
132
|
-
* included, deleted ones not. `null` when the request failed.
|
|
133
|
-
*/
|
|
134
|
-
async fetchInstances(seriesId, from, to) {
|
|
135
|
-
const accessData = await this.getAccess();
|
|
136
|
-
if (!accessData?.access_token)
|
|
137
|
-
return null;
|
|
138
|
-
const params = new URLSearchParams({
|
|
139
|
-
startDateTime: from.toISOString(),
|
|
140
|
-
endDateTime: to.toISOString(),
|
|
141
|
-
$select: "id,type,originalStart,start",
|
|
142
|
-
$top: "100",
|
|
143
|
-
});
|
|
144
|
-
let nextUrl = `https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events/${seriesId}/instances?${params.toString()}`;
|
|
145
|
-
const instances = [];
|
|
146
|
-
while (nextUrl) {
|
|
147
|
-
const res = await fetch(nextUrl, {
|
|
148
|
-
headers: { Authorization: `Bearer ${accessData.access_token}` },
|
|
149
|
-
});
|
|
150
|
-
if (!res.ok) {
|
|
151
|
-
console.error(`[CalendarManager] Failed to fetch instances of ${seriesId}: HTTP ${res.status}`);
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
const data = (await res.json());
|
|
155
|
-
instances.push(...(data.value ?? []));
|
|
156
|
-
nextUrl = data["@odata.nextLink"];
|
|
157
|
-
}
|
|
158
|
-
return instances;
|
|
159
|
-
}
|
|
160
|
-
async fetchEvents() {
|
|
161
|
-
const accessData = await this.getAccess();
|
|
162
|
-
if (!accessData?.access_token)
|
|
163
|
-
return;
|
|
164
|
-
const res = await fetch(`https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events`, {
|
|
165
|
-
method: "GET",
|
|
166
|
-
headers: {
|
|
167
|
-
Authorization: `Bearer ${accessData.access_token}`,
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
if (!res.ok) {
|
|
171
|
-
console.error(`[CalendarManager] Failed to fetch events: HTTP ${res.status}`);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
return (await res.json());
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Fetch changed events since the last delta sync.
|
|
178
|
-
* On the first call (no deltaLink), returns all current events and a deltaLink
|
|
179
|
-
* for subsequent incremental calls.
|
|
180
|
-
* @param deltaLink token from the previous call; omit for the initial full sync
|
|
181
|
-
*/
|
|
182
|
-
async fetchDelta(deltaLink) {
|
|
183
|
-
const accessData = await this.getAccess();
|
|
184
|
-
if (!accessData?.access_token)
|
|
185
|
-
return null;
|
|
186
|
-
const events = [];
|
|
187
|
-
let nextUrl = deltaLink ||
|
|
188
|
-
`https://graph.microsoft.com/v1.0/users/${encodeURIComponent(this.userMail)}/events/delta`;
|
|
189
|
-
let newDeltaLink = "";
|
|
190
|
-
while (nextUrl) {
|
|
191
|
-
const res = await fetch(nextUrl, {
|
|
192
|
-
headers: { Authorization: `Bearer ${accessData.access_token}` },
|
|
193
|
-
});
|
|
194
|
-
if (!res.ok) {
|
|
195
|
-
console.error(`[CalendarManager] fetchDelta HTTP ${res.status}:`, await res.text());
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
const data = (await res.json());
|
|
199
|
-
events.push(...(data.value ?? []));
|
|
200
|
-
nextUrl = data["@odata.nextLink"];
|
|
201
|
-
if (data["@odata.deltaLink"])
|
|
202
|
-
newDeltaLink = data["@odata.deltaLink"];
|
|
203
|
-
}
|
|
204
|
-
if (!newDeltaLink) {
|
|
205
|
-
console.error("[CalendarManager] fetchDelta did not return a deltaLink.");
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
return { events, deltaLink: newDeltaLink };
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.CalendarManager = CalendarManager;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Config } from "../../../../types/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
4
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
5
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
6
|
-
*/
|
|
7
|
-
export declare class CalendarSyncPoller {
|
|
8
|
-
private timer;
|
|
9
|
-
private config;
|
|
10
|
-
constructor(config: Config);
|
|
11
|
-
private get manager();
|
|
12
|
-
/**
|
|
13
|
-
* Start polling the Microsoft Calendar delta feed.
|
|
14
|
-
* @param intervalMs polling interval in milliseconds (default: 5 minutes)
|
|
15
|
-
*/
|
|
16
|
-
start(intervalMs?: number): void;
|
|
17
|
-
stop(): void;
|
|
18
|
-
private poll;
|
|
19
|
-
private processEvent;
|
|
20
|
-
private updateScheduleFromEvent;
|
|
21
|
-
private createScheduleFromEvent;
|
|
22
|
-
private handleDeleted;
|
|
23
|
-
private loadDeltaLink;
|
|
24
|
-
private saveDeltaLink;
|
|
25
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CalendarSyncPoller = void 0;
|
|
7
|
-
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
-
const eventToSchedule_js_1 = require("./eventToSchedule.js");
|
|
9
|
-
const calendarMetaHelper_js_1 = require("./calendarMetaHelper.js");
|
|
10
|
-
const CalendarManager_js_1 = require("./CalendarManager.js");
|
|
11
|
-
const index_js_1 = require("../../../../types/index.js");
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
14
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
15
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
16
|
-
*/
|
|
17
|
-
class CalendarSyncPoller {
|
|
18
|
-
timer = null;
|
|
19
|
-
config;
|
|
20
|
-
constructor(config) {
|
|
21
|
-
this.config = config;
|
|
22
|
-
}
|
|
23
|
-
get manager() {
|
|
24
|
-
const configValues = JSON.parse(this.config.get("value"));
|
|
25
|
-
return new CalendarManager_js_1.CalendarManager({
|
|
26
|
-
tenantId: configValues.tenant_id,
|
|
27
|
-
clientID: configValues.client_id,
|
|
28
|
-
clientSecret: configValues.client_secret,
|
|
29
|
-
userMail: configValues.user_email,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Start polling the Microsoft Calendar delta feed.
|
|
34
|
-
* @param intervalMs polling interval in milliseconds (default: 5 minutes)
|
|
35
|
-
*/
|
|
36
|
-
start(intervalMs = 5 * 60 * 1000) {
|
|
37
|
-
if (this.manager?.isValid !== true) {
|
|
38
|
-
console.error(`[CalendarSyncPoller] Not started — invalid configuration: ${this.manager?.isValid}`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
this.poll().catch(console.error);
|
|
42
|
-
this.timer = setInterval(() => this.poll().catch(console.error), intervalMs);
|
|
43
|
-
}
|
|
44
|
-
stop() {
|
|
45
|
-
if (this.timer)
|
|
46
|
-
clearInterval(this.timer);
|
|
47
|
-
}
|
|
48
|
-
async poll() {
|
|
49
|
-
const deltaLink = await this.loadDeltaLink();
|
|
50
|
-
const result = await this.manager?.fetchDelta(deltaLink);
|
|
51
|
-
if (!result) {
|
|
52
|
-
console.error("[CalendarSyncPoller] Failed to fetch calendar delta.");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
for (const event of result.events) {
|
|
56
|
-
try {
|
|
57
|
-
await this.processEvent(event);
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
console.error("[CalendarSyncPoller] Error processing event:", event.id, err);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
await this.saveDeltaLink(result.deltaLink);
|
|
64
|
-
}
|
|
65
|
-
async processEvent(event) {
|
|
66
|
-
if (event["@removed"]) {
|
|
67
|
-
await this.handleDeleted(event.id);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
// Exception events are individual moved/edited occurrences of a series.
|
|
71
|
-
// The series master handles the recurrence as a whole; exceptions are noise.
|
|
72
|
-
if (event.type === "exception")
|
|
73
|
-
return;
|
|
74
|
-
const metaEntry = await (0, calendarMetaHelper_js_1.findCalendarMetaByEventId)(event.id);
|
|
75
|
-
if (metaEntry) {
|
|
76
|
-
const storedChangeKey = metaEntry.get("values")?.microsoftCalendarChangeKey;
|
|
77
|
-
// Skip if we caused this change (our write already stored this changeKey)
|
|
78
|
-
if (event.changeKey && storedChangeKey === event.changeKey)
|
|
79
|
-
return;
|
|
80
|
-
await this.updateScheduleFromEvent(metaEntry, event);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
// Delta responses omit most properties; fetch the full event before creating a schedule
|
|
84
|
-
const fullEvent = await this.manager?.fetchEvent(event.id);
|
|
85
|
-
if (!fullEvent)
|
|
86
|
-
return;
|
|
87
|
-
await this.createScheduleFromEvent(fullEvent);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async updateScheduleFromEvent(metaEntry, event) {
|
|
91
|
-
const scheduleId = metaEntry.get("entryObjectId");
|
|
92
|
-
if (!scheduleId)
|
|
93
|
-
return;
|
|
94
|
-
// Delta responses omit most fields; fetch the full event for title/body/cron
|
|
95
|
-
const fullEvent = (await this.manager?.fetchEvent(event.id)) ?? event;
|
|
96
|
-
const schedule = await new node_1.default.Query(index_js_1.Maintenance_Schedule).get(scheduleId, { useMasterKey: true });
|
|
97
|
-
if (fullEvent.subject)
|
|
98
|
-
schedule.set("title", fullEvent.subject);
|
|
99
|
-
if (fullEvent.bodyPreview)
|
|
100
|
-
schedule.set("description", fullEvent.bodyPreview);
|
|
101
|
-
const cronData = (0, eventToSchedule_js_1.eventToSchedule)(fullEvent);
|
|
102
|
-
if (cronData) {
|
|
103
|
-
const { notifyBeforeDue, ...cron } = cronData;
|
|
104
|
-
schedule.set("cron", cron);
|
|
105
|
-
if (notifyBeforeDue != null)
|
|
106
|
-
schedule.set("notifyBeforeDue", notifyBeforeDue);
|
|
107
|
-
}
|
|
108
|
-
// useMasterKey prevents afterSaveHook from re-syncing back to calendar
|
|
109
|
-
await schedule.save(null, { useMasterKey: true });
|
|
110
|
-
if (event.changeKey) {
|
|
111
|
-
await (0, calendarMetaHelper_js_1.updateCalendarChangeKey)(metaEntry, event.changeKey, fullEvent);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async createScheduleFromEvent(event) {
|
|
115
|
-
const parsed = parseEventSubject(event.subject);
|
|
116
|
-
let source;
|
|
117
|
-
const tenant = this.config.get("tenant");
|
|
118
|
-
if (parsed) {
|
|
119
|
-
source = await new node_1.default.Query(index_js_1.Source)
|
|
120
|
-
.equalTo("name", parsed.sourceName)
|
|
121
|
-
.equalTo("tenant", tenant)
|
|
122
|
-
.first({ useMasterKey: true });
|
|
123
|
-
}
|
|
124
|
-
if (!source) {
|
|
125
|
-
const configValues = JSON.parse(this.config.get("value"));
|
|
126
|
-
if (!configValues.default_source_id) {
|
|
127
|
-
console.error(`[CalendarSyncPoller] Skipping event ${event.id} — no source name in subject and no default_source_id configured.`);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
source = await new node_1.default.Query(index_js_1.Source)
|
|
131
|
-
.equalTo("objectId", configValues.default_source_id)
|
|
132
|
-
.first({ useMasterKey: true });
|
|
133
|
-
if (!source) {
|
|
134
|
-
console.error(`[CalendarSyncPoller] Skipping event ${event.id} — default source "${configValues.default_source_id}" not found.`);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const schedule = new index_js_1.Maintenance_Schedule();
|
|
139
|
-
schedule.set("title", event.subject);
|
|
140
|
-
schedule.set("source", source);
|
|
141
|
-
schedule.set("enabled", true);
|
|
142
|
-
schedule.set("tenant", tenant);
|
|
143
|
-
if (event.bodyPreview)
|
|
144
|
-
schedule.set("description", event.bodyPreview);
|
|
145
|
-
const cronData = (0, eventToSchedule_js_1.eventToSchedule)(event);
|
|
146
|
-
if (cronData) {
|
|
147
|
-
const { notifyBeforeDue, ...cron } = cronData;
|
|
148
|
-
schedule.set("cron", cron);
|
|
149
|
-
if (notifyBeforeDue != null)
|
|
150
|
-
schedule.set("notifyBeforeDue", notifyBeforeDue);
|
|
151
|
-
}
|
|
152
|
-
// useMasterKey prevents afterSaveHook from syncing back to calendar
|
|
153
|
-
await schedule.save(null, { useMasterKey: true });
|
|
154
|
-
await (0, calendarMetaHelper_js_1.saveCalendarMeta)(schedule.id, event.id, event.changeKey, tenant, event);
|
|
155
|
-
}
|
|
156
|
-
async handleDeleted(eventId) {
|
|
157
|
-
const metaEntry = await (0, calendarMetaHelper_js_1.findCalendarMetaByEventId)(eventId);
|
|
158
|
-
if (!metaEntry)
|
|
159
|
-
return;
|
|
160
|
-
const scheduleId = metaEntry.get("entryObjectId");
|
|
161
|
-
if (scheduleId) {
|
|
162
|
-
try {
|
|
163
|
-
const schedule = await new node_1.default.Query(index_js_1.Maintenance_Schedule).get(scheduleId, { useMasterKey: true });
|
|
164
|
-
// Disable rather than delete to preserve execution history
|
|
165
|
-
schedule.set("enabled", false);
|
|
166
|
-
await schedule.save(null, { useMasterKey: true });
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
console.error("[CalendarSyncPoller] Could not disable schedule for deleted event:", scheduleId, err);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
await metaEntry.destroy({ useMasterKey: true });
|
|
173
|
-
}
|
|
174
|
-
async loadDeltaLink() {
|
|
175
|
-
this.config = await this.config.fetch({ useMasterKey: true });
|
|
176
|
-
const values = JSON.parse(this.config.get("value"));
|
|
177
|
-
return values.delta_link;
|
|
178
|
-
}
|
|
179
|
-
async saveDeltaLink(link) {
|
|
180
|
-
this.config = await this.config.fetch({ useMasterKey: true });
|
|
181
|
-
const values = JSON.parse(this.config.get("value"));
|
|
182
|
-
values.delta_link = link;
|
|
183
|
-
this.config.set("value", JSON.stringify(values));
|
|
184
|
-
await this.config.save(null, { useMasterKey: true });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
exports.CalendarSyncPoller = CalendarSyncPoller;
|
|
188
|
-
// Parses the source name out of an Outlook-originated event subject.
|
|
189
|
-
// Expected format for externally-created events: "<source.name>" - <anything>
|
|
190
|
-
// Quotes around the source name are optional.
|
|
191
|
-
function parseEventSubject(subject) {
|
|
192
|
-
if (!subject)
|
|
193
|
-
return null;
|
|
194
|
-
const separatorIdx = subject.indexOf(" - ");
|
|
195
|
-
if (separatorIdx === -1)
|
|
196
|
-
return null;
|
|
197
|
-
const rawSource = subject.slice(0, separatorIdx).trim();
|
|
198
|
-
if (!rawSource)
|
|
199
|
-
return null;
|
|
200
|
-
const sourceName = rawSource.replace(/^"(.*)"$/, "$1");
|
|
201
|
-
return { sourceName };
|
|
202
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
3
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
4
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
5
|
-
*/
|
|
6
|
-
export type ConfigValues = {
|
|
7
|
-
tenant_id: string;
|
|
8
|
-
client_id: string;
|
|
9
|
-
client_secret: string;
|
|
10
|
-
user_email: string;
|
|
11
|
-
default_source_id?: string;
|
|
12
|
-
delta_link?: string;
|
|
13
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Microsoft Graph calendar types — the wire shapes, not ours.
|
|
4
|
-
*
|
|
5
|
-
* In the v1 folder for history only, and **not** deprecated with the rest of
|
|
6
|
-
* it: `serviceSchedules/calendarSync` reads these same types, because the
|
|
7
|
-
* Graph payload is the same whichever class we map it onto.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Meta_Entry, Tenant } from "../../../../types/index.js";
|
|
2
|
-
import { MetaConfig } from "../../../../types/custom/MetaField.js";
|
|
3
|
-
import { GraphEventResponse } from "./Event.js";
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
6
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
7
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
8
|
-
*/
|
|
9
|
-
export declare const CALENDAR_SYNC_CONTEXT: string;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
12
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
13
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
14
|
-
*/
|
|
15
|
-
export interface CalendarEventSnapshot {
|
|
16
|
-
id: string;
|
|
17
|
-
subject?: string;
|
|
18
|
-
start: {
|
|
19
|
-
dateTime: string;
|
|
20
|
-
timeZone: string;
|
|
21
|
-
};
|
|
22
|
-
end: {
|
|
23
|
-
dateTime: string;
|
|
24
|
-
timeZone: string;
|
|
25
|
-
};
|
|
26
|
-
isAllDay?: boolean;
|
|
27
|
-
isCancelled?: boolean;
|
|
28
|
-
body?: {
|
|
29
|
-
contentType?: string;
|
|
30
|
-
content?: string;
|
|
31
|
-
};
|
|
32
|
-
recurrence?: GraphEventResponse["recurrence"];
|
|
33
|
-
location?: {
|
|
34
|
-
displayName?: string;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
39
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
40
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
41
|
-
*/
|
|
42
|
-
export interface CalendarMetaValues {
|
|
43
|
-
microsoftCalendarEventId: string;
|
|
44
|
-
microsoftCalendarChangeKey?: string;
|
|
45
|
-
microsoftCalendarEvent?: CalendarEventSnapshot;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
49
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
50
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
51
|
-
*/
|
|
52
|
-
export declare const CalendarMetaConfig: MetaConfig;
|
|
53
|
-
/**
|
|
54
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
55
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
56
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
57
|
-
*/
|
|
58
|
-
export declare function findCalendarMetaForSchedule(scheduleId: string): Promise<Meta_Entry | null>;
|
|
59
|
-
/**
|
|
60
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
61
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
62
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
63
|
-
*/
|
|
64
|
-
export declare function findCalendarMetaByEventId(eventId: string): Promise<Meta_Entry | null>;
|
|
65
|
-
/**
|
|
66
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
67
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
68
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
69
|
-
*/
|
|
70
|
-
export declare function saveCalendarMeta(scheduleId: string, eventId: string, changeKey?: string, tenant?: Tenant, event?: GraphEventResponse): Promise<Meta_Entry>;
|
|
71
|
-
/**
|
|
72
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
73
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
74
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
75
|
-
*/
|
|
76
|
-
export declare function updateCalendarChangeKey(entry: Meta_Entry, changeKey: string, event?: GraphEventResponse): Promise<void>;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CalendarMetaConfig = exports.CALENDAR_SYNC_CONTEXT = void 0;
|
|
7
|
-
exports.findCalendarMetaForSchedule = findCalendarMetaForSchedule;
|
|
8
|
-
exports.findCalendarMetaByEventId = findCalendarMetaByEventId;
|
|
9
|
-
exports.saveCalendarMeta = saveCalendarMeta;
|
|
10
|
-
exports.updateCalendarChangeKey = updateCalendarChangeKey;
|
|
11
|
-
const node_1 = __importDefault(require("parse/node"));
|
|
12
|
-
const index_js_1 = require("../../../../types/index.js");
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
15
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
16
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
17
|
-
*/
|
|
18
|
-
exports.CALENDAR_SYNC_CONTEXT = JSON.stringify([
|
|
19
|
-
"schedule",
|
|
20
|
-
"sync",
|
|
21
|
-
"microsoft",
|
|
22
|
-
]);
|
|
23
|
-
function toEventSnapshot(event) {
|
|
24
|
-
return {
|
|
25
|
-
id: event.id,
|
|
26
|
-
subject: event.subject,
|
|
27
|
-
start: event.start,
|
|
28
|
-
end: event.end,
|
|
29
|
-
isAllDay: event.isAllDay,
|
|
30
|
-
isCancelled: event.isCancelled,
|
|
31
|
-
body: event.body
|
|
32
|
-
? { contentType: event.body.contentType, content: event.body.content }
|
|
33
|
-
: undefined,
|
|
34
|
-
recurrence: event.recurrence ?? undefined,
|
|
35
|
-
location: event.location?.displayName
|
|
36
|
-
? { displayName: event.location.displayName }
|
|
37
|
-
: undefined,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
42
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
43
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
44
|
-
*/
|
|
45
|
-
exports.CalendarMetaConfig = {
|
|
46
|
-
fields: [
|
|
47
|
-
{
|
|
48
|
-
name: "microsoftCalendarEventId",
|
|
49
|
-
type: "string",
|
|
50
|
-
label: "Microsoft Calendar Event ID",
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: "microsoftCalendarChangeKey",
|
|
54
|
-
type: "string",
|
|
55
|
-
label: "Microsoft Calendar Change Key",
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
61
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
62
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
63
|
-
*/
|
|
64
|
-
async function findCalendarMetaForSchedule(scheduleId) {
|
|
65
|
-
return ((await new node_1.default.Query(index_js_1.Meta_Entry)
|
|
66
|
-
.equalTo("context", exports.CALENDAR_SYNC_CONTEXT)
|
|
67
|
-
.equalTo("entryClassName", index_js_1.Maintenance_Schedule.className)
|
|
68
|
-
.equalTo("entryObjectId", scheduleId)
|
|
69
|
-
.first({ useMasterKey: true })) ?? null);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
73
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
74
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
75
|
-
*/
|
|
76
|
-
async function findCalendarMetaByEventId(eventId) {
|
|
77
|
-
return ((await new node_1.default.Query(index_js_1.Meta_Entry)
|
|
78
|
-
.equalTo("context", exports.CALENDAR_SYNC_CONTEXT)
|
|
79
|
-
.equalTo("entryClassName", index_js_1.Maintenance_Schedule.className)
|
|
80
|
-
// @ts-expect-error
|
|
81
|
-
.equalTo("values.microsoftCalendarEventId", eventId)
|
|
82
|
-
.first({ useMasterKey: true })) ?? null);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
86
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
87
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
88
|
-
*/
|
|
89
|
-
async function saveCalendarMeta(scheduleId, eventId, changeKey, tenant, event) {
|
|
90
|
-
let entry = await findCalendarMetaForSchedule(scheduleId);
|
|
91
|
-
if (!entry) {
|
|
92
|
-
entry = new index_js_1.Meta_Entry();
|
|
93
|
-
entry.set("context", exports.CALENDAR_SYNC_CONTEXT);
|
|
94
|
-
entry.set("entryClassName", index_js_1.Maintenance_Schedule.className);
|
|
95
|
-
entry.set("entryObjectId", scheduleId);
|
|
96
|
-
entry.set("tenant", tenant);
|
|
97
|
-
entry.set("config", {});
|
|
98
|
-
}
|
|
99
|
-
const values = { microsoftCalendarEventId: eventId };
|
|
100
|
-
if (changeKey)
|
|
101
|
-
values.microsoftCalendarChangeKey = changeKey;
|
|
102
|
-
if (event)
|
|
103
|
-
values.microsoftCalendarEvent = toEventSnapshot(event);
|
|
104
|
-
entry.set("values", values);
|
|
105
|
-
return entry.save(null, { useMasterKey: true });
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @deprecated the v1 Outlook sync (`Maintenance_Schedule`). Replaced by
|
|
109
|
-
* `serviceSchedules/calendarSync/`. The Graph client itself
|
|
110
|
-
* (`CalendarManager`, `Event`, `Access`) is **not** deprecated — v2 shares it.
|
|
111
|
-
*/
|
|
112
|
-
async function updateCalendarChangeKey(entry, changeKey, event) {
|
|
113
|
-
entry.set("values", {
|
|
114
|
-
...entry.get("values"),
|
|
115
|
-
microsoftCalendarChangeKey: changeKey,
|
|
116
|
-
...(event ? { microsoftCalendarEvent: toEventSnapshot(event) } : {}),
|
|
117
|
-
});
|
|
118
|
-
await entry.save(null, { useMasterKey: true });
|
|
119
|
-
}
|