import {z} from 'zod' export type GetApiApiPayeesPayeeIdSummaryArgs = {payee_id: string, from?: (string | null) | undefined, to?: (string | null) | undefined, 'X-Workspace-Id'?: (string | null) | undefined}; export type GetApiApiPayeesPayeeIdSummaryOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const taxIdRead = z.object({kind: z.string(), value: z.string()}); export const payeeRead = z.object({id: z.string(), user_id: z.string(), name: z.string(), type: z.enum(["person", "company"]).nullable().optional(), source: z.enum(["manual", "sync", "import"]).optional(), is_favorite: z.boolean(), notes: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional(), address: z.string().nullable().optional(), website: z.string().nullable().optional(), tax_ids: z.array(taxIdRead).optional(), created_at: z.string(), transaction_count: z.number().int().optional()}); export const categoryRead = z.object({name: z.string(), icon: z.string().optional(), color: z.string().optional(), id: z.string(), user_id: z.string(), group_id: z.string().nullable().optional(), is_system: z.boolean(), is_hidden: z.boolean().optional(), treat_as_transfer: z.boolean().optional(), is_ignored: z.boolean().optional()}); export const payeeSummary = z.object({payee: payeeRead, total_spent: z.string().optional(), total_received: z.string().optional(), transaction_count: z.number().int().optional(), most_common_category: categoryRead.nullable().optional(), last_transaction_date: z.string().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 }; /** * Get Payee Summary * * GET /api/payees/{payee_id}/summary */ export const getApiApiPayeesPayeeIdSummary = async (args: GetApiApiPayeesPayeeIdSummaryArgs, options: GetApiApiPayeesPayeeIdSummaryOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args['X-Workspace-Id'] != null) headers.set("X-Workspace-Id", String(args['X-Workspace-Id'])) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/payees/${encodeURIComponent(String(args.payee_id))}/summary${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(payeeSummary, await res.json()) };