65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import z from "zod";
|
|
|
|
/**
|
|
* Zod schema for the HMAC signature algorithm pin. Matches the values
|
|
* accepted by `@suaveplan/webhook-client`'s `WebhookSignatureAlgorithm`.
|
|
*/
|
|
export const WebhookSignatureAlgorithmSchema = z.enum(["sha256", "sha512"]);
|
|
|
|
/**
|
|
* Zod schema for the persistent `WebhookEndpoint` shape. Used by the
|
|
* `EndpointStore` conformance harness and by the read-side `GET` routes.
|
|
*/
|
|
export const WebhookEndpointSchema = z.object({
|
|
id: z.string().min(1),
|
|
tenantId: z.string().min(1).nullable(),
|
|
url: z.string().url(),
|
|
secret: z.string().min(8),
|
|
events: z.array(z.string().min(1)).min(1).readonly(),
|
|
description: z.string().optional(),
|
|
headers: z.record(z.string(), z.string()).optional(),
|
|
algorithm: WebhookSignatureAlgorithmSchema,
|
|
active: z.boolean(),
|
|
createdAt: z.string(),
|
|
updatedAt: z.string(),
|
|
});
|
|
|
|
/**
|
|
* Zod schema for `POST /webhooks` request bodies. Derives `id`,
|
|
* `createdAt`, `updatedAt`, `algorithm` (default `"sha256"`), and
|
|
* `active` (default `true`).
|
|
*/
|
|
export const CreateEndpointInputSchema = z.object({
|
|
tenantId: z.string().min(1).nullable(),
|
|
url: z.string().url(),
|
|
secret: z.string().min(8),
|
|
events: z.array(z.string().min(1)).min(1),
|
|
description: z.string().optional(),
|
|
headers: z.record(z.string(), z.string()).optional(),
|
|
algorithm: WebhookSignatureAlgorithmSchema.optional(),
|
|
active: z.boolean().optional(),
|
|
});
|
|
|
|
/**
|
|
* Zod schema for `PATCH /webhooks/:id` request bodies. Every field is
|
|
* optional and `tenantId` is intentionally absent (cross-tenant moves
|
|
* require delete + recreate).
|
|
*/
|
|
export const UpdateEndpointInputSchema = z.object({
|
|
url: z.string().url().optional(),
|
|
secret: z.string().min(8).optional(),
|
|
events: z.array(z.string().min(1)).min(1).optional(),
|
|
description: z.string().optional(),
|
|
headers: z.record(z.string(), z.string()).optional(),
|
|
algorithm: WebhookSignatureAlgorithmSchema.optional(),
|
|
active: z.boolean().optional(),
|
|
});
|
|
|
|
export type WebhookEndpointShape = z.infer<typeof WebhookEndpointSchema>;
|
|
export type CreateEndpointInputShape = z.infer<
|
|
typeof CreateEndpointInputSchema
|
|
>;
|
|
export type UpdateEndpointInputShape = z.infer<
|
|
typeof UpdateEndpointInputSchema
|
|
>;
|