import {z} from 'zod' export type GetApiApiV2IncidentsIncidentIdTimestampOverridesArgs = {incident_id: string}; export type GetApiApiV2IncidentsIncidentIdTimestampOverridesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentTimestampType = z.enum(["detected", "resolved", "declared"]); export const incidentTimestampOverrideDataAttributesResponse = z.object({created_at: z.string(), deleted_at: z.string().nullable().optional(), incident_id: z.string(), modified_at: z.string(), timestamp_type: incidentTimestampType, timestamp_value: z.string()}); export const usersType = z.literal("users"); export const relationshipToUserData = z.object({id: z.string(), type: usersType}); export const relationshipToUser = z.object({data: relationshipToUserData}); export const incidentTimestampOverrideRelationships = z.object({created_by_user: relationshipToUser.optional(), last_modified_by_user: relationshipToUser.optional()}); export const incidentTimestampOverrideType = z.literal("incidents_timestamp_overrides"); export const incidentTimestampOverrideDataResponse = z.object({attributes: incidentTimestampOverrideDataAttributesResponse, id: z.string(), relationships: incidentTimestampOverrideRelationships.optional(), type: incidentTimestampOverrideType}); export const incidentUserAttributes = z.object({email: z.string().optional(), handle: z.string().optional(), icon: z.string().optional(), name: z.string().nullable().optional(), uuid: z.string().optional()}); export const incidentUserData = z.object({attributes: incidentUserAttributes.optional(), id: z.string().optional(), type: usersType.optional()}); export const incidentTimestampOverridesResponse = z.object({data: z.array(incidentTimestampOverrideDataResponse), included: z.array(incidentUserData).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 incident timestamp overrides * * GET /api/v2/incidents/{incident_id}/timestamp-overrides * * Also accepts auth: AuthZ */ export const getApiApiV2IncidentsIncidentIdTimestampOverrides = async (args: GetApiApiV2IncidentsIncidentIdTimestampOverridesArgs, options?: GetApiApiV2IncidentsIncidentIdTimestampOverridesOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/incidents/${encodeURIComponent(String(args.incident_id))}/timestamp-overrides${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(incidentTimestampOverridesResponse, await res.json()) };