import {z} from 'zod' export type GetApiApiV1ActivityLogsArgs = {Entity?: (string | null) | undefined, Id?: number | undefined, Ids?: (Array | null) | undefined, SearchDate?: (string | null) | undefined, From?: (string | null) | undefined, To?: (string | null) | undefined, Page?: number | undefined, PageSize?: number | undefined}; export type GetApiApiV1ActivityLogsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const changeTypeEnum = z.union([z.literal(1), z.literal(2), z.literal(3)]); export const activityLogItem = z.object({entity: z.string().nullable().optional(), id: z.number().int().optional(), changedBy: z.string().nullable().optional(), changedDate: z.string().optional(), changedColumn: z.string().nullable().optional(), changedFrom: z.string().nullable().optional(), changedTo: z.string().nullable().optional(), customValues: z.record(z.string(), z.string()).nullable().optional(), changeType: changeTypeEnum.optional()}); export const getApiApiV1ActivityLogsResponse = z.array(activityLogItem); 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 /api/v1/ActivityLogs */ export const getApiApiV1ActivityLogs = async (args: GetApiApiV1ActivityLogsArgs, options: GetApiApiV1ActivityLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Entity != null) query.append("Entity", String(args.Entity)) if (args.Id != null) query.append("Id", String(args.Id)) for (const item of args.Ids ?? []) query.append("Ids", String(item)) if (args.SearchDate != null) query.append("SearchDate", String(args.SearchDate)) if (args.From != null) query.append("From", String(args.From)) if (args.To != null) query.append("To", String(args.To)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/ActivityLogs${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(getApiApiV1ActivityLogsResponse, await res.json()) };