import {z} from 'zod' export type GetApiV3RentableSegmentsIdArgs = {id: string, 'fields[rentable_segment]'?: string | undefined, 'Accept-Language'?: string | undefined}; export type GetApiV3RentableSegmentsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const rentableSegment = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({name: z.object({cs: z.string().optional(), "da-DK": z.string().optional(), de: z.string().optional(), "de-AT": z.string().optional(), "de-CH": z.string().optional(), "en-US": z.string().optional(), "en-GB": z.string().optional(), es: z.string().optional(), fr: z.string().optional(), "fr-BE": z.string().optional(), "fr-LU": z.string().optional(), it: z.string().optional(), nb: z.string().optional(), nl: z.string().optional(), "nl-BE": z.string().optional(), pl: z.string().optional(), pt: z.string().optional(), tr: z.string().optional(), en: z.string().optional(), da: z.string().optional()}).optional(), semantic_segment: z.enum(["house", "pitch", "room", "berth", "apartment", "other", "year_site", "b_and_b", "bungalow", "cabin", "campervan_pitch", "caravan_pitch", "chalet", "cottage", "glamping_tent", "hotel_room", "houseboat", "mobile_home", "owners_managers_residence", "parking_place", "private_bathroom", "recreational_vehicle", "tent_pitch", "tiny_house", "treehouse", "villa"]).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const getApiV3RentableSegmentsIdResponse = z.object({data: rentableSegment.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 }; /** * GET rentable_segment * * GET /v3/rentable_segments/{id} * * Also accepts auth: OAuth2 */ export const getApiV3RentableSegmentsId = async (args: GetApiV3RentableSegmentsIdArgs, options?: GetApiV3RentableSegmentsIdOptions) => { const {baseUrl = "https://api.bookingexperts.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (args['fields[rentable_segment]'] != null) query.append("fields[rentable_segment]", String(args['fields[rentable_segment]'])) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/rentable_segments/${encodeURIComponent(String(args.id))}${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(getApiV3RentableSegmentsIdResponse, await res.json()) };