@blazeo.com/calendar-client 1.0.2 → 1.0.3

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,165 @@ 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,
32
33
  OpeningHourModel: () => OpeningHour_default,
34
+ ParticipantInfoModel: () => ParticipantInfo_default,
33
35
  ParticipantModel: () => Participant_default,
36
+ PreferenceModel: () => Preference_default,
37
+ PreferenceScope: () => PreferenceScope,
34
38
  RecurringFrequency: () => RecurringFrequency,
35
39
  RootStore: () => RootStore,
36
40
  SettingModel: () => Setting_default,
37
41
  TimeFrameModel: () => TimeFrame_default,
38
42
  TimeSlotModel: () => TimeSlot_default,
39
43
  Unit: () => Unit,
40
- mapCreateEventInputToEvent: () => mapCreateEventInputToEvent
44
+ configure: () => configure,
45
+ createRootStore: () => createRootStore,
46
+ getConfig: () => getConfig,
47
+ getConfigStore: () => getConfigStore,
48
+ setBaseUrl: () => setBaseUrl
41
49
  });
42
50
  module.exports = __toCommonJS(index_exports);
43
51
 
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;
52
+ // src/models/appointment/Calendar.js
53
+ var import_mobx_state_tree7 = require("mobx-state-tree");
54
+
55
+ // src/ConfigModel.js
56
+ var import_mobx_state_tree = require("mobx-state-tree");
57
+ var ConfigModel = import_mobx_state_tree.types.model("Config", {
58
+ baseUrl: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, "")
59
+ }).volatile(() => ({
60
+ fetch: void 0,
61
+ getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
62
+ })).actions((self) => ({
63
+ setBaseUrl(url) {
64
+ self.baseUrl = url;
65
+ },
66
+ setFetch(fn) {
67
+ self.fetch = fn;
68
+ },
69
+ setGetDefaultOffset(fn) {
70
+ self.getDefaultOffset = fn;
71
+ },
72
+ configure(env) {
73
+ if (env.baseUrl != null) self.baseUrl = env.baseUrl;
74
+ if (env.fetch != null) self.fetch = env.fetch;
75
+ if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
76
+ }
77
+ })).views((self) => ({
78
+ getEnv() {
79
+ return {
80
+ baseUrl: self.baseUrl || void 0,
81
+ fetch: self.fetch,
82
+ getDefaultOffset: self.getDefaultOffset
83
+ };
49
84
  }
50
- return void 0;
85
+ }));
86
+ var _instance = null;
87
+ function getConfigStore() {
88
+ if (!_instance) _instance = ConfigModel.create({});
89
+ return _instance;
51
90
  }
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;
91
+ var ConfigModel_default = ConfigModel;
92
+
93
+ // src/config.js
94
+ function configure(env) {
95
+ const store = getConfigStore();
96
+ store.configure(env);
61
97
  }
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);
98
+ function getConfig() {
99
+ const store = getConfigStore();
100
+ if (!store.baseUrl) return null;
101
+ return store.getEnv();
67
102
  }
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
- };
103
+ function setBaseUrl(baseUrl) {
104
+ getConfigStore().setBaseUrl(baseUrl);
108
105
  }
109
106
 
110
- // src/client.ts
111
- function normalizeBaseUrl(baseUrl) {
112
- return baseUrl.replace(/\/+$/, "");
113
- }
107
+ // src/apiRequest.js
114
108
  function buildQuery(params) {
115
109
  const search = new URLSearchParams();
116
- for (const [k, v] of Object.entries(params)) {
110
+ for (const [k, v] of Object.entries(params || {})) {
117
111
  if (v === void 0 || v === null) continue;
118
- search.set(k, String(v));
112
+ if (Array.isArray(v)) {
113
+ for (const item of v) search.append(k, String(item));
114
+ } else {
115
+ search.set(k, String(v));
116
+ }
119
117
  }
120
118
  const q = search.toString();
121
119
  return q ? `?${q}` : "";
122
120
  }
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");
121
+ async function request(baseUrl, fetchFn, path, options = {}) {
122
+ const { method = "GET", headers = {}, body, query, skipContentType } = options;
123
+ const url = `${String(baseUrl).replace(/\/+$/, "")}${path}${buildQuery(query)}`;
124
+ const reqHeaders = { ...headers };
125
+ if (!skipContentType && typeof body === "string") reqHeaders["Content-Type"] = "application/json";
126
+ const res = await fetchFn(url, { method, headers: reqHeaders, body });
127
+ const text = await res.text();
128
+ let data;
129
+ try {
130
+ data = JSON.parse(text);
131
+ } catch {
132
+ data = { status: "failure", message: text || res.statusText };
133
+ }
134
+ if (!res.ok && data.status !== "failure") {
135
+ data.status = "failure";
136
+ data.message = data.message ?? `HTTP ${res.status}`;
137
+ }
138
+ return data;
139
+ }
140
+ function createRequestHelpers(self, getEnv7) {
141
+ const env = () => getEnv7(self);
142
+ const baseUrl = () => env().baseUrl;
143
+ const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
144
+ throw new Error("fetch not available");
145
+ });
146
+ const req = (path, opts = {}) => {
147
+ const url = baseUrl();
148
+ if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
149
+ return request(url, fetchFn(), path, opts);
150
+ };
151
+ return {
152
+ req,
153
+ reqGet: (path, query, opts = {}) => req(path, { ...opts, query }),
154
+ reqPost: (path, body, query, opts = {}) => req(path, { ...opts, method: "POST", body: JSON.stringify(body), query })
155
+ };
156
+ }
157
+ function createRequestHelpersFromEnv(env) {
158
+ const e = env ?? getConfig();
159
+ if (!e) throw new Error("Env required. Pass env to the method or call configure({ baseUrl }) at app startup.");
160
+ const baseUrl = () => e == null ? void 0 : e.baseUrl;
161
+ const fetchFn = () => (e == null ? void 0 : e.fetch) ?? (typeof fetch !== "undefined" ? fetch : () => {
162
+ throw new Error("fetch not available");
163
+ });
164
+ const req = (path, opts = {}) => {
165
+ const url = baseUrl();
166
+ if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
167
+ return request(url, fetchFn(), path, opts);
168
+ };
169
+ return {
170
+ env: e,
171
+ req,
172
+ reqGet: (path, query, opts = {}) => req(path, { ...opts, query }),
173
+ reqPost: (path, body, query, opts = {}) => req(path, { ...opts, method: "POST", body: JSON.stringify(body), query })
174
+ };
175
+ }
716
176
 
717
- // src/models/appointment/enums.ts
177
+ // src/models/appointment/enums.js
718
178
  var Unit = {
719
179
  Minutes: 1,
720
180
  Hours: 2,
@@ -752,264 +212,991 @@ var DayOfWeek = {
752
212
  Saturday: 6
753
213
  };
754
214
 
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;
215
+ // src/models/appointment/Event.js
216
+ var import_mobx_state_tree3 = require("mobx-state-tree");
819
217
 
820
- // src/models/appointment/Event.ts
218
+ // src/models/appointment/TimeSlot.js
821
219
  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,
220
+ var TimeSlotModel = import_mobx_state_tree2.types.model("TimeSlot", {
833
221
  startHour: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
834
222
  startMinute: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
835
223
  endHour: import_mobx_state_tree2.types.optional(import_mobx_state_tree2.types.number, 0),
836
224
  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)
225
+ startDate: import_mobx_state_tree2.types.string,
226
+ endDate: import_mobx_state_tree2.types.string,
227
+ participantId: import_mobx_state_tree2.types.maybeNull(import_mobx_state_tree2.types.string)
848
228
  }).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);
229
+ setWithOffset(offsetMinutes) {
230
+ const start = new Date(self.startDate);
231
+ const end = new Date(self.endDate);
232
+ start.setMinutes(start.getMinutes() + offsetMinutes);
233
+ end.setMinutes(end.getMinutes() + offsetMinutes);
234
+ self.startDate = start.toISOString();
235
+ self.endDate = end.toISOString();
236
+ self.startHour = start.getHours();
237
+ self.startMinute = start.getMinutes();
238
+ self.endHour = end.getHours();
239
+ self.endMinute = end.getMinutes();
898
240
  }
899
241
  }));
