import {z} from 'zod' export type AccountSnapshot = {timestamp: string, meta?: Record | undefined, details?: ({status?: ('null' | 'Active' | 'Deactivated' | 'Frozen' | 'Pending' | 'Inactive' | null) | undefined, status_detail?: string | undefined, loan_credit_limit?: number | undefined, interest_rate?: number | undefined, original_interest_rate?: number | undefined, original_amount?: number | undefined, ach_push_limit?: number | undefined, ach_pull_limit?: number | undefined, name_first?: string | undefined, name_last?: string | undefined, email_address?: string | undefined, phone_number?: string | undefined, mailing_address_line1?: string | undefined, mailing_address_line2?: string | undefined, mailing_address_city?: string | undefined, mailing_address_state?: string | undefined, mailing_address_postal_code?: string | undefined, mailing_address_country_code?: string | undefined, primary_address_line1?: string | undefined, primary_address_line2?: string | undefined, primary_address_city?: string | undefined, primary_address_state?: string | undefined, primary_address_postal_code?: string | undefined, primary_address_country_code?: string | undefined}) | undefined, account_view?: ({account_balance?: number | undefined, date_last_activity?: string | undefined, is_good_standing?: boolean | undefined, past_due_days?: number | undefined}) | undefined}; export type SourceAccount = {bank_account_token?: string | undefined, external_account_id?: string | undefined, account_number?: string | undefined, account_class?: ('deposit' | 'credit' | 'brokerage') | undefined, account_name?: string | undefined, routing_number?: string | undefined, account_type?: ('merchant account' | 'person' | null) | undefined, is_linked_account?: (boolean | null) | undefined, link_timestamp?: (string | null) | undefined, unlink_timestamp?: (string | null) | undefined, opening_date?: (string | null) | undefined, country_code?: (string | null) | undefined, account_snapshot?: AccountSnapshot | undefined, product_code?: (string | null) | undefined, product_name?: (string | null) | undefined, product_number?: (string | null) | undefined, maturity_date?: (string | null) | undefined, closing_date?: (string | null) | undefined, cif_number?: (string | null) | undefined, card_network?: (string | null) | undefined, expiration_date?: (string | null) | undefined, tokenization_method?: (string | null) | undefined, merchant_category_code?: (string | null) | undefined, name_on_card?: (string | null) | undefined, account_number_last4?: (string | null) | undefined, avs?: (string | null) | undefined, currency?: (string | null) | undefined, meta?: (Record | null) | undefined}; export type DestinationAccount = {bank_account_token?: string | undefined, external_account_id?: string | undefined, account_number?: string | undefined, account_class?: ('deposit' | 'credit' | 'brokerage') | undefined, account_name?: string | undefined, routing_number?: string | undefined, account_type?: ('merchant account' | 'person' | null) | undefined, is_linked_account?: (boolean | null) | undefined, link_timestamp?: (string | null) | undefined, unlink_timestamp?: (string | null) | undefined, opening_date?: (string | null) | undefined, country_code?: (string | null) | undefined, account_snapshot?: AccountSnapshot | undefined, product_code?: (string | null) | undefined, product_name?: (string | null) | undefined, product_number?: (string | null) | undefined, maturity_date?: (string | null) | undefined, closing_date?: (string | null) | undefined, cif_number?: (string | null) | undefined, card_network?: (string | null) | undefined, expiration_date?: (string | null) | undefined, tokenization_method?: (string | null) | undefined, merchant_category_code?: (string | null) | undefined, name_on_card?: (string | null) | undefined, account_number_last4?: (string | null) | undefined, avs?: (string | null) | undefined, currency?: (string | null) | undefined, meta?: (Record | null) | undefined}; export type TransactionPatchRequestBody = {transaction_id: unknown, transaction_date?: string | undefined, amount?: number | undefined, currency?: string | undefined, source?: SourceAccount | undefined, destination?: DestinationAccount | undefined, account_snapshot?: (AccountSnapshot | null) | undefined, process_method?: ('Card' | 'Internal' | 'Check' | 'P2P' | 'ACH' | 'Cash' | 'Wire' | 'RTP' | 'Digital Wallet' | null) | undefined, category?: ('Adjustment' | 'ATM Rebate' | 'Bill Pay' | 'Chargeback' | 'Deposit' | 'Direct Deposit Bonus' | 'Interest' | 'Overdraft Fee' | 'Payment' | 'Promo' | 'Purchase' | 'Purchase Return' | 'Return' | 'Service Charge' | 'Withdrawal' | null) | undefined, interaction_point?: ('Android' | 'ATM' | 'Card Swipe Terminal' | 'iOS' | 'Mobile' | 'Online Form' | 'Point of Sale' | 'QR' | 'Teller' | '3rd Party App' | null) | undefined, type_code?: (string | null) | undefined, type_description?: (string | null) | undefined, is_approved?: (boolean | null) | undefined, is_reversal?: (boolean | null) | undefined, is_triggered_by_user?: (boolean | null) | undefined, is_international_override?: (boolean | null) | undefined, return_code?: (string | null) | undefined, return_code_reason?: ('Unauthorized' | null) | undefined, entry_mode?: (number | null) | undefined, response_code?: (number | null) | undefined, status?: ('Acknowledged' | 'Accepted' | 'Rejected' | 'Paused' | 'Pending' | 'Completed' | 'Declined' | 'Cancelled' | null) | undefined, status_detail?: (string | null) | undefined, iso_message?: (number | null) | undefined, settled_at?: (string | null) | undefined, latest_transaction_date?: (string | null) | undefined, description?: (string | null) | undefined, approval_code?: (string | null) | undefined, transaction_meta?: (Record | null) | undefined}; export type PatchApiTransactionsTransactionIdArgs = {body: TransactionPatchRequestBody}; export type PatchApiTransactionsTransactionIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const accountSnapshot = z.object({timestamp: z.string(), meta: z.object({}).optional(), details: z.object({status: z.enum(["null", "Active", "Deactivated", "Frozen", "Pending", "Inactive"]).nullable().optional(), status_detail: z.string().optional(), loan_credit_limit: z.number().int().optional(), interest_rate: z.number().optional(), original_interest_rate: z.number().optional(), original_amount: z.number().int().optional(), ach_push_limit: z.number().int().optional(), ach_pull_limit: z.number().int().optional(), name_first: z.string().optional(), name_last: z.string().optional(), email_address: z.string().optional(), phone_number: z.string().optional(), mailing_address_line1: z.string().optional(), mailing_address_line2: z.string().optional(), mailing_address_city: z.string().optional(), mailing_address_state: z.string().optional(), mailing_address_postal_code: z.string().optional(), mailing_address_country_code: z.string().optional(), primary_address_line1: z.string().optional(), primary_address_line2: z.string().optional(), primary_address_city: z.string().optional(), primary_address_state: z.string().optional(), primary_address_postal_code: z.string().optional(), primary_address_country_code: z.string().max(3).optional()}).optional(), account_view: z.object({account_balance: z.number().int().optional(), date_last_activity: z.string().optional(), is_good_standing: z.boolean().optional(), past_due_days: z.number().int().optional()}).optional()}); export const sourceAccount = z.object({bank_account_token: z.string().optional(), external_account_id: z.string().max(60).optional(), account_number: z.string().optional(), account_class: z.enum(["deposit", "credit", "brokerage"]).optional(), account_name: z.string().optional(), routing_number: z.string().optional(), account_type: z.enum(["merchant account", "person"]).nullable().optional(), is_linked_account: z.boolean().nullable().optional(), link_timestamp: z.string().nullable().optional(), unlink_timestamp: z.string().nullable().optional(), opening_date: z.string().nullable().optional(), country_code: z.string().max(2).nullable().optional(), account_snapshot: accountSnapshot.optional(), product_code: z.string().nullable().optional(), product_name: z.string().nullable().optional(), product_number: z.string().nullable().optional(), maturity_date: z.string().nullable().optional(), closing_date: z.string().nullable().optional(), cif_number: z.string().nullable().optional(), card_network: z.string().max(20).nullable().optional(), expiration_date: z.string().nullable().optional(), tokenization_method: z.string().max(20).nullable().optional(), merchant_category_code: z.string().max(20).nullable().optional(), name_on_card: z.string().max(100).nullable().optional(), account_number_last4: z.string().max(4).nullable().optional(), avs: z.string().max(20).nullable().optional(), currency: z.string().max(4).nullable().optional(), meta: z.object({}).nullable().optional()}); export const destinationAccount = z.object({bank_account_token: z.string().optional(), external_account_id: z.string().max(60).optional(), account_number: z.string().optional(), account_class: z.enum(["deposit", "credit", "brokerage"]).optional(), account_name: z.string().optional(), routing_number: z.string().optional(), account_type: z.enum(["merchant account", "person"]).nullable().optional(), is_linked_account: z.boolean().nullable().optional(), link_timestamp: z.string().nullable().optional(), unlink_timestamp: z.string().nullable().optional(), opening_date: z.string().nullable().optional(), country_code: z.string().max(2).nullable().optional(), account_snapshot: accountSnapshot.optional(), product_code: z.string().nullable().optional(), product_name: z.string().nullable().optional(), product_number: z.string().nullable().optional(), maturity_date: z.string().nullable().optional(), closing_date: z.string().nullable().optional(), cif_number: z.string().nullable().optional(), card_network: z.string().max(20).nullable().optional(), expiration_date: z.string().nullable().optional(), tokenization_method: z.string().max(20).nullable().optional(), merchant_category_code: z.string().max(20).nullable().optional(), name_on_card: z.string().max(100).nullable().optional(), account_number_last4: z.string().max(4).nullable().optional(), avs: z.string().max(20).nullable().optional(), currency: z.string().max(4).nullable().optional(), meta: z.object({}).nullable().optional()}); export const transactionPatchResponseBody = z.object({transaction_id: z.unknown(), transaction_date: z.string().optional(), amount: z.number().int().optional(), currency: z.string().optional(), source: sourceAccount.optional(), destination: destinationAccount.optional(), account_snapshot: accountSnapshot.nullable().optional(), process_method: z.enum(["Card", "Internal", "Check", "P2P", "ACH", "Cash", "Wire", "RTP", "Digital Wallet"]).nullable().optional(), category: z.enum(["Adjustment", "ATM Rebate", "Bill Pay", "Chargeback", "Deposit", "Direct Deposit Bonus", "Interest", "Overdraft Fee", "Payment", "Promo", "Purchase", "Purchase Return", "Return", "Service Charge", "Withdrawal"]).nullable().optional(), interaction_point: z.enum(["Android", "ATM", "Card Swipe Terminal", "iOS", "Mobile", "Online Form", "Point of Sale", "QR", "Teller", "3rd Party App"]).nullable().optional(), type_code: z.string().nullable().optional(), type_description: z.string().nullable().optional(), is_approved: z.boolean().nullable().optional(), is_reversal: z.boolean().nullable().optional(), is_triggered_by_user: z.boolean().nullable().optional(), is_international_override: z.boolean().nullable().optional(), return_code: z.string().nullable().optional(), return_code_reason: z.literal("Unauthorized").nullable().optional(), entry_mode: z.number().nullable().optional(), response_code: z.number().nullable().optional(), status: z.enum(["Acknowledged", "Accepted", "Rejected", "Paused", "Pending", "Completed", "Declined", "Cancelled"]).nullable().optional(), status_detail: z.string().nullable().optional(), iso_message: z.number().nullable().optional(), settled_at: z.string().nullable().optional(), latest_transaction_date: z.string().nullable().optional(), description: z.string().nullable().optional(), approval_code: z.string().nullable().optional(), transaction_meta: z.object({}).nullable().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 transaction. * * PATCH /transactions/{transaction_id} * * Also accepts auth: basic */ export const patchApiTransactionsTransactionId = async (args: PatchApiTransactionsTransactionIdArgs, options?: PatchApiTransactionsTransactionIdOptions) => { const {baseUrl = "https://sandbox.alloy.co/v1", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/${encodeURIComponent(String(args.transaction_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(transactionPatchResponseBody, await res.json()) };