/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { WebhookEventType, WebhookEventType$inboundSchema, WebhookEventType$outboundSchema, } from "./webhookeventtype.js"; import { WebhookStatus, WebhookStatus$inboundSchema, WebhookStatus$outboundSchema, } from "./webhookstatus.js"; /** * A configured webhook endpoint that receives event notifications. */ export type Webhook = { /** * Unique identifier for the webhook. */ webhookID: string; /** * The URL where webhook events will be sent. */ url: string; /** * The status of a webhook. */ status: WebhookStatus; /** * The list of event types this webhook is subscribed to. */ eventTypes: Array; /** * A description of the webhook for reference. */ description: string; /** * Timestamp of when the webhook was created. */ createdOn: Date; /** * Timestamp of when the webhook was last updated. */ updatedOn: Date; /** * Timestamp of when the webhook last received an event. */ lastUsedOn?: Date | undefined; }; /** @internal */ export const Webhook$inboundSchema: z.ZodType = z.object({ webhookID: z.string(), url: z.string(), status: WebhookStatus$inboundSchema, eventTypes: z.array(WebhookEventType$inboundSchema), description: z.string(), createdOn: z.string().datetime({ offset: true }).transform(v => new Date(v) ), updatedOn: z.string().datetime({ offset: true }).transform(v => new Date(v) ), lastUsedOn: z.string().datetime({ offset: true }).transform(v => new Date(v) ).optional(), }); /** @internal */ export type Webhook$Outbound = { webhookID: string; url: string; status: string; eventTypes: Array; description: string; createdOn: string; updatedOn: string; lastUsedOn?: string | undefined; }; /** @internal */ export const Webhook$outboundSchema: z.ZodType< Webhook$Outbound, z.ZodTypeDef, Webhook > = z.object({ webhookID: z.string(), url: z.string(), status: WebhookStatus$outboundSchema, eventTypes: z.array(WebhookEventType$outboundSchema), description: z.string(), createdOn: z.date().transform(v => v.toISOString()), updatedOn: z.date().transform(v => v.toISOString()), lastUsedOn: z.date().transform(v => v.toISOString()).optional(), }); export function webhookToJSON(webhook: Webhook): string { return JSON.stringify(Webhook$outboundSchema.parse(webhook)); } export function webhookFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Webhook$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Webhook' from JSON`, ); }