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