import {z} from 'zod' export type GetApiV3BrandsIdArgs = {id: string, 'fields[brand]'?: string | undefined, 'Accept-Language'?: string | undefined}; export type GetApiV3BrandsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const brand = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({name: z.string().optional(), google_tag_manager_mode: z.enum(["gtm_disabled", "basic", "server_side", "first_party"]).optional(), google_tag_manager_key: z.string().optional(), google_tag_manager_host: z.string().optional(), google_tag_manager_path: z.string().optional(), tagging_server_host: z.string().optional(), google_maps_key: z.string().optional(), primary_color: z.string().optional(), secondary_color: z.string().optional(), text_color: z.string().optional(), background_color: z.string().optional(), header_text_color: z.string().optional(), header_background_color: z.string().optional(), cookie_consent: z.boolean().optional(), cookie_consent_description: 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(), cookie_consent_buttons_layout: z.string().optional(), logo: z.string().optional(), logo_on_white: z.string().optional(), favicon: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const getApiV3BrandsIdResponse = z.object({data: brand.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 brand * * GET /v3/brands/{id} * * Also accepts auth: OAuth2 */ export const getApiV3BrandsId = async (args: GetApiV3BrandsIdArgs, options?: GetApiV3BrandsIdOptions) => { 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[brand]'] != null) query.append("fields[brand]", String(args['fields[brand]'])) 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/brands/${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(getApiV3BrandsIdResponse, await res.json()) };