import {z} from 'zod' export type CustomerId = string; export type GetApiApiV1CustomersCustomerIdArgs = {customerId: CustomerId}; export type GetApiApiV1CustomersCustomerIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerId = z.string(); export const metadata = z.record(z.string(), z.string()); export const verificationLevelResponse = z.object({level: z.enum(["kyc_level_0", "kyc_level_1", "kyc_level_2", "base_business", "individual_base", "business_base", "individual_enhanced"]), status: z.enum(["in_progress", "approved", "rejected", "requires_action"]), sub_status: z.array(z.enum(["BAD_PROOF_OF_IDENTITY", "BAD_PROOF_OF_ADDRESS", "DOCUMENT_PAGE_MISSING", "OTHER", "FILE_CORRUPTED", "FILE_EMPTY", "FILE_TOO_LARGE", "FILE_UNSUPPORTED_TYPE", "FAILED_TO_SUBMIT", "FAILED_TO_SUBMIT_BENEFICIARY"])).optional()}); export const getCustomerResponse = z.object({customer_id: customerId, external_customer_id: z.string().nullable(), customer_type: z.enum(["individual", "business"]), email: z.string(), phone: z.string().optional(), entitlements: z.array(z.object({name: z.string(), status: z.enum(["submitted", "in_progress", "approved", "rejected"])})).optional(), first_name: z.string().optional(), last_name: z.string().optional(), company_name: z.string().optional(), created_at: z.string(), updated_at: z.string(), metadata: metadata.optional(), verification_levels: z.array(verificationLevelResponse), status: z.string().optional(), compliance_lock: z.object({locked_at: z.string(), locked_by_user_id: z.string(), locked_by_user_name: z.string().nullable().optional(), locked_by_user_email: z.string().nullable().optional(), lock_reason: 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 }; /** * Get customer details by ID including KYC status * * GET /api/v1/customers/{customerId} * * Also accepts auth: apiKeyAuth */ export const getApiApiV1CustomersCustomerId = async (args: GetApiApiV1CustomersCustomerIdArgs, options?: GetApiApiV1CustomersCustomerIdOptions) => { const {baseUrl = "https://api.stables.money", 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(/\/+$/, '')}/api/v1/customers/${encodeURIComponent(String(args.customerId))}${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(getCustomerResponse, await res.json()) };