@blazeo.com/appointment-client 1.0.4 → 1.0.6
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/blazeo.com-appointment-client-1.0.6.tgz +0 -0
- package/dist/calendar/blazeoCalendarRelationMethods.d.ts +4 -36
- package/dist/calendar/blazeoCalendarRelationMethods.js +0 -1
- package/dist/calendar/buildUnifiedCalendarView.d.ts +31 -0
- package/dist/calendar/buildUnifiedCalendarView.js +265 -0
- package/dist/calendar/calendarCreation.d.ts +27 -0
- package/dist/calendar/calendarCreation.js +167 -0
- package/dist/calendar/calendarCreationFacade.d.ts +4 -13
- package/dist/calendar/calendarCreationFacade.js +3 -5
- package/dist/calendar/createCalendar.d.ts +67 -37
- package/dist/calendar/createCalendar.js +1 -3
- package/dist/calendar/fetchCalendarDetails.d.ts +73 -0
- package/dist/calendar/fetchCalendarDetails.js +192 -0
- package/dist/calendar/fetchCalendarWithOpeningHours.d.ts +34 -21
- package/dist/calendar/fetchCalendarWithOpeningHours.js +95 -75
- package/dist/calendar/getAllParticipantOpeningHours.d.ts +19 -0
- package/dist/calendar/getAllParticipantOpeningHours.js +17 -0
- package/dist/calendar/getOpeningHours.d.ts +5 -0
- package/dist/calendar/getOpeningHours.js +9 -0
- package/dist/calendar/getParticipantOpeningHours.d.ts +37 -0
- package/dist/calendar/getParticipantOpeningHours.js +43 -0
- package/dist/calendar/getParticipants.d.ts +4 -0
- package/dist/calendar/getParticipants.js +8 -0
- package/dist/calendar/mapCalendarBoToBlazeoSnapshot.d.ts +9 -9
- package/dist/calendar/mapCalendarBoToBlazeoSnapshot.js +43 -43
- package/dist/calendar/mapCalendarToBlazeoSnapshot.d.ts +22 -3
- package/dist/calendar/mapCalendarToBlazeoSnapshot.js +0 -1
- package/dist/config/applyBlazeoClientConfig.d.ts +2 -2
- package/dist/config/applyBlazeoClientConfig.js +13 -13
- package/dist/config/applyBlazeoDefaults.d.ts +0 -1
- package/dist/config/applyBlazeoDefaults.js +0 -1
- package/dist/config/blazeo.config.d.ts +10 -10
- package/dist/config/blazeo.config.js +10 -10
- package/dist/config/blazeoClientDefaults.d.ts +1 -2
- package/dist/config/blazeoClientDefaults.js +0 -1
- package/dist/config/initializeAppointmentClient.d.ts +4 -28
- package/dist/config/initializeAppointmentClient.js +5 -24
- package/dist/events/appointmentEventFacade.d.ts +55 -32
- package/dist/events/appointmentEventFacade.js +5 -10
- package/dist/events/mapAppointmentToEventSnapshot.d.ts +1 -4
- package/dist/events/mapAppointmentToEventSnapshot.js +0 -1
- package/dist/exampleData.d.ts +114 -10
- package/dist/exampleData.js +4 -5
- package/dist/facade/calendarCreationFacade.d.ts +39 -39
- package/dist/facade/calendarCreationFacade.js +95 -95
- package/dist/facade/mapCalendarBOToSnapshot.d.ts +9 -9
- package/dist/facade/mapCalendarBOToSnapshot.js +43 -43
- package/dist/facades/index.d.ts +11 -11
- package/dist/facades/index.js +11 -11
- package/dist/index.d.ts +23 -81
- package/dist/index.js +21 -32
- package/dist/models/CalendarRootModel.d.ts +36 -11
- package/dist/models/CalendarRootModel.js +22 -5
- package/dist/models/CalendarSlotModel.d.ts +8 -8
- package/dist/models/CalendarSlotModel.js +7 -7
- package/dist/models/EventModel.d.ts +10 -10
- package/dist/models/EventModel.js +9 -9
- package/dist/models/ParticipantModel.d.ts +8 -8
- package/dist/models/ParticipantModel.js +7 -7
- package/dist/models/index.d.ts +4 -4
- package/dist/models/index.js +4 -4
- package/dist/types/appointment.d.ts +27 -27
- package/dist/types/appointment.js +5 -5
- package/dist/types/calendar.d.ts +51 -51
- package/dist/types/calendar.js +5 -5
- package/dist/types/calendarBo.d.ts +61 -61
- package/dist/types/calendarBo.js +5 -5
- package/package.json +9 -4
- package/sample/build_error.txt +0 -0
- package/sample/demo.js +70 -0
- package/sample/package-lock.json +53 -2
- package/sample/package.json +3 -1
- package/sample/scripts/getInfoByCalendar.mjs +36 -0
- package/sample/scripts/getParticipantOpeningHours.mjs +48 -0
- package/sample/src/AllParticipantOpeningHoursTab.jsx +73 -0
- package/sample/src/App2.jsx +39 -2
- package/sample/src/BlazeoConnectionSettings.jsx +1 -1
- package/sample/src/EventTab.jsx +128 -0
- package/sample/src/FetchCalendarTab.jsx +72 -43
- package/sample/src/OpeningHoursTab.jsx +78 -0
- package/sample/src/ParticipantInfoTab.jsx +72 -0
- package/sample/src/ParticipantOpeningHoursTab.jsx +88 -0
- package/sample/src/ParticipantTab.jsx +2 -2
- package/src/calendar/blazeoCalendarRelationMethods.ts +19 -0
- package/src/calendar/buildUnifiedCalendarView.ts +322 -0
- package/src/calendar/calendarCreation.ts +179 -0
- package/src/calendar/createCalendar.ts +243 -0
- package/src/calendar/fetchCalendarDetails.ts +226 -0
- package/src/calendar/fetchCalendarWithOpeningHours.ts +99 -0
- package/src/calendar/getAllParticipantOpeningHours.ts +22 -0
- package/src/calendar/getOpeningHours.ts +10 -0
- package/src/calendar/getParticipantOpeningHours.ts +46 -0
- package/src/calendar/getParticipants.ts +9 -0
- package/src/calendar/mapCalendarToBlazeoSnapshot.ts +46 -0
- package/src/config/applyBlazeoDefaults.ts +13 -0
- package/src/config/blazeoClientDefaults.ts +11 -0
- package/src/config/initializeAppointmentClient.ts +18 -0
- package/src/events/appointmentEventFacade.ts +148 -0
- package/src/events/mapAppointmentToEventSnapshot.ts +65 -0
- package/src/exampleData.ts +79 -0
- package/src/index.ts +45 -0
- package/src/models/CalendarRootModel.ts +60 -0
- package/tsconfig.json +16 -0
- package/blazeo.com-appointment-client-1.0.4.tgz +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { CalendarModel, configure, getConfig } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { blazeoClientConfig } from "../config/blazeoClientDefaults.js";
|
|
3
|
+
import { mapCalendarBOToSnapshot } from "./mapCalendarToBlazeoSnapshot.js";
|
|
4
|
+
|
|
5
|
+
function isFailureStatus(res: any) {
|
|
6
|
+
return res.status !== "success" && res.status !== "Success";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Merge per-call options with global Blazeo config (defaults file + `configure`). */
|
|
10
|
+
export function resolveBlazeoConnection(options: any = {}) {
|
|
11
|
+
const cfg: any = getConfig();
|
|
12
|
+
const fromFileBase = blazeoClientConfig.baseUrl?.trim().replace(/\/+$/, "");
|
|
13
|
+
const fromFileConsumer = blazeoClientConfig.consumer?.trim();
|
|
14
|
+
|
|
15
|
+
const baseUrl =
|
|
16
|
+
options.baseUrl?.trim().replace(/\/+$/, "") ||
|
|
17
|
+
cfg?.baseUrl?.replace(/\/+$/, "") ||
|
|
18
|
+
(fromFileBase || undefined);
|
|
19
|
+
|
|
20
|
+
const consumer =
|
|
21
|
+
options.consumer?.trim() ||
|
|
22
|
+
cfg?.consumer ||
|
|
23
|
+
(fromFileConsumer || undefined);
|
|
24
|
+
|
|
25
|
+
return { baseUrl, consumer };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Shared MST `env` for Blazeo models (`Calendar`, `Event`, …). */
|
|
29
|
+
export function buildModelEnv(baseUrl: string | undefined, consumer: string | undefined, forLocalOnly: boolean) {
|
|
30
|
+
if (forLocalOnly && !baseUrl) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
const cfg: any = getConfig();
|
|
34
|
+
const env: any = {};
|
|
35
|
+
if (baseUrl) {
|
|
36
|
+
env.baseUrl = baseUrl;
|
|
37
|
+
} else if (cfg?.baseUrl) {
|
|
38
|
+
env.baseUrl = cfg.baseUrl;
|
|
39
|
+
}
|
|
40
|
+
if (consumer) {
|
|
41
|
+
env.consumer = consumer;
|
|
42
|
+
} else if (cfg?.consumer) {
|
|
43
|
+
env.consumer = cfg.consumer;
|
|
44
|
+
}
|
|
45
|
+
if (cfg?.fetch != null) env.fetch = cfg.fetch;
|
|
46
|
+
if (cfg?.getDefaultOffset != null) {
|
|
47
|
+
env.getDefaultOffset = cfg.getDefaultOffset;
|
|
48
|
+
}
|
|
49
|
+
return env;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Uses {@link resolveBlazeoConnection} (defaults + `configure` + optional overrides),
|
|
54
|
+
* then `CalendarModel.create` and `calendar.create()` unless `localOnly`.
|
|
55
|
+
*/
|
|
56
|
+
export async function createCalendarAsync(calendar: any, options: any = {}) {
|
|
57
|
+
try {
|
|
58
|
+
const { baseUrl: resolvedBase, consumer: resolvedConsumer } = resolveBlazeoConnection(options);
|
|
59
|
+
if (resolvedBase) {
|
|
60
|
+
configure({
|
|
61
|
+
baseUrl: resolvedBase,
|
|
62
|
+
...(resolvedConsumer ? { consumer: resolvedConsumer } : {}),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const baseUrl = resolvedBase;
|
|
67
|
+
const consumer = resolvedConsumer;
|
|
68
|
+
|
|
69
|
+
if (!options.localOnly && !baseUrl) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error:
|
|
73
|
+
"baseUrl is missing. Set `blazeoClientConfig.baseUrl` in `appointment-client/src/config/blazeoClientDefaults.ts` or call `configure({ baseUrl })`.",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const snapshot = mapCalendarBOToSnapshot(calendar);
|
|
78
|
+
const env = buildModelEnv(baseUrl, consumer, Boolean(options.localOnly));
|
|
79
|
+
|
|
80
|
+
if (!options.localOnly && env.baseUrl == null) {
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
error: "Model env requires baseUrl. Set `blazeoClientConfig` or pass `baseUrl` in options.",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const calendarNode: any = CalendarModel.create(snapshot, env);
|
|
88
|
+
|
|
89
|
+
if (options.localOnly) {
|
|
90
|
+
return { ok: true, calendar: calendarNode };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const apiRes: any = await calendarNode.create();
|
|
94
|
+
if (isFailureStatus(apiRes)) {
|
|
95
|
+
const msg =
|
|
96
|
+
apiRes.message ??
|
|
97
|
+
(typeof apiRes.data === "string" ? apiRes.data : undefined) ??
|
|
98
|
+
JSON.stringify(apiRes);
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
error: msg || "Calendar create failed",
|
|
102
|
+
apiResponse: apiRes,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { ok: true, calendar: calendarNode, apiResponse: apiRes };
|
|
107
|
+
} catch (err) {
|
|
108
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
109
|
+
return { ok: false, error: message };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Uses {@link resolveBlazeoConnection}, builds a `Calendar` node from {@link mapCalendarBOToSnapshot},
|
|
115
|
+
* then `calendar.update()` → POST `/Calendar/Event/Update` unless `localOnly`.
|
|
116
|
+
*/
|
|
117
|
+
export async function updateCalendarAsync(calendar: any, options: any = {}) {
|
|
118
|
+
try {
|
|
119
|
+
const { baseUrl: resolvedBase, consumer: resolvedConsumer } = resolveBlazeoConnection(options);
|
|
120
|
+
if (resolvedBase) {
|
|
121
|
+
configure({
|
|
122
|
+
baseUrl: resolvedBase,
|
|
123
|
+
...(resolvedConsumer ? { consumer: resolvedConsumer } : {}),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const baseUrl = resolvedBase;
|
|
128
|
+
const consumer = resolvedConsumer;
|
|
129
|
+
const snapshot = mapCalendarBOToSnapshot(calendar);
|
|
130
|
+
|
|
131
|
+
if (!options.localOnly && !(calendar.calendarId?.trim())) {
|
|
132
|
+
return {
|
|
133
|
+
ok: false,
|
|
134
|
+
error: "calendarId is required for update. Pass an existing id.",
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!options.localOnly && !baseUrl) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
error:
|
|
142
|
+
"baseUrl is missing. Set `blazeoClientConfig.baseUrl` in `appointment-client/src/config/blazeoClientDefaults.ts` or call `configure({ baseUrl })`.",
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const env = buildModelEnv(baseUrl, consumer, Boolean(options.localOnly));
|
|
147
|
+
|
|
148
|
+
if (!options.localOnly && env.baseUrl == null) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
error: "Model env requires baseUrl. Set `blazeoClientConfig` or pass `baseUrl` in options.",
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const calendarNode: any = CalendarModel.create(snapshot, env);
|
|
156
|
+
|
|
157
|
+
if (options.localOnly) {
|
|
158
|
+
return { ok: true, calendar: calendarNode };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const apiRes: any = await calendarNode.update();
|
|
162
|
+
if (isFailureStatus(apiRes)) {
|
|
163
|
+
const msg =
|
|
164
|
+
apiRes.message ??
|
|
165
|
+
(typeof apiRes.data === "string" ? apiRes.data : undefined) ??
|
|
166
|
+
JSON.stringify(apiRes);
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
error: msg || "Calendar update failed",
|
|
170
|
+
apiResponse: apiRes,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return { ok: true, calendar: calendarNode, apiResponse: apiRes };
|
|
175
|
+
} catch (err) {
|
|
176
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
177
|
+
return { ok: false, error: message };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Removes a calendar via `calendar.remove()` → GET `/Calendar/Remove?calendar_id=…`.
|
|
183
|
+
*/
|
|
184
|
+
export async function deleteCalendarAsync(calendarId: string, options: any = {}) {
|
|
185
|
+
try {
|
|
186
|
+
const id = calendarId.trim();
|
|
187
|
+
if (!id) {
|
|
188
|
+
return { ok: false, error: "calendarId is required for delete." };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const { baseUrl: resolvedBase, consumer: resolvedConsumer } = resolveBlazeoConnection(options);
|
|
192
|
+
if (resolvedBase) {
|
|
193
|
+
configure({
|
|
194
|
+
baseUrl: resolvedBase,
|
|
195
|
+
...(resolvedConsumer ? { consumer: resolvedConsumer } : {}),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const baseUrl = resolvedBase;
|
|
200
|
+
const consumer = resolvedConsumer;
|
|
201
|
+
|
|
202
|
+
if (!options.localOnly && !baseUrl) {
|
|
203
|
+
return {
|
|
204
|
+
ok: false,
|
|
205
|
+
error:
|
|
206
|
+
"baseUrl is missing. Set `blazeoClientConfig.baseUrl` in `appointment-client/src/config/blazeoClientDefaults.ts` or call `configure({ baseUrl })`.",
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const env = buildModelEnv(baseUrl, consumer, Boolean(options.localOnly));
|
|
211
|
+
|
|
212
|
+
if (!options.localOnly && env.baseUrl == null) {
|
|
213
|
+
return {
|
|
214
|
+
ok: false,
|
|
215
|
+
error: "Model env requires baseUrl. Set `blazeoClientConfig` or pass `baseUrl` in options.",
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const calendarNode: any = CalendarModel.create({ calendarId: id }, env);
|
|
220
|
+
|
|
221
|
+
if (options.localOnly) {
|
|
222
|
+
return { ok: true, calendar: calendarNode };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const apiRes: any = await calendarNode.remove();
|
|
226
|
+
if (isFailureStatus(apiRes)) {
|
|
227
|
+
const msg =
|
|
228
|
+
apiRes.message ??
|
|
229
|
+
(typeof apiRes.data === "string" ? apiRes.data : undefined) ??
|
|
230
|
+
JSON.stringify(apiRes);
|
|
231
|
+
return {
|
|
232
|
+
ok: false,
|
|
233
|
+
error: msg || "Calendar delete failed",
|
|
234
|
+
apiResponse: apiRes,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return { ok: true, calendar: calendarNode, apiResponse: apiRes };
|
|
239
|
+
} catch (err) {
|
|
240
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
241
|
+
return { ok: false, error: message };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { getSnapshot } from "mobx-state-tree";
|
|
3
|
+
import {
|
|
4
|
+
unwrapCalendarGetData,
|
|
5
|
+
pickOpeningHoursArrayFromCalendarPayload,
|
|
6
|
+
normalizeParticipantOpeningHoursResponse,
|
|
7
|
+
} from "./fetchCalendarWithOpeningHours.js";
|
|
8
|
+
import { buildUnifiedCalendarView, type UnifiedCalendarView } from "./buildUnifiedCalendarView.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Normalizes the REST envelope from `calendar.getParticipantOpeningHours()`
|
|
12
|
+
* (`GET /Calendar/Participant/OpeningHours/Get`) into a plain row array.
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeOpeningHours(res: any): any[] {
|
|
15
|
+
const { list } = normalizeParticipantOpeningHoursResponse(res);
|
|
16
|
+
return Array.isArray(list) ? list : [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeAllParticipantOpeningHoursResult(raw: any): any[] {
|
|
20
|
+
if (Array.isArray(raw)) return raw;
|
|
21
|
+
const { list } = normalizeParticipantOpeningHoursResponse(raw);
|
|
22
|
+
return Array.isArray(list) ? list : [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Prefer union of `/Participant/All` and `/Participant/Get` so members reconcile when either list is incomplete. */
|
|
26
|
+
function mergeParticipantSnapshots(
|
|
27
|
+
a: any[] | null | undefined,
|
|
28
|
+
b: any[] | null | undefined
|
|
29
|
+
): any[] {
|
|
30
|
+
const byKey = new Map<string, any>();
|
|
31
|
+
const ingest = (p: any) => {
|
|
32
|
+
if (p == null) return;
|
|
33
|
+
const participantId = String(
|
|
34
|
+
p.participantId ?? p.ParticipantId ?? p.participant_id ?? ""
|
|
35
|
+
).trim().toLowerCase();
|
|
36
|
+
const calPartId = String(
|
|
37
|
+
p.calendarParticipantId ?? p.CalendarParticipantId ?? p.calendarparticipant_id ?? ""
|
|
38
|
+
).trim()
|
|
39
|
+
.toLowerCase();
|
|
40
|
+
const key = participantId || calPartId;
|
|
41
|
+
if (!key) return;
|
|
42
|
+
if (!byKey.has(key)) byKey.set(key, p);
|
|
43
|
+
};
|
|
44
|
+
if (Array.isArray(a)) a.forEach(ingest);
|
|
45
|
+
if (Array.isArray(b)) b.forEach(ingest);
|
|
46
|
+
return [...byKey.values()];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Coerce MST / envelope / nested `data` shapes into a plain array for participants and GetInfo lists. */
|
|
50
|
+
function unwrapModelList(raw: any): any[] {
|
|
51
|
+
if (raw == null) return [];
|
|
52
|
+
if (Array.isArray(raw)) return raw;
|
|
53
|
+
if (typeof raw === "string") {
|
|
54
|
+
try {
|
|
55
|
+
return unwrapModelList(JSON.parse(raw));
|
|
56
|
+
} catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (typeof raw !== "object") return [];
|
|
61
|
+
const topArr = (raw as any).items ?? (raw as any).Items;
|
|
62
|
+
if (Array.isArray(topArr)) return topArr;
|
|
63
|
+
const d = raw.data ?? raw.Data;
|
|
64
|
+
if (Array.isArray(d)) return d;
|
|
65
|
+
if (d != null && typeof d === "object") {
|
|
66
|
+
const inner = (d as any).data ?? (d as any).Data ?? (d as any).items ?? (d as any).Items;
|
|
67
|
+
if (Array.isArray(inner)) return inner;
|
|
68
|
+
}
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Calendar + legacy opening hours + full detail bundle (`fetchCalendarDetails`), **or**
|
|
74
|
+
* only the **single unified object** via {@link fetchCalendarBundle}.
|
|
75
|
+
*
|
|
76
|
+
* **Flow**
|
|
77
|
+
* 1. **Calendar** — parallel `CalendarModel.get` + `getRaw` (both `GET /Calendar/Get`: model + raw envelope).
|
|
78
|
+
* 2. **Legacy `openingHours`** — embed from raw, else `getParticipantOpeningHours` (narrow endpoint).
|
|
79
|
+
* 3. **`calendarView` (one object)** — in parallel after calendar is known:
|
|
80
|
+
* - `GET /Calendar/Participant/All` and optional `/Participant/Get` merge when both return rows.
|
|
81
|
+
* - `GET /Calendar/Participants/GetInfo`
|
|
82
|
+
* - `GET /Calendar/Participant/OpeningHours/All/Get` when options enable it (`preferAllParticipantOpeningHours`)
|
|
83
|
+
* Then `calendarView` = calendar snapshot fields + **`members`** (with **`participantInfo`**) + **`openingHours`**
|
|
84
|
+
* (`openingHours[].member` → `members[].id`).
|
|
85
|
+
*
|
|
86
|
+
* Server still performs multiple HTTP calls; on the client, **`calendarView`** is returned as **one object**.
|
|
87
|
+
*/
|
|
88
|
+
export async function fetchCalendarDetails(
|
|
89
|
+
calendarId: string,
|
|
90
|
+
options: {
|
|
91
|
+
includeParticipantsInfo?: boolean;
|
|
92
|
+
includeUnifiedCalendarView?: boolean;
|
|
93
|
+
/** Prefer all-participant opening hours for **`calendarView`** when the API returns rows (default `true`). */
|
|
94
|
+
preferAllParticipantOpeningHours?: boolean;
|
|
95
|
+
} = {}
|
|
96
|
+
) {
|
|
97
|
+
const {
|
|
98
|
+
includeParticipantsInfo = false,
|
|
99
|
+
includeUnifiedCalendarView = true,
|
|
100
|
+
preferAllParticipantOpeningHours = true,
|
|
101
|
+
} = options;
|
|
102
|
+
|
|
103
|
+
const fetchParticipantsInfo = includeParticipantsInfo || includeUnifiedCalendarView;
|
|
104
|
+
const fetchAllHours = includeUnifiedCalendarView && preferAllParticipantOpeningHours;
|
|
105
|
+
|
|
106
|
+
// Calendar: `GET /Calendar/Get` is used twice (model + raw for embed) — run in parallel.
|
|
107
|
+
const [cal, rawRes]: [any, any] = await Promise.all([
|
|
108
|
+
CalendarModel.get(calendarId),
|
|
109
|
+
(CalendarModel as any).getRaw(calendarId),
|
|
110
|
+
]);
|
|
111
|
+
if (cal == null) {
|
|
112
|
+
return {
|
|
113
|
+
calendar: null,
|
|
114
|
+
cal: null,
|
|
115
|
+
calendarView: null as UnifiedCalendarView | null,
|
|
116
|
+
openingHours: [] as any[],
|
|
117
|
+
participants: [] as any[],
|
|
118
|
+
participantsInfo: null as any,
|
|
119
|
+
allParticipantOpeningHours: null as any[] | null,
|
|
120
|
+
embeddedFromGet: [] as any[],
|
|
121
|
+
fromCalendarGet: false,
|
|
122
|
+
fromParticipantApi: false,
|
|
123
|
+
participantOpeningHoursResponse: null as any,
|
|
124
|
+
rawGet: rawRes,
|
|
125
|
+
meta: { ok: false as const, reason: "calendar_not_found" },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const payload = unwrapCalendarGetData(rawRes);
|
|
130
|
+
const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
|
|
131
|
+
let participantOpeningHoursResponse: any = null;
|
|
132
|
+
let resolved: any[] | null = embedded.length > 0 ? embedded : null;
|
|
133
|
+
|
|
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) resolved = list;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const openingHours = Array.isArray(resolved) ? resolved : [];
|
|
141
|
+
|
|
142
|
+
// 2) Participants + participant info + all participant opening hours (parallel)
|
|
143
|
+
const getCalPart = (CalendarModel as any).getCalendarParticipant;
|
|
144
|
+
const participantsViaGetPromise =
|
|
145
|
+
includeUnifiedCalendarView && typeof getCalPart === "function"
|
|
146
|
+
? getCalPart.call(CalendarModel, calendarId)
|
|
147
|
+
: Promise.resolve(null);
|
|
148
|
+
|
|
149
|
+
const [participants, participantsViaGet, participantsInfo, allHoursRaw] = await Promise.all([
|
|
150
|
+
CalendarModel.getParticipants(calendarId),
|
|
151
|
+
participantsViaGetPromise,
|
|
152
|
+
fetchParticipantsInfo ? CalendarModel.getParticipantsInfo(calendarId) : Promise.resolve(null),
|
|
153
|
+
fetchAllHours ? (CalendarModel as any).getAllParticipantOpeningHours(calendarId) : Promise.resolve(null),
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
const snap = getSnapshot(cal);
|
|
157
|
+
const calendar = { ...(snap as any), openingHours };
|
|
158
|
+
|
|
159
|
+
const participantList = mergeParticipantSnapshots(
|
|
160
|
+
unwrapModelList(participants),
|
|
161
|
+
unwrapModelList(participantsViaGet)
|
|
162
|
+
);
|
|
163
|
+
const infoUnwrapped = fetchParticipantsInfo ? unwrapModelList(participantsInfo) : [];
|
|
164
|
+
const infoListForView = infoUnwrapped.length > 0 ? infoUnwrapped : null;
|
|
165
|
+
|
|
166
|
+
const allParticipantOpeningHours = fetchAllHours ? normalizeAllParticipantOpeningHoursResult(allHoursRaw) : null;
|
|
167
|
+
|
|
168
|
+
const openingHoursForUnifiedView =
|
|
169
|
+
includeUnifiedCalendarView &&
|
|
170
|
+
preferAllParticipantOpeningHours &&
|
|
171
|
+
allParticipantOpeningHours != null &&
|
|
172
|
+
allParticipantOpeningHours.length > 0
|
|
173
|
+
? allParticipantOpeningHours
|
|
174
|
+
: openingHours;
|
|
175
|
+
|
|
176
|
+
const calendarView = includeUnifiedCalendarView
|
|
177
|
+
? buildUnifiedCalendarView(snap as any, openingHoursForUnifiedView, participantList, infoListForView)
|
|
178
|
+
: null;
|
|
179
|
+
|
|
180
|
+
const unifiedUsedAllEndpoint =
|
|
181
|
+
includeUnifiedCalendarView &&
|
|
182
|
+
preferAllParticipantOpeningHours &&
|
|
183
|
+
allParticipantOpeningHours != null &&
|
|
184
|
+
allParticipantOpeningHours.length > 0;
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
calendar,
|
|
188
|
+
cal,
|
|
189
|
+
calendarView,
|
|
190
|
+
openingHours,
|
|
191
|
+
participants: participantList,
|
|
192
|
+
participantsInfo,
|
|
193
|
+
allParticipantOpeningHours,
|
|
194
|
+
embeddedFromGet: embedded,
|
|
195
|
+
fromCalendarGet: embedded.length > 0,
|
|
196
|
+
fromParticipantApi: embedded.length === 0 && openingHours.length > 0 && participantOpeningHoursResponse != null,
|
|
197
|
+
participantOpeningHoursResponse,
|
|
198
|
+
meta: {
|
|
199
|
+
ok: true as const,
|
|
200
|
+
/** `calendarView.openingHours` came from OpeningHours/All/Get */
|
|
201
|
+
calendarViewUsedAllParticipantOpeningHours: unifiedUsedAllEndpoint,
|
|
202
|
+
...(calendarView != null
|
|
203
|
+
? {
|
|
204
|
+
calendarViewMemberCount: calendarView.members.length,
|
|
205
|
+
calendarViewOpeningHourCount: calendarView.openingHours.length,
|
|
206
|
+
}
|
|
207
|
+
: {}),
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Single return value only: unified calendar **`calendarView`** —
|
|
214
|
+
* snapshot fields plus **`members`** (with **`participantInfo`**) plus **`openingHours`**
|
|
215
|
+
* (prefers all-participant opening hours when available). Same shape as `fetchCalendarDetails().calendarView`.
|
|
216
|
+
* Returns **`null`** if the calendar cannot be loaded (`CalendarModel.get`).
|
|
217
|
+
*/
|
|
218
|
+
export async function fetchCalendarBundle(calendarId: string): Promise<UnifiedCalendarView | null> {
|
|
219
|
+
const d = await fetchCalendarDetails(calendarId, {
|
|
220
|
+
includeUnifiedCalendarView: true,
|
|
221
|
+
includeParticipantsInfo: true,
|
|
222
|
+
preferAllParticipantOpeningHours: true,
|
|
223
|
+
});
|
|
224
|
+
if (!d.meta.ok) return null;
|
|
225
|
+
return d.calendarView;
|
|
226
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { getSnapshot } from "mobx-state-tree";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unwrap nested REST shapes: `res.data`, `res.Data`, or `res.data.data`.
|
|
6
|
+
*/
|
|
7
|
+
export function unwrapCalendarGetData(res: any) {
|
|
8
|
+
if (res == null || typeof res !== "object") return null;
|
|
9
|
+
let d = res.data ?? res.Data;
|
|
10
|
+
if (d == null) return null;
|
|
11
|
+
if (typeof d === "object" && (d.data != null || d.Data != null)) {
|
|
12
|
+
d = d.data ?? d.Data;
|
|
13
|
+
}
|
|
14
|
+
return d;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** `openingHours` / `OpeningHours` on the calendar object returned by GET /Calendar/
|
|
18
|
+
* Robustly picks opening hours array from a raw calendar payload.
|
|
19
|
+
*/
|
|
20
|
+
export function pickOpeningHoursArrayFromCalendarPayload(data: any) {
|
|
21
|
+
if (data == null) return null;
|
|
22
|
+
const { list } = normalizeParticipantOpeningHoursResponse(data);
|
|
23
|
+
return list;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Normalize `calendar.getParticipantOpeningHours()` response (`GET /Calendar/Participant/OpeningHours/Get`).
|
|
28
|
+
* Supports various Blazeo API shapes including nested data and common property names.
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeParticipantOpeningHoursResponse(res: any) {
|
|
31
|
+
if (res == null) return { list: null, raw: res };
|
|
32
|
+
|
|
33
|
+
// 1. Check for standard envelope: res.data or res.Data
|
|
34
|
+
let d = res.data ?? res.Data ?? res;
|
|
35
|
+
|
|
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) d = d.data;
|
|
39
|
+
else if (d.Data !== undefined) d = d.Data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 3. If d is now an array, that's our list
|
|
43
|
+
if (Array.isArray(d)) return { list: d, raw: res };
|
|
44
|
+
|
|
45
|
+
// 4. Otherwise check for known list properties on the object
|
|
46
|
+
if (d && typeof d === "object") {
|
|
47
|
+
const list =
|
|
48
|
+
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)) return { list, raw: res };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { list: null, raw: res };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Loads `CalendarModel` and attaches **`openingHours`** to the MST snapshot:
|
|
66
|
+
* 1. Prefer rows embedded on **GET /Calendar/Get** (`CalendarModel.getRaw` payload — `@blazeo.com/calendar-client` MST omits them).
|
|
67
|
+
* 2. If missing/empty, calls **`calendar.getParticipantOpeningHours()`** (`GET /Calendar/Participant/OpeningHours/Get`).
|
|
68
|
+
*/
|
|
69
|
+
export async function fetchCalendarWithOpeningHours(calendarId: string, options: any = {}) {
|
|
70
|
+
const { includeRawGet = false } = options;
|
|
71
|
+
const rawRes: any = await (CalendarModel as any).getRaw(calendarId);
|
|
72
|
+
const cal: any = await CalendarModel.get(calendarId);
|
|
73
|
+
const payload = unwrapCalendarGetData(rawRes);
|
|
74
|
+
const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
|
|
75
|
+
let resolved = embedded.length > 0 ? embedded : null;
|
|
76
|
+
let participantRes: any = null;
|
|
77
|
+
|
|
78
|
+
if ((resolved == null || resolved.length === 0) && cal != null) {
|
|
79
|
+
// Pass calendarId explicitly because some server shapes do not populate `self.calendarId` on the MST model.
|
|
80
|
+
participantRes = await cal.getParticipantOpeningHours({ calendarId });
|
|
81
|
+
const { list } = normalizeParticipantOpeningHoursResponse(participantRes);
|
|
82
|
+
if (list != null && list.length > 0) resolved = list;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const openingHours = Array.isArray(resolved) ? resolved : [];
|
|
86
|
+
const snap = cal != null ? getSnapshot(cal) : null;
|
|
87
|
+
const calendar = snap != null ? { ...(snap as any), openingHours } : null;
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
calendar,
|
|
91
|
+
cal,
|
|
92
|
+
openingHours,
|
|
93
|
+
embeddedFromGet: embedded,
|
|
94
|
+
fromCalendarGet: embedded.length > 0,
|
|
95
|
+
fromParticipantApi: embedded.length === 0 && openingHours.length > 0 && participantRes != null,
|
|
96
|
+
participantOpeningHoursResponse: participantRes,
|
|
97
|
+
...(includeRawGet ? { rawGet: rawRes } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { normalizeParticipantOpeningHoursResponse } from "./fetchCalendarWithOpeningHours.js";
|
|
3
|
+
|
|
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: string) {
|
|
9
|
+
const raw: any = await (CalendarModel as any).getAllParticipantOpeningHours(calendarId);
|
|
10
|
+
|
|
11
|
+
// calendar-client static helper returns either `unknown[] | null` or an envelope depending on version/entrypoint.
|
|
12
|
+
if (Array.isArray(raw)) {
|
|
13
|
+
return { openingHours: raw, raw, meta: { ok: true as const, shape: "array" as const } };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { list } = normalizeParticipantOpeningHoursResponse(raw);
|
|
17
|
+
const openingHours = Array.isArray(list) ? list : [];
|
|
18
|
+
const ok = Array.isArray(list) ? true : raw?.status === "success";
|
|
19
|
+
|
|
20
|
+
return { openingHours, raw, meta: { ok: !!ok as boolean } };
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { fetchCalendarWithOpeningHours } from "./fetchCalendarWithOpeningHours.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetches opening hours for a calendar.
|
|
5
|
+
* Automatically handles embedded calendar-level hours and participant-level fallbacks.
|
|
6
|
+
*/
|
|
7
|
+
export async function getOpeningHours(calendarId: string) {
|
|
8
|
+
const result = await fetchCalendarWithOpeningHours(calendarId);
|
|
9
|
+
return result.openingHours;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { normalizeParticipantOpeningHoursResponse } from "./fetchCalendarWithOpeningHours.js";
|
|
3
|
+
|
|
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: string, options: any = {}) {
|
|
11
|
+
try {
|
|
12
|
+
const cal: any = await CalendarModel.get(calendarId);
|
|
13
|
+
if (cal == null) {
|
|
14
|
+
return {
|
|
15
|
+
openingHours: [] as any[],
|
|
16
|
+
raw: null as any,
|
|
17
|
+
meta: { ok: false as const, reason: "calendar_not_found" },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const raw = await cal.getParticipantOpeningHours({ calendarId, ...(options ?? {}) });
|
|
22
|
+
const { list } = normalizeParticipantOpeningHoursResponse(raw);
|
|
23
|
+
const openingHours = Array.isArray(list) ? list : [];
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
openingHours,
|
|
27
|
+
raw,
|
|
28
|
+
meta: {
|
|
29
|
+
ok: true as const,
|
|
30
|
+
count: openingHours.length,
|
|
31
|
+
status: raw?.status ?? (raw?.Status || "unknown"),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return {
|
|
36
|
+
openingHours: [] as any[],
|
|
37
|
+
raw: null as any,
|
|
38
|
+
meta: {
|
|
39
|
+
ok: false as const,
|
|
40
|
+
reason: "exception",
|
|
41
|
+
error: err instanceof Error ? err.message : String(err),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetches participants for a calendar.
|
|
5
|
+
*/
|
|
6
|
+
export async function getParticipants(calendarId: string) {
|
|
7
|
+
const participants = await CalendarModel.getParticipants(calendarId);
|
|
8
|
+
return Array.isArray(participants) ? participants : [];
|
|
9
|
+
}
|