mirror of
https://github.com/documenso/documenso.git
synced 2026-07-11 05:25:08 +10:00
138d663c25
Merge origin/main into feat/external-2fa-codes. Resolve formatting conflicts caused by biome rollout; preserve both feature streams: PR's external 2FA token + signing-session 2FA proof additions plus main's RateLimit/RecipientExpired/signingReminders/date-auto-insert. In complete-document-with-token.ts, drop the duplicate early field-fetching block introduced when main moved that logic later with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH check using derivedRecipientActionAuth.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type { WebhookTriggerEvents } from '@prisma/client';
|
|
|
|
import { getWebhookById } from './get-webhook-by-id';
|
|
import { generateSampleWebhookPayload } from './trigger/generate-sample-data';
|
|
import { triggerWebhook } from './trigger/trigger-webhook';
|
|
|
|
export type TriggerTestWebhookOptions = {
|
|
id: string;
|
|
event: WebhookTriggerEvents;
|
|
userId: number;
|
|
teamId: number;
|
|
};
|
|
|
|
export const triggerTestWebhook = async ({ id, event, userId, teamId }: TriggerTestWebhookOptions) => {
|
|
const webhook = await getWebhookById({ id, userId, teamId });
|
|
|
|
if (!webhook.enabled) {
|
|
throw new Error('Webhook is disabled');
|
|
}
|
|
|
|
if (!webhook.eventTriggers.includes(event)) {
|
|
throw new Error(`Webhook does not support event: ${event}`);
|
|
}
|
|
|
|
const samplePayload = generateSampleWebhookPayload(event, webhook.webhookUrl);
|
|
|
|
try {
|
|
await triggerWebhook({
|
|
event,
|
|
data: samplePayload.payload,
|
|
userId,
|
|
teamId,
|
|
});
|
|
|
|
return { success: true, message: 'Test webhook triggered successfully' };
|
|
} catch (error) {
|
|
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
|
|
}
|
|
};
|