import {z} from 'zod' export type IdempotencyKey = string; export type GetApiV1CustomersCustomerIdDepositInstructionArgs = {customer_id: string, idempotency_key: IdempotencyKey}; export type GetApiV1CustomersCustomerIdDepositInstructionOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const depositWalletNetwork = z.string(); export const depositInstructionStatus = z.enum(["PENDING", "READY", "FAILED"]); export const chronoDateTimeSchema = z.string(); export const depositInstructionResponse = z.object({deposit_instruction_id: z.string(), network: depositWalletNetwork, address: z.string(), is_default: z.boolean(), nickname: z.string(), status: depositInstructionStatus, created_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_instruction */ export const getApiV1CustomersCustomerIdDepositInstruction = async (args: GetApiV1CustomersCustomerIdDepositInstructionArgs, options?: GetApiV1CustomersCustomerIdDepositInstructionOptions) => { 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.idempotency_key != null) query.append("idempotency_key", String(args.idempotency_key)) if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer_id))}/deposit_instruction${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(depositInstructionResponse, await res.json()) };