900
- var Event_default = EventModel;
242
+ var TimeSlot_default = TimeSlotModel;
901
243
 
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)
244
+ // src/models/appointment/Event.js
245
+ function getDefaultOffset() {
246
+ var _a;
247
+ const cfg = getConfig();
248
+ return ((_a = cfg == null ? void 0 : cfg.getDefaultOffset) == null ? void 0 : _a.call(cfg)) ?? -(/* @__PURE__ */ new Date()).getTimezoneOffset();
249
+ }
250
+ var EventModel = import_mobx_state_tree3.types.model("Event", {
251
+ id: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.number), null),
252
+ eventId: import_mobx_state_tree3.types.identifier,
253
+ calendarId: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.string, ""),
254
+ participantId: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
255
+ title: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
256
+ description: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
257
+ isRecurring: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.boolean, false),
258
+ recurringFrequency: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, RecurringFrequency.None),
259
+ startDate: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.string, ""),
260
+ endDate: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.string, ""),
261
+ startHour: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
262
+ startMinute: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
263
+ endHour: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
264
+ endMinute: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0),
265
+ visitorName: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
266
+ visitorEmail: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
267
+ visitorPhone: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
268
+ createdOn: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
269
+ modifiedOn: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
270
+ externalEventId: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
271
+ attendeeStatus: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, AttendeeStatus.Tentative),
272
+ rescheduleLink: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
273
+ cancelLink: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
274
+ timeZone: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.maybeNull(import_mobx_state_tree3.types.string), null),
275
+ offset: import_mobx_state_tree3.types.optional(import_mobx_state_tree3.types.number, 0)
276
+ }).actions((self) => {
277
+ const { req, reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree3.getEnv);
278
+ const getOffset = () => {
279
+ var _a, _b;
280
+ return ((_b = (_a = (0, import_mobx_state_tree3.getEnv)(self)).getDefaultOffset) == null ? void 0 : _b.call(_a)) ?? getDefaultOffset();
281
+ };
282
+ return {
283
+ /** GET /event/get – fetch this event by eventId or externalEventId */
284
+ async get(params) {
285
+ if ((params == null ? void 0 : params.eventId) ?? (params == null ? void 0 : params.event_id)) {
286
+ const res = await reqGet("/event/get", { event_id: params.eventId ?? params.event_id });
287
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
288
+ return res;
289
+ }
290
+ if ((params == null ? void 0 : params.externalEventId) ?? (params == null ? void 0 : params.externalevent_id)) {
291
+ const res = await reqGet("/event/get", { externalevent_id: params.externalEventId ?? params.externalevent_id });
292
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
293
+ return res;
294
+ }
295
+ return { status: "failure", message: "Provide eventId or externalEventId" };
296
+ },
297
+ /** POST /event/create – create event */
298
+ async create(offsetMinutes) {
299
+ const offset = offsetMinutes ?? getOffset();
300
+ const payload = {
301
+ calendarId: self.calendarId,
302
+ participantId: self.participantId ?? void 0,
303
+ title: self.title ?? void 0,
304
+ description: self.description ?? void 0,
305
+ startDate: self.startDate,
306
+ endDate: self.endDate,
307
+ startHour: self.startHour,
308
+ startMinute: self.startMinute,
309
+ endHour: self.endHour,
310
+ endMinute: self.endMinute,
311
+ visitorName: self.visitorName ?? void 0,
312
+ visitorEmail: self.visitorEmail ?? void 0,
313
+ visitorPhone: self.visitorPhone ?? void 0
314
+ };
315
+ const res = await reqPost("/event/create", payload, null, { headers: { offset: String(offset) } });
316
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
317
+ return res;
318
+ },
319
+ /** POST /event/update – update event */
320
+ async update() {
321
+ const payload = {
322
+ eventId: self.eventId,
323
+ calendarId: self.calendarId,
324
+ participantId: self.participantId ?? void 0,
325
+ title: self.title ?? void 0,
326
+ description: self.description ?? void 0,
327
+ startDate: self.startDate,
328
+ endDate: self.endDate,
329
+ startHour: self.startHour,
330
+ startMinute: self.startMinute,
331
+ endHour: self.endHour,
332
+ endMinute: self.endMinute,
333
+ visitorName: self.visitorName ?? void 0,
334
+ visitorEmail: self.visitorEmail ?? void 0,
335
+ visitorPhone: self.visitorPhone ?? void 0
336
+ };
337
+ return reqPost("/event/update", payload);
338
+ },
339
+ /** POST /event/reschedule – reschedule event */
340
+ async reschedule(offsetMinutes) {
341
+ const offset = offsetMinutes ?? getOffset();
342
+ const payload = {
343
+ eventId: self.eventId,
344
+ calendarId: self.calendarId,
345
+ participantId: self.participantId ?? void 0,
346
+ title: self.title ?? void 0,
347
+ description: self.description ?? void 0,
348
+ startDate: self.startDate,
349
+ endDate: self.endDate,
350
+ startHour: self.startHour,
351
+ startMinute: self.startMinute,
352
+ endHour: self.endHour,
353
+ endMinute: self.endMinute,
354
+ visitorName: self.visitorName ?? void 0,
355
+ visitorEmail: self.visitorEmail ?? void 0,
356
+ visitorPhone: self.visitorPhone ?? void 0
357
+ };
358
+ const res = await reqPost("/event/reschedule", payload, null, { headers: { offset: String(offset) } });
359
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree3.applySnapshot)(self, { ...res.data, eventId: self.eventId });
360
+ return res;
361
+ },
362
+ /** GET /event/cancel – cancel this event */
363
+ async cancel() {
364
+ return reqGet("/event/cancel", { event_id: self.eventId });
365
+ },
366
+ /** GET /event/cancellable – check if this event is cancellable */
367
+ async getCancellable() {
368
+ const res = await reqGet("/event/cancellable", { event_id: self.eventId });
369
+ if (res.data !== void 0) return { ...res, data: Boolean(res.data) };
370
+ return res;
371
+ },
372
+ /** GET /event/availability/get – get availability slots for a day */
373
+ async getAvailability(params) {
374
+ const query = {
375
+ calendar_id: self.calendarId,
376
+ year: params.year,
377
+ month: params.month,
378
+ day: params.day
379
+ };
380
+ if (params.participantId ?? self.participantId) query.participant_id = params.participantId ?? self.participantId;
381
+ return reqGet("/event/availability/get", query, { headers: { offset: String(params.offset ?? getOffset()) } });
382
+ },
383
+ /** GET /event/seteventreminder/{event_id} – set SMS reminder */
384
+ async setReminder() {
385
+ return req(`/event/seteventreminder/${encodeURIComponent(self.eventId)}`, { method: "GET" });
386
+ },
387
+ /** GET /event/{eventId}/{attendeeStatus} – set attendee status */
388
+ async setAttendeeStatus(status) {
389
+ const statusName = typeof status === "number" ? Object.keys(AttendeeStatus).find((k) => AttendeeStatus[k] === status) ?? "None" : status;
390
+ return reqGet(`/event/${encodeURIComponent(self.eventId)}/${encodeURIComponent(statusName)}`);
391
+ }
392
+ };
911
393
  });
