Skip to content

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

TypeScript

Merge the endpoint review fixes into the webhooks branch

Claude845bee0a977f
diff --cc docs/api.md
index 11049f7,38e4023..5d464ce
--- a/docs/api.md
+++ b/docs/api.md
@@@ -240,24 -243,23 +243,24 @@@ 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 the signer whose turn it is a reminder, at most once a day as in the web app. |
- | `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`, 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 the signer whose turn it is a reminder, at most once a day as in the web app. |
+ | `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's
administrator's documents, can be followed and voided there, and their audit
diff --cc src/lib/api/envelopes.dbtest.ts
index 4804a30,a1c0043..43f6a05
--- a/src/lib/api/envelopes.dbtest.ts
+++ b/src/lib/api/envelopes.dbtest.ts
@@@ -340,10 -343,28 +343,29 @@@ test("the list pages with a cursor, new
);
}
- // Same-second creations still come back in a stable order.
+ // One envelope is older, and three were made in the same second, so the
+ // id must keep their order stable across pages.
+ const [older, ...sameSecond] = ids as [string, ...string[]];
+
+ await database.query(`update envelopes set created_at = $2 where id = $1`, [
+ older,
+ 1_000,
+ ]);
+ await database.query(
+ `update envelopes set created_at = $2 where id = any($1::text[])`,
+ [sameSecond, 2_000],
+ );
+
+ const expected = await database.query<{ id: string }>(
+ `
+ select id from envelopes where id = any($1::text[])
+ order by created_at desc, id desc
+ `,
+ [ids],
+ );
const first = await listApiEnvelopes(actor.userId, { limit: 2 }, database);
+ assert.ok(first);
assert.equal(first.data.length, 2);
assert.ok(first.nextCursor);
@@@ -353,13 -374,13 +375,14 @@@
database,
);
+ assert.ok(second);
- assert.equal(second.data.length, 1);
+ assert.equal(second.data.length, 2);
assert.equal(second.nextCursor, null);
assert.deepEqual(
- new Set([...first.data, ...second.data].map((envelope) => envelope.id)),
- new Set(ids),
+ [...first.data, ...second.data].map((envelope) => envelope.id),
+ expected.rows.map((row) => row.id),
);
+ assert.equal(expected.rows.at(-1)?.id, older);
assert.equal(
(
await listApiEnvelopes(
diff --cc src/lib/api/openapi.ts
index c20517c,46875b3..2ff7bb4
--- a/src/lib/api/openapi.ts
+++ b/src/lib/api/openapi.ts
@@@ -1,9 -1,10 +1,12 @@@
// The OpenAPI 3.1 description of /api/v1, served at /api/v1/openapi.json.
// openapi.test.ts checks that every route file has a path here and every
- // path here has a route file, so the two cannot drift apart.
+ // path here has a route file, so the two cannot drift apart. Lists of
+ // allowed values come from the app's own, so they cannot drift either.
+
+ import { fieldTypes, signatureMeanings } from "../types/domain.ts";
+import { webhookEventTypes } from "../webhooks/events.ts";
+
const errorResponse = {
content: {
"application/json": { schema: { $ref: "#/components/schemas/Error" } },