import {z} from 'zod' export type GetApiV4OrganizationsOrganizationIdEventsEventIdOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const getEventResponse = z.object({id: z.string(), source: z.string(), key: z.string(), severity: z.string(), timestamp: z.string(), projectId: z.string().optional(), projectName: z.string().optional(), clusterId: z.string().optional(), clusterName: z.string().optional(), appServiceId: z.string().optional(), appServiceName: z.string().optional(), userId: z.string().optional(), userName: z.string().optional(), userEmail: z.string().optional(), sessionId: z.string().optional(), requestId: z.string().optional(), kv: z.object({}).optional(), summary: z.string().optional(), incidentIds: z.array(z.string()).optional(), occurrenceCount: z.number().int().optional(), imageURL: z.string().optional(), alertKey: z.string().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 }; /** * Get Event * * GET /v4/organizations/{organizationId}/events/{eventId} */ export const getApiV4OrganizationsOrganizationIdEventsEventId = async (options?: GetApiV4OrganizationsOrganizationIdEventsEventIdOptions) => { const {baseUrl = "https://cloudapi.cloud.couchbase.com", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/v4/organizations/${encodeURIComponent(String(args.organizationId))}/events/${encodeURIComponent(String(args.eventId))}${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(getEventResponse, await res.json()) };