@blazeo.com/appointment-client 1.0.3 → 1.0.5
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.5.tgz +0 -0
- package/dist/calendar/fetchCalendarDetails.d.ts +18 -0
- package/dist/calendar/fetchCalendarDetails.js +51 -0
- package/dist/calendar/fetchCalendarWithOpeningHours.d.ts +21 -0
- package/dist/calendar/fetchCalendarWithOpeningHours.js +75 -0
- package/dist/config/initializeAppointmentClient.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +22 -39
- package/sample/index.html +13 -0
- package/sample/package-lock.json +1706 -0
- package/sample/package.json +19 -0
- package/sample/src/App2.jsx +148 -0
- package/sample/src/AvailabilityTab.jsx +83 -0
- package/sample/src/BlazeoConnectionSettings.jsx +118 -0
- package/sample/src/CalendarTab.jsx +37 -0
- package/sample/src/CreateCalendarTab.jsx +147 -0
- package/sample/src/EventTab.jsx +372 -0
- package/sample/src/FetchCalendarTab.jsx +545 -0
- package/sample/src/ParticipantTab.jsx +102 -0
- package/sample/src/main.jsx +19 -0
- package/sample/src/style.css +681 -0
- package/sample/src/vite-env.d.ts +12 -0
- package/sample/vite.config.js +47 -0
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function fetchCalendarDetails(calendarId: string, options?: {
|
|
2
|
+
includeParticipantsInfo?: boolean;
|
|
3
|
+
}): Promise<{
|
|
4
|
+
calendar: (Record<string, unknown> & {
|
|
5
|
+
openingHours: unknown[];
|
|
6
|
+
}) | null;
|
|
7
|
+
/** Live MST calendar node (same as `CalendarModel.get`) — use for instance calls. */
|
|
8
|
+
cal: unknown;
|
|
9
|
+
openingHours: unknown[];
|
|
10
|
+
participants: unknown[];
|
|
11
|
+
participantsInfo: unknown;
|
|
12
|
+
openingHoursApiResponse: unknown;
|
|
13
|
+
meta: {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
reason?: string;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CalendarModel } from "@blazeo.com/calendar-client";
|
|
2
|
+
import { getSnapshot } from "mobx-state-tree";
|
|
3
|
+
import { normalizeParticipantOpeningHoursResponse } from "./fetchCalendarWithOpeningHours.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loads calendar + opening hours + participants and returns a single bundle.
|
|
7
|
+
*
|
|
8
|
+
* Network calls (when calendar exists):
|
|
9
|
+
* - GET /Calendar/Get
|
|
10
|
+
* - GET /Calendar/Participant/OpeningHours/Get
|
|
11
|
+
* - GET /Calendar/Participant/All
|
|
12
|
+
*/
|
|
13
|
+
export async function fetchCalendarDetails(calendarId, options = {}) {
|
|
14
|
+
const { includeParticipantsInfo = false } = options;
|
|
15
|
+
|
|
16
|
+
const cal = await CalendarModel.get(calendarId);
|
|
17
|
+
if (cal == null) {
|
|
18
|
+
return {
|
|
19
|
+
calendar: null,
|
|
20
|
+
cal: null,
|
|
21
|
+
openingHours: [],
|
|
22
|
+
participants: [],
|
|
23
|
+
participantsInfo: null,
|
|
24
|
+
openingHoursApiResponse: null,
|
|
25
|
+
meta: { ok: false, reason: "calendar_not_found" }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const [openingHoursRes, participants, participantsInfo] = await Promise.all([
|
|
30
|
+
cal.getParticipantOpeningHours({}),
|
|
31
|
+
cal.getParticipants(),
|
|
32
|
+
includeParticipantsInfo ? cal.getParticipantsInfo() : Promise.resolve(null)
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const { list: openingHoursList } = normalizeParticipantOpeningHoursResponse(openingHoursRes);
|
|
36
|
+
const openingHours = Array.isArray(openingHoursList) ? openingHoursList : [];
|
|
37
|
+
|
|
38
|
+
const snap = getSnapshot(cal);
|
|
39
|
+
const calendar = { ...snap, openingHours };
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
calendar,
|
|
43
|
+
cal,
|
|
44
|
+
openingHours,
|
|
45
|
+
participants: Array.isArray(participants) ? participants : [],
|
|
46
|
+
participantsInfo,
|
|
47
|
+
openingHoursApiResponse: openingHoursRes,
|
|
48
|
+
meta: { ok: true }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function unwrapCalendarGetData(res: unknown): unknown | null;
|
|
2
|
+
export declare function pickOpeningHoursArrayFromCalendarPayload(data: unknown): unknown[] | null;
|
|
3
|
+
export declare function normalizeParticipantOpeningHoursResponse(res: unknown): {
|
|
4
|
+
list: unknown[] | null;
|
|
5
|
+
raw: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare function fetchCalendarWithOpeningHours(calendarId: string, options?: {
|
|
8
|
+
includeRawGet?: boolean;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
calendar: (Record<string, unknown> & {
|
|
11
|
+
openingHours: unknown[];
|
|
12
|
+
}) | null;
|
|
13
|
+
/** Live MST calendar node (same as `CalendarModel.get`) — use for `getParticipants()`, etc. */
|
|
14
|
+
cal: unknown;
|
|
15
|
+
openingHours: unknown[];
|
|
16
|
+
embeddedFromGet: unknown[];
|
|
17
|
+
fromCalendarGet: boolean;
|
|
18
|
+
fromParticipantApi: boolean;
|
|
19
|
+
participantOpeningHoursResponse: unknown;
|
|
20
|
+
rawGet?: unknown;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,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/Get (matches GraphQL-style payloads). */
|
|
18
|
+
export function pickOpeningHoursArrayFromCalendarPayload(data) {
|
|
19
|
+
if (data == null || typeof data !== "object")
|
|
20
|
+
return null;
|
|
21
|
+
const h = data.openingHours ?? data.OpeningHours;
|
|
22
|
+
return Array.isArray(h) ? h : null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Normalize `calendar.getParticipantOpeningHours()` response (`GET /Calendar/Participant/OpeningHours/Get`).
|
|
26
|
+
*/
|
|
27
|
+
export function normalizeParticipantOpeningHoursResponse(res) {
|
|
28
|
+
if (res == null)
|
|
29
|
+
return { list: null, raw: res };
|
|
30
|
+
const d = res.data ?? res.Data;
|
|
31
|
+
if (Array.isArray(d))
|
|
32
|
+
return { list: d, raw: res };
|
|
33
|
+
if (d && typeof d === "object") {
|
|
34
|
+
if (Array.isArray(d.openingHours))
|
|
35
|
+
return { list: d.openingHours, raw: res };
|
|
36
|
+
if (Array.isArray(d.OpeningHours))
|
|
37
|
+
return { list: d.OpeningHours, raw: res };
|
|
38
|
+
if (Array.isArray(d.items))
|
|
39
|
+
return { list: d.items, raw: res };
|
|
40
|
+
}
|
|
41
|
+
return { list: null, raw: res };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Loads `CalendarModel` and attaches **`openingHours`** to the MST snapshot:
|
|
45
|
+
* 1. Prefer rows embedded on **GET /Calendar/Get** (`CalendarModel.getRaw` payload — `@blazeo.com/calendar-client` MST omits them).
|
|
46
|
+
* 2. If missing/empty, calls **`calendar.getParticipantOpeningHours()`** (`GET /Calendar/Participant/OpeningHours/Get`).
|
|
47
|
+
*/
|
|
48
|
+
export async function fetchCalendarWithOpeningHours(calendarId, options = {}) {
|
|
49
|
+
const { includeRawGet = false } = options;
|
|
50
|
+
const rawRes = await CalendarModel.getRaw(calendarId);
|
|
51
|
+
const cal = await CalendarModel.get(calendarId);
|
|
52
|
+
const payload = unwrapCalendarGetData(rawRes);
|
|
53
|
+
const embedded = pickOpeningHoursArrayFromCalendarPayload(payload) ?? [];
|
|
54
|
+
let resolved = embedded.length > 0 ? embedded : null;
|
|
55
|
+
let participantRes = null;
|
|
56
|
+
if ((resolved == null || resolved.length === 0) && cal != null) {
|
|
57
|
+
participantRes = await cal.getParticipantOpeningHours({});
|
|
58
|
+
const { list } = normalizeParticipantOpeningHoursResponse(participantRes);
|
|
59
|
+
if (list != null && list.length > 0)
|
|
60
|
+
resolved = list;
|
|
61
|
+
}
|
|
62
|
+
const openingHours = Array.isArray(resolved) ? resolved : [];
|
|
63
|
+
const snap = cal != null ? getSnapshot(cal) : null;
|
|
64
|
+
const calendar = snap != null ? { ...snap, openingHours } : null;
|
|
65
|
+
return {
|
|
66
|
+
calendar,
|
|
67
|
+
cal,
|
|
68
|
+
openingHours,
|
|
69
|
+
embeddedFromGet: embedded,
|
|
70
|
+
fromCalendarGet: embedded.length > 0,
|
|
71
|
+
fromParticipantApi: embedded.length === 0 && openingHours.length > 0 && participantRes != null,
|
|
72
|
+
participantOpeningHoursResponse: participantRes,
|
|
73
|
+
...(includeRawGet ? { rawGet: rawRes } : {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { configure, getConfig } from "@blazeo.com/calendar-client";
|
|
2
2
|
import { blazeoClientConfig } from "./blazeoClientDefaults.js";
|
|
3
3
|
export function initializeAppointmentClient(options = {}) {
|
|
4
|
+
debugger;
|
|
4
5
|
const fromOpts = options.baseUrl?.trim().replace(/\/+$/, "") ?? "";
|
|
5
6
|
const fromFile = blazeoClientConfig.baseUrl?.trim().replace(/\/+$/, "") ?? "";
|
|
6
7
|
const baseUrl = fromOpts || fromFile;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export * from "./models/index.js";
|
|
|
17
17
|
export { mapCalendarBOToSnapshot } from "./calendar/mapCalendarToBlazeoSnapshot.js";
|
|
18
18
|
export type { CalendarInput as CalendarBOInput, MemberBOInput, OpeningHourBOInput, } from "./types/calendar.js";
|
|
19
19
|
export type { ApexAppointmentInput } from "./types/appointment.js";
|
|
20
|
+
export { fetchCalendarWithOpeningHours, normalizeParticipantOpeningHoursResponse, pickOpeningHoursArrayFromCalendarPayload, unwrapCalendarGetData, } from "./calendar/fetchCalendarWithOpeningHours.js";
|
|
21
|
+
export { fetchCalendarDetails } from "./calendar/fetchCalendarDetails.js";
|
|
20
22
|
export { CalendarModel, EventModel, ParticipantModel, OpeningHourModel, } from "@blazeo.com/calendar-client";
|
|
21
23
|
export { configure, getConfig } from "@blazeo.com/calendar-client";
|
|
22
24
|
export { getExampleCalendarRoot, getExampleCalendarRootSnapshot, getExampleEvents, getExampleParticipants, getExampleSlots, } from "./exampleData.js";
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,8 @@ export { blazeoClientConfig } from "./config/blazeoClientDefaults.js";
|
|
|
16
16
|
export * from "./facades/index.js";
|
|
17
17
|
export * from "./models/index.js";
|
|
18
18
|
export { mapCalendarBOToSnapshot } from "./calendar/mapCalendarToBlazeoSnapshot.js";
|
|
19
|
+
export { fetchCalendarWithOpeningHours, normalizeParticipantOpeningHoursResponse, pickOpeningHoursArrayFromCalendarPayload, unwrapCalendarGetData, } from "./calendar/fetchCalendarWithOpeningHours.js";
|
|
20
|
+
export { fetchCalendarDetails } from "./calendar/fetchCalendarDetails.js";
|
|
19
21
|
export { CalendarModel, EventModel, ParticipantModel, OpeningHourModel, } from "@blazeo.com/calendar-client";
|
|
20
22
|
export { configure, getConfig } from "@blazeo.com/calendar-client";
|
|
21
23
|
export { getExampleCalendarRoot, getExampleCalendarRootSnapshot, getExampleEvents, getExampleParticipants, getExampleSlots, } from "./exampleData.js";
|
package/package.json
CHANGED
|
@@ -1,39 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@blazeo.com/appointment-client",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"import": "./dist/index.js"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"sample:build": "npm run build && npm install --prefix sample && npm run build --prefix sample",
|
|
24
|
-
"sample:preview": "npm run sample:build && npm run preview --prefix sample",
|
|
25
|
-
"sample:install": "npm install --prefix sample"
|
|
26
|
-
},
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=18"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@blazeo.com/calendar-client": "^1.0.5",
|
|
32
|
-
"calendar-client": "file:../calendar-client",
|
|
33
|
-
"mobx": "^6.13.7",
|
|
34
|
-
"mobx-state-tree": "^7.0.2"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"typescript": "^5.7.0"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@blazeo.com/appointment-client",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"author": "Blazeo",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@blazeo.com/calendar-client": "^1.0.17",
|
|
19
|
+
"mobx": "^6.13.7",
|
|
20
|
+
"mobx-state-tree": "^7.0.2"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>appointment-client sample</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.jsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
13
|
+
|