import {z} from 'zod' export type GetApiV2CustomersCustomerIdArgs = {customer_id: string}; export type GetApiV2CustomersCustomerIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const individualCustomerDetailV2 = z.object({customer_id: z.string().optional(), type: z.literal("INDIVIDUAL").optional(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), country_of_residence: z.string().optional(), verification_type: z.string().optional(), customer_status: z.string().optional(), tos_policies_url: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), last_status_updated_at: z.string().optional(), rejection_reason: z.object({applicant: z.object({moderation_comment: z.string().optional(), reject_labels: z.array(z.string()).optional()}).nullable().optional(), documents: z.array(z.object({uri: z.string().optional(), category: z.string().optional(), moderation_comment: z.string().optional(), reject_labels: z.array(z.string()).optional()})).optional()}).nullable().optional(), request_for_information: z.array(z.object({scope: z.enum(["CUSTOMER", "ASSOCIATED_PARTY"]).optional(), section: z.string().optional(), categories: z.array(z.object({document_type: z.string().optional(), fields: z.array(z.object({field_name: z.string().optional(), data_type: z.enum(["URI", "DATE", "TEXT", "ENUM"]).optional(), status: z.enum(["MISSING", "EXPIRED", "INVALID"]).optional(), reason: z.string().nullable().optional(), options: z.array(z.string()).optional()})).optional()})).optional()})).optional()}); export const businessCustomerDetailV2 = z.object({customer_id: z.string().optional(), type: z.literal("BUSINESS").optional(), business_name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), country_of_incorporation: z.string().optional(), verification_type: z.string().optional(), customer_status: z.enum(["INCOMPLETE", "PROCESSING", "REVIEWING", "APPROVED", "ASSOCIATED_PARTIES_REMAINING", "IN_COMPLIANCE", "ACTION_REQUIRED", "REJECTED"]).optional(), tos_policies_url: z.string().optional(), associated_parties: z.array(z.object({id: z.string().optional(), type: z.string().optional(), ownership_percent: z.number().optional(), email: z.string().optional(), verification: z.object({status: z.enum(["INITIATED", "REVIEWING", "APPROVED", "REJECTED"]).optional(), reason: z.object({for_customer: z.string().nullable().optional(), for_developer: z.string().nullable().optional()}).optional(), updated_at: z.string().optional()}).optional()})).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), rejection_reason: z.object({applicant: z.object({moderation_comment: z.string().optional(), reject_labels: z.array(z.string()).optional()}).nullable().optional(), documents: z.array(z.object({uri: z.string().optional(), category: z.string().optional(), moderation_comment: z.string().optional(), reject_labels: z.array(z.string()).optional()})).optional(), associated_parties: z.array(z.object({})).optional()}).nullable().optional(), request_for_information: z.array(z.object({section: z.string().optional(), categories: z.array(z.object({document_type: z.string().optional(), fields: z.array(z.object({field_name: z.string().optional(), data_type: z.enum(["URI", "DATE", "TEXT", "ENUM"]).optional(), status: z.enum(["MISSING", "EXPIRED", "INVALID"]).optional(), reason: z.string().nullable().optional()})).optional()})).optional()})).optional()}); export const getApiV2CustomersCustomerIdResponse = z.object({data: z.union([individualCustomerDetailV2, businessCustomerDetailV2]).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 Customer Details V2 * * GET /v2/customers/{customer_id} */ export const getApiV2CustomersCustomerId = async (args: GetApiV2CustomersCustomerIdArgs, options?: GetApiV2CustomersCustomerIdOptions) => { const {baseUrl = "https://sandbox.api.fin.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/customers/${encodeURIComponent(String(args.customer_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(getApiV2CustomersCustomerIdResponse, await res.json()) };