Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Merge the webhooks review fixes into the embedded signing branch
Claude796f773c1a52
diff --cc docs/api.mdindex 9f33c33,2e47548..cd00305--- a/docs/api.md+++ b/docs/api.md@@@ -256,25 -252,24 +257,25 @@@ To know when something happens without## Endpoints-| Method and path | Access | What it does |-| ---------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `GET /api/v1/me` | read | Which key this is and whom it acts as. |-| `POST /api/v1/envelopes` | write | Creates an envelope, and sends it if asked. |-| `GET /api/v1/envelopes` | read | Lists envelopes, newest first: `?status=`, `?limit=` (up to 100, 25 by default), and `?cursor=` with the `nextCursor` of the page before. |-| `GET /api/v1/envelopes/{id}` | read | One envelope. |-| `POST /api/v1/envelopes/{id}/send` | write | Sends a draft. Body: the `send` options above. |-| `POST /api/v1/envelopes/{id}/void` | write | Voids a sent envelope. Body: `{"reason": "…"}`, required on Part 11 installs. |-| `POST /api/v1/envelopes/{id}/remind` | write | Emails a reminder to each signer whose turn it is, at most once a day as in the web app. Too soon gets 429 with `Retry-After`. |-| `DELETE /api/v1/envelopes/{id}` | write | Deletes a draft. |-| `GET /api/v1/envelopes/{id}/events` | read | The audit trail, oldest first. |-| `GET /api/v1/envelopes/{id}/files/signed` | read | The signed PDF. |-| `GET /api/v1/envelopes/{id}/files/certificate` | read | The certificate of completion. |-| `POST /api/v1/uploads` | write | An upload URL for a PDF over 4 MB. |-| `GET /api/v1/templates` | read | Saved templates, with their roles in signing order. |-| `POST /api/v1/templates/{id}/envelopes` | write | An envelope from a template: `title`, `signers` (`name`, `email`, and `signatureMeaning` on Part 11 installs, one per role in order), and optionally `metadata` and `send`. Takes an `Idempotency-Key`. |-| `GET /api/v1/webhook-deliveries` | read | Webhook deliveries, newest first, with the payload each carried: `?since=` (ISO time), `?type=`, `?status=`, `?limit=`, `?cursor=`. See [Webhooks](#webhooks). |-| `GET /api/v1/openapi.json` | none | The OpenAPI 3.1 description of all of this, for code generators and API tools. |+| Method and path | Access | What it does |+| ----------------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `GET /api/v1/me` | read | Which key this is and whom it acts as. |+| `POST /api/v1/envelopes` | write | Creates an envelope, and sends it if asked. |+| `GET /api/v1/envelopes` | read | Lists envelopes, newest first: `?status=`, `?limit=` (up to 100, 25 by default), and `?cursor=` with the `nextCursor` of the page before. |+| `GET /api/v1/envelopes/{id}` | read | One envelope. |+| `POST /api/v1/envelopes/{id}/send` | write | Sends a draft. Body: the `send` options above. |+| `POST /api/v1/envelopes/{id}/void` | write | Voids a sent envelope. Body: `{"reason": "…"}`, required on Part 11 installs. |- | `POST /api/v1/envelopes/{id}/remind` | write | Emails a reminder to each signer whose turn it is, at most once a day as in the web app. |++| `POST /api/v1/envelopes/{id}/remind` | write | Emails a reminder to each signer whose turn it is, at most once a day as in the web app. Too soon gets 429 with `Retry-After`. |+| `POST /api/v1/envelopes/{id}/signers/{signerId}/embed-link` | write | A signing link for an embedded envelope, to show in a frame. Body: `{"origin": "https://…"}`. See [Embedded signing](#embedded-signing). |+| `DELETE /api/v1/envelopes/{id}` | write | Deletes a draft. |+| `GET /api/v1/envelopes/{id}/events` | read | The audit trail, oldest first. |+| `GET /api/v1/envelopes/{id}/files/signed` | read | The signed PDF. |+| `GET /api/v1/envelopes/{id}/files/certificate` | read | The certificate of completion. |+| `POST /api/v1/uploads` | write | An upload URL for a PDF over 4 MB. |+| `GET /api/v1/templates` | read | Saved templates, with their roles in signing order. |+| `POST /api/v1/templates/{id}/envelopes` | write | An envelope from a template: `title`, `signers` (`name`, `email`, and `signatureMeaning` on Part 11 installs, one per role in order), and optionally `metadata` and `send`. Takes an `Idempotency-Key`. |+| `GET /api/v1/webhook-deliveries` | read | Webhook deliveries, newest first, with the payload each carried: `?since=` (ISO time), `?type=`, `?status=`, `?limit=`, `?cursor=`. See [Webhooks](#webhooks). |+| `GET /api/v1/openapi.json` | none | The OpenAPI 3.1 description of all of this, for code generators and API tools. |Envelopes made through the API are ordinary envelopes: they show in the key'sadministrator's documents, can be followed and voided there, and their auditdiff --cc src/lib/webhooks/admin-route.tsindex 8af4ed8,93d10e6..83baaca--- a/src/lib/webhooks/admin-route.ts+++ b/src/lib/webhooks/admin-route.ts@@@ -33,30 -19,34 +33,35 @@@ export async function handleWebhookAdmirequest: Request,category: string,run: (actor: WebhookActor) => Promise<Response>,+ words: AdminRouteWords = WEBHOOK_WORDS,): Promise<Response> {- const sessionResult = await requireAdminSession(request);+ const ipAddress = getClientIpAddress(request.headers);+ // Known once the session is checked; a failure before that (the+ // database is down) is logged and answered the same way, just without it.+ let userId: string | null = null;- if (sessionResult instanceof Response) {- return sessionResult;- }+ try {+ const sessionResult = await requireAdminSession(request);- if ((await getSettings()).hosted) {- return NextResponse.json(- { error: words.hosted },- { headers: noStore, status: 400 },- );- }+ if (sessionResult instanceof Response) {+ return sessionResult;+ }- const actor: WebhookActor = {- email: sessionResult.user.email,- ipAddress: getClientIpAddress(request.headers),- userAgent: getRequestUserAgent(request.headers),- userId: sessionResult.user.id,- };+ userId = sessionResult.user.id;- try {- return await run(actor);+ if ((await getSettings()).hosted) {+ return NextResponse.json(- { error: "Webhooks are for self-hosted installs." },++ { error: words.hosted },+ { headers: noStore, status: 400 },+ );+ }++ return await run({+ email: sessionResult.user.email,+ ipAddress,+ userAgent: getRequestUserAgent(request.headers),+ userId: sessionResult.user.id,+ });} catch (error) {if (error instanceof WebhookEndpointError) {return NextResponse.json(@@@ -67,10 -57,10 +72,10 @@@logRouteError(error, {category,- ipAddress: actor.ipAddress ?? null,+ ipAddress: ipAddress ?? null,- message: "Unexpected failure in a webhook settings request.",+ message: words.failure,path: getRequestPathname(request),- userId: actor.userId,+ userId,});return NextResponse.json(