import {z} from 'zod' export type GetApiApiV1FeesIdArgs = {id: string}; export type GetApiApiV1FeesIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1FeesIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), projectId: z.string(), personId: z.string().nullable(), placementId: z.string().nullable(), createdById: z.string(), feeType: z.object({id: z.string(), name: z.string(), deletedAt: z.string().nullable()}).nullable(), feeDate: z.string().nullable(), amount: z.string().nullable(), defaultAmount: z.string().nullable(), currency: z.string(), defaultCurrency: z.string(), projectFeeStatus: z.enum(["projected", "earned", "invoiced", "paid"]), notes: z.string().nullable(), externalInvoiceNumber: z.string().nullable(), invoiceAccountCode: z.string().nullable(), paidAt: z.string().nullable(), invoicedAt: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), deletedAt: z.string().nullable(), splits: z.array(z.object({id: z.string(), feeEarner: z.object({id: z.string(), name: z.string().nullable(), email: z.string().nullable()}), feeType: z.object({id: z.string(), name: z.string(), deletedAt: z.string().nullable()}).nullable(), share: z.string().nullable(), notes: z.string().nullable(), deletedAt: z.string().nullable()}))})}); 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 fee details * * GET /api/v1/fees/{id} */ export const getApiApiV1FeesId = async (args: GetApiApiV1FeesIdArgs, options: GetApiApiV1FeesIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v1/fees/${encodeURIComponent(String(args.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(getApiApiV1FeesIdResponse, await res.json()) };