import {z} from 'zod' export type ObjectStatus = 'Active' | 'Inactive'; export type LogLevel = 'Verbose' | 'Debug' | 'Information' | 'Warning' | 'Error' | 'Fatal'; export type Log = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, level?: LogLevel | undefined, message?: (string | null) | undefined, user?: (string | null) | undefined, error?: (string | null) | undefined, comment?: (string | null) | undefined, owner?: (string | null) | undefined, ownerType?: (string | null) | undefined}; export type CreateApiApiTenantsTenantIdLogsArgs = {tenantId: number, body: Log}; export type CreateApiApiTenantsTenantIdLogsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const objectStatus = z.enum(["Active", "Inactive"]); export const logLevel = z.enum(["Verbose", "Debug", "Information", "Warning", "Error", "Fatal"]); export const log = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), level: logLevel.optional(), message: z.string().nullable().optional(), user: z.string().nullable().optional(), error: z.string().nullable().optional(), comment: z.string().nullable().optional(), owner: z.string().max(128).nullable().optional(), ownerType: z.string().max(128).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 }; /** * POST /api/tenants/{tenantId}/logs */ export const createApiApiTenantsTenantIdLogs = async (args: CreateApiApiTenantsTenantIdLogsArgs, options: CreateApiApiTenantsTenantIdLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/tenants/${encodeURIComponent(String(args.tenantId))}/logs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(log, await res.json()) };