import {z} from 'zod' export type GetApiV1BusinessProfileBusinessProfileIdArgs = {business_profile_id: string}; export type GetApiV1BusinessProfileBusinessProfileIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiV1BusinessProfileBusinessProfileIdResponse = z.object({id: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), kyb_type: z.enum(["receive-only", "unverified", "verified"]).optional(), business_info: z.object({business_name: z.string().optional(), business_type: z.enum(["soleProprietorship", "corporation", "llc", "nonprofit", "partnership"]).optional(), ein: z.string().optional(), doing_business_as: z.string().optional(), phone: z.string().optional(), address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional(), website: z.string().optional()}).optional(), business_admin: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional()}).optional(), business_controller: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), title: z.string().optional(), address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postal_code: z.string().optional()}).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 a Business Profile * * GET /v1/business_profile/{business_profile_id} */ export const getApiV1BusinessProfileBusinessProfileId = async (args: GetApiV1BusinessProfileBusinessProfileIdArgs, options?: GetApiV1BusinessProfileBusinessProfileIdOptions) => { const {baseUrl = "https://api-sandbox.astra.finance", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/business_profile/${encodeURIComponent(String(args.business_profile_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(getApiV1BusinessProfileBusinessProfileIdResponse, await res.json()) };