import {z} from 'zod' export type MonitorLogV3QuerySchema = {projectId?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}) | undefined, monitorId?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}) | undefined, time?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThan', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}) | undefined, logBody?: ({_type: 'IsNull'} | {_type: 'NotNull'}) | undefined, _id?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'Includes', value: Array}) | undefined, createdAt?: (string | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'GreaterThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThan', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}) | undefined}; export type MonitorLogV3SelectSchema = {projectId?: boolean | undefined, monitorId?: boolean | undefined, time?: boolean | undefined, logBody?: boolean | undefined, _id?: boolean | undefined, createdAt?: boolean | undefined}; export type MonitorLogV3SortSchema = {projectId?: ('ASC' | 'DESC') | undefined, monitorId?: ('ASC' | 'DESC') | undefined, time?: ('ASC' | 'DESC') | undefined, retentionDate?: ('ASC' | 'DESC') | undefined, _id?: ('ASC' | 'DESC') | undefined, createdAt?: ('ASC' | 'DESC') | undefined}; export type MonitorLogV3GroupBySchema = {projectId?: boolean | undefined, monitorId?: boolean | undefined, _id?: boolean | undefined, createdAt?: boolean | undefined}; export type CreateApiMonitorLogGetListArgs = {body: {query?: MonitorLogV3QuerySchema | undefined, select?: MonitorLogV3SelectSchema | undefined, sort?: MonitorLogV3SortSchema | undefined, groupBy?: MonitorLogV3GroupBySchema | undefined, limit?: number | undefined, skip?: number | undefined}}; export type CreateApiMonitorLogGetListOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const monitorLogV3 = z.object({projectId: z.string(), monitorId: z.string(), time: z.string().optional(), logBody: z.object({}).optional()}); export const createApiMonitorLogGetListResponse = z.object({data: z.array(monitorLogV3).optional(), count: z.number().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 }; /** * List Monitor Log * * POST /monitor-log/get-list */ export const createApiMonitorLogGetList = async (args: CreateApiMonitorLogGetListArgs, options?: CreateApiMonitorLogGetListOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/monitor-log/get-list${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(createApiMonitorLogGetListResponse, await res.json()) };