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