/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type Event = { id?: string | undefined; /** * The tenant this event belongs to. */ tenantId?: string | undefined; /** * The destination IDs that this event was routed to based on topic and filter matching. */ matchedDestinationIds?: Array | undefined; topic?: string | undefined; /** * Time the event was received/processed. */ time?: Date | undefined; /** * Key-value string pairs of metadata associated with the event. */ metadata?: { [k: string]: string } | null | undefined; /** * Freeform JSON data of the event. */ data?: { [k: string]: any } | undefined; }; /** @internal */ export const Event$inboundSchema: z.ZodType = z .object({ id: z.string().optional(), tenant_id: z.string().optional(), matched_destination_ids: z.array(z.string()).optional(), topic: z.string().optional(), time: z.string().datetime({ offset: true }).transform(v => new Date(v)) .optional(), metadata: z.nullable(z.record(z.string())).optional(), data: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { "tenant_id": "tenantId", "matched_destination_ids": "matchedDestinationIds", }); }); /** @internal */ export type Event$Outbound = { id?: string | undefined; tenant_id?: string | undefined; matched_destination_ids?: Array | undefined; topic?: string | undefined; time?: string | undefined; metadata?: { [k: string]: string } | null | undefined; data?: { [k: string]: any } | undefined; }; /** @internal */ export const Event$outboundSchema: z.ZodType< Event$Outbound, z.ZodTypeDef, Event > = z.object({ id: z.string().optional(), tenantId: z.string().optional(), matchedDestinationIds: z.array(z.string()).optional(), topic: z.string().optional(), time: z.date().transform(v => v.toISOString()).optional(), metadata: z.nullable(z.record(z.string())).optional(), data: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { tenantId: "tenant_id", matchedDestinationIds: "matched_destination_ids", }); }); export function eventToJSON(event: Event): string { return JSON.stringify(Event$outboundSchema.parse(event)); } export function eventFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Event$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Event' from JSON`, ); }