import {z} from 'zod' export type OnrampCustomerStatusRequest = {auth_intent_id: string, crypto_customer_id: string}; export type CreateApiOnrampVerificationStatusArgs = {'X-API-KEY': string, body: OnrampCustomerStatusRequest}; export type CreateApiOnrampVerificationStatusOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const customerTierStatus = z.object({tier: z.string(), verification_status: z.string(), verification_errors: z.array(z.string()).optional()}); export const customerTransactionLimitEntry = z.object({limit: z.number(), settlement_speed: z.string()}); export const customerTransactionLimits = z.object({livemode: z.boolean(), limits: z.record(z.string(), z.record(z.string(), z.array(customerTransactionLimitEntry)))}); export const onrampCustomerStatusResponse = z.object({crypto_customer_id: z.string(), kyc_required: z.boolean(), kyc_status: z.string().optional(), kyc_current_tier: z.string().optional(), kyc_region: z.string().nullable().optional(), kyc_next_step: z.string().optional(), identity_verification_required: z.boolean(), identity_verification_status: z.string().optional(), kyc_tiers: z.array(customerTierStatus).optional(), provided_fields: z.array(z.string()).optional(), transaction_limits: customerTransactionLimits.nullable().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 Onramp Verification Status * * POST /onramp/verification/status */ export const createApiOnrampVerificationStatus = async (args: CreateApiOnrampVerificationStatusArgs, options?: CreateApiOnrampVerificationStatusOptions) => { const {baseUrl = "https://api.coinvoyage.io/v3", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-KEY'] != null) headers.set("X-API-KEY", String(args['X-API-KEY'])) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/onramp/verification/status${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(onrampCustomerStatusResponse, await res.json()) };