import {z} from 'zod' export type Direction = 'ASC' | 'DESC'; export type GetApiBusinessV2EntitiesExpenseCategoryArgs = {text?: string | undefined, enabled?: boolean | undefined, p?: number | undefined, s?: number | undefined, d?: Direction | undefined, props?: Array | undefined}; export type GetApiBusinessV2EntitiesExpenseCategoryOptions = {baseUrl?: string | undefined, standardAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const merchantCategory = z.enum(["Advertising", "Entertainment", "Utilities", "Food_Cocktail_Bar", "Food_Restaurant", "Food_Store", "Food_Wine", "Services_Business", "Services_Cleaning", "Services_Contracted", "Services_Delivery", "Services_Educational", "Services_Financial", "Services_Gambling", "Services_Government", "Services_Health", "Services_Insurance", "Services_Legal", "Services_Museum", "Services_Organisation", "Services_Personal", "Services_Repair", "Services_Social", "Services_Stationery", "Services_Telecommunication", "Services_Veterinary", "Services_Warehouse", "Services_Wholesale", "Shopping_Accessories", "Shopping_Airline", "Shopping_Art", "Shopping_Automotive", "Shopping_Beauty", "Shopping_Books", "Shopping_Clothes", "Shopping_Digital_Goods", "Shopping_Direct_Marketing", "Shopping_Furnitures", "Shopping_Sport", "Shopping_Store", "Shopping_Technology", "Transport_Airports", "Transport_Charging_Station", "Transport_Parking", "Transport_Public_Transportation", "Transport_Road", "Transport_Service_Station", "Transport_Ships", "Transport_Taxi", "Transport_Toll_Roads", "Transport_Trains", "Travel_Airlines", "Travel_Agency", "Travel_Car_Rental", "Travel_Hotels", "Travel_Time_Shares"]); export const expenseCategory = z.object({id: z.string().optional(), code: z.string().optional(), name: z.string().optional(), description: z.string().optional(), tax_rate_id: z.string().optional(), enabled: z.boolean().optional(), merchant_categories: z.array(merchantCategory).optional(), expense_type: z.string().optional(), integration: z.string().optional(), creation_time: z.string().optional(), last_update_time: z.string().optional()}); export const expenseCategories = z.object({total: z.number().int().optional(), pages: z.number().int().optional(), page_size: z.number().int().optional(), current_page: z.number().int().optional(), results_size: z.number().int().optional(), results: z.array(expenseCategory).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 }; /** * Search Expense Categories * * GET /business/v2/entities/expense-category */ export const getApiBusinessV2EntitiesExpenseCategory = async (args: GetApiBusinessV2EntitiesExpenseCategoryArgs, options?: GetApiBusinessV2EntitiesExpenseCategoryOptions) => { const {baseUrl = "https://api.soldo.com", fetch: fetchFn = fetch, standardAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.text != null) query.append("text", String(args.text)) if (args.enabled != null) query.append("enabled", String(args.enabled)) if (args.p != null) query.append("p", String(args.p)) if (args.s != null) query.append("s", String(args.s)) if (args.d != null) query.append("d", String(args.d)) for (const item of args.props ?? []) query.append("props", String(item)) if (standardAuth !== undefined) headers.set('authorization', `Bearer ${standardAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/business/v2/entities/expense-category${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(expenseCategories, await res.json()) };