@blazeo.com/calendar-client 1.0.0 → 1.0.1
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/README.md +79 -0
- package/dist/index.d.mts +741 -0
- package/dist/index.d.ts +741 -0
- package/dist/index.js +707 -0
- package/dist/index.mjs +663 -0
- package/package.json +46 -12
package/dist/index.js
ADDED
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AppointmentClient: () => AppointmentClient,
|
|
24
|
+
AssignmentMethod: () => AssignmentMethod,
|
|
25
|
+
AttendeeStatus: () => AttendeeStatus,
|
|
26
|
+
AvailabilityDetailModel: () => AvailabilityDetail_default,
|
|
27
|
+
AvailabilityModel: () => Availability_default,
|
|
28
|
+
CalendarModel: () => Calendar_default,
|
|
29
|
+
CalendarParticipantModel: () => CalendarParticipant_default,
|
|
30
|
+
DayOfWeek: () => DayOfWeek,
|
|
31
|
+
EventModel: () => Event_default,
|
|
32
|
+
OpeningHourModel: () => OpeningHour_default,
|
|
33
|
+
ParticipantModel: () => Participant_default,
|
|
34
|
+
RecurringFrequency: () => RecurringFrequency,
|
|
35
|
+
RootStore: () => RootStore,
|
|
36
|
+
SettingModel: () => Setting_default,
|
|
37
|
+
TimeFrameModel: () => TimeFrame_default,
|
|
38
|
+
TimeSlotModel: () => TimeSlot_default,
|
|
39
|
+
Unit: () => Unit,
|
|
40
|
+
mapCreateEventInputToEvent: () => mapCreateEventInputToEvent
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/mapper.ts
|
|
45
|
+
function pickStr(obj, ...keys) {
|
|
46
|
+
for (const k of keys) {
|
|
47
|
+
const v = obj[k];
|
|
48
|
+
if (v != null && typeof v === "string") return v;
|
|
49
|
+
}
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
function pickNum(obj, ...keys) {
|
|
53
|
+
for (const k of keys) {
|
|
54
|
+
const v = obj[k];
|
|
55
|
+
if (v != null) {
|
|
56
|
+
const n = typeof v === "number" ? v : Number(v);
|
|
57
|
+
if (!Number.isNaN(n)) return n;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
function parseDate(s) {
|
|
63
|
+
if (!s) return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
64
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return s;
|
|
65
|
+
const d = new Date(s);
|
|
66
|
+
return isNaN(d.getTime()) ? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) : d.toISOString().slice(0, 10);
|
|
67
|
+
}
|
|
68
|
+
function mapCreateEventInputToEvent(input) {
|
|
69
|
+
const calendarId = input.calendarId ?? input.calendar_id;
|
|
70
|
+
const visitorName = pickStr(input, "visitorName", "visitor_name") ?? "";
|
|
71
|
+
const visitorEmail = pickStr(input, "visitorEmail", "visitor_email") ?? "";
|
|
72
|
+
const visitorPhone = pickStr(input, "visitorPhone", "visitor_phone") ?? "";
|
|
73
|
+
const startDateStr = pickStr(input, "startDate", "start_date");
|
|
74
|
+
const endDateStr = pickStr(input, "endDate", "end_date");
|
|
75
|
+
const startHour = pickNum(input, "startHour", "start_hour") ?? 0;
|
|
76
|
+
const startMinute = pickNum(input, "startMinute", "start_minute") ?? 0;
|
|
77
|
+
const endHour = pickNum(input, "endHour", "end_hour") ?? startHour;
|
|
78
|
+
const endMinute = pickNum(input, "endMinute", "end_minute") ?? startMinute;
|
|
79
|
+
let startDate = parseDate(startDateStr);
|
|
80
|
+
let parsedStartHour = startHour;
|
|
81
|
+
let parsedStartMinute = startMinute;
|
|
82
|
+
const startTime = pickStr(input, "startTime", "start_time");
|
|
83
|
+
if (startTime && /^\d{1,2}:\d{2}$/.test(startTime)) {
|
|
84
|
+
const [h, m] = startTime.split(":").map(Number);
|
|
85
|
+
parsedStartHour = h;
|
|
86
|
+
parsedStartMinute = m;
|
|
87
|
+
}
|
|
88
|
+
const endDate = endDateStr ? parseDate(endDateStr) : startDate;
|
|
89
|
+
const rawParticipantId = input.participantId ?? input.participant_id;
|
|
90
|
+
const participantId = rawParticipantId == null ? null : typeof rawParticipantId === "string" ? rawParticipantId : String(rawParticipantId);
|
|
91
|
+
return {
|
|
92
|
+
calendarId,
|
|
93
|
+
participantId,
|
|
94
|
+
title: input.title ?? "",
|
|
95
|
+
description: input.description ?? "",
|
|
96
|
+
startDate,
|
|
97
|
+
endDate,
|
|
98
|
+
startHour: parsedStartHour,
|
|
99
|
+
startMinute: parsedStartMinute,
|
|
100
|
+
endHour,
|
|
101
|
+
endMinute,
|
|
102
|
+
visitorName,
|
|
103
|
+
visitorEmail,
|
|
104
|
+
visitorPhone,
|
|
105
|
+
isRecurring: false,
|
|
106
|
+
recurringFrequency: 0
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/client.ts
|
|
111
|
+
function normalizeBaseUrl(baseUrl) {
|
|
112
|
+
return baseUrl.replace(/\/+$/, "");
|
|
113
|
+
}
|
|
114
|
+
function buildQuery(params) {
|
|
115
|
+
const search = new URLSearchParams();
|
|
116
|
+
for (const [k, v] of Object.entries(params)) {
|
|
117
|
+
if (v === void 0 || v === null) continue;
|
|
118
|
+
search.set(k, String(v));
|
|
119
|
+
}
|
|
120
|
+
const q = search.toString();
|
|
121
|
+
return q ? `?${q}` : "";
|
|
122
|
+
}
|
|
123
|
+
var AppointmentClient = class {
|
|
124
|
+
constructor(config) {
|
|
125
|
+
this.baseUrl = normalizeBaseUrl(config.baseUrl);
|
|
126
|
+
this.getDefaultOffset = config.getDefaultOffset ?? (() => (/* @__PURE__ */ new Date()).getTimezoneOffset());
|
|
127
|
+
this.fetchFn = config.fetch ?? (typeof fetch !== "undefined" ? fetch : (() => {
|
|
128
|
+
throw new Error("fetch not available");
|
|
129
|
+
})());
|
|
130
|
+
}
|
|
131
|
+
async request(path, options = {}) {
|
|
132
|
+
const { method = "GET", headers = {}, body, query } = options;
|
|
133
|
+
const url = `${this.baseUrl}${path}${buildQuery(query ?? {})}`;
|
|
134
|
+
const reqHeaders = {
|
|
135
|
+
"Content-Type": "application/json",
|
|
136
|
+
...headers
|
|
137
|
+
};
|
|
138
|
+
const res = await this.fetchFn(url, { method, headers: reqHeaders, body });
|
|
139
|
+
const text = await res.text();
|
|
140
|
+
let data;
|
|
141
|
+
try {
|
|
142
|
+
data = JSON.parse(text);
|
|
143
|
+
} catch {
|
|
144
|
+
data = { status: "failure", message: text || res.statusText };
|
|
145
|
+
}
|
|
146
|
+
if (!res.ok && data.status !== "failure") {
|
|
147
|
+
data.status = "failure";
|
|
148
|
+
data.message = data.message ?? `HTTP ${res.status}`;
|
|
149
|
+
}
|
|
150
|
+
return data;
|
|
151
|
+
}
|
|
152
|
+
// ---------- Event ----------
|
|
153
|
+
/** GET /event/get – by event_id or externalevent_id */
|
|
154
|
+
async getEvent(params) {
|
|
155
|
+
if (params.eventId ?? params.event_id) {
|
|
156
|
+
return this.request("/event/get", {
|
|
157
|
+
query: { event_id: params.eventId ?? params.event_id }
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (params.externalEventId ?? params.externalevent_id) {
|
|
161
|
+
return this.request("/event/get", {
|
|
162
|
+
query: { externalevent_id: params.externalEventId ?? params.externalevent_id }
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return Promise.resolve({ status: "failure", message: "Provide eventId or externalEventId" });
|
|
166
|
+
}
|
|
167
|
+
/** GET /event/availability/get – slots for a day. Optional participant_id. */
|
|
168
|
+
async getAvailability(params) {
|
|
169
|
+
const calendarId = params.calendarId ?? params.calendar_id;
|
|
170
|
+
const offset = params.offset;
|
|
171
|
+
const query = {
|
|
172
|
+
calendar_id: calendarId,
|
|
173
|
+
year: params.year,
|
|
174
|
+
month: params.month,
|
|
175
|
+
day: params.day
|
|
176
|
+
};
|
|
177
|
+
if (params.participantId ?? params.participant_id) {
|
|
178
|
+
query.participant_id = params.participantId ?? params.participant_id;
|
|
179
|
+
}
|
|
180
|
+
return this.request("/event/availability/get", {
|
|
181
|
+
headers: { offset: String(offset) },
|
|
182
|
+
query
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** GET /event/day/selectable/get – whether the day has any slots. Optional participant_id. */
|
|
186
|
+
async getDaySelectable(params) {
|
|
187
|
+
const calendarId = params.calendarId ?? params.calendar_id;
|
|
188
|
+
const query = {
|
|
189
|
+
calendar_id: calendarId,
|
|
190
|
+
year: params.year,
|
|
191
|
+
month: params.month,
|
|
192
|
+
day: params.day
|
|
193
|
+
};
|
|
194
|
+
if (params.participantId ?? params.participant_id) {
|
|
195
|
+
query.participant_id = params.participantId ?? params.participant_id;
|
|
196
|
+
}
|
|
197
|
+
const res = await this.request("/event/day/selectable/get", {
|
|
198
|
+
headers: { offset: String(params.offset) },
|
|
199
|
+
query
|
|
200
|
+
});
|
|
201
|
+
if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
|
|
202
|
+
return res;
|
|
203
|
+
}
|
|
204
|
+
/** GET /event/days/available/get – list of next N available days (yyyy-MM-dd). */
|
|
205
|
+
async getEarliestAvailableDays(params) {
|
|
206
|
+
const calendarId = params.calendarId ?? params.calendar_id;
|
|
207
|
+
const query = {
|
|
208
|
+
calendar_id: calendarId,
|
|
209
|
+
count: params.count
|
|
210
|
+
};
|
|
211
|
+
if (params.year != null) query.year = params.year;
|
|
212
|
+
if (params.month != null) query.month = params.month;
|
|
213
|
+
if (params.day != null) query.day = params.day;
|
|
214
|
+
return this.request("/event/days/available/get", {
|
|
215
|
+
headers: { offset: String(params.offset) },
|
|
216
|
+
query
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/** GET /event/existing/getbyvisitoremail – by company_key or calendar_id */
|
|
220
|
+
async getExistingEventsByVisitorEmail(params) {
|
|
221
|
+
const query = {
|
|
222
|
+
email: params.email,
|
|
223
|
+
offset: params.offset
|
|
224
|
+
};
|
|
225
|
+
if (params.companyKey ?? params.company_key) query.company_key = params.companyKey ?? params.company_key;
|
|
226
|
+
if (params.calendarId ?? params.calendar_id) query.calendar_id = params.calendarId ?? params.calendar_id;
|
|
227
|
+
return this.request("/event/existing/getbyvisitoremail", {
|
|
228
|
+
headers: { offset: String(params.offset) },
|
|
229
|
+
query
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** GET /event/existing/getbyvisitorphone – by company_key or calendar_id */
|
|
233
|
+
async getExistingEventsByVisitorPhone(params) {
|
|
234
|
+
const query = {
|
|
235
|
+
phone: params.phone,
|
|
236
|
+
offset: params.offset
|
|
237
|
+
};
|
|
238
|
+
if (params.companyKey ?? params.company_key) query.company_key = params.companyKey ?? params.company_key;
|
|
239
|
+
if (params.calendarId ?? params.calendar_id) query.calendar_id = params.calendarId ?? params.calendar_id;
|
|
240
|
+
return this.request("/event/existing/getbyvisitorphone", {
|
|
241
|
+
headers: { offset: String(params.offset) },
|
|
242
|
+
query
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** POST /event/create – create event. Accepts flexible input; maps to backend shape. */
|
|
246
|
+
async createEvent(input, offsetMinutes) {
|
|
247
|
+
const offset = offsetMinutes ?? this.getDefaultOffset();
|
|
248
|
+
const body = mapCreateEventInputToEvent(input);
|
|
249
|
+
return this.request("/event/create", {
|
|
250
|
+
method: "POST",
|
|
251
|
+
headers: { offset: String(offset) },
|
|
252
|
+
body: JSON.stringify(body)
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
/** GET /event/cancel – cancel by event_id */
|
|
256
|
+
async cancelEvent(eventId) {
|
|
257
|
+
return this.request("/event/cancel", { query: { event_id: eventId } });
|
|
258
|
+
}
|
|
259
|
+
/** GET /event/cancellable – check if event can be cancelled */
|
|
260
|
+
async getCancellable(eventId) {
|
|
261
|
+
const res = await this.request("/event/cancellable", { query: { event_id: eventId } });
|
|
262
|
+
if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
|
|
263
|
+
return res;
|
|
264
|
+
}
|
|
265
|
+
/** GET /event/participant/roundrobin/get – get assignable participant for calendar */
|
|
266
|
+
async getRoundRobinParticipant(calendarId) {
|
|
267
|
+
return this.request("/event/participant/roundrobin/get", {
|
|
268
|
+
query: { calendar_id: calendarId }
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/** GET /event/attendeeStatus – set attendee status (route: /event/{eventId}/{attendeeStatus}) */
|
|
272
|
+
async setAttendeeStatus(eventId, attendeeStatus) {
|
|
273
|
+
return this.request(`/event/${encodeURIComponent(eventId)}/${encodeURIComponent(attendeeStatus)}`);
|
|
274
|
+
}
|
|
275
|
+
/** GET /event/seteventreminder/{event_id} */
|
|
276
|
+
async setEventReminder(eventId) {
|
|
277
|
+
return this.request(`/event/seteventreminder/${encodeURIComponent(eventId)}`);
|
|
278
|
+
}
|
|
279
|
+
// ---------- Calendar ----------
|
|
280
|
+
/** GET Calendar/Get – get calendar by calendar_id */
|
|
281
|
+
async getCalendar(calendarId) {
|
|
282
|
+
return this.request("/Calendar/Get", { query: { calendar_id: calendarId } });
|
|
283
|
+
}
|
|
284
|
+
/** GET Calendar/All – calendars by company_key */
|
|
285
|
+
async getCalendarsByCompany(companyKey) {
|
|
286
|
+
return this.request("/Calendar/All", { query: { company_key: companyKey } });
|
|
287
|
+
}
|
|
288
|
+
/** GET Calendar/TimeZones/Get */
|
|
289
|
+
async getTimeZones() {
|
|
290
|
+
return this.request("/Calendar/TimeZones/Get");
|
|
291
|
+
}
|
|
292
|
+
/** GET Calendar/TimeZone/Get – display name for timezone_id */
|
|
293
|
+
async getTimeZone(timezoneId) {
|
|
294
|
+
return this.request("/Calendar/TimeZone/Get", { query: { timezone_id: timezoneId } });
|
|
295
|
+
}
|
|
296
|
+
/** POST Calendar/Create – create or update calendar */
|
|
297
|
+
async createCalendar(payload) {
|
|
298
|
+
return this.request("/Calendar/Create", { method: "POST", body: JSON.stringify(payload) });
|
|
299
|
+
}
|
|
300
|
+
/** GET Calendar/Remove */
|
|
301
|
+
async removeCalendar(calendarId) {
|
|
302
|
+
return this.request(`/Calendar/Remove`, { query: { calendar_id: calendarId } });
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/models/appointment/Calendar.ts
|
|
307
|
+
var import_mobx_state_tree = require("mobx-state-tree");
|
|
308
|
+
|
|
309
|
+
// src/models/appointment/enums.ts
|
|
310
|
+
var Unit = {
|
|
311
|
+
Minutes: 1,
|
|
312
|
+
Hours: 2,
|
|
313
|
+
Days: 3,
|
|
314
|
+
Months: 4,
|
|
315
|
+
Year: 5,
|
|
316
|
+
Week: 6
|
|
317
|
+
};
|
|
318
|
+
var AssignmentMethod = {
|
|
319
|
+
RoundRobin: 1,
|
|
320
|
+
MaximizeAvailability: 2
|
|
321
|
+
};
|
|
322
|
+
var AttendeeStatus = {
|
|
323
|
+
None: 0,
|
|
324
|
+
Accepted: 1,
|
|
325
|
+
Declined: 2,
|
|
326
|
+
Tentative: 3,
|
|
327
|
+
NeedsAction: 4,
|
|
328
|
+
Canceled: 5
|
|
329
|
+
};
|
|
330
|
+
var RecurringFrequency = {
|
|
331
|
+
None: 0,
|
|
332
|
+
Daily: 1,
|
|
333
|
+
Weekly: 2,
|
|
334
|
+
Monthly: 3,
|
|
335
|
+
Yearly: 4
|
|
336
|
+
};
|
|
337
|
+
var DayOfWeek = {
|
|
338
|
+
Sunday: 0,
|
|
339
|
+
Monday: 1,
|
|
340
|
+
Tuesday: 2,
|
|
341
|
+
Wednesday: 3,
|
|
342
|
+
Thursday: 4,
|
|
343
|
+
Friday: 5,
|
|
344
|
+
Saturday: 6
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/models/appointment/Calendar.ts
|
|
348
|
+
var CalendarModel = import_mobx_state_tree.types.model("Calendar", {
|
|
349
|
+
id: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.number),
|
|
350
|
+
companyKey: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
351
|
+
calendarId: import_mobx_state_tree.types.identifier,
|
|
352
|
+
name: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
353
|
+
location: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
354
|
+
timeZoneId: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
355
|
+
purpose: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, ""),
|
|
356
|
+
description: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
357
|
+
assignmentMethod: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, AssignmentMethod.RoundRobin),
|
|
358
|
+
duration: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
359
|
+
durationUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
360
|
+
minimumBookingNotice: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
361
|
+
minimumBookingNoticeUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
362
|
+
minimumCancelationNotice: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
363
|
+
minimumCancelationNoticeUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
364
|
+
futureLimit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
365
|
+
futureLimitUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Days),
|
|
366
|
+
bufferTime: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
367
|
+
bufferTimeUnit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, Unit.Minutes),
|
|
368
|
+
bookingLimit: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.number, 0),
|
|
369
|
+
createdOn: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string),
|
|
370
|
+
modifiedOn: import_mobx_state_tree.types.maybeNull(import_mobx_state_tree.types.string)
|
|
371
|
+
}).actions((self) => ({
|
|
372
|
+
async create() {
|
|
373
|
+
const api = (0, import_mobx_state_tree.getEnv)(self).api;
|
|
374
|
+
const payload = {
|
|
375
|
+
calendarId: self.calendarId,
|
|
376
|
+
companyKey: self.companyKey ?? void 0,
|
|
377
|
+
name: self.name ?? void 0,
|
|
378
|
+
location: self.location ?? void 0,
|
|
379
|
+
timeZoneId: self.timeZoneId ?? void 0,
|
|
380
|
+
purpose: self.purpose,
|
|
381
|
+
description: self.description ?? void 0,
|
|
382
|
+
assignmentMethod: self.assignmentMethod,
|
|
383
|
+
duration: self.duration,
|
|
384
|
+
durationUnit: self.durationUnit,
|
|
385
|
+
minimumBookingNotice: self.minimumBookingNotice,
|
|
386
|
+
minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
|
|
387
|
+
minimumCancelationNotice: self.minimumCancelationNotice,
|
|
388
|
+
minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
|
|
389
|
+
futureLimit: self.futureLimit,
|
|
390
|
+
futureLimitUnit: self.futureLimitUnit,
|
|
391
|
+
bufferTime: self.bufferTime,
|
|
392
|
+
bufferTimeUnit: self.bufferTimeUnit,
|
|
393
|
+
bookingLimit: self.bookingLimit
|
|
394
|
+
};
|
|
395
|
+
const res = await api.createCalendar(payload);
|
|
396
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree.applySnapshot)(self, { ...res.data, calendarId: self.calendarId });
|
|
397
|
+
return res;
|
|
398
|
+
},
|
|
399
|
+
async get() {
|
|
400
|
+
const api = (0, import_mobx_state_tree.getEnv)(self).api;
|
|
401
|
+
const res = await api.getCalendar(self.calendarId);
|
|
402
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree.applySnapshot)(self, { ...res.data, calendarId: self.calendarId });
|
|
403
|
+
return res;
|
|
404
|
+
},
|
|
405
|
+
async remove() {
|
|
406
|
+
const api = (0, import_mobx_state_tree.getEnv)(self).api;
|
|
407
|
+
return api.removeCalendar(self.calendarId);
|
|
408
|
+
}
|
|
409
|
+
}));
|
|
410
|
+
var Calendar_default = CalendarModel;
|
|
411
|
+
|
|
412
|
+
// src/models/appointment/Event.ts
|
|
413
|
+
var import_mobx_state_tree2 = require("mobx-state-tree");
|
|
414
|
+
var EventModel = import_mobx_state_tree2.types.model("Event", {
|
|
415
|
+
id: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.number),
|
|
416
|
+
eventId: import_mobx_state_tree2.types.identifier,
|
|
417
|
+
calendarId: import_mobx_state_tree2.types.string,
|
|
418
|
+
participantId: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
419
|
+
title: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
420
|
+
description: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
421
|
+
isRecurring: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.boolean, false),
|
|
422
|
+
recurringFrequency: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, RecurringFrequency.None),
|
|
423
|
+
startDate: import_mobx_state_tree2.types.string,
|
|
424
|
+
endDate: import_mobx_state_tree2.types.string,
|
|
425
|
+
startHour: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
426
|
+
startMinute: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
427
|
+
endHour: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
428
|
+
endMinute: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
|
|
429
|
+
visitorName: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
430
|
+
visitorEmail: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
431
|
+
visitorPhone: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
432
|
+
createdOn: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
433
|
+
modifiedOn: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
434
|
+
externalEventId: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
435
|
+
attendeeStatus: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, AttendeeStatus.Tentative),
|
|
436
|
+
rescheduleLink: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
437
|
+
cancelLink: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
438
|
+
timeZone: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string),
|
|
439
|
+
offset: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0)
|
|
440
|
+
}).actions((self) => ({
|
|
441
|
+
async get(params) {
|
|
442
|
+
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
443
|
+
const res = await api.getEvent(params);
|
|
444
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree2.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
445
|
+
return res;
|
|
446
|
+
},
|
|
447
|
+
async create(offsetMinutes) {
|
|
448
|
+
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
449
|
+
const payload = {
|
|
450
|
+
calendarId: self.calendarId,
|
|
451
|
+
participantId: self.participantId ?? void 0,
|
|
452
|
+
title: self.title ?? void 0,
|
|
453
|
+
description: self.description ?? void 0,
|
|
454
|
+
startDate: self.startDate,
|
|
455
|
+
endDate: self.endDate,
|
|
456
|
+
startHour: self.startHour,
|
|
457
|
+
startMinute: self.startMinute,
|
|
458
|
+
endHour: self.endHour,
|
|
459
|
+
endMinute: self.endMinute,
|
|
460
|
+
visitorName: self.visitorName ?? void 0,
|
|
461
|
+
visitorEmail: self.visitorEmail ?? void 0,
|
|
462
|
+
visitorPhone: self.visitorPhone ?? void 0
|
|
463
|
+
};
|
|
464
|
+
const res = await api.createEvent(payload, offsetMinutes);
|
|
465
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree2.applySnapshot)(self, { ...res.data, eventId: self.eventId });
|
|
466
|
+
return res;
|
|
467
|
+
},
|
|
468
|
+
async cancel() {
|
|
469
|
+
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
470
|
+
return api.cancelEvent(self.eventId);
|
|
471
|
+
},
|
|
472
|
+
async getCancellable() {
|
|
473
|
+
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
474
|
+
return api.getCancellable(self.eventId);
|
|
475
|
+
},
|
|
476
|
+
async getAvailability(params) {
|
|
477
|
+
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
478
|
+
return api.getAvailability({
|
|
479
|
+
calendarId: self.calendarId,
|
|
480
|
+
participantId: params.participantId ?? self.participantId ?? void 0,
|
|
481
|
+
year: params.year,
|
|
482
|
+
month: params.month,
|
|
483
|
+
day: params.day,
|
|
484
|
+
offset: params.offset
|
|
485
|
+
});
|
|
486
|
+
},
|
|
487
|
+
async setReminder() {
|
|
488
|
+
const api = (0, import_mobx_state_tree2.getEnv)(self).api;
|
|
489
|
+
return api.setEventReminder(self.eventId);
|
|
490
|
+
}
|
|
491
|
+
}));
|
|
492
|
+
var Event_default = EventModel;
|
|
493
|
+
|
|
494
|
+
// src/models/appointment/Availability.ts
|
|
495
|
+
var import_mobx_state_tree3 = require("mobx-state-tree");
|
|
496
|
+
var AvailabilityModel = import_mobx_state_tree3.types.model("Availability", {
|
|
497
|
+
id: import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.number),
|
|
498
|
+
availabilityId: import_mobx_state_tree3.types.string,
|
|
499
|
+
calendarId: import_mobx_state_tree3.types.string,
|
|
500
|
+
participantId: import_mobx_state_tree3.types.string,
|
|
501
|
+
createdOn: import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string),
|
|
502
|
+
modifiedOn: import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string)
|
|
503
|
+
});
|
|
504
|
+
var Availability_default = AvailabilityModel;
|
|
505
|
+
|
|
506
|
+
// src/models/appointment/AvailabilityDetail.ts
|
|
507
|
+
var import_mobx_state_tree4 = require("mobx-state-tree");
|
|
508
|
+
var AvailabilityDetailModel = import_mobx_state_tree4.types.model("AvailabilityDetail", {
|
|
509
|
+
id: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.number),
|
|
510
|
+
availabilityId: import_mobx_state_tree4.types.string,
|
|
511
|
+
sunday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
512
|
+
monday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
513
|
+
tuesday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
514
|
+
wednesday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
515
|
+
thursday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
516
|
+
friday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
517
|
+
saturday: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
|
|
518
|
+
startHour: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
519
|
+
startMinute: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
520
|
+
endHour: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
521
|
+
endMinute: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
|
|
522
|
+
createdOn: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string),
|
|
523
|
+
modifiedOn: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string)
|
|
524
|
+
});
|
|
525
|
+
var AvailabilityDetail_default = AvailabilityDetailModel;
|
|
526
|
+
|
|
527
|
+
// src/models/appointment/CalendarParticipant.ts
|
|
528
|
+
var import_mobx_state_tree5 = require("mobx-state-tree");
|
|
529
|
+
var CalendarParticipantModel = import_mobx_state_tree5.types.model("CalendarParticipant", {
|
|
530
|
+
id: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.number),
|
|
531
|
+
calendarParticipantId: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.string, ""),
|
|
532
|
+
participantId: import_mobx_state_tree5.types.string,
|
|
533
|
+
calendarId: import_mobx_state_tree5.types.string,
|
|
534
|
+
createdOn: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string),
|
|
535
|
+
modifiedOn: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string)
|
|
536
|
+
});
|
|
537
|
+
var CalendarParticipant_default = CalendarParticipantModel;
|
|
538
|
+
|
|
539
|
+
// src/models/appointment/Participant.ts
|
|
540
|
+
var import_mobx_state_tree6 = require("mobx-state-tree");
|
|
541
|
+
var ParticipantModel = import_mobx_state_tree6.types.model("Participant", {
|
|
542
|
+
id: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.number),
|
|
543
|
+
participantId: import_mobx_state_tree6.types.identifier,
|
|
544
|
+
companyKey: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.string),
|
|
545
|
+
alias: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.string, ""),
|
|
546
|
+
email: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.string, ""),
|
|
547
|
+
isApproved: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.boolean, false),
|
|
548
|
+
isAvailable: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.boolean, false),
|
|
549
|
+
provider: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.number, 0),
|
|
550
|
+
createdOn: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.string),
|
|
551
|
+
modifiedOn: import_mobx_state_tree6.types.maybeNull(import_mobx_state_tree6.types.string),
|
|
552
|
+
isDeleted: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.boolean, false)
|
|
553
|
+
});
|
|
554
|
+
var Participant_default = ParticipantModel;
|
|
555
|
+
|
|
556
|
+
// src/models/appointment/OpeningHour.ts
|
|
557
|
+
var import_mobx_state_tree7 = require("mobx-state-tree");
|
|
558
|
+
var OpeningHourModel = import_mobx_state_tree7.types.model("OpeningHour", {
|
|
559
|
+
id: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.number),
|
|
560
|
+
openingHourId: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.string, ""),
|
|
561
|
+
calendarId: import_mobx_state_tree7.types.string,
|
|
562
|
+
participantId: import_mobx_state_tree7.types.string,
|
|
563
|
+
day: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
564
|
+
startHour: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
565
|
+
startMinute: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
566
|
+
endHour: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
567
|
+
endMinute: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
|
|
568
|
+
off: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.boolean, false),
|
|
569
|
+
createdOn: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
|
|
570
|
+
modifiedOn: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string)
|
|
571
|
+
});
|
|
572
|
+
var OpeningHour_default = OpeningHourModel;
|
|
573
|
+
|
|
574
|
+
// src/models/appointment/TimeSlot.ts
|
|
575
|
+
var import_mobx_state_tree8 = require("mobx-state-tree");
|
|
576
|
+
var TimeSlotModel = import_mobx_state_tree8.types.model("TimeSlot", {
|
|
577
|
+
startHour: import_mobx_state_tree8.types.optional(import_mobx_state_tree8.types.number, 0),
|
|
578
|
+
startMinute: import_mobx_state_tree8.types.optional(import_mobx_state_tree8.types.number, 0),
|
|
579
|
+
endHour: import_mobx_state_tree8.types.optional(import_mobx_state_tree8.types.number, 0),
|
|
580
|
+
endMinute: import_mobx_state_tree8.types.optional(import_mobx_state_tree8.types.number, 0),
|
|
581
|
+
startDate: import_mobx_state_tree8.types.string,
|
|
582
|
+
endDate: import_mobx_state_tree8.types.string,
|
|
583
|
+
participantId: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.string)
|
|
584
|
+
}).actions((self) => ({
|
|
585
|
+
setWithOffset(offsetMinutes) {
|
|
586
|
+
const start = new Date(self.startDate);
|
|
587
|
+
const end = new Date(self.endDate);
|
|
588
|
+
start.setMinutes(start.getMinutes() + offsetMinutes);
|
|
589
|
+
end.setMinutes(end.getMinutes() + offsetMinutes);
|
|
590
|
+
self.startDate = start.toISOString();
|
|
591
|
+
self.endDate = end.toISOString();
|
|
592
|
+
self.startHour = start.getHours();
|
|
593
|
+
self.startMinute = start.getMinutes();
|
|
594
|
+
self.endHour = end.getHours();
|
|
595
|
+
self.endMinute = end.getMinutes();
|
|
596
|
+
}
|
|
597
|
+
}));
|
|
598
|
+
var TimeSlot_default = TimeSlotModel;
|
|
599
|
+
|
|
600
|
+
// src/models/appointment/TimeFrame.ts
|
|
601
|
+
var import_mobx_state_tree9 = require("mobx-state-tree");
|
|
602
|
+
var TimeFrameModel = import_mobx_state_tree9.types.model("TimeFrame", {
|
|
603
|
+
start: import_mobx_state_tree9.types.string,
|
|
604
|
+
end: import_mobx_state_tree9.types.string
|
|
605
|
+
}).actions((self) => ({
|
|
606
|
+
buffer(bufferMinutes, unit) {
|
|
607
|
+
const bfr = unit === Unit.Hours ? bufferMinutes * 60 : bufferMinutes;
|
|
608
|
+
const s = new Date(self.start);
|
|
609
|
+
const e = new Date(self.end);
|
|
610
|
+
s.setMinutes(s.getMinutes() - bfr);
|
|
611
|
+
e.setMinutes(e.getMinutes() + bfr);
|
|
612
|
+
self.start = s.toISOString();
|
|
613
|
+
self.end = e.toISOString();
|
|
614
|
+
},
|
|
615
|
+
conflicts(start, end) {
|
|
616
|
+
const thisStart = new Date(self.start).getTime();
|
|
617
|
+
const thisEnd = new Date(self.end).getTime();
|
|
618
|
+
const startT = start.getTime();
|
|
619
|
+
const endT = end.getTime();
|
|
620
|
+
return startT >= thisStart && startT <= thisEnd || endT >= thisStart && endT <= thisEnd || startT <= thisStart && endT >= thisEnd;
|
|
621
|
+
},
|
|
622
|
+
breakIntoSlots(slotDurationMinutes) {
|
|
623
|
+
const start = new Date(self.start);
|
|
624
|
+
const end = new Date(self.end);
|
|
625
|
+
const slots = [];
|
|
626
|
+
let current = new Date(start);
|
|
627
|
+
const align = (m) => {
|
|
628
|
+
if (m === 0 || m === 15 || m === 30 || m === 45) return m;
|
|
629
|
+
if (m > 0 && m < 15) return 15;
|
|
630
|
+
if (m > 15 && m < 30) return 30;
|
|
631
|
+
if (m > 30 && m < 45) return 45;
|
|
632
|
+
return 0;
|
|
633
|
+
};
|
|
634
|
+
current.setMinutes(align(current.getMinutes()), 0, 0);
|
|
635
|
+
let slotEnd = new Date(current.getTime());
|
|
636
|
+
slotEnd.setMinutes(slotEnd.getMinutes() + slotDurationMinutes);
|
|
637
|
+
while (slotEnd.getTime() <= end.getTime()) {
|
|
638
|
+
slots.push({
|
|
639
|
+
startHour: current.getHours(),
|
|
640
|
+
startMinute: current.getMinutes(),
|
|
641
|
+
endHour: slotEnd.getHours(),
|
|
642
|
+
endMinute: slotEnd.getMinutes(),
|
|
643
|
+
startDate: current.toISOString(),
|
|
644
|
+
endDate: slotEnd.toISOString()
|
|
645
|
+
});
|
|
646
|
+
current = new Date(slotEnd.getTime());
|
|
647
|
+
slotEnd.setMinutes(slotEnd.getMinutes() + slotDurationMinutes);
|
|
648
|
+
}
|
|
649
|
+
return slots;
|
|
650
|
+
}
|
|
651
|
+
}));
|
|
652
|
+
var TimeFrame_default = TimeFrameModel;
|
|
653
|
+
|
|
654
|
+
// src/models/appointment/Setting.ts
|
|
655
|
+
var import_mobx_state_tree10 = require("mobx-state-tree");
|
|
656
|
+
var SettingModel = import_mobx_state_tree10.types.model("Setting", {
|
|
657
|
+
id: import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.number),
|
|
658
|
+
settingsId: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.string, ""),
|
|
659
|
+
calendarId: import_mobx_state_tree10.types.string,
|
|
660
|
+
logo: import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string),
|
|
661
|
+
theme: import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string),
|
|
662
|
+
schedulingButtonText: import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string),
|
|
663
|
+
scheduledMessage: import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string)
|
|
664
|
+
});
|
|
665
|
+
var Setting_default = SettingModel;
|
|
666
|
+
|
|
667
|
+
// src/models/appointment/index.ts
|
|
668
|
+
var import_mobx_state_tree11 = require("mobx-state-tree");
|
|
669
|
+
var RootStore = import_mobx_state_tree11.types.model("RootStore", {
|
|
670
|
+
calendars: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.map(Calendar_default), {}),
|
|
671
|
+
events: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.map(Event_default), {})
|
|
672
|
+
}).actions((self) => ({
|
|
673
|
+
getApi() {
|
|
674
|
+
return (0, import_mobx_state_tree11.getEnv)(self).api;
|
|
675
|
+
},
|
|
676
|
+
addCalendar(snapshot) {
|
|
677
|
+
const cal = Calendar_default.create(snapshot);
|
|
678
|
+
self.calendars.set(cal.calendarId, cal);
|
|
679
|
+
return cal;
|
|
680
|
+
},
|
|
681
|
+
addEvent(snapshot) {
|
|
682
|
+
const ev = Event_default.create(snapshot);
|
|
683
|
+
self.events.set(ev.eventId, ev);
|
|
684
|
+
return ev;
|
|
685
|
+
}
|
|
686
|
+
}));
|
|
687
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
688
|
+
0 && (module.exports = {
|
|
689
|
+
AppointmentClient,
|
|
690
|
+
AssignmentMethod,
|
|
691
|
+
AttendeeStatus,
|
|
692
|
+
AvailabilityDetailModel,
|
|
693
|
+
AvailabilityModel,
|
|
694
|
+
CalendarModel,
|
|
695
|
+
CalendarParticipantModel,
|
|
696
|
+
DayOfWeek,
|
|
697
|
+
EventModel,
|
|
698
|
+
OpeningHourModel,
|
|
699
|
+
ParticipantModel,
|
|
700
|
+
RecurringFrequency,
|
|
701
|
+
RootStore,
|
|
702
|
+
SettingModel,
|
|
703
|
+
TimeFrameModel,
|
|
704
|
+
TimeSlotModel,
|
|
705
|
+
Unit,
|
|
706
|
+
mapCreateEventInputToEvent
|
|
707
|
+
});
|