import {z} from 'zod' export type PatchApiBankingEntitiesEntityIdArgs = {entity_id: string, body: {account_id: string, merchant_entity_id?: string | undefined, phone?: ({country_code?: string | undefined, number?: string | undefined}) | undefined, address?: ({address_line_1?: string | undefined, address_line_2?: (string | null) | undefined, building_number_1?: (string | null) | undefined, building_number_2?: (string | null) | undefined, city?: string | undefined, state?: string | undefined, zip_code?: string | undefined, country?: string | undefined}) | undefined, entity_detail?: ({individual?: ({email?: string | undefined, country_of_residence?: string | undefined} | null) | undefined, entity?: ({name?: string | undefined} | null) | undefined}) | undefined}}; export type PatchApiBankingEntitiesEntityIdOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiBankingEntitiesEntityIdResponse = z.object({id: z.string().optional(), account_id: z.string().optional(), merchant_entity_id: z.string().optional(), national_entity: z.enum(["INDIVIDUAL", "ENTITY"]).optional(), phone: z.object({country_code: z.string().optional(), number: z.string().optional()}).optional(), address: z.object({address_line_1: z.string().optional(), address_line_2: z.string().nullable().optional(), building_number_1: z.string().nullable().optional(), building_number_2: z.string().nullable().optional(), city: z.string().optional(), state: z.string().optional(), zip_code: z.string().optional(), country: z.string().optional()}).optional(), entity_detail: z.object({individual: z.object({first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), date_of_birth: z.string().optional(), gender: z.string().optional(), country_of_residence: z.string().optional(), tax_information: z.array(z.object({country: z.string().optional(), tax_id_last_4: z.string().optional(), tax_id_type: z.string().optional(), is_primary: z.boolean().optional()})).optional(), document: z.object({document_type: z.string().optional(), document_number_last_4: z.string().optional(), issuing_country: z.string().optional(), issued_at: z.string().optional(), expires_at: z.string().nullable().optional()}).optional()}).nullable().optional(), entity: z.object({}).nullable().optional()}).optional(), created_at: z.string().optional(), updated_at: z.string().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 Entity (Banking Connectivity) * * PATCH /banking/entities/{entity_id} */ export const patchApiBankingEntitiesEntityId = async (args: PatchApiBankingEntitiesEntityIdArgs, options?: PatchApiBankingEntitiesEntityIdOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (publicApiKey !== undefined) headers.set("PUBLIC-API-KEY", publicApiKey) if (privateSecretKey !== undefined) headers.set("PRIVATE-SECRET-KEY", privateSecretKey) const url = `${baseUrl.replace(/\/+$/, '')}/banking/entities/${encodeURIComponent(String(args.entity_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiBankingEntitiesEntityIdResponse, await res.json()) };