Skip to content

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

TypeScript

Let the API use signing steps and the install's signer limit

Claude2f5513d3486f
diff --git a/docs/api.md b/docs/api.md
index 38e4023..b580028 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -126,15 +126,21 @@ curl https://sign.example.com/api/v1/envelopes \
```
The answer is the envelope (see [The envelope](#the-envelope)), with status
-`sent`, and the first signer has their invitation email. Leave out `send` to
+`sent`, and the first signer has their invitation email (every signer of the
+first step, when signers share one). Leave out `send` to
make a draft and send it later with `POST /api/v1/envelopes/{id}/send`.
Things to know:
-- **Signers** sign in the order given. Each has a `ref`, your own name for
- them (letters, digits, `.`, `_`, `:` and `-`), which fields use to say whose
- they are and which comes back with the signer. Up to 10 signers, and up to
- 10 `copyRecipients` (`name`, `email`) who get the finished document.
+- **Signers** sign in the order given, one after the other. To have some sign
+ at the same time, give every signer a `step` (1, 2, 3, ...): signers who
+ share a step are invited together, sign in any order, and the next step
+ starts once they all have. Each signer has a `ref`, your own name for them
+ (letters, digits, `.`, `_`, `:` and `-`), which fields use to say whose they
+ are and which comes back with the signer. Up to 25 signers, or as many as
+ the install sets with `MAX_SIGNERS_PER_ENVELOPE` (up to 100; the
+ `maxItems` in `/api/v1/openapi.json` says), and up to 10 `copyRecipients`
+ (`name`, `email`) who get the finished document.
`accessCode` and `requireEmailCode: true` add the same extra checks the web
app offers. On a Part 11 install, give each signer a `signatureMeaning`
(`approval`, `review`, `responsibility` or `authorship`) before sending.
@@ -216,6 +222,7 @@ Every endpoint that returns an envelope returns the same object:
"name": "Casey Client",
"email": "[email protected]",
"order": 1,
+ "step": 1,
"status": "notified",
"viewedAt": null,
"signedAt": null,
@@ -232,8 +239,9 @@ Every endpoint that returns an envelope returns the same object:
envelope past its deadline has `expired: true` until it is voided or the
deadline moves.
- A signer's `status` is `pending` (not their turn yet), `notified` (their
- turn, invited), `signed` or `declined`. `viewedAt` is when they first
- opened it.
+ turn, invited), `signed` or `declined`. `step` is their step of the signing
+ order: signers who share one sign at the same time. `viewedAt` is when they
+ first opened it.
- `files` gives the paths to download once there is something to download:
the signed PDF once the envelope is completed, and the certificate of
completion once it is completed, declined or voided.
@@ -251,7 +259,7 @@ webhooks (coming in the next release).
| `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. |
+| `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. |
| `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. |
diff --git a/src/app/api/v1/envelopes/[id]/remind/route.ts b/src/app/api/v1/envelopes/[id]/remind/route.ts
index c350fca..7152476 100644
--- a/src/app/api/v1/envelopes/[id]/remind/route.ts
+++ b/src/app/api/v1/envelopes/[id]/remind/route.ts
@@ -5,7 +5,7 @@ import { sendManualEnvelopeNudge } from "@/lib/reminders";
type Context = { params: Promise<{ id: string }> };
-// Emails the signer whose turn it is a reminder, under the same limit as
+// Emails a reminder to each signer whose turn it is, under the same limit as
// the reminder button in the web app.
export async function POST(request: Request, context: Context) {
const { id } = await context.params;
diff --git a/src/lib/api/envelopes.dbtest.ts b/src/lib/api/envelopes.dbtest.ts
index a1c0043..5b6f897 100644
--- a/src/lib/api/envelopes.dbtest.ts
+++ b/src/lib/api/envelopes.dbtest.ts
@@ -214,6 +214,81 @@ test("one call creates and sends an envelope, with refs, metadata and the key in
assert.equal(stored.rows[0]?.apiKeyId, actor.apiKeyId);
});
+test("signers given one step are invited together, and each signer shows its step", async () => {
+ const actor = await createActor();
+ const envelope = await createEnvelopeForApi(
+ actor,
+ request({
+ send: { permittedUseConfirmed: true },
+ signers: [
+ {
+ email: "[email protected]",
+ name: "Casey Client",
+ ref: "client",
+ step: 1,
+ },
+ {
+ email: "[email protected]",
+ name: "Wes Witness",
+ ref: "witness",
+ step: 1,
+ },
+ ],
+ }),
+ source(),
+ database,
+ );
+
+ assert.deepEqual(
+ envelope.signers.map((signer) => [signer.ref, signer.step, signer.status]),
+ [
+ ["client", 1, "notified"],
+ ["witness", 1, "notified"],
+ ],
+ );
+
+ // Without steps, each signer has a step of their own.
+ const plain = await createEnvelopeForApi(
+ actor,
+ request(),
+ source(),
+ database,
+ );
+
+ assert.deepEqual(
+ plain.signers.map((signer) => signer.step),
+ [1, 2],
+ );
+
+ // Steps go to every signer or to none, as in the web app.
+ await assert.rejects(
+ createEnvelopeForApi(
+ actor,
+ request({
+ signers: [
+ {
+ email: "[email protected]",
+ name: "Casey Client",
+ ref: "client",
+ step: 1,
+ },
+ {
+ email: "[email protected]",
+ name: "Wes Witness",
+ ref: "witness",
+ },
+ ],
+ }),
+ source(),
+ database,
+ ),
+ (error: unknown) =>
+ error instanceof EnvelopeMutationError &&
+ error.statusCode === 400 &&
+ /every signer a step/.test(error.message),
+ );
+});
+
test("a create that cannot be finished leaves no draft behind", async () => {
const actor = await createActor();
const countDrafts = async () =>
diff --git a/src/lib/api/envelopes.ts b/src/lib/api/envelopes.ts
index 0cd67f3..6f04f7a 100644
--- a/src/lib/api/envelopes.ts
+++ b/src/lib/api/envelopes.ts
@@ -25,6 +25,7 @@ import {
reminderIntervalDaysSchema,
} from "../schemas/envelope.ts";
import { fieldTypeSchema } from "../schemas/field.ts";
+import { signingStepOf } from "../signing-steps.ts";
import {
MAX_COPY_RECIPIENTS_PER_ENVELOPE,
MAX_SIGNERS_CEILING,
@@ -53,6 +54,8 @@ export type ApiSigner = {
ref: string | null;
signedAt: string | null;
status: SignerStatus;
+ /** Signers who share a step sign at the same time. */
+ step: number;
viewedAt: string | null;
};
@@ -120,6 +123,10 @@ const apiSignerSchema = z.object({
ref: refSchema,
requireEmailCode: z.boolean().optional(),
signatureMeaning: z.enum(signatureMeanings).optional(),
+ // The step of the signing order, as in the web app: signers who share a
+ // step sign at the same time. Given for every signer or for none; left
+ // out, they sign one after the other in the order of the list.
+ step: z.number().int().positive().max(MAX_SIGNERS_CEILING).optional(),
});
const apiFieldSchema = z.object({
@@ -268,6 +275,7 @@ export async function createEnvelopeForApi(
name: signer.name,
requireEmailCode: signer.requireEmailCode,
signatureMeaning: signer.signatureMeaning,
+ signingStep: signer.step,
signOrder: index + 1,
})),
},
@@ -385,6 +393,7 @@ type SignerRow = {
name: string;
role: "cc" | "signer";
signedAt: number | null;
+ signingStep: number | null;
signOrder: number;
status: SignerStatus;
viewedAt: number | null;
@@ -427,6 +436,7 @@ async function readSigners(
s.email,
s.role,
s.sign_order AS "signOrder",
+ s.signing_step AS "signingStep",
s.status,
s.signed_at AS "signedAt",
s.declined_at AS "declinedAt",
@@ -505,6 +515,7 @@ export function toApiEnvelope(
ref: signer.apiRef,
signedAt: isoTime(signer.signedAt),
status: signer.status,
+ step: signingStepOf(signer),
viewedAt: isoTime(signer.viewedAt),
})),
status: row.status,
diff --git a/src/lib/api/openapi.test.ts b/src/lib/api/openapi.test.ts
index 5a042e2..50fc54f 100644
--- a/src/lib/api/openapi.test.ts
+++ b/src/lib/api/openapi.test.ts
@@ -75,3 +75,17 @@ test("the OpenAPI description allows the values the API accepts", () => {
);
assert.deepEqual(fromTemplate.signatureMeaning.enum, [...signatureMeanings]);
});
+
+test("the OpenAPI description gives this install's signer limit", () => {
+ const document = buildOpenApiDocument("https://sign.example.com/api/v1", 40);
+ const fromTemplate =
+ document.paths["/templates/{id}/envelopes"].post.requestBody.content[
+ "application/json"
+ ].schema.properties.signers;
+
+ assert.equal(
+ document.components.schemas.CreateEnvelope.properties.signers.maxItems,
+ 40,
+ );
+ assert.equal(fromTemplate.maxItems, 40);
+});
diff --git a/src/lib/api/openapi.ts b/src/lib/api/openapi.ts
index cb0c961..6390368 100644
--- a/src/lib/api/openapi.ts
+++ b/src/lib/api/openapi.ts
@@ -3,6 +3,7 @@
// 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 { getMaxSignersPerEnvelope } from "../signer-limit.ts";
import { fieldTypes, signatureMeanings } from "../types/domain.ts";
const errorResponse = {
@@ -65,7 +66,14 @@ const listOf = (item: Record<string, unknown>) => ({
type: "object",
});
-export function buildOpenApiDocument(serverUrl: string) {
+/**
+ * maxSigners is this install's limit, MAX_SIGNERS_PER_ENVELOPE, so the
+ * description says what this install accepts.
+ */
+export function buildOpenApiDocument(
+ serverUrl: string,
+ maxSigners: number = getMaxSignersPerEnvelope(),
+) {
return {
components: {
schemas: {
@@ -116,11 +124,17 @@ export function buildOpenApiDocument(serverUrl: string) {
enum: [...signatureMeanings],
type: "string",
},
+ step: {
+ description:
+ "The step of the signing order. Signers who share a step sign at the same time, and the next step starts once they all have. Give it for every signer or for none; left out, they sign one after the other.",
+ minimum: 1,
+ type: "integer",
+ },
},
required: ["ref", "name", "email"],
type: "object",
},
- maxItems: 10,
+ maxItems: maxSigners,
minItems: 1,
type: "array",
},
@@ -271,6 +285,11 @@ export function buildOpenApiDocument(serverUrl: string) {
enum: ["pending", "notified", "signed", "declined"],
type: "string",
},
+ step: {
+ description:
+ "Their step of the signing order. Signers who share a step sign at the same time.",
+ type: "integer",
+ },
viewedAt: isoTime,
},
type: "object",
@@ -498,7 +517,7 @@ export function buildOpenApiDocument(serverUrl: string) {
post: {
parameters: [idParameter],
responses: { "200": envelopeResponse("The envelope."), ...errors },
- summary: "Remind the signer whose turn it is",
+ summary: "Remind each signer whose turn it is",
},
},
"/envelopes/{id}/send": {
@@ -630,7 +649,7 @@ export function buildOpenApiDocument(serverUrl: string) {
required: ["name", "email"],
type: "object",
},
- maxItems: 10,
+ maxItems: maxSigners,
minItems: 1,
type: "array",
},