import {z} from 'zod' export type GetApiApiV2IncidentsIncidentIdRespondersResponderIdArgs = {incident_id: string, responder_id: string}; export type GetApiApiV2IncidentsIncidentIdRespondersResponderIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const incidentResponderDataAttributesResponse = z.object({created: z.string(), external_id: z.string().nullable().optional(), external_source: z.string().nullable().optional(), is_billable: z.boolean(), last_active: z.string().nullable().optional(), meta: z.record(z.string(), z.unknown()).nullable().optional(), modified: 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 incidentResponderRoleAssignmentRelationshipData = z.object({id: z.string(), type: z.string()}); export const incidentResponderRoleAssignmentsRelationship = z.object({data: z.array(incidentResponderRoleAssignmentRelationshipData).optional()}); export const nullableRelationshipToUserData = z.object({id: z.string(), type: usersType}).nullable(); export const nullableRelationshipToUser = z.object({data: nullableRelationshipToUserData}).nullable(); export const incidentResponderRelationships = z.object({created_by: relationshipToUser.optional(), last_modified_by: relationshipToUser.optional(), role_assignments: incidentResponderRoleAssignmentsRelationship.optional(), user: nullableRelationshipToUser.optional()}); export const incidentResponderType = z.literal("incident_responders"); export const incidentResponderDataResponse = z.object({attributes: incidentResponderDataAttributesResponse, id: z.string(), relationships: incidentResponderRelationships.optional(), type: incidentResponderType}); 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 incidentResponderResponse = z.object({data: incidentResponderDataResponse, 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 }; /** * Get an incident responder * * GET /api/v2/incidents/{incident_id}/responders/{responder_id} * * Also accepts auth: AuthZ */ export const getApiApiV2IncidentsIncidentIdRespondersResponderId = async (args: GetApiApiV2IncidentsIncidentIdRespondersResponderIdArgs, options?: GetApiApiV2IncidentsIncidentIdRespondersResponderIdOptions) => { 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))}/responders/${encodeURIComponent(String(args.responder_id))}${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(incidentResponderResponse, await res.json()) };