912
- var Availability_default = AvailabilityModel;
394
+ function mapEventFromApi(d) {
395
+ if (!d) return d;
396
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
397
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
398
+ return {
399
+ eventId: String(pick("eventId", "EventId", "event_id") ?? ""),
400
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
401
+ participantId: pick("participantId", "ParticipantId", "participant_id") ?? null,
402
+ title: pick("title", "Title"),
403
+ description: pick("description", "Description"),
404
+ startDate: pick("startDate", "StartDate", "start_date"),
405
+ endDate: pick("endDate", "EndDate", "end_date"),
406
+ startHour: n(pick("startHour", "StartHour", "start_hour")),
407
+ startMinute: n(pick("startMinute", "StartMinute", "start_minute")),
408
+ endHour: n(pick("endHour", "EndHour", "end_hour")),
409
+ endMinute: n(pick("endMinute", "EndMinute", "end_minute")),
410
+ visitorName: pick("visitorName", "VisitorName", "visitor_name"),
411
+ visitorEmail: pick("visitorEmail", "VisitorEmail", "visitor_email"),
412
+ visitorPhone: pick("visitorPhone", "VisitorPhone", "visitor_phone"),
413
+ externalEventId: pick("externalEventId", "ExternalEventId", "external_event_id"),
414
+ attendeeStatus: n(pick("attendeeStatus", "AttendeeStatus", "attendee_status")),
415
+ rescheduleLink: pick("rescheduleLink", "RescheduleLink", "reschedule_link"),
416
+ cancelLink: pick("cancelLink", "CancelLink", "cancel_link"),
417
+ timeZone: pick("timeZone", "TimeZone", "time_zone"),
418
+ createdOn: pick("createdOn", "CreatedOn", "created_on"),
419
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on")
420
+ };
421
+ }
422
+ EventModel.get = async (eventId) => {
423
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
424
+ const res = await reqGet("/event/get", { event_id: eventId });
425
+ if (res.status === "success" && res.data) {
426
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
427
+ }
428
+ return null;
429
+ };
430
+ EventModel.getByExternalId = async (externalEventId) => {
431
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
432
+ const res = await reqGet("/event/get", { externalevent_id: externalEventId });
433
+ if (res.status === "success" && res.data) {
434
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
435
+ }
436
+ return null;
437
+ };
438
+ EventModel.getRoundRobinParticipant = async (calendarId) => {
439
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
440
+ const res = await reqGet("/event/participant/roundrobin/get", { calendar_id: calendarId });
441
+ return res.status === "success" ? res.data : null;
442
+ };
443
+ EventModel.getEarliestAvailableDays = async (calendarId, count, opts = {}) => {
444
+ const { req } = createRequestHelpersFromEnv(getConfig());
445
+ const query = { calendar_id: calendarId, count };
446
+ if (opts.year != null) query.year = opts.year;
447
+ if (opts.month != null) query.month = opts.month;
448
+ if (opts.day != null) query.day = opts.day;
449
+ const offset = opts.offset ?? getDefaultOffset();
450
+ const res = await req("/event/days/available/get", { method: "GET", query, headers: { offset: String(offset) } });
451
+ return res.status === "success" && Array.isArray(res.data) ? res.data : null;
452
+ };
453
+ EventModel.getDaySelectable = async (calendarId, year, month, day, opts = {}) => {
454
+ const { req } = createRequestHelpersFromEnv(getConfig());
455
+ const query = { calendar_id: calendarId, year, month, day };
456
+ if (opts.participantId) query.participant_id = opts.participantId;
457
+ const offset = opts.offset ?? getDefaultOffset();
458
+ const res = await req("/event/day/selectable/get", { method: "GET", query, headers: { offset: String(offset) } });
459
+ return res.status === "success" ? Boolean(res.data) : false;
460
+ };
461
+ EventModel.getByVisitorEmail = async (email, opts = {}) => {
462
+ const { req } = createRequestHelpersFromEnv(getConfig());
463
+ const query = { email };
464
+ if (opts.companyKey) query.company_key = opts.companyKey;
465
+ else if (opts.calendarId) query.calendar_id = opts.calendarId;
466
+ else throw new Error("companyKey or calendarId required");
467
+ const offset = opts.offset ?? getDefaultOffset();
468
+ const res = await req("/event/existing/getbyvisitoremail", { method: "GET", query, headers: { offset: String(offset) } });
469
+ if (res.status === "success" && Array.isArray(res.data)) {
470
+ return res.data.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
471
+ }
472
+ return null;
473
+ };
474
+ EventModel.getByVisitorPhone = async (phone, opts = {}) => {
475
+ const { req } = createRequestHelpersFromEnv(getConfig());
476
+ const query = { phone };
477
+ if (opts.companyKey) query.company_key = opts.companyKey;
478
+ else if (opts.calendarId) query.calendar_id = opts.calendarId;
479
+ else throw new Error("companyKey or calendarId required");
480
+ const offset = opts.offset ?? getDefaultOffset();
481
+ const res = await req("/event/existing/getbyvisitorphone", { method: "GET", query, headers: { offset: String(offset) } });
482
+ if (res.status === "success" && Array.isArray(res.data)) {
483
+ return res.data.map((e) => EventModel.create(mapEventFromApi(e), { env: getConfig() }));
484
+ }
485
+ return null;
486
+ };
487
+ EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) => {
488
+ const { req } = createRequestHelpersFromEnv(getConfig());
489
+ const query = { calendar_id: calendarId, year, month, day };
490
+ if (opts.participantId) query.participant_id = opts.participantId;
491
+ const offset = opts.offset ?? getDefaultOffset();
492
+ const res = await req("/event/availability/get", { method: "GET", query, headers: { offset: String(offset) } });
493
+ if (res.status === "success" && Array.isArray(res.data)) {
494
+ return res.data.map((s) => TimeSlot_default.create({
495
+ startHour: s.startHour ?? s.StartHour,
496
+ startMinute: s.startMinute ?? s.StartMinute,
497
+ endHour: s.endHour ?? s.EndHour,
498
+ endMinute: s.endMinute ?? s.EndMinute,
499
+ startDate: s.startDate ?? s.StartDate,
500
+ endDate: s.endDate ?? s.EndDate,
501
+ participantId: s.participantId ?? s.ParticipantId ?? null
502
+ }));
503
+ }
504
+ return [];
505
+ };
506
+ EventModel.cancel = async (eventId) => {
507
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
508
+ return reqGet("/event/cancel", { event_id: eventId });
509
+ };
510
+ EventModel.getCancellable = async (eventId) => {
511
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
512
+ const res = await reqGet("/event/cancellable", { event_id: eventId });
513
+ return res.status === "success" ? Boolean(res.data) : false;
514
+ };
515
+ EventModel.createEvent = async (payload, offsetMinutes) => {
516
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
517
+ const offset = offsetMinutes ?? getDefaultOffset();
518
+ const res = await reqPost("/event/create", payload, null, { headers: { offset: String(offset) } });
519
+ if (res.status === "success" && res.data) {
520
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
521
+ }
522
+ return null;
523
+ };
524
+ EventModel.reschedule = async (payload, offsetMinutes) => {
525
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
526
+ const offset = offsetMinutes ?? getDefaultOffset();
527
+ const res = await reqPost("/event/reschedule", payload, null, { headers: { offset: String(offset) } });
528
+ if (res.status === "success" && res.data) {
529
+ return EventModel.create(mapEventFromApi(res.data), { env: getConfig() });
530
+ }
531
+ return null;
532
+ };
533
+ EventModel.updateEvent = async (payload) => {
534
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
535
+ return reqPost("/event/update", payload);
536
+ };
537
+ EventModel.createTest = async (payload, offsetMinutes) => {
538
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
539
+ const offset = offsetMinutes ?? getDefaultOffset();
540
+ return reqPost("/event/testcreate", payload, null, { headers: { offset: String(offset) } });
541
+ };
542
+ EventModel.getCustomData = async (calendarId, eventId) => {
543
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
544
+ const query = { calendar_id: calendarId };
545
+ if (eventId) query.event_id = eventId;
546
+ const res = await reqPost("/event/customdata/get", {}, query);
547
+ if (res.status === "success" && typeof res.data === "string") {
548
+ try {
549
+ return JSON.parse(res.data);
550
+ } catch {
551
+ return res.data;
552
+ }
553
+ }
554
+ return res.status === "success" ? res.data : null;
555
+ };
556
+ EventModel.setReminder = async (eventId) => {
557
+ const { req } = createRequestHelpersFromEnv(getConfig());
558
+ return req(`/event/seteventreminder/${encodeURIComponent(eventId)}`, { method: "GET" });
559
+ };
560
+ EventModel.setAttendeeStatus = async (eventId, attendeeStatus) => {
561
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
562
+ const statusName = typeof attendeeStatus === "number" ? Object.keys(AttendeeStatus).find((k) => AttendeeStatus[k] === attendeeStatus) ?? "None" : attendeeStatus;
563
+ return reqGet(`/event/${encodeURIComponent(eventId)}/${encodeURIComponent(statusName)}`);
564
+ };
565
+ var Event_default = EventModel;
913
566
 
914
- // src/models/appointment/AvailabilityDetail.ts
567
+ // src/models/appointment/CalendarParticipant.js
568
+ var import_mobx_state_tree5 = require("mobx-state-tree");
569
+
570
+ // src/models/appointment/ParticipantInfo.js
915
571
  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)
572
+ var ParticipantInfoModel = import_mobx_state_tree4.types.model("ParticipantInfo", {
573
+ participantId: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.string, ""),
574
+ calendarParticipantId: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.string, ""),
575
+ alias: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string),
576
+ email: import_mobx_state_tree4.types.maybeNull(import_mobx_state_tree4.types.string),
577
+ isApproved: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false),
578
+ emailProvider: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.number, 0),
579
+ isAvailable: import_mobx_state_tree4.types.optional(import_mobx_state_tree4.types.boolean, false)
932
580
  });
933
- var AvailabilityDetail_default = AvailabilityDetailModel;
581
+ var ParticipantInfo_default = ParticipantInfoModel;
934
582
 
935
- // src/models/appointment/CalendarParticipant.ts
936
- var import_mobx_state_tree5 = require("mobx-state-tree");
583
+ // src/models/appointment/CalendarParticipant.js
937
584
  var CalendarParticipantModel = import_mobx_state_tree5.types.model("CalendarParticipant", {
938
- id: import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.number),
585
+ id: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.number), null),
939
586
  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)
