import {z} from 'zod' export type GetApiV1TestSessionErrorGroupsProjectsProjectIdArgs = {projectId: string, 'x-checkly-account'?: string | undefined}; export type GetApiV1TestSessionErrorGroupsProjectsProjectIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const testSessionErrorGroupPlaywrightMetadata = z.object({projectName: z.string(), specId: z.string().max(500).optional(), testFile: z.string(), testTitle: z.string(), suitePath: z.array(z.string())}); export const testSessionErrorGroupRootCauseAnalysis = z.object({id: z.string().optional(), created_at: z.string().optional(), analysis: z.unknown(), provider: z.string().nullable().optional(), model: z.string().nullable().optional(), durationMs: z.number().nullable().optional(), userContext: z.unknown()}); export const testSessionErrorGroup = z.object({id: z.string(), projectId: z.string().nullable().optional(), environments: z.array(z.string()).nullable(), errorHash: z.string(), rawErrorMessage: z.string().nullable(), cleanedErrorMessage: z.string(), firstSeen: z.string(), lastSeen: z.string(), archivedUntilNextEvent: z.boolean(), pwtMetadata: z.array(testSessionErrorGroupPlaywrightMetadata).nullable(), rootCauseAnalyses: z.array(testSessionErrorGroupRootCauseAnalysis).optional()}); export const testSessionErrorGroupsList = z.array(testSessionErrorGroup); 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 all test session error groups for a specific project. * * GET /v1/test-session-error-groups/projects/{projectId} */ export const getApiV1TestSessionErrorGroupsProjectsProjectId = async (args: GetApiV1TestSessionErrorGroupsProjectsProjectIdArgs, options?: GetApiV1TestSessionErrorGroupsProjectsProjectIdOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-checkly-account'] != null) headers.set("x-checkly-account", String(args['x-checkly-account'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/test-session-error-groups/projects/${encodeURIComponent(String(args.projectId))}${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(testSessionErrorGroupsList, await res.json()) };