import {z} from 'zod' export type GetApiProjectsProjectIdSitesSiteIdChecksArgs = {project_id: string, site_id: string, limit?: number | undefined, created_after?: number | undefined, created_before?: number | undefined}; export type GetApiProjectsProjectIdSitesSiteIdChecksOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const siteLocation = z.enum(["Virginia", "Frankfurt", "Singapore", "London", "Oregon"]); export const uptimeCheck = z.object({created_at: z.string(), duration: z.number().int().nullable().optional(), location: siteLocation.nullable().optional(), up: z.boolean().nullable().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 getApiProjectsProjectIdSitesSiteIdChecksResponse = z.object({data: z.array(uptimeCheck), 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 uptime checks * * GET /projects/{project_id}/sites/{site_id}/checks */ export const getApiProjectsProjectIdSitesSiteIdChecks = async (args: GetApiProjectsProjectIdSitesSiteIdChecksArgs, options?: GetApiProjectsProjectIdSitesSiteIdChecksOptions) => { 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.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/sites/${encodeURIComponent(String(args.site_id))}/checks${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(getApiProjectsProjectIdSitesSiteIdChecksResponse, await res.json()) };