import {z} from 'zod' export type ObjectIDFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'Includes', value: Array}; export type DateFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'GreaterThan', value: string} | {_type: 'LessThan', value: string} | {_type: 'GreaterThanOrEqual', value: string} | {_type: 'LessThanOrEqual', value: string} | {_type: 'InBetween', startValue: string, endValue: string}; export type ShortTextFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string} | {_type: 'Includes', value: Array}; export type LongTextFilter = string | {_type: 'EqualTo', value: string} | {_type: 'NotEqual', value: string} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: string} | {_type: 'Search', value: string} | {_type: 'Includes', value: Array}; export type BooleanFilter = boolean | {_type: 'EqualTo', value: boolean} | {_type: 'NotEqual', value: boolean} | {_type: 'IsNull'} | {_type: 'NotNull'} | {_type: 'EqualToOrNull', value: boolean}; export type UserOnCallLogTimelineQuerySchema = {_id?: ObjectIDFilter | undefined, createdAt?: DateFilter | undefined, updatedAt?: DateFilter | undefined, deletedAt?: DateFilter | undefined, userId?: ObjectIDFilter | undefined, projectId?: ObjectIDFilter | undefined, userNotificationLogId?: ObjectIDFilter | undefined, userNotificationRuleId?: ObjectIDFilter | undefined, onCallDutyPolicyId?: ObjectIDFilter | undefined, triggeredByIncidentId?: ObjectIDFilter | undefined, triggeredByAlertId?: ObjectIDFilter | undefined, triggeredByAlertEpisodeId?: ObjectIDFilter | undefined, triggeredByIncidentEpisodeId?: ObjectIDFilter | undefined, onCallDutyPolicyExecutionLogId?: ObjectIDFilter | undefined, onCallDutyPolicyExecutionLogTimelineId?: ObjectIDFilter | undefined, userNotificationEventType?: ShortTextFilter | undefined, onCallDutyPolicyEscalationRuleId?: ObjectIDFilter | undefined, userBelongsToTeamId?: ObjectIDFilter | undefined, statusMessage?: LongTextFilter | undefined, status?: ShortTextFilter | undefined, createdByUserId?: ObjectIDFilter | undefined, isAcknowledged?: BooleanFilter | undefined, acknowledgedAt?: DateFilter | undefined, userCallId?: ObjectIDFilter | undefined, userSmsId?: ObjectIDFilter | undefined, userWhatsAppId?: ObjectIDFilter | undefined, userTelegramId?: ObjectIDFilter | undefined, userSlackId?: ObjectIDFilter | undefined, userMicrosoftTeamsId?: ObjectIDFilter | undefined, userMattermostId?: ObjectIDFilter | undefined, userWebhookId?: ObjectIDFilter | undefined, customNotificationChannelId?: ObjectIDFilter | undefined, userEmailId?: ObjectIDFilter | undefined, userPushId?: ObjectIDFilter | undefined}; export type CreateApiUserNotificationLogTimelineCountArgs = {body: {query?: UserOnCallLogTimelineQuerySchema | undefined}}; export type CreateApiUserNotificationLogTimelineCountOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiUserNotificationLogTimelineCountResponse = z.object({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 }; /** * Count User On-Call Log Timeline * * POST /user-notification-log-timeline/count */ export const createApiUserNotificationLogTimelineCount = async (args: CreateApiUserNotificationLogTimelineCountArgs, options?: CreateApiUserNotificationLogTimelineCountOptions) => { 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(/\/+$/, '')}/user-notification-log-timeline/count${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(createApiUserNotificationLogTimelineCountResponse, await res.json()) };