Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Keep the delivery log open across endpoint changes, and fix three webhook details

Claude82211ecaabc3
diff --git a/docs/api.md b/docs/api.md
index 2e47548..bdf21fd 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -395,12 +395,15 @@ day. On Pro you can run it more often by changing the schedule of
If your app was down, `GET /api/v1/webhook-deliveries?since=…` lists what
it missed, with the same payloads. `since` counts from when each delivery
-was queued, which is when its event happened, not when it was sent: give
-the time of the last event your app has. Times are kept to the second, so
-a `since` with a fraction counts from the start of its second, and you may
-get a delivery you already have: skip it by its `webhook-id`. Deliveries
-are kept 30 days after they are delivered, and otherwise 90 days after
-their last try or "Send again".
+was queued, which is when its event happened, not when it was sent.
+Deliveries can arrive out of order, as one can still be retrying while a
+later one gets through, so the newest event your app has is not a safe
+`since`. Give a time from before anything it may have missed, for example
+three days before it went down (retries take about two and a half days),
+and skip what it already has by its `webhook-id`. Times are kept to the
+second, so a `since` with a fraction counts from the start of its second.
+Deliveries are kept 30 days after they are delivered, and otherwise 90
+days after their last try or "Send again".
### Safety
diff --git a/src/components/settings/webhooks-panel.tsx b/src/components/settings/webhooks-panel.tsx
index 9061685..cd2e6cf 100644
--- a/src/components/settings/webhooks-panel.tsx
+++ b/src/components/settings/webhooks-panel.tsx
@@ -77,7 +77,18 @@ function deliveryTone(status: WebhookDeliverySummary["status"]) {
: "pill-warning";
}
-function DeliveryLog({ endpointId }: { endpointId: string }) {
+/**
+ * One endpoint's recent deliveries. `refreshKey` changes when the panel
+ * changes an endpoint: the log reads itself again but stays mounted, so a
+ * "Send again" under way and its error are not lost.
+ */
+function DeliveryLog({
+ endpointId,
+ refreshKey,
+}: {
+ endpointId: string;
+ refreshKey: number;
+}) {
const [deliveries, setDeliveries] = useState<WebhookDeliverySummary[] | null>(
null,
);
@@ -111,7 +122,7 @@ function DeliveryLog({ endpointId }: { endpointId: string }) {
return () => {
cancelled = true;
};
- }, [endpointId, revision]);
+ }, [endpointId, refreshKey, revision]);
function refresh() {
setError(null);
@@ -687,7 +698,7 @@ export function WebhooksPanel() {
)}
</div>
{openLogId === endpoint.id ? (
- <DeliveryLog endpointId={endpoint.id} key={revision} />
+ <DeliveryLog endpointId={endpoint.id} refreshKey={revision} />
) : null}
</li>
))}
diff --git a/src/lib/webhooks/admin-route.ts b/src/lib/webhooks/admin-route.ts
index 93d10e6..e5d44a1 100644
--- a/src/lib/webhooks/admin-route.ts
+++ b/src/lib/webhooks/admin-route.ts
@@ -29,6 +29,8 @@ export async function handleWebhookAdmin(
const sessionResult = await requireAdminSession(request);
if (sessionResult instanceof Response) {
+ // A refusal is not cached either.
+ sessionResult.headers.set("cache-control", noStore["cache-control"]);
return sessionResult;
}
diff --git a/src/lib/webhooks/webhooks.dbtest.ts b/src/lib/webhooks/webhooks.dbtest.ts
index 827828c..078c9b3 100644
--- a/src/lib/webhooks/webhooks.dbtest.ts
+++ b/src/lib/webhooks/webhooks.dbtest.ts
@@ -666,7 +666,11 @@ test("a send whose invitation email fails leaves no envelope.sent webhook", asyn
process.env.EMAIL_CAPTURE_DIR = path.join(blocker, "outbox");
try {
- await assert.rejects(createEnvelope(admin));
+ // The capture's own error, so the send got as far as the email.
+ await assert.rejects(
+ createEnvelope(admin),
+ (error: unknown) => (error as { code?: unknown }).code === "ENOTDIR",
+ );
} finally {
process.env.EMAIL_CAPTURE_DIR = outbox;
}