587
+ participantId: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.string, ""),
588
+ calendarId: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.string, ""),
589
+ createdOn: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string), null),
590
+ modifiedOn: import_mobx_state_tree5.types.optional(import_mobx_state_tree5.types.maybeNull(import_mobx_state_tree5.types.string), null)
944
591
  });
592
+ function mapFromApi(d) {
593
+ if (!d) return d;
594
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
595
+ return {
596
+ id: pick("id", "Id"),
597
+ calendarParticipantId: String(pick("calendarParticipantId", "CalendarParticipantId", "calendarparticipant_id") ?? ""),
598
+ participantId: String(pick("participantId", "ParticipantId", "participant_id") ?? ""),
599
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
600
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
601
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
602
+ };
603
+ }
604
+ CalendarParticipantModel.getByCalendar = async (calendarId) => {
605
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
606
+ const res = await reqGet("/Calendar/Participant/Get", { calendar_id: calendarId });
607
+ if (res.status === "success" && res.data != null) {
608
+ const arr = Array.isArray(res.data) ? res.data : typeof res.data === "string" ? JSON.parse(res.data) : [];
609
+ return arr.map((p) => CalendarParticipantModel.create(mapFromApi({ ...p, calendar_id: calendarId })));
610
+ }
611
+ return null;
612
+ };
613
+ CalendarParticipantModel.getInfoByCalendar = async (calendarId) => {
614
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
615
+ const res = await reqGet("/Calendar/Participants/GetInfo", { calendar_id: calendarId });
616
+ if (res.status === "success" && Array.isArray(res.data)) {
617
+ return res.data.map(
618
+ (p) => ParticipantInfo_default.create({
619
+ participantId: p.participantId ?? p.ParticipantId ?? p.participant_id ?? "",
620
+ calendarParticipantId: p.calendarParticipantId ?? p.CalendarParticipantId ?? p.calendarparticipant_id ?? "",
621
+ alias: p.alias ?? p.Alias ?? null,
622
+ email: p.email ?? p.Email ?? null,
623
+ isApproved: p.isApproved ?? p.IsApproved ?? p.is_approved ?? false,
624
+ emailProvider: p.emailProvider ?? p.EmailProvider ?? p.email_provider ?? 0,
625
+ isAvailable: p.isAvailable ?? p.IsAvailable ?? p.is_available ?? false
626
+ })
627
+ );
628
+ }
629
+ return null;
630
+ };
631
+ CalendarParticipantModel.getByParticipant = async (participantId) => {
632
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
633
+ const res = await reqGet("/Participant/calendar/get", { participant_id: participantId });
634
+ if (res.status === "success" && res.data != null) {
635
+ const arr = Array.isArray(res.data) ? res.data : typeof res.data === "string" ? JSON.parse(res.data) : [];
636
+ return arr.map((p) => CalendarParticipantModel.create(mapFromApi({ ...p, participant_id: participantId })));
637
+ }
638
+ return null;
639
+ };
945
640
  var CalendarParticipant_default = CalendarParticipantModel;
946
641
 
947
- // src/models/appointment/Participant.ts
642
+ // src/models/appointment/CalendarDay.js
948
643
  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)
644
+ var CalendarDayModel = import_mobx_state_tree6.types.model("CalendarDay", {
645
+ date: import_mobx_state_tree6.types.optional(import_mobx_state_tree6.types.string, "")
961
646
  });
962
- var Participant_default = ParticipantModel;
647
+ var CalendarDay_default = CalendarDayModel;
963
648
 
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", {
649
+ // src/models/appointment/Calendar.js
650
+ var CalendarModel = import_mobx_state_tree7.types.model("Calendar", {
967
651
  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),
652
+ companyKey: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
653
+ calendarId: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.identifier, "new"),
654
+ name: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
655
+ // location: types.maybeNull(types.string),
656
+ timeZoneId: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
657
+ purpose: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.string, ""),
658
+ description: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
659
+ assignmentMethod: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, AssignmentMethod.RoundRobin),
660
+ duration: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
661
+ durationUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
662
+ minimumBookingNotice: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
663
+ minimumBookingNoticeUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
664
+ minimumCancelationNotice: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
665
+ minimumCancelationNoticeUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
666
+ futureLimit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
667
+ futureLimitUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Days),
668
+ bufferTime: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
669
+ bufferTimeUnit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, Unit.Minutes),
670
+ bookingLimit: import_mobx_state_tree7.types.optional(import_mobx_state_tree7.types.number, 0),
977
671
  createdOn: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string),
978
672
  modifiedOn: import_mobx_state_tree7.types.maybeNull(import_mobx_state_tree7.types.string)
673
+ }).actions((self) => {
674
+ const { req, reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree7.getEnv);
675
+ return {
676
+ /** GET Calendar/Get – fetch this calendar by calendarId */
677
+ async get() {
678
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
679
+ const res = await reqGet("/Calendar/Get", { calendar_id: self.calendarId });
680
+ if (res.status === "success" && res.data) {
681
+ (0, import_mobx_state_tree7.applySnapshot)(self, { ...res.data, calendarId: self.calendarId });
682
+ }
683
+ return res;
684
+ },
685
+ /** POST Calendar/Create – create or update calendar */
686
+ async create() {
687
+ const payload = {
688
+ calendarId: self.calendarId || void 0,
689
+ companyKey: self.companyKey ?? void 0,
690
+ name: self.name ?? void 0,
691
+ timeZoneId: self.timeZoneId ?? void 0,
692
+ purpose: self.purpose,
693
+ description: self.description ?? void 0,
694
+ assignmentMethod: self.assignmentMethod,
695
+ duration: self.duration,
696
+ durationUnit: self.durationUnit,
697
+ minimumBookingNotice: self.minimumBookingNotice,
698
+ minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
699
+ minimumCancelationNotice: self.minimumCancelationNotice,
700
+ minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
701
+ futureLimit: self.futureLimit,
702
+ futureLimitUnit: self.futureLimitUnit,
703
+ bufferTime: self.bufferTime,
704
+ bufferTimeUnit: self.bufferTimeUnit,
705
+ bookingLimit: self.bookingLimit
706
+ };
707
+ const res = await reqPost("/Calendar/Create", payload);
708
+ if (res.status === "success" && res.data) {
709
+ (0, import_mobx_state_tree7.applySnapshot)(self, { ...res.data, calendarId: res.data.calendarId || self.calendarId });
710
+ }
711
+ return res;
712
+ },
713
+ /** GET Calendar/Remove */
714
+ async remove() {
715
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
716
+ return reqGet("/Calendar/Remove", { calendar_id: self.calendarId });
717
+ },
718
+ /** POST Calendar/Event/Update */
719
+ async update() {
720
+ const payload = {
721
+ calendarId: self.calendarId,
722
+ companyKey: self.companyKey ?? void 0,
723
+ name: self.name ?? void 0,
724
+ timeZoneId: self.timeZoneId ?? void 0,
725
+ purpose: self.purpose,
726
+ description: self.description ?? void 0,
727
+ assignmentMethod: self.assignmentMethod,
728
+ duration: self.duration,
729
+ durationUnit: self.durationUnit,
730
+ minimumBookingNotice: self.minimumBookingNotice,
731
+ minimumBookingNoticeUnit: self.minimumBookingNoticeUnit,
732
+ minimumCancelationNotice: self.minimumCancelationNotice,
733
+ minimumCancelationNoticeUnit: self.minimumCancelationNoticeUnit,
734
+ futureLimit: self.futureLimit,
735
+ futureLimitUnit: self.futureLimitUnit,
736
+ bufferTime: self.bufferTime,
737
+ bufferTimeUnit: self.bufferTimeUnit,
738
+ bookingLimit: self.bookingLimit
739
+ };
740
+ return reqPost("/Calendar/Event/Update", payload);
741
+ },
742
+ /** GET Calendar/Participant/Add */
743
+ async addParticipant(participantId) {
744
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
745
+ return reqGet("/Calendar/Participant/Add", { calendar_id: self.calendarId, participant_id: participantId });
746
+ },
747
+ /** GET Calendar/Participant/Remove */
748
+ async removeParticipant(participantId) {
749
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
750
+ return reqGet("/Calendar/Participant/Remove", { calendar_id: self.calendarId, participant_id: participantId });
751
+ },
752
+ /** GET Calendar/Participant/OpeningHours/Get */
753
+ async getParticipantOpeningHours(params = {}) {
754
+ if (!self.calendarId && !params.calendarParticipantId) {
755
+ return { status: "failure", message: "calendarId or calendarParticipantId required" };
756
+ }
757
+ const q = {};
758
+ if (params.calendarParticipantId) q.calendarparticipant_id = params.calendarParticipantId;
759
+ if (params.participantId) q.participant_id = params.participantId;
760
+ if (params.calendarId) q.calendar_id = params.calendarId;
761
+ else if (self.calendarId) q.calendar_id = self.calendarId;
762
+ return reqGet("/Calendar/Participant/OpeningHours/Get", q);
763
+ },
764
+ /** POST Calendar/Participant/Availability/OpeningHour/Save */
765
+ async saveOpeningHour(payload) {
766
+ return reqPost("/Calendar/Participant/Availability/OpeningHour/Save", payload);
767
+ },
768
+ /** POST Calendar/Participant/Availability/OpeningHours/Save */
769
+ async saveOpeningHours(payload) {
770
+ return reqPost("/Calendar/Participant/Availability/OpeningHours/Save", payload);
771
+ },
772
+ /** GET Calendar/Participant/OpeningHour/Remove */
773
+ async removeParticipantOpeningHours(participantId) {
774
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
775
+ return reqGet("/Calendar/Participant/OpeningHour/Remove", { calendar_id: self.calendarId, participant_id: participantId });
776
+ },
777
+ /** GET Calendar/Participant/Availability/Add */
778
+ async addParticipantAvailability(participantId, detail) {
779
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
780
+ return req("/Calendar/Participant/Availability/Add", {
781
+ method: "GET",
782
+ query: { calendar_id: self.calendarId, participant_id: participantId },
783
+ body: JSON.stringify(detail)
784
+ });
785
+ },
786
+ /** GET Calendar/Participant/All */
787
+ async getParticipants() {
788
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
789
+ return reqGet("/Calendar/Participant/All", { calendar_id: self.calendarId });
790
+ },
791
+ /** GET Calendar/Month/Get */
792
+ async getMonth(year, month) {
793
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
794
+ return reqGet("/Calendar/Month/Get", { calendar_id: self.calendarId, year, month });
795
+ },
796
+ /** GET Calendar/Events/Get */
797
+ async getEvents() {
798
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
799
+ return reqGet("/Calendar/Events/Get", { calendar_id: self.calendarId });
800
+ },
801
+ /** GET Calendar/Participant/Get */
802
+ async getCalendarParticipant() {
803
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
804
+ return reqGet("/Calendar/Participant/Get", { calendar_id: self.calendarId });
805
+ },
806
+ /** GET Calendar/Participants/GetInfo */
807
+ async getParticipantsInfo() {
808
+ if (!self.calendarId) return { status: "failure", message: "calendarId required" };
809
+ return reqGet("/Calendar/Participants/GetInfo", { calendar_id: self.calendarId });
810
+ },
811
+ /** GET Calendar/All – calendars by company_key */
812
+ async getByCompany(companyKey) {
813
+ return reqGet("/Calendar/All", { company_key: companyKey || self.companyKey });
814
+ },
815
+ /** GET Calendar/TimeZones/Get */
816
+ async getTimeZones() {
817
+ return reqGet("/Calendar/TimeZones/Get");
818
+ },
819
+ /** GET Calendar/TimeZone/Get – display name for timezone_id */
820
+ async getTimeZone(timezoneId) {
821
+ return reqGet("/Calendar/TimeZone/Get", { timezone_id: timezoneId || self.timeZoneId });
822
+ },
823
+ /** GET Calendar/CreateWithParticipants */
824
+ async createWithParticipants(name, companyKey, participantIds, description) {
825
+ const q = {
826
+ name,
827
+ company_key: companyKey,
828
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
829
+ };
830
+ if (description) q.description = description;
831
+ return reqGet("/Calendar/CreateWithParticipants", q);
832
+ },
833
+ /** GET Calendar/EditWithParticipants */
834
+ async editWithParticipants(calendarId, name, participantIds, description) {
835
+ const q = {
836
+ calendar_id: calendarId,
837
+ name,
838
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
839
+ };
840
+ if (description) q.description = description;
841
+ return reqGet("/Calendar/EditWithParticipants", q);
842
+ }
843
+ };
979
844
  });
