Compare commits

..

2 Commits

Author SHA1 Message Date
8083e54625 fix: remove redundant step 2025-11-24 19:33:56 +11:00
7a55abadaf fix: optimize webhook routing 2025-11-24 13:53:57 +11:00
5 changed files with 62 additions and 72 deletions

View File

@ -1,3 +1,4 @@
// Todo: [Webhooks] delete file after deployment.
import { handlerTriggerWebhooks } from '@documenso/lib/server-only/webhooks/trigger/handler'; import { handlerTriggerWebhooks } from '@documenso/lib/server-only/webhooks/trigger/handler';
import type { Route } from './+types/webhook.trigger'; import type { Route } from './+types/webhook.trigger';

View File

@ -22,7 +22,6 @@ export const run = async ({
const { webhookUrl: url, secret } = webhook; const { webhookUrl: url, secret } = webhook;
await io.runTask('execute-webhook', async () => {
const payloadData = { const payloadData = {
event, event,
payload: data, payload: data,
@ -70,5 +69,4 @@ export const run = async ({
success: response.ok, success: response.ok,
status: response.status, status: response.status,
}; };
});
}; };

View File

@ -13,6 +13,7 @@ export type HandlerTriggerWebhooksResponse =
error: string; error: string;
}; };
// Todo: [Webhooks] delete after deployment.
export const handlerTriggerWebhooks = async (req: Request) => { export const handlerTriggerWebhooks = async (req: Request) => {
const signature = req.headers.get('x-webhook-signature'); const signature = req.headers.get('x-webhook-signature');

View File

@ -1,7 +1,6 @@
import type { WebhookTriggerEvents } from '@prisma/client'; import type { WebhookTriggerEvents } from '@prisma/client';
import { NEXT_PRIVATE_INTERNAL_WEBAPP_URL } from '../../../constants/app'; import { jobs } from '../../../jobs/client';
import { sign } from '../../crypto/sign';
import { getAllWebhooksByEventTrigger } from '../get-all-webhooks-by-event-trigger'; import { getAllWebhooksByEventTrigger } from '../get-all-webhooks-by-event-trigger';
export type TriggerWebhookOptions = { export type TriggerWebhookOptions = {
@ -13,35 +12,26 @@ export type TriggerWebhookOptions = {
export const triggerWebhook = async ({ event, data, userId, teamId }: TriggerWebhookOptions) => { export const triggerWebhook = async ({ event, data, userId, teamId }: TriggerWebhookOptions) => {
try { try {
const body = {
event,
data,
userId,
teamId,
};
const registeredWebhooks = await getAllWebhooksByEventTrigger({ event, userId, teamId }); const registeredWebhooks = await getAllWebhooksByEventTrigger({ event, userId, teamId });
if (registeredWebhooks.length === 0) { if (registeredWebhooks.length === 0) {
return; return;
} }
const signature = sign(body); await Promise.allSettled(
registeredWebhooks.map(async (webhook) => {
await Promise.race([ await jobs.triggerJob({
fetch(`${NEXT_PRIVATE_INTERNAL_WEBAPP_URL()}/api/webhook/trigger`, { name: 'internal.execute-webhook',
method: 'POST', payload: {
headers: { event,
'content-type': 'application/json', webhookId: webhook.id,
'x-webhook-signature': signature, data,
}, },
body: JSON.stringify(body), });
}), }),
new Promise((_, reject) => { );
setTimeout(() => reject(new Error('Request timeout')), 500);
}),
]).catch(() => null);
} catch (err) { } catch (err) {
console.error(err);
throw new Error(`Failed to trigger webhook`); throw new Error(`Failed to trigger webhook`);
} }
}; };

View File

@ -8,7 +8,7 @@ msgstr ""
"Language: pl\n" "Language: pl\n"
"Project-Id-Version: documenso-app\n" "Project-Id-Version: documenso-app\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-11-21 00:14\n" "PO-Revision-Date: 2025-11-20 02:32\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: Polish\n" "Language-Team: Polish\n"
"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && (n%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n" "Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && (n%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n"
@ -7584,7 +7584,7 @@ msgstr "Liczba podpisów"
#: packages/ui/components/document/envelope-recipient-field-tooltip.tsx #: packages/ui/components/document/envelope-recipient-field-tooltip.tsx
#: packages/ui/components/document/document-read-only-fields.tsx #: packages/ui/components/document/document-read-only-fields.tsx
msgid "Signed" msgid "Signed"
msgstr "Podpisano" msgstr "Podpisał"
#: apps/remix/app/components/dialogs/envelope-download-dialog.tsx #: apps/remix/app/components/dialogs/envelope-download-dialog.tsx
msgctxt "Signed document (adjective)" msgctxt "Signed document (adjective)"