import {z} from 'zod' export type AnalyticsPdAdvanceUsageFilter = {filters?: ({created_at_start?: string | undefined, created_at_end?: string | undefined, incident_created_at_start?: string | undefined, incident_created_at_end?: string | undefined, urgency?: ('high' | 'low') | undefined, major?: boolean | undefined, min_ackowledgements?: number | undefined, min_timeout_escalations?: number | undefined, min_manual_escalations?: number | undefined, team_ids?: Array | undefined, service_ids?: Array | undefined, escalation_policy_ids?: Array | undefined, priority_ids?: Array | undefined, priority_names?: Array | undefined}) | undefined, time_zone?: string | undefined}; export type CreateApiAnalyticsMetricsPdAdvanceUsageFeaturesArgs = {Accept: string, 'Content-Type': 'application/json', body: AnalyticsPdAdvanceUsageFilter}; export type CreateApiAnalyticsMetricsPdAdvanceUsageFeaturesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAnalyticsMetricsPdAdvanceUsageFeaturesResponse = z.object({data: z.array(z.object({feature_id: z.string().optional(), total_credits_used: z.number().int().optional(), total_use_count: z.number().int().optional(), total_proactive_credits_used: z.number().int().optional(), total_proactive_use_count: z.number().int().optional()})).optional(), filters: z.object({created_at_start: z.string().optional(), created_at_end: z.string().optional(), incident_created_at_start: z.string().optional(), incident_created_at_end: z.string().optional(), urgency: z.enum(["high", "low"]).optional(), major: z.boolean().optional(), min_ackowledgements: z.number().int().optional(), min_timeout_escalations: z.number().int().optional(), min_manual_escalations: z.number().int().optional(), team_ids: z.array(z.string()).optional(), service_ids: z.array(z.string()).optional(), escalation_policy_ids: z.array(z.string()).optional(), priority_ids: z.array(z.string()).optional(), priority_names: 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 PD Advance usage data * * POST /analytics/metrics/pd_advance_usage/features */ export const createApiAnalyticsMetricsPdAdvanceUsageFeatures = async (args: CreateApiAnalyticsMetricsPdAdvanceUsageFeaturesArgs, options?: CreateApiAnalyticsMetricsPdAdvanceUsageFeaturesOptions) => { 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/pd_advance_usage/features${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(createApiAnalyticsMetricsPdAdvanceUsageFeaturesResponse, await res.json()) };