@blazeo.com/calendar-client 1.0.9 → 1.0.10

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,5 +1,5 @@
1
1
  // src/models/appointment/Calendar.js
2
- import { types as types7, getEnv as getEnv2, applySnapshot as applySnapshot2 } from "mobx-state-tree";
2
+ import { types as types8, getEnv as getEnv2, applySnapshot as applySnapshot2 } from "mobx-state-tree";
3
3
 
4
4
  // src/ConfigModel.js
5
5
  import { types } from "mobx-state-tree";
@@ -173,7 +173,7 @@ var DayOfWeek = {
173
173
  };
174
174
 
175
175
  // src/models/appointment/Event.js
176
- import { types as types3, getEnv, applySnapshot } from "mobx-state-tree";
176
+ import { types as types4, getEnv, applySnapshot } from "mobx-state-tree";
177
177
 
178
178
  // src/models/appointment/TimeSlot.js
179
179
  import { types as types2 } from "mobx-state-tree";
@@ -201,38 +201,92 @@ var TimeSlotModel = types2.model("TimeSlot", {
201
201
  }));
202
202
  var TimeSlot_default = TimeSlotModel;
203
203
 
204
+ // src/models/appointment/TimeFrame.js
205
+ import { types as types3 } from "mobx-state-tree";
206
+ var TimeFrameModel = types3.model("TimeFrame", {
207
+ start: types3.string,
208
+ end: types3.string
209
+ }).actions((self) => ({
210
+ buffer(bufferMinutes, unit) {
211
+ const bfr = unit === Unit.Hours ? bufferMinutes * 60 : bufferMinutes;
212
+ const s = new Date(self.start);
213
+ const e = new Date(self.end);
214
+ s.setMinutes(s.getMinutes() - bfr);
215
+ e.setMinutes(e.getMinutes() + bfr);
216
+ self.start = s.toISOString();
217
+ self.end = e.toISOString();
218
+ },
219
+ conflicts(start, end) {
220
+ const thisStart = new Date(self.start).getTime();
221
+ const thisEnd = new Date(self.end).getTime();
222
+ const startT = start.getTime();
223
+ const endT = end.getTime();
224
+ return startT >= thisStart && startT <= thisEnd || endT >= thisStart && endT <= thisEnd || startT <= thisStart && endT >= thisEnd;
225
+ },
226
+ breakIntoSlots(slotDurationMinutes) {
227
+ const start = new Date(self.start);
228
+ const end = new Date(self.end);
229
+ const slots = [];
230
+ let current = new Date(start);
231
+ const align = (m) => {
232
+ if (m === 0 || m === 15 || m === 30 || m === 45) return m;
233
+ if (m > 0 && m < 15) return 15;
234
+ if (m > 15 && m < 30) return 30;
235
+ if (m > 30 && m < 45) return 45;
236
+ return 0;
237
+ };
238
+ current.setMinutes(align(current.getMinutes()), 0, 0);
239
+ let slotEnd = new Date(current.getTime());
240
+ slotEnd.setMinutes(slotEnd.getMinutes() + slotDurationMinutes);
241
+ while (slotEnd.getTime() <= end.getTime()) {
242
+ slots.push({
243
+ startHour: current.getHours(),
244
+ startMinute: current.getMinutes(),
245
+ endHour: slotEnd.getHours(),
246
+ endMinute: slotEnd.getMinutes(),
247
+ startDate: current.toISOString(),
248
+ endDate: slotEnd.toISOString()
249
+ });
250
+ current = new Date(slotEnd.getTime());
251
+ slotEnd.setMinutes(slotEnd.getMinutes() + slotDurationMinutes);
252
+ }
253
+ return slots;
254
+ }
255
+ }));
256
+ var TimeFrame_default = TimeFrameModel;
257
+
204
258
  // src/models/appointment/Event.js
205
259
  function getDefaultOffset() {
206
260
  var _a;
207
261
  const cfg = getConfig();
208
262
  return ((_a = cfg == null ? void 0 : cfg.getDefaultOffset) == null ? void 0 : _a.call(cfg)) ?? -(/* @__PURE__ */ new Date()).getTimezoneOffset();
209
263
  }
