@voyantjs/flights-react 0.21.0

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 (58) hide show
  1. package/dist/client.d.ts +16 -0
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/client.js +75 -0
  4. package/dist/hooks/index.d.ts +13 -0
  5. package/dist/hooks/index.d.ts.map +1 -0
  6. package/dist/hooks/index.js +12 -0
  7. package/dist/hooks/use-aircraft.d.ts +17 -0
  8. package/dist/hooks/use-aircraft.d.ts.map +1 -0
  9. package/dist/hooks/use-aircraft.js +18 -0
  10. package/dist/hooks/use-airlines.d.ts +18 -0
  11. package/dist/hooks/use-airlines.d.ts.map +1 -0
  12. package/dist/hooks/use-airlines.js +18 -0
  13. package/dist/hooks/use-airport-search.d.ts +28 -0
  14. package/dist/hooks/use-airport-search.d.ts.map +1 -0
  15. package/dist/hooks/use-airport-search.js +23 -0
  16. package/dist/hooks/use-airports.d.ts +21 -0
  17. package/dist/hooks/use-airports.d.ts.map +1 -0
  18. package/dist/hooks/use-airports.js +17 -0
  19. package/dist/hooks/use-flight-ancillaries.d.ts +63 -0
  20. package/dist/hooks/use-flight-ancillaries.d.ts.map +1 -0
  21. package/dist/hooks/use-flight-ancillaries.js +24 -0
  22. package/dist/hooks/use-flight-book.d.ts +139 -0
  23. package/dist/hooks/use-flight-book.d.ts.map +1 -0
  24. package/dist/hooks/use-flight-book.js +24 -0
  25. package/dist/hooks/use-flight-offer.d.ts +106 -0
  26. package/dist/hooks/use-flight-offer.d.ts.map +1 -0
  27. package/dist/hooks/use-flight-offer.js +20 -0
  28. package/dist/hooks/use-flight-order.d.ts +286 -0
  29. package/dist/hooks/use-flight-order.d.ts.map +1 -0
  30. package/dist/hooks/use-flight-order.js +38 -0
  31. package/dist/hooks/use-flight-orders.d.ts +147 -0
  32. package/dist/hooks/use-flight-orders.d.ts.map +1 -0
  33. package/dist/hooks/use-flight-orders.js +31 -0
  34. package/dist/hooks/use-flight-search.d.ts +110 -0
  35. package/dist/hooks/use-flight-search.d.ts.map +1 -0
  36. package/dist/hooks/use-flight-search.js +18 -0
  37. package/dist/hooks/use-flight-seat-map.d.ts +49 -0
  38. package/dist/hooks/use-flight-seat-map.d.ts.map +1 -0
  39. package/dist/hooks/use-flight-seat-map.js +23 -0
  40. package/dist/hooks/use-saved-payment-methods.d.ts +23 -0
  41. package/dist/hooks/use-saved-payment-methods.d.ts.map +1 -0
  42. package/dist/hooks/use-saved-payment-methods.js +20 -0
  43. package/dist/index.d.ts +7 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +6 -0
  46. package/dist/provider.d.ts +2 -0
  47. package/dist/provider.d.ts.map +1 -0
  48. package/dist/provider.js +1 -0
  49. package/dist/query-keys.d.ts +42 -0
  50. package/dist/query-keys.d.ts.map +1 -0
  51. package/dist/query-keys.js +22 -0
  52. package/dist/query-options.d.ts +827 -0
  53. package/dist/query-options.d.ts.map +1 -0
  54. package/dist/query-options.js +58 -0
  55. package/dist/schemas.d.ts +1658 -0
  56. package/dist/schemas.d.ts.map +1 -0
  57. package/dist/schemas.js +295 -0
  58. package/package.json +85 -0
