import {z} from 'zod' export type BankAccountCountryCode = 'CA' | 'US'; export type BankAccountCreateSignatureText = {bankName: string, bankPrimaryLine?: string | undefined, bankSecondaryLine?: string | undefined, bankCountryCode: BankAccountCountryCode, accountNumber: string, routingNumber?: string | undefined, transitNumber?: string | undefined, routeNumber?: string | undefined, caDesignationNumber?: string | undefined, description?: string | undefined, metadata?: {[key: string]: unknown} | undefined, signatureText: string}; export type BankAccountCreateSignatureImageURL = {bankName: string, bankPrimaryLine?: string | undefined, bankSecondaryLine?: string | undefined, bankCountryCode: BankAccountCountryCode, accountNumber: string, routingNumber?: string | undefined, transitNumber?: string | undefined, routeNumber?: string | undefined, caDesignationNumber?: string | undefined, description?: string | undefined, metadata?: {[key: string]: unknown} | undefined, signatureImage: string}; export type BankAccountCreateSignatureImageFile = {bankName: string, bankPrimaryLine?: string | undefined, bankSecondaryLine?: string | undefined, bankCountryCode: BankAccountCountryCode, accountNumber: string, routingNumber?: string | undefined, transitNumber?: string | undefined, routeNumber?: string | undefined, caDesignationNumber?: string | undefined, description?: string | undefined, metadata?: {[key: string]: unknown} | undefined, signatureImage: string}; export type BankAccountCreate = BankAccountCreateSignatureText | BankAccountCreateSignatureImageURL | BankAccountCreateSignatureImageFile; export type CreateApiPrintMailV1BankAccountsArgs = {body: BankAccountCreate}; export type CreateApiPrintMailV1BankAccountsOptions = {baseUrl?: string | undefined, PrintMailApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bankAccountCountryCode = z.enum(["CA", "US"]); export const bankAccount = z.object({object: z.literal("bank_account"), bankName: z.string(), bankPrimaryLine: z.string().optional(), bankSecondaryLine: z.string().optional(), bankCountryCode: bankAccountCountryCode, accountNumber: z.string(), routingNumber: z.string().optional(), transitNumber: z.string().optional(), routeNumber: z.string().optional(), caDesignationNumber: z.string().optional(), id: z.string(), description: z.string().optional(), metadata: z.record(z.string(), z.unknown()).optional(), live: z.boolean(), createdAt: z.string(), updatedAt: z.string(), signatureText: z.string().optional(), signatureImage: 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 }; /** * Create Bank Account * * POST /print-mail/v1/bank_accounts */ export const createApiPrintMailV1BankAccounts = async (args: CreateApiPrintMailV1BankAccountsArgs, options?: CreateApiPrintMailV1BankAccountsOptions) => { const {baseUrl = "https://api.postgrid.com", fetch: fetchFn = fetch, PrintMailApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (PrintMailApiKeyAuth !== undefined) headers.set("X-API-Key", PrintMailApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/print-mail/v1/bank_accounts${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(bankAccount, await res.json()) };