fix(events): route webhooks by source UUID (#2127)

This commit is contained in:
sam committed 2026-11-24 08:07:09 +11:00
1 parent 58f1f9ce57
commit ba077f3779
16 files changed
+90 -176

No files matched your search

+2 -5
View File
@@ -21,7 +21,7 @@ import { Skeleton } from "@/components/ui/skeleton";
import { errors } from "@/copy/errors";
import { api, describeError, type EventSource_, type SourceIssued, type SourceVerification } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { signingKind, signingLabel, sourceURL } from "@/sources/source-signing";
import { signingKind, signingLabel } from "@/sources/source-signing";
import { useLiveResource } from "@/stores/session";
const { data, error, reload } = useRead(() => api.eventSources());
@@ -68,7 +68,7 @@ async function put(connector: string, verification?: SourceVerification, existin
}
function showWebhook(source: EventSource_, secret?: string): void {
webhook.value = { url: sourceURL(window.location.origin, source.webhook_path), secret };
webhook.value = { url: new URL(source.url, window.location.origin).toString(), secret };
}
function saveSigning(write: () => Promise<EventSource_>): Promise<boolean> {
@@ -117,7 +117,6 @@ function openEdit(source: EventSource_): void {
const sourceFields = {
label: { label: "Source name", required: true, write: api.sourceLabel },
webhook_path: { label: "Webhook path", required: true, write: api.sourceWebhookPath },
delivery_header: { label: "Delivery ID header", required: false, write: api.sourceDeliveryHeader },
key_fields: {
label: "Group by", required: false,
@@ -177,7 +176,6 @@ const connectorPlaceholder = computed(() => {
<DropdownMenuItem :disabled="!!(webhook?.token || webhook?.secret)" @select="showWebhook(row)">Webhook URL</DropdownMenuItem>
<DropdownMenuItem @select="openEdit(row)">Edit connector and verification…</DropdownMenuItem>
<DropdownMenuItem @select="openField(row, 'label')">Rename…</DropdownMenuItem>
<DropdownMenuItem @select="openField(row, 'webhook_path')">Change webhook path…</DropdownMenuItem>
<DropdownMenuItem @select="openField(row, 'delivery_header')">Set delivery ID header…</DropdownMenuItem>
<DropdownMenuItem @select="openField(row, 'key_fields')">Group by…</DropdownMenuItem>
<DropdownMenuItem :disabled="busy" @select="toggleCapture(row)">{{ row.capture ? "Stop keeping payloads" : "Keep payloads" }}</DropdownMenuItem>
@@ -263,7 +261,6 @@ const connectorPlaceholder = computed(() => {
<Input id="source-field" v-model="fieldEdit.value" :required="sourceFields[fieldEdit.key].required" />
</Field>
<p v-if="fieldEdit.key === 'key_fields'" class="text-caption text-fg-muted">Comma-separated field paths. Leave empty for the connector's default. Applies to events that arrive after you save.</p>
<p v-if="fieldEdit.key === 'webhook_path'" class="text-caption text-fg-muted">Senders must post to the new URL.</p>
<p v-if="actionError" role="alert" class="text-caption text-danger">{{ actionError }}</p>
</form>
<DialogFooter class="flex-row justify-end">
+3 -5
View File
@@ -218,7 +218,7 @@ export const api = {
request<EventRecord[]>("/api/events" + qs(params)),
event: (id: string) => request<EventDetail>(`/api/events/${encodeURIComponent(id)}`),
eventSources: () => request<EventSource_[]>("/api/sources"),
createEventSource: (input: { label: string; webhook_path?: string; scope?: SourceScope; connector: string } & Partial<SourceVerification>) =>
createEventSource: (input: { label: string; scope?: SourceScope; connector: string } & Partial<SourceVerification>) =>
request<SourceIssued>("/api/sources", { method: "POST", body: input }),
updateEventSource: (id: string, connector: string, verification?: SourceVerification) =>
request<SourceIssued>(`/api/sources/${encodeURIComponent(id)}`, { method: "PUT", body: { connector, ...verification } }),
@@ -674,8 +674,6 @@ export const api = {
}),
sourceLabel: (id: string, label: string) =>
request<EventSource_>(`/api/sources/${encodeURIComponent(id)}/label`, { method: "PUT", body: { label } }),
sourceWebhookPath: (id: string, path: string) =>
request<EventSource_>(`/api/sources/${encodeURIComponent(id)}/webhook-path`, { method: "PUT", body: { path } }),
sourceDeliveryHeader: (id: string, header: string) =>
request<EventSource_>(`/api/sources/${encodeURIComponent(id)}/delivery-header`, { method: "PUT", body: { header } }),
sourceDelete: (id: string) =>
@@ -1106,8 +1104,8 @@ export interface EventSource_ {
scope: SourceScope;
/** The name people see, unique within the scope. */
label: string;
/** The last segment of the URL deliveries post to. */
webhook_path: string;
/** The webhook URL identified by the source UUID. */
url: string;
connector: string;
key_fields?: string[];
token_set: boolean;
-5
View File
@@ -22,8 +22,3 @@ export function signingLabel(signing?: string): string {
export function signingKind(signing?: string): SigningKind {
return KINDS[signing ?? ""] ?? "idle";
}
/** The URL a sender posts to. */
export function sourceURL(origin: string, path: string): string {
return `${origin}/hooks/${encodeURIComponent(path)}`;
}