import {z} from 'zod' export type GetApiV1AccountIdIncidentsIncidentIdCommentsArgs = {accountId: string, incidentId: string, sortOrder?: string | undefined, sortBy?: string | undefined, fields?: string | undefined, limit?: number | undefined, duration?: string | undefined, startAfter?: string | undefined, groupBy?: string | undefined}; export type GetApiV1AccountIdIncidentsIncidentIdCommentsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const comment = z.object({id: z.string().optional(), incidentId: z.string().optional(), account: z.string().optional(), user: z.string().optional(), comment: z.string().optional(), creationTime: z.string().optional()}); export const commentWithActionTransition = z.object({id: z.string().optional(), incidentId: z.string().optional(), account: z.string().optional(), user: z.string().optional(), comment: z.string().optional(), creationTime: z.string().optional(), command: z.string().optional(), actionId: z.string().optional(), context: z.string().optional()}); export const commentWithIncidentTransition = z.object({id: z.string().optional(), incidentId: z.string().optional(), account: z.string().optional(), user: z.string().optional(), comment: z.string().optional(), creationTime: z.string().optional(), newStatus: z.string().optional(), context: z.string().optional()}); export const updatedComment = z.union([comment, commentWithActionTransition, commentWithIncidentTransition, z.object({lastUpdateTime: z.string().optional()})]); export const fetchComments = z.object({items: z.array(z.union([comment, updatedComment, commentWithIncidentTransition, commentWithActionTransition])).optional(), count: z.number().int().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 }; /** * Retrieves a list of comments for an incident. * * GET /v1/{accountId}/incidents/{incidentId}/comments */ export const getApiV1AccountIdIncidentsIncidentIdComments = async (args: GetApiV1AccountIdIncidentsIncidentIdCommentsArgs, options?: GetApiV1AccountIdIncidentsIncidentIdCommentsOptions) => { const {baseUrl = "https://api.usa.cloud.watchguard.com/rest/threatsync/management", fetch: fetchFn = fetch, ApiKeyAuth, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.duration != null) query.append("duration", String(args.duration)) if (args.startAfter != null) query.append("startAfter", String(args.startAfter)) if (args.groupBy != null) query.append("groupBy", String(args.groupBy)) if (ApiKeyAuth !== undefined) headers.set("WatchGuard-API-Key", ApiKeyAuth) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.accountId))}/incidents/${encodeURIComponent(String(args.incidentId))}/comments${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(fetchComments, await res.json()) };