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