import {z} from 'zod' export type GetApiBankingEntitiesEntityIdArgs = {entity_id: string}; export type GetApiBankingEntitiesEntityIdOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBankingEntitiesEntityIdResponse = z.object({account_id: z.string().optional(), merchant_entity_id: z.string().optional(), national_entity: z.string().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().optional(), building_number_1: z.string().optional(), building_number_2: z.unknown(), 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: 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: z.string().optional(), issuing_country: z.string().optional(), issued_at: z.string().optional(), expires_at: z.string().optional()}).optional()}).optional(), entity: z.unknown()}).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 Entity Details (Banking Connectivity) * * GET /banking/entities/{entity_id} */ export const getApiBankingEntitiesEntityId = async (args: GetApiBankingEntitiesEntityIdArgs, options?: GetApiBankingEntitiesEntityIdOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiBankingEntitiesEntityIdResponse, await res.json()) };