import {z} from 'zod' export type UpdateApiAccountsEntitiesIdBusinessDetailsArgs = {id: string, body: {status?: ('active' | 'pending') | undefined, legal_name: string, trading_name: string, additional_trading_names?: Array | undefined, registered_address: {address_line1: string, address_line2?: (string | null) | undefined, city: string, state?: string | undefined, zip: string | null, country: unknown}, principal_address: {address_line1: string, address_line2?: (string | null) | undefined, city: string, state?: string | undefined, zip: string | null, country: unknown}, documents?: ({company_verification?: {type: 'incorporation_document', front: string} | undefined, proof_of_principal_address?: {type: 'proof_of_address', front: string} | undefined, proof_of_registered_address?: {type: 'proof_of_address', front: string} | undefined}) | undefined} | {status?: ('active' | 'pending') | undefined, trading_name: string, additional_trading_names?: Array | undefined, principal_address: {address_line1: string, address_line2?: (string | null) | undefined, city: string, state?: string | undefined, zip: string | null, country: unknown}, documents?: ({company_verification?: {type: 'incorporation_document', front: string} | undefined, proof_of_principal_address?: {type: 'proof_of_address', front: string} | undefined}) | undefined}}; export type UpdateApiAccountsEntitiesIdBusinessDetailsOptions = {baseUrl: string, OAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiAccountsEntitiesIdBusinessDetailsResponse = z.union([z.object({status: z.enum(["active", "pending"]).optional(), legal_name: z.string().min(2).max(300), trading_name: z.string().min(2).max(300), additional_trading_names: z.array(z.string().min(2).max(300)).optional(), registered_address: z.object({address_line1: z.string().min(1).max(300), address_line2: z.string().max(300).nullable().optional(), city: z.string().min(2).max(300), state: z.string().min(1).max(300).optional(), zip: z.string().max(16).nullable(), country: z.string().min(2).max(2)}), principal_address: z.object({address_line1: z.string().min(1).max(300), address_line2: z.string().max(300).nullable().optional(), city: z.string().min(2).max(300), state: z.string().min(1).max(300).optional(), zip: z.string().max(16).nullable(), country: z.string().min(2).max(2)}), documents: z.object({company_verification: z.object({type: z.literal("incorporation_document"), front: z.string().min(31).max(31)}).optional(), proof_of_principal_address: z.object({type: z.literal("proof_of_address"), front: z.string().min(31).max(31)}).optional(), proof_of_registered_address: z.object({type: z.literal("proof_of_address"), front: z.string().min(31).max(31)}).optional()}).optional()}), z.object({status: z.enum(["active", "pending"]).optional(), trading_name: z.string().min(2).max(300), additional_trading_names: z.array(z.string().min(2).max(300)).optional(), principal_address: z.object({address_line1: z.string().min(1).max(300), address_line2: z.string().max(300).nullable().optional(), city: z.string().min(2).max(300), state: z.string().min(1).max(300).optional(), zip: z.string().max(16).nullable(), country: z.string().min(2).max(2)}), documents: z.object({company_verification: z.object({type: z.literal("incorporation_document"), front: z.string().min(31).max(31)}).optional(), proof_of_principal_address: z.object({type: z.literal("proof_of_address"), front: z.string().min(31).max(31)}).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 }; /** * Update a sub-entity's business details * * PUT /accounts/entities/{id}/business-details * * Also accepts auth: ApiSecretKey */ export const updateApiAccountsEntitiesIdBusinessDetails = async (args: UpdateApiAccountsEntitiesIdBusinessDetailsArgs, options: UpdateApiAccountsEntitiesIdBusinessDetailsOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth !== undefined) headers.set('authorization', `Bearer ${OAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/entities/${encodeURIComponent(String(args.id))}/business-details${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiAccountsEntitiesIdBusinessDetailsResponse, await res.json()) };