@blazeo.com/calendar-client 1.0.2 → 1.0.4

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 CHANGED
@@ -1,677 +1,129 @@
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;
1
+ // src/models/appointment/Calendar.js
2
+ import { types as types7, getEnv as getEnv2, applySnapshot as applySnapshot2 } from "mobx-state-tree";
3
+
4
+ // src/ConfigModel.js
5
+ import { types } from "mobx-state-tree";
6
+ var ConfigModel = types.model("Config", {
7
+ baseUrl: types.optional(types.string, "")
8
+ }).volatile(() => ({
9
+ fetch: void 0,
10
+ getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
11
+ })).actions((self) => ({
12
+ setBaseUrl(url) {
13
+ self.baseUrl = url;
14
+ },
15
+ setFetch(fn) {
16
+ self.fetch = fn;
17
+ },
18
+ setGetDefaultOffset(fn) {
19
+ self.getDefaultOffset = fn;
20
+ },
21
+ configure(env) {
22
+ if (env.baseUrl != null) self.baseUrl = env.baseUrl;
23
+ if (env.fetch != null) self.fetch = env.fetch;
24
+ if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
25
+ }
26
+ })).views((self) => ({
27
+ getEnv() {
28
+ return {
29
+ baseUrl: self.baseUrl || void 0,
30
+ fetch: self.fetch,
31
+ getDefaultOffset: self.getDefaultOffset
32
+ };
6
33
  }
7
- return void 0;
34
+ }));
35
+ var _instance = null;
36
+ function getConfigStore() {
37
+ if (!_instance) _instance = ConfigModel.create({});
38
+ return _instance;
8
39
  }
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;
40
+ var ConfigModel_default = ConfigModel;
41
+
42
+ // src/config.js
43
+ function configure(env) {
44
+ const store = getConfigStore();
45
+ store.configure(env);
18
46
  }
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);
47
+ function getConfig() {
48
+ const store = getConfigStore();
49
+ if (!store.baseUrl) return null;
50
+ return store.getEnv();
24
51
  }
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
- };
52
+ function setBaseUrl(baseUrl) {
53
+ getConfigStore().setBaseUrl(baseUrl);
65
54
  }
66
55
 
67
- // src/client.ts
68
- function normalizeBaseUrl(baseUrl) {
69
- return baseUrl.replace(/\/+$/, "");
70
- }
56
+ // src/apiRequest.js
71
57
  function buildQuery(params) {
72
58
  const search = new URLSearchParams();
73
- for (const [k, v] of Object.entries(params)) {
59
+ for (const [k, v] of Object.entries(params || {})) {
74
60
  if (v === void 0 || v === null) continue;
75
- search.set(k, String(v));
61
+ if (Array.isArray(v)) {
62
+ for (const item of v) search.append(k, String(item));
63
+ } else {
64
+ search.set(k, String(v));
65
+ }
76
66
  }
77
67
  const q = search.toString();
78
68
  return q ? `?${q}` : "";
79
69
  }
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, skipContentType } = options;
90
- const url = `${this.baseUrl}${path}${buildQuery(query ?? {})}`;
91
- const reqHeaders = { ...headers };
92
- if (!skipContentType && typeof body === "string") {
93
- reqHeaders["Content-Type"] = "application/json";
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
- /** POST /event/reschedule – reschedule event */
237
- async rescheduleEvent(payload, offsetMinutes) {
238
- const offset = offsetMinutes ?? this.getDefaultOffset();
239
- return this.request("/event/reschedule", {
240
- method: "POST",
241
- headers: { offset: String(offset) },
242
- body: JSON.stringify(payload)
243
- });
244
- }
245
- /** POST /event/update – update event */
246
- async updateEvent(payload) {
247
- return this.request("/event/update", {
248
- method: "POST",
249
- body: JSON.stringify(payload)
250
- });
251
- }
252
- /** POST /event/testcreate – test create (no notifications) */
253
- async testCreateEvent(payload, offsetMinutes) {
254
- const offset = offsetMinutes ?? this.getDefaultOffset();
255
- return this.request("/event/testcreate", {
256
- method: "POST",
257
- headers: { offset: String(offset) },
258
- body: JSON.stringify(payload)
259
- });
260
- }
261
- /** POST /event/customdata/get – get custom field schema for calendar */
262
- async getEventCustomData(calendarId, eventId) {
263
- const query = { calendar_id: calendarId };
264
- if (eventId) query.event_id = eventId;
265
- return this.request("/event/customdata/get", {
266
- method: "POST",
267
- body: JSON.stringify({}),
268
- query
269
- });
270
- }
271
- // ---------- Calendar ----------
272
- /** GET Calendar/Get – get calendar by calendar_id */
273
- async getCalendar(calendarId) {
274
- return this.request("/Calendar/Get", { query: { calendar_id: calendarId } });
275
- }
276
- /** GET Calendar/All – calendars by company_key */
277
- async getCalendarsByCompany(companyKey) {
278
- return this.request("/Calendar/All", { query: { company_key: companyKey } });
279
- }
280
- /** GET Calendar/TimeZones/Get */
281
- async getTimeZones() {
282
- return this.request("/Calendar/TimeZones/Get");
283
- }
284
- /** GET Calendar/TimeZone/Get – display name for timezone_id */
285
- async getTimeZone(timezoneId) {
286
- return this.request("/Calendar/TimeZone/Get", { query: { timezone_id: timezoneId } });
287
- }
288
- /** POST Calendar/Create – create or update calendar */
289
- async createCalendar(payload) {
290
- return this.request("/Calendar/Create", { method: "POST", body: JSON.stringify(payload) });
291
- }
292
- /** GET Calendar/Remove */
293
- async removeCalendar(calendarId) {
294
- return this.request(`/Calendar/Remove`, { query: { calendar_id: calendarId } });
295
- }
296
- /** POST Calendar/Event/Update – update calendar */
297
- async updateCalendar(payload) {
298
- return this.request("/Calendar/Event/Update", {
299
- method: "POST",
300
- body: JSON.stringify(payload)
301
- });
302
- }
303
- /** GET Calendar/Participant/Add */
304
- async addParticipantToCalendar(calendarId, participantId) {
305
- return this.request("/Calendar/Participant/Add", {
306
- query: { calendar_id: calendarId, participant_id: participantId }
307
- });
308
- }
309
- /** GET Calendar/Participant/Remove */
310
- async removeParticipantFromCalendar(calendarId, participantId) {
311
- return this.request("/Calendar/Participant/Remove", {
312
- query: { calendar_id: calendarId, participant_id: participantId }
313
- });
314
- }
315
- /** GET Calendar/Participant/OpeningHours/Get */
316
- async getParticipantOpeningHours(params) {
317
- const query = {};
318
- if (params.calendarParticipantId) query.calendarparticipant_id = params.calendarParticipantId;
319
- if (params.participantId) query.participant_id = params.participantId;
320
- if (params.calendarId) query.calendar_id = params.calendarId;
321
- return this.request("/Calendar/Participant/OpeningHours/Get", { query });
322
- }
323
- /** POST Calendar/Participant/Availability/OpeningHour/Save */
324
- async saveOpeningHour(payload) {
325
- return this.request("/Calendar/Participant/Availability/OpeningHour/Save", {
326
- method: "POST",
327
- body: JSON.stringify(payload)
328
- });
329
- }
330
- /** POST Calendar/Participant/Availability/OpeningHours/Save */
331
- async saveOpeningHours(payload) {
332
- return this.request("/Calendar/Participant/Availability/OpeningHours/Save", {
333
- method: "POST",
334
- body: JSON.stringify(payload)
335
- });
336
- }
337
- /** GET Calendar/Participant/OpeningHour/Remove */
338
- async removeParticipantOpeningHours(calendarId, participantId) {
339
- return this.request("/Calendar/Participant/OpeningHour/Remove", {
340
- query: { calendar_id: calendarId, participant_id: participantId }
341
- });
342
- }
343
- /** GET Calendar/Participant/Availability/Add – backend expects body (AvailabilityDetail). Note: GET with body is non-standard; fetch may reject. Consider backend POST if needed. */
344
- async addParticipantAvailability(calendarId, participantId, detail) {
345
- return this.request("/Calendar/Participant/Availability/Add", {
346
- method: "GET",
347
- query: { calendar_id: calendarId, participant_id: participantId },
348
- body: JSON.stringify(detail)
349
- });
350
- }
351
- /** GET Calendar/Participant/All */
352
- async getCalendarParticipants(calendarId) {
353
- return this.request("/Calendar/Participant/All", {
354
- query: { calendar_id: calendarId }
355
- });
356
- }
357
- /** GET Calendar/CreateWithParticipants */
358
- async createCalendarWithParticipants(params) {
359
- const query = {
360
- name: params.name,
361
- company_key: params.companyKey,
362
- participantids: params.participantIds.join(",")
363
- };
364
- if (params.description) query.description = params.description;
365
- if (params.calendarId) query.calendar_id = params.calendarId;
366
- return this.request("/Calendar/CreateWithParticipants", { query });
367
- }
368
- /** GET Calendar/EditWithParticipants */
369
- async editCalendarWithParticipants(params) {
370
- const query = {
371
- calendar_id: params.calendarId,
372
- name: params.name,
373
- participantids: params.participantIds.join(",")
374
- };
375
- if (params.description) query.description = params.description;
376
- return this.request("/Calendar/EditWithParticipants", { query });
377
- }
378
- /** GET Calendar/Month/Get */
379
- async getCalendarMonth(calendarId, year, month) {
380
- return this.request("/Calendar/Month/Get", {
381
- query: { calendar_id: calendarId, year, month }
382
- });
383
- }
384
- /** GET Calendar/Events/Get */
385
- async getCalendarEvents(calendarId) {
386
- return this.request("/Calendar/Events/Get", {
387
- query: { calendar_id: calendarId }
388
- });
389
- }
390
- // ---------- Participant ----------
391
- /** GET participant/get */
392
- async getParticipant(participantId) {
393
- return this.request("/participant/get", { query: { participant_id: participantId } });
394
- }
395
- /** GET participant/participants/get */
396
- async getParticipantsByIds(participantIds) {
397
- return this.request("/participant/participants/get", {
398
- query: { participantids: participantIds.join(",") }
399
- });
400
- }
401
- /** GET Participant/All */
402
- async getAllParticipants(companyKey) {
403
- return this.request("/Participant/All", { query: { company_key: companyKey } });
404
- }
405
- /** GET participant/sendemail */
406
- async sendParticipantEmail(participantId) {
407
- return this.request("/participant/sendemail", { query: { participant_id: participantId } });
408
- }
409
- /** POST Participant/Add */
410
- async addParticipant(payload, calendarId) {
411
- const query = calendarId ? { calendar_id: calendarId } : void 0;
412
- return this.request("/Participant/Add", {
413
- method: "POST",
414
- body: JSON.stringify(payload),
415
- query
416
- });
417
- }
418
- /** GET participant/remove */
419
- async removeParticipant(participantId) {
420
- return this.request("/participant/remove", { query: { participant_id: participantId } });
421
- }
422
- /** POST participant/update */
423
- async updateParticipant(payload) {
424
- return this.request("/participant/update", {
425
- method: "POST",
426
- body: JSON.stringify(payload)
427
- });
428
- }
429
- /** POST participant/save */
430
- async saveParticipant(payload) {
431
- return this.request("/participant/save", {
432
- method: "POST",
433
- body: JSON.stringify(payload)
434
- });
435
- }
436
- // ---------- CalendarParticipant ----------
437
- /** GET Calendar/Participant/Get */
438
- async getCalendarParticipant(calendarId) {
439
- return this.request("/Calendar/Participant/Get", {
440
- query: { calendar_id: calendarId }
441
- });
442
- }
443
- /** GET Calendar/Participants/GetInfo */
444
- async getCalendarParticipantsInfo(calendarId) {
445
- return this.request("/Calendar/Participants/GetInfo", {
446
- query: { calendar_id: calendarId }
447
- });
448
- }
449
- /** GET Participant/calendar/get */
450
- async getParticipantCalendars(participantId) {
451
- return this.request("/Participant/calendar/get", {
452
- query: { participant_id: participantId }
453
- });
454
- }
455
- // ---------- CustomField ----------
456
- /** GET CustomField/GetAll */
457
- async getCustomFields(calendarId) {
458
- return this.request("/CustomField/GetAll", { query: { calendar_id: calendarId } });
459
- }
460
- /** GET CustomField/FieldType/Get */
461
- async getCustomFieldType(fieldType) {
462
- return this.request("/CustomField/FieldType/Get", { query: { FieldType: fieldType } });
463
- }
464
- /** POST CustomField/Add */
465
- async addCustomField(payload) {
466
- return this.request("/CustomField/Add", {
467
- method: "POST",
468
- body: JSON.stringify(payload)
469
- });
470
- }
471
- /** GET CustomField/FieldTypes/Get */
472
- async getCustomFieldTypes() {
473
- return this.request("/CustomField/FieldTypes/Get");
474
- }
475
- /** GET CustomField/RemoveField */
476
- async removeCustomField(customFieldId) {
477
- return this.request("/CustomField/RemoveField", { query: { customfield_id: customFieldId } });
478
- }
479
- /** GET CustomField/RemoveAllFields */
480
- async removeAllCustomFields(calendarId) {
481
- return this.request("/CustomField/RemoveAllFields", { query: { calendar_id: calendarId } });
482
- }
483
- /** GET CustomField/Form/Get */
484
- async getCustomForm(calendarId, dataId) {
485
- const query = { calendar_id: calendarId };
486
- if (dataId) query.data_id = dataId;
487
- return this.request("/CustomField/Form/Get", { query });
488
- }
489
- /** GET CustomField/Form/Data/Get */
490
- async getCustomFormData(calendarId, dataId) {
491
- const query = { calendar_id: calendarId };
492
- if (dataId) query.data_id = dataId;
493
- return this.request("/CustomField/Form/Data/Get", { query });
494
- }
495
- /** POST CustomField/Form/Save */
496
- async saveCustomForm(calendarId, fields) {
497
- return this.request("/CustomField/Form/Save", {
498
- method: "POST",
499
- body: JSON.stringify(fields),
500
- query: { calendar_id: calendarId }
501
- });
502
- }
503
- /** POST CustomField/Form/Data/Save */
504
- async saveCustomFormData(dataId, fields) {
505
- return this.request("/CustomField/Form/Data/Save", {
506
- method: "POST",
507
- body: JSON.stringify(fields),
508
- query: { data_id: dataId }
509
- });
510
- }
511
- /** POST CustomField/Form/Field/Data/Save */
512
- async saveCustomFormFieldData(field) {
513
- return this.request("/CustomField/Form/Field/Data/Save", {
514
- method: "POST",
515
- body: JSON.stringify(field)
516
- });
517
- }
518
- // ---------- Setting ----------
519
- /** GET setting/get */
520
- async getSetting(calendarId) {
521
- return this.request("/setting/get", { query: { calendar_id: calendarId } });
522
- }
523
- /** POST setting/save */
524
- async saveSetting(payload) {
525
- return this.request("/setting/save", {
526
- method: "POST",
527
- body: JSON.stringify(payload)
528
- });
529
- }
530
- /** POST setting/logo/upload */
531
- async uploadSettingLogo(calendarId, file) {
532
- const form = new FormData();
533
- form.append("file", file);
534
- return this.request("/setting/logo/upload", {
535
- method: "POST",
536
- body: form,
537
- query: { calendar_id: calendarId },
538
- skipContentType: true
539
- });
540
- }
541
- // ---------- Consumer ----------
542
- /** POST Consumer/Register/EventListener */
543
- async registerEventListener(payload) {
544
- return this.request("/Consumer/Register/EventListener", {
545
- method: "POST",
546
- body: JSON.stringify(payload)
547
- });
548
- }
549
- /** PUT Consumer/Update/EventListener */
550
- async updateEventListener(payload) {
551
- return this.request("/Consumer/Update/EventListener", {
552
- method: "PUT",
553
- body: JSON.stringify(payload)
554
- });
555
- }
556
- /** POST Consumer/Register */
557
- async registerConsumer(payload) {
558
- return this.request("/Consumer/Register", {
559
- method: "POST",
560
- body: JSON.stringify(payload)
561
- });
562
- }
563
- /** GET Consumer/Events/List */
564
- async listEventListeners() {
565
- return this.request("/Consumer/Events/List");
566
- }
567
- /** GET Consumer/List */
568
- async listConsumers() {
569
- return this.request("/Consumer/List");
570
- }
571
- // ---------- Preference ----------
572
- /** POST /preference/{scope}/{key}/{option} */
573
- async setPreference(scope, key, option, body) {
574
- return this.request(`/preference/${encodeURIComponent(scope)}/${encodeURIComponent(key)}/${encodeURIComponent(option)}`, {
575
- method: "POST",
576
- body
577
- });
578
- }
579
- /** GET /preference/scopes */
580
- async getPreferenceScopes() {
581
- return this.request("/preference/scopes");
582
- }
583
- /** GET /preference/options */
584
- async getPreferenceOptions() {
585
- return this.request("/preference/options");
586
- }
587
- /** GET /preference/options/{option} */
588
- async getPreferenceOption(option) {
589
- return this.request(`/preference/options/${encodeURIComponent(option)}`);
590
- }
591
- /** GET /preference/{option} */
592
- async getPreference(option, keys) {
593
- return this.request(`/preference/${encodeURIComponent(option)}`, {
594
- query: { keys: keys.join(",") }
595
- });
596
- }
597
- // ---------- Notification ----------
598
- /** POST /notification/sms/outbound */
599
- async sendSmsOutbound(payload) {
600
- return this.request("/notification/sms/outbound", {
601
- method: "POST",
602
- body: JSON.stringify(payload)
603
- });
604
- }
605
- /** GET /notification/sms/queue */
606
- async getSmsQueue(id) {
607
- return this.request("/notification/sms/queue", { query: { id } });
608
- }
609
- /** POST /notification/sms/inbound */
610
- async smsInbound(formData) {
611
- return this.request("/notification/sms/inbound", {
612
- method: "POST",
613
- body: formData,
614
- skipContentType: true
615
- });
616
- }
617
- /** POST /notification/sms/status */
618
- async smsStatus(payload) {
619
- return this.request("/notification/sms/status", {
620
- method: "POST",
621
- body: JSON.stringify(payload)
622
- });
623
- }
624
- /** GET /notification/sms/outbox/send */
625
- async sendSmsOutbox() {
626
- return this.request("/notification/sms/outbox/send");
627
- }
628
- // ---------- Auth ----------
629
- /** GET /CallBack – OAuth callback (typically used as redirect URL) */
630
- getCallbackUrl() {
631
- return `${this.baseUrl}/CallBack`;
632
- }
633
- /** POST Auth/AddParticipantCredentials */
634
- async addParticipantCredentials(payload) {
635
- return this.request("/Auth/AddParticipantCredentials", {
636
- method: "POST",
637
- body: JSON.stringify(payload)
638
- });
639
- }
640
- /** GET Auth/ParticipantCredentials */
641
- async getParticipantCredentials(participantId) {
642
- return this.request("/Auth/ParticipantCredentials", { query: { participant_id: participantId } });
643
- }
644
- // ---------- Ping ----------
645
- /** GET /ping */
646
- async ping() {
647
- return this.request("/ping");
648
- }
649
- /** GET /setup */
650
- async setup(name) {
651
- return this.request("/setup", { query: name ? { name } : void 0 });
652
- }
653
- /** GET /reset */
654
- async reset() {
655
- return this.request("/reset");
656
- }
657
- /** POST /ping */
658
- async pingPost() {
659
- return this.request("/ping", { method: "POST" });
660
- }
661
- // ---------- Schedule ----------
662
- /** POST /schedule/calendar/ */
663
- async scheduleCalendar(calendar) {
664
- return this.request("/schedule/calendar/", {
665
- method: "POST",
666
- query: calendar ? { calendar } : void 0
667
- });
668
- }
669
- };
670
-
671
- // src/models/appointment/Calendar.ts
672
- import { types, getEnv, applySnapshot } from "mobx-state-tree";
70
+ async function request(baseUrl, fetchFn, path, options = {}) {
71
+ const { method = "GET", headers = {}, body, query, skipContentType } = options;
72
+ const url = `${String(baseUrl).replace(/\/+$/, "")}${path}${buildQuery(query)}`;
73
+ const reqHeaders = { ...headers };
74
+ if (!skipContentType && typeof body === "string") reqHeaders["Content-Type"] = "application/json";
75
+ const res = await fetchFn(url, { method, headers: reqHeaders, body });
76
+ const text = await res.text();
77
+ let data;
78
+ try {
79
+ data = JSON.parse(text);
80
+ } catch {
81
+ data = { status: "failure", message: text || res.statusText };
82
+ }
83
+ if (!res.ok && data.status !== "failure") {
84
+ data.status = "failure";
85
+ data.message = data.message ?? `HTTP ${res.status}`;
86
+ }
87
+ return data;
88
+ }
89
+ function createRequestHelpers(self, getEnv9) {
90
+ const env = () => getEnv9(self);
91
+ const baseUrl = () => env().baseUrl;
92
+ const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
93
+ throw new Error("fetch not available");
94
+ });
95
+ const req = (path, opts = {}) => {
96
+ const url = baseUrl();
97
+ if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
98
+ return request(url, fetchFn(), path, opts);
99
+ };
100
+ return {
101
+ req,
102
+ reqGet: (path, query, opts = {}) => req(path, { ...opts, query }),
103
+ reqPost: (path, body, query, opts = {}) => req(path, { ...opts, method: "POST", body: JSON.stringify(body), query })
104
+ };
105
+ }
106
+ function createRequestHelpersFromEnv(env) {
107
+ const e = env ?? getConfig();
108
+ if (!e) throw new Error("Env required. Pass env to the method or call configure({ baseUrl }) at app startup.");
109
+ const baseUrl = () => e == null ? void 0 : e.baseUrl;
110
+ const fetchFn = () => (e == null ? void 0 : e.fetch) ?? (typeof fetch !== "undefined" ? fetch : () => {
111
+ throw new Error("fetch not available");
112
+ });
113
+ const req = (path, opts = {}) => {
114
+ const url = baseUrl();
115
+ if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
116
+ return request(url, fetchFn(), path, opts);
117
+ };
118
+ return {
119
+ env: e,
120
+ req,
121
+ reqGet: (path, query, opts = {}) => req(path, { ...opts, query }),
122
+ reqPost: (path, body, query, opts = {}) => req(path, { ...opts, method: "POST", body: JSON.stringify(body), query })
123
+ };
124
+ }
673
125
 
