import {z} from 'zod' export type GetApiV11EventSchemasViolationsPipelineEventsArgs = {earliestSeen?: (string | null) | undefined, writeKey?: string | undefined, eventName?: string | undefined, type?: string | undefined, field?: string | undefined, details?: string | undefined, schemaId?: string | undefined, versionId?: string | undefined, limit?: number | undefined}; export type GetApiV11EventSchemasViolationsPipelineEventsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const googleProtobufListValue = z.object({values: z.array(z.union([z.object({}).nullable(), z.lazy(() => googleProtobufValue)])).nullable().optional()}); export const googleProtobufValue: z.ZodType = z.object({boolValue: z.boolean().optional(), listValue: z.union([z.object({}).nullable(), googleProtobufListValue]).optional(), nullValue: z.literal("NULL_VALUE").optional(), numberValue: z.number().optional(), stringValue: z.string().optional(), structValue: z.union([z.object({}).nullable(), z.lazy(() => googleProtobufStruct)]).optional()}); export const googleProtobufStruct: z.ZodType = z.object({fields: z.record(z.string(), z.union([z.object({}).nullable(), googleProtobufValue])).nullable().optional()}); export const protobufControlpbV1GetEventSchemaViolationEventsResponse = z.object({events: z.array(z.union([z.object({}).nullable(), googleProtobufStruct])).nullable().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 }; /** * GetEventSchemaViolationEvents gets a sampling of events that match a schema violation. * * GET /v1.1/event_schemas/violations/pipeline/events */ export const getApiV11EventSchemasViolationsPipelineEvents = async (args: GetApiV11EventSchemasViolationsPipelineEventsArgs, options?: GetApiV11EventSchemasViolationsPipelineEventsOptions) => { const {baseUrl = "https://www.metarouter.io/contact", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.earliestSeen != null) query.append("earliestSeen", String(args.earliestSeen)) if (args.writeKey != null) query.append("writeKey", String(args.writeKey)) if (args.eventName != null) query.append("eventName", String(args.eventName)) if (args.type != null) query.append("type", String(args.type)) if (args.field != null) query.append("field", String(args.field)) if (args.details != null) query.append("details", String(args.details)) if (args.schemaId != null) query.append("schemaId", String(args.schemaId)) if (args.versionId != null) query.append("versionId", String(args.versionId)) if (args.limit != null) query.append("limit", String(args.limit)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1.1/event_schemas/violations/pipeline/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(protobufControlpbV1GetEventSchemaViolationEventsResponse, await res.json()) };