@blazeo.com/appointment-client 1.0.11 → 1.0.14

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.
Files changed (138) hide show
  1. package/blazeo.com-appointment-client-1.0.14.tgz +0 -0
  2. package/package.json +3 -2
  3. package/sample/src/EventTab.jsx +435 -395
  4. package/sample/src/FetchCalendarTab.jsx +19 -33
  5. package/sample/src/LeadTab.jsx +335 -0
  6. package/src/calendar/calendarCreation.ts +62 -15
  7. package/src/calendar/fetchCalendarDetails.ts +10 -2
  8. package/src/calendar/getCalendarsByCompany.ts +17 -64
  9. package/src/calendar/mapToDesiredResponse.ts +31 -17
  10. package/src/events/getAppointmentsByFilter.ts +98 -0
  11. package/src/index.ts +23 -14
  12. package/src/lead/fetchLeadDetails.ts +106 -0
  13. package/blazeo.com-appointment-client-1.0.11.tgz +0 -0
  14. package/dist/calendar/blazeoCalendarRelationMethods.d.ts +0 -8
  15. package/dist/calendar/blazeoCalendarRelationMethods.d.ts.map +0 -1
  16. package/dist/calendar/blazeoCalendarRelationMethods.js +0 -16
  17. package/dist/calendar/blazeoCalendarRelationMethods.js.map +0 -1
  18. package/dist/calendar/buildUnifiedCalendarView.d.ts +0 -39
  19. package/dist/calendar/buildUnifiedCalendarView.js +0 -301
  20. package/dist/calendar/calendarCreation.d.ts +0 -27
  21. package/dist/calendar/calendarCreation.js +0 -191
  22. package/dist/calendar/calendarCreationFacade.d.ts +0 -27
  23. package/dist/calendar/calendarCreationFacade.d.ts.map +0 -1
  24. package/dist/calendar/calendarCreationFacade.js +0 -167
  25. package/dist/calendar/calendarCreationFacade.js.map +0 -1
  26. package/dist/calendar/createCalendar.d.ts +0 -81
  27. package/dist/calendar/createCalendar.d.ts.map +0 -1
  28. package/dist/calendar/createCalendar.js +0 -206
  29. package/dist/calendar/createCalendar.js.map +0 -1
  30. package/dist/calendar/fetchCalendarDetails.d.ts +0 -41
  31. package/dist/calendar/fetchCalendarDetails.js +0 -262
  32. package/dist/calendar/fetchCalendarWithOpeningHours.d.ts +0 -25
  33. package/dist/calendar/fetchCalendarWithOpeningHours.js +0 -114
  34. package/dist/calendar/getAllParticipantOpeningHours.d.ts +0 -22
  35. package/dist/calendar/getAllParticipantOpeningHours.js +0 -22
  36. package/dist/calendar/getCalendarsByCompany.d.ts +0 -9
  37. package/dist/calendar/getCalendarsByCompany.js +0 -107
  38. package/dist/calendar/getOpeningHours.d.ts +0 -8
  39. package/dist/calendar/getOpeningHours.js +0 -9
  40. package/dist/calendar/getParticipantOpeningHours.d.ts +0 -37
  41. package/dist/calendar/getParticipantOpeningHours.js +0 -48
  42. package/dist/calendar/getParticipants.d.ts +0 -7
  43. package/dist/calendar/getParticipants.js +0 -13
  44. package/dist/calendar/mapCalendarBoToBlazeoSnapshot.d.ts +0 -10
  45. package/dist/calendar/mapCalendarBoToBlazeoSnapshot.d.ts.map +0 -1
  46. package/dist/calendar/mapCalendarBoToBlazeoSnapshot.js +0 -44
  47. package/dist/calendar/mapCalendarBoToBlazeoSnapshot.js.map +0 -1
  48. package/dist/calendar/mapCalendarToBlazeoSnapshot.d.ts +0 -29
  49. package/dist/calendar/mapCalendarToBlazeoSnapshot.d.ts.map +0 -1
  50. package/dist/calendar/mapCalendarToBlazeoSnapshot.js +0 -44
  51. package/dist/calendar/mapCalendarToBlazeoSnapshot.js.map +0 -1
  52. package/dist/calendar/mapToDesiredResponse.d.ts +0 -70
  53. package/dist/calendar/mapToDesiredResponse.js +0 -99
  54. package/dist/config/applyBlazeoClientConfig.d.ts +0 -3
  55. package/dist/config/applyBlazeoClientConfig.d.ts.map +0 -1
  56. package/dist/config/applyBlazeoClientConfig.js +0 -14
  57. package/dist/config/applyBlazeoClientConfig.js.map +0 -1
  58. package/dist/config/applyBlazeoDefaults.d.ts +0 -2
  59. package/dist/config/applyBlazeoDefaults.d.ts.map +0 -1
  60. package/dist/config/applyBlazeoDefaults.js +0 -14
  61. package/dist/config/applyBlazeoDefaults.js.map +0 -1
  62. package/dist/config/blazeo.config.d.ts +0 -11
  63. package/dist/config/blazeo.config.d.ts.map +0 -1
  64. package/dist/config/blazeo.config.js +0 -11
  65. package/dist/config/blazeo.config.js.map +0 -1
  66. package/dist/config/blazeoClientDefaults.d.ts +0 -11
  67. package/dist/config/blazeoClientDefaults.d.ts.map +0 -1
  68. package/dist/config/blazeoClientDefaults.js +0 -11
  69. package/dist/config/blazeoClientDefaults.js.map +0 -1
  70. package/dist/config/ensureBlazeoHttpReady.d.ts +0 -17
  71. package/dist/config/ensureBlazeoHttpReady.js +0 -31
  72. package/dist/config/initializeAppointmentClient.d.ts +0 -11
  73. package/dist/config/initializeAppointmentClient.d.ts.map +0 -1
  74. package/dist/config/initializeAppointmentClient.js +0 -15
  75. package/dist/config/initializeAppointmentClient.js.map +0 -1
  76. package/dist/config/syncBlazeoConnection.d.ts +0 -6
  77. package/dist/config/syncBlazeoConnection.js +0 -18
  78. package/dist/events/appointmentEventFacade.d.ts +0 -67
  79. package/dist/events/appointmentEventFacade.d.ts.map +0 -1
  80. package/dist/events/appointmentEventFacade.js +0 -124
  81. package/dist/events/appointmentEventFacade.js.map +0 -1
  82. package/dist/events/mapAppointmentToEventSnapshot.d.ts +0 -5
  83. package/dist/events/mapAppointmentToEventSnapshot.d.ts.map +0 -1
  84. package/dist/events/mapAppointmentToEventSnapshot.js +0 -57
  85. package/dist/events/mapAppointmentToEventSnapshot.js.map +0 -1
  86. package/dist/exampleData.d.ts +0 -119
  87. package/dist/exampleData.d.ts.map +0 -1
  88. package/dist/exampleData.js +0 -71
  89. package/dist/exampleData.js.map +0 -1
  90. package/dist/facade/calendarCreationFacade.d.ts +0 -40
  91. package/dist/facade/calendarCreationFacade.d.ts.map +0 -1
  92. package/dist/facade/calendarCreationFacade.js +0 -96
  93. package/dist/facade/calendarCreationFacade.js.map +0 -1
  94. package/dist/facade/mapCalendarBOToSnapshot.d.ts +0 -10
  95. package/dist/facade/mapCalendarBOToSnapshot.d.ts.map +0 -1
  96. package/dist/facade/mapCalendarBOToSnapshot.js +0 -44
  97. package/dist/facade/mapCalendarBOToSnapshot.js.map +0 -1
  98. package/dist/facades/index.d.ts +0 -12
  99. package/dist/facades/index.d.ts.map +0 -1
  100. package/dist/facades/index.js +0 -12
  101. package/dist/facades/index.js.map +0 -1
  102. package/dist/index.d.ts +0 -40
  103. package/dist/index.d.ts.map +0 -1
  104. package/dist/index.js +0 -39
  105. package/dist/index.js.map +0 -1
  106. package/dist/models/CalendarRootModel.d.ts +0 -56
  107. package/dist/models/CalendarRootModel.d.ts.map +0 -1
  108. package/dist/models/CalendarRootModel.js +0 -54
  109. package/dist/models/CalendarRootModel.js.map +0 -1
  110. package/dist/models/CalendarSlotModel.d.ts +0 -9
  111. package/dist/models/CalendarSlotModel.d.ts.map +0 -1
  112. package/dist/models/CalendarSlotModel.js +0 -8
  113. package/dist/models/CalendarSlotModel.js.map +0 -1
  114. package/dist/models/EventModel.d.ts +0 -11
  115. package/dist/models/EventModel.d.ts.map +0 -1
  116. package/dist/models/EventModel.js +0 -10
  117. package/dist/models/EventModel.js.map +0 -1
  118. package/dist/models/ParticipantModel.d.ts +0 -9
  119. package/dist/models/ParticipantModel.d.ts.map +0 -1
  120. package/dist/models/ParticipantModel.js +0 -8
  121. package/dist/models/ParticipantModel.js.map +0 -1
  122. package/dist/models/index.d.ts +0 -5
  123. package/dist/models/index.d.ts.map +0 -1
  124. package/dist/models/index.js +0 -5
  125. package/dist/models/index.js.map +0 -1
  126. package/dist/types/appointment.d.ts +0 -28
  127. package/dist/types/appointment.d.ts.map +0 -1
  128. package/dist/types/appointment.js +0 -6
  129. package/dist/types/appointment.js.map +0 -1
  130. package/dist/types/calendar.d.ts +0 -52
  131. package/dist/types/calendar.d.ts.map +0 -1
  132. package/dist/types/calendar.js +0 -6
  133. package/dist/types/calendar.js.map +0 -1
  134. package/dist/types/calendarBo.d.ts +0 -62
  135. package/dist/types/calendarBo.d.ts.map +0 -1
  136. package/dist/types/calendarBo.js +0 -6
  137. package/dist/types/calendarBo.js.map +0 -1
  138. package/sample/package-lock.json +0 -1778