980
- var OpeningHour_default = OpeningHourModel;
845
+ function mapCalendarFromApi(d) {
846
+ if (!d) return d;
847
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
848
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
849
+ return {
850
+ id: pick("id", "Id"),
851
+ companyKey: pick("companyKey", "CompanyKey", "company_key"),
852
+ calendarId: pick("calendarId", "CalendarId", "calendar_id") ?? "",
853
+ name: pick("name", "Name"),
854
+ timeZoneId: pick("timeZoneId", "TimeZoneId", "time_zone_id"),
855
+ purpose: pick("purpose", "Purpose") ?? "",
856
+ description: pick("description", "Description"),
857
+ assignmentMethod: n(pick("assignmentMethod", "AssignmentMethod", "assignment_method")),
858
+ duration: n(pick("duration", "Duration")),
859
+ durationUnit: n(pick("durationUnit", "DurationUnit", "duration_unit")),
860
+ minimumBookingNotice: n(pick("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")),
861
+ minimumBookingNoticeUnit: n(pick("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")),
862
+ minimumCancelationNotice: n(pick("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")),
863
+ minimumCancelationNoticeUnit: n(pick("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")),
864
+ futureLimit: n(pick("futureLimit", "FutureLimit", "future_limit")),
865
+ futureLimitUnit: n(pick("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")),
866
+ bufferTime: n(pick("bufferTime", "BufferTime", "buffer_time")),
867
+ bufferTimeUnit: n(pick("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")),
868
+ bookingLimit: n(pick("bookingLimit", "BookingLimit", "booking_limit")),
869
+ createdOn: pick("createdOn", "CreatedOn", "created_on"),
870
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on")
871
+ };
872
+ }
873
+ CalendarModel.getRaw = async (calendarId) => {
874
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
875
+ return reqGet("/Calendar/Get", { calendar_id: calendarId });
876
+ };
877
+ CalendarModel.get = async (calendarId) => {
878
+ var _a, _b;
879
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
880
+ const res = await reqGet("/Calendar/Get", { calendar_id: calendarId });
881
+ if (res.status === "success" && res.data) {
882
+ const raw = ((_a = res.data) == null ? void 0 : _a.data) ?? ((_b = res.data) == null ? void 0 : _b.Data) ?? res.data;
883
+ const mapped = mapCalendarFromApi({ ...raw, calendar_id: calendarId });
884
+ return CalendarModel.create(mapped, { env: getConfig() });
885
+ }
886
+ return null;
887
+ };
888
+ CalendarModel.getByCompany = async (companyKey) => {
889
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
890
+ const res = await reqGet("/Calendar/All", { company_key: companyKey });
891
+ if (res.status === "success" && Array.isArray(res.data)) {
892
+ return res.data.map(
893
+ (c) => CalendarModel.create(mapCalendarFromApi(c), { env: getConfig() })
894
+ );
895
+ }
896
+ return null;
897
+ };
898
+ CalendarModel.getTimeZones = async () => {
899
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
900
+ const res = await reqGet("/Calendar/TimeZones/Get");
901
+ return res.status === "success" && res.data != null ? res.data : null;
902
+ };
903
+ CalendarModel.getTimeZone = async (timezoneId) => {
904
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
905
+ const res = await reqGet("/Calendar/TimeZone/Get", { timezone_id: timezoneId });
906
+ return res.status === "success" && res.data != null ? res.data : null;
907
+ };
908
+ CalendarModel.getParticipants = async (calendarId) => {
909
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
910
+ const res = await reqGet("/Calendar/Participant/All", { calendar_id: calendarId });
911
+ if (res.status === "success" && Array.isArray(res.data)) {
912
+ return res.data.map(
913
+ (p) => CalendarParticipant_default.create({
914
+ ...p,
915
+ participantId: p.participantId ?? p.participant_id ?? "",
916
+ calendarId: p.calendarId ?? p.calendar_id ?? calendarId,
917
+ calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? ""
918
+ })
919
+ );
920
+ }
921
+ return null;
922
+ };
923
+ CalendarModel.getCalendarParticipant = async (calendarId) => {
924
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
925
+ const res = await reqGet("/Calendar/Participant/Get", { calendar_id: calendarId });
926
+ if (res.status === "success" && Array.isArray(res.data)) {
927
+ return res.data.map(
928
+ (p) => CalendarParticipant_default.create({
929
+ ...p,
930
+ participantId: p.participantId ?? p.participant_id ?? "",
931
+ calendarId: p.calendarId ?? p.calendar_id ?? calendarId,
932
+ calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? ""
933
+ })
934
+ );
935
+ }
936
+ return null;
937
+ };
938
+ CalendarModel.getParticipantsInfo = async (calendarId) => {
939
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
940
+ const res = await reqGet("/Calendar/Participants/GetInfo", { calendar_id: calendarId });
941
+ if (res.status === "success" && Array.isArray(res.data)) {
942
+ return res.data.map(
943
+ (p) => ParticipantInfo_default.create({
944
+ participantId: p.participantId ?? p.participant_id ?? "",
945
+ calendarParticipantId: p.calendarParticipantId ?? p.calendarparticipant_id ?? "",
946
+ alias: p.alias ?? null,
947
+ email: p.email ?? null,
948
+ isApproved: p.isApproved ?? p.is_approved ?? false,
949
+ emailProvider: p.emailProvider ?? p.email_provider ?? 0,
950
+ isAvailable: p.isAvailable ?? p.is_available ?? false
951
+ })
952
+ );
953
+ }
954
+ return null;
955
+ };
956
+ CalendarModel.getMonth = async (calendarId, year, month) => {
957
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
958
+ const res = await reqGet("/Calendar/Month/Get", { calendar_id: calendarId, year, month });
959
+ if (res.status === "success" && Array.isArray(res.data)) {
960
+ return res.data.map((d) => CalendarDay_default.create({ date: d.date ?? d.Date ?? "" }));
961
+ }
962
+ return null;
963
+ };
964
+ CalendarModel.getEvents = async (calendarId) => {
965
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
966
+ const res = await reqGet("/Calendar/Events/Get", { calendar_id: calendarId });
967
+ if (res.status === "success" && Array.isArray(res.data)) {
968
+ return res.data.map(
969
+ (ev) => Event_default.create(
970
+ {
971
+ ...ev,
972
+ eventId: ev.eventId ?? ev.event_id ?? "",
973
+ calendarId: ev.calendarId ?? ev.calendar_id ?? calendarId
974
+ },
975
+ { env: getConfig() }
976
+ )
977
+ );
978
+ }
979
+ return null;
980
+ };
981
+ CalendarModel.createWithParticipants = async (name, companyKey, participantIds, description, calendarId) => {
982
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
983
+ const q = {
984
+ name,
985
+ company_key: companyKey,
986
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
987
+ };
988
+ if (description) q.description = description;
989
+ if (calendarId) q.calendar_id = calendarId;
990
+ const res = await reqGet("/Calendar/CreateWithParticipants", q);
991
+ if (res.status === "success" && res.data) {
992
+ const id = typeof res.data === "string" ? res.data : res.data.calendarId ?? res.data.calendar_id;
993
+ return CalendarModel.get(id);
994
+ }
995
+ return null;
996
+ };
997
+ CalendarModel.editWithParticipants = async (calendarId, name, participantIds, description) => {
998
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
999
+ const q = {
1000
+ calendar_id: calendarId,
1001
+ name,
1002
+ participantids: Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds)
1003
+ };
1004
+ if (description) q.description = description;
1005
+ const res = await reqGet("/Calendar/EditWithParticipants", q);
1006
+ if (res.status === "success") {
1007
+ return CalendarModel.get(calendarId);
1008
+ }
1009
+ return null;
1010
+ };
1011
+ var Calendar_default = CalendarModel;
981
1012
 
