import {z} from 'zod' export type GetApiV1ExpensesExpenseIdArgs = {expenseId: string}; export type GetApiV1ExpensesExpenseIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v1ExpensesExpenseIdGetResponseCategory = z.object({id: z.string().optional(), name: z.string().optional()}); export const v1ExpensesExpenseIdGetResponseReceipt = z.object({id: z.string().optional(), name: z.string().optional(), link: z.string().optional()}); export const v1ExpensesExpenseIdGetResponseItem = z.object({itemId: z.string().optional(), title: z.string().optional(), amount: z.number().optional(), date: z.string().optional(), category: v1ExpensesExpenseIdGetResponseCategory.optional(), description: z.string().optional(), receipts: z.array(v1ExpensesExpenseIdGetResponseReceipt).optional()}); export const v1ExpensesExpenseIdGetResponse = z.object({expenseId: z.string(), title: z.string(), status: z.enum(["DRAFT", "REVOKED", "APPROVAL_IN_PROGRESS", "APPROVED", "REJECTED", "PROCESSING", "PAID", "TO_BE_PAID", "ON_HOLD", "UNKNOWN"]), totalAmount: z.number(), currency: z.string(), submittedAt: z.string().optional(), createdOn: z.string().optional(), updatedOn: z.string().optional(), employeeId: z.string().optional(), items: z.array(v1ExpensesExpenseIdGetResponseItem).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 }; /** * Retrieve detailed expense information * * GET /v1/expenses/{expenseId} */ export const getApiV1ExpensesExpenseId = async (args: GetApiV1ExpensesExpenseIdArgs, options?: GetApiV1ExpensesExpenseIdOptions) => { const {baseUrl = "https://api.usemultiplier.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/expenses/${encodeURIComponent(String(args.expenseId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(v1ExpensesExpenseIdGetResponse, await res.json()) };