import {z} from 'zod' export type MerchantCategory = '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 type ExpenseType = 'COMPANY' | 'PERSONAL' | 'TRAVEL_AND_ENTERTAINMENT'; export type CreateExpenseCategory = {code?: string | undefined, name: string, description?: string | undefined, tax_rate_id?: string | undefined, enabled?: boolean | undefined, merchant_categories?: Array | undefined, expense_type: ExpenseType}; export type CreateApiBusinessV2EntitiesExpenseCategoryArgs = {body: CreateExpenseCategory}; export type CreateApiBusinessV2EntitiesExpenseCategoryOptions = {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 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 }; /** * Add Expense Category * * POST /business/v2/entities/expense-category */ export const createApiBusinessV2EntitiesExpenseCategory = async (args: CreateApiBusinessV2EntitiesExpenseCategoryArgs, options?: CreateApiBusinessV2EntitiesExpenseCategoryOptions) => { const {baseUrl = "https://api.soldo.com", fetch: fetchFn = fetch, standardAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "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(expenseCategory, await res.json()) };