import {z} from 'zod' export type IncidentResponderRelatedObject = 'users' | 'role_assignments'; export type GetApiApiV2IncidentsIncidentIdRespondersArgs = {incident_id: string, include?: Array | undefined, 'page[limit]'?: number | undefined, 'page[offset]'?: number | undefined}; export type GetApiApiV2IncidentsIncidentIdRespondersOptions = {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 incidentRoleAssignmentDataAttributesResponse = z.object({created: z.string(), deleted: z.string().optional(), modified: z.string(), responder_type: z.string(), role: z.string()}); export const incidentRoleAssignmentResponderRelationshipData = z.object({id: z.string(), type: z.string()}); export const incidentRoleAssignmentResponderRelationship = z.object({data: incidentRoleAssignmentResponderRelationshipData}); export const incidentRoleAssignmentRoleRelationshipData = z.object({id: z.string(), type: z.string()}).nullable(); export const incidentRoleAssignmentRoleRelationship = z.object({data: incidentRoleAssignmentRoleRelationshipData.optional()}); export const incidentRoleAssignmentRelationshipsResponse = z.object({created_by_user: incidentRoleAssignmentResponderRelationship.optional(), last_modified_by_user: incidentRoleAssignmentResponderRelationship.optional(), reserved_role: incidentRoleAssignmentRoleRelationship.optional(), responder: incidentRoleAssignmentResponderRelationship, user_defined_role: incidentRoleAssignmentRoleRelationship.optional()}); export const incidentRoleAssignmentType = z.literal("incident_role_assignments"); export const incidentRoleAssignmentDataResponse = z.object({attributes: incidentRoleAssignmentDataAttributesResponse, id: z.string(), relationships: incidentRoleAssignmentRelationshipsResponse.optional(), type: incidentRoleAssignmentType}); export const incidentResponderIncludedItem = z.union([incidentUserData, incidentRoleAssignmentDataResponse]); export const incidentRespondersResponseMetaPage = z.object({total_filtered_count: z.number().int()}); export const incidentRespondersPagination = z.object({first_offset: z.number().int().optional(), last_offset: z.number().int().nullable().optional(), limit: z.number().int().optional(), next_offset: z.number().int().nullable().optional(), offset: z.number().int().optional(), prev_offset: z.number().int().nullable().optional(), total: z.number().int().nullable().optional(), type: z.string().optional()}); export const incidentRespondersResponseMeta = z.object({page: incidentRespondersResponseMetaPage.optional(), pagination: incidentRespondersPagination.optional()}); export const incidentRespondersResponse = z.object({data: z.array(incidentResponderDataResponse), included: z.array(incidentResponderIncludedItem).optional(), links: z.record(z.string(), z.string()).optional(), meta: incidentRespondersResponseMeta.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 responders * * GET /api/v2/incidents/{incident_id}/responders * * Also accepts auth: AuthZ */ export const getApiApiV2IncidentsIncidentIdResponders = async (args: GetApiApiV2IncidentsIncidentIdRespondersArgs, options?: GetApiApiV2IncidentsIncidentIdRespondersOptions) => { 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 (args.include != null) query.append("include", args.include.join(',')) if (args['page[limit]'] != null) query.append("page[limit]", String(args['page[limit]'])) if (args['page[offset]'] != null) query.append("page[offset]", String(args['page[offset]'])) 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${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(incidentRespondersResponse, await res.json()) };