982
- // src/models/appointment/TimeSlot.ts
1013
+ // src/models/appointment/Availability.js
983
1014
  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;
1015
+ var AvailabilityModel = import_mobx_state_tree8.types.model("Availability", {
1016
+ id: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.number),
1017
+ availabilityId: import_mobx_state_tree8.types.string,
1018
+ calendarId: import_mobx_state_tree8.types.string,
1019
+ participantId: import_mobx_state_tree8.types.string,
1020
+ createdOn: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.string),
1021
+ modifiedOn: import_mobx_state_tree8.types.maybeNull(import_mobx_state_tree8.types.string)
1022
+ });
1023
+ var Availability_default = AvailabilityModel;
1007
1024
 
1008
- // src/models/appointment/TimeFrame.ts
1025
+ // src/models/appointment/AvailabilityDetail.js
1009
1026
  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
1027
+ var AvailabilityDetailModel = import_mobx_state_tree9.types.model("AvailabilityDetail", {
1028
+ id: import_mobx_state_tree9.types.maybeNull(import_mobx_state_tree9.types.number),
1029
+ availabilityId: import_mobx_state_tree9.types.string,
1030
+ sunday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1031
+ monday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1032
+ tuesday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1033
+ wednesday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1034
+ thursday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1035
+ friday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1036
+ saturday: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.boolean, false),
1037
+ startHour: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
1038
+ startMinute: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
1039
+ endHour: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
1040
+ endMinute: import_mobx_state_tree9.types.optional(import_mobx_state_tree9.types.number, 0),
1041
+ createdOn: import_mobx_state_tree9.types.maybeNull(import_mobx_state_tree9.types.string),
1042
+ modifiedOn: import_mobx_state_tree9.types.maybeNull(import_mobx_state_tree9.types.string)
1043
+ });
1044
+ var AvailabilityDetail_default = AvailabilityDetailModel;
1045
+
1046
+ // src/models/appointment/Participant.js
1047
+ var import_mobx_state_tree10 = require("mobx-state-tree");
1048
+ var ParticipantModel = import_mobx_state_tree10.types.model("Participant", {
1049
+ id: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.number), null),
1050
+ participantId: import_mobx_state_tree10.types.identifier,
1051
+ companyKey: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string), null),
1052
+ alias: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.string, ""),
1053
+ email: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.string, ""),
1054
+ isApproved: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.boolean, false),
1055
+ isAvailable: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.boolean, false),
1056
+ provider: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.number, 0),
1057
+ createdOn: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string), null),
1058
+ modifiedOn: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.maybeNull(import_mobx_state_tree10.types.string), null),
1059
+ isDeleted: import_mobx_state_tree10.types.optional(import_mobx_state_tree10.types.boolean, false)
1060
+ }).actions((self) => {
1061
+ const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree10.getEnv);
1062
+ return {
1063
+ /** GET participant/get – fetch this participant */
1064
+ async get() {
1065
+ const res = await reqGet("/participant/get", { participant_id: self.participantId });
1066
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree10.applySnapshot)(self, mapFromApi2(res.data));
1067
+ return res;
1068
+ },
1069
+ /** POST participant/save – save participant (add or update) */
1070
+ async save() {
1071
+ const payload = toPayload(self);
1072
+ const res = await reqPost("/participant/save", payload);
1073
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree10.applySnapshot)(self, mapFromApi2(res.data));
1074
+ return res;
1075
+ },
1076
+ /** POST participant/update – update participant */
1077
+ async update() {
1078
+ const payload = toPayload(self);
1079
+ const res = await reqPost("/participant/update", payload);
1080
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree10.applySnapshot)(self, mapFromApi2(res.data));
1081
+ return res;
1082
+ },
1083
+ /** GET participant/remove – remove this participant */
1084
+ async remove() {
1085
+ return reqGet("/participant/remove", { participant_id: self.participantId });
1086
+ },
1087
+ /** GET participant/sendemail – send email to this participant */
1088
+ async sendEmail() {
1089
+ return reqGet("/participant/sendemail", { participant_id: self.participantId });
1090
+ }
1091
+ };
1092
+ });
1093
+ function mapFromApi2(d) {
1094
+ if (!d) return d;
1095
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1096
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
1097
+ return {
1098
+ participantId: String(pick("participantId", "ParticipantId", "participant_id") ?? ""),
1099
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? null,
1100
+ alias: pick("alias", "Alias") ?? "",
1101
+ email: pick("email", "Email") ?? "",
1102
+ isApproved: Boolean(pick("isApproved", "IsApproved", "is_approved")),
1103
+ isAvailable: Boolean(pick("isAvailable", "IsAvailable", "is_available")),
1104
+ provider: n(pick("provider", "Provider")) ?? 0,
1105
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1106
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null,
1107
+ isDeleted: Boolean(pick("isDeleted", "IsDeleted", "is_deleted"))
1108
+ };
1109
+ }
1110
+ function toPayload(self) {
1111
+ return {
1112
+ participantId: self.participantId,
1113
+ companyKey: self.companyKey ?? void 0,
1114
+ alias: self.alias,
1115
+ email: self.email,
1116
+ isApproved: self.isApproved,
1117
+ isAvailable: self.isAvailable,
1118
+ provider: self.provider
1119
+ };
1120
+ }
1121
+ ParticipantModel.get = async (participantId) => {
1122
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1123
+ const res = await reqGet("/participant/get", { participant_id: participantId });
1124
+ if (res.status === "success" && res.data) {
1125
+ return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
1126
+ }
1127
+ return null;
1128
+ };
1129
+ ParticipantModel.getByIds = async (participantIds) => {
1130
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1131
+ const ids = Array.isArray(participantIds) ? participantIds.join(",") : String(participantIds);
1132
+ const res = await reqGet("/participant/participants/get", { participantids: ids });
1133
+ if (res.status === "success" && Array.isArray(res.data)) {
1134
+ return res.data.map((p) => ParticipantModel.create(mapFromApi2(p), { env: getConfig() }));
1135
+ }
1136
+ return null;
1137
+ };
1138
+ ParticipantModel.getAll = async (companyKey) => {
1139
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1140
+ const res = await reqGet("/Participant/All", { company_key: companyKey });
1141
+ if (res.status === "success" && Array.isArray(res.data)) {
1142
+ return res.data.map((p) => ParticipantModel.create(mapFromApi2(p), { env: getConfig() }));
1143
+ }
1144
+ return null;
1145
+ };
1146
+ ParticipantModel.add = async (payload, calendarId) => {
1147
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1148
+ const query = calendarId ? { calendar_id: calendarId } : null;
1149
+ const res = await reqPost("/Participant/Add", payload, query);
1150
+ if (res.status === "success" && res.data) {
1151
+ return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
1152
+ }
1153
+ return null;
1154
+ };
1155
+ ParticipantModel.remove = async (participantId) => {
1156
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1157
+ return reqGet("/participant/remove", { participant_id: participantId });
1158
+ };
1159
+ ParticipantModel.update = async (payload) => {
1160
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1161
+ return reqPost("/participant/update", payload);
1162
+ };
1163
+ ParticipantModel.save = async (payload) => {
1164
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1165
+ const res = await reqPost("/participant/save", payload);
1166
+ if (res.status === "success" && res.data) {
1167
+ return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
1168
+ }
1169
+ return null;
1170
+ };
1171
+ ParticipantModel.sendEmail = async (participantId) => {
1172
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1173
+ return reqGet("/participant/sendemail", { participant_id: participantId });
1174
+ };
1175
+ var Participant_default = ParticipantModel;
1176
+
1177
+ // src/models/appointment/OpeningHour.js
1178
+ var import_mobx_state_tree11 = require("mobx-state-tree");
1179
+ var OpeningHourModel = import_mobx_state_tree11.types.model("OpeningHour", {
1180
+ id: import_mobx_state_tree11.types.maybeNull(import_mobx_state_tree11.types.number),
1181
+ openingHourId: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.string, ""),
1182
+ calendarId: import_mobx_state_tree11.types.string,
1183
+ participantId: import_mobx_state_tree11.types.string,
1184
+ day: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
1185
+ startHour: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
1186
+ startMinute: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
1187
+ endHour: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
1188
+ endMinute: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.number, 0),
1189
+ off: import_mobx_state_tree11.types.optional(import_mobx_state_tree11.types.boolean, false),
1190
+ createdOn: import_mobx_state_tree11.types.maybeNull(import_mobx_state_tree11.types.string),
1191
+ modifiedOn: import_mobx_state_tree11.types.maybeNull(import_mobx_state_tree11.types.string)
1192
+ });
1193
+ var OpeningHour_default = OpeningHourModel;
1194
+
1195
+ // src/models/appointment/TimeFrame.js
1196
+ var import_mobx_state_tree12 = require("mobx-state-tree");
1197
+ var TimeFrameModel = import_mobx_state_tree12.types.model("TimeFrame", {
1198
+ start: import_mobx_state_tree12.types.string,
1199
+ end: import_mobx_state_tree12.types.string
1013
1200
  }).actions((self) => ({
1014
1201
  buffer(bufferMinutes, unit) {
1015
1202
  const bfr = unit === Unit.Hours ? bufferMinutes * 60 : bufferMinutes;
@@ -1059,28 +1246,238 @@ var TimeFrameModel = import_mobx_state_tree9.types.model("TimeFrame", {
1059
1246
  }));
1060
1247
  var TimeFrame_default = TimeFrameModel;
1061
1248
 
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)
1249
+ // src/models/appointment/Setting.js
1250
+ var import_mobx_state_tree13 = require("mobx-state-tree");
1251
+ var SettingModel = import_mobx_state_tree13.types.model("Setting", {
1252
+ id: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.number), null),
1253
+ settingsId: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.string, ""),
1254
+ calendarId: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.string, ""),
1255
+ logo: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null),
1256
+ theme: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null),
1257
+ schedulingButtonText: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null),
1258
+ scheduledMessage: import_mobx_state_tree13.types.optional(import_mobx_state_tree13.types.maybeNull(import_mobx_state_tree13.types.string), null)
1259
+ }).actions((self) => {
1260
+ const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree13.getEnv);
1261
+ return {
1262
+ /** GET setting/get – fetch setting for this calendar */
1263
+ async get() {
1264
+ const res = await reqGet("/setting/get", { calendar_id: self.calendarId });
1265
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree13.applySnapshot)(self, mapFromApi3(res.data));
1266
+ return res;
1267
+ },
1268
+ /** POST setting/save – save this setting */
1269
+ async save() {
1270
+ const payload = toPayload2(self);
1271
+ const res = await reqPost("/setting/save", payload);
1272
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree13.applySnapshot)(self, mapFromApi3(res.data));
1273
+ return res;
1274
+ },
1275
+ /** POST setting/logo/upload – upload logo file for this calendar */
1276
+ async uploadLogo(file) {
1277
+ return SettingModel.uploadLogo(self.calendarId, file);
1278
+ }
1279
+ };
1072
1280
  });
