import * as z from "zod/mini"; import { appEventPayloadSchema } from "./app-event.js"; import { telemetryEnvelopeSchema } from "./telemetry-envelope.js"; export const TRAFFIC_TELEMETRY_RPC_METHOD = "traffic.telemetry"; export type TrafficTelemetryRpcMethod = typeof TRAFFIC_TELEMETRY_RPC_METHOD; export const trafficTelemetryRpcParamsSchema = z.object({ envelope: telemetryEnvelopeSchema, }); export type TrafficTelemetryRpcParams = z.output< typeof trafficTelemetryRpcParamsSchema >; export const trafficTelemetryRpcResultSchema = z.discriminatedUnion("allowed", [ z.object({ allowed: z.literal(true), envelope: telemetryEnvelopeSchema, }), z.object({ allowed: z.literal(false), }), ]); export type TrafficTelemetryRpcResult = z.output< typeof trafficTelemetryRpcResultSchema >; export const TRAFFIC_APP_EVENT_RPC_METHOD = "traffic.appEvent"; export type TrafficAppEventRpcMethod = typeof TRAFFIC_APP_EVENT_RPC_METHOD; export const trafficAppEventRpcParamsSchema = z.object({ instanceId: z.string().check(z.trim(), z.minLength(1)), payload: appEventPayloadSchema, }); export type TrafficAppEventRpcParams = z.output< typeof trafficAppEventRpcParamsSchema >; export const trafficAppEventRpcResultSchema = z.discriminatedUnion("allowed", [ z.object({ allowed: z.literal(true), payload: appEventPayloadSchema, }), z.object({ allowed: z.literal(false), }), ]); export type TrafficAppEventRpcResult = z.output< typeof trafficAppEventRpcResultSchema >; export interface TrafficTelemetryRpcContract { method: TrafficTelemetryRpcMethod; params: TrafficTelemetryRpcParams; result: TrafficTelemetryRpcResult; } export interface TrafficAppEventRpcContract { method: TrafficAppEventRpcMethod; params: TrafficAppEventRpcParams; result: TrafficAppEventRpcResult; }