/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { safeParse } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { ClosedEnum, OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { SDKValidationError } from "../errors/sdk-validation-error.js"; export const CreateWebhookEventTypeRequest = { QueueItemNew: "QUEUE_ITEM_NEW", QueueItemCompleted: "QUEUE_ITEM_COMPLETED", QueueItemAction: "QUEUE_ITEM_ACTION", QueueItemRejected: "QUEUE_ITEM_REJECTED", QueueItemAllowed: "QUEUE_ITEM_ALLOWED", AuthorBlocked: "AUTHOR_BLOCKED", AuthorUnblocked: "AUTHOR_UNBLOCKED", AuthorSuspended: "AUTHOR_SUSPENDED", AuthorUpdated: "AUTHOR_UPDATED", AuthorTrustLevelChanged: "AUTHOR_TRUST_LEVEL_CHANGED", AuthorAction: "AUTHOR_ACTION", } as const; export type CreateWebhookEventTypeRequest = ClosedEnum< typeof CreateWebhookEventTypeRequest >; export type CreateWebhookRequestBody = { /** * The webhook's name, used to identify it in the dashboard */ name: string; /** * The webhook's description */ description?: string | null | undefined; /** * The webhook's URL. We'll call this URL when an event occurs. */ url: string; /** * Event types this webhook subscribes to. One webhook URL receives all events you list here. */ eventTypes: Array; }; export type CreateWebhookRequest = { /** * The project to act on, when you call with an organization key. Optional when the organization has one project. A project key acts on its own project: naming another one is an error. */ projectId?: string | undefined; body: CreateWebhookRequestBody; }; export const CreateWebhookEventTypeResponse = { QueueItemNew: "QUEUE_ITEM_NEW", QueueItemCompleted: "QUEUE_ITEM_COMPLETED", QueueItemAction: "QUEUE_ITEM_ACTION", QueueItemRejected: "QUEUE_ITEM_REJECTED", QueueItemAllowed: "QUEUE_ITEM_ALLOWED", AuthorBlocked: "AUTHOR_BLOCKED", AuthorUnblocked: "AUTHOR_UNBLOCKED", AuthorSuspended: "AUTHOR_SUSPENDED", AuthorUpdated: "AUTHOR_UPDATED", AuthorTrustLevelChanged: "AUTHOR_TRUST_LEVEL_CHANGED", AuthorAction: "AUTHOR_ACTION", } as const; export type CreateWebhookEventTypeResponse = OpenEnum< typeof CreateWebhookEventTypeResponse >; /** * Payload envelope version. V2 is the Stripe-style envelope; V1 is the legacy flat shape and is read-only via this API. */ export const CreateWebhookPayloadVersion = { V1: "V1", V2: "V2", } as const; /** * Payload envelope version. V2 is the Stripe-style envelope; V1 is the legacy flat shape and is read-only via this API. */ export type CreateWebhookPayloadVersion = OpenEnum< typeof CreateWebhookPayloadVersion >; /** * Webhook created successfully */ export type CreateWebhookResponse = { /** * The ID of the webhook. */ id: string; /** * The webhook's name. */ name: string; /** * The webhook's description. */ description?: string | null | undefined; /** * The URL we call when a subscribed event occurs. */ url: string; /** * Event types this webhook subscribes to. Empty for legacy v1 webhooks, which subscribe via their single deprecated `type` instead. */ eventTypes: Array; /** * Payload envelope version. V2 is the Stripe-style envelope; V1 is the legacy flat shape and is read-only via this API. */ payloadVersion: CreateWebhookPayloadVersion; /** * The date the webhook was created. */ createdAt: string; }; /** @internal */ export const CreateWebhookEventTypeRequest$outboundSchema: z.ZodMiniEnum< typeof CreateWebhookEventTypeRequest > = z.enum(CreateWebhookEventTypeRequest); /** @internal */ export type CreateWebhookRequestBody$Outbound = { name: string; description?: string | null | undefined; url: string; eventTypes: Array; }; /** @internal */ export const CreateWebhookRequestBody$outboundSchema: z.ZodMiniType< CreateWebhookRequestBody$Outbound, CreateWebhookRequestBody > = z.object({ name: z.string(), description: z.optional(z.nullable(z.string())), url: z.string(), eventTypes: z.array(CreateWebhookEventTypeRequest$outboundSchema), }); export function createWebhookRequestBodyToJSON( createWebhookRequestBody: CreateWebhookRequestBody, ): string { return JSON.stringify( CreateWebhookRequestBody$outboundSchema.parse(createWebhookRequestBody), ); } /** @internal */ export type CreateWebhookRequest$Outbound = { projectId?: string | undefined; body: CreateWebhookRequestBody$Outbound; }; /** @internal */ export const CreateWebhookRequest$outboundSchema: z.ZodMiniType< CreateWebhookRequest$Outbound, CreateWebhookRequest > = z.object({ projectId: z.optional(z.string()), body: z.lazy(() => CreateWebhookRequestBody$outboundSchema), }); export function createWebhookRequestToJSON( createWebhookRequest: CreateWebhookRequest, ): string { return JSON.stringify( CreateWebhookRequest$outboundSchema.parse(createWebhookRequest), ); } /** @internal */ export const CreateWebhookEventTypeResponse$inboundSchema: z.ZodMiniType< CreateWebhookEventTypeResponse, unknown > = openEnums.inboundSchema(CreateWebhookEventTypeResponse); /** @internal */ export const CreateWebhookPayloadVersion$inboundSchema: z.ZodMiniType< CreateWebhookPayloadVersion, unknown > = openEnums.inboundSchema(CreateWebhookPayloadVersion); /** @internal */ export const CreateWebhookResponse$inboundSchema: z.ZodMiniType< CreateWebhookResponse, unknown > = z.object({ id: types.string(), name: types.string(), description: z.optional(z.nullable(types.string())), url: types.string(), eventTypes: z.array(CreateWebhookEventTypeResponse$inboundSchema), payloadVersion: CreateWebhookPayloadVersion$inboundSchema, createdAt: types.string(), }); export function createWebhookResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateWebhookResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateWebhookResponse' from JSON`, ); }