674
- // src/models/appointment/enums.ts
126
+ // src/models/appointment/enums.js
675
127
  var Unit = {
676
128
  Minutes: 1,
677
129
  Hours: 2,
@@ -709,264 +161,991 @@ var DayOfWeek = {
709
161
  Saturday: 6
710
162
  };
711
163
 
712
- // src/models/appointment/Calendar.ts
713
- var CalendarModel = types.model("Calendar", {
714
- id: types.maybeNull(types.number),
715
- companyKey: types.maybeNull(types.string),
716
- calendarId: types.identifier,
717
- name: types.maybeNull(types.string),
718
- location: types.maybeNull(types.string),
719
- timeZoneId: types.maybeNull(types.string),
720
- purpose: types.optional(types.string, ""),
721
- description: types.maybeNull(types.string),
722
- assignmentMethod: types.optional(types.number, AssignmentMethod.RoundRobin),
723
- duration: types.optional(types.number, 0),
724
- durationUnit: types.optional(types.number, Unit.Minutes),
725
- minimumBookingNotice: types.optional(types.number, 0),
726
- minimumBookingNoticeUnit: types.optional(types.number, Unit.Minutes),
727
- minimumCancelationNotice: types.optional(types.number, 0),
728
- minimumCancelationNoticeUnit: types.optional(types.number, Unit.Minutes),
729
- futureLimit: types.optional(types.number, 0),
730
- futureLimitUnit: types.optional(types.number, Unit.Days),
731
- bufferTime: types.optional(types.number, 0),
732
- bufferTimeUnit: types.optional(types.number, Unit.Minutes),
733
- bookingLimit: types.optional(types.number, 0),
734
- createdOn: types.maybeNull(types.string),
735
- modifiedOn: types.maybeNull(types.string)
736
- }).actions((self) => ({
737
- async create() {
738
- const api = getEnv(self).api;
739
- const payload = {
740
- calendarId: self.calendarId,
741
- companyKey: self.companyKey ?? void 0,
742
- name: self.name ?? void 0,
743
- location: self.location ?? void 0,
744
- timeZoneId: self.timeZoneId ?? void 0,
745
- purpose: self.purpose,
746
- description: self.description ?? void 0,
747
- assignmentMethod: self.assignmentMethod,
748
- duration: self.duration,
749
- durationUnit: self.durationUnit,
750
- minimumBookingNotice: self.minimumBookingNotice,
751
- minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
752
- minimumCancelationNotice: self.minimumCancelationNotice,
753
- minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
754
- futureLimit: self.futureLimit,
755
- futureLimitUnit: self.futureLimitUnit,
756
- bufferTime: self.bufferTime,
757
- bufferTimeUnit: self.bufferTimeUnit,
758
- bookingLimit: self.bookingLimit
759
- };
760
- const res = await api.createCalendar(payload);
761
- if (res.status === "success" && res.data) applySnapshot(self, { ...res.data, calendarId: self.calendarId });
762
- return res;
763
- },
764
- async get() {
765
- const api = getEnv(self).api;
766
- const res = await api.getCalendar(self.calendarId);
767
- if (res.status === "success" && res.data) applySnapshot(self, { ...res.data, calendarId: self.calendarId });
768
- return res;
769
- },
770
- async remove() {
771
- const api = getEnv(self).api;
772
- return api.removeCalendar(self.calendarId);
773
- }
774
- }));
775
- var Calendar_default = CalendarModel;
164
+ // src/models/appointment/Event.js
165
+ import { types as types3, getEnv, applySnapshot } from "mobx-state-tree";
776
166
 
777
- // src/models/appointment/Event.ts
778
- import { types as types2, getEnv as getEnv2, applySnapshot as applySnapshot2 } from "mobx-state-tree";
779
- var EventModel = types2.model("Event", {
780
- id: types2.maybeNull(types2.number),
781
- eventId: types2.identifier,
782
- calendarId: types2.string,
783
- participantId: types2.maybeNull(types2.string),
784
- title: types2.maybeNull(types2.string),
785
- description: types2.maybeNull(types2.string),
786
- isRecurring: types2.optional(types2.boolean, false),
787
- recurringFrequency: types2.optional(types2.number, RecurringFrequency.None),
788
- startDate: types2.string,
789
- endDate: types2.string,
167
+ // src/models/appointment/TimeSlot.js
168
+ import { types as types2 } from "mobx-state-tree";
169
+ var TimeSlotModel = types2.model("TimeSlot", {
790
170
  startHour: types2.optional(types2.number, 0),
791
171
  startMinute: types2.optional(types2.number, 0),
792
172
  endHour: types2.optional(types2.number, 0),
793
173
  endMinute: types2.optional(types2.number, 0),
794
- visitorName: types2.maybeNull(types2.string),
795
- visitorEmail: types2.maybeNull(types2.string),
796
- visitorPhone: types2.maybeNull(types2.string),
797
- createdOn: types2.maybeNull(types2.string),
798
- modifiedOn: types2.maybeNull(types2.string),
799
- externalEventId: types2.maybeNull(types2.string),
800
- attendeeStatus: types2.optional(types2.number, AttendeeStatus.Tentative),
801
- rescheduleLink: types2.maybeNull(types2.string),
802
- cancelLink: types2.maybeNull(types2.string),
803
- timeZone: types2.maybeNull(types2.string),
804
- offset: types2.optional(types2.number, 0)
174
+ startDate: types2.string,
175
+ endDate: types2.string,
176
+ participantId: types2.maybeNull(types2.string)
805
177
  }).actions((self) => ({
806
- async get(params) {
807
- const api = getEnv2(self).api;
808
- const res = await api.getEvent(params);
809
- if (res.status === "success" && res.data) applySnapshot2(self, { ...res.data, eventId: self.eventId });
810
- return res;
811
- },
812
- async create(offsetMinutes) {
813
- const api = getEnv2(self).api;
814
- const payload = {
815
- calendarId: self.calendarId,
816
- participantId: self.participantId ?? void 0,
817
- title: self.title ?? void 0,
818
- description: self.description ?? void 0,
819
- startDate: self.startDate,
820
- endDate: self.endDate,
821
- startHour: self.startHour,
822
- startMinute: self.startMinute,
823
- endHour: self.endHour,
824
- endMinute: self.endMinute,
825
- visitorName: self.visitorName ?? void 0,
826
- visitorEmail: self.visitorEmail ?? void 0,
827
- visitorPhone: self.visitorPhone ?? void 0
828
- };
829
- const res = await api.createEvent(payload, offsetMinutes);
830
- if (res.status === "success" && res.data) applySnapshot2(self, { ...res.data, eventId: self.eventId });
831
- return res;
832
- },
833
- async cancel() {
834
- const api = getEnv2(self).api;
835
- return api.cancelEvent(self.eventId);
836
- },
837
- async getCancellable() {
838
- const api = getEnv2(self).api;
839
- return api.getCancellable(self.eventId);
840
- },
841
- async getAvailability(params) {
842
- const api = getEnv2(self).api;
843
- return api.getAvailability({
844
- calendarId: self.calendarId,
845
- participantId: params.participantId ?? self.participantId ?? void 0,
846
- year: params.year,
847
- month: params.month,
848
- day: params.day,
849
- offset: params.offset
850
- });
851
- },
852
- async setReminder() {
853
- const api = getEnv2(self).api;
854
- return api.setEventReminder(self.eventId);
178
+ setWithOffset(offsetMinutes) {
179
+ const start = new Date(self.startDate);
180
+ const end = new Date(self.endDate);
181
+ start.setMinutes(start.getMinutes() + offsetMinutes);
182
+ end.setMinutes(end.getMinutes() + offsetMinutes);
183
+ self.startDate = start.toISOString();
184
+ self.endDate = end.toISOString();
185
+ self.startHour = start.getHours();
186
+ self.startMinute = start.getMinutes();
187
+ self.endHour = end.getHours();
188
+ self.endMinute = end.getMinutes();
855
189
  }
856
190
  }));
857
- var Event_default = EventModel;
191
+ var TimeSlot_default = TimeSlotModel;
858
192
 
859
- // src/models/appointment/Availability.ts
860
- import { types as types3 } from "mobx-state-tree";
861
- var AvailabilityModel = types3.model("Availability", {
862
- id: types3.maybeNull(types3.number),
863
- availabilityId: types3.string,
864
- calendarId: types3.string,
865
- participantId: types3.string,
866
- createdOn: types3.maybeNull(types3.string),
867
- modifiedOn: types3.maybeNull(types3.string)
193
+ // src/models/appointment/Event.js
194
+ function getDefaultOffset() {
195
+ var _a;
196
+ const cfg = getConfig();
197
+ return ((_a = cfg == null ? void 0 : cfg.getDefaultOffset) == null ? void 0 : _a.call(cfg)) ?? -(/* @__PURE__ */ new Date()).getTimezoneOffset();
198
+ }
199
+ var EventModel = types3.model("Event", {
200
+ id: types3.optional(types3.maybeNull(types3.number), null),
201
+ eventId: types3.identifier,
202
+ calendarId: types3.optional(types3.string, ""),
203
+ participantId: types3.optional(types3.maybeNull(types3.string), null),
204
+ title: types3.optional(types3.maybeNull(types3.string), null),
205
+ description: types3.optional(types3.maybeNull(types3.string), null),
206
+ isRecurring: types3.optional(types3.boolean, false),
207
+ recurringFrequency: types3.optional(types3.number, RecurringFrequency.None),
208
+ startDate: types3.optional(types3.string, ""),
209
+ endDate: types3.optional(types3.string, ""),
210
+ startHour: types3.optional(types3.number, 0),
211
+ startMinute: types3.optional(types3.number, 0),
212
+ endHour: types3.optional(types3.number, 0),
213
+ endMinute: types3.optional(types3.number, 0),
214
+ visitorName: types3.optional(types3.maybeNull(types3.string), null),
215
+ visitorEmail: types3.optional(types3.maybeNull(types3.string), null),
216
+ visitorPhone: types3.optional(types3.maybeNull(types3.string), null),
217
+ createdOn: types3.optional(types3.maybeNull(types3.string), null),
218
+ modifiedOn: types3.optional(types3.maybeNull(types3.string), null),
219
+ externalEventId: types3.optional(types3.maybeNull(types3.string), null),
220
+ attendeeStatus: types3.optional(types3.number, AttendeeStatus.Tentative),
221
+ rescheduleLink: types3.optional(types3.maybeNull(types3.string), null),
222
+ cancelLink: types3.optional(types3.maybeNull(types3.string), null),
223
+ timeZone: types3.optional(types3.maybeNull(types3.string), null),
224
+ offset: types3.optional(types3.number, 0)
225
+ }).actions((self) => {
226
+ const { req, reqGet, reqPost } = createRequestHelpers(self, getEnv);
227
+ const getOffset = () => {
228
+ var _a, _b;
229
+ return ((_b = (_a = getEnv(self)).getDefaultOffset) == null ? void 0 : _b.call(_a)) ?? getDefaultOffset();
230
+ };
231
+ return {
232
+ /** GET /event/get – fetch this event by eventId or externalEventId */
233
+ async get(params) {
234
+ if ((params == null ? void 0 : params.eventId) ?? (params == null ? void 0 : params.event_id)) {
235
+ const res = await reqGet("/event/get", { event_id: params.eventId ?? params.event_id });
236
+ if (res.status === "success" && res.data) applySnapshot(self, { ...res.data, eventId: self.eventId });
237
+ return res;
238
+ }
239
+ if ((params == null ? void 0 : params.externalEventId) ?? (params == null ? void 0 : params.externalevent_id)) {
240
+ const res = await reqGet("/event/get", { externalevent_id: params.externalEventId ?? params.externalevent_id });
241
+ if (res.status === "success" && res.data) applySnapshot(self, { ...res.data, eventId: self.eventId });
242
+ return res;
243
+ }
244
+ return { status: "failure", message: "Provide eventId or externalEventId" };
245
+ },
246
+ /** POST /event/create – create event */
247
+ async create(offsetMinutes) {
248
+ const offset = offsetMinutes ?? getOffset();
249
+ const payload = {
250
+ calendarId: self.calendarId,
251
+ participantId: self.participantId ?? void 0,
252
+ title: self.title ?? void 0,
253
+ description: self.description ?? void 0,
254
+ startDate: self.startDate,
255
+ endDate: self.endDate,
256
+ startHour: self.startHour,
257
+ startMinute: self.startMinute,
258
+ endHour: self.endHour,
259
+ endMinute: self.endMinute,
260
+ visitorName: self.visitorName ?? void 0,
261
+ visitorEmail: self.visitorEmail ?? void 0,
262
+ visitorPhone: self.visitorPhone ?? void 0
263
+ };
264
+ const res = await reqPost("/event/create", payload, null, { headers: { offset: String(offset) } });
265
+ if (res.status === "success" && res.data) applySnapshot(self, { ...res.data, eventId: self.eventId });
266
+ return res;
267
+ },
268
+ /** POST /event/update – update event */
269
+ async update() {
270
+ const payload = {
271
+ eventId: self.eventId,
272
+ calendarId: self.calendarId,
273
+ participantId: self.participantId ?? void 0,
274
+ title: self.title ?? void 0,
275
+ description: self.description ?? void 0,
276
+ startDate: self.startDate,
277
+ endDate: self.endDate,
278
+ startHour: self.startHour,
279
+ startMinute: self.startMinute,
280
+ endHour: self.endHour,
281
+ endMinute: self.endMinute,
282
+ visitorName: self.visitorName ?? void 0,
283
+ visitorEmail: self.visitorEmail ?? void 0,
284
+ visitorPhone: self.visitorPhone ?? void 0
285
+ };
286
+ return reqPost("/event/update", payload);
287
+ },
288
+ /** POST /event/reschedule – reschedule event */
289
+ async reschedule(offsetMinutes) {
290
+ const offset = offsetMinutes ?? getOffset();
291
+ const payload = {
292
+ eventId: self.eventId,
293
+ calendarId: self.calendarId,
294
+ participantId: self.participantId ?? void 0,
295
+ title: self.title ?? void 0,
296
+ description: self.description ?? void 0,
297
+ startDate: self.startDate,
298
+ endDate: self.endDate,
299
+ startHour: self.startHour,
300
+ startMinute: self.startMinute,
301
+ endHour: self.endHour,
302
+ endMinute: self.endMinute,
303
+ visitorName: self.visitorName ?? void 0,
304
+ visitorEmail: self.visitorEmail ?? void 0,
305
+ visitorPhone: self.visitorPhone ?? void 0
306
+ };
307
+ const res = await reqPost("/event/reschedule", payload, null, { headers: { offset: String(offset) } });
308
+ if (res.status === "success" && res.data) applySnapshot(self, { ...res.data, eventId: self.eventId });
309
+ return res;
310
+ },
311
+ /** GET /event/cancel – cancel this event */
312
+ async cancel() {
313
+ return reqGet("/event/cancel", { event_id: self.eventId });
314
+ },
315
+ /** GET /event/cancellable – check if this event is cancellable */
316
+ async getCancellable() {
317
+ const res = await reqGet("/event/cancellable", { event_id: self.eventId });
318
+ if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
319
+ return res;
320
+ },
321
+ /** GET /event/availability/get – get availability slots for a day */
322
+ async getAvailability(params) {
323
+ const query = {
324
+ calendar_id: self.calendarId,
325
+ year: params.year,
326
+ month: params.month,
327
+ day: params.day
328
+ };
329
+ if (params.participantId ?? self.participantId) query.participant_id = params.participantId ?? self.participantId;
330
+ return reqGet("/event/availability/get", query, { headers: { offset: String(params.offset ?? getOffset()) } });
331
+ },
332
+ /** GET /event/seteventreminder/{event_id} – set SMS reminder */
333
+ async setReminder() {
334
+ return req(`/event/seteventreminder/${encodeURIComponent(self.eventId)}`, { method: "GET" });
335
+ },
336
+ /** GET /event/{eventId}/{attendeeStatus} – set attendee status */
337
+ async setAttendeeStatus(status) {
338
+ const statusName = typeof status === "number" ? Object.keys(AttendeeStatus).find((k) => AttendeeStatus[k] === status) ?? "None" : status;
339
+ return reqGet(`/event/${encodeURIComponent(self.eventId)}/${encodeURIComponent(statusName)}`);
340
+ }
341
+ };
868
342
  });
869
- var Availability_default = AvailabilityModel;
343
+ function mapEventFromApi(d) {
344
+ if (!d) return d;
345
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
346
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
347
+ return {
348
+ eventId: String(pick("eventId", "EventId", "event_id") ?? ""),
349
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
350
+ participantId: pick("participantId", "ParticipantId", "participant_id") ?? null,
351
+ title: pick("title", "Title"),
352
+ description: pick("description", "Description"),
353
+ startDate: pick("startDate", "StartDate", "start_date"),
354
+ endDate: pick("endDate", "EndDate", "end_date"),
355
+ startHour: n(pick("startHour", "StartHour", "start_hour")),
356
+ startMinute: n(pick("startMinute", "StartMinute", "start_minute")),
357
+ endHour: n(pick("endHour", "EndHour", "end_hour")),
358
+ endMinute: n(pick("endMinute", "EndMinute", "end_minute")),
359
+ visitorName: pick("visitorName", "VisitorName", "visitor_name"),
360
+ visitorEmail: pick("visitorEmail", "VisitorEmail", "visitor_email"),
361
+ visitorPhone: pick("visitorPhone", "VisitorPhone", "visitor_phone"),
362
+ externalEventId: pick("externalEventId", "ExternalEventId", "external_event_id"),
363
+ attendeeStatus: n(pick("attendeeStatus", "AttendeeStatus", "attendee_status")),
364
+ rescheduleLink: pick("rescheduleLink", "RescheduleLink", "reschedule_link"),
365
+ cancelLink: pick("cancelLink", "CancelLink", "cancel_link"),
366
+ timeZone: pick("timeZone", "TimeZone", "time_zone"),
367
+ createdOn: pick("createdOn", "CreatedOn", "created_on"),
368
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on")
369
+ };
370
+ }
371
+ EventModel.get = async (eventId) => {
372
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
373
+ const res = await reqGet("/event/get", { event_id: eventId });
374
+ if (res.status === "success" && res.data) {
375
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
376
+ }
377
+ return null;
378
+ };
379
+ EventModel.getByExternalId = async (externalEventId) => {
380
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
381
+ const res = await reqGet("/event/get", { externalevent_id: externalEventId });
382
+ if (res.status === "success" && res.data) {
383
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
384
+ }
385
+ return null;
386
+ };
387
+ EventModel.getRoundRobinParticipant = async (calendarId) => {
388
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
389
+ const res = await reqGet("/event/participant/roundrobin/get", { calendar_id: calendarId });
390
+ return res.status === "success" ? res.data : null;
391
+ };
392
+ EventModel.getEarliestAvailableDays = async (calendarId, count, opts = {}) => {
393
+ const { req } = createRequestHelpersFromEnv(getConfig());
394
+ const query = { calendar_id: calendarId, count };
395
+ if (opts.year != null) query.year = opts.year;
396
+ if (opts.month != null) query.month = opts.month;
397
+ if (opts.day != null) query.day = opts.day;
398
+ const offset = opts.offset ?? getDefaultOffset();
399
+ const res = await req("/event/days/available/get", { method: "GET", query, headers: { offset: String(offset) } });
400
+ return res.status === "success" && Array.isArray(res.data) ? res.data : null;
401
+ };
402
+ EventModel.getDaySelectable = async (calendarId, year, month, day, opts = {}) => {
403
+ const { req } = createRequestHelpersFromEnv(getConfig());
404
+ const query = { calendar_id: calendarId, year, month, day };
405
+ if (opts.participantId) query.participant_id = opts.participantId;
406
+ const offset = opts.offset ?? getDefaultOffset();
407
+ const res = await req("/event/day/selectable/get", { method: "GET", query, headers: { offset: String(offset) } });
408
+ return res.status === "success" ? Boolean(res.data) : false;
409
+ };
410
+ EventModel.getByVisitorEmail = async (email, opts = {}) => {
411
+ const { req } = createRequestHelpersFromEnv(getConfig());
412
+ const query = { email };
413
+ if (opts.companyKey) query.company_key = opts.companyKey;
414
+ else if (opts.calendarId) query.calendar_id = opts.calendarId;
415
+ else throw new Error("companyKey or calendarId required");
416
+ const offset = opts.offset ?? getDefaultOffset();
417
+ const res = await req("/event/existing/getbyvisitoremail", { method: "GET", query, headers: { offset: String(offset) } });
418
+ if (res.status === "success" && Array.isArray(res.data)) {
419
+ return res.data.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
420
+ }
421
+ return null;
422
+ };
423
+ EventModel.getByVisitorPhone = async (phone, opts = {}) => {
424
+ const { req } = createRequestHelpersFromEnv(getConfig());
425
+ const query = { phone };
426
+ if (opts.companyKey) query.company_key = opts.companyKey;
427
+ else if (opts.calendarId) query.calendar_id = opts.calendarId;
428
+ else throw new Error("companyKey or calendarId required");
429
+ const offset = opts.offset ?? getDefaultOffset();
430
+ const res = await req("/event/existing/getbyvisitorphone", { method: "GET", query, headers: { offset: String(offset) } });
431
+ if (res.status === "success" && Array.isArray(res.data)) {
432
+ return res.data.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
433
+ }
434
+ return null;
435
+ };
436
+ EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
437
+ const { req } = createRequestHelpersFromEnv(getConfig());
438
+ const query = { calendar_id: calendarId, year, month, day };
439
+ if (opts.participantId) query.participant_id = opts.participantId;
440
+ const offset = opts.offset ?? getDefaultOffset();
441
+ const res = await req("/event/availability/get", { method: "GET", query, headers: { offset: String(offset) } });
442
+ if (res.status === "success" && Array.isArray(res.data)) {
443
+ return res.data.map((s) => TimeSlot_default.create({
444
+ startHour: s.startHour ?? s.StartHour,
445
+ startMinute: s.startMinute ?? s.StartMinute,
446
+ endHour: s.endHour ?? s.EndHour,
447
+ endMinute: s.endMinute ?? s.EndMinute,
448
+ startDate: s.startDate ?? s.StartDate,
449
+ endDate: s.endDate ?? s.EndDate,
450
+ participantId: s.participantId ?? s.ParticipantId ?? null
451
+ }));
452
+ }
453
+ return [];
454
+ };
455
+ EventModel.cancel = async (eventId) => {
456
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
457
+ return reqGet("/event/cancel", { event_id: eventId });
458
+ };
459
+ EventModel.getCancellable = async (eventId) => {
460
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
461
+ const res = await reqGet("/event/cancellable", { event_id: eventId });
462
+ return res.status === "success" ? Boolean(res.data) : false;
463
+ };
464
+ EventModel.createEvent = async (payload, offsetMinutes) => {
465
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
466
+ const offset = offsetMinutes ?? getDefaultOffset();
467
+ const res = await reqPost("/event/create", payload, null, { headers: { offset: String(offset) } });
468
+ if (res.status === "success" && res.data) {
469
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
470
+ }
471
+ return null;
472
+ };
473
+ EventModel.reschedule = async (payload, offsetMinutes) => {
474
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
475
+ const offset = offsetMinutes ?? getDefaultOffset();
476
+ const res = await reqPost("/event/reschedule", payload, null, { headers: { offset: String(offset) } });
477
+ if (res.status === "success" && res.data) {
478
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
479
+ }
480
+ return null;
481
+ };
482
+ EventModel.updateEvent = async (payload) => {
483
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
484
+ return reqPost("/event/update", payload);
485
+ };
486
+ EventModel.createTest = async (payload, offsetMinutes) => {
487
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
488
+ const offset = offsetMinutes ?? getDefaultOffset();
489
+ return reqPost("/event/testcreate", payload, null, { headers: { offset: String(offset) } });
490
+ };
491
+ EventModel.getCustomData = async (calendarId, eventId) => {
492
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
493
+ const query = { calendar_id: calendarId };
494
+ if (eventId) query.event_id = eventId;
495
+ const res = await reqPost("/event/customdata/get", {}, query);
496
+ if (res.status === "success" && typeof res.data === "string") {
497
+ try {
498
+ return JSON.parse(res.data);
499
+ } catch {
500
+ return res.data;
501
+ }
502
+ }
503
+ return res.status === "success" ? res.data : null;
504
+ };
505
+ EventModel.setReminder = async (eventId) => {
506
+ const { req } = createRequestHelpersFromEnv(getConfig());
507
+ return req(`/event/seteventreminder/${encodeURIComponent(eventId)}`, { method: "GET" });
508
+ };
509
+ EventModel.setAttendeeStatus = async (eventId, attendeeStatus) => {
510
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
511
+ const statusName = typeof attendeeStatus === "number" ? Object.keys(AttendeeStatus).find((k) => AttendeeStatus[k] === attendeeStatus) ?? "None" : attendeeStatus;
512
+ return reqGet(`/event/${encodeURIComponent(eventId)}/${encodeURIComponent(statusName)}`);
513
+ };
514
+ var Event_default = EventModel;
515
+
516
+ // src/models/appointment/CalendarParticipant.js
517
+ import { types as types5 } from "mobx-state-tree";
870
518
 
871
- // src/models/appointment/AvailabilityDetail.ts
519
+ // src/models/appointment/ParticipantInfo.js
872
520
  import { types as types4 } from "mobx-state-tree";
873
- var AvailabilityDetailModel = types4.model("AvailabilityDetail", {
874
- id: types4.maybeNull(types4.number),
875
- availabilityId: types4.string,
876
- sunday: types4.optional(types4.boolean, false),
877
- monday: types4.optional(types4.boolean, false),
878
- tuesday: types4.optional(types4.boolean, false),
879
- wednesday: types4.optional(types4.boolean, false),
880
- thursday: types4.optional(types4.boolean, false),
881
- friday: types4.optional(types4.boolean, false),
882
- saturday: types4.optional(types4.boolean, false),
883
- startHour: types4.optional(types4.number, 0),
884
- startMinute: types4.optional(types4.number, 0),
885
- endHour: types4.optional(types4.number, 0),
886
- endMinute: types4.optional(types4.number, 0),
887
- createdOn: types4.maybeNull(types4.string),
888
- modifiedOn: types4.maybeNull(types4.string)
521
+ var ParticipantInfoModel = types4.model("ParticipantInfo", {
522
+ participantId: types4.optional(types4.string, ""),
523
+ calendarParticipantId: types4.optional(types4.string, ""),
524
+ alias: types4.maybeNull(types4.string),
525
+ email: types4.maybeNull(types4.string),
526
+ isApproved: types4.optional(types4.boolean, false),
527
+ emailProvider: types4.optional(types4.number, 0),
528
+ isAvailable: types4.optional(types4.boolean, false)
889
529
  });
890
- var AvailabilityDetail_default = AvailabilityDetailModel;
530
+ var ParticipantInfo_default = ParticipantInfoModel;
891
531
 
892
- // src/models/appointment/CalendarParticipant.ts
893
- import { types as types5 } from "mobx-state-tree";
532
+ // src/models/appointment/CalendarParticipant.js
894
533
  var CalendarParticipantModel = types5.model("CalendarParticipant", {
895
- id: types5.maybeNull(types5.number),
534
+ id: types5.optional(types5.maybeNull(types5.number), null),
896
535
  calendarParticipantId: types5.optional(types5.string, ""),
897
- participantId: types5.string,
898
- calendarId: types5.string,
899
- createdOn: types5.maybeNull(types5.string),
900
- modifiedOn: types5.maybeNull(types5.string)
536
+ participantId: types5.optional(types5.string, ""),
537
+ calendarId: types5.optional(types5.string, ""),
538
+ createdOn: types5.optional(types5.maybeNull(types5.string), null),
539
+ modifiedOn: types5.optional(types5.maybeNull(types5.string), null)
901
540
  });
541
+ function mapFromApi(d) {
542
+ if (!d) return d;
543
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
544
+ return {
545
+ id: pick("id", "Id"),
546
+ calendarParticipantId: String(pick("calendarParticipantId", "CalendarParticipantId", "calendarparticipant_id") ?? ""),
547
+ participantId: String(pick("participantId", "ParticipantId", "participant_id") ?? ""),
548
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
549
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
550
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
551
+ };
552
+ }
553
+ CalendarParticipantModel.getByCalendar = async (calendarId) => {
554
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
555
+ const res = await reqGet("/Calendar/Participant/Get", { calendar_id: calendarId });
556
+ if (res.status === "success" && res.data != null) {
557
+ const arr = Array.isArray(res.data) ? res.data : typeof res.data === "string" ? JSON.parse(res.data) : [];
558
+ return arr.map((p) => CalendarParticipantModel.create(mapFromApi({ ...p, calendar_id: calendarId })));
559
+ }
560
+ return null;
561
+ };
562
+ CalendarParticipantModel.getInfoByCalendar = async (calendarId) => {
563
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
564
+ const res = await reqGet("/Calendar/Participants/GetInfo", { calendar_id: calendarId });
565
+ if (res.status === "success" && Array.isArray(res.data)) {
566
+ return res.data.map(
567
+ (p) => ParticipantInfo_default.create({
568
+ participantId: p.participantId ?? p.ParticipantId ?? p.participant_id ?? "",
569
+ calendarParticipantId: p.calendarParticipantId ?? p.CalendarParticipantId ?? p.calendarparticipant_id ?? "",
570
+ alias: p.alias ?? p.Alias ?? null,
571
+ email: p.email ?? p.Email ?? null,
572
+ isApproved: p.isApproved ?? p.IsApproved ?? p.is_approved ?? false,
573
+ emailProvider: p.emailProvider ?? p.EmailProvider ?? p.email_provider ?? 0,
574
+ isAvailable: p.isAvailable ?? p.IsAvailable ?? p.is_available ?? false
575
+ })
576
+ );
577
+ }
578
+ return null;
579
+ };
580
+ CalendarParticipantModel.getByParticipant = async (participantId) => {
581
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
582
+ const res = await reqGet("/Participant/calendar/get", { participant_id: participantId });
583
+ if (res.status === "success" && res.data != null) {
584
+ const arr = Array.isArray(res.data) ? res.data : typeof res.data === "string" ? JSON.parse(res.data) : [];
585
+ return arr.map((p) => CalendarParticipantModel.create(mapFromApi({ ...p, participant_id: participantId })));
586
+ }
587
+ return null;
588
+ };
902
589
  var CalendarParticipant_default = CalendarParticipantModel;
903
590
 
904
- // src/models/appointment/Participant.ts
591
+ // src/models/appointment/CalendarDay.js
905
592
  import { types as types6 } from "mobx-state-tree";
906
- var ParticipantModel = types6.model("Participant", {
907
- id: types6.maybeNull(types6.number),
908
- participantId: types6.identifier,
909
- companyKey: types6.maybeNull(types6.string),
910
- alias: types6.optional(types6.string, ""),
911
- email: types6.optional(types6.string, ""),
912
- isApproved: types6.optional(types6.boolean, false),
913
- isAvailable: types6.optional(types6.boolean, false),
914
- provider: types6.optional(types6.number, 0),
915
- createdOn: types6.maybeNull(types6.string),
916
- modifiedOn: types6.maybeNull(types6.string),
917
- isDeleted: types6.optional(types6.boolean, false)
593
+ var CalendarDayModel = types6.model("CalendarDay", {
594
+ date: types6.optional(types6.string, "")
918
595
  });
919
- var Participant_default = ParticipantModel;
596
+ var CalendarDay_default = CalendarDayModel;
920
597
 
921
- // src/models/appointment/OpeningHour.ts
922
- import { types as types7 } from "mobx-state-tree";
923
- var OpeningHourModel = types7.model("OpeningHour", {
598
+ // src/models/appointment/Calendar.js
599
+ var CalendarModel = types7.model("Calendar", {
924
600
  id: types7.maybeNull(types7.number),
925
- openingHourId: types7.optional(types7.string, ""),
926
- calendarId: types7.string,
927
- participantId: types7.string,
928
- day: types7.optional(types7.number, 0),
929
- startHour: types7.optional(types7.number, 0),
930
- startMinute: types7.optional(types7.number, 0),
931
- endHour: types7.optional(types7.number, 0),
932
- endMinute: types7.optional(types7.number, 0),
933
- off: types7.optional(types7.boolean, false),
601
+ companyKey: types7.maybeNull(types7.string),
602
+ calendarId: types7.optional(types7.identifier, "new"),
603
+ name: types7.maybeNull(types7.string),
604
+ // location: types.maybeNull(types.string),
605
+ timeZoneId: types7.maybeNull(types7.string),
606
+ purpose: types7.optional(types7.string, ""),
607
+ description: types7.maybeNull(types7.string),
608
+ assignmentMethod: types7.optional(types7.number, AssignmentMethod.RoundRobin),
609
+ duration: types7.optional(types7.number, 0),
610
+ durationUnit: types7.optional(types7.number, Unit.Minutes),
611
+ minimumBookingNotice: types7.optional(types7.number, 0),
612
+ minimumBookingNoticeUnit: types7.optional(types7.number, Unit.Minutes),
613
+ minimumCancelationNotice: types7.optional(types7.number, 0),
614
+ minimumCancelationNoticeUnit: types7.optional(types7.number, Unit.Minutes),
615
+ futureLimit: types7.optional(types7.number, 0),
616
+ futureLimitUnit: types7.optional(types7.number, Unit.Days),
617
+ bufferTime: types7.optional(types7.number, 0),
618
+ bufferTimeUnit: types7.optional(types7.number, Unit.Minutes),
619
+ bookingLimit: types7.optional(types7.number, 0),
934
620
  createdOn: types7.maybeNull(types7.string),
935
621
  modifiedOn: types7.maybeNull(types7.string)
622
+ }).actions((self) => {
623
+ const { req, reqGet, reqPost } = createRequestHelpers(self, getEnv2);
624
+ return {
625
+ /** GET Calendar/Get – fetch this calendar by calendarId */
626
+ async get() {
627
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
628
+ const res = await reqGet("/Calendar/Get", { calendar_id: self.calendarId });
629
+ if (res.status === "success" && res.data) {
630
+ applySnapshot2(self, { ...res.data, calendarId: self.calendarId });
631
+ }
632
+ return res;
633
+ },
634
+ /** POST Calendar/Create – create or update calendar */
635
+ async create() {
636
+ const payload = {
637
+ calendarId: self.calendarId || void 0,
638
+ companyKey: self.companyKey ?? void 0,
639
+ name: self.name ?? void 0,
640
+ timeZoneId: self.timeZoneId ?? void 0,
641
+ purpose: self.purpose,
642
+ description: self.description ?? void 0,
643
+ assignmentMethod: self.assignmentMethod,
644
+ duration: self.duration,
645
+ durationUnit: self.durationUnit,
646
+ minimumBookingNotice: self.minimumBookingNotice,
647
+ minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
648
+ minimumCancelationNotice: self.minimumCancelationNotice,
649
+ minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
650
+ futureLimit: self.futureLimit,
651
+ futureLimitUnit: self.futureLimitUnit,
652
+ bufferTime: self.bufferTime,
653
+ bufferTimeUnit: self.bufferTimeUnit,
654
+ bookingLimit: self.bookingLimit
655
+ };
656
+ const res = await reqPost("/Calendar/Create", payload);
657
+ if (res.status === "success" && res.data) {
658
+ applySnapshot2(self, { ...res.data, calendarId: res.data.calendarId || self.calendarId });
659
+ }
660
+ return res;
661
+ },
662
+ /** GET Calendar/Remove */
663
+ async remove() {
664
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
665
+ return reqGet("/Calendar/Remove", { calendar_id: self.calendarId });
666
+ },
667
+ /** POST Calendar/Event/Update */
668
+ async update() {
669
+ const payload = {
670
+ calendarId: self.calendarId,
671
+ companyKey: self.companyKey ?? void 0,
672
+ name: self.name ?? void 0,
673
+ timeZoneId: self.timeZoneId ?? void 0,
674
+ purpose: self.purpose,
675
+ description: self.description ?? void 0,
676
+ assignmentMethod: self.assignmentMethod,
677
+ duration: self.duration,
678
+ durationUnit: self.durationUnit,
679
+ minimumBookingNotice: self.minimumBookingNotice,
680
+ minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
681
+ minimumCancelationNotice: self.minimumCancelationNotice,
682
+ minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
683
+ futureLimit: self.futureLimit,
684
+ futureLimitUnit: self.futureLimitUnit,
685
+ bufferTime: self.bufferTime,
686
+ bufferTimeUnit: self.bufferTimeUnit,
687
+ bookingLimit: self.bookingLimit
688
+ };
689
+ return reqPost("/Calendar/Event/Update", payload);
690
+ },
691
+ /** GET Calendar/Participant/Add */
692
+ async addParticipant(participantId) {
693
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
694
+ return reqGet("/Calendar/Participant/Add", { calendar_id: self.calendarId, participant_id: participantId });
695
+ },
696
+ /** GET Calendar/Participant/Remove */
697
+ async removeParticipant(participantId) {
698
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
699
+ return reqGet("/Calendar/Participant/Remove", { calendar_id: self.calendarId, participant_id: participantId });
700
+ },
701
+ /** GET Calendar/Participant/OpeningHours/Get */
702
+ async getParticipantOpeningHours(params = {}) {
703
+ if (!self.calendarId && !params.calendarParticipantId) {
704
+ return { status: "failure", message: "calendarId or calendarParticipantId required" };
705
+ }
706
+ const q = {};
707
+ if (params.calendarParticipantId) q.calendarparticipant_id = params.calendarParticipantId;
708
+ if (params.participantId) q.participant_id = params.participantId;
709
+ if (params.calendarId) q.calendar_id = params.calendarId;
710
+ else if (self.calendarId) q.calendar_id = self.calendarId;
711
+ return reqGet("/Calendar/Participant/OpeningHours/Get", q);
712
+ },
713
+ /** POST Calendar/Participant/Availability/OpeningHour/Save */
714
+ async saveOpeningHour(payload) {
715
+ return reqPost("/Calendar/Participant/Availability/OpeningHour/Save", payload);
716
+ },
717
+ /** POST Calendar/Participant/Availability/OpeningHours/Save */
718
+ async saveOpeningHours(payload) {
719
+ return reqPost("/Calendar/Participant/Availability/OpeningHours/Save", payload);
720
+ },
721
+ /** GET Calendar/Participant/OpeningHour/Remove */
722
+ async removeParticipantOpeningHours(participantId) {
723
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
724
+ return reqGet("/Calendar/Participant/OpeningHour/Remove", { calendar_id: self.calendarId, participant_id: participantId });
725
+ },
726
+ /** GET Calendar/Participant/Availability/Add */
727
+ async addParticipantAvailability(participantId, detail) {
728
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
729
+ return req("/Calendar/Participant/Availability/Add", {
730
+ method: "GET",
731
+ query: { calendar_id: self.calendarId, participant_id: participantId },
732
+ body: JSON.stringify(detail)
733
+ });
734
+ },
735
+ /** GET Calendar/Participant/All */
736
+ async getParticipants() {
737
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
738
+ return reqGet("/Calendar/Participant/All", { calendar_id: self.calendarId });
739
+ },
740
+ /** GET Calendar/Month/Get */
741
+ async getMonth(year, month) {
742
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
743
+ return reqGet("/Calendar/Month/Get", { calendar_id: self.calendarId, year, month });
744
+ },
745
+ /** GET Calendar/Events/Get */
746
+ async getEvents() {
747
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
748
+ return reqGet("/Calendar/Events/Get", { calendar_id: self.calendarId });
749
+ },
750
+ /** GET Calendar/Participant/Get */
751
+ async getCalendarParticipant() {
752
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
753
+ return reqGet("/Calendar/Participant/Get", { calendar_id: self.calendarId });
754
+ },
755
+ /** GET Calendar/Participants/GetInfo */
756
+ async getParticipantsInfo() {
757
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
758
+ return reqGet("/Calendar/Participants/GetInfo", { calendar_id: self.calendarId });
759
+ },
760
+ /** GET Calendar/All – calendars by company_key */
761
+ async getByCompany(companyKey) {
762
+ return reqGet("/Calendar/All", { company_key: companyKey || self.companyKey });
763
+ },
764
+ /** GET Calendar/TimeZones/Get */
765
+ async getTimeZones() {
766
+ return reqGet("/Calendar/TimeZones/Get");
767
+ },
768
+ /** GET Calendar/TimeZone/Get – display name for timezone_id */
769
+ async getTimeZone(timezoneId) {
770
+ return reqGet("/Calendar/TimeZone/Get", { timezone_id: timezoneId || self.timeZoneId });
771
+ },
772
+ /** GET Calendar/CreateWithParticipants */
773
+ async createWithParticipants(name, companyKey, participantIds, description) {
774
+ const q = {
775
+ name,
776
+ company_key: companyKey,
777
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
778
+ };
779
+ if (description) q.description = description;
780
+ return reqGet("/Calendar/CreateWithParticipants", q);
781
+ },
782
+ /** GET Calendar/EditWithParticipants */
783
+ async editWithParticipants(calendarId, name, participantIds, description) {
784
+ const q = {
785
+ calendar_id: calendarId,
786
+ name,
787
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
788
+ };
789
+ if (description) q.description = description;
790
+ return reqGet("/Calendar/EditWithParticipants", q);
791
+ }
792
+ };
936
793
  });
937
- var OpeningHour_default = OpeningHourModel;
794
+ function mapCalendarFromApi(d) {
795
+ if (!d) return d;
796
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
797
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
798
+ return {
799
+ id: pick("id", "Id"),
800
+ companyKey: pick("companyKey", "CompanyKey", "company_key"),
801
+ calendarId: pick("calendarId", "CalendarId", "calendar_id") ?? "",
802
+ name: pick("name", "Name"),
803
+ timeZoneId: pick("timeZoneId", "TimeZoneId", "time_zone_id"),
804
+ purpose: pick("purpose", "Purpose") ?? "",
805
+ description: pick("description", "Description"),
806
+ assignmentMethod: n(pick("assignmentMethod", "AssignmentMethod", "assignment_method")),
807
+ duration: n(pick("duration", "Duration")),
808
+ durationUnit: n(pick("durationUnit", "DurationUnit", "duration_unit")),
809
+ minimumBookingNotice: n(pick("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")),
810
+ minimumBookingNoticeUnit: n(pick("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")),
811
+ minimumCancelationNotice: n(pick("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")),
812
+ minimumCancelationNoticeUnit: n(pick("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")),
813
+ futureLimit: n(pick("futureLimit", "FutureLimit", "future_limit")),
814
+ futureLimitUnit: n(pick("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")),
815
+ bufferTime: n(pick("bufferTime", "BufferTime", "buffer_time")),
816
+ bufferTimeUnit: n(pick("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")),
817
+ bookingLimit: n(pick("bookingLimit", "BookingLimit", "booking_limit")),
818
+ createdOn: pick("createdOn", "CreatedOn", "created_on"),
819
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on")
820
+ };
821
+ }
822
+ CalendarModel.getRaw = async (calendarId) => {
823
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
824
+ return reqGet("/Calendar/Get", { calendar_id: calendarId });
825
+ };
826
+ CalendarModel.get = async (calendarId) => {
827
+ var _a, _b;
828
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
829
+ const res = await reqGet("/Calendar/Get", { calendar_id: calendarId });
830
+ if (res.status === "success" && res.data) {
831
+ const raw = ((_a = res.data) == null ? void 0 : _a.data) ?? ((_b = res.data) == null ? void 0 : _b.Data) ?? res.data;
832
+ const mapped = mapCalendarFromApi({ ...raw, calendar_id: calendarId });
833
+ return CalendarModel.create(mapped, { env: getConfig() });
834
+ }
835
+ return null;
836
+ };
837
+ CalendarModel.getByCompany = async (companyKey) => {
838
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
839
+ const res = await reqGet("/Calendar/All", { company_key: companyKey });
840
+ if (res.status === "success" && Array.isArray(res.data)) {
841
+ return res.data.map(
842
+ (c) => CalendarModel.create(mapCalendarFromApi(c), { env: getConfig() })
843
+ );
844
+ }
845
+ return null;
846
+ };
847
+ CalendarModel.getTimeZones = async () => {
848
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
849
+ const res = await reqGet("/Calendar/TimeZones/Get");
850
+ return res.status === "success" && res.data != null ? res.data : null;
851
+ };
852
+ CalendarModel.getTimeZone = async (timezoneId) => {
853
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
854
+ const res = await reqGet("/Calendar/TimeZone/Get", { timezone_id: timezoneId });
855
+ return res.status === "success" && res.data != null ? res.data : null;
856
+ };
857
+ CalendarModel.getParticipants = async (calendarId) => {
858
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
859
+ const res = await reqGet("/Calendar/Participant/All", { calendar_id: calendarId });
860
+ if (res.status === "success" && Array.isArray(res.data)) {
861
+ return res.data.map(
862
+ (p) => CalendarParticipant_default.create({
863
+ ...p,
864
+ participantId: p.participantId ?? p.participant_id ?? "",
865
+ calendarId: p.calendarId ?? p.calendar_id ?? calendarId,
866
+ calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? ""
867
+ })
868
+ );
869
+ }
870
+ return null;
871
+ };
872
+ CalendarModel.getCalendarParticipant = async (calendarId) => {
873
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
874
+ const res = await reqGet("/Calendar/Participant/Get", { calendar_id: calendarId });
875
+ if (res.status === "success" && Array.isArray(res.data)) {
876
+ return res.data.map(
877
+ (p) => CalendarParticipant_default.create({
878
+ ...p,
879
+ participantId: p.participantId ?? p.participant_id ?? "",
880
+ calendarId: p.calendarId ?? p.calendar_id ?? calendarId,
881
+ calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? ""
882
+ })
883
+ );
884
+ }
885
+ return null;
886
+ };
887
+ CalendarModel.getParticipantsInfo = async (calendarId) => {
888
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
889
+ const res = await reqGet("/Calendar/Participants/GetInfo", { calendar_id: calendarId });
890
+ if (res.status === "success" && Array.isArray(res.data)) {
891
+ return res.data.map(
892
+ (p) => ParticipantInfo_default.create({
893
+ participantId: p.participantId ?? p.participant_id ?? "",
894
+ calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? "",
895
+ alias: p.alias ?? null,
896
+ email: p.email ?? null,
897
+ isApproved: p.isApproved ?? p.is_approved ?? false,
898
+ emailProvider: p.emailProvider ?? p.email_provider ?? 0,
899
+ isAvailable: p.isAvailable ?? p.is_available ?? false
900
+ })
901
+ );
902
+ }
903
+ return null;
904
+ };
905
+ CalendarModel.getMonth = async (calendarId, year, month) => {
906
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
907
+ const res = await reqGet("/Calendar/Month/Get", { calendar_id: calendarId, year, month });
908
+ if (res.status === "success" && Array.isArray(res.data)) {
909
+ return res.data.map((d) => CalendarDay_default.create({ date: d.date ?? d.Date ?? "" }));
910
+ }
911
+ return null;
912
+ };
913
+ CalendarModel.getEvents = async (calendarId) => {
914
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
915
+ const res = await reqGet("/Calendar/Events/Get", { calendar_id: calendarId });
916
+ if (res.status === "success" && Array.isArray(res.data)) {
917
+ return res.data.map(
918
+ (ev) => Event_default.create(
919
+ {
920
+ ...ev,
921
+ eventId: ev.eventId ?? ev.event_id ?? "",
922
+ calendarId: ev.calendarId ?? ev.calendar_id ?? calendarId
923
+ },
924
+ { env: getConfig() }
925
+ )
926
+ );
927
+ }
928
+ return null;
929
+ };
930
+ CalendarModel.createWithParticipants = async (name, companyKey, participantIds, description, calendarId) => {
931
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
932
+ const q = {
933
+ name,
934
+ company_key: companyKey,
935
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
936
+ };
937
+ if (description) q.description = description;
938
+ if (calendarId) q.calendar_id = calendarId;
939
+ const res = await reqGet("/Calendar/CreateWithParticipants", q);
940
+ if (res.status === "success" && res.data) {
941
+ const id = typeof res.data === "string" ? res.data : res.data.calendarId ?? res.data.calendar_id;
942
+ return CalendarModel.get(id);
943
+ }
944
+ return null;
945
+ };
946
+ CalendarModel.editWithParticipants = async (calendarId, name, participantIds, description) => {
947
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
948
+ const q = {
949
+ calendar_id: calendarId,
950
+ name,
951
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
952
+ };
953
+ if (description) q.description = description;
954
+ const res = await reqGet("/Calendar/EditWithParticipants", q);
955
+ if (res.status === "success") {
956
+ return CalendarModel.get(calendarId);
957
+ }
958
+ return null;
959
+ };
960
+ var Calendar_default = CalendarModel;
938
961
 
939
- // src/models/appointment/TimeSlot.ts
962
+ // src/models/appointment/Availability.js
940
963
  import { types as types8 } from "mobx-state-tree";
941
- var TimeSlotModel = types8.model("TimeSlot", {
942
- startHour: types8.optional(types8.number, 0),
943
- startMinute: types8.optional(types8.number, 0),
944
- endHour: types8.optional(types8.number, 0),
945
- endMinute: types8.optional(types8.number, 0),
946
- startDate: types8.string,
947
- endDate: types8.string,
948
- participantId: types8.maybeNull(types8.string)
949
- }).actions((self) => ({
950
- setWithOffset(offsetMinutes) {
951
- const start = new Date(self.startDate);
952
- const end = new Date(self.endDate);
953
- start.setMinutes(start.getMinutes() + offsetMinutes);
954
- end.setMinutes(end.getMinutes() + offsetMinutes);
955
- self.startDate = start.toISOString();
956
- self.endDate = end.toISOString();
957
- self.startHour = start.getHours();
958
- self.startMinute = start.getMinutes();
959
- self.endHour = end.getHours();
960
- self.endMinute = end.getMinutes();
961
- }
962
- }));
963
- var TimeSlot_default = TimeSlotModel;
964
+ var AvailabilityModel = types8.model("Availability", {
965
+ id: types8.maybeNull(types8.number),
966
+ availabilityId: types8.string,
967
+ calendarId: types8.string,
968
+ participantId: types8.string,
969
+ createdOn: types8.maybeNull(types8.string),
970
+ modifiedOn: types8.maybeNull(types8.string)
971
+ });
972
+ var Availability_default = AvailabilityModel;
964
973
 
965
- // src/models/appointment/TimeFrame.ts
974
+ // src/models/appointment/AvailabilityDetail.js
966
975
  import { types as types9 } from "mobx-state-tree";
967
- var TimeFrameModel = types9.model("TimeFrame", {
968
- start: types9.string,
969
- end: types9.string
976
+ var AvailabilityDetailModel = types9.model("AvailabilityDetail", {
977
+ id: types9.maybeNull(types9.number),
978
+ availabilityId: types9.string,
979
+ sunday: types9.optional(types9.boolean, false),
980
+ monday: types9.optional(types9.boolean, false),
981
+ tuesday: types9.optional(types9.boolean, false),
982
+ wednesday: types9.optional(types9.boolean, false),
983
+ thursday: types9.optional(types9.boolean, false),
984
+ friday: types9.optional(types9.boolean, false),
985
+ saturday: types9.optional(types9.boolean, false),
986
+ startHour: types9.optional(types9.number, 0),
987
+ startMinute: types9.optional(types9.number, 0),
988
+ endHour: types9.optional(types9.number, 0),
989
+ endMinute: types9.optional(types9.number, 0),
990
+ createdOn: types9.maybeNull(types9.string),
991
+ modifiedOn: types9.maybeNull(types9.string)
992
+ });
993
+ var AvailabilityDetail_default = AvailabilityDetailModel;
994
+
995
+ // src/models/appointment/Participant.js
996
+ import { types as types10, getEnv as getEnv3, applySnapshot as applySnapshot3 } from "mobx-state-tree";
997
+ var ParticipantModel = types10.model("Participant", {
998
+ id: types10.optional(types10.maybeNull(types10.number), null),
999
+ participantId: types10.identifier,
1000
+ companyKey: types10.optional(types10.maybeNull(types10.string), null),
1001
+ alias: types10.optional(types10.string, ""),
1002
+ email: types10.optional(types10.string, ""),
1003
+ isApproved: types10.optional(types10.boolean, false),
1004
+ isAvailable: types10.optional(types10.boolean, false),
1005
+ provider: types10.optional(types10.number, 0),
1006
+ createdOn: types10.optional(types10.maybeNull(types10.string), null),
1007
+ modifiedOn: types10.optional(types10.maybeNull(types10.string), null),
1008
+ isDeleted: types10.optional(types10.boolean, false)
1009
+ }).actions((self) => {
1010
+ const { reqGet, reqPost } = createRequestHelpers(self, getEnv3);
1011
+ return {
1012
+ /** GET participant/get – fetch this participant */
1013
+ async get() {
1014
+ const res = await reqGet("/participant/get", { participant_id: self.participantId });
1015
+ if (res.status === "success" && res.data) applySnapshot3(self, mapFromApi2(res.data));
1016
+ return res;
1017
+ },
1018
+ /** POST participant/save – save participant (add or update) */
1019
+ async save() {
1020
+ const payload = toPayload(self);
1021
+ const res = await reqPost("/participant/save", payload);
1022
+ if (res.status === "success" && res.data) applySnapshot3(self, mapFromApi2(res.data));
1023
+ return res;
1024
+ },
1025
+ /** POST participant/update – update participant */
1026
+ async update() {
1027
+ const payload = toPayload(self);
1028
+ const res = await reqPost("/participant/update", payload);
1029
+ if (res.status === "success" && res.data) applySnapshot3(self, mapFromApi2(res.data));
1030
+ return res;
1031
+ },
1032
+ /** GET participant/remove – remove this participant */
1033
+ async remove() {
1034
+ return reqGet("/participant/remove", { participant_id: self.participantId });
1035
+ },
1036
+ /** GET participant/sendemail – send email to this participant */
1037
+ async sendEmail() {
1038
+ return reqGet("/participant/sendemail", { participant_id: self.participantId });
1039
+ }
1040
+ };
1041
+ });
1042
+ function mapFromApi2(d) {
1043
+ if (!d) return d;
1044
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1045
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
1046
+ return {
1047
+ participantId: String(pick("participantId", "ParticipantId", "participant_id") ?? ""),
1048
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? null,
1049
+ alias: pick("alias", "Alias") ?? "",
1050
+ email: pick("email", "Email") ?? "",
1051
+ isApproved: Boolean(pick("isApproved", "IsApproved", "is_approved")),
1052
+ isAvailable: Boolean(pick("isAvailable", "IsAvailable", "is_available")),
1053
+ provider: n(pick("provider", "Provider")) ?? 0,
1054
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1055
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null,
1056
+ isDeleted: Boolean(pick("isDeleted", "IsDeleted", "is_deleted"))
1057
+ };
1058
+ }
1059
+ function toPayload(self) {
1060
+ return {
1061
+ participantId: self.participantId,
1062
+ companyKey: self.companyKey ?? void 0,
1063
+ alias: self.alias,
1064
+ email: self.email,
1065
+ isApproved: self.isApproved,
1066
+ isAvailable: self.isAvailable,
1067
+ provider: self.provider
1068
+ };
1069
+ }
1070
+ ParticipantModel.get = async (participantId) => {
1071
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1072
+ const res = await reqGet("/participant/get", { participant_id: participantId });
1073
+ if (res.status === "success" && res.data) {
1074
+ return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
1075
+ }
1076
+ return null;
1077
+ };
1078
+ ParticipantModel.getByIds = async (participantIds) => {
1079
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1080
+ const ids = Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds);
1081
+ const res = await reqGet("/participant/participants/get", { participantids: ids });
1082
+ if (res.status === "success" && Array.isArray(res.data)) {
1083
+ return res.data.map((p) => ParticipantModel.create(mapFromApi2(p), { env: getConfig() }));
1084
+ }
1085
+ return null;
1086
+ };
1087
+ ParticipantModel.getAll = async (companyKey) => {
1088
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1089
+ const res = await reqGet("/Participant/All", { company_key: companyKey });
1090
+ if (res.status === "success" && Array.isArray(res.data)) {
1091
+ return res.data.map((p) => ParticipantModel.create(mapFromApi2(p), { env: getConfig() }));
1092
+ }
1093
+ return null;
1094
+ };
1095
+ ParticipantModel.add = async (payload, calendarId) => {
1096
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1097
+ const query = calendarId ? { calendar_id: calendarId } : null;
1098
+ const res = await reqPost("/Participant/Add", payload, query);
1099
+ if (res.status === "success" && res.data) {
1100
+ return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
1101
+ }
1102
+ return null;
1103
+ };
1104
+ ParticipantModel.remove = async (participantId) => {
1105
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1106
+ return reqGet("/participant/remove", { participant_id: participantId });
1107
+ };
1108
+ ParticipantModel.update = async (payload) => {
1109
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1110
+ return reqPost("/participant/update", payload);
1111
+ };
1112
+ ParticipantModel.save = async (payload) => {
1113
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1114
+ const res = await reqPost("/participant/save", payload);
1115
+ if (res.status === "success" && res.data) {
1116
+ return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
1117
+ }
1118
+ return null;
1119
+ };
1120
+ ParticipantModel.sendEmail = async (participantId) => {
1121
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1122
+ return reqGet("/participant/sendemail", { participant_id: participantId });
1123
+ };
1124
+ var Participant_default = ParticipantModel;
1125
+
1126
+ // src/models/appointment/OpeningHour.js
1127
+ import { types as types11 } from "mobx-state-tree";
1128
+ var OpeningHourModel = types11.model("OpeningHour", {
1129
+ id: types11.maybeNull(types11.number),
1130
+ openingHourId: types11.optional(types11.string, ""),
1131
+ calendarId: types11.string,
1132
+ participantId: types11.string,
1133
+ day: types11.optional(types11.number, 0),
1134
+ startHour: types11.optional(types11.number, 0),
1135
+ startMinute: types11.optional(types11.number, 0),
1136
+ endHour: types11.optional(types11.number, 0),
1137
+ endMinute: types11.optional(types11.number, 0),
1138
+ off: types11.optional(types11.boolean, false),
1139
+ createdOn: types11.maybeNull(types11.string),
1140
+ modifiedOn: types11.maybeNull(types11.string)
1141
+ });
1142
+ var OpeningHour_default = OpeningHourModel;
1143
+
1144
+ // src/models/appointment/TimeFrame.js
1145
+ import { types as types12 } from "mobx-state-tree";
1146
+ var TimeFrameModel = types12.model("TimeFrame", {
1147
+ start: types12.string,
1148
+ end: types12.string
970
1149
  }).actions((self) => ({
971
1150
  buffer(bufferMinutes, unit) {
972
1151
  const bfr = unit === Unit.Hours ? bufferMinutes * 60 : bufferMinutes;
@@ -1016,28 +1195,517 @@ var TimeFrameModel = types9.model("TimeFrame", {
1016
1195
  }));
1017
1196
  var TimeFrame_default = TimeFrameModel;
1018
1197
 
1019
- // src/models/appointment/Setting.ts
1020
- import { types as types10 } from "mobx-state-tree";
1021
- var SettingModel = types10.model("Setting", {
1022
- id: types10.maybeNull(types10.number),
1023
- settingsId: types10.optional(types10.string, ""),
1024
- calendarId: types10.string,
1025
- logo: types10.maybeNull(types10.string),
1026
- theme: types10.maybeNull(types10.string),
1027
- schedulingButtonText: types10.maybeNull(types10.string),
1028
- scheduledMessage: types10.maybeNull(types10.string)
1198
+ // src/models/appointment/Setting.js
1199
+ import { types as types13, getEnv as getEnv4, applySnapshot as applySnapshot4 } from "mobx-state-tree";
1200
+ var SettingModel = types13.model("Setting", {
1201
+ id: types13.optional(types13.maybeNull(types13.number), null),
1202
+ settingsId: types13.optional(types13.string, ""),
1203
+ calendarId: types13.optional(types13.string, ""),
1204
+ logo: types13.optional(types13.maybeNull(types13.string), null),
1205
+ theme: types13.optional(types13.maybeNull(types13.string), null),
1206
+ schedulingButtonText: types13.optional(types13.maybeNull(types13.string), null),
1207
+ scheduledMessage: types13.optional(types13.maybeNull(types13.string), null)
1208
+ }).actions((self) => {
1209
+ const { reqGet, reqPost } = createRequestHelpers(self, getEnv4);
1210
+ return {
1211
+ /** GET setting/get – fetch setting for this calendar */
1212
+ async get() {
1213
+ const res = await reqGet("/setting/get", { calendar_id: self.calendarId });
1214
+ if (res.status === "success" && res.data) applySnapshot4(self, mapFromApi3(res.data));
1215
+ return res;
1216
+ },
1217
+ /** POST setting/save – save this setting */
1218
+ async save() {
1219
+ const payload = toPayload2(self);
1220
+ const res = await reqPost("/setting/save", payload);
1221
+ if (res.status === "success" && res.data) applySnapshot4(self, mapFromApi3(res.data));
1222
+ return res;
1223
+ },
1224
+ /** POST setting/logo/upload – upload logo file for this calendar */
1225
+ async uploadLogo(file) {
1226
+ return SettingModel.uploadLogo(self.calendarId, file);
1227
+ }
1228
+ };
1029
1229
  });
1230
+ function mapFromApi3(d) {
1231
+ if (!d) return d;
1232
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1233
+ return {
1234
+ settingsId: String(pick("settingsId", "SettingsId", "settings_id") ?? ""),
1235
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
1236
+ logo: pick("logo", "Logo") ?? null,
1237
+ theme: pick("theme", "Theme") ?? null,
1238
+ schedulingButtonText: pick("schedulingButtonText", "SchedulingButtonText", "scheduling_button_text") ?? null,
1239
+ scheduledMessage: pick("scheduledMessage", "ScheduledMessage", "scheduled_message") ?? null
1240
+ };
1241
+ }
1242
+ function toPayload2(self) {
1243
+ return {
1244
+ settingsId: self.settingsId || void 0,
1245
+ calendarId: self.calendarId,
1246
+ logo: self.logo ?? void 0,
1247
+ theme: self.theme ?? void 0,
1248
+ schedulingButtonText: self.schedulingButtonText ?? void 0,
1249
+ scheduledMessage: self.scheduledMessage ?? void 0
1250
+ };
1251
+ }
1252
+ SettingModel.get = async (calendarId) => {
1253
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1254
+ const res = await reqGet("/setting/get", { calendar_id: calendarId });
1255
+ if (res.status === "success" && res.data) {
1256
+ return SettingModel.create(mapFromApi3(res.data), { env: getConfig() });
1257
+ }
1258
+ return null;
1259
+ };
1260
+ SettingModel.save = async (payload) => {
1261
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1262
+ return reqPost("/setting/save", payload);
1263
+ };
1264
+ SettingModel.uploadLogo = async (calendarId, file) => {
1265
+ const cfg = getConfig();
1266
+ if (!(cfg == null ? void 0 : cfg.baseUrl)) throw new Error("Configure baseUrl before uploadLogo");
1267
+ const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
1268
+ throw new Error("fetch not available");
1269
+ });
1270
+ const baseUrl = String(cfg.baseUrl).replace(/\/+$/, "");
1271
+ const url = `${baseUrl}/setting/logo/upload?calendar_id=${encodeURIComponent(calendarId)}`;
1272
+ const formData = new FormData();
1273
+ formData.append("file", file);
1274
+ const res = await fetchFn(url, {
1275
+ method: "POST",
1276
+ body: formData
1277
+ });
1278
+ const text = await res.text();
1279
+ let data;
1280
+ try {
1281
+ data = JSON.parse(text);
1282
+ } catch {
1283
+ data = { status: "failure", message: text || res.statusText };
1284
+ }
1285
+ if (!res.ok && data.status !== "failure") {
1286
+ data.status = "failure";
1287
+ data.message = data.message ?? `HTTP ${res.status}`;
1288
+ }
1289
+ return data;
1290
+ };
1030
1291
  var Setting_default = SettingModel;
1031
1292
 
1032
- // src/models/appointment/index.ts
1033
- import { types as types11, getEnv as getEnv3 } from "mobx-state-tree";
1034
- var RootStore = types11.model("RootStore", {
1035
- calendars: types11.optional(types11.map(Calendar_default), {}),
1036
- events: types11.optional(types11.map(Event_default), {})
1293
+ // src/models/appointment/Company.js
1294
+ import { types as types14, getEnv as getEnv5, applySnapshot as applySnapshot5 } from "mobx-state-tree";
1295
+ var CompanyModel = types14.model("Company", {
1296
+ id: types14.optional(types14.maybeNull(types14.number), null),
1297
+ companyKey: types14.identifier,
1298
+ companyName: types14.optional(types14.string, ""),
1299
+ createdOn: types14.optional(types14.maybeNull(types14.string), null),
1300
+ modifiedOn: types14.optional(types14.maybeNull(types14.string), null)
1301
+ }).actions((self) => {
1302
+ const { reqGet, reqPost } = createRequestHelpers(self, getEnv5);
1303
+ return {
1304
+ /** GET Company/Get – fetch this company */
1305
+ async get() {
1306
+ const res = await reqGet("/Company/Get", { company_key: self.companyKey });
1307
+ if (res.status === "success" && res.data) applySnapshot5(self, mapFromApi4(res.data));
1308
+ return res;
1309
+ },
1310
+ /** POST Company/Save – save this company */
1311
+ async save() {
1312
+ const payload = toPayload3(self);
1313
+ const res = await reqPost("/Company/Save", payload);
1314
+ if (res.status === "success" && res.data) applySnapshot5(self, mapFromApi4(res.data));
1315
+ return res;
1316
+ }
1317
+ };
1318
+ });
1319
+ function mapFromApi4(d) {
1320
+ if (!d) return d;
1321
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1322
+ return {
1323
+ companyKey: String(pick("companyKey", "CompanyKey", "company_key") ?? ""),
1324
+ companyName: pick("companyName", "CompanyName", "company_name") ?? "",
1325
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1326
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1327
+ };
1328
+ }
1329
+ function toPayload3(self) {
1330
+ return {
1331
+ companyKey: self.companyKey,
1332
+ companyName: self.companyName ?? void 0
1333
+ };
1334
+ }
1335
+ CompanyModel.get = async (companyKey) => {
1336
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1337
+ const res = await reqGet("/Company/Get", { company_key: companyKey });
1338
+ if (res.status === "success" && res.data) {
1339
+ return CompanyModel.create(mapFromApi4(res.data), { env: getConfig() });
1340
+ }
1341
+ return null;
1342
+ };
1343
+ CompanyModel.getAll = async () => {
1344
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1345
+ const res = await reqGet("/Company/All");
1346
+ if (res.status === "success" && Array.isArray(res.data)) {
1347
+ return res.data.map((c) => CompanyModel.create(mapFromApi4(c), { env: getConfig() }));
1348
+ }
1349
+ return null;
1350
+ };
1351
+ CompanyModel.save = async (payload) => {
1352
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1353
+ const res = await reqPost("/Company/Save", payload);
1354
+ if (res.status === "success" && res.data) {
1355
+ return CompanyModel.create(mapFromApi4(res.data), { env: getConfig() });
1356
+ }
1357
+ return null;
1358
+ };
1359
+ var Company_default = CompanyModel;
1360
+
1361
+ // src/models/appointment/Preference.js
1362
+ import { types as types15 } from "mobx-state-tree";
1363
+ var PreferenceScope = {
1364
+ Global: 0,
1365
+ Consumer: 1,
1366
+ Company: 2,
1367
+ Calendar: 3,
1368
+ Event: 4
1369
+ };
1370
+ var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event"];
1371
+ var PreferenceModel = types15.model("Preference", {
1372
+ id: types15.optional(types15.maybeNull(types15.number), null),
1373
+ preferenceId: types15.optional(types15.maybeNull(types15.string), null),
1374
+ level: types15.optional(types15.number, 0),
1375
+ primaryKey: types15.optional(types15.string, ""),
1376
+ preferenceOption: types15.optional(types15.string, ""),
1377
+ optionsJson: types15.optional(types15.maybeNull(types15.string), null)
1037
1378
  }).actions((self) => ({
1038
- getApi() {
1039
- return getEnv3(self).api;
1379
+ /** POST /preference/{scope}/{key}/{option} – save this preference to the API. */
1380
+ async save() {
1381
+ const scope = SCOPE_NAMES[self.level] ?? "Global";
1382
+ return PreferenceModel.set(scope, self.primaryKey, self.preferenceOption, self.optionsJson ?? "{}");
1040
1383
  },
1384
+ /** GET /preference/remove?preference_id={id} – remove this preference from the API. Requires preferenceId from a prior get. */
1385
+ async delete() {
1386
+ if (!self.preferenceId) throw new Error("preferenceId required for delete; use PreferenceModel.delete(preferenceId) or load preference from get first.");
1387
+ return PreferenceModel.delete(self.preferenceId);
1388
+ }
1389
+ }));
1390
+ PreferenceModel.getScopes = async () => {
1391
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1392
+ const res = await reqGet("/preference/scopes");
1393
+ return res.status === "success" && res.data != null ? res.data : null;
1394
+ };
1395
+ PreferenceModel.getOptions = async () => {
1396
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1397
+ const res = await reqGet("/preference/options");
1398
+ return res.status === "success" && res.data != null ? res.data : null;
1399
+ };
1400
+ PreferenceModel.getOptionTemplate = async (option) => {
1401
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1402
+ const res = await reqGet(`/preference/options/${encodeURIComponent(option)}`);
1403
+ return res.status === "success" && res.data != null ? res.data : null;
1404
+ };
1405
+ PreferenceModel.get = async (option, keys) => {
1406
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1407
+ const keysArr = Array.isArray(keys) ? keys : keys != null ? [String(keys)] : [];
1408
+ const query = keysArr.length ? { keys: keysArr } : {};
1409
+ const res = await reqGet(`/preference/${encodeURIComponent(option)}`, query);
1410
+ return res.status === "success" && res.data != null ? res.data : null;
1411
+ };
1412
+ PreferenceModel.set = async (scope, key, option, body) => {
1413
+ const { req } = createRequestHelpersFromEnv(getConfig());
1414
+ const path = `/preference/${encodeURIComponent(scope)}/${encodeURIComponent(key)}/${encodeURIComponent(option)}`;
1415
+ const payload = typeof body === "string" ? body : JSON.stringify(body ?? {});
1416
+ return req(path, { method: "POST", body: payload });
1417
+ };
1418
+ PreferenceModel.delete = async (preferenceId) => {
1419
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1420
+ return reqGet("/preference/remove", { preference_id: preferenceId });
1421
+ };
1422
+ var Preference_default = PreferenceModel;
1423
+
1424
+ // src/models/appointment/Flow.js
1425
+ import { types as types16, getEnv as getEnv6, applySnapshot as applySnapshot6 } from "mobx-state-tree";
1426
+ function mapFlowFromApi(d) {
1427
+ if (!d) return d;
1428
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1429
+ const b = (v) => v === true || v === "true" || v === 1;
1430
+ return {
1431
+ id: pick("id", "Id") ?? null,
1432
+ flowId: pick("flowId", "FlowId", "flow_id") ?? "",
1433
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
1434
+ name: pick("name", "Name") ?? "",
1435
+ description: pick("description", "Description") ?? null,
1436
+ flowJson: pick("flowJson", "FlowJson", "flow_json") ?? "",
1437
+ isActive: b(pick("isActive", "IsActive", "is_active")) ?? true,
1438
+ isDeleted: b(pick("isDeleted", "IsDeleted", "is_deleted")) ?? false,
1439
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1440
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1441
+ };
1442
+ }
1443
+ var FlowModel = types16.model("Flow", {
1444
+ id: types16.maybeNull(types16.number),
1445
+ flowId: types16.optional(types16.identifier, "new"),
1446
+ companyKey: types16.maybeNull(types16.string),
1447
+ name: types16.maybeNull(types16.string),
1448
+ description: types16.maybeNull(types16.string),
1449
+ flowJson: types16.optional(types16.string, ""),
1450
+ isActive: types16.optional(types16.boolean, true),
1451
+ isDeleted: types16.optional(types16.boolean, false),
1452
+ createdOn: types16.maybeNull(types16.string),
1453
+ modifiedOn: types16.maybeNull(types16.string)
1454
+ }).actions((self) => {
1455
+ const { reqGet, reqPost } = createRequestHelpers(self, getEnv6);
1456
+ return {
1457
+ /** GET flow/get – fetch this flow by flowId */
1458
+ async get() {
1459
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1460
+ const res = await reqGet("/flow/get", { flow_id: self.flowId });
1461
+ if (res.status === "success" && res.data) {
1462
+ applySnapshot6(self, mapFlowFromApi(res.data));
1463
+ }
1464
+ return res;
1465
+ },
1466
+ /** POST flow/create – create flow */
1467
+ async create() {
1468
+ const payload = {
1469
+ companyKey: self.companyKey ?? void 0,
1470
+ name: self.name ?? void 0,
1471
+ description: self.description ?? void 0,
1472
+ flowJson: self.flowJson || void 0,
1473
+ isActive: self.isActive
1474
+ };
1475
+ const res = await reqPost("/flow/create", payload);
1476
+ if (res.status === "success" && res.data) {
1477
+ applySnapshot6(self, mapFlowFromApi(res.data));
1478
+ }
1479
+ return res;
1480
+ },
1481
+ /** POST flow/update – update flow */
1482
+ async update() {
1483
+ const payload = {
1484
+ flowId: self.flowId,
1485
+ name: self.name ?? void 0,
1486
+ description: self.description ?? void 0,
1487
+ flowJson: self.flowJson || void 0,
1488
+ isActive: self.isActive
1489
+ };
1490
+ const res = await reqPost("/flow/update", payload);
1491
+ if (res.status === "success" && res.data) {
1492
+ applySnapshot6(self, mapFlowFromApi(res.data));
1493
+ }
1494
+ return res;
1495
+ },
1496
+ /** POST flow/delete – soft delete flow */
1497
+ async delete() {
1498
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1499
+ return reqPost("/flow/delete", { flow_id: self.flowId });
1500
+ },
1501
+ /** POST flow/duplicate – duplicate flow */
1502
+ async duplicate(newName) {
1503
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1504
+ const res = await reqPost("/flow/duplicate", { flow_id: self.flowId, new_name: newName ?? void 0 });
1505
+ return res;
1506
+ }
1507
+ };
1508
+ });
1509
+ FlowModel.list = async (companyKey, includeDeleted = false) => {
1510
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1511
+ const query = { company_key: companyKey };
1512
+ if (includeDeleted) query.include_deleted = "true";
1513
+ const res = await reqGet("/flow/list", query);
1514
+ if (res.status === "success" && Array.isArray(res.data)) {
1515
+ return res.data.map((f) => FlowModel.create(mapFlowFromApi(f), { env: getConfig() }));
1516
+ }
1517
+ return null;
1518
+ };
1519
+ FlowModel.get = async (flowId) => {
1520
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1521
+ const res = await reqGet("/flow/get", { flow_id: flowId });
1522
+ if (res.status === "success" && res.data) {
1523
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1524
+ }
1525
+ return null;
1526
+ };
1527
+ FlowModel.createFlow = async (payload) => {
1528
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1529
+ const res = await reqPost("/flow/create", payload);
1530
+ if (res.status === "success" && res.data) {
1531
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1532
+ }
1533
+ return null;
1534
+ };
1535
+ FlowModel.updateFlow = async (payload) => {
1536
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1537
+ const res = await reqPost("/flow/update", payload);
1538
+ if (res.status === "success" && res.data) {
1539
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1540
+ }
1541
+ return null;
1542
+ };
1543
+ FlowModel.delete = async (flowId) => {
1544
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1545
+ return reqPost("/flow/delete", { flow_id: flowId });
1546
+ };
1547
+ FlowModel.duplicate = async (flowId, newName) => {
1548
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1549
+ const res = await reqPost("/flow/duplicate", { flow_id: flowId, new_name: newName ?? void 0 });
1550
+ if (res.status === "success" && res.data) {
1551
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1552
+ }
1553
+ return null;
1554
+ };
1555
+ FlowModel.getAppearance = async (flowId) => {
1556
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1557
+ const res = await reqGet("/flow/appearance/get", { flow_id: flowId });
1558
+ if (res.status === "success" && res.data != null) {
1559
+ const d = res.data;
1560
+ return {
1561
+ id: d.id ?? d.Id ?? null,
1562
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? flowId,
1563
+ appearanceJson: d.appearanceJson ?? d.AppearanceJson ?? d.appearance_json ?? "",
1564
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1565
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1566
+ };
1567
+ }
1568
+ return null;
1569
+ };
1570
+ FlowModel.saveAppearance = async (payload) => {
1571
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1572
+ const res = await reqPost("/flow/appearance/save", payload);
1573
+ if (res.status === "success" && res.data) {
1574
+ const d = res.data;
1575
+ return {
1576
+ id: d.id ?? d.Id ?? null,
1577
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? payload.flowId ?? payload.flow_id,
1578
+ appearanceJson: d.appearanceJson ?? d.AppearanceJson ?? d.appearance_json ?? "",
1579
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1580
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1581
+ };
1582
+ }
1583
+ return null;
1584
+ };
1585
+ FlowModel.getEmbed = async (flowId) => {
1586
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1587
+ const res = await reqGet("/flow/embed/get", { flow_id: flowId });
1588
+ if (res.status === "success" && res.data != null) {
1589
+ const d = res.data;
1590
+ return {
1591
+ id: d.id ?? d.Id ?? null,
1592
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? flowId,
1593
+ embedJson: d.embedJson ?? d.EmbedJson ?? d.embed_json ?? "",
1594
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1595
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1596
+ };
1597
+ }
1598
+ return null;
1599
+ };
1600
+ FlowModel.saveEmbed = async (payload) => {
1601
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1602
+ const res = await reqPost("/flow/embed/save", payload);
1603
+ if (res.status === "success" && res.data) {
1604
+ const d = res.data;
1605
+ return {
1606
+ id: d.id ?? d.Id ?? null,
1607
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? payload.flowId ?? payload.flow_id,
1608
+ embedJson: d.embedJson ?? d.EmbedJson ?? d.embed_json ?? "",
1609
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1610
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1611
+ };
1612
+ }
1613
+ return null;
1614
+ };
1615
+ FlowModel.getPublic = async (flowId) => {
1616
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1617
+ const res = await reqGet("/flow/public/get", { flow_id: flowId });
1618
+ if (res.status === "success" && res.data) {
1619
+ const d = res.data;
1620
+ return {
1621
+ flow: d.flow ? mapFlowFromApi(d.flow) : null,
1622
+ appearance: d.appearance ?? null,
1623
+ embed: d.embed ?? null
1624
+ };
1625
+ }
1626
+ return null;
1627
+ };
1628
+ FlowModel.getPreview = async (flowId) => {
1629
+ return FlowModel.getPublic(flowId);
1630
+ };
1631
+ var Flow_default = FlowModel;
1632
+
1633
+ // src/models/appointment/Lead.js
1634
+ import { types as types17, getEnv as getEnv7, applySnapshot as applySnapshot7 } from "mobx-state-tree";
1635
+ function mapLeadFromApi(d) {
1636
+ if (!d) return d;
1637
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1638
+ return {
1639
+ id: pick("id", "Id") ?? null,
1640
+ leadId: pick("leadId", "LeadId", "lead_id") ?? "",
1641
+ email: pick("email", "Email") ?? "",
1642
+ name: pick("name", "Name") ?? "",
1643
+ phone: pick("phone", "Phone") ?? "",
1644
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
1645
+ source: pick("source", "Source") ?? "",
1646
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1647
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1648
+ };
1649
+ }
1650
+ var LeadModel = types17.model("Lead", {
1651
+ id: types17.maybeNull(types17.number),
1652
+ leadId: types17.optional(types17.identifier, "new"),
1653
+ email: types17.optional(types17.string, ""),
1654
+ name: types17.optional(types17.string, ""),
1655
+ phone: types17.optional(types17.string, ""),
1656
+ companyKey: types17.optional(types17.string, ""),
1657
+ source: types17.optional(types17.string, ""),
1658
+ createdOn: types17.maybeNull(types17.string),
1659
+ modifiedOn: types17.maybeNull(types17.string)
1660
+ }).actions((self) => {
1661
+ const { reqGet } = createRequestHelpers(self, getEnv7);
1662
+ return {
1663
+ /** GET /lead/get – fetch this lead by leadId */
1664
+ async get() {
1665
+ if (!self.leadId || self.leadId === "new") return { status: "failure", message: "leadId required" };
1666
+ const res = await reqGet("/lead/get", { lead_id: self.leadId });
1667
+ if (res.status === "success" && res.data) {
1668
+ applySnapshot7(self, mapLeadFromApi(res.data));
1669
+ }
1670
+ return res;
1671
+ }
1672
+ };
1673
+ });
1674
+ LeadModel.get = async (leadId) => {
1675
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1676
+ const res = await reqGet("/lead/get", { lead_id: leadId });
1677
+ if (res.status === "success" && res.data) {
1678
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
1679
+ }
1680
+ return null;
1681
+ };
1682
+ LeadModel.getByEmail = async (email, companyKey) => {
1683
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1684
+ const res = await reqGet("/lead/getbyemail", { email, company_key: companyKey });
1685
+ if (res.status === "success" && res.data) {
1686
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
1687
+ }
1688
+ return null;
1689
+ };
1690
+ LeadModel.getByCompany = async (companyKey, opts = {}) => {
1691
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1692
+ const query = { company_key: companyKey };
1693
+ if (opts.skip != null) query.skip = opts.skip;
1694
+ if (opts.take != null) query.take = opts.take;
1695
+ const res = await reqGet("/lead/company/get", query);
1696
+ if (res.status === "success" && Array.isArray(res.data)) {
1697
+ return res.data.map((l) => LeadModel.create(mapLeadFromApi(l), { env: getConfig() }));
1698
+ }
1699
+ return null;
1700
+ };
1701
+ var Lead_default = LeadModel;
1702
+
1703
+ // src/models/appointment/index.js
1704
+ import { types as types18, getEnv as getEnv8 } from "mobx-state-tree";
1705
+ var RootStore = types18.model("RootStore", {
1706
+ calendars: types18.optional(types18.map(Calendar_default), {}),
1707
+ events: types18.optional(types18.map(Event_default), {})
1708
+ }).actions((self) => ({
1041
1709
  addCalendar(snapshot) {
1042
1710
  const cal = Calendar_default.create(snapshot);
1043
1711
  self.calendars.set(cal.calendarId, cal);
@@ -1049,23 +1717,39 @@ var RootStore = types11.model("RootStore", {
1049
1717
  return ev;
1050
1718
  }
1051
1719
  }));
1720
+ function createRootStore(initialState = {}) {
1721
+ const env = getConfig();
1722
+ if (!env) throw new Error("Call configure({ baseUrl }) before createRootStore()");
1723
+ return RootStore.create(initialState, { env });
1724
+ }
1052
1725
  export {
1053
- AppointmentClient,
1054
1726
  AssignmentMethod,
1055
1727
  AttendeeStatus,
1056
1728
  AvailabilityDetail_default as AvailabilityDetailModel,
1057
1729
  Availability_default as AvailabilityModel,
1730
+ CalendarDay_default as CalendarDayModel,
1058
1731
  Calendar_default as CalendarModel,
1059
1732
  CalendarParticipant_default as CalendarParticipantModel,
1733
+ Company_default as CompanyModel,
1734
+ ConfigModel_default as ConfigModel,
1060
1735
  DayOfWeek,
1061
1736
  Event_default as EventModel,
1737
+ Flow_default as FlowModel,
1738
+ Lead_default as LeadModel,
1062
1739
  OpeningHour_default as OpeningHourModel,
1740
+ ParticipantInfo_default as ParticipantInfoModel,
1063
1741
  Participant_default as ParticipantModel,
1742
+ Preference_default as PreferenceModel,
1743
+ PreferenceScope,
1064
1744
  RecurringFrequency,
1065
1745
  RootStore,
1066
1746
  Setting_default as SettingModel,
1067
1747
  TimeFrame_default as TimeFrameModel,
1068
1748
  TimeSlot_default as TimeSlotModel,
1069
1749
  Unit,
1070
- mapCreateEventInputToEvent
1750
+ configure,
1751
+ createRootStore,
1752
+ getConfig,
1753
+ getConfigStore,
1754
+ setBaseUrl
1071
1755
  };