import {z} from 'zod' export type GetApiV1ProjectsProjectIdBreakGlassEventsArgs = {projectId: string}; export type GetApiV1ProjectsProjectIdBreakGlassEventsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const breakGlassEventDto = z.object({jti: z.string(), env: z.enum(["production", "staging", "uat", "dev"]), durationHours: z.number().gte(1).lte(72), notAfter: z.string(), reason: z.string(), issuedAt: z.string(), revokedAt: z.string().nullable(), revokedReason: z.string().nullable()}); export const breakGlassEventListDto = z.object({items: z.array(breakGlassEventDto)}); 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 recent break-glass token issuances and revocations for a project (ECO-114). * * GET /v1/projects/{projectId}/break-glass/events */ export const getApiV1ProjectsProjectIdBreakGlassEvents = async (args: GetApiV1ProjectsProjectIdBreakGlassEventsArgs, options: GetApiV1ProjectsProjectIdBreakGlassEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/break-glass/events${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(breakGlassEventListDto, await res.json()) };