import {z} from 'zod' export type HotelTypeInputDTO = {hotel_type_ids?: Array | undefined, languages?: (Array<'ar' | 'bg' | 'ca' | 'cs' | 'da' | 'de' | 'el' | 'en' | 'en-gb' | 'en-us' | 'es' | 'es-ar' | 'es-mx' | 'et' | 'fi' | 'fr' | 'he' | 'hi' | 'hr' | 'hu' | 'id' | 'is' | 'it' | 'ja' | 'ka' | 'ko' | 'lt' | 'lv' | 'ms' | 'nl' | 'no' | 'pl' | 'pt-br' | 'pt-pt' | 'pt' | 'ro' | 'ru' | 'sk' | 'sl' | 'sr' | 'sv' | 'th' | 'tl' | 'tr' | 'uk' | 'vi' | 'zh' | 'zh-cn' | 'zh-tw'>) | undefined, offset?: number | undefined, row?: number | undefined}; export type GetApiDemandApiV2CompatibleHotelTypesArgs = {hotelTypeInputDTO: HotelTypeInputDTO, Accept?: 'application/json' | undefined}; export type GetApiDemandApiV2CompatibleHotelTypesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const meta = z.object({ruid: z.string().optional()}); export const translationDto = z.object({language: z.string().optional(), name: z.string().optional()}); export const hotelTypesOutputDto = z.object({translations: z.array(translationDto).optional(), name: z.string().optional(), hotel_type_id: z.number().int().optional()}); export const responseOutputV2HotelTypesOutputDto = z.object({meta: meta.optional(), result: z.array(hotelTypesOutputDto).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 }; /** * List hotel types * * GET /demand-api-v2-compatible/hotelTypes */ export const getApiDemandApiV2CompatibleHotelTypes = async (args: GetApiDemandApiV2CompatibleHotelTypesArgs, options?: GetApiDemandApiV2CompatibleHotelTypesOptions) => { const {baseUrl = "https://metasearch-connect-api.booking.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.hotelTypeInputDTO != null) query.append("hotelTypeInputDTO", JSON.stringify(args.hotelTypeInputDTO)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/demand-api-v2-compatible/hotelTypes${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(responseOutputV2HotelTypesOutputDto, await res.json()) };