210
- var EventModel = types3.model("Event", {
211
- id: types3.optional(types3.maybeNull(types3.number), null),
212
- eventId: types3.identifier,
213
- calendarId: types3.optional(types3.string, ""),
214
- participantId: types3.optional(types3.maybeNull(types3.string), null),
215
- title: types3.optional(types3.maybeNull(types3.string), null),
216
- description: types3.optional(types3.maybeNull(types3.string), null),
217
- isRecurring: types3.optional(types3.boolean, false),
218
- recurringFrequency: types3.optional(types3.number, RecurringFrequency.None),
219
- startDate: types3.optional(types3.string, ""),
220
- endDate: types3.optional(types3.string, ""),
221
- startHour: types3.optional(types3.number, 0),
222
- startMinute: types3.optional(types3.number, 0),
223
- endHour: types3.optional(types3.number, 0),
224
- endMinute: types3.optional(types3.number, 0),
225
- visitorName: types3.optional(types3.maybeNull(types3.string), null),
226
- visitorEmail: types3.optional(types3.maybeNull(types3.string), null),
227
- visitorPhone: types3.optional(types3.maybeNull(types3.string), null),
228
- createdOn: types3.optional(types3.maybeNull(types3.string), null),
229
- modifiedOn: types3.optional(types3.maybeNull(types3.string), null),
230
- externalEventId: types3.optional(types3.maybeNull(types3.string), null),
231
- attendeeStatus: types3.optional(types3.number, AttendeeStatus.Tentative),
232
- rescheduleLink: types3.optional(types3.maybeNull(types3.string), null),
233
- cancelLink: types3.optional(types3.maybeNull(types3.string), null),
234
- timeZone: types3.optional(types3.maybeNull(types3.string), null),
235
- offset: types3.optional(types3.number, 0)
264
+ var EventModel = types4.model("Event", {
265
+ id: types4.optional(types4.maybeNull(types4.number), null),
266
+ eventId: types4.identifier,
267
+ calendarId: types4.optional(types4.string, ""),
268
+ participantId: types4.optional(types4.maybeNull(types4.string), null),
269
+ title: types4.optional(types4.maybeNull(types4.string), null),
270
+ description: types4.optional(types4.maybeNull(types4.string), null),
271
+ isRecurring: types4.optional(types4.boolean, false),
272
+ recurringFrequency: types4.optional(types4.number, RecurringFrequency.None),
273
+ startDate: types4.optional(types4.string, ""),
274
+ endDate: types4.optional(types4.string, ""),
275
+ startHour: types4.optional(types4.number, 0),
276
+ startMinute: types4.optional(types4.number, 0),
277
+ endHour: types4.optional(types4.number, 0),
278
+ endMinute: types4.optional(types4.number, 0),
279
+ visitorName: types4.optional(types4.maybeNull(types4.string), null),
280
+ visitorEmail: types4.optional(types4.maybeNull(types4.string), null),
281
+ visitorPhone: types4.optional(types4.maybeNull(types4.string), null),
282
+ createdOn: types4.optional(types4.maybeNull(types4.string), null),
283
+ modifiedOn: types4.optional(types4.maybeNull(types4.string), null),
284
+ externalEventId: types4.optional(types4.maybeNull(types4.string), null),
285
+ attendeeStatus: types4.optional(types4.number, AttendeeStatus.Tentative),
286
+ rescheduleLink: types4.optional(types4.maybeNull(types4.string), null),
287
+ cancelLink: types4.optional(types4.maybeNull(types4.string), null),
288
+ timeZone: types4.optional(types4.maybeNull(types4.string), null),
289
+ offset: types4.optional(types4.number, 0)
236
290
  }).actions((self) => {
237
291
  const { req, reqGet, reqPost } = createRequestHelpers(self, getEnv);
238
292
  const getOffset = () => {
@@ -505,6 +559,32 @@ EventModel.getAvailability = async (calendarId, year, month, day, opts = {}) =>
505
559
  }
506
560
  return [];
507
561
  };
562
+ EventModel.getExternalUnavailability = async (participantId, opts = {}) => {
563
+ if (!participantId) throw new Error("participantId required");
564
+ const { req } = createRequestHelpersFromEnv(getConfig());
565
+ const query = { participant_id: participantId };
566
+ if (opts.startUtc && opts.endUtc) {
567
+ query.start_utc = opts.startUtc;
568
+ query.end_utc = opts.endUtc;
569
+ } else {
570
+ if (opts.year == null || opts.month == null || opts.day == null) {
571
+ throw new Error("Provide startUtc/endUtc or year/month/day");
572
+ }
573
+ query.year = opts.year;
574
+ query.month = opts.month;
575
+ query.day = opts.day;
576
+ if (opts.days != null) query.days = opts.days;
577
+ }
578
+ const offset = opts.offset ?? getDefaultOffset();
579
+ const res = await req("/externalcalendar/unavailability/get", { method: "GET", query, headers: { offset: String(offset) } });
580
+ if (res.status === "success" && Array.isArray(res.data)) {
581
+ return res.data.map((f) => TimeFrame_default.create({
582
+ start: f.start ?? f.Start,
583
+ end: f.end ?? f.End
584
+ }));
585
+ }
586
+ return [];
587
+ };
508
588
  EventModel.cancel = async (eventId) => {
509
589
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
510
590
  return reqGet("/event/cancel", { event_id: eventId });
@@ -567,29 +647,29 @@ EventModel.setAttendeeStatus = async (eventId, attendeeStatus) => {
567
647
  var Event_default = EventModel;
568
648
 
569
649
  // src/models/appointment/CalendarParticipant.js
570
- import { types as types5 } from "mobx-state-tree";
650
+ import { types as types6 } from "mobx-state-tree";
571
651
 
572
652
  // src/models/appointment/ParticipantInfo.js
573
- import { types as types4 } from "mobx-state-tree";
574
- var ParticipantInfoModel = types4.model("ParticipantInfo", {
575
- participantId: types4.optional(types4.string, ""),
576
- calendarParticipantId: types4.optional(types4.string, ""),
577
- alias: types4.maybeNull(types4.string),
578
- email: types4.maybeNull(types4.string),
579
- isApproved: types4.optional(types4.boolean, false),
580
- emailProvider: types4.optional(types4.number, 0),
581
- isAvailable: types4.optional(types4.boolean, false)
653
+ import { types as types5 } from "mobx-state-tree";
654
+ var ParticipantInfoModel = types5.model("ParticipantInfo", {
655
+ participantId: types5.optional(types5.string, ""),
656
+ calendarParticipantId: types5.optional(types5.string, ""),
657
+ alias: types5.maybeNull(types5.string),
658
+ email: types5.maybeNull(types5.string),
659
+ isApproved: types5.optional(types5.boolean, false),
660
+ emailProvider: types5.optional(types5.number, 0),
661
+ isAvailable: types5.optional(types5.boolean, false)
582
662
  });
583
663
  var ParticipantInfo_default = ParticipantInfoModel;
584
664
 
585
665
  // src/models/appointment/CalendarParticipant.js
586
- var CalendarParticipantModel = types5.model("CalendarParticipant", {
587
- id: types5.optional(types5.maybeNull(types5.number), null),
588
- calendarParticipantId: types5.optional(types5.string, ""),
589
- participantId: types5.optional(types5.string, ""),
590
- calendarId: types5.optional(types5.string, ""),
591
- createdOn: types5.optional(types5.maybeNull(types5.string), null),
592
- modifiedOn: types5.optional(types5.maybeNull(types5.string), null)
666
+ var CalendarParticipantModel = types6.model("CalendarParticipant", {
667
+ id: types6.optional(types6.maybeNull(types6.number), null),
668
+ calendarParticipantId: types6.optional(types6.string, ""),
669
+ participantId: types6.optional(types6.string, ""),
670
+ calendarId: types6.optional(types6.string, ""),
671
+ createdOn: types6.optional(types6.maybeNull(types6.string), null),
672
+ modifiedOn: types6.optional(types6.maybeNull(types6.string), null)
593
673
  });
594
674
  function mapFromApi(d) {
595
675
  if (!d) return d;
@@ -642,36 +722,36 @@ CalendarParticipantModel.getByParticipant = async (participantId) => {
642
722
  var CalendarParticipant_default = CalendarParticipantModel;
643
723
 
644
724
  // src/models/appointment/CalendarDay.js
645
- import { types as types6 } from "mobx-state-tree";
646
- var CalendarDayModel = types6.model("CalendarDay", {
647
- date: types6.optional(types6.string, "")
725
+ import { types as types7 } from "mobx-state-tree";
726
+ var CalendarDayModel = types7.model("CalendarDay", {
727
+ date: types7.optional(types7.string, "")
648
728
  });
649
729
  var CalendarDay_default = CalendarDayModel;
650
730
 
651
731
  // src/models/appointment/Calendar.js
652
- var CalendarModel = types7.model("Calendar", {
653
- id: types7.maybeNull(types7.number),
654
- companyKey: types7.maybeNull(types7.string),
655
- calendarId: types7.optional(types7.identifier, "new"),
656
- name: types7.maybeNull(types7.string),
732
+ var CalendarModel = types8.model("Calendar", {
733
+ id: types8.maybeNull(types8.number),
734
+ companyKey: types8.maybeNull(types8.string),
735
+ calendarId: types8.optional(types8.identifier, "new"),
736
+ name: types8.maybeNull(types8.string),
657
737
  // location: types.maybeNull(types.string),
658
- timeZoneId: types7.maybeNull(types7.string),
659
- purpose: types7.optional(types7.string, ""),
660
- description: types7.maybeNull(types7.string),
661
- assignmentMethod: types7.optional(types7.number, AssignmentMethod.RoundRobin),
662
- duration: types7.optional(types7.number, 0),
663
- durationUnit: types7.optional(types7.number, Unit.Minutes),
664
- minimumBookingNotice: types7.optional(types7.number, 0),
665
- minimumBookingNoticeUnit: types7.optional(types7.number, Unit.Minutes),
666
- minimumCancelationNotice: types7.optional(types7.number, 0),
667
- minimumCancelationNoticeUnit: types7.optional(types7.number, Unit.Minutes),
668
- futureLimit: types7.optional(types7.number, 0),
669
- futureLimitUnit: types7.optional(types7.number, Unit.Days),
670
- bufferTime: types7.optional(types7.number, 0),
671
- bufferTimeUnit: types7.optional(types7.number, Unit.Minutes),
672
- bookingLimit: types7.optional(types7.number, 0),
673
- createdOn: types7.maybeNull(types7.string),
674
- modifiedOn: types7.maybeNull(types7.string)
738
+ timeZoneId: types8.maybeNull(types8.string),
739
+ purpose: types8.optional(types8.string, ""),
740
+ description: types8.maybeNull(types8.string),
741
+ assignmentMethod: types8.optional(types8.number, AssignmentMethod.RoundRobin),
742
+ duration: types8.optional(types8.number, 0),
743
+ durationUnit: types8.optional(types8.number, Unit.Minutes),
744
+ minimumBookingNotice: types8.optional(types8.number, 0),
745
+ minimumBookingNoticeUnit: types8.optional(types8.number, Unit.Minutes),
746
+ minimumCancelationNotice: types8.optional(types8.number, 0),
747
+ minimumCancelationNoticeUnit: types8.optional(types8.number, Unit.Minutes),
748
+ futureLimit: types8.optional(types8.number, 0),
749
+ futureLimitUnit: types8.optional(types8.number, Unit.Days),
750
+ bufferTime: types8.optional(types8.number, 0),
751
+ bufferTimeUnit: types8.optional(types8.number, Unit.Minutes),
752
+ bookingLimit: types8.optional(types8.number, 0),
753
+ createdOn: types8.maybeNull(types8.string),
754
+ modifiedOn: types8.maybeNull(types8.string)
675
755
  }).actions((self) => {
676
756
  const { req, reqGet, reqPost } = createRequestHelpers(self, getEnv2);
677
757
  return {
@@ -810,9 +890,25 @@ var CalendarModel = types7.model("Calendar", {
810
890
  if (!self.calendarId) return { status: "failure", message: "calendarId required" };
811
891
  return reqGet("/Calendar/Participants/GetInfo", { calendar_id: self.calendarId });
812
892
  },
813
- /** GET Calendar/All – calendars by company_key */
814
- async getByCompany(companyKey) {
815
- return reqGet("/Calendar/All", { company_key: companyKey || self.companyKey });
893
+ /** GET Calendar/All – calendars by company_key with paging options */
894
+ async getByCompany(companyKey, opts = {}) {
895
+ const resolvedCompanyKey = companyKey || self.companyKey;
896
+ const q = { company_key: resolvedCompanyKey };
897
+ const sortBy = opts.sortBy ?? opts.sort ?? opts.sort_column;
898
+ if (sortBy != null && sortBy !== "") q.sort = sortBy;
899
+ const sortOrderRaw = opts.sortOrder ?? opts.sort_dir;
900
+ if (sortOrderRaw != null && String(sortOrderRaw).trim() !== "") {
901
+ const u = String(sortOrderRaw).trim().toUpperCase();
902
+ q.sort_dir = u.startsWith("DESC") ? "desc" : "asc";
903
+ }
904
+ if (opts.page != null) {
905
+ q.page = opts.page;
906
+ if (opts.page_size != null) q.page_size = opts.page_size;
907
+ } else {
908
+ if (opts.skip != null) q.skip = opts.skip;
909
+ if (opts.take != null) q.take = opts.take;
910
+ }
911
+ return reqGet("/Calendar/All", q);
816
912
  },
817
913
  /** GET Calendar/TimeZones/Get */
818
914
  async getTimeZones() {
@@ -887,13 +983,34 @@ CalendarModel.get = async (calendarId) => {
887
983
  }
888
984
  return null;
889
985
  };
890
- CalendarModel.getByCompany = async (companyKey) => {
986
+ CalendarModel.getByCompany = async (companyKey, opts = {}) => {
987
+ var _a, _b, _c, _d;
891
988
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
892
- const res = await reqGet("/Calendar/All", { company_key: companyKey });
893
- if (res.status === "success" && Array.isArray(res.data)) {
894
- return res.data.map(
895
- (c) => CalendarModel.create(mapCalendarFromApi(c), { env: getConfig() })
896
- );
989
+ const query = { company_key: companyKey };
990
+ const sortBy = opts.sortBy ?? opts.sort ?? opts.sort_column;
991
+ if (sortBy != null && sortBy !== "") query.sort = sortBy;
992
+ const sortOrderRaw = opts.sortOrder ?? opts.sort_dir;
993
+ if (sortOrderRaw != null && String(sortOrderRaw).trim() !== "") {
994
+ const u = String(sortOrderRaw).trim().toUpperCase();
995
+ query.sort_dir = u.startsWith("DESC") ? "desc" : "asc";
996
+ }
997
+ if (opts.page != null) {
998
+ query.page = opts.page;
999
+ if (opts.page_size != null) query.page_size = opts.page_size;
1000
+ } else {
1001
+ if (opts.skip != null) query.skip = opts.skip;
1002
+ if (opts.take != null) query.take = opts.take;
1003
+ }
1004
+ const res = await reqGet("/Calendar/All", query);
1005
+ if (res.status === "success") {
1006
+ const calendarsRaw = Array.isArray(res.data) ? res.data : Array.isArray((_a = res.data) == null ? void 0 : _a.Calendars) ? res.data.Calendars : Array.isArray((_b = res.data) == null ? void 0 : _b.calendars) ? res.data.calendars : null;
1007
+ if (calendarsRaw) {
1008
+ const calendars = calendarsRaw.map(
1009
+ (c) => CalendarModel.create(mapCalendarFromApi(c), { env: getConfig() })
1010
+ );
1011
+ const totalCount = Number(((_c = res.data) == null ? void 0 : _c.TotalCount) ?? ((_d = res.data) == null ? void 0 : _d.totalCount) ?? calendars.length);
1012
+ return { calendars, totalCount };
1013
+ }
897
1014
  }
898
1015
  return null;
899
1016
  };
@@ -1013,52 +1130,52 @@ CalendarModel.editWithParticipants = async (calendarId, name, participantIds, de
1013
1130
  var Calendar_default = CalendarModel;
1014
1131
 
1015
1132
  // src/models/appointment/Availability.js
1016
- import { types as types8 } from "mobx-state-tree";
1017
- var AvailabilityModel = types8.model("Availability", {
1018
- id: types8.maybeNull(types8.number),
1019
- availabilityId: types8.string,
1020
- calendarId: types8.string,
1021
- participantId: types8.string,
1022
- createdOn: types8.maybeNull(types8.string),
1023
- modifiedOn: types8.maybeNull(types8.string)
1024
- });
1025
- var Availability_default = AvailabilityModel;
1026
-
1027
- // src/models/appointment/AvailabilityDetail.js
1028
1133
  import { types as types9 } from "mobx-state-tree";
1029
- var AvailabilityDetailModel = types9.model("AvailabilityDetail", {
1134
+ var AvailabilityModel = types9.model("Availability", {
1030
1135
  id: types9.maybeNull(types9.number),
1031
1136
  availabilityId: types9.string,
1032
- sunday: types9.optional(types9.boolean, false),
1033
- monday: types9.optional(types9.boolean, false),
1034
- tuesday: types9.optional(types9.boolean, false),
1035
- wednesday: types9.optional(types9.boolean, false),
1036
- thursday: types9.optional(types9.boolean, false),
1037
- friday: types9.optional(types9.boolean, false),
1038
- saturday: types9.optional(types9.boolean, false),
1039
- startHour: types9.optional(types9.number, 0),
1040
- startMinute: types9.optional(types9.number, 0),
1041
- endHour: types9.optional(types9.number, 0),
1042
- endMinute: types9.optional(types9.number, 0),
1137
+ calendarId: types9.string,
1138
+ participantId: types9.string,
1043
1139
  createdOn: types9.maybeNull(types9.string),
1044
1140
  modifiedOn: types9.maybeNull(types9.string)
1045
1141
  });
1142
+ var Availability_default = AvailabilityModel;
1143
+
1144
+ // src/models/appointment/AvailabilityDetail.js
1145
+ import { types as types10 } from "mobx-state-tree";
1146
+ var AvailabilityDetailModel = types10.model("AvailabilityDetail", {
1147
+ id: types10.maybeNull(types10.number),
1148
+ availabilityId: types10.string,
1149
+ sunday: types10.optional(types10.boolean, false),
1150
+ monday: types10.optional(types10.boolean, false),
1151
+ tuesday: types10.optional(types10.boolean, false),
1152
+ wednesday: types10.optional(types10.boolean, false),
1153
+ thursday: types10.optional(types10.boolean, false),
1154
+ friday: types10.optional(types10.boolean, false),
1155
+ saturday: types10.optional(types10.boolean, false),
1156
+ startHour: types10.optional(types10.number, 0),
1157
+ startMinute: types10.optional(types10.number, 0),
1158
+ endHour: types10.optional(types10.number, 0),
1159
+ endMinute: types10.optional(types10.number, 0),
1160
+ createdOn: types10.maybeNull(types10.string),
1161
+ modifiedOn: types10.maybeNull(types10.string)
1162
+ });
1046
1163
  var AvailabilityDetail_default = AvailabilityDetailModel;
1047
1164
 
1048
1165
  // src/models/appointment/Participant.js
1049
- import { types as types10, getEnv as getEnv3, applySnapshot as applySnapshot3 } from "mobx-state-tree";
1050
- var ParticipantModel = types10.model("Participant", {
1051
- id: types10.optional(types10.maybeNull(types10.number), null),
1052
- participantId: types10.identifier,
1053
- companyKey: types10.optional(types10.maybeNull(types10.string), null),
1054
- alias: types10.optional(types10.string, ""),
1055
- email: types10.optional(types10.string, ""),
1056
- isApproved: types10.optional(types10.boolean, false),
1057
- isAvailable: types10.optional(types10.boolean, false),
1058
- provider: types10.optional(types10.number, 0),
1059
- createdOn: types10.optional(types10.maybeNull(types10.string), null),
1060
- modifiedOn: types10.optional(types10.maybeNull(types10.string), null),
1061
- isDeleted: types10.optional(types10.boolean, false)
1166
+ import { types as types11, getEnv as getEnv3, applySnapshot as applySnapshot3 } from "mobx-state-tree";
1167
+ var ParticipantModel = types11.model("Participant", {
1168
+ id: types11.optional(types11.maybeNull(types11.number), null),
1169
+ participantId: types11.identifier,
1170
+ companyKey: types11.optional(types11.maybeNull(types11.string), null),
1171
+ alias: types11.optional(types11.string, ""),
1172
+ email: types11.optional(types11.string, ""),
1173
+ isApproved: types11.optional(types11.boolean, false),
1174
+ isAvailable: types11.optional(types11.boolean, false),
1175
+ provider: types11.optional(types11.number, 0),
1176
+ createdOn: types11.optional(types11.maybeNull(types11.string), null),
1177
+ modifiedOn: types11.optional(types11.maybeNull(types11.string), null),
1178
+ isDeleted: types11.optional(types11.boolean, false)
1062
1179
  }).actions((self) => {
1063
1180
  const { reqGet, reqPost } = createRequestHelpers(self, getEnv3);
1064
1181
  return {
@@ -1089,6 +1206,37 @@ var ParticipantModel = types10.model("Participant", {
1089
1206
  /** GET participant/sendemail – send email to this participant */
1090
1207
  async sendEmail() {
1091
1208
  return reqGet("/participant/sendemail", { participant_id: self.participantId });
1209
+ },
1210
+ /** GET participant/calendars/get – calendars for this participant (paged) */
1211
+ async getCalendars(opts = {}) {
1212
+ var _a, _b, _c, _d;
1213
+ const q = { participant_id: self.participantId };
1214
+ const sortBy = opts.sortBy ?? opts.sort ?? opts.sort_column;
1215
+ if (sortBy != null && sortBy !== "") q.sort = sortBy;
1216
+ const sortOrderRaw = opts.sortOrder ?? opts.sort_dir;
1217
+ if (sortOrderRaw != null && String(sortOrderRaw).trim() !== "") {
1218
+ const u = String(sortOrderRaw).trim().toUpperCase();
1219
+ q.sort_dir = u.startsWith("DESC") ? "desc" : "asc";
1220
+ }
1221
+ if (opts.page != null) {
1222
+ q.page = opts.page;
1223
+ if (opts.page_size != null) q.page_size = opts.page_size;
1224
+ } else {
1225
+ if (opts.skip != null) q.skip = opts.skip;
1226
+ if (opts.take != null) q.take = opts.take;
1227
+ }
1228
+ const res = await reqGet("/participant/calendars/get", q);
1229
+ if (res.status === "success") {
1230
+ const calendarsRaw = Array.isArray(res.data) ? res.data : Array.isArray((_a = res.data) == null ? void 0 : _a.Calendars) ? res.data.Calendars : Array.isArray((_b = res.data) == null ? void 0 : _b.calendars) ? res.data.calendars : null;
1231
+ if (calendarsRaw) {
1232
+ const calendars = calendarsRaw.map(
1233
+ (c) => Calendar_default.create(mapCalendarFromApi2(c), { env: getConfig() })
1234
+ );
1235
+ const totalCount = Number(((_c = res.data) == null ? void 0 : _c.TotalCount) ?? ((_d = res.data) == null ? void 0 : _d.totalCount) ?? calendars.length);
1236
+ return { calendars, totalCount };
1237
+ }
1238
+ }
1239
+ return null;
1092
1240
  }
1093
1241
  };
1094
1242
  });
@@ -1120,6 +1268,34 @@ function toPayload(self) {
1120
1268
  provider: self.provider
1121
1269
  };
1122
1270
  }
1271
+ function mapCalendarFromApi2(d) {
1272
+ if (!d) return d;
1273
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1274
+ const n = (v) => v != null && v !== "" ? Number(v) : void 0;
1275
+ return {
1276
+ id: pick("id", "Id"),
1277
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? null,
1278
+ calendarId: String(pick("calendarId", "CalendarId", "calendar_id") ?? ""),
1279
+ name: pick("name", "Name") ?? null,
1280
+ timeZoneId: pick("timeZoneId", "TimeZoneId", "time_zone_id") ?? null,
1281
+ purpose: pick("purpose", "Purpose") ?? "",
1282
+ description: pick("description", "Description") ?? null,
1283
+ assignmentMethod: n(pick("assignmentMethod", "AssignmentMethod", "assignment_method")) ?? void 0,
1284
+ duration: n(pick("duration", "Duration")) ?? void 0,
1285
+ durationUnit: n(pick("durationUnit", "DurationUnit", "duration_unit")) ?? void 0,
1286
+ minimumBookingNotice: n(pick("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")) ?? void 0,
1287
+ minimumBookingNoticeUnit: n(pick("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")) ?? void 0,
1288
+ minimumCancelationNotice: n(pick("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")) ?? void 0,
1289
+ minimumCancelationNoticeUnit: n(pick("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")) ?? void 0,
1290
+ futureLimit: n(pick("futureLimit", "FutureLimit", "future_limit")) ?? void 0,
1291
+ futureLimitUnit: n(pick("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")) ?? void 0,
1292
+ bufferTime: n(pick("bufferTime", "BufferTime", "buffer_time")) ?? void 0,
1293
+ bufferTimeUnit: n(pick("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")) ?? void 0,
1294
+ bookingLimit: n(pick("bookingLimit", "BookingLimit", "booking_limit")) ?? void 0,
1295
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1296
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1297
+ };
1298
+ }
1123
1299
  ParticipantModel.get = async (participantId) => {
1124
1300
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
1125
1301
  const res = await reqGet("/participant/get", { participant_id: participantId });
@@ -1174,80 +1350,57 @@ ParticipantModel.sendEmail = async (participantId) => {
1174
1350
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
1175
1351
  return reqGet("/participant/sendemail", { participant_id: participantId });
1176
1352
  };
1353
+ ParticipantModel.getCalendars = async (participantId, opts = {}) => {
1354
+ var _a, _b, _c, _d;
1355
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1356
+ const q = { participant_id: participantId };
1357
+ const sortBy = opts.sortBy ?? opts.sort ?? opts.sort_column;
1358
+ if (sortBy != null && sortBy !== "") q.sort = sortBy;
1359
+ const sortOrderRaw = opts.sortOrder ?? opts.sort_dir;
1360
+ if (sortOrderRaw != null && String(sortOrderRaw).trim() !== "") {
1361
+ const u = String(sortOrderRaw).trim().toUpperCase();
1362
+ q.sort_dir = u.startsWith("DESC") ? "desc" : "asc";
1363
+ }
1364
+ if (opts.page != null) {
1365
+ q.page = opts.page;
1366
+ if (opts.page_size != null) q.page_size = opts.page_size;
1367
+ } else {
1368
+ if (opts.skip != null) q.skip = opts.skip;
1369
+ if (opts.take != null) q.take = opts.take;
1370
+ }
1371
+ const res = await reqGet("/participant/calendars/get", q);
1372
+ if (res.status === "success") {
1373
+ const calendarsRaw = Array.isArray(res.data) ? res.data : Array.isArray((_a = res.data) == null ? void 0 : _a.Calendars) ? res.data.Calendars : Array.isArray((_b = res.data) == null ? void 0 : _b.calendars) ? res.data.calendars : null;
1374
+ if (calendarsRaw) {
1375
+ const calendars = calendarsRaw.map(
1376
+ (c) => Calendar_default.create(mapCalendarFromApi2(c), { env: getConfig() })
1377
+ );
1378
+ const totalCount = Number(((_c = res.data) == null ? void 0 : _c.TotalCount) ?? ((_d = res.data) == null ? void 0 : _d.totalCount) ?? calendars.length);
1379
+ return { calendars, totalCount };
1380
+ }
1381
+ }
1382
+ return null;
1383
+ };
1177
1384
  var Participant_default = ParticipantModel;
1178
1385
 
1179
1386
  // src/models/appointment/OpeningHour.js
1180
- import { types as types11 } from "mobx-state-tree";
1181
- var OpeningHourModel = types11.model("OpeningHour", {
1182
- id: types11.maybeNull(types11.number),
1183
- openingHourId: types11.optional(types11.string, ""),
1184
- calendarId: types11.string,
1185
- participantId: types11.string,
1186
- day: types11.optional(types11.number, 0),
1187
- startHour: types11.optional(types11.number, 0),
1188
- startMinute: types11.optional(types11.number, 0),
1189
- endHour: types11.optional(types11.number, 0),
1190
- endMinute: types11.optional(types11.number, 0),
1191
- off: types11.optional(types11.boolean, false),
1192
- createdOn: types11.maybeNull(types11.string),
1193
- modifiedOn: types11.maybeNull(types11.string)
1387
+ import { types as types12 } from "mobx-state-tree";
1388
+ var OpeningHourModel = types12.model("OpeningHour", {
1389
+ id: types12.maybeNull(types12.number),
1390
+ openingHourId: types12.optional(types12.string, ""),
1391
+ calendarId: types12.string,
1392
+ participantId: types12.string,
1393
+ day: types12.optional(types12.number, 0),
1394
+ startHour: types12.optional(types12.number, 0),
1395
+ startMinute: types12.optional(types12.number, 0),
1396
+ endHour: types12.optional(types12.number, 0),
1397
+ endMinute: types12.optional(types12.number, 0),
1398
+ off: types12.optional(types12.boolean, false),
1399
+ createdOn: types12.maybeNull(types12.string),
1400
+ modifiedOn: types12.maybeNull(types12.string)
1194
1401
  });
1195
1402
  var OpeningHour_default = OpeningHourModel;
1196
1403
 
1197
- // src/models/appointment/TimeFrame.js
1198
- import { types as types12 } from "mobx-state-tree";
1199
- var TimeFrameModel = types12.model("TimeFrame", {
1200
- start: types12.string,
1201
- end: types12.string
1202
- }).actions((self) => ({
1203
- buffer(bufferMinutes, unit) {
1204
- const bfr = unit === Unit.Hours ? bufferMinutes * 60 : bufferMinutes;
1205
- const s = new Date(self.start);
1206
- const e = new Date(self.end);
1207
- s.setMinutes(s.getMinutes() - bfr);
1208
- e.setMinutes(e.getMinutes() + bfr);
1209
- self.start = s.toISOString();
1210
- self.end = e.toISOString();
1211
- },
1212
- conflicts(start, end) {
1213
- const thisStart = new Date(self.start).getTime();
1214
- const thisEnd = new Date(self.end).getTime();
1215
- const startT = start.getTime();
1216
- const endT = end.getTime();
1217
- return startT >= thisStart && startT <= thisEnd || endT >= thisStart && endT <= thisEnd || startT <= thisStart && endT >= thisEnd;
1218
- },
1219
- breakIntoSlots(slotDurationMinutes) {
1220
- const start = new Date(self.start);
1221
- const end = new Date(self.end);
1222
- const slots = [];
1223
- let current = new Date(start);
1224
- const align = (m) => {
1225
- if (m === 0 || m === 15 || m === 30 || m === 45) return m;
1226
- if (m > 0 && m < 15) return 15;
1227
- if (m > 15 && m < 30) return 30;
1228
- if (m > 30 && m < 45) return 45;
1229
- return 0;
1230
- };
1231
- current.setMinutes(align(current.getMinutes()), 0, 0);
1232
- let slotEnd = new Date(current.getTime());
1233
- slotEnd.setMinutes(slotEnd.getMinutes() + slotDurationMinutes);
1234
- while (slotEnd.getTime() <= end.getTime()) {
1235
- slots.push({
1236
- startHour: current.getHours(),
1237
- startMinute: current.getMinutes(),
1238
- endHour: slotEnd.getHours(),
1239
- endMinute: slotEnd.getMinutes(),
1240
- startDate: current.toISOString(),
1241
- endDate: slotEnd.toISOString()
1242
- });
1243
- current = new Date(slotEnd.getTime());
1244
- slotEnd.setMinutes(slotEnd.getMinutes() + slotDurationMinutes);
1245
- }
1246
- return slots;
1247
- }
1248
- }));
1249
- var TimeFrame_default = TimeFrameModel;
1250
-
1251
1404
  // src/models/appointment/Setting.js
1252
1405
  import { types as types13, getEnv as getEnv4, applySnapshot as applySnapshot4 } from "mobx-state-tree";
1253
1406
  var SettingModel = types13.model("Setting", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazeo.com/calendar-client",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Blazeo Calendar / Appointment API client with MobX State Tree models",
5
5
  "exports": {
6
6
  ".": {