import {z} from 'zod' export type PatchApiStatementConfigIdArgs = {id: string, body: {account_id?: string | undefined, apy?: string | undefined, apy_custom?: string | undefined, bank_disclosure_message?: string | undefined, display_authorized_user?: boolean | undefined, email_address?: string | undefined, footnote?: string | undefined, logo_file_id?: string | undefined, org_legal_name?: string | undefined, phone_number?: string | undefined, physical_address?: ({city?: string | undefined, postal_code?: string | undefined, state?: string | undefined, street_line_1?: string | undefined, street_line_2?: string | undefined}) | undefined, show_transaction_ids?: boolean | undefined, support_url?: string | undefined, timezone?: string | undefined}}; export type PatchApiStatementConfigIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const patchApiStatementConfigIdResponse = z.object({account_id: z.string().optional(), apy: z.string().optional(), apy_custom: z.string().optional(), bank_disclosure_message: z.string().optional(), display_authorized_user: z.boolean().optional(), email_address: z.string().optional(), footnote: z.string().optional(), id: z.string().optional(), logo_file_id: z.string().optional(), org_legal_name: z.string().optional(), phone_number: z.string().optional(), physical_address: z.object({city: z.string().optional(), postal_code: z.string().optional(), state: z.string().optional(), street_line_1: z.string().optional(), street_line_2: z.string().optional()}).optional(), show_transaction_ids: z.boolean().optional(), support_url: z.string().optional(), timezone: 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 }; /** * Update a Configuration * * PATCH /statement_config/{id} * * Also accepts auth: apiKey */ export const patchApiStatementConfigId = async (args: PatchApiStatementConfigIdArgs, options?: PatchApiStatementConfigIdOptions) => { const {baseUrl = "https://api.treasuryprime.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/statement_config/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiStatementConfigIdResponse, await res.json()) };