@@ -0,0 +1,16 @@
1
+ import type { z } from "zod";
2
+ export type VoyantFetcher = (url: string, init?: RequestInit) => Promise<Response>;
3
+ export declare const defaultFetcher: VoyantFetcher;
4
+ export declare class VoyantApiError extends Error {
5
+ readonly status: number;
6
+ readonly body: unknown;
7
+ constructor(message: string, status: number, body: unknown);
8
+ }
9
+ export interface FetchWithValidationOptions {
10
+ baseUrl: string;
11
+ fetcher: VoyantFetcher;
12
+ }
13
+ export declare function fetchWithValidation<TOut>(path: string, schema: z.ZodType<TOut>, options: FetchWithValidationOptions, init?: RequestInit): Promise<TOut>;
14
+ export type QueryParamValue = string | number | boolean | null | undefined | Array<string | number | boolean>;
15
+ export declare function withQueryParams(path: string, params: Record<string, QueryParamValue>): string;
16
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAElF,eAAO,MAAM,cAAc,EAAE,aACoB,CAAA;AAEjD,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAM3D;AAaD,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,aAAa,CAAA;CACvB;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAC5C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EACvB,OAAO,EAAE,0BAA0B,EACnC,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAgCf;AAkBD,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;AAEpC,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,MAAM,CAY7F"}
package/dist/client.js ADDED
@@ -0,0 +1,75 @@
1
+ export const defaultFetcher = (url, init) => fetch(url, { credentials: "include", ...init });
2
+ export class VoyantApiError extends Error {
3
+ status;
4
+ body;
5
+ constructor(message, status, body) {
6
+ super(message);
7
+ this.name = "VoyantApiError";
8
+ this.status = status;
9
+ this.body = body;
10
+ }
11
+ }
12
+ function extractErrorMessage(status, statusText, body) {
13
+ if (typeof body === "object" && body !== null && "error" in body) {
14
+ const err = body.error;
15
+ if (typeof err === "string")
16
+ return err;
17
+ if (typeof err === "object" && err !== null && "message" in err) {
18
+ return String(err.message);
19
+ }
20
+ }
21
+ return `Voyant API error: ${status} ${statusText}`;
22
+ }
23
+ export async function fetchWithValidation(path, schema, options, init) {
24
+ const url = joinUrl(options.baseUrl, path);
25
+ const headers = new Headers(init?.headers);
26
+ if (init?.body !== undefined && !headers.has("Content-Type")) {
27
+ headers.set("Content-Type", "application/json");
28
+ }
29
+ const response = await options.fetcher(url, { ...init, headers });
30
+ if (!response.ok) {
31
+ const body = await safeJson(response);
32
+ throw new VoyantApiError(extractErrorMessage(response.status, response.statusText, body), response.status, body);
33
+ }
34
+ if (response.status === 204) {
35
+ return schema.parse(undefined);
36
+ }
37
+ const body = await safeJson(response);
38
+ const parsed = schema.safeParse(body);
39
+ if (!parsed.success) {
40
+ throw new VoyantApiError(`Voyant API response failed validation: ${parsed.error.message}`, response.status, body);
41
+ }
42
+ return parsed.data;
43
+ }
44
+ async function safeJson(response) {
45
+ const text = await response.text();
46
+ if (!text)
47
+ return undefined;
48
+ try {
49
+ return JSON.parse(text);
50
+ }
51
+ catch {
52
+ return text;
53
+ }
54
+ }
55
+ function joinUrl(baseUrl, path) {
56
+ const trimmedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
57
+ const trimmedPath = path.startsWith("/") ? path : `/${path}`;
58
+ return `${trimmedBase}${trimmedPath}`;
59
+ }
60
+ export function withQueryParams(path, params) {
61
+ const search = new URLSearchParams();
62
+ for (const [key, value] of Object.entries(params)) {
63
+ if (value === undefined || value === null)
64
+ continue;
65
+ if (Array.isArray(value)) {
66
+ for (const v of value)
67
+ search.append(key, String(v));
68
+ }
69
+ else {
70
+ search.set(key, String(value));
71
+ }
72
+ }
73
+ const qs = search.toString();
74
+ return qs ? `${path}?${qs}` : path;
75
+ }
@@ -0,0 +1,13 @@
1
+ export { useAircraft } from "./use-aircraft.js";
2
+ export { useAirlines } from "./use-airlines.js";
3
+ export { type UseAirportSearchOptions, useAirportSearch } from "./use-airport-search.js";
4
+ export { type UseAirportsOptions, useAirports } from "./use-airports.js";
5
+ export { type UseFlightAncillariesOptions, useFlightAncillaries, } from "./use-flight-ancillaries.js";
6
+ export { useFlightBook } from "./use-flight-book.js";
7
+ export { type PriceOfferInput, useFlightOfferPrice } from "./use-flight-offer.js";
8
+ export { type CancelOrderInput, type UseFlightOrderOptions, useFlightOrder, useFlightOrderCancel, } from "./use-flight-order.js";
9
+ export { type UseFlightOrdersOptions, useFlightOrders } from "./use-flight-orders.js";
10
+ export { type UseFlightSearchOptions, useFlightSearch } from "./use-flight-search.js";
11
+ export { type UseFlightSeatMapOptions, useFlightSeatMap, } from "./use-flight-seat-map.js";
12
+ export { type UseSavedPaymentMethodsOptions, useSavedPaymentMethods, } from "./use-saved-payment-methods.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,KAAK,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AACxF,OAAO,EAAE,KAAK,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EACL,KAAK,2BAA2B,EAChC,oBAAoB,GACrB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,KAAK,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACjF,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACrF,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACrF,OAAO,EACL,KAAK,uBAAuB,EAC5B,gBAAgB,GACjB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,KAAK,6BAA6B,EAClC,sBAAsB,GACvB,MAAM,gCAAgC,CAAA"}
@@ -0,0 +1,12 @@
1
+ export { useAircraft } from "./use-aircraft.js";
2
+ export { useAirlines } from "./use-airlines.js";
3
+ export { useAirportSearch } from "./use-airport-search.js";
4
+ export { useAirports } from "./use-airports.js";
5
+ export { useFlightAncillaries, } from "./use-flight-ancillaries.js";
6
+ export { useFlightBook } from "./use-flight-book.js";
7
+ export { useFlightOfferPrice } from "./use-flight-offer.js";
8
+ export { useFlightOrder, useFlightOrderCancel, } from "./use-flight-order.js";
9
+ export { useFlightOrders } from "./use-flight-orders.js";
10
+ export { useFlightSearch } from "./use-flight-search.js";
11
+ export { useFlightSeatMap, } from "./use-flight-seat-map.js";
12
+ export { useSavedPaymentMethods, } from "./use-saved-payment-methods.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Fetches the aircraft reference list. Mostly used to hydrate the IATA
3
+ * aircraft type code on segments (e.g. `738` → "Boeing 737-800") in the
4
+ * detail sheet.
5
+ */
6
+ export declare function useAircraft(options?: {
7
+ enabled?: boolean;
8
+ }): import("@tanstack/react-query").UseQueryResult<{
9
+ data: {
10
+ iataCode: string;
11
+ name: string;
12
+ icaoCode?: string | null | undefined;
13
+ manufacturer?: string | null | undefined;
14
+ typicalSeats?: number | null | undefined;
15
+ }[];
16
+ }, Error>;
17
+ //# sourceMappingURL=use-aircraft.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-aircraft.d.ts","sourceRoot":"","sources":["../../src/hooks/use-aircraft.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;UAQ9D"}
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFlightsContext } from "../provider.js";
4
+ import { getAircraftQueryOptions } from "../query-options.js";
5
+ /**
6
+ * Fetches the aircraft reference list. Mostly used to hydrate the IATA
7
+ * aircraft type code on segments (e.g. `738` → "Boeing 737-800") in the
8
+ * detail sheet.
9
+ */
10
+ export function useAircraft(options = {}) {
11
+ const client = useVoyantFlightsContext();
12
+ const { enabled = true } = options;
13
+ return useQuery({
14
+ ...getAircraftQueryOptions(client),
15
+ enabled,
16
+ staleTime: 24 * 60 * 60 * 1000,
17
+ });
18
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Fetches the full airline reference list. Long-stale because airlines
3
+ * rarely change once seeded — the operator's reference table is a
4
+ * deliberate snapshot, not a live feed.
5
+ */
6
+ export declare function useAirlines(options?: {
7
+ enabled?: boolean;
8
+ }): import("@tanstack/react-query").UseQueryResult<{
9
+ data: {
10
+ iataCode: string;
11
+ name: string;
12
+ icaoCode?: string | null | undefined;
13
+ country?: string | null | undefined;
14
+ logoUrl?: string | null | undefined;
15
+ alliance?: string | null | undefined;
16
+ }[];
17
+ }, Error>;
18
+ //# sourceMappingURL=use-airlines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-airlines.d.ts","sourceRoot":"","sources":["../../src/hooks/use-airlines.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;;UAQ9D"}
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFlightsContext } from "../provider.js";
4
+ import { getAirlinesQueryOptions } from "../query-options.js";
5
+ /**
6
+ * Fetches the full airline reference list. Long-stale because airlines
7
+ * rarely change once seeded — the operator's reference table is a
8
+ * deliberate snapshot, not a live feed.
9
+ */
10
+ export function useAirlines(options = {}) {
11
+ const client = useVoyantFlightsContext();
12
+ const { enabled = true } = options;
13
+ return useQuery({
14
+ ...getAirlinesQueryOptions(client),
15
+ enabled,
16
+ staleTime: 24 * 60 * 60 * 1000,
17
+ });
18
+ }
@@ -0,0 +1,28 @@
1
+ export interface UseAirportSearchOptions {
2
+ /** Debounce on keystrokes, milliseconds. Default 200. */
3
+ debounceMs?: number;
4
+ /** Maximum results returned by the server. Default 25. */
5
+ limit?: number;
6
+ /** Disable network entirely (e.g. while combobox is closed). */
7
+ enabled?: boolean;
8
+ }
9
+ /**
10
+ * Debounced airport-search hook for combobox typeaheads. Tracks the
11
+ * raw input separately from the debounced server query so users can
12
+ * type freely without N round-trips. The query short-circuits when
13
+ * `enabled` is false or the debounced value is empty AND limit isn't
14
+ * set (callers that want a default open list should pass `limit`).
15
+ */
16
+ export declare function useAirportSearch(input: string, options?: UseAirportSearchOptions): import("@tanstack/react-query").UseQueryResult<{
17
+ data: {
18
+ iataCode: string;
19
+ name: string;
20
+ city: string;
21
+ country: string;
22
+ icaoCode?: string | null | undefined;
23
+ timezone?: string | null | undefined;
24
+ latitude?: number | null | undefined;
25
+ longitude?: number | null | undefined;
26
+ }[];
27
+ }, Error>;
28
+ //# sourceMappingURL=use-airport-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-airport-search.d.ts","sourceRoot":"","sources":["../../src/hooks/use-airport-search.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,uBAAuB;IACtC,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;;;;;;;;;;;UAcpF"}
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ import { useAirports } from "./use-airports.js";
4
+ /**
5
+ * Debounced airport-search hook for combobox typeaheads. Tracks the
6
+ * raw input separately from the debounced server query so users can
7
+ * type freely without N round-trips. The query short-circuits when
8
+ * `enabled` is false or the debounced value is empty AND limit isn't
9
+ * set (callers that want a default open list should pass `limit`).
10
+ */
11
+ export function useAirportSearch(input, options = {}) {
12
+ const { debounceMs = 200, limit = 25, enabled = true } = options;
13
+ const [debounced, setDebounced] = useState(input);
14
+ useEffect(() => {
15
+ const t = setTimeout(() => setDebounced(input), debounceMs);
16
+ return () => clearTimeout(t);
17
+ }, [input, debounceMs]);
18
+ return useAirports({
19
+ q: debounced.trim() || undefined,
20
+ limit,
21
+ enabled,
22
+ });
23
+ }
@@ -0,0 +1,21 @@
1
+ import type { AirportSearchFilters } from "../query-keys.js";
2
+ export interface UseAirportsOptions extends AirportSearchFilters {
3
+ enabled?: boolean;
4
+ }
5
+ /**
6
+ * Fetch the airport reference list. Use the `q` filter for substring
7
+ * search (city / IATA / name). Cached per-filter.
8
+ */
9
+ export declare function useAirports(options?: UseAirportsOptions): import("@tanstack/react-query").UseQueryResult<{
10
+ data: {
11
+ iataCode: string;
12
+ name: string;
13
+ city: string;
14
+ country: string;
15
+ icaoCode?: string | null | undefined;
16
+ timezone?: string | null | undefined;
17
+ latitude?: number | null | undefined;
18
+ longitude?: number | null | undefined;
19
+ }[];
20
+ }, Error>;
21
+ //# sourceMappingURL=use-airports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-airports.d.ts","sourceRoot":"","sources":["../../src/hooks/use-airports.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC9D,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB;;;;;;;;;;;UAQ3D"}
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFlightsContext } from "../provider.js";
4
+ import { getAirportsQueryOptions } from "../query-options.js";
5
+ /**
6
+ * Fetch the airport reference list. Use the `q` filter for substring
7
+ * search (city / IATA / name). Cached per-filter.
8
+ */
9
+ export function useAirports(options = {}) {
10
+ const client = useVoyantFlightsContext();
11
+ const { enabled = true, ...filters } = options;
12
+ return useQuery({
13
+ ...getAirportsQueryOptions(client, filters),
14
+ enabled,
15
+ staleTime: 24 * 60 * 60 * 1000,
16
+ });
17
+ }
@@ -0,0 +1,63 @@
1
+ import type { FlightOffer } from "@voyantjs/flights/contract/types";
2
+ export interface UseFlightAncillariesOptions {
3
+ /** Disable the query — useful before the offer is re-priced. */
4
+ enabled?: boolean;
5
+ /** TanStack Query stale time, milliseconds. Default 5 minutes. */
6
+ staleTime?: number;
7
+ }
8
+ /**
9
+ * POST `/v1/admin/flights/ancillaries` — fetches the bag/assistance/extras
10
+ * catalog for an offer. Catalog is offer-scoped; in the per-leg booking
11
+ * flow callers fire one query per leg and merge the picks at book time
12
+ * via `FlightBookRequest.ancillaries`.
13
+ *
14
+ * Default `enabled = false` so callers gate the query on having a valid
15
+ * (re-priced) offer in hand. When the connector doesn't declare
16
+ * `flight/ancillaries`, the API returns 501 — propagated as a query error.
17
+ */
18
+ export declare function useFlightAncillaries(input: {
19
+ offerId: string;
20
+ offer?: FlightOffer;
21
+ } | null, options?: UseFlightAncillariesOptions): import("@tanstack/react-query").UseQueryResult<{
22
+ catalog: {
23
+ baggage: {
24
+ id: string;
25
+ label: string;
26
+ category: "checked" | "cabin" | "personal_item" | "sports" | "oversized";
27
+ price: {
28
+ amount: string;
29
+ currency: string;
30
+ };
31
+ weightKg?: number | undefined;
32
+ dimensions?: {
33
+ lengthCm?: number | undefined;
34
+ widthCm?: number | undefined;
35
+ heightCm?: number | undefined;
36
+ } | undefined;
37
+ recommended?: boolean | undefined;
38
+ providerData?: Record<string, unknown> | undefined;
39
+ }[];
40
+ assistance: {
41
+ id: string;
42
+ label: string;
43
+ category: "wheelchair" | "visual" | "hearing" | "cognitive" | "medical" | "other";
44
+ price?: {
45
+ amount: string;
46
+ currency: string;
47
+ } | undefined;
48
+ notes?: string | undefined;
49
+ }[];
50
+ extras: {
51
+ id: string;
52
+ label: string;
53
+ category: string;
54
+ price: {
55
+ amount: string;
56
+ currency: string;
57
+ };
58
+ pricingScope?: "per_passenger" | "per_booking" | undefined;
59
+ }[];
60
+ };
61
+ validUntil?: string | undefined;
62
+ }, Error>;
63
+ //# sourceMappingURL=use-flight-ancillaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-flight-ancillaries.d.ts","sourceRoot":"","sources":["../../src/hooks/use-flight-ancillaries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAKnE,MAAM,WAAW,2BAA2B;IAC1C,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,EACtD,OAAO,GAAE,2BAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAU1C"}
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFlightsContext } from "../provider.js";
4
+ import { getFlightAncillariesQueryOptions } from "../query-options.js";
5
+ /**
6
+ * POST `/v1/admin/flights/ancillaries` — fetches the bag/assistance/extras
7
+ * catalog for an offer. Catalog is offer-scoped; in the per-leg booking
8
+ * flow callers fire one query per leg and merge the picks at book time
9
+ * via `FlightBookRequest.ancillaries`.
10
+ *
11
+ * Default `enabled = false` so callers gate the query on having a valid
12
+ * (re-priced) offer in hand. When the connector doesn't declare
13
+ * `flight/ancillaries`, the API returns 501 — propagated as a query error.
14
+ */
15
+ export function useFlightAncillaries(input, options = {}) {
16
+ const client = useVoyantFlightsContext();
17
+ const { enabled = false, staleTime = 5 * 60_000 } = options;
18
+ const safeInput = input ?? { offerId: "" };
19
+ return useQuery({
20
+ ...getFlightAncillariesQueryOptions(client, safeInput),
21
+ enabled: enabled && !!input?.offerId,
22
+ staleTime,
23
+ });
24
+ }
@@ -0,0 +1,139 @@
1
+ import type { FlightBookRequest } from "@voyantjs/flights/contract/types";
2
+ /**
3
+ * POST `/v1/admin/flights/book` — books the offer with the given passengers
4
+ * and contact info. Mutation; on success invalidates the order query so the
5
+ * confirmation page reads the just-created record.
6
+ */
7
+ export declare function useFlightBook(): import("@tanstack/react-query").UseMutationResult<{
8
+ order: {
9
+ orderId: string;
10
+ status: "pending" | "confirmed" | "ticketed" | "cancelled" | "failed";
11
+ offer: {
12
+ offerId: string;
13
+ source: string;
14
+ itineraries: {
15
+ segments: {
16
+ segmentId: string;
17
+ carrierCode: string;
18
+ flightNumber: string;
19
+ departure: {
20
+ iataCode: string;
21
+ at: string;
22
+ terminal?: string | undefined;
23
+ };
24
+ arrival: {
25
+ iataCode: string;
26
+ at: string;
27
+ terminal?: string | undefined;
28
+ };
29
+ cabin: "economy" | "premium_economy" | "business" | "first";
30
+ operatingCarrierCode?: string | undefined;
31
+ operatingFlightNumber?: string | undefined;
32
+ duration?: string | undefined;
33
+ aircraft?: string | undefined;
34
+ fareClass?: string | undefined;
35
+ fareBasis?: string | undefined;
36
+ status?: string | undefined;
37
+ providerData?: Record<string, unknown> | undefined;
38
+ }[];
39
+ duration?: string | undefined;
40
+ }[];
41
+ fareBreakdowns: {
42
+ passengerType: "adult" | "child" | "infant" | "senior" | "youth";
43
+ passengerCount: number;
44
+ baseFare: {
45
+ amount: string;
46
+ currency: string;
47
+ };
48
+ taxes: {
49
+ amount: string;
50
+ currency: string;
51
+ };
52
+ total: {
53
+ amount: string;
54
+ currency: string;
55
+ };
56
+ fees?: {
57
+ amount: string;
58
+ currency: string;
59
+ } | undefined;
60
+ fareFamily?: string | undefined;
61
+ }[];
62
+ totalPrice: {
63
+ amount: string;
64
+ currency: string;
65
+ };
66
+ validatingCarrier?: string | undefined;
67
+ expiresAt?: string | undefined;
68
+ lastTicketingDate?: string | undefined;
69
+ instantTicketing?: boolean | undefined;
70
+ fareBundles?: {
71
+ id: string;
72
+ label: string;
73
+ tier: "basic" | "standard" | "plus" | "premium";
74
+ priceDelta: {
75
+ amount: string;
76
+ currency: string;
77
+ };
78
+ inclusions: {
79
+ cabinBag?: {
80
+ included: boolean;
81
+ weightKg?: number | undefined;
82
+ } | undefined;
83
+ checkedBag?: {
84
+ included: boolean;
85
+ pieces?: number | undefined;
86
+ weightKg?: number | undefined;
87
+ } | undefined;
88
+ seatSelection?: "standard" | "none" | "free" | undefined;
89
+ priorityBoarding?: boolean | undefined;
90
+ loungeAccess?: boolean | undefined;
91
+ refundable?: boolean | undefined;
92
+ changeable?: boolean | undefined;
93
+ notes?: string[] | undefined;
94
+ };
95
+ recommended?: boolean | undefined;
96
+ providerData?: Record<string, unknown> | undefined;
97
+ }[] | undefined;
98
+ providerData?: Record<string, unknown> | undefined;
99
+ };
100
+ passengers: {
101
+ passengerId: string;
102
+ type: "adult" | "child" | "infant" | "senior" | "youth";
103
+ firstName: string;
104
+ lastName: string;
105
+ dateOfBirth: string;
106
+ middleName?: string | undefined;
107
+ gender?: "M" | "F" | "X" | undefined;
108
+ email?: string | undefined;
109
+ phone?: string | undefined;
110
+ documents?: {
111
+ type: "passport" | "national_id" | "visa";
112
+ number: string;
113
+ countryOfIssue: string;
114
+ countryOfNationality?: string | undefined;
115
+ expiryDate?: string | undefined;
116
+ }[] | undefined;
117
+ }[];
118
+ totalPrice: {
119
+ amount: string;
120
+ currency: string;
121
+ };
122
+ createdAt: string;
123
+ pnr?: string | undefined;
124
+ contact?: {
125
+ email?: string | undefined;
126
+ phone?: string | undefined;
127
+ } | undefined;
128
+ tickets?: {
129
+ ticketNumber: string;
130
+ passengerId: string;
131
+ segmentIds: string[];
132
+ status?: string | undefined;
133
+ }[] | undefined;
134
+ paymentDeadline?: string | undefined;
135
+ updatedAt?: string | undefined;
136
+ providerData?: Record<string, unknown> | undefined;
137
+ };
138
+ }, Error, FlightBookRequest, unknown>;
139
+ //# sourceMappingURL=use-flight-book.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-flight-book.d.ts","sourceRoot":"","sources":["../../src/hooks/use-flight-book.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAOzE;;;;GAIG;AACH,wBAAgB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sCAa5B"}
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantFlightsContext } from "../provider.js";
5
+ import { flightsQueryKeys } from "../query-keys.js";
6
+ import { flightBookResponseSchema } from "../schemas.js";
7
+ /**
8
+ * POST `/v1/admin/flights/book` — books the offer with the given passengers
9
+ * and contact info. Mutation; on success invalidates the order query so the
10
+ * confirmation page reads the just-created record.
11
+ */
12
+ export function useFlightBook() {
13
+ const client = useVoyantFlightsContext();
14
+ const qc = useQueryClient();
15
+ return useMutation({
16
+ mutationFn: (input) => fetchWithValidation("/v1/admin/flights/book", flightBookResponseSchema, client, {
17
+ method: "POST",
18
+ body: JSON.stringify(input),
19
+ }),
20
+ onSuccess: (data) => {
21
+ qc.setQueryData(flightsQueryKeys.orderDetail(data.order.orderId), { order: data.order });
22
+ },
23
+ });
24
+ }