import {z} from 'zod' export type CreateApiBusinessesIdRegistrationInformationArgs = {id: string, body: {business_name?: (string | null) | undefined, business_type?: (string | null) | undefined, business_industry?: (string | null) | undefined, business_registration_identifier?: (string | null) | undefined, business_registration_number?: (string | null) | undefined, business_identity?: (string | null) | undefined, business_regime_of_operation?: (string | null) | undefined, company_type?: (string | null) | undefined, website_url?: (string | null) | undefined, social_media_profiles_urls?: Array | undefined, street_address?: (string | null) | undefined, street_address_line_2?: (string | null) | undefined, city?: (string | null) | undefined, region?: (string | null) | undefined, postal_code?: (string | null) | undefined, iso_country_code?: (string | null) | undefined, contact?: ({first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, title?: (string | null) | undefined, job_position?: (string | null) | undefined, phone_number?: (string | null) | undefined, email_address?: (string | null) | undefined} | null) | undefined, supplemental_links?: Array | undefined, privacy_policy_link?: (string | null) | undefined, preferred_phone_number_prefixes?: Array | undefined}}; export type CreateApiBusinessesIdRegistrationInformationOptions = {baseUrl?: string | undefined, HttpBasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const businessRegistrationInformation = z.object({id: z.string(), business_name: z.string().nullable(), business_type: z.string().nullable(), business_industry: z.string().nullable(), business_registration_identifier: z.string().nullable(), business_registration_number: z.string().nullable(), business_identity: z.string().nullable(), business_regime_of_operation: z.string().nullable(), company_type: z.string().nullable(), website_url: z.string().nullable(), social_media_profiles_urls: z.array(z.string()), street_address: z.string().nullable(), street_address_line_2: z.string().nullable(), city: z.string().nullable(), region: z.string().nullable(), postal_code: z.string().nullable(), iso_country_code: z.string().nullable(), contact: z.object({first_name: z.string().nullable(), last_name: z.string().nullable(), title: z.string().nullable(), job_position: z.string().nullable(), phone_number: z.string().nullable(), email_address: z.string().nullable()}).nullable(), supplemental_links: z.array(z.string()), privacy_policy_link: z.string().nullable(), preferred_phone_number_prefixes: z.array(z.string())}); 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 }; /** * Create or update business registration information * * POST /businesses/{id}/registration_information */ export const createApiBusinessesIdRegistrationInformation = async (args: CreateApiBusinessesIdRegistrationInformationArgs, options?: CreateApiBusinessesIdRegistrationInformationOptions) => { const {baseUrl = "https://api.pocketflows.com", fetch: fetchFn = fetch, HttpBasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HttpBasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${HttpBasicAuth.username}:${HttpBasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/businesses/${encodeURIComponent(String(args.id))}/registration_information${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(businessRegistrationInformation, await res.json()) };