/* * 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 { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Status, Status$inboundSchema, Status$outboundSchema, } from "./status.js"; import { UnifiedApiId, UnifiedApiId$inboundSchema, UnifiedApiId$outboundSchema, } from "./unifiedapiid.js"; import { WebhookEventType, WebhookEventType$inboundSchema, WebhookEventType$outboundSchema, } from "./webhookeventtype.js"; /** * Indicates if the webhook has has been disabled as it reached its retry limit or if account is over the usage allocated by it's plan. */ export const DisabledReason = { None: "none", RetryLimit: "retry_limit", UsageLimit: "usage_limit", } as const; /** * Indicates if the webhook has has been disabled as it reached its retry limit or if account is over the usage allocated by it's plan. */ export type DisabledReason = ClosedEnum; export type Webhook = { id?: string | undefined; /** * A description of the object. */ description?: string | null | undefined; /** * Name of Apideck Unified API */ unifiedApi: UnifiedApiId; /** * The status of the webhook. */ status: Status; /** * Indicates if the webhook has has been disabled as it reached its retry limit or if account is over the usage allocated by it's plan. */ disabledReason?: DisabledReason | undefined; /** * The delivery url of the webhook endpoint. */ deliveryUrl: string; /** * The Unify Base URL events from connectors will be sent to after service id is appended. */ executeBaseUrl: string; /** * The list of subscribed events for this webhook. [`*`] indicates that all events are enabled. */ events: Array; /** * The date and time when the object was last updated. */ updatedAt?: Date | null | undefined; /** * The date and time when the object was created. */ createdAt?: Date | null | undefined; }; /** @internal */ export const DisabledReason$inboundSchema: z.ZodNativeEnum< typeof DisabledReason > = z.nativeEnum(DisabledReason); /** @internal */ export const DisabledReason$outboundSchema: z.ZodNativeEnum< typeof DisabledReason > = DisabledReason$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace DisabledReason$ { /** @deprecated use `DisabledReason$inboundSchema` instead. */ export const inboundSchema = DisabledReason$inboundSchema; /** @deprecated use `DisabledReason$outboundSchema` instead. */ export const outboundSchema = DisabledReason$outboundSchema; } /** @internal */ export const Webhook$inboundSchema: z.ZodType = z.object({ id: z.string().optional(), description: z.nullable(z.string()).optional(), unified_api: UnifiedApiId$inboundSchema, status: Status$inboundSchema, disabled_reason: DisabledReason$inboundSchema.optional(), delivery_url: z.string(), execute_base_url: z.string(), events: z.array(WebhookEventType$inboundSchema), updated_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), created_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), }).transform((v) => { return remap$(v, { "unified_api": "unifiedApi", "disabled_reason": "disabledReason", "delivery_url": "deliveryUrl", "execute_base_url": "executeBaseUrl", "updated_at": "updatedAt", "created_at": "createdAt", }); }); /** @internal */ export type Webhook$Outbound = { id?: string | undefined; description?: string | null | undefined; unified_api: string; status: string; disabled_reason?: string | undefined; delivery_url: string; execute_base_url: string; events: Array; updated_at?: string | null | undefined; created_at?: string | null | undefined; }; /** @internal */ export const Webhook$outboundSchema: z.ZodType< Webhook$Outbound, z.ZodTypeDef, Webhook > = z.object({ id: z.string().optional(), description: z.nullable(z.string()).optional(), unifiedApi: UnifiedApiId$outboundSchema, status: Status$outboundSchema, disabledReason: DisabledReason$outboundSchema.optional(), deliveryUrl: z.string(), executeBaseUrl: z.string(), events: z.array(WebhookEventType$outboundSchema), updatedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(), createdAt: z.nullable(z.date().transform(v => v.toISOString())).optional(), }).transform((v) => { return remap$(v, { unifiedApi: "unified_api", disabledReason: "disabled_reason", deliveryUrl: "delivery_url", executeBaseUrl: "execute_base_url", updatedAt: "updated_at", createdAt: "created_at", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Webhook$ { /** @deprecated use `Webhook$inboundSchema` instead. */ export const inboundSchema = Webhook$inboundSchema; /** @deprecated use `Webhook$outboundSchema` instead. */ export const outboundSchema = Webhook$outboundSchema; /** @deprecated use `Webhook$Outbound` instead. */ export type Outbound = Webhook$Outbound; } 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`, ); }