import {z} from 'zod' export type FlightOfferSource = 'GDS'; export type TravelClass = 'ECONOMY' | 'PREMIUM_ECONOMY' | 'BUSINESS' | 'FIRST'; export type Co2Emission = {weight?: number | undefined, weightUnit?: string | undefined, cabin?: TravelClass | undefined}; export type FlightEndPoint = {iataCode?: string | undefined, terminal?: string | undefined, at?: string | undefined}; export type AircraftEquipment = {code?: string | undefined}; export type OperatingFlight = {carrierCode?: string | undefined, number?: string | undefined, suffix?: string | undefined}; export type FlightStop = {iataCode?: string | undefined, newAircraft?: AircraftEquipment | undefined, duration?: string | undefined, arrivalAt?: string | undefined, departureAt?: string | undefined}; export type Segment = {id?: string | undefined, numberOfStops?: number | undefined, blacklistedInEU?: boolean | undefined, co2Emissions?: Array | undefined, departure?: FlightEndPoint | undefined, arrival?: FlightEndPoint | undefined, carrierCode?: string | undefined, number?: string | undefined, aircraft?: AircraftEquipment | undefined, operating?: OperatingFlight | undefined, duration?: string | undefined, stops?: Array | undefined}; export type AdditionalServiceType = 'CHECKED_BAGS' | 'MEALS' | 'SEATS' | 'OTHER_SERVICES'; export type FeeType = 'TICKETING' | 'FORM_OF_PAYMENT' | 'SUPPLIER'; export type Fee = {amount?: string | undefined, type?: FeeType | undefined}; export type Tax = {amount?: string | undefined, code?: string | undefined}; export type ExtendedPrice = {margin?: string | undefined, grandTotal?: string | undefined, billingCurrency?: string | undefined, additionalServices?: (Array<{amount?: string | undefined, type?: AdditionalServiceType | undefined}>) | undefined, currency?: string | undefined, total?: string | undefined, base?: string | undefined, fees?: Array | undefined, taxes?: Array | undefined}; export type PricingOptionsFareType = Array<'PUBLISHED' | 'NEGOTIATED' | 'CORPORATE'>; export type TravelerPricingFareOption = 'STANDARD' | 'INCLUSIVE_TOUR' | 'SPANISH_MELILLA_RESIDENT' | 'SPANISH_CEUTA_RESIDENT' | 'SPANISH_CANARY_RESIDENT' | 'SPANISH_BALEARIC_RESIDENT' | 'AIR_FRANCE_METROPOLITAN_DISCOUNT_PASS' | 'AIR_FRANCE_DOM_DISCOUNT_PASS' | 'AIR_FRANCE_COMBINED_DISCOUNT_PASS' | 'AIR_FRANCE_FAMILY' | 'ADULT_WITH_COMPANION' | 'COMPANION'; export type TravelerType = 'ADULT' | 'CHILD' | 'SENIOR' | 'YOUNG' | 'HELD_INFANT' | 'SEATED_INFANT' | 'STUDENT'; export type Price = {currency?: string | undefined, total?: string | undefined, base?: string | undefined, fees?: Array | undefined, taxes?: Array | undefined}; export type SliceDiceIndicator = 'LOCAL_AVAILABILITY' | 'SUB_OD_AVAILABILITY_1' | 'SUB_OD_AVAILABILITY_2'; export type ElementaryPrice = {amount?: string | undefined, currencyCode?: string | undefined}; export type BaggageAllowance = {excessRate?: ElementaryPrice | undefined, quantity?: number | undefined, weight?: number | undefined, weightUnit?: string | undefined}; export type ServiceName = 'PRIORITY_BOARDING' | 'AIRPORT_CHECKIN'; export type TermAndCondition = {category?: ('REFUND' | 'EXCHANGE' | 'REVALIDATION' | 'REISSUE' | 'REBOOK' | 'CANCELLATION') | undefined, circumstances?: string | undefined, notApplicable?: boolean | undefined, maxPenaltyAmount?: string | undefined, descriptions?: (Array<{descriptionType?: string | undefined, text?: string | undefined}>) | undefined}; export type FareRules = {currency?: string | undefined, rules?: Array | undefined}; export type FlightOffer = {type: string, id: string, source?: FlightOfferSource | undefined, instantTicketingRequired?: boolean | undefined, disablePricing?: boolean | undefined, nonHomogeneous?: boolean | undefined, oneWay?: boolean | undefined, paymentCardRequired?: boolean | undefined, lastTicketingDate?: string | undefined, numberOfBookableSeats?: number | undefined, itineraries?: (Array<{duration?: string | undefined, segments: Array}>) | undefined, price?: ExtendedPrice | undefined, pricingOptions?: ({fareType?: PricingOptionsFareType | undefined, corporateCodes?: Array | undefined, includedCheckedBagsOnly?: boolean | undefined, refundableFare?: boolean | undefined, noRestrictionFare?: boolean | undefined, noPenaltyFare?: boolean | undefined}) | undefined, validatingAirlineCodes?: Array | undefined, travelerPricings?: (Array<{travelerId: string, fareOption: TravelerPricingFareOption, travelerType: TravelerType, associatedAdultId?: string | undefined, price?: Price | undefined, fareDetailsBySegment: Array<{segmentId: string, cabin?: TravelClass | undefined, fareBasis?: string | undefined, brandedFare?: string | undefined, class?: string | undefined, isAllotment?: boolean | undefined, allotmentDetails?: ({tourName?: string | undefined, tourReference?: string | undefined}) | undefined, sliceDiceIndicator?: SliceDiceIndicator | undefined, includedCheckedBags?: BaggageAllowance | undefined, additionalServices?: ({chargeableCheckedBags?: BaggageAllowance | undefined, chargeableSeatNumber?: string | undefined, otherServices?: Array | undefined}) | undefined}>}>) | undefined, fareRules?: FareRules | undefined}; export type CreateApiShoppingSeatmapsArgs = {'X-HTTP-Method-Override': string, body: {data: Array, included?: {travelers: unknown} | undefined}}; export type CreateApiShoppingSeatmapsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const collectionMeta = z.object({count: z.number().int().optional(), links: z.object({self: z.string().optional(), next: z.string().optional(), previous: z.string().optional(), last: z.string().optional(), first: z.string().optional(), up: z.string().optional()}).optional()}); export const issue = z.object({status: z.number().int().optional(), code: z.number().int().optional(), title: z.string().optional(), detail: z.string().optional(), source: z.object({pointer: z.string().optional(), parameter: z.string().optional(), example: z.string().optional()}).optional()}); export const link = z.object({href: z.string(), methods: z.array(z.enum(["GET", "PUT", "DELETE", "POST", "PATCH"])).optional(), count: z.number().int().optional()}); export const flightEndPoint = z.object({iataCode: z.string().optional(), terminal: z.string().optional(), at: z.string().optional()}); export const operatingFlight = z.object({carrierCode: z.string().min(1).max(2).optional(), number: z.string().min(1).max(4).optional(), suffix: z.string().min(1).max(4).optional()}); export const aircraftEquipment = z.object({code: z.string().optional()}); export const deckConfiguration = z.object({width: z.number().int().optional(), length: z.number().int().optional(), startSeatRow: z.number().int().optional(), endSeatRow: z.number().int().optional(), startWingsX: z.number().int().optional(), endWingsX: z.number().int().optional(), startWingsRow: z.number().int().optional(), endWingsRow: z.number().int().optional(), exitRowsX: z.array(z.number().int()).optional()}); export const coordinates = z.object({x: z.number().int().optional(), y: z.number().int().optional()}); export const facility = z.object({code: z.string().optional(), column: z.string().optional(), row: z.string().optional(), position: z.enum(["FRONT", "REAR", "SEAT"]).optional(), coordinates: coordinates.optional()}); export const feeType = z.enum(["TICKETING", "FORM_OF_PAYMENT", "SUPPLIER"]); export const fee = z.object({amount: z.string().optional(), type: feeType.optional()}); export const tax = z.object({amount: z.string().optional(), code: z.string().optional()}); export const price = z.object({currency: z.string().optional(), total: z.string().optional(), base: z.string().optional(), fees: z.array(fee).optional(), taxes: z.array(tax).optional()}); export const seatmapTravelerPricing = z.object({travelerId: z.string().optional(), seatAvailabilityStatus: z.enum(["AVAILABLE", "BLOCKED", "OCCUPIED"]).optional(), price: price.optional()}); export const seat = z.object({cabin: z.string().optional(), number: z.string().optional(), characteristicsCodes: z.array(z.string()).optional(), travelerPricing: z.array(seatmapTravelerPricing).optional(), coordinates: coordinates.optional()}); export const deck = z.object({deckType: z.enum(["UPPER", "MAIN", "LOWER"]).optional(), deckConfiguration: deckConfiguration.optional(), facilities: z.array(facility).optional(), seats: z.array(seat).optional()}); export const aircraftCabinAmenitiesPower = z.object({isChargeable: z.boolean().optional(), powerType: z.enum(["PLUG", "USB_PORT", "ADAPTOR", "PLUG_OR_USB_PORT"]).optional(), usbType: z.enum(["USB_A", "USB_C", "USB_A_AND_USB_C"]).optional()}); export const qualifiedFreeText = z.object({text: z.string().optional(), lang: z.string().optional()}); export const amenityMedia = z.object({title: z.string().optional(), href: z.string().optional(), description: qualifiedFreeText.optional(), mediaType: z.enum(["application", "audio", "font", "example", "image", "message", "model", "multipart", "text", "video"]).optional()}); export const amenitySeat = z.object({legSpace: z.number().int().optional(), spaceUnit: z.enum(["INCHES", "CENTIMENTERS"]).optional(), tilt: z.enum(["FULL_FLAT", "ANGLE_FLAT", "NORMAL"]).optional(), amenityType: z.literal("SEAT").optional(), medias: z.array(amenityMedia).optional()}); export const aircraftCabinAmenitiesWifi = z.object({isChargeable: z.boolean().optional(), wifiCoverage: z.enum(["FULL", "PARTIAL"]).optional()}); export const aircraftCabinAmenitiesEntertainment = z.object({isChargeable: z.boolean().optional(), entertainmentType: z.enum(["LIVE_TV", "MOVIES", "AUDIO_VIDEO_ON_DEMAND", "TV_SHOWS", "IP_TV"]).optional()}); export const aircraftCabinAmenitiesFood = z.object({isChargeable: z.boolean().optional(), foodType: z.enum(["MEAL", "FRESH_MEAL", "SNACK", "FRESH_SNACK"]).optional()}); export const aircraftCabinAmenitiesBeverage = z.object({isChargeable: z.boolean().optional(), beverageType: z.enum(["ALCOHOLIC", "NON_ALCOHOLIC", "ALCOHOLIC_AND_NON_ALCOHOLIC"]).optional()}); export const aircraftCabinAmenities = z.object({power: aircraftCabinAmenitiesPower.optional(), seat: amenitySeat.optional(), wifi: aircraftCabinAmenitiesWifi.optional(), entertainment: z.array(aircraftCabinAmenitiesEntertainment).optional(), food: aircraftCabinAmenitiesFood.optional(), beverage: aircraftCabinAmenitiesBeverage.optional()}); export const availableSeatsCounter = z.object({travelerId: z.string().optional(), value: z.number().int().optional()}); export const seatMap = z.object({type: z.string().optional(), id: z.string().optional(), self: link.optional(), departure: flightEndPoint.optional(), arrival: flightEndPoint.optional(), carrierCode: z.string().min(1).max(2).optional(), number: z.string().min(1).max(4).optional(), operating: operatingFlight.optional(), aircraft: aircraftEquipment.optional(), class: z.string().min(1).max(2).optional(), flightOfferId: z.string().optional(), segmentId: z.string().optional(), decks: z.array(deck).optional(), aircraftCabinAmenities: aircraftCabinAmenities.optional(), availableSeatsCounters: z.array(availableSeatsCounter).optional()}); export const locationEntry = z.unknown(); export const facilityDictionary = z.record(z.string(), z.string()); export const seatCharacteristicDictionary = z.record(z.string(), z.string()); export const createApiShoppingSeatmapsResponse = z.object({meta: collectionMeta.optional(), warnings: z.array(issue).optional(), data: z.array(seatMap), dictionaries: z.object({locations: locationEntry.optional(), facilities: facilityDictionary.optional(), seatCharacteristics: seatCharacteristicDictionary.optional()}).optional()}); 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 }; /** * Returns all the seat maps of a given flightOffer. * * POST /shopping/seatmaps */ export const createApiShoppingSeatmaps = async (args: CreateApiShoppingSeatmapsArgs, options?: CreateApiShoppingSeatmapsOptions) => { const {baseUrl = "https://test.api.amadeus.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.amadeus+json") headers.set('accept', "application/vnd.amadeus+json") if (args['X-HTTP-Method-Override'] != null) headers.set("X-HTTP-Method-Override", String(args['X-HTTP-Method-Override'])) const url = `${baseUrl.replace(/\/+$/, '')}/shopping/seatmaps${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiShoppingSeatmapsResponse, await res.json()) };