@blazeo.com/appointment-client 1.0.3 → 1.0.4

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.
@@ -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,7 @@ 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";
20
21
  export { CalendarModel, EventModel, ParticipantModel, OpeningHourModel, } from "@blazeo.com/calendar-client";
21
22
  export { configure, getConfig } from "@blazeo.com/calendar-client";
22
23
  export { getExampleCalendarRoot, getExampleCalendarRootSnapshot, getExampleEvents, getExampleParticipants, getExampleSlots, } from "./exampleData.js";
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ 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";
19
20
  export { CalendarModel, EventModel, ParticipantModel, OpeningHourModel, } from "@blazeo.com/calendar-client";
20
21
  export { configure, getConfig } from "@blazeo.com/calendar-client";
21
22
  export { getExampleCalendarRoot, getExampleCalendarRootSnapshot, getExampleEvents, getExampleParticipants, getExampleSlots, } from "./exampleData.js";
package/package.json CHANGED
@@ -1,39 +1,23 @@
1
- {
2
- "name": "@blazeo.com/appointment-client",
3
- "version": "1.0.3",
4
- "description": "Appointment API client",
5
- "license": "UNLICENSED",
6
- "type": "module",
7
- "main": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "author": "Blazeo",
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js"
14
- }
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "scripts": {
20
- "build": "tsc",
21
- "prepublishOnly": "npm run build",
22
- "sample:dev": "npm run build && npm install --prefix sample && npm run dev --prefix sample",
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.4",
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.5",
19
+ "mobx": "^6.13.7",
20
+ "mobx-state-tree": "^7.0.2"
21
+ }
22
+ }
23
+
@@ -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
+