/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; 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"; /** * Represents an envelope and the data of an event */ export type EventMessage = { /** * The account group ID related to the event (if applicable) */ accountGroupId?: string | undefined; /** * The account ID related to the event (if applicable) */ accountId?: string | undefined; /** * The client ID related to the event */ clientId?: string | undefined; /** * The correspondent ID related to the event (if applicable) */ correspondentId?: string | undefined; /** * A data payload containing the fields specific to the type of event being sent */ data?: { [k: string]: any } | null | undefined; /** * Specifies the action that triggered the event as well as what resource changed */ eventType?: string | undefined; /** * A unique identifier for the event */ messageId?: string | undefined; /** * The resource name of the event; Format: messages/{message} */ name?: string | undefined; /** * A value, if present, is used to group related events together; Events with the same partition key are guaranteed to be sent to the consumer in the same order they were published */ partitionKey?: string | undefined; /** * The date and time of the event publication (not necessarily the time the event occurred) */ publishTime?: Date | null | undefined; }; /** @internal */ export const EventMessage$inboundSchema: z.ZodType< EventMessage, z.ZodTypeDef, unknown > = z.object({ account_group_id: z.string().optional(), account_id: z.string().optional(), client_id: z.string().optional(), correspondent_id: z.string().optional(), data: z.nullable(z.record(z.any())).optional(), event_type: z.string().optional(), message_id: z.string().optional(), name: z.string().optional(), partition_key: z.string().optional(), publish_time: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), }).transform((v) => { return remap$(v, { "account_group_id": "accountGroupId", "account_id": "accountId", "client_id": "clientId", "correspondent_id": "correspondentId", "event_type": "eventType", "message_id": "messageId", "partition_key": "partitionKey", "publish_time": "publishTime", }); }); /** @internal */ export type EventMessage$Outbound = { account_group_id?: string | undefined; account_id?: string | undefined; client_id?: string | undefined; correspondent_id?: string | undefined; data?: { [k: string]: any } | null | undefined; event_type?: string | undefined; message_id?: string | undefined; name?: string | undefined; partition_key?: string | undefined; publish_time?: string | null | undefined; }; /** @internal */ export const EventMessage$outboundSchema: z.ZodType< EventMessage$Outbound, z.ZodTypeDef, EventMessage > = z.object({ accountGroupId: z.string().optional(), accountId: z.string().optional(), clientId: z.string().optional(), correspondentId: z.string().optional(), data: z.nullable(z.record(z.any())).optional(), eventType: z.string().optional(), messageId: z.string().optional(), name: z.string().optional(), partitionKey: z.string().optional(), publishTime: z.nullable(z.date().transform(v => v.toISOString())).optional(), }).transform((v) => { return remap$(v, { accountGroupId: "account_group_id", accountId: "account_id", clientId: "client_id", correspondentId: "correspondent_id", eventType: "event_type", messageId: "message_id", partitionKey: "partition_key", publishTime: "publish_time", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace EventMessage$ { /** @deprecated use `EventMessage$inboundSchema` instead. */ export const inboundSchema = EventMessage$inboundSchema; /** @deprecated use `EventMessage$outboundSchema` instead. */ export const outboundSchema = EventMessage$outboundSchema; /** @deprecated use `EventMessage$Outbound` instead. */ export type Outbound = EventMessage$Outbound; } export function eventMessageToJSON(eventMessage: EventMessage): string { return JSON.stringify(EventMessage$outboundSchema.parse(eventMessage)); } export function eventMessageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => EventMessage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'EventMessage' from JSON`, ); }