import {z} from 'zod' export type SortOrder = 0 | 1; export type AuditLogEventType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; export type GetApiOrganizationsOrganizationIdLibraryItemsLibraryItemIdLogsArgs = {'SortField.Name'?: string | undefined, 'SortField.Order'?: SortOrder | undefined, PageNumber?: number | undefined, PageSize?: number | undefined, EntityId?: number | undefined, UserName?: string | undefined, Type?: Array | undefined, organizationId: number, libraryItemId: number}; export type GetApiOrganizationsOrganizationIdLibraryItemsLibraryItemIdLogsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const inputOptionDto = z.object({constant: z.number().nullable().optional(), polynomial: z.array(z.number()).nullable().optional(), curve: z.array(z.array(z.number())).nullable().optional()}); export const propertyDto = z.object({name: z.string().nullable().optional(), value: inputOptionDto.optional()}); export const libraryItemAuditLogDto = z.object({entityId: z.number().int().nullable().optional(), name: z.string().nullable().optional(), userName: z.string().nullable().optional(), updated: z.string().nullable().optional(), eventType: z.string().nullable().optional(), action: z.string().nullable().optional(), project: z.string().nullable().optional(), data: z.string().nullable().optional(), caseId: z.number().int().nullable().optional(), properties: z.array(propertyDto).nullable().optional()}); export const libraryItemAuditLogDtoPageResult = z.object({items: z.array(libraryItemAuditLogDto).nullable().optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), totalItems: z.number().int().optional(), totalPages: 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 library item history * * GET /organizations/{organizationId}/library-items/{libraryItemId}/logs */ export const getApiOrganizationsOrganizationIdLibraryItemsLibraryItemIdLogs = async (args: GetApiOrganizationsOrganizationIdLibraryItemsLibraryItemIdLogsArgs, options?: GetApiOrganizationsOrganizationIdLibraryItemsLibraryItemIdLogsOptions) => { const {baseUrl = "https://case.coldstream.diabatix.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['SortField.Name'] != null) query.append("SortField.Name", String(args['SortField.Name'])) if (args['SortField.Order'] != null) query.append("SortField.Order", String(args['SortField.Order'])) if (args.PageNumber != null) query.append("PageNumber", String(args.PageNumber)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.EntityId != null) query.append("EntityId", String(args.EntityId)) if (args.UserName != null) query.append("UserName", String(args.UserName)) for (const item of args.Type ?? []) query.append("Type", String(item)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organizationId))}/library-items/${encodeURIComponent(String(args.libraryItemId))}/logs${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(libraryItemAuditLogDtoPageResult, await res.json()) };