Files
outline/plugins/webhooks/server/api/schema.ts
T
Tom Moor 1cc10f5fff fix: Increase valid user-supplied URL length to 1024 (#12585)
* fix: Increase valid user-supplied URL length to 1024

* fix: Wrap URL length migration in a transaction

Wrap the multi-column changeColumn operations in a transaction so a
failure on any column rolls back the whole migration rather than leaving
the database partially migrated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 23:30:55 -04:00

80 lines
2.0 KiB
TypeScript

import { z } from "zod";
import { WebhookSubscriptionValidation } from "@shared/validations";
import env from "@server/env";
import { WebhookSubscription } from "@server/models";
import { BaseSchema } from "@server/routes/api/schema";
const webhookUrl = z
.url()
.max(WebhookSubscriptionValidation.maxUrlLength, {
error: `Webhook url must be ${WebhookSubscriptionValidation.maxUrlLength} characters or less`,
})
.refine((val) => !env.isCloudHosted || val.startsWith("https://"), {
error: "Webhook url must use https",
});
export const WebhookSubscriptionsListSchema = BaseSchema.extend({
body: z.object({
/** Webhook subscriptions sorting direction */
direction: z
.string()
.optional()
.transform((val) => (val !== "ASC" ? "DESC" : val)),
/** Webhook subscriptions sorting column */
sort: z
.string()
.refine(
(val) => Object.keys(WebhookSubscription.getAttributes()).includes(val),
{
error: "Invalid sort parameter",
}
)
.prefault("createdAt"),
/** Search query to filter webhook subscriptions by name */
query: z.string().optional(),
}),
});
export type WebhookSubscriptionsListReq = z.infer<
typeof WebhookSubscriptionsListSchema
>;
export const WebhookSubscriptionsCreateSchema = z.object({
body: z.object({
name: z.string(),
url: webhookUrl,
secret: z.string().optional(),
events: z.array(z.string()),
}),
});
export type WebhookSubscriptionsCreateReq = z.infer<
typeof WebhookSubscriptionsCreateSchema
>;
export const WebhookSubscriptionsUpdateSchema = z.object({
body: z.object({
id: z.uuid(),
name: z.string(),
url: webhookUrl,
secret: z.string().optional(),
events: z.array(z.string()),
}),
});
export type WebhookSubscriptionsUpdateReq = z.infer<
typeof WebhookSubscriptionsUpdateSchema
>;
export const WebhookSubscriptionsDeleteSchema = z.object({
body: z.object({
id: z.uuid(),
}),
});
export type WebhookSubscriptionsDeleteReq = z.infer<
typeof WebhookSubscriptionsDeleteSchema
>;