import {z} from 'zod' export type GetApiProjectsProjectIdFaultsFaultIdNoticesArgs = {project_id: string, fault_id: string, limit?: number | undefined, before?: string | undefined, after?: string | undefined, unmapped?: boolean | undefined}; export type GetApiProjectsProjectIdFaultsFaultIdNoticesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sourceBlock = z.object({first_line: z.number().int(), lines: z.array(z.string().max(1024))}); export const noticeFrame = z.object({file: z.string().nullable().optional(), line: z.number().int().nullable().optional(), column: z.number().int().nullable().optional(), method: z.string().nullable().optional(), in_app: z.boolean().optional(), mapping: z.enum(["source_mapped", "reported"]).optional(), source: z.array(sourceBlock).optional()}); export const webLinks = z.object({web: z.string()}); export const notice = z.object({id: z.string(), fault_id: z.string(), project_id: z.string(), environment: z.string().nullable().optional(), message: z.string().nullable(), created_at: z.string(), request: z.object({url: z.string().nullable().optional(), component: z.string().nullable().optional(), action: z.string().nullable().optional(), params: z.object({}).nullable().optional(), session: z.object({}).nullable().optional()}).nullable().optional(), context: z.record(z.string(), z.unknown()).optional(), backtrace: z.array(noticeFrame).optional(), backtrace_mode: z.enum(["source_mapped", "reported"]).optional(), backtrace_total_frames: z.number().int().optional(), backtrace_truncated: z.boolean().optional(), request_fields_removed: z.array(z.string()).nullable().optional(), links: webLinks.optional()}); export const timeSeriesPagination = z.object({limit: z.number().int().gte(1).lte(100), has_older: z.boolean(), has_newer: z.boolean(), oldest_cursor: z.string().nullable().optional(), newest_cursor: z.string().nullable().optional()}); export const timeSeriesLinks = z.object({self: z.string(), older: z.string().nullable().optional(), newer: z.string().nullable().optional()}); export const responseMeta = z.object({request_id: z.string().optional()}); export const getApiProjectsProjectIdFaultsFaultIdNoticesResponse = z.object({data: z.array(notice), pagination: timeSeriesPagination.optional(), links: timeSeriesLinks.optional(), meta: responseMeta.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 notices * * GET /projects/{project_id}/faults/{fault_id}/notices */ export const getApiProjectsProjectIdFaultsFaultIdNotices = async (args: GetApiProjectsProjectIdFaultsFaultIdNoticesArgs, options?: GetApiProjectsProjectIdFaultsFaultIdNoticesOptions) => { const {baseUrl = "https://app.honeybadger.io/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.before != null) query.append("before", String(args.before)) if (args.after != null) query.append("after", String(args.after)) if (args.unmapped != null) query.append("unmapped", String(args.unmapped)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/faults/${encodeURIComponent(String(args.fault_id))}/notices${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(getApiProjectsProjectIdFaultsFaultIdNoticesResponse, await res.json()) };