import {z} from 'zod' export type AssetName = string; export type NetworkName = string; export type GetApiV1CustomersCustomerIdDepositInstructionsArgs = {customer_id: string, asset: AssetName, network: NetworkName}; export type GetApiV1CustomersCustomerIdDepositInstructionsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const assetName = z.string(); export const networkName = z.string(); export const addressDetails = z.object({full_address: z.string(), country_code: z.string(), address_line1: z.string(), address_line2: z.string().nullable().optional(), city: z.string(), region: z.string().nullable().optional(), postal_code: z.string()}); export const feeMeta = z.object({value: z.string(), asset: assetName}); export const bankDepositInfo = z.object({bank_name: z.string().nullable(), routing_number: z.string().nullable(), account_holder: z.string().nullable(), account_number: z.string().nullable(), bic_code: z.string().nullable().optional(), memorandum: z.string().nullable().optional(), address: addressDetails.nullable().optional(), transaction_fee: feeMeta}); export const walletDepositInfo = z.object({wallet_address: z.string(), minimum_deposit: z.string(), contract_address_url: z.string()}); export const clabeDepositInfo = z.object({clabe: z.string(), bank_name: z.string().nullable().optional(), beneficiary_name: z.string().nullable().optional(), reference: z.string().nullable().optional(), transaction_fee: feeMeta}); export const depositAction = z.literal("DEPOSIT"); export const chronoDateTimeSchema = z.string(); export const depositInfoResponse = z.object({asset: assetName, network: networkName, deposit_instruction_id: z.string().nullable().optional(), bank_instruction: bankDepositInfo.nullable().optional(), wallet_instruction: walletDepositInfo.nullable().optional(), clabe_instruction: clabeDepositInfo.nullable().optional(), transaction_action: depositAction, created_at: chronoDateTimeSchema, modified_at: chronoDateTimeSchema}); 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 /v1/customers/{customer_id}/deposit_instructions */ export const getApiV1CustomersCustomerIdDepositInstructions = async (args: GetApiV1CustomersCustomerIdDepositInstructionsArgs, options?: GetApiV1CustomersCustomerIdDepositInstructionsOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.asset != null) query.append("asset", String(args.asset)) if (args.network != null) query.append("network", String(args.network)) if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}/deposit_instructions${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(depositInfoResponse, await res.json()) };