Files
dataroom/lib/webhook/send-webhooks.ts
zeekay 89004ff9a7 rebrand: Papermark → Hanzo Dataroom across user-facing surfaces
108 files: README, marketing copy, page titles, meta tags, footer
text, email templates, .env.example, UI strings. URLs swapped
from papermark.com/papermark.io to dataroom.hanzo.ai.

Internal identifiers left intact per repo policy: localStorage
keys (papermark.email/papermark.name/last_papermark_login —
changing them logs users out), type field names
(papermarkUserId), internal helper symbols (PAPERMARK_HEADERS,
PapermarkSparkle component, isPapermarkUrl helper),
internal-only filenames. LLM.md retains 'Upstream: Papermark'
attribution line. Per-locale .po translations regenerate from
source on the next lingui-extract CI run.

DB migrations untouched (append-only history; rewriting them
breaks installed schemas). LICENSE stays AGPL-3.0.
2026-06-07 12:23:40 -07:00

66 lines
1.6 KiB
TypeScript

import { Webhook } from "@prisma/client";
import { qstash } from "@/lib/cron";
import { createWebhookSignature } from "./signature";
import { prepareWebhookPayload } from "./transform";
import { EventDataProps, WebhookPayload, WebhookTrigger } from "./types";
// Send webhooks to multiple webhooks
export const sendWebhooks = async ({
webhooks,
trigger,
data,
}: {
webhooks: Pick<Webhook, "pId" | "url" | "secret">[];
trigger: WebhookTrigger;
data: EventDataProps;
}) => {
if (webhooks.length === 0) {
return;
}
const payload = prepareWebhookPayload(trigger, data);
return await Promise.all(
webhooks.map((webhook) =>
publishWebhookEventToQStash({ webhook, payload }),
),
);
};
// Publish webhook event to QStash
const publishWebhookEventToQStash = async ({
webhook,
payload,
}: {
webhook: Pick<Webhook, "pId" | "url" | "secret">;
payload: WebhookPayload;
}) => {
const callbackUrl = new URL(
`${process.env.NEXT_PUBLIC_BASE_URL}/api/webhooks/callback`,
);
callbackUrl.searchParams.append("webhookId", webhook.pId);
callbackUrl.searchParams.append("eventId", payload.id);
callbackUrl.searchParams.append("event", payload.event);
const signature = await createWebhookSignature(webhook.secret, payload);
const response = await qstash.publishJSON({
url: webhook.url,
body: payload,
headers: {
"X-Hanzo Dataroom-Signature": signature,
"Upstash-Hide-Headers": "true",
},
callback: callbackUrl.href,
failureCallback: callbackUrl.href,
});
if (!response.messageId) {
console.error("Failed to publish webhook event to QStash", response);
}
return response;
};