The Capture, Map and Bind steps read the module's captures, event types, mappings and triggers. A binding is a trigger bound to an event type; the sources panel creates HMAC sources and shows each delivery's verification result. The workspace filter is removed: the binary has one workspace per organisation and the data carries none.
This commit is contained in:
20 files changed
+404
-418
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { errors } from "@/copy/errors";
|
||||
import DispatchLinks from "./DispatchLinks.vue";
|
||||
import TriggerRuns from "./TriggerRuns.vue";
|
||||
import { computed, ref, watch } from "vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
@@ -13,12 +13,7 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
Field,
|
||||
FieldDescription,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
} from "@/components/ui/field";
|
||||
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { eventTypeLabel, type EventType } from "@/captures/event-types";
|
||||
import {
|
||||
@@ -34,19 +29,15 @@ import {
|
||||
draftFromBinding,
|
||||
emptyDraft,
|
||||
mappingsForEventType,
|
||||
paramsForType,
|
||||
takesRepository,
|
||||
type Binding,
|
||||
type BindingDraft,
|
||||
type MappingOption,
|
||||
type WorkflowOption,
|
||||
} from "./binding-draft";
|
||||
} from "./binding-trigger";
|
||||
|
||||
/**
|
||||
* The binding editor: name, the event type it applies to, one of that type's
|
||||
* mappings, an optional filter over the mapping's parameters, the workflow, its
|
||||
* inputs, and the repository when the workflow takes one. Signing is the
|
||||
* source's.
|
||||
* The binding editor: name, the event type it applies to, an optional mapping
|
||||
* of that type, and the workflow it starts. Signing is the source's.
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -69,9 +60,7 @@ watch(
|
||||
open,
|
||||
(isOpen) => {
|
||||
if (isOpen)
|
||||
draft.value = props.binding
|
||||
? draftFromBinding(props.binding, props.mappings)
|
||||
: emptyDraft();
|
||||
draft.value = props.binding ? draftFromBinding(props.binding) : emptyDraft();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@@ -90,44 +79,12 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
const workflow = computed(() =>
|
||||
props.workflows.find((w) => w.id === draft.value.workflow),
|
||||
);
|
||||
const declaredInputs = computed(() =>
|
||||
Object.entries(workflow.value?.inputs ?? {}).sort(([a], [b]) =>
|
||||
a.localeCompare(b),
|
||||
),
|
||||
);
|
||||
const mappingFields = computed(
|
||||
() =>
|
||||
props.mappings.find((m) => m.id === draft.value.mappingId)?.fields ?? [],
|
||||
);
|
||||
const stringParams = computed(() =>
|
||||
paramsForType(mappingFields.value, "string"),
|
||||
);
|
||||
|
||||
// The constant sentinel stands for "no parameter": Select items cannot carry
|
||||
// an empty value.
|
||||
const CONSTANT = "__constant__";
|
||||
|
||||
function inputDraft(name: string) {
|
||||
draft.value.inputs[name] ??= { param: "", value: "" };
|
||||
return draft.value.inputs[name];
|
||||
}
|
||||
|
||||
function inputSource(name: string): string {
|
||||
return inputDraft(name).param || CONSTANT;
|
||||
}
|
||||
|
||||
function setInputSource(name: string, source: unknown): void {
|
||||
inputDraft(name).param = source === CONSTANT ? "" : String(source);
|
||||
}
|
||||
|
||||
const NO_PARAM = "__none__";
|
||||
const repoSource = computed({
|
||||
get: () => draft.value.repoParam || NO_PARAM,
|
||||
// Select items cannot carry an empty value.
|
||||
const NO_MAPPING = "__none__";
|
||||
const mappingChoice = computed({
|
||||
get: () => draft.value.mappingId || NO_MAPPING,
|
||||
set: (v: string) => {
|
||||
draft.value.repoParam = v === NO_PARAM ? "" : v;
|
||||
draft.value.mappingId = v === NO_MAPPING ? "" : v;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -136,8 +93,6 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<!-- Six fields make this taller than a short window; the dialog itself
|
||||
scrolls rather than clipping its own Save button. -->
|
||||
<DialogContent class="max-h-[85vh] overflow-y-auto sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ title }}</DialogTitle>
|
||||
@@ -148,7 +103,13 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel for="binding-name">Name</FieldLabel>
|
||||
<Input id="binding-name" v-model="draft.name" />
|
||||
<Input
|
||||
id="binding-name"
|
||||
v-model="draft.name"
|
||||
:disabled="!!props.binding"
|
||||
pattern="[a-z][a-z0-9\-]*"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
@@ -173,18 +134,13 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-mapping">Field mapping</FieldLabel>
|
||||
<Select v-model="draft.mappingId" :disabled="!typeMappings.length">
|
||||
<Select v-model="mappingChoice" :disabled="!draft.eventTypeId">
|
||||
<SelectTrigger id="binding-mapping" class="w-full">
|
||||
<SelectValue
|
||||
:placeholder="
|
||||
draft.eventTypeId && !typeMappings.length
|
||||
? 'No mappings for this event type'
|
||||
: 'Pick a mapping'
|
||||
"
|
||||
/>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="NO_MAPPING">None</SelectItem>
|
||||
<SelectItem
|
||||
v-for="mapping in typeMappings"
|
||||
:key="mapping.id"
|
||||
@@ -197,19 +153,6 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-filter">Filter</FieldLabel>
|
||||
<Input
|
||||
id="binding-filter"
|
||||
v-model="draft.filter"
|
||||
class="font-mono text-caption"
|
||||
placeholder='severity in ["high", "critical"]'
|
||||
/>
|
||||
<FieldDescription
|
||||
>Optional CEL over the mapping's parameters.</FieldDescription
|
||||
>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel for="binding-workflow">Workflow</FieldLabel>
|
||||
<Select v-model="draft.workflow">
|
||||
@@ -229,88 +172,11 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field v-for="[name, spec] in declaredInputs" :key="name">
|
||||
<FieldLabel :for="`binding-input-${name}`">Input <span class="font-mono">{{ name }}</span>
|
||||
<span class="text-fg-muted"
|
||||
>({{ spec.type }}{{ spec.required ? ", required" : "" }})</span
|
||||
>
|
||||
</FieldLabel>
|
||||
<div class="grid grid-cols-1 items-start gap-3 sm:grid-cols-2">
|
||||
<Select
|
||||
:model-value="inputSource(name)"
|
||||
@update:model-value="setInputSource(name, $event)"
|
||||
>
|
||||
<SelectTrigger :id="`binding-input-${name}`" class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="CONSTANT">Constant</SelectItem>
|
||||
<SelectItem
|
||||
v-for="field in paramsForType(mappingFields, spec.type)"
|
||||
:key="field.name"
|
||||
:value="field.name"
|
||||
>
|
||||
{{ field.name }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
v-if="!inputDraft(name).param"
|
||||
v-model="inputDraft(name).value"
|
||||
class="font-mono text-caption"
|
||||
:aria-label="`${name} value`"
|
||||
placeholder="value"
|
||||
/>
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
<Field v-if="takesRepository(workflow)">
|
||||
<FieldLabel for="binding-repo-param">Repository from</FieldLabel>
|
||||
<Select v-model="repoSource">
|
||||
<SelectTrigger id="binding-repo-param" class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="NO_PARAM"
|
||||
>A pinned or configured repo</SelectItem
|
||||
>
|
||||
<SelectItem
|
||||
v-for="field in stringParams"
|
||||
:key="field.name"
|
||||
:value="field.name"
|
||||
>Parameter {{ field.name }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FieldDescription
|
||||
>A parameter must hold owner/name and name a configured
|
||||
repo.</FieldDescription
|
||||
>
|
||||
</Field>
|
||||
|
||||
<Field v-if="takesRepository(workflow) && !draft.repoParam">
|
||||
<div class="grid grid-cols-1 items-start gap-3 sm:grid-cols-2">
|
||||
<Field>
|
||||
<FieldLabel for="binding-owner">Pinned owner</FieldLabel>
|
||||
<Input id="binding-owner" v-model="draft.owner" />
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel for="binding-repo">Pinned repo</FieldLabel>
|
||||
<Input id="binding-repo" v-model="draft.repo" />
|
||||
</Field>
|
||||
</div>
|
||||
<FieldDescription>Both or neither; blank uses the configured repo.</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
|
||||
<section v-if="props.binding" class="mt-4 flex flex-col gap-2">
|
||||
<h3 class="text-caption font-medium tracking-[0.06em] text-fg-subtle uppercase">Recent dispatches</h3>
|
||||
<DispatchLinks kind="bindings" :id="props.binding.id" />
|
||||
<h3 class="text-caption font-medium tracking-[0.06em] text-fg-subtle uppercase">Recent runs</h3>
|
||||
<TriggerRuns kind="triggers" :id="props.binding.id" />
|
||||
</section>
|
||||
|
||||
<!-- Beside the buttons, not at the top: the dialog scrolls, and Save is
|
||||
@@ -324,7 +190,10 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
|
||||
<Button type="button" variant="outline" @click="open = false"
|
||||
>Cancel</Button
|
||||
>
|
||||
<Button type="submit" :disabled="props.saving">
|
||||
<Button
|
||||
type="submit"
|
||||
:disabled="props.saving || !draft.eventTypeId || !draft.workflow"
|
||||
>
|
||||
<Spinner v-if="props.saving" data-icon="inline-start" />{{ props.saving ? "Saving" : "Save" }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
@@ -1,34 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { Check, Pause, Pencil, Play, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
import { TableCell, TableRow } from "@/components/ui/table";
|
||||
import BindingStatusBadge from "./BindingStatusBadge.vue";
|
||||
import { eventTypeLabel, type EventType } from "@/captures/event-types";
|
||||
import {
|
||||
bindingEventType,
|
||||
repoPin,
|
||||
type Binding,
|
||||
type MappingOption,
|
||||
} from "./binding-draft";
|
||||
import type { Binding } from "./binding-trigger";
|
||||
|
||||
/** One saved binding's summary row. */
|
||||
const props = defineProps<{
|
||||
binding: Binding;
|
||||
mappings: MappingOption[];
|
||||
eventTypes: EventType[];
|
||||
}>();
|
||||
// A filtered capture is the filter doing its job; any other reason means the
|
||||
// binding matched an event and could not start its workflow.
|
||||
const failing = computed(() => {
|
||||
const reason = props.binding.last_outcome?.reason;
|
||||
return !!reason && reason !== "filtered";
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
edit: [binding: Binding];
|
||||
approve: [binding: Binding];
|
||||
@@ -43,38 +29,11 @@ const emit = defineEmits<{
|
||||
<TableCell class="font-medium">{{ props.binding.name }}</TableCell>
|
||||
<TableCell class="font-mono text-fg-muted">
|
||||
<div class="flex items-center gap-2">
|
||||
{{
|
||||
eventTypeLabel(
|
||||
bindingEventType(props.binding, props.mappings),
|
||||
props.eventTypes,
|
||||
)
|
||||
}}
|
||||
{{ eventTypeLabel(props.binding.event_type_id, props.eventTypes) }}
|
||||
<Badge v-if="props.binding.unsigned" variant="warn">Unsigned</Badge>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell class="max-w-56 font-mono text-caption text-fg-muted">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<span tabindex="0" class="block truncate">{{ props.binding.filter || "–" }}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent v-if="props.binding.filter">{{ props.binding.filter }}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div class="flex items-center gap-2">
|
||||
{{ props.binding.workflow || "–" }}
|
||||
<Badge v-if="props.binding.workflow_disabled" variant="warn">Disabled</Badge>
|
||||
<Tooltip v-if="failing">
|
||||
<TooltipTrigger as-child>
|
||||
<span tabindex="0" class="inline-flex"><Badge variant="danger">Not dispatching</Badge></span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent v-if="props.binding.last_outcome?.reason">{{ props.binding.last_outcome?.reason }}</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell class="font-mono text-fg-muted">{{
|
||||
repoPin(props.binding)
|
||||
}}</TableCell>
|
||||
<TableCell>{{ props.binding.workflow || "–" }}</TableCell>
|
||||
<TableCell><BindingStatusBadge :status="props.binding.status" /></TableCell>
|
||||
<TableCell>
|
||||
<div class="flex items-center justify-end gap-1">
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useLiveResource } from "@/stores/session";
|
||||
import BindingEditor from "./BindingEditor.vue";
|
||||
import BindingsTable from "./BindingsTable.vue";
|
||||
import DeleteBindingDialog from "./DeleteBindingDialog.vue";
|
||||
import type { Binding, BindingDraft } from "./binding-draft";
|
||||
import type { Binding, BindingDraft } from "./binding-trigger";
|
||||
import { useBindings } from "./use-bindings";
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,6 @@ async function handleDelete(binding: Binding): Promise<void> {
|
||||
|
||||
<BindingsTable
|
||||
:bindings="bindings"
|
||||
:mappings="mappings"
|
||||
:event-types="eventTypes"
|
||||
:failure="failure"
|
||||
@edit="startEdit"
|
||||
|
||||
@@ -13,19 +13,19 @@ import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import BindingRow from "./BindingRow.vue";
|
||||
import type { EventType } from "@/captures/event-types";
|
||||
import type { Binding, MappingOption } from "./binding-draft";
|
||||
import type { Binding } from "./binding-trigger";
|
||||
import type { LoadFailure } from "./use-bindings";
|
||||
|
||||
const props = defineProps<{
|
||||
/** null means loading, [] means loaded and empty. */
|
||||
bindings: Binding[] | null;
|
||||
mappings: MappingOption[];
|
||||
eventTypes: EventType[];
|
||||
failure: LoadFailure | null;
|
||||
}>();
|
||||
@@ -72,9 +72,7 @@ const failureTitle = computed(() =>
|
||||
<TableRow>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead>Event type</TableHead>
|
||||
<TableHead>Filter</TableHead>
|
||||
<TableHead>Workflow</TableHead>
|
||||
<TableHead>Repo pin</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
@@ -82,7 +80,7 @@ const failureTitle = computed(() =>
|
||||
<TableBody>
|
||||
<template v-if="loading">
|
||||
<TableRow v-for="row in 3" :key="row">
|
||||
<TableCell v-for="col in 7" :key="col"
|
||||
<TableCell v-for="col in 5" :key="col"
|
||||
><Skeleton class="h-4 w-full"
|
||||
/></TableCell>
|
||||
</TableRow>
|
||||
@@ -92,7 +90,6 @@ const failureTitle = computed(() =>
|
||||
v-for="binding in rows"
|
||||
:key="binding.id"
|
||||
:binding="binding"
|
||||
:mappings="props.mappings"
|
||||
:event-types="props.eventTypes"
|
||||
@edit="emit('edit', $event)"
|
||||
@approve="emit('approve', $event)"
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import type { Binding } from "./binding-draft";
|
||||
import type { Binding } from "./binding-trigger";
|
||||
|
||||
/** Confirming a delete, and nothing else. A binding cannot be recovered, so
|
||||
* the action is behind a dialog rather than a click. */
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
import { api, type TriggerRun } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
|
||||
/**
|
||||
* The runs a trigger started or a stored delivery started, each linking the
|
||||
* other two ends: which delivery, which trigger, which run.
|
||||
*/
|
||||
const props = defineProps<{
|
||||
kind: "triggers" | "captures";
|
||||
id: string;
|
||||
}>();
|
||||
|
||||
const runs = ref<TriggerRun[]>([]);
|
||||
const failed = ref(false);
|
||||
let generation = 0;
|
||||
|
||||
watch(
|
||||
() => [props.kind, props.id],
|
||||
async () => {
|
||||
const current = ++generation;
|
||||
failed.value = false;
|
||||
try {
|
||||
const res =
|
||||
props.kind === "triggers"
|
||||
? await api.triggerDispatches(props.id)
|
||||
: await api.captureDispatches(props.id);
|
||||
if (current !== generation) return;
|
||||
runs.value = res;
|
||||
} catch {
|
||||
if (current !== generation) return;
|
||||
runs.value = [];
|
||||
failed.value = true;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<p v-if="failed" class="text-caption text-fg-muted">{{ errors.bindings.dispatchLinks.unavailable }}</p>
|
||||
<ul v-else-if="runs.length" class="flex flex-col gap-1 text-caption">
|
||||
<li
|
||||
v-for="r in runs"
|
||||
:key="r.event_id + (r.trigger ?? '')"
|
||||
class="flex flex-wrap items-center gap-x-2 font-mono text-fg-muted"
|
||||
>
|
||||
<RouterLink
|
||||
v-if="props.kind === 'triggers'"
|
||||
:to="{ path: '/events', query: { tab: 'inspector', capture: r.event_id } }"
|
||||
class="hover:text-foreground"
|
||||
>capture {{ r.event_id.slice(0, 8) }}</RouterLink
|
||||
>
|
||||
<RouterLink
|
||||
v-else
|
||||
:to="{ path: '/events', query: { tab: 'bindings' } }"
|
||||
class="hover:text-foreground"
|
||||
>{{ r.trigger }}</RouterLink
|
||||
>
|
||||
<RouterLink :to="`/runs/${r.run_id}`" class="text-foreground hover:underline"
|
||||
>run {{ r.run_id.slice(0, 8) }}</RouterLink
|
||||
>
|
||||
<Timestamp v-if="r.created_at" :at="r.created_at" />
|
||||
</li>
|
||||
</ul>
|
||||
<Empty v-else><EmptyHeader><EmptyTitle>No runs yet.</EmptyTitle></EmptyHeader></Empty>
|
||||
</template>
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* The bindings vocabulary on the binary: a binding is a trigger bound to an
|
||||
* event type, so the wire shape is the trigger's. The status ramp is
|
||||
* binding-draft.ts's.
|
||||
*/
|
||||
|
||||
import type { EventType } from "../captures/event-types";
|
||||
import type { Trigger, TriggerInput } from "../lib/api";
|
||||
|
||||
/** A trigger bound to an event type, named by the trigger's name. */
|
||||
export interface Binding {
|
||||
id: string;
|
||||
name: string;
|
||||
source: string;
|
||||
event_type_id?: string;
|
||||
mapping_id?: string;
|
||||
workflow?: string;
|
||||
status?: string;
|
||||
/** The source takes deliveries with no verification. */
|
||||
unsigned?: boolean;
|
||||
}
|
||||
|
||||
export function bindingOfTrigger(trigger: Trigger): Binding {
|
||||
return {
|
||||
id: trigger.name,
|
||||
name: trigger.name,
|
||||
source: trigger.source ?? "",
|
||||
event_type_id: trigger.event_type_id,
|
||||
mapping_id: trigger.mapping_id,
|
||||
workflow: trigger.workflow,
|
||||
status: trigger.status,
|
||||
unsigned: trigger.unsigned,
|
||||
};
|
||||
}
|
||||
|
||||
/** The fields of GET /api/mappings this page needs. */
|
||||
export interface MappingOption {
|
||||
id: string;
|
||||
name: string;
|
||||
event_type_id?: string;
|
||||
}
|
||||
|
||||
/** The mappings that belong to one event type, which are the ones a binding
|
||||
* on that type can use. */
|
||||
export function mappingsForEventType(
|
||||
mappings: MappingOption[],
|
||||
eventTypeId: string,
|
||||
): MappingOption[] {
|
||||
if (!eventTypeId) return [];
|
||||
return mappings.filter((m) => m.event_type_id === eventTypeId);
|
||||
}
|
||||
|
||||
/** A workflow a binding can start. */
|
||||
export interface WorkflowOption {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/** The editor's field state. */
|
||||
export interface BindingDraft {
|
||||
/** The trigger's name when editing; null for a new binding. */
|
||||
id: string | null;
|
||||
name: string;
|
||||
/** The event type the binding applies to; its source is the binding's. */
|
||||
eventTypeId: string;
|
||||
mappingId: string;
|
||||
workflow: string;
|
||||
}
|
||||
|
||||
export function emptyDraft(): BindingDraft {
|
||||
return { id: null, name: "", eventTypeId: "", mappingId: "", workflow: "" };
|
||||
}
|
||||
|
||||
export function draftFromBinding(binding: Binding): BindingDraft {
|
||||
return {
|
||||
id: binding.id,
|
||||
name: binding.name,
|
||||
eventTypeId: binding.event_type_id || "",
|
||||
mappingId: binding.mapping_id || "",
|
||||
workflow: binding.workflow || "",
|
||||
};
|
||||
}
|
||||
|
||||
/** The body PUT /api/triggers/{name} takes. A saved binding waits for
|
||||
* approval again. */
|
||||
export function bindingPayload(
|
||||
draft: BindingDraft,
|
||||
eventTypes: EventType[],
|
||||
): TriggerInput {
|
||||
const eventType = eventTypes.find((t) => t.id === draft.eventTypeId);
|
||||
return {
|
||||
source: eventType?.source ?? "",
|
||||
event_type_id: draft.eventTypeId,
|
||||
mapping_id: draft.mappingId || undefined,
|
||||
workflow: draft.workflow,
|
||||
disabled: false,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { useEventsStore } from "@/stores/events";
|
||||
import { api, ApiError, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import type { EventType } from "@/captures/event-types";
|
||||
import {
|
||||
bindingOfTrigger,
|
||||
bindingPayload,
|
||||
type Binding,
|
||||
type BindingDraft,
|
||||
type MappingOption,
|
||||
type WorkflowOption,
|
||||
} from "./binding-draft";
|
||||
} from "./binding-trigger";
|
||||
|
||||
/**
|
||||
* Why the page has nothing to show. "unconfigured" is a daemon with no
|
||||
* bindings store wired (501/503) -- the feature is off, which reads very
|
||||
* differently from a daemon that answered badly.
|
||||
* Why the page has nothing to show. "unconfigured" is a server that doesn't
|
||||
* serve triggers (501/503), which reads very differently from one that
|
||||
* answered badly.
|
||||
*/
|
||||
type LoadFailureKind = "unconfigured" | "failed";
|
||||
|
||||
@@ -25,8 +25,7 @@ export interface LoadFailure {
|
||||
}
|
||||
|
||||
function failureFor(err: unknown): LoadFailure {
|
||||
const message =
|
||||
describeError(err, errors.common.unknown);
|
||||
const message = describeError(err, errors.common.unknown);
|
||||
const status = err instanceof ApiError ? err.status : undefined;
|
||||
return {
|
||||
kind: status === 501 || status === 503 ? "unconfigured" : "failed",
|
||||
@@ -35,10 +34,9 @@ function failureFor(err: unknown): LoadFailure {
|
||||
}
|
||||
|
||||
/**
|
||||
* The bindings page's data: the three lists the list and the editor read, the
|
||||
* load that fills them, and the three mutations. Every mutation goes through
|
||||
* api.* so the CSRF and Content-Type headers are sent -- a bare fetch is
|
||||
* refused 403/415 by archied's mutation guard.
|
||||
* The bindings page's data: the lists the table and the editor read, the load
|
||||
* that fills them, and the mutations. Every mutation goes through api.* so the
|
||||
* CSRF and Content-Type headers are sent.
|
||||
*/
|
||||
export function useBindings() {
|
||||
// null means loading, [] means loaded and empty.
|
||||
@@ -56,18 +54,16 @@ export function useBindings() {
|
||||
async function load(): Promise<void> {
|
||||
failure.value = null;
|
||||
try {
|
||||
const [b, m, w, t] = await Promise.all([
|
||||
api.bindings<{ bindings?: Binding[] }>(useEventsStore().workspace),
|
||||
const [triggers, m, w, t] = await Promise.all([
|
||||
api.triggers(),
|
||||
api.mappings<{ mappings?: MappingOption[] }>(),
|
||||
api.workflows<{ definitions?: WorkflowOption[] }>(),
|
||||
api.workflowList(),
|
||||
api.eventTypes<{ event_types?: EventType[] }>(),
|
||||
]);
|
||||
bindings.value = b.bindings || [];
|
||||
bindings.value = triggers.filter((x) => x.event_type_id).map(bindingOfTrigger);
|
||||
mappings.value = m.mappings || [];
|
||||
eventTypes.value = t.event_types || [];
|
||||
// Only enabled definitions are offerable: binding to a disabled one
|
||||
// would persist a binding that can never dispatch.
|
||||
workflows.value = (w.definitions || []).filter((d) => d.enabled);
|
||||
workflows.value = w.map((d) => ({ id: d.name, name: d.name }));
|
||||
} catch (err) {
|
||||
failure.value = failureFor(err);
|
||||
bindings.value = null;
|
||||
@@ -83,18 +79,11 @@ export function useBindings() {
|
||||
saving.value = true;
|
||||
saveFailure.value = null;
|
||||
try {
|
||||
const workflow = workflows.value.find((w) => w.id === draft.workflow);
|
||||
const body = bindingPayload(draft, eventTypes.value, workflow);
|
||||
if (draft.id) {
|
||||
await api.bindingUpdate(String(draft.id), body);
|
||||
} else {
|
||||
await api.bindingCreate(body);
|
||||
}
|
||||
await api.putTrigger(draft.id ?? draft.name, bindingPayload(draft, eventTypes.value));
|
||||
await load();
|
||||
return true;
|
||||
} catch (err) {
|
||||
saveFailure.value =
|
||||
describeError(err, errors.common.unknown);
|
||||
saveFailure.value = describeError(err, errors.common.unknown);
|
||||
return false;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
@@ -104,25 +93,16 @@ export function useBindings() {
|
||||
async function transition(command: (id: string) => Promise<unknown>, binding: Binding): Promise<void> {
|
||||
actionFailure.value = null;
|
||||
try {
|
||||
await command(String(binding.id));
|
||||
await load();
|
||||
} catch (err) {
|
||||
actionFailure.value = failureFor(err);
|
||||
}
|
||||
}
|
||||
const approve = (binding: Binding) => transition(api.bindingApprove, binding);
|
||||
const pause = (binding: Binding) => transition(api.bindingPause, binding);
|
||||
const resume = (binding: Binding) => transition(api.bindingResume, binding);
|
||||
|
||||
async function remove(binding: Binding): Promise<void> {
|
||||
actionFailure.value = null;
|
||||
try {
|
||||
await api.bindingDelete(String(binding.id));
|
||||
await command(binding.id);
|
||||
await load();
|
||||
} catch (err) {
|
||||
actionFailure.value = failureFor(err);
|
||||
}
|
||||
}
|
||||
const approve = (binding: Binding) => transition(api.approveTrigger, binding);
|
||||
const pause = (binding: Binding) => transition(api.pauseTrigger, binding);
|
||||
const resume = (binding: Binding) => transition(api.resumeTrigger, binding);
|
||||
const remove = (binding: Binding) => transition(api.deleteTrigger, binding);
|
||||
|
||||
return {
|
||||
bindings,
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { captureSignature } from "./capture-signature";
|
||||
import CapturePayload from "./CapturePayload.vue";
|
||||
import DispatchLinks from "@/bindings/DispatchLinks.vue";
|
||||
import TriggerRuns from "@/bindings/TriggerRuns.vue";
|
||||
import { selected } from "./state";
|
||||
|
||||
/**
|
||||
@@ -86,8 +86,8 @@ watch(selected, () => {
|
||||
<CapturePayload label="Payload" :raw="selected.body" />
|
||||
<CapturePayload label="Headers" :raw="selected.headers" />
|
||||
<section class="flex flex-col gap-2">
|
||||
<h3 class="text-caption font-medium tracking-[0.06em] text-fg-subtle uppercase">Dispatches</h3>
|
||||
<DispatchLinks kind="captures" :id="selected.id" />
|
||||
<h3 class="text-caption font-medium tracking-[0.06em] text-fg-subtle uppercase">Runs</h3>
|
||||
<TriggerRuns kind="captures" :id="selected.id" />
|
||||
</section>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
/**
|
||||
* How a capture may dispatch: signed by its source's secret, taken on a
|
||||
* source approved for unsigned events, or neither -- in which case nothing
|
||||
* starts from it.
|
||||
* How a capture was verified when it arrived: by its source's HMAC signature,
|
||||
* by the source's bearer token, or on a source approved to take deliveries
|
||||
* with no verification.
|
||||
*/
|
||||
export interface CaptureSignature {
|
||||
label: "Signed" | "Unsigned" | "Unverified";
|
||||
label: "Signed" | "Token" | "Unsigned" | "Unverified";
|
||||
kind: "ok" | "warn" | "idle";
|
||||
}
|
||||
|
||||
export function captureSignature(capture: {
|
||||
authenticated?: boolean;
|
||||
unsigned?: boolean;
|
||||
verification?: string;
|
||||
}): CaptureSignature {
|
||||
if (capture.unsigned) return { label: "Unsigned", kind: "warn" };
|
||||
if (capture.authenticated) return { label: "Signed", kind: "ok" };
|
||||
switch (capture.verification) {
|
||||
case "signed":
|
||||
return { label: "Signed", kind: "ok" };
|
||||
case "token":
|
||||
return { label: "Token", kind: "ok" };
|
||||
case "unsigned":
|
||||
return { label: "Unsigned", kind: "warn" };
|
||||
}
|
||||
return { label: "Unverified", kind: "idle" };
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { useEventsStore } from "@/stores/events";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { captures } from "./state";
|
||||
@@ -54,7 +53,7 @@ let generation = 0;
|
||||
export async function loadEventTypes(): Promise<void> {
|
||||
const current = ++generation;
|
||||
try {
|
||||
const res = await api.eventTypes<EventTypesResponse>(useEventsStore().workspace);
|
||||
const res = await api.eventTypes<EventTypesResponse>();
|
||||
if (current !== generation) return;
|
||||
eventTypesEnabled.value = res.enabled !== false;
|
||||
eventTypes.value = res.event_types || [];
|
||||
|
||||
@@ -27,10 +27,10 @@ export interface Capture {
|
||||
content_type?: string;
|
||||
headers?: string;
|
||||
body?: string;
|
||||
authenticated?: boolean;
|
||||
/** How the delivery was verified: signed, token or unsigned. */
|
||||
verification?: string;
|
||||
/** The event type it was identified as on arrival; empty is unidentified. */
|
||||
event_type?: string;
|
||||
unsigned?: boolean;
|
||||
}
|
||||
|
||||
interface CapturesResponse {
|
||||
|
||||
@@ -7,17 +7,6 @@ import { useRoute, useRouter } from "vue-router";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import type { OrgWorkspace } from "@/org/org";
|
||||
import { useEventsStore } from "@/stores/events";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import BindingsPage from "@/bindings/BindingsPage.vue";
|
||||
import CapturesPage from "@/captures/CapturesPage.vue";
|
||||
import { api } from "@/lib/api";
|
||||
@@ -54,8 +43,6 @@ const PANELS: Record<string, Component> = {
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const orgStore = useOrgStore();
|
||||
const events = useEventsStore();
|
||||
|
||||
const session = useSessionStore();
|
||||
const tabs = computed(() => availableTabs(session.sections));
|
||||
@@ -80,54 +67,24 @@ watch(active, (tab) => show(tab), { immediate: true });
|
||||
// read one source rather than three.
|
||||
const counts = ref<EventsCounts>({});
|
||||
// A counts read bumps the generation; one that settles after a newer read
|
||||
// started is dropped, so the previous workspace's counts never overwrite the
|
||||
// current one.
|
||||
// started is dropped.
|
||||
let countsGeneration = 0;
|
||||
// The capture chain's counts read routes only a capture backend serves.
|
||||
const captureChain = computed(() => session.sections?.captures !== false);
|
||||
async function loadCounts() {
|
||||
if (!captureChain.value) return;
|
||||
const gen = ++countsGeneration;
|
||||
const workspace = events.workspace;
|
||||
const loaded = await loadEventCounts({
|
||||
captures: api.captures,
|
||||
mappings: () => api.mappings(workspace),
|
||||
bindings: () => api.bindings(workspace),
|
||||
mappings: () => api.mappings(),
|
||||
// A binding is a trigger bound to an event type.
|
||||
bindings: async () => ({ bindings: (await api.triggers()).filter((t) => t.event_type_id) }),
|
||||
});
|
||||
if (gen !== countsGeneration) return;
|
||||
counts.value = loaded;
|
||||
}
|
||||
useLiveResource(null, () => void loadCounts(), 1000);
|
||||
|
||||
// The workspace the lists show rides in the query string (`?workspace=`) like
|
||||
// the step, so a filtered view is a link. "All" needs a sentinel: an empty
|
||||
// string is how a Select spells "nothing selected".
|
||||
const ALL = "__all__";
|
||||
const workspaces = ref<OrgWorkspace[]>([]);
|
||||
watch(
|
||||
() => String(route.query.workspace ?? ""),
|
||||
(workspace) => {
|
||||
events.workspace = workspace;
|
||||
void loadCounts();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
function pickWorkspace(value: unknown): void {
|
||||
const workspace = String(value) === ALL ? undefined : String(value);
|
||||
void router.replace({ query: { ...route.query, workspace } });
|
||||
}
|
||||
onMounted(async () => {
|
||||
if (session.sections?.org === false) return;
|
||||
try {
|
||||
await orgStore.loadOrg();
|
||||
workspaces.value = (
|
||||
await api.orgWorkspaces<{ workspaces: OrgWorkspace[] }>(orgStore.homeOrg)
|
||||
).workspaces;
|
||||
} catch {
|
||||
// Without the list there is nothing to pick; every workspace shows.
|
||||
workspaces.value = [];
|
||||
}
|
||||
});
|
||||
onMounted(() => void loadCounts());
|
||||
|
||||
const steps = computed(() => stepsFor(tabs.value));
|
||||
|
||||
@@ -139,23 +96,6 @@ const panel = computed(() => PANELS[active.value]);
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Events">
|
||||
<Select
|
||||
v-if="workspaces.length > 1"
|
||||
:model-value="events.workspace || ALL"
|
||||
@update:model-value="pickWorkspace"
|
||||
>
|
||||
<SelectTrigger size="sm" aria-label="Show records from workspace">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectItem :value="ALL">All workspaces</SelectItem>
|
||||
<SelectItem v-for="workspace in workspaces" :key="workspace.id" :value="workspace.id">
|
||||
{{ workspace.name }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<template v-if="captureChain && !captureLoading">
|
||||
<Badge v-if="!captureEnabled" variant="warn">Capture off</Badge>
|
||||
</template>
|
||||
@@ -173,7 +113,7 @@ const panel = computed(() => PANELS[active.value]);
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
|
||||
<component :is="panel" v-if="panel" :key="`${active}:${events.workspace}`" />
|
||||
<component :is="panel" v-if="panel" :key="active" />
|
||||
<Empty v-else>
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>Event automation is not enabled</EmptyTitle>
|
||||
|
||||
+47
-5
@@ -203,7 +203,24 @@ export const api = {
|
||||
event: (id: string) => request<EventDetail>(`/api/events/${encodeURIComponent(id)}`),
|
||||
eventSources: () => request<EventSource_[]>("/api/sources"),
|
||||
putEventSource: (name: string, connector: string, verification?: SourceVerification) =>
|
||||
request<{ source: string; token?: string; url: string }>(`/api/sources/${encodeURIComponent(name)}`, { method: "PUT", body: { connector, ...verification } }),
|
||||
request<{ source: string; token?: string; secret?: string; url: string }>(`/api/sources/${encodeURIComponent(name)}`, { method: "PUT", body: { connector, ...verification } }),
|
||||
sourceCapture: (name: string, capture: boolean) =>
|
||||
request<EventSource_>(`/api/sources/${encodeURIComponent(name)}/capture`, { method: "PUT", body: { capture } }),
|
||||
/** The runs a trigger started, newest first. */
|
||||
triggerDispatches: (name: string) =>
|
||||
request<TriggerRun[]>(`/api/triggers/${encodeURIComponent(name)}/dispatches`),
|
||||
approveTrigger: (name: string) =>
|
||||
request<Trigger>(`/api/triggers/${encodeURIComponent(name)}/approve`, { method: "POST" }),
|
||||
pauseTrigger: (name: string) =>
|
||||
request<Trigger>(`/api/triggers/${encodeURIComponent(name)}/pause`, { method: "POST" }),
|
||||
/** A resumed trigger waits for approval again. */
|
||||
resumeTrigger: (name: string) =>
|
||||
request<Trigger>(`/api/triggers/${encodeURIComponent(name)}/resume`, { method: "POST" }),
|
||||
deleteTrigger: (name: string) =>
|
||||
request<void>(`/api/triggers/${encodeURIComponent(name)}`, { method: "DELETE", parse: false }),
|
||||
/** The runs a stored delivery started. */
|
||||
captureDispatches: (id: string) =>
|
||||
request<TriggerRun[]>(`/api/captures/${encodeURIComponent(id)}/dispatches`),
|
||||
putSourceKeyFields: (name: string, paths: string[]) =>
|
||||
request<{ key_fields: string[] }>(`/api/sources/${encodeURIComponent(name)}/key-fields`, { method: "PUT", body: { paths } }),
|
||||
triggers: () => request<Trigger[]>("/api/triggers"),
|
||||
@@ -500,8 +517,7 @@ export const api = {
|
||||
}),
|
||||
captures: <T = unknown>(limit?: number) =>
|
||||
request<T>("/api/captures" + qs({ limit })),
|
||||
eventTypes: <T = unknown>(workspace?: string) =>
|
||||
request<T>("/api/event-types" + qs({ workspace })),
|
||||
eventTypes: <T = unknown>() => request<T>("/api/event-types"),
|
||||
eventTypeCreate: <T = unknown>(eventType: Payload) =>
|
||||
request<T>("/api/event-types", { method: "POST", body: eventType }),
|
||||
eventTypeUpdate: <T = unknown>(id: string, eventType: Payload) =>
|
||||
@@ -514,8 +530,7 @@ export const api = {
|
||||
method: "DELETE",
|
||||
parse: false,
|
||||
}),
|
||||
mappings: <T = unknown>(workspace?: string) =>
|
||||
request<T>("/api/mappings" + qs({ workspace })),
|
||||
mappings: <T = unknown>() => request<T>("/api/mappings"),
|
||||
mappingCreate: <T = unknown>(mapping: Payload) =>
|
||||
request<T>("/api/mappings", { method: "POST", body: mapping }),
|
||||
mappingUpdate: <T = unknown>(id: string, mapping: Payload) =>
|
||||
@@ -846,6 +861,16 @@ export interface EventRecord {
|
||||
dispatched_at?: string;
|
||||
linked_to?: string;
|
||||
fields?: unknown;
|
||||
/** How the delivery was verified; empty for an event a connector streamed. */
|
||||
verification?: "signed" | "token" | "unsigned" | "";
|
||||
}
|
||||
|
||||
/** A run a trigger started for a stored event. */
|
||||
export interface TriggerRun {
|
||||
event_id: string;
|
||||
run_id: string;
|
||||
trigger?: string;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface EventDetail {
|
||||
@@ -871,6 +896,14 @@ export interface EventSource_ {
|
||||
hmac_header?: string;
|
||||
hmac_prefix?: string;
|
||||
hmac_secret_set: boolean;
|
||||
display_name?: string;
|
||||
/** The header a sender repeats on every retry of one delivery. */
|
||||
delivery_header?: string;
|
||||
signing: "signed" | "token" | "unsigned_pending_approval" | "unsigned";
|
||||
/** Whether the source keeps each delivery's headers and payload. */
|
||||
capture: boolean;
|
||||
/** A signing secret the request issued; shown once. */
|
||||
secret?: string;
|
||||
}
|
||||
|
||||
export interface Trigger {
|
||||
@@ -881,6 +914,11 @@ export interface Trigger {
|
||||
workflow: string;
|
||||
filter?: Record<string, string>;
|
||||
enabled: boolean;
|
||||
status: "pending_approval" | "armed" | "paused";
|
||||
event_type_id?: string;
|
||||
mapping_id?: string;
|
||||
/** The source takes deliveries with no verification. */
|
||||
unsigned: boolean;
|
||||
}
|
||||
|
||||
export interface TriggerInput {
|
||||
@@ -890,6 +928,10 @@ export interface TriggerInput {
|
||||
workflow: string;
|
||||
filter?: Record<string, string>;
|
||||
disabled: boolean;
|
||||
event_type_id?: string;
|
||||
mapping_id?: string;
|
||||
/** Save waiting for approval. */
|
||||
pending?: boolean;
|
||||
}
|
||||
|
||||
export interface WorkflowVersion {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { useEventsStore } from "@/stores/events";
|
||||
import { api, classifyActionError, describeError, type ActionErrorKind } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import type { EventType } from "@/captures/event-types";
|
||||
@@ -146,7 +145,7 @@ export async function loadMappings(): Promise<void> {
|
||||
// mappings without it -- so a failing capture leg flags the picker instead
|
||||
// of taking the mappings list down with it.
|
||||
const [listed, captured, types] = await Promise.all([
|
||||
api.mappings<{ mappings?: Mapping[] }>(useEventsStore().workspace),
|
||||
api.mappings<{ mappings?: Mapping[] }>(),
|
||||
api
|
||||
.captures<{ captures?: Capture[]; enabled?: boolean }>(100)
|
||||
.catch(() => null),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { Check, Copy, KeyRound, Lock, LockOpen, Plus, Trash2 } from "@lucide/vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { Check, Copy, Eye, EyeOff, KeyRound, Lock, LockOpen, Plus, Trash2 } from "@lucide/vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
||||
@@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import {
|
||||
Table,
|
||||
@@ -23,6 +24,8 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import {
|
||||
signingKind,
|
||||
@@ -52,16 +55,23 @@ const {
|
||||
approveUnsigned,
|
||||
rename,
|
||||
setDeliveryHeader,
|
||||
setCapture,
|
||||
remove,
|
||||
refusals,
|
||||
} = useSources();
|
||||
const connectors = useRead(() => api.extensions("connectors"));
|
||||
const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c.name));
|
||||
const connector = ref("");
|
||||
const header = ref("");
|
||||
const pending = ref<Source | null>(null);
|
||||
|
||||
const customPath = ref("");
|
||||
const copied = ref<string | null>(null);
|
||||
|
||||
useLiveResource(null, () => void load());
|
||||
onMounted(load);
|
||||
onMounted(() => {
|
||||
void load();
|
||||
void connectors.reload();
|
||||
});
|
||||
|
||||
async function copy(value: string): Promise<void> {
|
||||
await navigator.clipboard.writeText(value);
|
||||
@@ -70,8 +80,11 @@ async function copy(value: string): Promise<void> {
|
||||
}
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
await create(customPath.value);
|
||||
if (!failure.value) customPath.value = "";
|
||||
await create(customPath.value.trim(), connector.value, header.value.trim());
|
||||
if (!failure.value) {
|
||||
customPath.value = "";
|
||||
header.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function url(source: Source): string {
|
||||
@@ -87,11 +100,26 @@ function url(source: Source): string {
|
||||
>
|
||||
<Input
|
||||
v-model="customPath"
|
||||
class="w-full font-mono sm:w-64"
|
||||
placeholder="Custom path (optional)"
|
||||
aria-label="Custom path"
|
||||
class="w-full font-mono sm:w-48"
|
||||
placeholder="Source name"
|
||||
aria-label="Source name"
|
||||
pattern="[a-z][a-z0-9\-]*"
|
||||
required
|
||||
/>
|
||||
<Button type="submit" variant="outline" :disabled="busy">
|
||||
<Select v-model="connector" required>
|
||||
<SelectTrigger class="w-full sm:w-44" aria-label="Connector"><SelectValue placeholder="Connector" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="name in connectorNames" :key="name" :value="name">{{ name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
v-model="header"
|
||||
class="w-full font-mono sm:w-48"
|
||||
placeholder="Signature header"
|
||||
aria-label="Signature header"
|
||||
required
|
||||
/>
|
||||
<Button type="submit" variant="outline" :disabled="busy || !customPath || !connector || !header">
|
||||
<Plus data-icon="inline-start" />
|
||||
New source</Button>
|
||||
</form>
|
||||
@@ -139,14 +167,6 @@ function url(source: Source): string {
|
||||
:disabled="busy"
|
||||
@change="setDeliveryHeader(source, ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
<div
|
||||
v-if="refusals[source.path]"
|
||||
class="text-caption font-sans text-danger"
|
||||
:title="refusals[source.path].addrs.join(', ')"
|
||||
>
|
||||
{{ refusals[source.path].refused }} refused in 24h from
|
||||
{{ refusals[source.path].addrs.slice(0, 3).join(", ") }}
|
||||
</div>
|
||||
</div></TableCell
|
||||
>
|
||||
<TableCell>
|
||||
@@ -184,6 +204,21 @@ function url(source: Source): string {
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>New secret</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
:aria-label="source.capture ? 'Stop keeping payloads' : 'Keep payloads'"
|
||||
:disabled="busy"
|
||||
@click="setCapture(source, !source.capture)"
|
||||
>
|
||||
<Eye v-if="source.capture" />
|
||||
<EyeOff v-else />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ source.capture ? "Stop keeping payloads" : "Keep payloads" }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<Button
|
||||
v-if="source.signing === 'signed'"
|
||||
variant="outline"
|
||||
@@ -202,7 +237,7 @@ function url(source: Source): string {
|
||||
<Check data-icon="inline-start" />
|
||||
Approve unsigned</Button>
|
||||
<Button
|
||||
v-if="source.signing !== 'signed'"
|
||||
v-if="source.signing === 'unsigned' || source.signing === 'unsigned_pending_approval'"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="busy"
|
||||
|
||||
@@ -1,38 +1,48 @@
|
||||
/**
|
||||
* The sources vocabulary: the wire shape GET /api/sources returns and the
|
||||
* signing states it carries. A source's secret is only ever in the response
|
||||
* to the write that generated it.
|
||||
* The sources vocabulary: a source as the panel shows it, and the signing
|
||||
* states the server reports. A source's secret is only ever in the response to
|
||||
* the write that generated it.
|
||||
*/
|
||||
|
||||
import type { EventSource_ } from "@/lib/api";
|
||||
|
||||
export interface Source {
|
||||
/** The source's name, which its webhook URL ends in. */
|
||||
path: string;
|
||||
/** The operator's label; the path stays the source's identity. */
|
||||
name?: string;
|
||||
/** The header the sender repeats on every retry of one delivery. */
|
||||
delivery_header?: string;
|
||||
signing?: string;
|
||||
/** Whether the source keeps each delivery's headers and payload. */
|
||||
capture: boolean;
|
||||
/** Present only on create and on a new secret. */
|
||||
secret?: string;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
/** What the network rules refused on one source in the last day. */
|
||||
export interface SourceRefusals {
|
||||
refused: number;
|
||||
accepted: number;
|
||||
addrs: string[];
|
||||
export function toSource(view: EventSource_): Source {
|
||||
return {
|
||||
path: view.name,
|
||||
name: view.display_name,
|
||||
delivery_header: view.delivery_header,
|
||||
signing: view.signing,
|
||||
capture: view.capture,
|
||||
secret: view.secret,
|
||||
};
|
||||
}
|
||||
|
||||
export type SigningKind = "ok" | "info" | "warn" | "idle";
|
||||
|
||||
const LABELS: Record<string, string> = {
|
||||
signed: "signed",
|
||||
token: "bearer token",
|
||||
unsigned_pending_approval: "unsigned pending approval",
|
||||
unsigned: "unsigned",
|
||||
};
|
||||
|
||||
const KINDS: Record<string, SigningKind> = {
|
||||
signed: "ok",
|
||||
token: "ok",
|
||||
unsigned_pending_approval: "info",
|
||||
unsigned: "warn",
|
||||
};
|
||||
@@ -48,5 +58,5 @@ export function signingKind(signing?: string): SigningKind {
|
||||
|
||||
/** The URL a sender posts to. */
|
||||
export function sourceURL(origin: string, path: string): string {
|
||||
return `${origin}/webhooks/capture/${encodeURIComponent(path)}`;
|
||||
return `${origin}/hooks/${encodeURIComponent(path)}`;
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
import { useEventsStore } from "@/stores/events";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import type { Source, SourceRefusals } from "./source-signing";
|
||||
import { api, describeError, type EventSource_ } from "@/lib/api";
|
||||
import { toSource, type Source } from "./source-signing";
|
||||
|
||||
/**
|
||||
* The sources list and its writes. A write that generates a secret keeps the
|
||||
@@ -18,20 +17,15 @@ export function useSources() {
|
||||
const loadError = ref<string | null>(null);
|
||||
const failure = ref<string | null>(null);
|
||||
const revealed = ref<Source | null>(null);
|
||||
const refusals = ref<Record<string, SourceRefusals>>({});
|
||||
const busy = ref(false);
|
||||
|
||||
let generation = 0;
|
||||
async function load(): Promise<void> {
|
||||
const current = ++generation;
|
||||
try {
|
||||
const res = await api.sources<{
|
||||
sources?: Source[];
|
||||
refusals?: Record<string, SourceRefusals>;
|
||||
}>(useEventsStore().workspace);
|
||||
const res = await api.eventSources();
|
||||
if (current !== generation) return;
|
||||
sources.value = res.sources || [];
|
||||
refusals.value = res.refusals || {};
|
||||
sources.value = res.map(toSource);
|
||||
failure.value = null;
|
||||
loadError.value = null;
|
||||
} catch (err) {
|
||||
@@ -54,30 +48,32 @@ export function useSources() {
|
||||
}
|
||||
}
|
||||
|
||||
const source = (write: Promise<EventSource_>) => write.then(toSource);
|
||||
|
||||
return {
|
||||
sources,
|
||||
loadError,
|
||||
failure,
|
||||
revealed,
|
||||
refusals,
|
||||
busy,
|
||||
load,
|
||||
create: (path: string) =>
|
||||
run(() => api.sourceCreate<Source>(path.trim(), useEventsStore().workspace)),
|
||||
newSecret: (source: Source) =>
|
||||
run(() => api.sourceSecret<Source>(source.path)),
|
||||
requestUnsigned: (source: Source) =>
|
||||
run(() => api.sourceSigning<Source>(source.path, false)),
|
||||
requireSigning: (source: Source) =>
|
||||
run(() => api.sourceSigning<Source>(source.path, true)),
|
||||
approveUnsigned: (source: Source) =>
|
||||
run(() => api.sourceApproveUnsigned<Source>(source.path)),
|
||||
rename: (source: Source, name: string) =>
|
||||
run(() => api.sourceName<Source>(source.path, name.trim())),
|
||||
setDeliveryHeader: (source: Source, header: string) =>
|
||||
run(() => api.sourceDeliveryHeader<Source>(source.path, header.trim())),
|
||||
// An armed binding on the source refuses the delete; the refusal shows
|
||||
// A new source signs with an HMAC over the body; the server generates the
|
||||
// secret and returns it once.
|
||||
create: (name: string, connector: string, header: string) =>
|
||||
run(async () => {
|
||||
const created = await api.putEventSource(name, connector, { verification: "hmac", hmac_header: header });
|
||||
return { path: name, signing: "signed", capture: true, secret: created.secret };
|
||||
}),
|
||||
newSecret: (s: Source) => run(() => source(api.sourceSecret<EventSource_>(s.path))),
|
||||
requestUnsigned: (s: Source) => run(() => source(api.sourceSigning<EventSource_>(s.path, false))),
|
||||
requireSigning: (s: Source) => run(() => source(api.sourceSigning<EventSource_>(s.path, true))),
|
||||
approveUnsigned: (s: Source) => run(() => source(api.sourceApproveUnsigned<EventSource_>(s.path))),
|
||||
rename: (s: Source, name: string) => run(() => source(api.sourceName<EventSource_>(s.path, name.trim()))),
|
||||
setDeliveryHeader: (s: Source, header: string) =>
|
||||
run(() => source(api.sourceDeliveryHeader<EventSource_>(s.path, header.trim()))),
|
||||
setCapture: (s: Source, capture: boolean) => run(() => source(api.sourceCapture(s.path, capture))),
|
||||
// A trigger that names the source refuses the delete; the refusal shows
|
||||
// as the panel's failure.
|
||||
remove: (source: Source) => run(() => api.sourceDelete(source.path)),
|
||||
remove: (s: Source) => run(() => api.sourceDelete(s.path)),
|
||||
};
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
/** What the Events pages share across their panels. */
|
||||
export const useEventsStore = defineStore("events", () => {
|
||||
/**
|
||||
* The workspace the Events pages list records from and create sources in.
|
||||
* Empty lists every workspace and creates in the org's default one. Event
|
||||
* types and bindings take their source's workspace, mappings their event
|
||||
* type's, so the source is the one record this picks for.
|
||||
*/
|
||||
const workspace = ref("");
|
||||
return { workspace };
|
||||
});
|
||||
@@ -10,13 +10,12 @@ import {
|
||||
import { describeTimelineEvent } from "../src/tasks/timeline-event.ts";
|
||||
|
||||
test("a capture shows how it may dispatch", () => {
|
||||
const cases: Array<
|
||||
[{ authenticated?: boolean; unsigned?: boolean }, string, string]
|
||||
> = [
|
||||
[{ authenticated: true }, "Signed", "ok"],
|
||||
[{ unsigned: true }, "Unsigned", "warn"],
|
||||
const cases: Array<[{ verification?: string }, string, string]> = [
|
||||
[{ verification: "signed" }, "Signed", "ok"],
|
||||
[{ verification: "token" }, "Token", "ok"],
|
||||
[{ verification: "unsigned" }, "Unsigned", "warn"],
|
||||
[{}, "Unverified", "idle"],
|
||||
[{ authenticated: false, unsigned: false }, "Unverified", "idle"],
|
||||
[{ verification: "" }, "Unverified", "idle"],
|
||||
];
|
||||
for (const [capture, label, kind] of cases) {
|
||||
assert.deepEqual(
|
||||
@@ -30,6 +29,7 @@ test("a capture shows how it may dispatch", () => {
|
||||
test("a source's signing state names itself and its tone", () => {
|
||||
const cases: Array<[string | undefined, string, string]> = [
|
||||
["signed", "signed", "ok"],
|
||||
["token", "bearer token", "ok"],
|
||||
["unsigned_pending_approval", "unsigned pending approval", "info"],
|
||||
["unsigned", "unsigned", "warn"],
|
||||
["something_new", "something_new", "idle"],
|
||||
@@ -44,9 +44,9 @@ test("a source's signing state names itself and its tone", () => {
|
||||
test("a source's URL escapes nothing a valid path can hold", () => {
|
||||
assert.equal(
|
||||
sourceURL("https://archie.example", "0199a0b2-0000-7000-8000-000000000000"),
|
||||
"https://archie.example/webhooks/capture/0199a0b2-0000-7000-8000-000000000000",
|
||||
"https://archie.example/hooks/0199a0b2-0000-7000-8000-000000000000",
|
||||
);
|
||||
assert.equal(sourceURL("http://h", "a b"), "http://h/webhooks/capture/a%20b");
|
||||
assert.equal(sourceURL("http://h", "a b"), "http://h/hooks/a%20b");
|
||||
});
|
||||
|
||||
test("a task started by an unsigned event says so on its timeline", () => {
|
||||
|
||||
Reference in new issue
Block a user