Spaces:
Sleeping
Sleeping
File size: 955 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import { z } from "zod";
const BLACKLISTED_WEBHOOK_HEADERS = ["x-firecrawl-signature"];
export function createWebhookSchema<T extends [string, ...string[]]>(
events: T,
) {
const blacklistedLower = BLACKLISTED_WEBHOOK_HEADERS.map(h =>
h.toLowerCase(),
);
return z.preprocess(
x => (typeof x === "string" ? { url: x } : x),
z
.strictObject({
url: z.url(),
headers: z.record(z.string(), z.string()).prefault({}),
metadata: z.record(z.string(), z.string()).prefault({}),
events: z.array(z.enum(events)).prefault([...events]),
})
.refine(
obj =>
!Object.keys(obj.headers).some(key =>
blacklistedLower.includes(key.toLowerCase()),
),
`The following headers are not allowed: ${BLACKLISTED_WEBHOOK_HEADERS.join(", ")}`,
),
);
}
export const webhookSchema = createWebhookSchema([
"completed",
"failed",
"page",
"started",
]);
|