import {z} from 'zod' export type PatchApiV1LinkedBankAccountsLinkedBankAccountIdCancelArgs = {linked_bank_account_id: string, 'request-id'?: string | undefined, 'correlation-id'?: string | undefined, 'idempotency-key'?: string | undefined}; export type PatchApiV1LinkedBankAccountsLinkedBankAccountIdCancelOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const responseMetadata = z.object({api_request_id: z.string(), api_request_timestamp: z.string()}); export const statusDetailOfLinkedBankAccountStatusDetailEnum = z.object({reason: z.enum(["unverified", "in_review", "pending", "stuck", "verified", "failed_verification", "disabled", "new"]), source: z.literal("watchtower"), code: z.string(), message: z.string()}); export const bankAccountV1 = z.object({institution_name: z.string(), account_holder: z.string(), routing_number: z.string(), account_mask: z.string()}); export const linkedBankAccountV1 = z.object({id: z.string(), account_id: z.string().nullable(), status: z.enum(["created", "onboarding", "active", "rejected", "inactive", "canceled"]), status_detail: statusDetailOfLinkedBankAccountStatusDetailEnum, bank_account: bankAccountV1, metadata: z.record(z.string(), z.string().nullable()).nullable().optional(), created_at: z.string(), updated_at: z.string(), platform_id: z.string().nullable().optional(), purposes: z.array(z.enum(["charges", "payouts", "billing"])), description: z.string().nullable().optional()}); export const itemResponseOfLinkedBankAccountV1 = z.object({meta: responseMetadata, response_type: z.enum(["object", "array", "error", "none"]), data: linkedBankAccountV1}); 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 }; /** * Cancel a linked bank account * * PATCH /v1/linked_bank_accounts/{linked_bank_account_id}/cancel */ export const patchApiV1LinkedBankAccountsLinkedBankAccountIdCancel = async (args: PatchApiV1LinkedBankAccountsLinkedBankAccountIdCancelArgs, options?: PatchApiV1LinkedBankAccountsLinkedBankAccountIdCancelOptions) => { const {baseUrl = "https://sandbox.straddle.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['request-id'] != null) headers.set("request-id", String(args['request-id'])) if (args['correlation-id'] != null) headers.set("correlation-id", String(args['correlation-id'])) if (args['idempotency-key'] != null) headers.set("idempotency-key", String(args['idempotency-key'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/linked_bank_accounts/${encodeURIComponent(String(args.linked_bank_account_id))}/cancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(itemResponseOfLinkedBankAccountV1, await res.json()) };