@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
|
@@ -1,51 +1,81 @@
|
|
|
1
|
-
import type { IStateTreeNode } from "mobx-state-tree";
|
|
2
|
-
import type { CalendarInput } from "../types/calendar.js";
|
|
3
|
-
export type CreateCalendarOptions = {
|
|
4
|
-
/** Overrides packaged defaults / global `configure` when set. */
|
|
5
|
-
baseUrl?: string;
|
|
6
|
-
consumer?: string;
|
|
7
|
-
/**
|
|
8
|
-
* When true, only builds the MST `Calendar` node (no HTTP).
|
|
9
|
-
* Default false: calls `calendar.create()` → POST `/Calendar/Create`.
|
|
10
|
-
*/
|
|
11
|
-
localOnly?: boolean;
|
|
12
|
-
};
|
|
13
|
-
/** Typical Blazeo `reqPost` / `calendar.create()` result shape. */
|
|
14
|
-
export type BlazeoCalendarCreateResponse = {
|
|
15
|
-
status: string;
|
|
16
|
-
message?: string;
|
|
17
|
-
data?: unknown;
|
|
18
|
-
};
|
|
19
|
-
export type CreateCalendarSuccess = {
|
|
20
|
-
ok: true;
|
|
21
|
-
calendar: IStateTreeNode;
|
|
22
|
-
apiResponse?: BlazeoCalendarCreateResponse;
|
|
23
|
-
};
|
|
24
|
-
export type CreateCalendarFailure = {
|
|
25
|
-
ok: false;
|
|
26
|
-
error: string;
|
|
27
|
-
apiResponse?: BlazeoCalendarCreateResponse;
|
|
28
|
-
};
|
|
29
|
-
export type CreateCalendarResult = CreateCalendarSuccess | CreateCalendarFailure;
|
|
30
1
|
/** Merge per-call options with global Blazeo config (defaults file + `configure`). */
|
|
31
|
-
export declare function resolveBlazeoConnection(options?:
|
|
32
|
-
baseUrl
|
|
33
|
-
consumer
|
|
2
|
+
export declare function resolveBlazeoConnection(options?: any): {
|
|
3
|
+
baseUrl: any;
|
|
4
|
+
consumer: any;
|
|
34
5
|
};
|
|
35
6
|
/** Shared MST `env` for Blazeo models (`Calendar`, `Event`, …). */
|
|
36
|
-
export declare function buildModelEnv(baseUrl: string | undefined, consumer: string | undefined, forLocalOnly: boolean):
|
|
7
|
+
export declare function buildModelEnv(baseUrl: string | undefined, consumer: string | undefined, forLocalOnly: boolean): any;
|
|
37
8
|
/**
|
|
38
9
|
* Uses {@link resolveBlazeoConnection} (defaults + `configure` + optional overrides),
|
|
39
10
|
* then `CalendarModel.create` and `calendar.create()` unless `localOnly`.
|
|
40
11
|
*/
|
|
41
|
-
export declare function createCalendarAsync(calendar:
|
|
12
|
+
export declare function createCalendarAsync(calendar: any, options?: any): Promise<{
|
|
13
|
+
ok: boolean;
|
|
14
|
+
error: string;
|
|
15
|
+
calendar?: undefined;
|
|
16
|
+
apiResponse?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
calendar: any;
|
|
20
|
+
error?: undefined;
|
|
21
|
+
apiResponse?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
ok: boolean;
|
|
24
|
+
error: any;
|
|
25
|
+
apiResponse: any;
|
|
26
|
+
calendar?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
ok: boolean;
|
|
29
|
+
calendar: any;
|
|
30
|
+
apiResponse: any;
|
|
31
|
+
error?: undefined;
|
|
32
|
+
}>;
|
|
42
33
|
/**
|
|
43
34
|
* Uses {@link resolveBlazeoConnection}, builds a `Calendar` node from {@link mapCalendarBOToSnapshot},
|
|
44
35
|
* then `calendar.update()` → POST `/Calendar/Event/Update` unless `localOnly`.
|
|
45
36
|
*/
|
|
46
|
-
export declare function updateCalendarAsync(calendar:
|
|
37
|
+
export declare function updateCalendarAsync(calendar: any, options?: any): Promise<{
|
|
38
|
+
ok: boolean;
|
|
39
|
+
error: string;
|
|
40
|
+
calendar?: undefined;
|
|
41
|
+
apiResponse?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
calendar: any;
|
|
45
|
+
error?: undefined;
|
|
46
|
+
apiResponse?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
error: any;
|
|
50
|
+
apiResponse: any;
|
|
51
|
+
calendar?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
ok: boolean;
|
|
54
|
+
calendar: any;
|
|
55
|
+
apiResponse: any;
|
|
56
|
+
error?: undefined;
|
|
57
|
+
}>;
|
|
47
58
|
/**
|
|
48
59
|
* Removes a calendar via `calendar.remove()` → GET `/Calendar/Remove?calendar_id=…`.
|
|
49
60
|
*/
|
|
50
|
-
export declare function deleteCalendarAsync(calendarId: string, options?:
|
|
51
|
-
|
|
61
|
+
export declare function deleteCalendarAsync(calendarId: string, options?: any): Promise<{
|
|
62
|
+
ok: boolean;
|
|
63
|
+
error: string;
|
|
64
|
+
calendar?: undefined;
|
|
65
|
+
apiResponse?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
ok: boolean;
|
|
68
|
+
calendar: any;
|
|
69
|
+
error?: undefined;
|
|
70
|
+
apiResponse?: undefined;
|
|
71
|
+
} | {
|
|
72
|
+
ok: boolean;
|
|
73
|
+
error: any;
|
|
74
|
+
apiResponse: any;
|
|
75
|
+
calendar?: undefined;
|
|
76
|
+
} | {
|
|
77
|
+
ok: boolean;
|
|
78
|
+
calendar: any;
|
|
79
|
+
apiResponse: any;
|
|
80
|
+
error?: undefined;
|
|
81
|
+
}>;
|
|
@@ -110,8 +110,7 @@ export async function updateCalendarAsync(calendar, options = {}) {
|
|
|
110
110
|
const baseUrl = resolvedBase;
|
|
111
111
|
const consumer = resolvedConsumer;
|
|
112
112
|
const snapshot = mapCalendarBOToSnapshot(calendar);
|
|
113
|
-
if (!options.localOnly &&
|
|
114
|
-
!(calendar.calendarId?.trim())) {
|
|
113
|
+
if (!options.localOnly && !(calendar.calendarId?.trim())) {
|
|
115
114
|
return {
|
|
116
115
|
ok: false,
|
|
117
116
|
error: "calendarId is required for update. Pass an existing id.",
|
|
@@ -205,4 +204,3 @@ export async function deleteCalendarAsync(calendarId, options = {}) {
|
|
|
205
204
|
return { ok: false, error: message };
|
|
206
205
|
}
|
|
207
206
|
}
|
|
208
|
-
//# sourceMappingURL=createCalendar.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type UnifiedCalendarView } from "./buildUnifiedCalendarView.js";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes the REST envelope from `calendar.getParticipantOpeningHours()`
|
|
4
|
+
* (`GET /Calendar/Participant/OpeningHours/Get`) into a plain row array.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeOpeningHours(res: any): any[];
|
|
7
|
+
/**
|
|
8
|
+
* Calendar + legacy opening hours + full detail bundle (`fetchCalendarDetails`), **or**
|
|
9
|
+
* only the **single unified object** via {@link fetchCalendarBundle}.
|
|
10
|
+
*
|
|
11
|
+
* **Flow**
|
|
12
|
+
* 1. **Calendar** — parallel `CalendarModel.get` + `getRaw` (both `GET /Calendar/Get`: model + raw envelope).
|
|
13
|
+
* 2. **Legacy `openingHours`** — embed from raw, else `getParticipantOpeningHours` (narrow endpoint).
|
|
14
|
+
* 3. **`calendarView` (one object)** — in parallel after calendar is known:
|
|
15
|
+
* - `GET /Calendar/Participant/All` and optional `/Participant/Get` merge when both return rows.
|
|
16
|
+
* - `GET /Calendar/Participants/GetInfo`
|
|
17
|
+
* - `GET /Calendar/Participant/OpeningHours/All/Get` when options enable it (`preferAllParticipantOpeningHours`)
|
|
18
|
+
* Then `calendarView` = calendar snapshot fields + **`members`** (with **`participantInfo`**) + **`openingHours`**
|
|
19
|
+
* (`openingHours[].member` → `members[].id`).
|
|
20
|
+
*
|
|
21
|
+
* Server still performs multiple HTTP calls; on the client, **`calendarView`** is returned as **one object**.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fetchCalendarDetails(calendarId: string, options?: {
|
|
24
|
+
includeParticipantsInfo?: boolean;
|
|
25
|
+
includeUnifiedCalendarView?: boolean;
|
|
26
|
+
/** Prefer all-participant opening hours for **`calendarView`** when the API returns rows (default `true`). */
|
|
27
|
+
preferAllParticipantOpeningHours?: boolean;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
calendar: null;
|
|
30
|
+
cal: null;
|
|
31
|
+
calendarView: UnifiedCalendarView | null;
|
|
32
|
+
openingHours: any[];
|
|
33
|
+
participants: any[];
|
|
34
|
+
participantsInfo: any;
|
|
35
|
+
allParticipantOpeningHours: any[] | null;
|
|
36
|
+
embeddedFromGet: any[];
|
|
37
|
+
fromCalendarGet: boolean;
|
|
38
|
+
fromParticipantApi: boolean;
|
|
39
|
+
participantOpeningHoursResponse: any;
|
|
40
|
+
rawGet: any;
|
|
41
|
+
meta: {
|
|
42
|
+
ok: false;
|
|
43
|
+
reason: string;
|
|
44
|
+
};
|
|
45
|
+
} | {
|
|
46
|
+
calendar: any;
|
|
47
|
+
cal: any;
|
|
48
|
+
calendarView: UnifiedCalendarView | null;
|
|
49
|
+
openingHours: any[];
|
|
50
|
+
participants: any[];
|
|
51
|
+
participantsInfo: unknown;
|
|
52
|
+
allParticipantOpeningHours: any[] | null;
|
|
53
|
+
embeddedFromGet: any[];
|
|
54
|
+
fromCalendarGet: boolean;
|
|
55
|
+
fromParticipantApi: boolean;
|
|
56
|
+
participantOpeningHoursResponse: any;
|
|
57
|
+
meta: {
|
|
58
|
+
calendarViewMemberCount?: number | undefined;
|
|
59
|
+
calendarViewOpeningHourCount?: number | undefined;
|
|
60
|
+
ok: true;
|
|
61
|
+
/** `calendarView.openingHours` came from OpeningHours/All/Get */
|
|
62
|
+
calendarViewUsedAllParticipantOpeningHours: boolean;
|
|
63
|
+
reason?: undefined;
|
|
64
|
+
};
|
|
65
|
+
rawGet?: undefined;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Single return value only: unified calendar **`calendarView`** —
|
|
69
|
+
* snapshot fields plus **`members`** (with **`participantInfo`**) plus **`openingHours`**
|
|
70
|
+
* (prefers all-participant opening hours when available). Same shape as `fetchCalendarDetails().calendarView`.
|
|
71
|
+
* Returns **`null`** if the calendar cannot be loaded (`CalendarModel.get`).
|
|
72
|
+
*/
|
|
73
|
+
export declare function fetchCalendarBundle(calendarId: string): Promise<UnifiedCalendarView | null>;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { getSnapshot } from "mobx-state-tree";
|
|
3
|
+
import { unwrapCalendarGetData, pickOpeningHoursArrayFromCalendarPayload, normalizeParticipantOpeningHoursResponse, } from "./fetchCalendarWithOpeningHours.js";
|
|
4
|
+
import { buildUnifiedCalendarView } from "./buildUnifiedCalendarView.js";
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes the REST envelope from `calendar.getParticipantOpeningHours()`
|
|
7
|
+
* (`GET /Calendar/Participant/OpeningHours/Get`) into a plain row array.
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeOpeningHours(res) {
|
|
10
|
+
const { list } = normalizeParticipantOpeningHoursResponse(res);
|
|
11
|
+
return Array.isArray(list) ? list : [];
|
|
12
|
+
}
|
|
13
|
+
function normalizeAllParticipantOpeningHoursResult(raw) {
|
|
14
|
+
if (Array.isArray(raw))
|
|
15
|
+
return raw;
|
|
16
|
+
const { list } = normalizeParticipantOpeningHoursResponse(raw);
|
|
17
|
+
return Array.isArray(list) ? list : [];
|
|
18
|
+
}
|
|
19
|
+
/** Prefer union of `/Participant/All` and `/Participant/Get` so members reconcile when either list is incomplete. */
|
|
20
|
+
function mergeParticipantSnapshots(a, b) {
|
|
21
|
+
const byKey = new Map();
|
|
22
|
+
const ingest = (p) => {
|
|
23
|
+
if (p == null)
|
|
24
|
+
return;
|
|
25
|
+
const participantId = String(p.participantId ?? p.ParticipantId ?? p.participant_id ?? "").trim().toLowerCase();
|
|
26
|
+
const calPartId = String(p.calendarParticipantId ?? p.CalendarParticipantId ?? p.calendarparticipant_id ?? "").trim()
|
|
27
|
+
.toLowerCase();
|
|
28
|
+
const key = participantId || calPartId;
|
|
29
|
+
if (!key)
|
|
30
|
+
return;
|
|
31
|
+
if (!byKey.has(key))
|
|
32
|
+
byKey.set(key, p);
|
|
33
|
+
};
|
|
34
|
+
if (Array.isArray(a))
|
|
35
|
+
a.forEach(ingest);
|
|
36
|
+
if (Array.isArray(b))
|
|
37
|
+
b.forEach(ingest);
|
|
38
|
+
return [...byKey.values()];
|
|
39
|
+
}
|
|
40
|
+
/** Coerce MST / envelope / nested `data` shapes into a plain array for participants and GetInfo lists. */
|
|
41
|
+
function unwrapModelList(raw) {
|
|
42
|
+
if (raw == null)
|
|
43
|
+
return [];
|
|
44
|
+
if (Array.isArray(raw))
|
|
45
|
+
return raw;
|
|
46
|
+
if (typeof raw === "string") {
|
|
47
|
+
try {
|
|
48
|
+
return unwrapModelList(JSON.parse(raw));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (typeof raw !== "object")
|
|
55
|
+
return [];
|
|
56
|
+
const topArr = raw.items ?? raw.Items;
|
|
57
|
+
if (Array.isArray(topArr))
|
|
58
|
+
return topArr;
|
|
59
|
+
const d = raw.data ?? raw.Data;
|
|
60
|
+
if (Array.isArray(d))
|
|
61
|
+
return d;
|
|
62
|
+
if (d != null && typeof d === "object") {
|
|
63
|
+
const inner = d.data ?? d.Data ?? d.items ?? d.Items;
|
|
64
|
+
if (Array.isArray(inner))
|
|
65
|
+
return inner;
|
|
66
|
+
}
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calendar + legacy opening hours + full detail bundle (`fetchCalendarDetails`), **or**
|
|
71
|
+
* only the **single unified object** via {@link fetchCalendarBundle}.
|
|
72
|
+
*
|
|
73
|
+
* **Flow**
|
|
74
|
+
* 1. **Calendar** — parallel `CalendarModel.get` + `getRaw` (both `GET /Calendar/Get`: model + raw envelope).
|
|
75
|
+
* 2. **Legacy `openingHours`** — embed from raw, else `getParticipantOpeningHours` (narrow endpoint).
|
|
76
|
+
* 3. **`calendarView` (one object)** — in parallel after calendar is known:
|
|
77
|
+
* - `GET /Calendar/Participant/All` and optional `/Participant/Get` merge when both return rows.
|
|
78
|
+
* - `GET /Calendar/Participants/GetInfo`
|
|
79
|
+
* - `GET /Calendar/Participant/OpeningHours/All/Get` when options enable it (`preferAllParticipantOpeningHours`)
|
|
80
|
+
* Then `calendarView` = calendar snapshot fields + **`members`** (with **`participantInfo`**) + **`openingHours`**
|
|
81
|
+
* (`openingHours[].member` → `members[].id`).
|
|
82
|
+
*
|
|
83
|
+
* Server still performs multiple HTTP calls; on the client, **`calendarView`** is returned as **one object**.
|
|
84
|
+
*/
|
|
85
|
+
export async function fetchCalendarDetails(calendarId, options = {}) {
|
|
86
|
+
const { includeParticipantsInfo = false, includeUnifiedCalendarView = true, preferAllParticipantOpeningHours = true, } = options;
|
|
87
|
+
const fetchParticipantsInfo = includeParticipantsInfo || includeUnifiedCalendarView;
|
|
88
|
+
const fetchAllHours = includeUnifiedCalendarView && preferAllParticipantOpeningHours;
|
|
89
|
+
// Calendar: `GET /Calendar/Get` is used twice (model + raw for embed) — run in parallel.
|
|
90
|
+
const [cal, rawRes] = await Promise.all([
|
|
91
|
+
CalendarModel.get(calendarId),
|
|
92
|
+
CalendarModel.getRaw(calendarId),
|
|
93
|
+
]);
|
|
94
|
+
if (cal == null) {
|
|
95
|
+
return {
|
|
96
|
+
calendar: null,
|
|
97
|
+
cal: null,
|
|
98
|
+
calendarView: null,
|
|
99
|
+
openingHours: [],
|
|
100
|
+
participants: [],
|
|
101
|
+
participantsInfo: null,
|
|
102
|
+
allParticipantOpeningHours: null,
|
|
103
|
+
embeddedFromGet: [],
|
|
104
|
+
fromCalendarGet: false,
|
|
105
|
+
fromParticipantApi: false,
|
|
106
|
+
participantOpeningHoursResponse: null,
|
|
107
|
+
rawGet: rawRes,
|
|
108
|
+
meta: { ok: false, reason: "calendar_not_found" },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const payload = unwrapCalendarGetData(rawRes);
|
|
112
|
+
const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
|
|
113
|
+
let participantOpeningHoursResponse = null;
|
|
114
|
+
let resolved = embedded.length > 0 ? embedded : null;
|
|
115
|
+
if ((resolved == null || resolved.length === 0) && cal != null) {
|
|
116
|
+
participantOpeningHoursResponse = await cal.getParticipantOpeningHours({ calendarId });
|
|
117
|
+
const { list } = normalizeParticipantOpeningHoursResponse(participantOpeningHoursResponse);
|
|
118
|
+
if (list != null && list.length > 0)
|
|
119
|
+
resolved = list;
|
|
120
|
+
}
|
|
121
|
+
const openingHours = Array.isArray(resolved) ? resolved : [];
|
|
122
|
+
// 2) Participants + participant info + all participant opening hours (parallel)
|
|
123
|
+
const getCalPart = CalendarModel.getCalendarParticipant;
|
|
124
|
+
const participantsViaGetPromise = includeUnifiedCalendarView && typeof getCalPart === "function"
|
|
125
|
+
? getCalPart.call(CalendarModel, calendarId)
|
|
126
|
+
: Promise.resolve(null);
|
|
127
|
+
const [participants, participantsViaGet, participantsInfo, allHoursRaw] = await Promise.all([
|
|
128
|
+
CalendarModel.getParticipants(calendarId),
|
|
129
|
+
participantsViaGetPromise,
|
|
130
|
+
fetchParticipantsInfo ? CalendarModel.getParticipantsInfo(calendarId) : Promise.resolve(null),
|
|
131
|
+
fetchAllHours ? CalendarModel.getAllParticipantOpeningHours(calendarId) : Promise.resolve(null),
|
|
132
|
+
]);
|
|
133
|
+
const snap = getSnapshot(cal);
|
|
134
|
+
const calendar = { ...snap, openingHours };
|
|
135
|
+
const participantList = mergeParticipantSnapshots(unwrapModelList(participants), unwrapModelList(participantsViaGet));
|
|
136
|
+
const infoUnwrapped = fetchParticipantsInfo ? unwrapModelList(participantsInfo) : [];
|
|
137
|
+
const infoListForView = infoUnwrapped.length > 0 ? infoUnwrapped : null;
|
|
138
|
+
const allParticipantOpeningHours = fetchAllHours ? normalizeAllParticipantOpeningHoursResult(allHoursRaw) : null;
|
|
139
|
+
const openingHoursForUnifiedView = includeUnifiedCalendarView &&
|
|
140
|
+
preferAllParticipantOpeningHours &&
|
|
141
|
+
allParticipantOpeningHours != null &&
|
|
142
|
+
allParticipantOpeningHours.length > 0
|
|
143
|
+
? allParticipantOpeningHours
|
|
144
|
+
: openingHours;
|
|
145
|
+
const calendarView = includeUnifiedCalendarView
|
|
146
|
+
? buildUnifiedCalendarView(snap, openingHoursForUnifiedView, participantList, infoListForView)
|
|
147
|
+
: null;
|
|
148
|
+
const unifiedUsedAllEndpoint = includeUnifiedCalendarView &&
|
|
149
|
+
preferAllParticipantOpeningHours &&
|
|
150
|
+
allParticipantOpeningHours != null &&
|
|
151
|
+
allParticipantOpeningHours.length > 0;
|
|
152
|
+
return {
|
|
153
|
+
calendar,
|
|
154
|
+
cal,
|
|
155
|
+
calendarView,
|
|
156
|
+
openingHours,
|
|
157
|
+
participants: participantList,
|
|
158
|
+
participantsInfo,
|
|
159
|
+
allParticipantOpeningHours,
|
|
160
|
+
embeddedFromGet: embedded,
|
|
161
|
+
fromCalendarGet: embedded.length > 0,
|
|
162
|
+
fromParticipantApi: embedded.length === 0 && openingHours.length > 0 && participantOpeningHoursResponse != null,
|
|
163
|
+
participantOpeningHoursResponse,
|
|
164
|
+
meta: {
|
|
165
|
+
ok: true,
|
|
166
|
+
/** `calendarView.openingHours` came from OpeningHours/All/Get */
|
|
167
|
+
calendarViewUsedAllParticipantOpeningHours: unifiedUsedAllEndpoint,
|
|
168
|
+
...(calendarView != null
|
|
169
|
+
? {
|
|
170
|
+
calendarViewMemberCount: calendarView.members.length,
|
|
171
|
+
calendarViewOpeningHourCount: calendarView.openingHours.length,
|
|
172
|
+
}
|
|
173
|
+
: {}),
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Single return value only: unified calendar **`calendarView`** —
|
|
179
|
+
* snapshot fields plus **`members`** (with **`participantInfo`**) plus **`openingHours`**
|
|
180
|
+
* (prefers all-participant opening hours when available). Same shape as `fetchCalendarDetails().calendarView`.
|
|
181
|
+
* Returns **`null`** if the calendar cannot be loaded (`CalendarModel.get`).
|
|
182
|
+
*/
|
|
183
|
+
export async function fetchCalendarBundle(calendarId) {
|
|
184
|
+
const d = await fetchCalendarDetails(calendarId, {
|
|
185
|
+
includeUnifiedCalendarView: true,
|
|
186
|
+
includeParticipantsInfo: true,
|
|
187
|
+
preferAllParticipantOpeningHours: true,
|
|
188
|
+
});
|
|
189
|
+
if (!d.meta.ok)
|
|
190
|
+
return null;
|
|
191
|
+
return d.calendarView;
|
|
192
|
+
}
|
|
@@ -1,21 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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<{
|
|
26
|
+
rawGet?: any;
|
|
27
|
+
calendar: any;
|
|
28
|
+
cal: any;
|
|
29
|
+
openingHours: any[];
|
|
30
|
+
embeddedFromGet: any[];
|
|
31
|
+
fromCalendarGet: boolean;
|
|
32
|
+
fromParticipantApi: boolean;
|
|
33
|
+
participantOpeningHoursResponse: any;
|
|
34
|
+
}>;
|
|
@@ -1,75 +1,95 @@
|
|
|
1
|
-
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
-
import { getSnapshot } from "mobx-state-tree";
|
|
3
|
-
/**
|
|
4
|
-
* Unwrap nested REST shapes: `res.data`, `res.Data`, or `res.data.data`.
|
|
5
|
-
*/
|
|
6
|
-
export function unwrapCalendarGetData(res) {
|
|
7
|
-
if (res == null || typeof res !== "object")
|
|
8
|
-
return null;
|
|
9
|
-
let d = res.data ?? res.Data;
|
|
10
|
-
if (d == null)
|
|
11
|
-
return null;
|
|
12
|
-
if (typeof d === "object" && (d.data != null || d.Data != null)) {
|
|
13
|
-
d = d.data ?? d.Data;
|
|
14
|
-
}
|
|
15
|
-
return d;
|
|
16
|
-
}
|
|
17
|
-
/** `openingHours` / `OpeningHours` on the calendar object returned by GET /Calendar/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
return { list:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { getSnapshot } from "mobx-state-tree";
|
|
3
|
+
/**
|
|
4
|
+
* Unwrap nested REST shapes: `res.data`, `res.Data`, or `res.data.data`.
|
|
5
|
+
*/
|
|
6
|
+
export function unwrapCalendarGetData(res) {
|
|
7
|
+
if (res == null || typeof res !== "object")
|
|
8
|
+
return null;
|
|
9
|
+
let d = res.data ?? res.Data;
|
|
10
|
+
if (d == null)
|
|
11
|
+
return null;
|
|
12
|
+
if (typeof d === "object" && (d.data != null || d.Data != null)) {
|
|
13
|
+
d = d.data ?? d.Data;
|
|
14
|
+
}
|
|
15
|
+
return d;
|
|
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) {
|
|
21
|
+
if (data == null)
|
|
22
|
+
return null;
|
|
23
|
+
const { list } = normalizeParticipantOpeningHoursResponse(data);
|
|
24
|
+
return list;
|
|
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) {
|
|
31
|
+
if (res == null)
|
|
32
|
+
return { list: null, raw: res };
|
|
33
|
+
// 1. Check for standard envelope: res.data or res.Data
|
|
34
|
+
let d = res.data ?? res.Data ?? res;
|
|
35
|
+
// 2. Handle double-nested data (common in some Blazeo API versions)
|
|
36
|
+
if (d && typeof d === "object" && !Array.isArray(d)) {
|
|
37
|
+
if (d.data !== undefined)
|
|
38
|
+
d = d.data;
|
|
39
|
+
else if (d.Data !== undefined)
|
|
40
|
+
d = d.Data;
|
|
41
|
+
}
|
|
42
|
+
// 3. If d is now an array, that's our list
|
|
43
|
+
if (Array.isArray(d))
|
|
44
|
+
return { list: d, raw: res };
|
|
45
|
+
// 4. Otherwise check for known list properties on the object
|
|
46
|
+
if (d && typeof d === "object") {
|
|
47
|
+
const list = d.openingHours ??
|
|
48
|
+
d.OpeningHours ??
|
|
49
|
+
d.participantOpeningHours ??
|
|
50
|
+
d.ParticipantOpeningHours ??
|
|
51
|
+
d.rows ??
|
|
52
|
+
d.Rows ??
|
|
53
|
+
d.items ??
|
|
54
|
+
d.Items ??
|
|
55
|
+
d.list ??
|
|
56
|
+
d.List;
|
|
57
|
+
if (Array.isArray(list))
|
|
58
|
+
return { list, raw: res };
|
|
59
|
+
}
|
|
60
|
+
return { list: null, raw: res };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Loads `CalendarModel` and attaches **`openingHours`** to the MST snapshot:
|
|
64
|
+
* 1. Prefer rows embedded on **GET /Calendar/Get** (`CalendarModel.getRaw` payload — `@blazeo.com/calendar-client` MST omits them).
|
|
65
|
+
* 2. If missing/empty, calls **`calendar.getParticipantOpeningHours()`** (`GET /Calendar/Participant/OpeningHours/Get`).
|
|
66
|
+
*/
|
|
67
|
+
export async function fetchCalendarWithOpeningHours(calendarId, options = {}) {
|
|
68
|
+
const { includeRawGet = false } = options;
|
|
69
|
+
const rawRes = await CalendarModel.getRaw(calendarId);
|
|
70
|
+
const cal = await CalendarModel.get(calendarId);
|
|
71
|
+
const payload = unwrapCalendarGetData(rawRes);
|
|
72
|
+
const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
|
|
73
|
+
let resolved = embedded.length > 0 ? embedded : null;
|
|
74
|
+
let participantRes = null;
|
|
75
|
+
if ((resolved == null || resolved.length === 0) && cal != null) {
|
|
76
|
+
// Pass calendarId explicitly because some server shapes do not populate `self.calendarId` on the MST model.
|
|
77
|
+
participantRes = await cal.getParticipantOpeningHours({ calendarId });
|
|
78
|
+
const { list } = normalizeParticipantOpeningHoursResponse(participantRes);
|
|
79
|
+
if (list != null && list.length > 0)
|
|
80
|
+
resolved = list;
|
|
81
|
+
}
|
|
82
|
+
const openingHours = Array.isArray(resolved) ? resolved : [];
|
|
83
|
+
const snap = cal != null ? getSnapshot(cal) : null;
|
|
84
|
+
const calendar = snap != null ? { ...snap, openingHours } : null;
|
|
85
|
+
return {
|
|
86
|
+
calendar,
|
|
87
|
+
cal,
|
|
88
|
+
openingHours,
|
|
89
|
+
embeddedFromGet: embedded,
|
|
90
|
+
fromCalendarGet: embedded.length > 0,
|
|
91
|
+
fromParticipantApi: embedded.length === 0 && openingHours.length > 0 && participantRes != null,
|
|
92
|
+
participantOpeningHoursResponse: participantRes,
|
|
93
|
+
...(includeRawGet ? { rawGet: rawRes } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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): Promise<{
|
|
6
|
+
openingHours: any[];
|
|
7
|
+
raw: any[];
|
|
8
|
+
meta: {
|
|
9
|
+
ok: true;
|
|
10
|
+
shape: "array";
|
|
11
|
+
};
|
|
12
|
+
} | {
|
|
13
|
+
openingHours: any[];
|
|
14
|
+
raw: any;
|
|
15
|
+
meta: {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
shape?: undefined;
|
|
18
|
+
};
|
|
19
|
+
}>;
|