/* * 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 { catchUnrecognizedEnum, OpenEnum, Unrecognized, } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The outcome of the delivery */ export enum Result { PushSubscriptionDeliveryResultUnspecified = "PUSH_SUBSCRIPTION_DELIVERY_RESULT_UNSPECIFIED", Succeeded = "SUCCEEDED", Failed = "FAILED", } /** * The outcome of the delivery */ export type ResultOpen = OpenEnum; /** * Represents the delivery results of an event for a push subscription */ export type PushSubscriptionDelivery = { /** * The unique identifier for the delivery */ deliveryId?: string | undefined; /** * The total time spent delivering */ duration?: string | undefined; /** * The resource name of the event; Format: messages/{message} */ event?: string | undefined; /** * The date and time of the event publication */ eventPublishTime?: Date | null | undefined; /** * The last response received when delivering the event */ lastResponse?: string | undefined; /** * The time the event was last pushed */ lastSendTime?: Date | null | undefined; /** * The resource name of the delivery; Format: subscriptions/{subscription}/deliveries/{delivery} */ name?: string | undefined; /** * The outcome of the delivery */ result?: ResultOpen | undefined; }; /** @internal */ export const Result$inboundSchema: z.ZodType< ResultOpen, z.ZodTypeDef, unknown > = z .union([ z.nativeEnum(Result), z.string().transform(catchUnrecognizedEnum), ]); /** @internal */ export const Result$outboundSchema: z.ZodType< ResultOpen, z.ZodTypeDef, ResultOpen > = z.union([ z.nativeEnum(Result), z.string().and(z.custom>()), ]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Result$ { /** @deprecated use `Result$inboundSchema` instead. */ export const inboundSchema = Result$inboundSchema; /** @deprecated use `Result$outboundSchema` instead. */ export const outboundSchema = Result$outboundSchema; } /** @internal */ export const PushSubscriptionDelivery$inboundSchema: z.ZodType< PushSubscriptionDelivery, z.ZodTypeDef, unknown > = z.object({ delivery_id: z.string().optional(), duration: z.string().optional(), event: z.string().optional(), event_publish_time: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), last_response: z.string().optional(), last_send_time: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), name: z.string().optional(), result: Result$inboundSchema.optional(), }).transform((v) => { return remap$(v, { "delivery_id": "deliveryId", "event_publish_time": "eventPublishTime", "last_response": "lastResponse", "last_send_time": "lastSendTime", }); }); /** @internal */ export type PushSubscriptionDelivery$Outbound = { delivery_id?: string | undefined; duration?: string | undefined; event?: string | undefined; event_publish_time?: string | null | undefined; last_response?: string | undefined; last_send_time?: string | null | undefined; name?: string | undefined; result?: string | undefined; }; /** @internal */ export const PushSubscriptionDelivery$outboundSchema: z.ZodType< PushSubscriptionDelivery$Outbound, z.ZodTypeDef, PushSubscriptionDelivery > = z.object({ deliveryId: z.string().optional(), duration: z.string().optional(), event: z.string().optional(), eventPublishTime: z.nullable(z.date().transform(v => v.toISOString())) .optional(), lastResponse: z.string().optional(), lastSendTime: z.nullable(z.date().transform(v => v.toISOString())).optional(), name: z.string().optional(), result: Result$outboundSchema.optional(), }).transform((v) => { return remap$(v, { deliveryId: "delivery_id", eventPublishTime: "event_publish_time", lastResponse: "last_response", lastSendTime: "last_send_time", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace PushSubscriptionDelivery$ { /** @deprecated use `PushSubscriptionDelivery$inboundSchema` instead. */ export const inboundSchema = PushSubscriptionDelivery$inboundSchema; /** @deprecated use `PushSubscriptionDelivery$outboundSchema` instead. */ export const outboundSchema = PushSubscriptionDelivery$outboundSchema; /** @deprecated use `PushSubscriptionDelivery$Outbound` instead. */ export type Outbound = PushSubscriptionDelivery$Outbound; } export function pushSubscriptionDeliveryToJSON( pushSubscriptionDelivery: PushSubscriptionDelivery, ): string { return JSON.stringify( PushSubscriptionDelivery$outboundSchema.parse(pushSubscriptionDelivery), ); } export function pushSubscriptionDeliveryFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => PushSubscriptionDelivery$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PushSubscriptionDelivery' from JSON`, ); }