import {z} from 'zod' export type AnalyticsUserFilterConditions = {created_at_start?: string | undefined, created_at_end?: string | undefined, team_ids?: Array | undefined, user_ids?: Array | undefined, role_ids?: Array | undefined}; export type AnalyticsUserFilter = {filters?: AnalyticsUserFilterConditions | undefined, time_zone?: string | undefined, order?: ('asc' | 'desc') | undefined, order_by?: string | undefined, aggregate_unit?: ('day' | 'week' | 'month' | null) | undefined, limit?: number | undefined, starting_after?: (string | null) | undefined, ending_before?: (string | null) | undefined}; export type CreateApiAnalyticsMetricsUsersAllArgs = {Accept: string, 'Content-Type': 'application/json', body: AnalyticsUserFilter}; export type CreateApiAnalyticsMetricsUsersAllOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const analyticsUserMetrics = z.object({total_downloaded_mobile_app_count: z.number().int().optional(), total_downloaded_mobile_app_percentage: z.number().optional(), total_on_escalation_policy_count: z.number().int().optional(), total_on_escalation_policy_percentage: z.number().optional(), total_signed_up_count: z.number().int().optional(), total_signed_up_percentage: z.number().optional(), total_user_count: z.number().int().optional(), total_with_notification_methods_count: z.number().int().optional(), total_with_notification_methods_percentage: z.number().optional()}); export const createApiAnalyticsMetricsUsersAllResponse = z.object({data: z.array(analyticsUserMetrics).optional(), filters: z.object({created_at_start: z.string().optional(), created_at_end: z.string().optional(), team_ids: z.array(z.string()).optional()}).optional(), time_zone: z.string().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 aggregated metrics for all users * * POST /analytics/metrics/users/all */ export const createApiAnalyticsMetricsUsersAll = async (args: CreateApiAnalyticsMetricsUsersAllArgs, options?: CreateApiAnalyticsMetricsUsersAllOptions) => { const {baseUrl = "https://api.pagerduty.com", 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 (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/analytics/metrics/users/all${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(createApiAnalyticsMetricsUsersAllResponse, await res.json()) };