import {z} from 'zod' export type GetApiV3CustomersIdArgs = {id: string, 'fields[customer]'?: string | undefined, include?: string | undefined, 'Accept-Language'?: string | undefined}; export type GetApiV3CustomersIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customer = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({receive_newsletter: z.boolean().optional(), title: z.enum(["mr", "ms", "family", "mrs", "miss", "mx", "dr", "prof", "rev", "sir", "dame", "lord", "lady"]).optional(), first_name: z.string().optional(), last_name: z.string().optional(), phone: z.string().optional(), email: z.string().optional(), is_company: z.boolean().optional(), company: z.string().optional(), vat_nr: z.string().optional(), business_registration_number: z.string().optional(), date_of_birth: z.string().optional(), gender: z.enum(["male", "female", "other", "prefer_not_to_say"]).optional(), address: z.string().optional(), number: z.string().optional(), postalcode: z.string().optional(), city: z.string().optional(), country_code: z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW", "XK", "AN", "ZZ", "WW"]).optional(), locale: z.enum(["cs", "da-DK", "de", "de-AT", "de-CH", "en-US", "en-GB", "es", "fr", "fr-BE", "fr-LU", "it", "nb", "nl", "nl-BE", "pl", "pt", "tr", "en", "da"]).optional(), debtor_code: z.string().optional(), debtor_codes: z.array(z.string()).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), relationships: z.object({labels: z.object({data: z.array(z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()})).optional()}).optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const label = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({name: z.string().optional(), background: z.string().optional(), foreground: z.string().optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const getApiV3CustomersIdResponse = z.object({data: customer.optional(), included: z.array(label).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 customer * * GET /v3/customers/{id} * * Also accepts auth: OAuth2 */ export const getApiV3CustomersId = async (args: GetApiV3CustomersIdArgs, options?: GetApiV3CustomersIdOptions) => { 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[customer]'] != null) query.append("fields[customer]", String(args['fields[customer]'])) if (args.include != null) query.append("include", String(args.include)) 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/customers/${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(getApiV3CustomersIdResponse, await res.json()) };