import {z} from 'zod' export type BankAccountTypeEnum = 'CHECKING' | 'SAVING' | 'CREDIT_CARD' | 'DEBIT_CARD' | 'INVESTMENT' | 'LOAN'; export type BlankEnum = ''; export type NullEnum = unknown; export type PatchedBankAccount = {id?: number | undefined, is_deleted?: boolean | undefined, deleted_at?: (string | null) | undefined, entity_name?: string | undefined, department_name?: string | undefined, chart_of_accounts_account_name?: string | undefined, account_type?: string | undefined, account_subtype?: string | undefined, account_cashflow_classification?: string | undefined, type_name?: string | undefined, subtype_name?: string | undefined, cashflow_classification_name?: string | undefined, account_id?: string | undefined, currency?: string | undefined, external_account_id?: (string | null) | undefined, name?: (string | null) | undefined, nickname?: (string | null) | undefined, status?: (string | null) | undefined, type?: (BankAccountTypeEnum | BlankEnum | NullEnum | null) | undefined, available_balance?: (number | null) | undefined, current_balance?: (number | null) | undefined, institution_id?: (string | null) | undefined, source?: (string | null) | undefined, aba_routing_number?: (string | null) | undefined, swift_bic?: (string | null) | undefined, created_at?: string | undefined, last_modified_at?: string | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, customer?: number | undefined, entity?: number | undefined, chart_of_accounts_account?: (number | null) | undefined, department?: (number | null) | undefined, tags?: Array | undefined}; export type PatchApiCaApiAccountIdArgs = {id: number, body: PatchedBankAccount}; export type PatchApiCaApiAccountIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const bankAccountTypeEnum = z.enum(["CHECKING", "SAVING", "CREDIT_CARD", "DEBIT_CARD", "INVESTMENT", "LOAN"]); export const blankEnum = z.literal(""); export const nullEnum = z.unknown(); export const bankAccount = z.object({id: z.number().int(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), entity_name: z.string(), department_name: z.string(), chart_of_accounts_account_name: z.string(), account_type: z.string(), account_subtype: z.string(), account_cashflow_classification: z.string(), type_name: z.string(), subtype_name: z.string(), cashflow_classification_name: z.string(), account_id: z.string(), currency: z.string().max(3).optional(), external_account_id: z.string().max(200).nullable().optional(), name: z.string().max(250).nullable().optional(), nickname: z.string().max(250).nullable().optional(), status: z.string().max(250).nullable().optional(), type: z.union([bankAccountTypeEnum, blankEnum, nullEnum]).nullable().optional(), available_balance: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), current_balance: z.number().gt(-1000000000000000000).lt(1000000000000000000).nullable().optional(), institution_id: z.string().max(250).nullable().optional(), source: z.string().max(250).nullable().optional(), aba_routing_number: z.string().max(9).nullable().optional(), swift_bic: z.string().max(11).nullable().optional(), created_at: z.string(), last_modified_at: z.string(), tag_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), tag_group_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), customer: z.number().int(), entity: z.number().int(), chart_of_accounts_account: z.number().int().nullable().optional(), department: z.number().int().nullable().optional(), tags: z.array(z.number().int())}); 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 }; /** * Partial Update Bank Account * * PATCH /ca/api/account/{id} */ export const patchApiCaApiAccountId = async (args: PatchApiCaApiAccountIdArgs, options?: PatchApiCaApiAccountIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/ca/api/account/${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(bankAccount, await res.json()) };