1281
+ function mapFromApi3(d) {
1282
+ if (!d) return d;
1283
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1284
+ return {
1285
+ settingsId: String(pick("settingsId", "SettingsId", "settings_id") ?? ""),
1286
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
1287
+ logo: pick("logo", "Logo") ?? null,
1288
+ theme: pick("theme", "Theme") ?? null,
1289
+ schedulingButtonText: pick("schedulingButtonText", "SchedulingButtonText", "scheduling_button_text") ?? null,
1290
+ scheduledMessage: pick("scheduledMessage", "ScheduledMessage", "scheduled_message") ?? null
1291
+ };
1292
+ }
1293
+ function toPayload2(self) {
1294
+ return {
1295
+ settingsId: self.settingsId || void 0,
1296
+ calendarId: self.calendarId,
1297
+ logo: self.logo ?? void 0,
1298
+ theme: self.theme ?? void 0,
1299
+ schedulingButtonText: self.schedulingButtonText ?? void 0,
1300
+ scheduledMessage: self.scheduledMessage ?? void 0
1301
+ };
1302
+ }
1303
+ SettingModel.get = async (calendarId) => {
1304
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1305
+ const res = await reqGet("/setting/get", { calendar_id: calendarId });
1306
+ if (res.status === "success" && res.data) {
1307
+ return SettingModel.create(mapFromApi3(res.data), { env: getConfig() });
1308
+ }
1309
+ return null;
1310
+ };
1311
+ SettingModel.save = async (payload) => {
1312
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1313
+ return reqPost("/setting/save", payload);
1314
+ };
1315
+ SettingModel.uploadLogo = async (calendarId, file) => {
1316
+ const cfg = getConfig();
1317
+ if (!(cfg == null ? void 0 : cfg.baseUrl)) throw new Error("Configure baseUrl before uploadLogo");
1318
+ const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
1319
+ throw new Error("fetch not available");
1320
+ });
1321
+ const baseUrl = String(cfg.baseUrl).replace(/\/+$/, "");
1322
+ const url = `${baseUrl}/setting/logo/upload?calendar_id=${encodeURIComponent(calendarId)}`;
1323
+ const formData = new FormData();
1324
+ formData.append("file", file);
1325
+ const res = await fetchFn(url, {
1326
+ method: "POST",
1327
+ body: formData
1328
+ });
1329
+ const text = await res.text();
1330
+ let data;
1331
+ try {
1332
+ data = JSON.parse(text);
1333
+ } catch {
1334
+ data = { status: "failure", message: text || res.statusText };
1335
+ }
1336
+ if (!res.ok && data.status !== "failure") {
1337
+ data.status = "failure";
1338
+ data.message = data.message ?? `HTTP ${res.status}`;
1339
+ }
1340
+ return data;
1341
+ };
1073
1342
  var Setting_default = SettingModel;
