import {z} from 'zod' export type SandboxCreateAnAdjustmentForAnInboundCheckDepositParameters = {amount?: number | undefined, reason?: ('late_return' | 'wrong_payee_credit' | 'duplicate_entry') | undefined}; export type CreateApiSimulationsInboundCheckDepositsInboundCheckDepositIdAdjustmentArgs = {inbound_check_deposit_id: string, body: SandboxCreateAnAdjustmentForAnInboundCheckDepositParameters}; export type CreateApiSimulationsInboundCheckDepositsInboundCheckDepositIdAdjustmentOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const inboundCheckDeposit = z.object({accepted_at: z.string().nullable(), account_id: z.string(), account_number_id: z.string().nullable(), adjustments: z.array(z.object({adjusted_at: z.string(), amount: z.number().int(), reason: z.enum(["late_return", "wrong_payee_credit", "duplicate_entry"]), transaction_id: z.string()})), amount: z.number().int(), automatically_resolves_at: z.string(), back_image_file_id: z.string(), bank_of_first_deposit_routing_number: z.string().nullable(), check_number: z.string().nullable(), check_transfer_id: z.string().nullable(), checkbook_check_id: z.string().nullable(), created_at: z.string(), currency: z.literal("USD"), declined_at: z.string().nullable(), declined_transaction_id: z.string().nullable(), deposit_return: z.object({reason: z.enum(["altered_or_fictitious", "not_authorized", "duplicate_presentment", "endorsement_missing", "endorsement_irregular", "refer_to_maker"]), returned_at: z.string(), transaction_id: z.string()}).nullable(), front_image_file_id: z.string(), id: z.string(), payee_name_analysis: z.enum(["name_matches", "does_not_match", "not_evaluated"]), status: z.enum(["pending", "accepted", "declined", "returned", "requires_attention"]), transaction_id: z.string().nullable(), type: z.literal("inbound_check_deposit")}); 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 }; /** * Sandbox: Create an adjustment for an Inbound Check Deposit * * POST /simulations/inbound_check_deposits/{inbound_check_deposit_id}/adjustment */ export const createApiSimulationsInboundCheckDepositsInboundCheckDepositIdAdjustment = async (args: CreateApiSimulationsInboundCheckDepositsInboundCheckDepositIdAdjustmentArgs, options?: CreateApiSimulationsInboundCheckDepositsInboundCheckDepositIdAdjustmentOptions) => { const {baseUrl = "https://api.increase.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/simulations/inbound_check_deposits/${encodeURIComponent(String(args.inbound_check_deposit_id))}/adjustment${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(inboundCheckDeposit, await res.json()) };