mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
* feat(webhook): replace single secret header pair with webhookHeaders array schema * feat(webhook): iterate webhookHeaders array; keep backward compat for legacy secret fields * feat(webhook): replace single header pair with dynamic useFieldArray header list Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(webhook): add field labels to header key/value inputs * fix(webhook): guard reserved headers; align delete button with inputs * feat(nextcloud): add nextcloud to provider_kind enum * feat(nextcloud): add ProviderKind entry and HMAC-signed provider * feat(nextcloud): add Zod schema and form component * feat(nextcloud): wire nextcloud into form registry and UI provider list Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(nextcloud): register sendNextcloud in provider dispatch map * fix: multiple webhook headers and nextcloud talk notification provider * test(webhook): update e2e to use Add Header button and Header Value label * fix: webhook.ts --------- Co-authored-by: charles-gauthereau <charles.gauthereau@soluce-technologies.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import type { EventPayload, DispatchResult } from '../types';
|
|
|
|
type WebhookConfig = {
|
|
webhookUrl: string;
|
|
webhookHeaders?: { key: string; value: string }[];
|
|
webhookSecret?: string;
|
|
webhookSecretHeader?: string;
|
|
};
|
|
|
|
export async function sendWebhook(
|
|
config: WebhookConfig,
|
|
payload: EventPayload
|
|
): Promise<DispatchResult> {
|
|
const { webhookUrl, webhookHeaders, webhookSecret, webhookSecretHeader } = config;
|
|
|
|
const headers: Record<string, string> = {
|
|
'Content-Type': 'application/json',
|
|
'User-Agent': 'Portabase-Notifier/1.0',
|
|
};
|
|
|
|
// New format: iterate custom headers array
|
|
if (webhookHeaders && webhookHeaders.length > 0) {
|
|
const RESERVED = new Set(['content-type', 'user-agent']);
|
|
for (const { key, value } of webhookHeaders) {
|
|
if (key && !RESERVED.has(key.toLowerCase())) headers[key] = value;
|
|
}
|
|
} else if (webhookSecret) {
|
|
// Legacy format: single secret header pair
|
|
headers[webhookSecretHeader || 'X-Webhook-Secret'] = webhookSecret;
|
|
}
|
|
|
|
const res = await fetch(webhookUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload),
|
|
headers,
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const err = await res.text();
|
|
throw new Error(`Webhook error: ${res.status} ${err}`);
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
provider: 'webhook',
|
|
message: 'Sent to Webhook',
|
|
response: await res.text(),
|
|
};
|
|
}
|