import {z} from 'zod' export type GetApiXAuditLogsScheduleUpdated1Options = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const auditLogActorMetadataV2 = z.object({api_key_roles: z.string().optional(), external_resource_external_id: z.string().optional(), external_resource_type: z.string().optional(), user_base_role_slug: z.string().optional(), user_custom_role_slugs: z.string().optional()}); export const auditLogActorV2 = z.object({id: z.string(), metadata: auditLogActorMetadataV2.optional(), name: z.string().optional(), type: z.enum(["user", "system", "api_key", "workflow", "external_resource"])}); export const auditLogEntryContextV2 = z.object({location: z.string(), user_agent: z.string().optional()}); export const auditLogTargetV2 = z.object({id: z.string(), name: z.string().optional(), type: z.enum(["api_key", "alert_route", "alert_schema", "alert_source", "announcement_rule", "catalog_type", "custom_field", "debrief_invite_rule", "escalation_path", "follow_up_priority", "holiday_user_feed", "incident", "incident_call_setting", "incident_duration_metric", "incident_role", "incident_status", "incident_timestamp", "incident_type", "integration", "internal_status_page", "nudge", "schedule_override", "policy", "post_incident_task", "postmortem_template", "postmortem_template_section", "private_incident_membership", "rbac_role", "scim_group", "schedule", "severity", "status_page", "status_page_sub_page", "status_page_template", "user", "workflow"])}); export const auditLogsScheduleUpdatedV1ResponseBody = z.object({action: z.string(), actor: auditLogActorV2, context: auditLogEntryContextV2, occurred_at: z.string(), targets: z.array(auditLogTargetV2), version: z.number().int()}); 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 }; /** * ScheduleUpdatedV1 Audit logs * * GET /x-audit-logs/schedule.updated.1 */ export const getApiXAuditLogsScheduleUpdated1 = async (options?: GetApiXAuditLogsScheduleUpdated1Options) => { const {baseUrl = "https:////api.incident.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/x-audit-logs/schedule.updated.1${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(auditLogsScheduleUpdatedV1ResponseBody, await res.json()) };