import {z} from 'zod' export type GetApiApiPayeesPayeeIdArgs = {payee_id: string, 'X-Workspace-Id'?: (string | null) | undefined}; export type GetApiApiPayeesPayeeIdOptions = {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 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 * * GET /api/payees/{payee_id} */ export const getApiApiPayeesPayeeId = async (args: GetApiApiPayeesPayeeIdArgs, options: GetApiApiPayeesPayeeIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") 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))}${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(payeeRead, await res.json()) };