@@ -1,262 +0,0 @@
1
- import { CalendarModel } from "@blazeo.com/calendar-client";
2
- import { ensureBlazeoHttpReady } from "../config/ensureBlazeoHttpReady.js";
3
- import { unwrapCalendarGetData, pickOpeningHoursArrayFromCalendarPayload, normalizeParticipantOpeningHoursResponse, } from "./fetchCalendarWithOpeningHours.js";
4
- import { buildUnifiedCalendarView } from "./buildUnifiedCalendarView.js";
5
- import { mapToDesiredCalendarResponse } from "./mapToDesiredResponse.js";
6
- /**
7
- * Normalizes the REST envelope from `calendar.getParticipantOpeningHours()`
8
- * (`GET /Calendar/Participant/OpeningHours/Get`) into a plain row array.
9
- */
10
- export function normalizeOpeningHours(res) {
11
- const { list } = normalizeParticipantOpeningHoursResponse(res);
12
- return Array.isArray(list) ? list : [];
13
- }
14
- function normalizeAllParticipantOpeningHoursResult(raw) {
15
- if (Array.isArray(raw))
16
- return raw;
17
- const { list } = normalizeParticipantOpeningHoursResponse(raw);
18
- return Array.isArray(list) ? list : [];
19
- }
20
- /** Prefer union of `/Participant/All` and `/Participant/Get` so members reconcile when either list is incomplete. */
21
- function mergeParticipantSnapshots(a, b) {
22
- const byKey = new Map();
23
- const ingest = (p) => {
24
- if (p == null)
25
- return;
26
- const participantId = String(p.participantId ?? p.ParticipantId ?? p.participant_id ?? "").trim().toLowerCase();
27
- const calPartId = String(p.calendarParticipantId ?? p.CalendarParticipantId ?? p.calendarparticipant_id ?? "").trim()
28
- .toLowerCase();
29
- const key = participantId || calPartId;
30
- if (!key)
31
- return;
32
- if (!byKey.has(key))
33
- byKey.set(key, p);
34
- };
35
- if (Array.isArray(a))
36
- a.forEach(ingest);
37
- if (Array.isArray(b))
38
- b.forEach(ingest);
39
- return [...byKey.values()];
40
- }
41
- /** Coerce MST / envelope / nested `data` shapes into a plain array for participants and GetInfo lists. */
42
- function unwrapModelList(raw) {
43
- if (raw == null)
44
- return [];
45
- if (Array.isArray(raw))
46
- return raw;
47
- if (typeof raw === "string") {
48
- try {
49
- return unwrapModelList(JSON.parse(raw));
50
- }
51
- catch {
52
- return [];
53
- }
54
- }
55
- if (typeof raw !== "object")
56
- return [];
57
- const topArr = raw.items ?? raw.Items;
58
- if (Array.isArray(topArr))
59
- return topArr;
60
- const d = raw.data ?? raw.Data;
61
- if (Array.isArray(d))
62
- return d;
63
- if (d != null && typeof d === "object") {
64
- const inner = d.data ?? d.Data ?? d.items ?? d.Items;
65
- if (Array.isArray(inner))
66
- return inner;
67
- }
68
- return [];
69
- }
70
- /**
71
- * Calendar + legacy opening hours + full detail bundle (`fetchCalendarDetails`), **or**
72
- * only the **single unified object** via {@link fetchCalendarBundle}.
73
- *
74
- * **Flow**
75
- * 1. **Calendar** — parallel `CalendarModel.get` + `getRaw` (both `GET /Calendar/Get`: model + raw envelope).
76
- * 2. **Legacy `openingHours`** — embed from raw, else `getParticipantOpeningHours` (narrow endpoint).
77
- * 3. **`calendarView` (one object)** — in parallel after calendar is known:
78
- * - `GET /Calendar/Participant/All` and optional `/Participant/Get` merge when both return rows.
79
- * - `GET /Calendar/Participants/GetInfo`
80
- * - `GET /Calendar/Participant/OpeningHours/All/Get` when options enable it (`preferAllParticipantOpeningHours`)
81
- * Then `calendarView` = calendar snapshot fields + **`members`** (with **`participantInfo`**) + **`openingHours`**
82
- * (`openingHours[].member` → `members[].id`).
83
- *
84
- * Server still performs multiple HTTP calls; on the client, **`calendarView`** is returned as **one object**.
85
- */
86
- export async function fetchCalendarDetails(calendarId, options = {}) {
87
- const { includeParticipantsInfo = false, includeUnifiedCalendarView = true, preferAllParticipantOpeningHours = true, baseUrl: optBaseUrl, consumer: optConsumer, } = options;
88
- const conn = ensureBlazeoHttpReady({ baseUrl: optBaseUrl, consumer: optConsumer });
89
- if (!conn.ok) {
90
- return {
91
- calendar: null,
92
- cal: null,
93
- calendarView: null,
94
- openingHours: [],
95
- participants: [],
96
- participantsInfo: null,
97
- allParticipantOpeningHours: null,
98
- embeddedFromGet: [],
99
- fromCalendarGet: false,
100
- fromParticipantApi: false,
101
- participantOpeningHoursResponse: null,
102
- rawGet: null,
103
- meta: { ok: false, reason: "missing_base_url", detail: conn.error },
104
- };
105
- }
106
- const fetchParticipantsInfo = includeParticipantsInfo || includeUnifiedCalendarView;
107
- const fetchAllHours = includeUnifiedCalendarView && preferAllParticipantOpeningHours;
108
- // Calendar: `GET /Calendar/Get` is used to get the raw data first.
109
- const rawRes = await CalendarModel.getRaw(calendarId);
110
- const payload = unwrapCalendarGetData(rawRes);
111
- if (!payload) {
112
- return {
113
- calendar: null,
114
- cal: null,
115
- calendarView: null,
116
- openingHours: [],
117
- participants: null,
118
- participantsInfo: null,
119
- allParticipantOpeningHours: null,
120
- embeddedFromGet: [],
121
- fromCalendarGet: false,
122
- fromParticipantApi: false,
123
- participantOpeningHoursResponse: null,
124
- rawGet: rawRes,
125
- meta: { ok: false, reason: "calendar_not_found" },
126
- };
127
- }
128
- // Build the model instance manually to ensure the environment is correctly set.
129
- // The static CalendarModel.get in calendar-client has a bug where it wraps env in { env: ... }.
130
- const cal = CalendarModel.create({ ...payload, calendarId }, { baseUrl: conn.baseUrl, consumer: conn.consumer });
131
- const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
132
- let participantOpeningHoursResponse = null;
133
- let resolved = embedded.length > 0 ? embedded : null;
134
- if ((resolved == null || resolved.length === 0) && cal != null) {
135
- participantOpeningHoursResponse = await cal.getParticipantOpeningHours({ calendarId });
136
- const { list } = normalizeParticipantOpeningHoursResponse(participantOpeningHoursResponse);
137
- if (list != null && list.length > 0)
138
- resolved = list;
139
- }
140
- const openingHours = Array.isArray(resolved) ? resolved : [];
141
- // 2) Participants + participant info + all participant opening hours (parallel)
142
- const getCalPart = CalendarModel.getCalendarParticipant;
143
- const participantsViaGetPromise = includeUnifiedCalendarView && typeof getCalPart === "function"
144
- ? getCalPart.call(CalendarModel, calendarId)
145
- : Promise.resolve(null);
146
- const [participantsRaw, participantsViaGet, participantsInfoRaw, allHoursRaw] = await Promise.all([
147
- cal.getParticipants(),
148
- participantsViaGetPromise,
149
- fetchParticipantsInfo ? cal.getParticipantsInfo() : Promise.resolve(null),
150
- fetchAllHours ? cal.getAllParticipantOpeningHours() : Promise.resolve(null),
151
- ]);
152
- const participantList = mergeParticipantSnapshots(unwrapModelList(participantsRaw), unwrapModelList(participantsViaGet));
153
- const infoList = unwrapModelList(participantsInfoRaw);
154
- // Merge participantList and infoList to ensure we have all members
155
- const mergedParticipantsMap = new Map();
156
- // Prefer the participantId GUID; fall back to numeric id.
157
- const getAnyId = (obj) => obj.participantId ?? obj.ParticipantId ?? obj.participant_id ?? obj.id ?? obj.Id;
158
- // 1. Add from standard list
159
- participantList.forEach((p) => {
160
- const id = getAnyId(p);
161
- if (id) {
162
- mergedParticipantsMap.set(String(id).toLowerCase(), {
163
- id: id,
164
- name: p.name ?? p.Name ?? p.alias ?? p.Alias ?? "Member",
165
- email: p.email ?? p.Email,
166
- status: p.status ?? p.Status ?? 0,
167
- });
168
- }
169
- });
170
- // 2. Add from info list (fallback/enrich)
171
- infoList.forEach((i) => {
172
- const id = getAnyId(i);
173
- if (!id)
174
- return;
175
- const key = String(id).toLowerCase();
176
- const existing = mergedParticipantsMap.get(key);
177
- if (!existing) {
178
- mergedParticipantsMap.set(key, {
179
- id: id,
180
- name: i.alias || i.Alias || i.name || i.Name || "Member",
181
- email: i.email || i.Email,
182
- status: i.status ?? i.Status ?? (i.isApproved ? 1 : 0),
183
- });
184
- }
185
- else {
186
- // Enrich existing with email/name if missing
187
- if (!existing.email)
188
- existing.email = i.email || i.Email;
189
- if (!existing.name || existing.name === "Member") {
190
- existing.name = i.alias || i.Alias || i.name || i.Name || existing.name;
191
- }
192
- }
193
- });
194
- // 3. Synthetic Fallback: If openingHours reference a member we don't have, add them.
195
- openingHours.forEach((oh) => {
196
- const mid = oh.member ?? oh.Member ?? oh.participantId ?? oh.ParticipantId;
197
- if (mid) {
198
- const key = String(mid).toLowerCase();
199
- if (!mergedParticipantsMap.has(key)) {
200
- mergedParticipantsMap.set(key, {
201
- id: mid,
202
- name: "Member",
203
- email: null,
204
- status: 0,
205
- });
206
- }
207
- }
208
- });
209
- const finalParticipantList = Array.from(mergedParticipantsMap.values());
210
- const allParticipantOpeningHours = fetchAllHours ? normalizeAllParticipantOpeningHoursResult(allHoursRaw) : null;
211
- const openingHoursForUnifiedView = includeUnifiedCalendarView &&
212
- preferAllParticipantOpeningHours &&
213
- allParticipantOpeningHours != null &&
214
- allParticipantOpeningHours.length > 0
215
- ? allParticipantOpeningHours
216
- : openingHours;
217
- const calendarViewRaw = includeUnifiedCalendarView
218
- ? buildUnifiedCalendarView(payload, openingHoursForUnifiedView, finalParticipantList, infoList)
219
- : null;
220
- const calendarView = calendarViewRaw ? mapToDesiredCalendarResponse(calendarViewRaw, calendarViewRaw.openingHours, calendarViewRaw.members) : null;
221
- const unifiedUsedAllEndpoint = includeUnifiedCalendarView &&
222
- preferAllParticipantOpeningHours &&
223
- allParticipantOpeningHours != null &&
224
- allParticipantOpeningHours.length > 0;
225
- if (!calendarView)
226
- return null;
227
- // Attach metadata as non-enumerable properties so they don't show up in JSON.stringify
228
- // but are still accessible for debugging if needed.
229
- Object.defineProperties(calendarView, {
230
- _cal: { value: cal, enumerable: false },
231
- _participants: { value: participantList, enumerable: false },
232
- _openingHours: { value: openingHours, enumerable: false },
233
- _rawGet: { value: rawRes, enumerable: false },
234
- _meta: {
235
- value: {
236
- ok: true,
237
- calendarViewUsedAllParticipantOpeningHours: unifiedUsedAllEndpoint,
238
- calendarViewMemberCount: calendarView.members.length,
239
- calendarViewOpeningHourCount: calendarView.openingHours.length,
240
- },
241
- enumerable: false
242
- },
243
- });
244
- return calendarView;
245
- }
246
- /**
247
- * Single return value only: unified calendar **`calendarView`** —
248
- * snapshot fields plus **`members`** (with **`participantInfo`**) plus **`openingHours`**
249
- * (prefers all-participant opening hours when available). Same shape as `fetchCalendarDetails().calendarView`.
250
- * Returns **`null`** if the calendar cannot be loaded (`CalendarModel.get`).
251
- */
252
- export async function fetchCalendarBundle(calendarId, connection) {
253
- const d = await fetchCalendarDetails(calendarId, {
254
- includeUnifiedCalendarView: true,
255
- includeParticipantsInfo: true,
256
- preferAllParticipantOpeningHours: true,
257
- ...connection,
258
- });
259
- if (!d)
260
- return null;
261
- return d;
262
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Unwrap nested REST shapes: `res.data`, `res.Data`, or `res.data.data`.
3
- */
4
- export declare function unwrapCalendarGetData(res: any): any;
5
- /** `openingHours` / `OpeningHours` on the calendar object returned by GET /Calendar/
6
- * Robustly picks opening hours array from a raw calendar payload.
7
- */
8
- export declare function pickOpeningHoursArrayFromCalendarPayload(data: any): any[] | null;
9
- /**
10
- * Normalize `calendar.getParticipantOpeningHours()` response (`GET /Calendar/Participant/OpeningHours/Get`).
11
- * Supports various Blazeo API shapes including nested data and common property names.
12
- */
13
- export declare function normalizeParticipantOpeningHoursResponse(res: any): {
14
- list: null;
15
- raw: any;
16
- } | {
17
- list: any[];
18
- raw: any;
19
- };
20
- /**
21
- * Loads `CalendarModel` and attaches **`openingHours`** to the MST snapshot:
22
- * 1. Prefer rows embedded on **GET /Calendar/Get** (`CalendarModel.getRaw` payload — `@blazeo.com/calendar-client` MST omits them).
23
- * 2. If missing/empty, calls **`calendar.getParticipantOpeningHours()`** (`GET /Calendar/Participant/OpeningHours/Get`).
24
- */
25
- export declare function fetchCalendarWithOpeningHours(calendarId: string, options?: any): Promise<any>;
@@ -1,114 +0,0 @@
1
- import { CalendarModel } from "@blazeo.com/calendar-client";
2
- import { resolveBlazeoConnection } from "./createCalendar.js";
3
- import { mapToDesiredCalendarResponse } from "./mapToDesiredResponse.js";
4
- /**
5
- * Unwrap nested REST shapes: `res.data`, `res.Data`, or `res.data.data`.
6
- */
7
- export function unwrapCalendarGetData(res) {
8
- if (res == null || typeof res !== "object")
9
- return null;
10
- let d = res.data ?? res.Data;
11
- if (d == null)
12
- return null;
13
- if (typeof d === "object" && (d.data != null || d.Data != null)) {
14
- d = d.data ?? d.Data;
15
- }
16
- return d;
17
- }
18
- /** `openingHours` / `OpeningHours` on the calendar object returned by GET /Calendar/
19
- * Robustly picks opening hours array from a raw calendar payload.
20
- */
21
- export function pickOpeningHoursArrayFromCalendarPayload(data) {
22
- if (data == null)
23
- return null;
24
- const { list } = normalizeParticipantOpeningHoursResponse(data);
25
- return list;
26
- }
27
- /**
28
- * Normalize `calendar.getParticipantOpeningHours()` response (`GET /Calendar/Participant/OpeningHours/Get`).
29
- * Supports various Blazeo API shapes including nested data and common property names.
30
- */
31
- export function normalizeParticipantOpeningHoursResponse(res) {
32
- if (res == null)
33
- return { list: null, raw: res };
34
- // 1. Check for standard envelope: res.data or res.Data
35
- let d = res.data ?? res.Data ?? res;
36
- // 2. Handle double-nested data (common in some Blazeo API versions)
37
- if (d && typeof d === "object" && !Array.isArray(d)) {
38
- if (d.data !== undefined)
39
- d = d.data;
40
- else if (d.Data !== undefined)
41
- d = d.Data;
42
- }
43
- // 3. If d is now an array, that's our list
44
- if (Array.isArray(d))
45
- return { list: d, raw: res };
46
- // 4. Otherwise check for known list properties on the object
47
- if (d && typeof d === "object") {
48
- const list = d.openingHours ??
49
- d.OpeningHours ??
50
- d.participantOpeningHours ??
51
- d.ParticipantOpeningHours ??
52
- d.rows ??
53
- d.Rows ??
54
- d.items ??
55
- d.Items ??
56
- d.list ??
57
- d.List;
58
- if (Array.isArray(list))
59
- return { list, raw: res };
60
- }
61
- return { list: null, raw: res };
62
- }
63
- /**
64
- * Loads `CalendarModel` and attaches **`openingHours`** to the MST snapshot:
65
- * 1. Prefer rows embedded on **GET /Calendar/Get** (`CalendarModel.getRaw` payload — `@blazeo.com/calendar-client` MST omits them).
66
- * 2. If missing/empty, calls **`calendar.getParticipantOpeningHours()`** (`GET /Calendar/Participant/OpeningHours/Get`).
67
- */
68
- export async function fetchCalendarWithOpeningHours(calendarId, options = {}) {
69
- const { includeRawGet = false, baseUrl, consumer } = options;
70
- const { baseUrl: resolvedBase, consumer: resolvedConsumer } = resolveBlazeoConnection({ baseUrl, consumer });
71
- const rawRes = await CalendarModel.getRaw(calendarId);
72
- const payload = unwrapCalendarGetData(rawRes);
73
- let cal = null;
74
- if (payload) {
75
- // Manually create the model instance to fix a bug in calendar-client static get.
76
- cal = CalendarModel.create({ ...payload, calendarId }, { baseUrl: resolvedBase, consumer: resolvedConsumer });
77
- }
78
- if (cal == null) {
79
- return {
80
- calendar: null,
81
- openingHours: [],
82
- raw: rawRes,
83
- meta: { ok: false, reason: "calendar_not_found" },
84
- };
85
- }
86
- const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
87
- let resolved = embedded.length > 0 ? embedded : null;
88
- let participantRes = null;
89
- if ((resolved == null || resolved.length === 0) && cal != null) {
90
- // Pass calendarId explicitly because some server shapes do not populate `self.calendarId` on the MST model.
91
- participantRes = await cal.getParticipantOpeningHours({ calendarId });
92
- const { list } = normalizeParticipantOpeningHoursResponse(participantRes);
93
- if (list != null && list.length > 0)
94
- resolved = list;
95
- }
96
- const openingHours = Array.isArray(resolved) ? resolved : [];
97
- const mappedOpeningHours = openingHours.map(oh => ({
98
- ...oh,
99
- }));
100
- const rawMembers = payload?.members ?? payload?.Members ?? payload?.participants ?? payload?.Participants;
101
- const mappedMembers = Array.isArray(rawMembers)
102
- ? rawMembers.map((m) => ({ ...m }))
103
- : [];
104
- const calendar = mapToDesiredCalendarResponse(payload, openingHours, mappedMembers);
105
- if (!calendar)
106
- return null;
107
- Object.defineProperties(calendar, {
108
- _cal: { value: cal, enumerable: false },
109
- _openingHours: { value: openingHours, enumerable: false },
110
- _embeddedFromGet: { value: embedded, enumerable: false },
111
- _rawGet: { value: rawRes, enumerable: false },
112
- });
113
- return calendar;
114
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Fetch all participant opening hours for a calendar.
3
- * Uses `GET /Calendar/Participant/OpeningHours/All/Get`.
4
- */
5
- export declare function getAllParticipantOpeningHours(calendarId: string, options?: {
6
- baseUrl?: string;
7
- consumer?: string;
8
- }): Promise<{
9
- openingHours: any[];
10
- raw: any[];
11
- meta: {
12
- ok: true;
13
- shape: "array";
14
- };
15
- } | {
16
- openingHours: any[];
17
- raw: any;
18
- meta: {
19
- ok: boolean;
20
- shape?: undefined;
21
- };
22
- }>;
@@ -1,22 +0,0 @@
1
- import { CalendarModel } from "@blazeo.com/calendar-client";
2
- import { ensureBlazeoHttpReady } from "../config/ensureBlazeoHttpReady.js";
3
- import { normalizeParticipantOpeningHoursResponse } from "./fetchCalendarWithOpeningHours.js";
4
- /**
5
- * Fetch all participant opening hours for a calendar.
6
- * Uses `GET /Calendar/Participant/OpeningHours/All/Get`.
7
- */
8
- export async function getAllParticipantOpeningHours(calendarId, options = {}) {
9
- const ready = ensureBlazeoHttpReady(options);
10
- if (!ready.ok) {
11
- throw new Error(ready.error);
12
- }
13
- const raw = await CalendarModel.getAllParticipantOpeningHours(calendarId);
14
- // calendar-client static helper returns either `unknown[] | null` or an envelope depending on version/entrypoint.
15
- if (Array.isArray(raw)) {
16
- return { openingHours: raw, raw, meta: { ok: true, shape: "array" } };
17
- }
18
- const { list } = normalizeParticipantOpeningHoursResponse(raw);
19
- const openingHours = Array.isArray(list) ? list : [];
20
- const ok = Array.isArray(list) ? true : raw?.status === "success";
21
- return { openingHours, raw, meta: { ok: !!ok } };
22
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Fetches all calendars for a company and populates each with its members (participants).
3
- * Fetches both Participant List and Participant Info to ensure names and emails are included,
4
- * while still skipping heavy data like opening hours.
5
- */
6
- export declare function getCalendarsByCompany(companyKey: string, connection?: {
7
- baseUrl?: string;
8
- consumer?: string;
9
- }): Promise<any[]>;
@@ -1,107 +0,0 @@
1
- import { CalendarModel, CalendarParticipantModel } from "@blazeo.com/calendar-client";
2
- import { ensureBlazeoHttpReady } from "../config/ensureBlazeoHttpReady.js";
3
- /**
4
- * Fetches all calendars for a company and populates each with its members (participants).
5
- * Fetches both Participant List and Participant Info to ensure names and emails are included,
6
- * while still skipping heavy data like opening hours.
7
- */
8
- export async function getCalendarsByCompany(companyKey, connection = {}) {
9
- const ready = ensureBlazeoHttpReady(connection);
10
- if (!ready.ok) {
11
- throw new Error(ready.error);
12
- }
13
- // 1. Get all calendars for the company
14
- const result = await CalendarModel.getByCompany(companyKey);
15
- const calendars = Array.isArray(result) ? result : result?.calendars ?? [];
16
- if (!calendars || calendars.length === 0) {
17
- return [];
18
- }
19
- // 2. Fetch lightweight members for each calendar in parallel
20
- const enrichedCalendars = await Promise.all(calendars.map(async (cal) => {
21
- const calendarId = cal.calendarId ?? String(cal.id ?? "");
22
- if (!calendarId)
23
- return null;
24
- try {
25
- // We need both List and Info to get the names/emails
26
- const [partsRaw, infoRaw] = await Promise.all([
27
- CalendarParticipantModel.getByCalendar(calendarId),
28
- CalendarParticipantModel.getInfoByCalendar(calendarId)
29
- ]);
30
- const parts = Array.isArray(partsRaw) ? partsRaw : partsRaw?.participants ?? [];
31
- const info = Array.isArray(infoRaw) ? infoRaw : infoRaw?.info ?? [];
32
- // Merge logic to ensure names are matched to IDs
33
- const membersMap = new Map();
34
- // Use participantId GUID as the primary key
35
- const getAnyId = (obj) => obj.participantId ?? obj.ParticipantId ?? obj.participant_id ?? obj.id ?? obj.Id;
36
- // 1. Initialize with basic participant data
37
- parts.forEach((p) => {
38
- const mid = getAnyId(p);
39
- if (mid) {
40
- membersMap.set(String(mid).toLowerCase(), {
41
- id: mid,
42
- name: p.name ?? p.Name ?? "Member",
43
- email: p.email ?? p.Email,
44
- status: p.status ?? p.Status ?? 1,
45
- uuId: mid
46
- });
47
- }
48
- });
49
- // 2. Enrich with detailed info (Name, Email, Alias)
50
- info.forEach((i) => {
51
- const mid = getAnyId(i);
52
- if (!mid)
53
- return;
54
- const key = String(mid).toLowerCase();
55
- const existing = membersMap.get(key);
56
- const resolvedEmail = i.email ?? i.Email ?? i.userSsoEmail ?? i.UserSsoEmail ?? existing?.email;
57
- const memberData = {
58
- id: mid,
59
- name: i.name ?? i.Name ?? i.alias ?? i.Alias ?? (existing?.name || "Member"),
60
- email: resolvedEmail,
61
- alias: i.alias ?? i.Alias ?? i.name ?? i.Name,
62
- userSsoEmail: resolvedEmail,
63
- uuId: mid,
64
- status: i.status ?? i.Status ?? existing?.status ?? 1
65
- };
66
- if (!existing) {
67
- membersMap.set(key, memberData);
68
- }
69
- else {
70
- Object.assign(existing, memberData);
71
- }
72
- });
73
- const members = Array.from(membersMap.values());
74
- // Map to the EXACT schema requested by the user
75
- return {
76
- id: cal.id ?? cal.Id,
77
- calendarLink: cal.calendarLink ?? cal.CalendarLink ?? "",
78
- uuid: calendarId,
79
- createdOn: cal.createdOn ?? cal.CreatedOn,
80
- name: cal.name ?? cal.Name,
81
- timeZoneId: cal.timeZoneId ?? cal.TimeZoneId,
82
- description: cal.description ?? cal.Description ?? "",
83
- assignmentType: cal.assignmentMethod ?? cal.AssignmentMethod ?? cal.assignmentType,
84
- status: cal.status ?? cal.Status ?? 1,
85
- location: cal.location ?? cal.Location ?? "",
86
- members
87
- };
88
- }
89
- catch (err) {
90
- console.error(`[getCalendarsByCompany] Error fetching members for ${calendarId}:`, err);
91
- return {
92
- id: cal.id ?? cal.Id,
93
- calendarLink: cal.calendarLink ?? cal.CalendarLink ?? "",
94
- uuid: calendarId,
95
- createdOn: cal.createdOn ?? cal.CreatedOn,
96
- name: cal.name ?? cal.Name,
97
- timeZoneId: cal.timeZoneId ?? cal.TimeZoneId,
98
- description: cal.description ?? cal.Description ?? "",
99
- assignmentType: cal.assignmentMethod ?? cal.AssignmentMethod ?? cal.assignmentType,
100
- status: cal.status ?? cal.Status ?? 1,
101
- location: cal.location ?? cal.Location ?? "",
102
- members: []
103
- };
104
- }
105
- }));
106
- return enrichedCalendars.filter(c => c !== null);
107
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Fetches opening hours for a calendar.
3
- * Automatically handles embedded calendar-level hours and participant-level fallbacks.
4
- */
5
- export declare function getOpeningHours(calendarId: string, options?: {
6
- baseUrl?: string;
7
- consumer?: string;
8
- }): Promise<any>;
@@ -1,9 +0,0 @@
1
- import { fetchCalendarWithOpeningHours } from "./fetchCalendarWithOpeningHours.js";
2
- /**
3
- * Fetches opening hours for a calendar.
4
- * Automatically handles embedded calendar-level hours and participant-level fallbacks.
5
- */
6
- export async function getOpeningHours(calendarId, options = {}) {
7
- const result = await fetchCalendarWithOpeningHours(calendarId, options);
8
- return result.openingHours;
9
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * Direct wrapper around `calendar.getParticipantOpeningHours()` for a calendar id.
3
- *
4
- * This hits `GET /Calendar/Participant/OpeningHours/Get` (server-side shape may vary),
5
- * so we also return a normalized list alongside the raw response.
6
- */
7
- export declare function getParticipantOpeningHours(calendarId: string, options?: any): Promise<{
8
- openingHours: any[];
9
- raw: any;
10
- meta: {
11
- ok: false;
12
- reason: string;
13
- count?: undefined;
14
- status?: undefined;
15
- error?: undefined;
16
- };
17
- } | {
18
- openingHours: any[];
19
- raw: any;
20
- meta: {
21
- ok: true;
22
- count: number;
23
- status: any;
24
- reason?: undefined;
25
- error?: undefined;
26
- };
27
- } | {
28
- openingHours: any[];
29
- raw: any;
30
- meta: {
31
- ok: false;
32
- reason: string;
33
- error: string;
34
- count?: undefined;
35
- status?: undefined;
36
- };
37
- }>;
@@ -1,48 +0,0 @@
1
- import { CalendarModel } from "@blazeo.com/calendar-client";
2
- import { resolveBlazeoConnection } from "./createCalendar.js";
3
- import { unwrapCalendarGetData, normalizeParticipantOpeningHoursResponse } from "./fetchCalendarWithOpeningHours.js";
4
- /**
5
- * Direct wrapper around `calendar.getParticipantOpeningHours()` for a calendar id.
6
- *
7
- * This hits `GET /Calendar/Participant/OpeningHours/Get` (server-side shape may vary),
8
- * so we also return a normalized list alongside the raw response.
9
- */
10
- export async function getParticipantOpeningHours(calendarId, options = {}) {
11
- try {
12
- const { baseUrl, consumer, ...passThrough } = options;
13
- const { baseUrl: resolvedBase, consumer: resolvedConsumer } = resolveBlazeoConnection({ baseUrl, consumer });
14
- const rawRes = await CalendarModel.getRaw(calendarId);
15
- const payload = unwrapCalendarGetData(rawRes);
16
- if (!payload) {
17
- return {
18
- openingHours: [],
19
- raw: null,
20
- meta: { ok: false, reason: "calendar_not_found" },
21
- };
22
- }
23
- const cal = CalendarModel.create({ ...payload, calendarId }, { baseUrl: resolvedBase, consumer: resolvedConsumer });
24
- const raw = await cal.getParticipantOpeningHours({ calendarId, ...(passThrough ?? {}) });
25
- const { list } = normalizeParticipantOpeningHoursResponse(raw);
26
- const openingHours = Array.isArray(list) ? list : [];
27
- return {
28
- openingHours,
29
- raw,
30
- meta: {
31
- ok: true,
32
- count: openingHours.length,
33
- status: raw?.status ?? (raw?.Status || "unknown"),
34
- },
35
- };
36
- }
37
- catch (err) {
38
- return {
39
- openingHours: [],
40
- raw: null,
41
- meta: {
42
- ok: false,
43
- reason: "exception",
44
- error: err instanceof Error ? err.message : String(err),
45
- },
46
- };
47
- }
48
- }