1074
1343
 
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), {})
1344
+ // src/models/appointment/Company.js
1345
+ var import_mobx_state_tree14 = require("mobx-state-tree");
1346
+ var CompanyModel = import_mobx_state_tree14.types.model("Company", {
1347
+ id: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.maybeNull(import_mobx_state_tree14.types.number), null),
1348
+ companyKey: import_mobx_state_tree14.types.identifier,
1349
+ companyName: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.string, ""),
1350
+ createdOn: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.maybeNull(import_mobx_state_tree14.types.string), null),
1351
+ modifiedOn: import_mobx_state_tree14.types.optional(import_mobx_state_tree14.types.maybeNull(import_mobx_state_tree14.types.string), null)
1352
+ }).actions((self) => {
1353
+ const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree14.getEnv);
1354
+ return {
1355
+ /** GET Company/Get – fetch this company */
1356
+ async get() {
1357
+ const res = await reqGet("/Company/Get", { company_key: self.companyKey });
1358
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree14.applySnapshot)(self, mapFromApi4(res.data));
1359
+ return res;
1360
+ },
1361
+ /** POST Company/Save – save this company */
1362
+ async save() {
1363
+ const payload = toPayload3(self);
1364
+ const res = await reqPost("/Company/Save", payload);
1365
+ if (res.status === "success" && res.data) (0, import_mobx_state_tree14.applySnapshot)(self, mapFromApi4(res.data));
1366
+ return res;
1367
+ }
1368
+ };
1369
+ });
1370
+ function mapFromApi4(d) {
1371
+ if (!d) return d;
1372
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1373
+ return {
1374
+ companyKey: String(pick("companyKey", "CompanyKey", "company_key") ?? ""),
1375
+ companyName: pick("companyName", "CompanyName", "company_name") ?? "",
1376
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1377
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1378
+ };
1379
+ }
1380
+ function toPayload3(self) {
1381
+ return {
1382
+ companyKey: self.companyKey,
1383
+ companyName: self.companyName ?? void 0
1384
+ };
1385
+ }
1386
+ CompanyModel.get = async (companyKey) => {
1387
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1388
+ const res = await reqGet("/Company/Get", { company_key: companyKey });
1389
+ if (res.status === "success" && res.data) {
1390
+ return CompanyModel.create(mapFromApi4(res.data), { env: getConfig() });
1391
+ }
1392
+ return null;
1393
+ };
1394
+ CompanyModel.getAll = async () => {
1395
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1396
+ const res = await reqGet("/Company/All");
1397
+ if (res.status === "success" && Array.isArray(res.data)) {
1398
+ return res.data.map((c) => CompanyModel.create(mapFromApi4(c), { env: getConfig() }));
1399
+ }
1400
+ return null;
1401
+ };
1402
+ CompanyModel.save = async (payload) => {
1403
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1404
+ const res = await reqPost("/Company/Save", payload);
1405
+ if (res.status === "success" && res.data) {
1406
+ return CompanyModel.create(mapFromApi4(res.data), { env: getConfig() });
1407
+ }
1408
+ return null;
1409
+ };
1410
+ var Company_default = CompanyModel;
1411
+
1412
+ // src/models/appointment/Preference.js
1413
+ var import_mobx_state_tree15 = require("mobx-state-tree");
1414
+ var PreferenceScope = {
1415
+ Global: 0,
1416
+ Consumer: 1,
1417
+ Company: 2,
1418
+ Calendar: 3,
1419
+ Event: 4
1420
+ };
1421
+ var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event"];
1422
+ var PreferenceModel = import_mobx_state_tree15.types.model("Preference", {
1423
+ id: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.maybeNull(import_mobx_state_tree15.types.number), null),
1424
+ preferenceId: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.maybeNull(import_mobx_state_tree15.types.string), null),
1425
+ level: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.number, 0),
1426
+ primaryKey: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.string, ""),
1427
+ preferenceOption: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.string, ""),
1428
+ optionsJson: import_mobx_state_tree15.types.optional(import_mobx_state_tree15.types.maybeNull(import_mobx_state_tree15.types.string), null)
1080
1429
  }).actions((self) => ({
1081
- getApi() {
1082
- return (0, import_mobx_state_tree11.getEnv)(self).api;
1430
+ /** POST /preference/{scope}/{key}/{option} – save this preference to the API. */
1431
+ async save() {
1432
+ const scope = SCOPE_NAMES[self.level] ?? "Global";
1433
+ return PreferenceModel.set(scope, self.primaryKey, self.preferenceOption, self.optionsJson ?? "{}");
1083
1434
  },
1435
+ /** GET /preference/remove?preference_id={id} – remove this preference from the API. Requires preferenceId from a prior get. */
1436
+ async delete() {
1437
+ if (!self.preferenceId) throw new Error("preferenceId required for delete; use PreferenceModel.delete(preferenceId) or load preference from get first.");
1438
+ return PreferenceModel.delete(self.preferenceId);
1439
+ }
1440
+ }));
1441
+ PreferenceModel.getScopes = async () => {
1442
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1443
+ const res = await reqGet("/preference/scopes");
1444
+ return res.status === "success" && res.data != null ? res.data : null;
1445
+ };
1446
+ PreferenceModel.getOptions = async () => {
1447
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1448
+ const res = await reqGet("/preference/options");
1449
+ return res.status === "success" && res.data != null ? res.data : null;
1450
+ };
1451
+ PreferenceModel.getOptionTemplate = async (option) => {
1452
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1453
+ const res = await reqGet(`/preference/options/${encodeURIComponent(option)}`);
1454
+ return res.status === "success" && res.data != null ? res.data : null;
1455
+ };
1456
+ PreferenceModel.get = async (option, keys) => {
1457
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1458
+ const keysArr = Array.isArray(keys) ? keys : keys != null ? [String(keys)] : [];
1459
+ const query = keysArr.length ? { keys: keysArr } : {};
1460
+ const res = await reqGet(`/preference/${encodeURIComponent(option)}`, query);
1461
+ return res.status === "success" && res.data != null ? res.data : null;
1462
+ };
1463
+ PreferenceModel.set = async (scope, key, option, body) => {
1464
+ const { req } = createRequestHelpersFromEnv(getConfig());
1465
+ const path = `/preference/${encodeURIComponent(scope)}/${encodeURIComponent(key)}/${encodeURIComponent(option)}`;
1466
+ const payload = typeof body === "string" ? body : JSON.stringify(body ?? {});
1467
+ return req(path, { method: "POST", body: payload });
1468
+ };
1469
+ PreferenceModel.delete = async (preferenceId) => {
1470
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1471
+ return reqGet("/preference/remove", { preference_id: preferenceId });
1472
+ };
1473
+ var Preference_default = PreferenceModel;
1474
+
1475
+ // src/models/appointment/index.js
1476
+ var import_mobx_state_tree16 = require("mobx-state-tree");
1477
+ var RootStore = import_mobx_state_tree16.types.model("RootStore", {
1478
+ calendars: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.map(Calendar_default), {}),
1479
+ events: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.map(Event_default), {})
1480
+ }).actions((self) => ({
1084
1481
  addCalendar(snapshot) {
1085
1482
  const cal = Calendar_default.create(snapshot);
1086
1483
  self.calendars.set(cal.calendarId, cal);
@@ -1092,24 +1489,38 @@ var RootStore = import_mobx_state_tree11.types.model("RootStore", {
1092
1489
  return ev;
1093
1490
  }
1094
1491
  }));
1492
+ function createRootStore(initialState = {}) {
1493
+ const env = getConfig();
1494
+ if (!env) throw new Error("Call configure({ baseUrl }) before createRootStore()");
1495
+ return RootStore.create(initialState, { env });
1496
+ }
1095
1497
  // Annotate the CommonJS export names for ESM import in node:
1096
1498
  0 && (module.exports = {
1097
- AppointmentClient,
1098
1499
  AssignmentMethod,
1099
1500
  AttendeeStatus,
1100
1501
  AvailabilityDetailModel,
1101
1502
  AvailabilityModel,
1503
+ CalendarDayModel,
1102
1504
  CalendarModel,
1103
1505
  CalendarParticipantModel,
1506
+ CompanyModel,
1507
+ ConfigModel,
1104
1508
  DayOfWeek,
1105
1509
  EventModel,
1106
1510
  OpeningHourModel,
1511
+ ParticipantInfoModel,
1107
1512
  ParticipantModel,
1513
+ PreferenceModel,
1514
+ PreferenceScope,
1108
1515
  RecurringFrequency,
1109
1516
  RootStore,
1110
1517
  SettingModel,
1111
1518
  TimeFrameModel,
1112
1519
  TimeSlotModel,
1113
1520
  Unit,
1114
- mapCreateEventInputToEvent
1521
+ configure,
1522
+ createRootStore,
1523
+ getConfig,
1524
+ getConfigStore,
1525
+ setBaseUrl
1115
1526
  });