import {z} from 'zod' export type GetApiOffersFaresDeeplinkItcoArgs = {catalogues: string, origin: string, destination: string, 'travel-date': string, 'outbound-segments': string, fare: string, 'fare-currency': string, trackingid: string, country: string, lang: string, Accept: string, 'return-date'?: string | undefined, 'cabin-class'?: string | undefined, 'return-segments'?: string | undefined, travelers?: string | undefined, 'net-fare'?: string | undefined, partnerid?: string | undefined, 'encryption-key'?: string | undefined}; export type GetApiOffersFaresDeeplinkItcoOptions = {baseUrl?: string | undefined, auth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiOffersFaresDeeplinkItcoResponse = z.string(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * LH Deep Links - ITCO * * GET /offers/fares/deeplink/itco */ export const getApiOffersFaresDeeplinkItco = async (args: GetApiOffersFaresDeeplinkItcoArgs, options?: GetApiOffersFaresDeeplinkItcoOptions) => { const {baseUrl = "https://api.lufthansa.com/v1", fetch: fetchFn = fetch, auth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.catalogues != null) query.append("catalogues", String(args.catalogues)) if (args.origin != null) query.append("origin", String(args.origin)) if (args.destination != null) query.append("destination", String(args.destination)) if (args['travel-date'] != null) query.append("travel-date", String(args['travel-date'])) if (args['outbound-segments'] != null) query.append("outbound-segments", String(args['outbound-segments'])) if (args.fare != null) query.append("fare", String(args.fare)) if (args['fare-currency'] != null) query.append("fare-currency", String(args['fare-currency'])) if (args.trackingid != null) query.append("trackingid", String(args.trackingid)) if (args.country != null) query.append("country", String(args.country)) if (args.lang != null) query.append("lang", String(args.lang)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['return-date'] != null) query.append("return-date", String(args['return-date'])) if (args['cabin-class'] != null) query.append("cabin-class", String(args['cabin-class'])) if (args['return-segments'] != null) query.append("return-segments", String(args['return-segments'])) if (args.travelers != null) query.append("travelers", String(args.travelers)) if (args['net-fare'] != null) query.append("net-fare", String(args['net-fare'])) if (args.partnerid != null) query.append("partnerid", String(args.partnerid)) if (args['encryption-key'] != null) query.append("encryption-key", String(args['encryption-key'])) if (auth !== undefined) headers.set('authorization', `Bearer ${auth}`) const url = `${baseUrl.replace(/\/+$/, '')}/offers/fares/deeplink/itco${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiOffersFaresDeeplinkItcoResponse, await res.json()) };