/* * 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 { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Destination, Destination$inboundSchema, Destination$Outbound, Destination$outboundSchema, } from "./destination.js"; /** * The attempt status. */ export const Status = { Success: "success", Failed: "failed", } as const; /** * The attempt status. */ export type Status = ClosedEnum; /** * Full event object with data (returned when include=event.data). */ export type EventFull = { id?: string | undefined; /** * The tenant this event belongs to. */ tenantId?: string | undefined; /** * The destination this event was delivered to. */ destinationId?: string | undefined; topic?: string | undefined; /** * Time the event was received. */ time?: Date | undefined; /** * Whether this event can be retried. */ eligibleForRetry?: boolean | undefined; metadata?: { [k: string]: string } | null | undefined; /** * The event payload data. */ data?: { [k: string]: any } | undefined; }; /** * Event object without data (returned when include=event). */ export type EventSummary = { id?: string | undefined; /** * The tenant this event belongs to. */ tenantId?: string | undefined; /** * The destination this event was delivered to. */ destinationId?: string | undefined; topic?: string | undefined; /** * Time the event was received. */ time?: Date | undefined; /** * Whether this event can be retried. */ eligibleForRetry?: boolean | undefined; metadata?: { [k: string]: string } | null | undefined; }; /** * The associated event object. Only present when include=event or include=event.data. */ export type EventUnion = EventSummary | EventFull; /** * An attempt represents a single delivery attempt of an event to a destination. */ export type Attempt = { /** * Unique identifier for this attempt. */ id?: string | undefined; /** * The tenant this attempt belongs to. */ tenantId?: string | undefined; /** * The attempt status. */ status?: Status | undefined; /** * Time the attempt was made. */ time?: Date | undefined; /** * Response status code or error code. */ code?: string | undefined; /** * Response data from the attempt. Only included when include=response_data. */ responseData?: { [k: string]: any } | null | undefined; /** * The attempt number (1 for first attempt, 2+ for retries). */ attemptNumber?: number | undefined; /** * Whether this attempt was manually triggered (e.g., a retry initiated by a user). */ manual?: boolean | undefined; /** * The ID of the associated event. */ eventId?: string | undefined; /** * The destination ID this attempt was sent to. */ destinationId?: string | undefined; /** * The associated event object. Only present when include=event or include=event.data. */ event?: EventSummary | EventFull | null | undefined; destination?: Destination | undefined; }; /** @internal */ export const Status$inboundSchema: z.ZodNativeEnum = z .nativeEnum(Status); /** @internal */ export const Status$outboundSchema: z.ZodNativeEnum = Status$inboundSchema; /** @internal */ export const EventFull$inboundSchema: z.ZodType< EventFull, z.ZodTypeDef, unknown > = z.object({ id: z.string().optional(), tenant_id: z.string().optional(), destination_id: z.string().optional(), topic: z.string().optional(), time: z.string().datetime({ offset: true }).transform(v => new Date(v)) .optional(), eligible_for_retry: z.boolean().optional(), metadata: z.nullable(z.record(z.string())).optional(), data: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { "tenant_id": "tenantId", "destination_id": "destinationId", "eligible_for_retry": "eligibleForRetry", }); }); /** @internal */ export type EventFull$Outbound = { id?: string | undefined; tenant_id?: string | undefined; destination_id?: string | undefined; topic?: string | undefined; time?: string | undefined; eligible_for_retry?: boolean | undefined; metadata?: { [k: string]: string } | null | undefined; data?: { [k: string]: any } | undefined; }; /** @internal */ export const EventFull$outboundSchema: z.ZodType< EventFull$Outbound, z.ZodTypeDef, EventFull > = z.object({ id: z.string().optional(), tenantId: z.string().optional(), destinationId: z.string().optional(), topic: z.string().optional(), time: z.date().transform(v => v.toISOString()).optional(), eligibleForRetry: z.boolean().optional(), metadata: z.nullable(z.record(z.string())).optional(), data: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { tenantId: "tenant_id", destinationId: "destination_id", eligibleForRetry: "eligible_for_retry", }); }); export function eventFullToJSON(eventFull: EventFull): string { return JSON.stringify(EventFull$outboundSchema.parse(eventFull)); } export function eventFullFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => EventFull$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'EventFull' from JSON`, ); } /** @internal */ export const EventSummary$inboundSchema: z.ZodType< EventSummary, z.ZodTypeDef, unknown > = z.object({ id: z.string().optional(), tenant_id: z.string().optional(), destination_id: z.string().optional(), topic: z.string().optional(), time: z.string().datetime({ offset: true }).transform(v => new Date(v)) .optional(), eligible_for_retry: z.boolean().optional(), metadata: z.nullable(z.record(z.string())).optional(), }).transform((v) => { return remap$(v, { "tenant_id": "tenantId", "destination_id": "destinationId", "eligible_for_retry": "eligibleForRetry", }); }); /** @internal */ export type EventSummary$Outbound = { id?: string | undefined; tenant_id?: string | undefined; destination_id?: string | undefined; topic?: string | undefined; time?: string | undefined; eligible_for_retry?: boolean | undefined; metadata?: { [k: string]: string } | null | undefined; }; /** @internal */ export const EventSummary$outboundSchema: z.ZodType< EventSummary$Outbound, z.ZodTypeDef, EventSummary > = z.object({ id: z.string().optional(), tenantId: z.string().optional(), destinationId: z.string().optional(), topic: z.string().optional(), time: z.date().transform(v => v.toISOString()).optional(), eligibleForRetry: z.boolean().optional(), metadata: z.nullable(z.record(z.string())).optional(), }).transform((v) => { return remap$(v, { tenantId: "tenant_id", destinationId: "destination_id", eligibleForRetry: "eligible_for_retry", }); }); export function eventSummaryToJSON(eventSummary: EventSummary): string { return JSON.stringify(EventSummary$outboundSchema.parse(eventSummary)); } export function eventSummaryFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => EventSummary$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'EventSummary' from JSON`, ); } /** @internal */ export const EventUnion$inboundSchema: z.ZodType< EventUnion, z.ZodTypeDef, unknown > = z.union([ z.lazy(() => EventSummary$inboundSchema), z.lazy(() => EventFull$inboundSchema), ]); /** @internal */ export type EventUnion$Outbound = EventSummary$Outbound | EventFull$Outbound; /** @internal */ export const EventUnion$outboundSchema: z.ZodType< EventUnion$Outbound, z.ZodTypeDef, EventUnion > = z.union([ z.lazy(() => EventSummary$outboundSchema), z.lazy(() => EventFull$outboundSchema), ]); export function eventUnionToJSON(eventUnion: EventUnion): string { return JSON.stringify(EventUnion$outboundSchema.parse(eventUnion)); } export function eventUnionFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => EventUnion$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'EventUnion' from JSON`, ); } /** @internal */ export const Attempt$inboundSchema: z.ZodType = z.object({ id: z.string().optional(), tenant_id: z.string().optional(), status: Status$inboundSchema.optional(), time: z.string().datetime({ offset: true }).transform(v => new Date(v)) .optional(), code: z.string().optional(), response_data: z.nullable(z.record(z.any())).optional(), attempt_number: z.number().int().optional(), manual: z.boolean().optional(), event_id: z.string().optional(), destination_id: z.string().optional(), event: z.nullable( z.union([ z.lazy(() => EventSummary$inboundSchema), z.lazy(() => EventFull$inboundSchema), ]), ).optional(), destination: Destination$inboundSchema.optional(), }).transform((v) => { return remap$(v, { "tenant_id": "tenantId", "response_data": "responseData", "attempt_number": "attemptNumber", "event_id": "eventId", "destination_id": "destinationId", }); }); /** @internal */ export type Attempt$Outbound = { id?: string | undefined; tenant_id?: string | undefined; status?: string | undefined; time?: string | undefined; code?: string | undefined; response_data?: { [k: string]: any } | null | undefined; attempt_number?: number | undefined; manual?: boolean | undefined; event_id?: string | undefined; destination_id?: string | undefined; event?: EventSummary$Outbound | EventFull$Outbound | null | undefined; destination?: Destination$Outbound | undefined; }; /** @internal */ export const Attempt$outboundSchema: z.ZodType< Attempt$Outbound, z.ZodTypeDef, Attempt > = z.object({ id: z.string().optional(), tenantId: z.string().optional(), status: Status$outboundSchema.optional(), time: z.date().transform(v => v.toISOString()).optional(), code: z.string().optional(), responseData: z.nullable(z.record(z.any())).optional(), attemptNumber: z.number().int().optional(), manual: z.boolean().optional(), eventId: z.string().optional(), destinationId: z.string().optional(), event: z.nullable( z.union([ z.lazy(() => EventSummary$outboundSchema), z.lazy(() => EventFull$outboundSchema), ]), ).optional(), destination: Destination$outboundSchema.optional(), }).transform((v) => { return remap$(v, { tenantId: "tenant_id", responseData: "response_data", attemptNumber: "attempt_number", eventId: "event_id", destinationId: "destination_id", }); }); export function attemptToJSON(attempt: Attempt): string { return JSON.stringify(Attempt$outboundSchema.parse(attempt)); } export function attemptFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Attempt$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Attempt' from JSON`, ); }