import {z} from 'zod' export type UpdateExpenseRequest = {memo?: (string | null) | undefined}; export type UpdateApiV1ExpensesCardExpenseIdArgs = {expense_id: string, body: UpdateExpenseRequest}; export type UpdateApiV1ExpensesCardExpenseIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const category = z.enum(["ADVERTISING_AND_MARKETING", "GROCERY", "TELEPHONY", "OFFICE_SUPPLIES", "PRIVATE_AIR_TRAVEL", "CLOTHING", "CAR_RENTAL", "VEHICLE_EXPENSES", "RESTAURANTS", "GAMBLING", "FLOWERS", "ELECTRONICS", "LEGAL_SERVICES", "UTILITIES", "FURNITURE", "BARS_AND_NIGHTLIFE", "LAUNDRY", "EVENT_EXPENSES", "SHIPPING", "OTHER_TRAVEL_EXPENSES", "CHARITY", "SOFTWARE_NON_RECURRING", "LODGING", "FACILITIES_EXPENSES", "SERVERS", "CONFERENCES", "FOOD_DELIVERY", "RENT", "AIRLINE_EXPENSES", "OTHER_BUSINESS_EXPENSES", "BANK_AND_FINANCIAL_FEES", "BOOKS_AND_NEWSPAPERS", "CONSULTANT_AND_CONTRACTOR", "CORPORATE_INSURANCE", "DIGITAL_GOODS", "FEES_AND_LICENSES_AND_TAXES", "GAS_AND_FUEL", "GENERAL_MERCHANDISE", "MEDICAL", "MEMBERSHIPS_AND_CLUBS", "PARKING_EXPENSES", "POLITICAL_DONATIONS", "PUBLIC_TRANSPORTATION", "RECURRING_SOFTWARE_AND_SAAS", "RIDESHARE_AND_TAXI", "TOLL_AND_BRIDGE_FEES", "TRAINING_AND_EDUCATION", "TRAVEL_WIFI"]); export const expenseStatus = z.enum(["DRAFT", "SUBMITTED", "APPROVED", "OUT_OF_POLICY", "VOID", "CANCELED", "SPLIT", "SETTLED"]); export const expensePaymentStatus = z.enum(["NOT_STARTED", "PROCESSING", "CANCELED", "DECLINED", "CLEARED", "REFUNDING", "REFUNDED", "CASH_ADVANCE", "CREDITED", "AWAITING_PAYMENT", "SCHEDULED", "HELD"]); export const expense = z.object({id: z.string(), memo: z.string().nullable().optional(), location_id: z.string().nullable().optional(), department_id: z.string().nullable().optional(), updated_at: z.string(), category: category.nullable().optional(), merchant_id: z.string().nullable().optional(), budget_id: z.string().nullable().optional(), original_amount: z.object({amount: z.number().int(), currency: z.string().nullable().optional()}).nullable().optional(), billing_amount: z.object({amount: z.number().int(), currency: z.string().nullable().optional()}).nullable().optional(), purchased_at: z.string().nullable().optional(), status: expenseStatus.nullable().optional(), payment_status: expensePaymentStatus.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 an expense * * PUT /v1/expenses/card/{expense_id} */ export const updateApiV1ExpensesCardExpenseId = async (args: UpdateApiV1ExpensesCardExpenseIdArgs, options?: UpdateApiV1ExpensesCardExpenseIdOptions) => { const {baseUrl = "https://api.brex.com", 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(/\/+$/, '')}/v1/expenses/card/${encodeURIComponent(String(args.expense_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(expense, await res.json()) };