@assinafy/sdk 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -12
- package/dist/index.d.mts +209 -35
- package/dist/index.d.ts +209 -35
- package/dist/index.js +229 -74
- package/dist/index.mjs +228 -74
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Provides 100% endpoint coverage of the public API: documents, signers, assignmen
|
|
|
6
6
|
|
|
7
7
|
## Requirements
|
|
8
8
|
|
|
9
|
-
- Node.js
|
|
9
|
+
- Node.js 20+ (current LTS) for the built-in `FormData` / `Blob` APIs used by uploads
|
|
10
10
|
- or Bun 1.0+
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
@@ -66,11 +66,19 @@ new AssinafyClient({ token: 'jwt_xxx', accountId: 'acc_xxx' });
|
|
|
66
66
|
| `apiKey` | string | — | Preferred credential (sent as `X-Api-Key`). |
|
|
67
67
|
| `token` | string | — | Legacy access token (sent as `Bearer`). |
|
|
68
68
|
| `accountId` | string | — | Default workspace/account ID. |
|
|
69
|
-
| `baseUrl` | string | `https://api.assinafy.com.br/v1` | Override base URL.
|
|
69
|
+
| `baseUrl` | string | `https://api.assinafy.com.br/v1` | Override base URL (e.g. the sandbox). |
|
|
70
70
|
| `webhookSecret` | string | — | Shared secret used by `WebhookVerifier`. |
|
|
71
71
|
| `timeout` | number | `30000` | Request timeout in milliseconds. |
|
|
72
|
+
| `maxRetries` | number | `2` | Auto-retries on HTTP 429, honoring `Retry-After`. `0` disables. |
|
|
72
73
|
| `logger` | `Logger` | no-op | Optional `{debug,info,warn,error}` logger. |
|
|
73
74
|
|
|
75
|
+
### Rate limiting
|
|
76
|
+
|
|
77
|
+
The API allows ~120 requests/minute and returns `X-Rate-Limit-*` headers. On an
|
|
78
|
+
HTTP `429`, the client automatically retries up to `maxRetries` times, waiting
|
|
79
|
+
for the server-provided `Retry-After` (or `X-Rate-Limit-Reset`) delay before
|
|
80
|
+
each attempt. Only `429` is retried, so non-idempotent calls are safe.
|
|
81
|
+
|
|
74
82
|
### Factories
|
|
75
83
|
|
|
76
84
|
```ts
|
|
@@ -92,8 +100,8 @@ Every public endpoint documented in https://api.assinafy.com.br/v1/docs is cover
|
|
|
92
100
|
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
93
101
|
| `client.documents` | list, upload, details, activities, waitUntilReady, download, thumbnail, downloadPage, statuses, delete, verify, createFromTemplate, estimateCostFromTemplate, **getPublic**, **sendToken**, **listTags**, **replaceTags**, **addTags**, **detachTag**, isFullySigned, getSigningProgress |
|
|
94
102
|
| `client.signers` | create, get, list, update, delete, findByEmail |
|
|
95
|
-
| `client.assignments` | create, estimateCost, resetExpiration, resendNotification, estimateResendCost, listWhatsAppNotifications
|
|
96
|
-
| `client.templates` | list, get, downloadPage
|
|
103
|
+
| `client.assignments` | create, estimateCost, resetExpiration, resendNotification, estimateResendCost, listWhatsAppNotifications |
|
|
104
|
+
| `client.templates` | **create**, list, get, **update**, **delete**, downloadPage |
|
|
97
105
|
| `client.tags` | list, create, update, delete |
|
|
98
106
|
| `client.workspaces` | create, list, get, update, delete |
|
|
99
107
|
| `client.webhooks` | register, get, inactivate, delete, listEventTypes, listDispatches, retryDispatch |
|
|
@@ -114,10 +122,19 @@ const doc = await client.documents.upload(
|
|
|
114
122
|
{ filePath: './contract.pdf' },
|
|
115
123
|
{ metadata: { type: 'service' } },
|
|
116
124
|
);
|
|
125
|
+
// → {
|
|
126
|
+
// resource: 'document', id: '1031…', account_id: '102d…', template_id: null,
|
|
127
|
+
// name: 'contract.pdf', status: 'uploaded',
|
|
128
|
+
// artifacts: { original: 'https://…/download/original' },
|
|
129
|
+
// signing_url: 'https://app…/sign/1031…',
|
|
130
|
+
// pages: [], // populated once status reaches `metadata_ready`
|
|
131
|
+
// tags: [], is_closed: false, created_at: '2026-…', updated_at: '2026-…'
|
|
132
|
+
// }
|
|
117
133
|
|
|
118
134
|
// …or from a Buffer already in memory
|
|
119
135
|
await client.documents.upload({ buffer, fileName: 'contract.pdf' });
|
|
120
136
|
|
|
137
|
+
// List → { data: IDocumentListItem[], meta?: { current_page, per_page, total, last_page } }
|
|
121
138
|
const { data, meta } = await client.documents.list({ page: 1, per_page: 20, sort: '-created_at' });
|
|
122
139
|
await client.documents.details(doc.id);
|
|
123
140
|
await client.documents.activities(doc.id);
|
|
@@ -159,6 +176,9 @@ await client.signers.create({
|
|
|
159
176
|
whatsapp_phone_number: '+5548999990000',
|
|
160
177
|
cpf: '123.456.789-00', // optional Brazilian tax ID — non-digits are stripped automatically
|
|
161
178
|
});
|
|
179
|
+
// → { id: '19e6…', full_name: 'John Doe', email: 'john@example.com',
|
|
180
|
+
// whatsapp_phone_number: '+5548999990000', has_accepted_terms: false }
|
|
181
|
+
// (note: `cpf` is accepted on input but never echoed back by the API)
|
|
162
182
|
|
|
163
183
|
// `email` is optional — a WhatsApp-only signer is valid (at least one is required)
|
|
164
184
|
await client.signers.create({
|
|
@@ -204,40 +224,80 @@ await client.assignments.create(documentId, {
|
|
|
204
224
|
],
|
|
205
225
|
});
|
|
206
226
|
|
|
207
|
-
// Estimate cost (signers may omit `id` when only the channel matters)
|
|
227
|
+
// Estimate cost (signers may omit `id` when only the channel matters) → ICostEstimate
|
|
208
228
|
await client.assignments.estimateCost(documentId, { signers: ['signer-1'] });
|
|
209
229
|
await client.assignments.estimateCost(documentId, {
|
|
210
230
|
signers: [{ verification_method: 'Whatsapp' }],
|
|
211
231
|
});
|
|
232
|
+
// → {
|
|
233
|
+
// documents: 1, credits: 0, needs_extra_document: false, extra_document_cost: 0,
|
|
234
|
+
// total_credits: 0, breakdown: [], document_balance: 67, credit_balance: 0,
|
|
235
|
+
// has_sufficient_resources: true, blocking_reason: null, message: null
|
|
236
|
+
// }
|
|
212
237
|
|
|
213
238
|
await client.assignments.resetExpiration(documentId, assignmentId, '2025-06-30T00:00:00Z');
|
|
214
239
|
await client.assignments.resetExpiration(documentId, assignmentId, null); // remove expiration
|
|
240
|
+
|
|
215
241
|
await client.assignments.resendNotification(documentId, assignmentId, signerId);
|
|
242
|
+
// → { is_sent: true, document_id: '…', signer_id: '…' }
|
|
243
|
+
|
|
216
244
|
await client.assignments.estimateResendCost(documentId, assignmentId, signerId);
|
|
217
|
-
|
|
218
|
-
|
|
245
|
+
// → { total: 0, breakdown: [{ code: 'NotificationEmailResend', name: '…', cost: 0 }],
|
|
246
|
+
// credit_balance: 0, has_sufficient_credits: true }
|
|
247
|
+
|
|
248
|
+
await client.assignments.listWhatsAppNotifications(documentId, assignmentId); // → IWhatsAppNotification[]
|
|
219
249
|
```
|
|
220
250
|
|
|
251
|
+
The `create` response is an `IAssignment`: `{ id, method, signers: [...], items: [...], signing_urls: [{ signer_id, url }], … }`.
|
|
252
|
+
|
|
221
253
|
For backwards compatibility, the SDK also accepts legacy `signer_ids` and `signerIds` payloads and rewrites them to the current `signers: [{ id }]` format expected by the API.
|
|
222
254
|
|
|
255
|
+
**Cancelling a signature request.** Assinafy has no workspace-side "cancel" endpoint. To stop a pending request either delete the document (when its status is deletable) or have the signer decline:
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
await client.documents.delete(documentId); // workspace-side
|
|
259
|
+
await client.signerDocuments.decline(documentId, assignmentId, accessCode, 'No longer needed'); // signer-side
|
|
260
|
+
```
|
|
261
|
+
|
|
223
262
|
### Templates
|
|
224
263
|
|
|
225
264
|
```ts
|
|
265
|
+
// Create a template by uploading a PDF (multipart). The template starts in
|
|
266
|
+
// `Uploaded` status and becomes `Ready` once its pages are processed.
|
|
267
|
+
const created = await client.templates.create(
|
|
268
|
+
{ filePath: './nda.pdf' }, // or { buffer, fileName: 'nda.pdf' }
|
|
269
|
+
{ name: 'NDA template' },
|
|
270
|
+
);
|
|
271
|
+
// →
|
|
272
|
+
// {
|
|
273
|
+
// resource: 'template', id: '1032...', name: 'nda.pdf',
|
|
274
|
+
// document_name: 'nda.pdf', message: null, status: 'Uploaded',
|
|
275
|
+
// roles: [{ id: '1032...', name: 'TemplateEditor', assignment_type: 'Editor' }],
|
|
276
|
+
// pages: [], tags: [], created_at: '2026-…', updated_at: '2026-…'
|
|
277
|
+
// }
|
|
278
|
+
|
|
226
279
|
const { data, meta } = await client.templates.list({ search: 'NDA', per_page: 20 });
|
|
227
|
-
const template = await client.templates.get(
|
|
228
|
-
await client.templates.
|
|
280
|
+
const template = await client.templates.get(created.id); // includes pages[] + default_document_tags
|
|
281
|
+
await client.templates.update(created.id, { name: 'NDA v2', message: 'Please sign' });
|
|
282
|
+
await client.templates.downloadPage(created.id, template.pages![0].id); // → Buffer (JPEG)
|
|
283
|
+
await client.templates.delete(created.id);
|
|
229
284
|
|
|
230
|
-
// Create a document from a template (each signer maps to a template role)
|
|
285
|
+
// Create a *document* from a template (each signer maps to a template role)
|
|
231
286
|
await client.documents.createFromTemplate(
|
|
232
287
|
templateId,
|
|
233
288
|
[{ role_id: template.roles![0].id, id: signerId, verification_method: 'Email', notification_methods: ['Email'] }],
|
|
234
289
|
{ name: 'NDA - John Doe', message: 'Please sign at your earliest convenience.' },
|
|
235
290
|
);
|
|
236
291
|
|
|
237
|
-
// Estimate the cost before creating
|
|
292
|
+
// Estimate the cost before creating → ICostEstimate
|
|
238
293
|
await client.documents.estimateCostFromTemplate(templateId, [{ role_id: 'role_id', id: signerId }]);
|
|
294
|
+
// → { documents: 1, total_credits: 0, document_balance: 67, credit_balance: 0,
|
|
295
|
+
// has_sufficient_resources: true, blocking_reason: null, breakdown: [], … }
|
|
239
296
|
```
|
|
240
297
|
|
|
298
|
+
Template creation only uploads the PDF and provisions the default editor role —
|
|
299
|
+
configure roles/fields in the Assinafy editor (or the web UI) afterwards.
|
|
300
|
+
|
|
241
301
|
### Tags
|
|
242
302
|
|
|
243
303
|
Workspace-scoped labels that can be attached to documents and templates. Tag names are unique per workspace (case-insensitive).
|
|
@@ -448,9 +508,12 @@ A real-network test script under [`scripts/live-smoke.ts`](scripts/live-smoke.ts
|
|
|
448
508
|
```bash
|
|
449
509
|
ASSINAFY_API_KEY=… ASSINAFY_ACCOUNT_ID=… bun scripts/live-smoke.ts # read-only
|
|
450
510
|
ASSINAFY_API_KEY=… ASSINAFY_ACCOUNT_ID=… bun scripts/live-smoke.ts --write # also creates+deletes a signer
|
|
451
|
-
ASSINAFY_API_KEY=… ASSINAFY_ACCOUNT_ID=… bun scripts/live-smoke.ts --upload # also uploads+
|
|
511
|
+
ASSINAFY_API_KEY=… ASSINAFY_ACCOUNT_ID=… bun scripts/live-smoke.ts --upload # also uploads a PDF + a template, then deletes both
|
|
452
512
|
```
|
|
453
513
|
|
|
514
|
+
Set `ASSINAFY_BASE_URL=https://sandbox.assinafy.com.br/v1` to run it against the
|
|
515
|
+
sandbox instead of production.
|
|
516
|
+
|
|
454
517
|
## Development
|
|
455
518
|
|
|
456
519
|
```bash
|
package/dist/index.d.mts
CHANGED
|
@@ -34,6 +34,11 @@ interface AssinafyClientOptions {
|
|
|
34
34
|
webhookSecret?: string;
|
|
35
35
|
/** Request timeout in milliseconds. Defaults to 30_000. */
|
|
36
36
|
timeout?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Max automatic retries on HTTP 429 (rate limit), honoring `Retry-After`.
|
|
39
|
+
* Defaults to `2`. Set to `0` to disable retrying.
|
|
40
|
+
*/
|
|
41
|
+
maxRetries?: number;
|
|
37
42
|
/** Optional logger. Defaults to a no-op logger. */
|
|
38
43
|
logger?: Logger;
|
|
39
44
|
}
|
|
@@ -70,6 +75,10 @@ interface ISigner {
|
|
|
70
75
|
full_name: string;
|
|
71
76
|
email: string | null;
|
|
72
77
|
whatsapp_phone_number?: string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Accepted on create/update payloads but **never echoed back** on any signer
|
|
80
|
+
* response — present here only so response objects stay assignable from inputs.
|
|
81
|
+
*/
|
|
73
82
|
cpf?: string | null;
|
|
74
83
|
has_accepted_terms?: boolean;
|
|
75
84
|
/** Only returned by `GET /signers/self`. */
|
|
@@ -131,23 +140,56 @@ interface ICreateAssignmentPayload {
|
|
|
131
140
|
/** Field placement entries used when `method` is `collect`. */
|
|
132
141
|
entries?: unknown[];
|
|
133
142
|
}
|
|
143
|
+
/** A signer as embedded inside an assignment (richer than the bare {@link ISigner}). */
|
|
144
|
+
interface IAssignmentSigner extends ISigner {
|
|
145
|
+
completed: boolean;
|
|
146
|
+
notification_history: unknown[];
|
|
147
|
+
verification_method: AssignmentVerificationMethod;
|
|
148
|
+
notification_methods: AssignmentNotificationMethod[];
|
|
149
|
+
/** 1-based signing order. See {@link SignerReference.step}. */
|
|
150
|
+
step: number;
|
|
151
|
+
notified: boolean;
|
|
152
|
+
}
|
|
153
|
+
/** A placed field/item within an assignment (one row per signer × field). */
|
|
154
|
+
interface IAssignmentItem {
|
|
155
|
+
id: string;
|
|
156
|
+
page: {
|
|
157
|
+
id: string;
|
|
158
|
+
number: number;
|
|
159
|
+
height: number;
|
|
160
|
+
width: number;
|
|
161
|
+
download_url: string;
|
|
162
|
+
} | null;
|
|
163
|
+
signer: ISigner;
|
|
164
|
+
field: IFieldDefinition;
|
|
165
|
+
value: string | null;
|
|
166
|
+
completed?: boolean;
|
|
167
|
+
[key: string]: unknown;
|
|
168
|
+
}
|
|
134
169
|
/** Assignment object as returned by the API. */
|
|
135
170
|
interface IAssignment {
|
|
171
|
+
resource?: string;
|
|
136
172
|
id: string;
|
|
137
173
|
sender_email?: string;
|
|
138
174
|
method: AssignmentMethod;
|
|
139
|
-
expires_at?: string;
|
|
175
|
+
expires_at?: string | null;
|
|
140
176
|
expiration?: string;
|
|
141
177
|
message?: string;
|
|
142
|
-
signers:
|
|
178
|
+
signers: IAssignmentSigner[];
|
|
143
179
|
copy_receivers?: string[];
|
|
144
|
-
items?:
|
|
180
|
+
items?: IAssignmentItem[];
|
|
145
181
|
summary?: {
|
|
146
182
|
signer_count: number;
|
|
147
183
|
completed_count: number;
|
|
148
|
-
signers:
|
|
184
|
+
signers: Array<ISigner & {
|
|
185
|
+
completed?: boolean;
|
|
186
|
+
}>;
|
|
149
187
|
};
|
|
150
|
-
|
|
188
|
+
/** Per-signer signing URLs. Array of `{ signer_id, url }` (not a map). */
|
|
189
|
+
signing_urls?: Array<{
|
|
190
|
+
signer_id: string;
|
|
191
|
+
url: string;
|
|
192
|
+
}>;
|
|
151
193
|
}
|
|
152
194
|
type ICreateAssignmentResponse = IAssignment;
|
|
153
195
|
interface IResendEmailResponse {
|
|
@@ -155,6 +197,41 @@ interface IResendEmailResponse {
|
|
|
155
197
|
document_id?: string;
|
|
156
198
|
signer_id?: string;
|
|
157
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Credit/document cost estimate returned by `assignments.estimateCost` and
|
|
202
|
+
* `documents.estimateCostFromTemplate`.
|
|
203
|
+
*/
|
|
204
|
+
interface ICostEstimate {
|
|
205
|
+
documents: number;
|
|
206
|
+
credits: number;
|
|
207
|
+
needs_extra_document: boolean;
|
|
208
|
+
extra_document_cost: number;
|
|
209
|
+
total_credits: number;
|
|
210
|
+
breakdown: Array<{
|
|
211
|
+
code: string;
|
|
212
|
+
name: string;
|
|
213
|
+
cost: number;
|
|
214
|
+
quantity?: number;
|
|
215
|
+
unit_cost?: number;
|
|
216
|
+
}>;
|
|
217
|
+
document_balance: number;
|
|
218
|
+
credit_balance: number;
|
|
219
|
+
has_sufficient_resources: boolean;
|
|
220
|
+
/** `null` when the operation can proceed; otherwise a reason code. */
|
|
221
|
+
blocking_reason: string | null;
|
|
222
|
+
message: string | null;
|
|
223
|
+
}
|
|
224
|
+
/** Cost estimate returned by `assignments.estimateResendCost`. */
|
|
225
|
+
interface IResendCostEstimate {
|
|
226
|
+
total: number;
|
|
227
|
+
breakdown: Array<{
|
|
228
|
+
code: string;
|
|
229
|
+
name: string;
|
|
230
|
+
cost: number;
|
|
231
|
+
}>;
|
|
232
|
+
credit_balance: number;
|
|
233
|
+
has_sufficient_credits: boolean;
|
|
234
|
+
}
|
|
158
235
|
/** Webhook payload envelope. */
|
|
159
236
|
interface IWebhookPayload {
|
|
160
237
|
id?: number;
|
|
@@ -182,6 +259,14 @@ interface IDocumentListItem {
|
|
|
182
259
|
status: DocumentStatus;
|
|
183
260
|
account_id?: string;
|
|
184
261
|
template_id?: string | null;
|
|
262
|
+
/** Artifact download URLs keyed by name (`original`, `thumbnail`, …). */
|
|
263
|
+
artifacts?: IDocumentUploadResponse['artifacts'];
|
|
264
|
+
/** Public signing-portal URL for the document. */
|
|
265
|
+
signing_url?: string;
|
|
266
|
+
pages?: IDocumentUploadResponse['pages'];
|
|
267
|
+
assignment?: IAssignment | null;
|
|
268
|
+
decline_reason?: string | null;
|
|
269
|
+
declined_by?: ISigner | null;
|
|
185
270
|
/** Tags attached to the document (inline `{ id, name, color }` shape). */
|
|
186
271
|
tags?: IInlineTag[];
|
|
187
272
|
created_at: string;
|
|
@@ -206,7 +291,8 @@ interface IDocumentUploadResponse {
|
|
|
206
291
|
template_id: string | null;
|
|
207
292
|
name: string;
|
|
208
293
|
status: DocumentStatus;
|
|
209
|
-
|
|
294
|
+
/** Absent on a fresh upload; an {@link IAssignment} (or `null`) once one exists. */
|
|
295
|
+
assignment?: IAssignment | null;
|
|
210
296
|
artifacts: {
|
|
211
297
|
original: string;
|
|
212
298
|
certificated?: string;
|
|
@@ -214,6 +300,7 @@ interface IDocumentUploadResponse {
|
|
|
214
300
|
bundle?: string;
|
|
215
301
|
thumbnail?: string;
|
|
216
302
|
};
|
|
303
|
+
/** Empty (`[]`) on fresh upload (status `uploaded`); populated once `metadata_ready`. */
|
|
217
304
|
pages: Array<{
|
|
218
305
|
id: string;
|
|
219
306
|
number: number;
|
|
@@ -234,6 +321,7 @@ interface IDocumentDetailsResponse {
|
|
|
234
321
|
resource?: string;
|
|
235
322
|
id: string;
|
|
236
323
|
account_id: string;
|
|
324
|
+
template_id?: string | null;
|
|
237
325
|
name: string;
|
|
238
326
|
status: DocumentStatus;
|
|
239
327
|
assignment: IAssignment | null;
|
|
@@ -253,7 +341,7 @@ interface IDocumentDetailsResponse {
|
|
|
253
341
|
created_at: string;
|
|
254
342
|
updated_at: string;
|
|
255
343
|
is_closed: boolean;
|
|
256
|
-
decline_reason?: string;
|
|
344
|
+
decline_reason?: string | null;
|
|
257
345
|
declined_by?: ISigner | null;
|
|
258
346
|
activities?: Array<IDocumentActivity>;
|
|
259
347
|
}
|
|
@@ -300,8 +388,8 @@ interface IUpdateWorkspacePayload {
|
|
|
300
388
|
interface IWorkspaceResponse {
|
|
301
389
|
id: string;
|
|
302
390
|
name: string;
|
|
303
|
-
primary_color?: string;
|
|
304
|
-
secondary_color?: string;
|
|
391
|
+
primary_color?: string | null;
|
|
392
|
+
secondary_color?: string | null;
|
|
305
393
|
created_at: string;
|
|
306
394
|
}
|
|
307
395
|
interface IWorkspaceListItem {
|
|
@@ -319,13 +407,16 @@ interface IWebhookRegisterPayload {
|
|
|
319
407
|
events?: WebhookEventType[] | string[];
|
|
320
408
|
is_active?: boolean;
|
|
321
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Webhook subscription as returned by the API. There is exactly one
|
|
412
|
+
* subscription per workspace, keyed by URL — the API returns
|
|
413
|
+
* `{ events, is_active, url, email, updated_at }` (no `id` / `created_at`).
|
|
414
|
+
*/
|
|
322
415
|
interface IWebhookSubscription {
|
|
323
|
-
id?: string;
|
|
324
416
|
url: string;
|
|
325
417
|
email: string;
|
|
326
418
|
events: string[];
|
|
327
419
|
is_active: boolean;
|
|
328
|
-
created_at?: string;
|
|
329
420
|
updated_at?: string;
|
|
330
421
|
}
|
|
331
422
|
interface IWebhookEventTypeInfo {
|
|
@@ -372,8 +463,18 @@ interface IUploadAndRequestSignaturesSigner {
|
|
|
372
463
|
interface ITemplateRole {
|
|
373
464
|
id: string;
|
|
374
465
|
name: string;
|
|
466
|
+
/** Role kind, e.g. `Editor` or `Signer`. */
|
|
467
|
+
assignment_type?: string;
|
|
468
|
+
created_at?: string;
|
|
469
|
+
updated_at?: string;
|
|
375
470
|
[key: string]: unknown;
|
|
376
471
|
}
|
|
472
|
+
/** Payload for `PUT /accounts/{id}/templates/{template_id}`. Omit a field to leave it unchanged. */
|
|
473
|
+
interface IUpdateTemplatePayload {
|
|
474
|
+
name?: string;
|
|
475
|
+
/** Default invitation message applied to documents created from the template. */
|
|
476
|
+
message?: string;
|
|
477
|
+
}
|
|
377
478
|
/** Template list item (paginated). */
|
|
378
479
|
interface ITemplateListItem {
|
|
379
480
|
resource?: string;
|
|
@@ -613,7 +714,7 @@ declare abstract class BaseResource {
|
|
|
613
714
|
}
|
|
614
715
|
type RequestFn = () => Promise<AxiosResponse>;
|
|
615
716
|
|
|
616
|
-
/** Input for
|
|
717
|
+
/** Input for an upload: either an on-disk file or an in-memory buffer. */
|
|
617
718
|
type DocumentUploadSource = {
|
|
618
719
|
filePath: string;
|
|
619
720
|
fileName?: string;
|
|
@@ -621,6 +722,7 @@ type DocumentUploadSource = {
|
|
|
621
722
|
buffer: Buffer;
|
|
622
723
|
fileName: string;
|
|
623
724
|
};
|
|
725
|
+
|
|
624
726
|
interface IDocumentUploadOptions {
|
|
625
727
|
/** Optional metadata sent alongside the file (JSON-encoded). */
|
|
626
728
|
metadata?: Record<string, unknown>;
|
|
@@ -684,8 +786,13 @@ declare class DocumentResource extends BaseResource {
|
|
|
684
786
|
* ```
|
|
685
787
|
*/
|
|
686
788
|
createFromTemplate(templateId: string, signers: ITemplateSigner[], options?: ICreateDocumentFromTemplateOptions, accountId?: string): Promise<IDocumentDetailsResponse>;
|
|
687
|
-
/**
|
|
688
|
-
|
|
789
|
+
/**
|
|
790
|
+
* Estimate the credit cost of creating a document from a template.
|
|
791
|
+
*
|
|
792
|
+
* @returns an {@link ICostEstimate}: `total_credits`, balances, and a
|
|
793
|
+
* per-line `breakdown` of what the operation would consume.
|
|
794
|
+
*/
|
|
795
|
+
estimateCostFromTemplate(templateId: string, signers: ITemplateSigner[], accountId?: string): Promise<ICostEstimate>;
|
|
689
796
|
/** Verify a document by its signature hash. */
|
|
690
797
|
verify(hash: string): Promise<Record<string, unknown>>;
|
|
691
798
|
/**
|
|
@@ -756,8 +863,16 @@ declare function buildAssignmentPayload(payload: ICreateAssignmentPayload, optio
|
|
|
756
863
|
declare class AssignmentResource extends BaseResource {
|
|
757
864
|
/** Create a signing assignment for a document. */
|
|
758
865
|
create(documentId: string, payload: ICreateAssignmentPayload): Promise<ICreateAssignmentResponse>;
|
|
759
|
-
/**
|
|
760
|
-
|
|
866
|
+
/**
|
|
867
|
+
* Estimate the cost (in credits/documents) of creating the assignment.
|
|
868
|
+
*
|
|
869
|
+
* Signer entries may omit `id` and supply only `verification_method` /
|
|
870
|
+
* `notification_methods` when only the channel mix matters for the estimate.
|
|
871
|
+
*
|
|
872
|
+
* @returns an {@link ICostEstimate} with `total_credits`, balances, and a
|
|
873
|
+
* line-item `breakdown`.
|
|
874
|
+
*/
|
|
875
|
+
estimateCost(documentId: string, payload: ICreateAssignmentPayload): Promise<ICostEstimate>;
|
|
761
876
|
/**
|
|
762
877
|
* Update the expiration date of an existing assignment.
|
|
763
878
|
* Pass `null` to remove the expiration entirely.
|
|
@@ -765,22 +880,40 @@ declare class AssignmentResource extends BaseResource {
|
|
|
765
880
|
resetExpiration(documentId: string, assignmentId: string, expiresAt: string | null): Promise<IAssignment>;
|
|
766
881
|
/** Resend the signing notification to a single signer. */
|
|
767
882
|
resendNotification(documentId: string, assignmentId: string, signerId: string): Promise<IResendEmailResponse>;
|
|
768
|
-
/**
|
|
769
|
-
|
|
883
|
+
/**
|
|
884
|
+
* Estimate the cost of resending a signer notification.
|
|
885
|
+
*
|
|
886
|
+
* @returns an {@link IResendCostEstimate} (`total`, `breakdown`, balances).
|
|
887
|
+
*/
|
|
888
|
+
estimateResendCost(documentId: string, assignmentId: string, signerId: string): Promise<IResendCostEstimate>;
|
|
770
889
|
/**
|
|
771
890
|
* `GET /documents/{documentId}/assignments/{assignmentId}/whatsapp-notifications`
|
|
772
891
|
* — list every WhatsApp notification rendered + sent for an assignment.
|
|
773
892
|
*/
|
|
774
893
|
listWhatsAppNotifications(documentId: string, assignmentId: string): Promise<IWhatsAppNotification[]>;
|
|
775
|
-
/**
|
|
776
|
-
* Cancel a signature request. This endpoint is not listed in the public
|
|
777
|
-
* Swagger but is exposed by the platform.
|
|
778
|
-
*/
|
|
779
|
-
cancel(documentId: string, reason: string, accountId?: string): Promise<unknown>;
|
|
780
894
|
}
|
|
781
895
|
|
|
896
|
+
/**
|
|
897
|
+
* Default webhook events applied by {@link WebhookResource.register} when the
|
|
898
|
+
* caller omits `events` (or passes an empty array).
|
|
899
|
+
*/
|
|
900
|
+
declare const DEFAULT_WEBHOOK_EVENTS: WebhookEventType[];
|
|
782
901
|
declare class WebhookResource extends BaseResource {
|
|
783
|
-
/**
|
|
902
|
+
/**
|
|
903
|
+
* Register (or replace) the workspace's single webhook subscription
|
|
904
|
+
* (`PUT /accounts/{id}/webhooks/subscriptions`). There is exactly one
|
|
905
|
+
* subscription per workspace, keyed by URL.
|
|
906
|
+
*
|
|
907
|
+
* When `events` is omitted or empty, {@link DEFAULT_WEBHOOK_EVENTS} is used
|
|
908
|
+
* (`document_ready`, `document_prepared`, `signer_signed_document`,
|
|
909
|
+
* `signer_rejected_document`, `document_processing_failed`).
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* await client.webhooks.register({ url: 'https://example.com/hook', email: 'ops@example.com' });
|
|
914
|
+
* // → { url, email, events: [...], is_active: true, updated_at: '2026-…' }
|
|
915
|
+
* ```
|
|
916
|
+
*/
|
|
784
917
|
register(payload: IWebhookRegisterPayload, accountId?: string): Promise<IWebhookSubscription>;
|
|
785
918
|
/** Fetch the current webhook subscription. Returns `null` if none exists. */
|
|
786
919
|
get(accountId?: string): Promise<IWebhookSubscription | null>;
|
|
@@ -797,20 +930,55 @@ declare class WebhookResource extends BaseResource {
|
|
|
797
930
|
}
|
|
798
931
|
|
|
799
932
|
declare class TemplateResource extends BaseResource {
|
|
933
|
+
/**
|
|
934
|
+
* Create a template by uploading a PDF (`POST /accounts/{id}/templates`).
|
|
935
|
+
*
|
|
936
|
+
* The template is created in `Uploaded` status and transitions to `Ready`
|
|
937
|
+
* once the platform finishes processing its pages. Configure roles/fields
|
|
938
|
+
* afterwards in the Assinafy editor.
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* ```ts
|
|
942
|
+
* const tmpl = await client.templates.create(
|
|
943
|
+
* { filePath: './nda.pdf' },
|
|
944
|
+
* { name: 'NDA template' },
|
|
945
|
+
* );
|
|
946
|
+
* // → { resource: 'template', id, name, status: 'Uploaded',
|
|
947
|
+
* // roles: [{ id, name: 'TemplateEditor', assignment_type: 'Editor' }],
|
|
948
|
+
* // pages: [], tags: [], created_at, updated_at }
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
create(source: DocumentUploadSource, options?: {
|
|
952
|
+
name?: string;
|
|
953
|
+
accountId?: string;
|
|
954
|
+
}): Promise<ITemplateDetailsResponse>;
|
|
800
955
|
/** List templates for the workspace. */
|
|
801
956
|
list(params?: IListParams, accountId?: string): Promise<ITemplateListResponse>;
|
|
802
957
|
/**
|
|
803
|
-
* Get a template by ID.
|
|
958
|
+
* Get a template by ID (`GET /accounts/{id}/templates/{template_id}`).
|
|
804
959
|
*
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
* by the official PHP SDK.
|
|
960
|
+
* Unlike the list endpoint, the single-template response includes `pages`
|
|
961
|
+
* (with per-page `download_url`) and `default_document_tags`.
|
|
808
962
|
*/
|
|
809
963
|
get(templateId: string, accountId?: string): Promise<ITemplateDetailsResponse>;
|
|
810
964
|
/**
|
|
811
|
-
* `
|
|
812
|
-
*
|
|
813
|
-
*
|
|
965
|
+
* Update a template's `name` and/or default `message`
|
|
966
|
+
* (`PUT /accounts/{id}/templates/{template_id}`). Returns the updated template.
|
|
967
|
+
*
|
|
968
|
+
* @example
|
|
969
|
+
* ```ts
|
|
970
|
+
* await client.templates.update(templateId, { name: 'NDA v2', message: 'Please sign' });
|
|
971
|
+
* ```
|
|
972
|
+
*/
|
|
973
|
+
update(templateId: string, payload: IUpdateTemplatePayload, accountId?: string): Promise<ITemplateDetailsResponse>;
|
|
974
|
+
/** Delete a template (`DELETE /accounts/{id}/templates/{template_id}`). */
|
|
975
|
+
delete(templateId: string, accountId?: string): Promise<void>;
|
|
976
|
+
/**
|
|
977
|
+
* Download a template page as a JPEG
|
|
978
|
+
* (`GET /accounts/{id}/templates/{template_id}/pages/{page_id}/download`).
|
|
979
|
+
*
|
|
980
|
+
* Used by template editors to render page thumbnails on the client. The
|
|
981
|
+
* matching `download_url` is also returned on each `template.pages[]` entry.
|
|
814
982
|
*/
|
|
815
983
|
downloadPage(templateId: string, pageId: string, accountId?: string): Promise<Buffer>;
|
|
816
984
|
}
|
|
@@ -990,14 +1158,19 @@ declare class SignerDocumentsResource extends BaseResource {
|
|
|
990
1158
|
}): Promise<unknown>;
|
|
991
1159
|
/** `GET /signature/{type}?signer-access-code=…` — download the signer's signature/initial. */
|
|
992
1160
|
downloadSignature(signerAccessCode: string, imageType?: 'signature' | 'initial'): Promise<Buffer>;
|
|
993
|
-
/**
|
|
1161
|
+
/**
|
|
1162
|
+
* `GET /sign?signer-access-code=…` — fetch the assignment as the signer sees it.
|
|
1163
|
+
*
|
|
1164
|
+
* @param hasAcceptedTerms maps to the `has_accepted_terms` query param
|
|
1165
|
+
* (server default `false`); pass `true` once the signer has accepted terms.
|
|
1166
|
+
*/
|
|
994
1167
|
getAssignment(signerAccessCode: string, hasAcceptedTerms?: boolean): Promise<unknown>;
|
|
995
1168
|
/** `POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…` — sign. */
|
|
996
1169
|
sign(documentId: string, assignmentId: string, signerAccessCode: string, entries: ISignFieldEntry[]): Promise<unknown>;
|
|
997
1170
|
/**
|
|
998
1171
|
* `PUT /documents/{documentId}/assignments/{assignmentId}/reject?signer-access-code=…`
|
|
999
|
-
* — signer-side decline. (
|
|
1000
|
-
* workspace
|
|
1172
|
+
* — signer-side decline. (The workspace-side equivalent is to delete the
|
|
1173
|
+
* document via `documents.delete`; there is no workspace "cancel" endpoint.)
|
|
1001
1174
|
*/
|
|
1002
1175
|
decline(documentId: string, assignmentId: string, signerAccessCode: string, declineReason: string): Promise<unknown>;
|
|
1003
1176
|
}
|
|
@@ -1037,6 +1210,7 @@ interface ClientConfigInput {
|
|
|
1037
1210
|
webhook_secret?: string;
|
|
1038
1211
|
webhookSecret?: string;
|
|
1039
1212
|
timeout?: number;
|
|
1213
|
+
maxRetries?: number;
|
|
1040
1214
|
logger?: Logger;
|
|
1041
1215
|
}
|
|
1042
1216
|
/**
|
|
@@ -1120,4 +1294,4 @@ declare class NetworkError extends AssinafyError {
|
|
|
1120
1294
|
});
|
|
1121
1295
|
}
|
|
1122
1296
|
|
|
1123
|
-
export { ApiError, type AssignmentMethod, type AssignmentNotificationMethod, AssignmentResource, type AssignmentVerificationMethod, AssinafyClient, type AssinafyClientOptions, AssinafyError, AuthenticationResource, type ClientConfigInput, type DocumentArtifactName, DocumentResource, type DocumentStatus, type DocumentUploadSource, FieldsResource, type IApiKeyResponse, type IAssignment, type ICreateAssignmentPayload, type ICreateAssignmentResponse, type ICreateDocumentFromTemplateOptions, type ICreateFieldPayload, type ICreateSignerPayload, type ICreateSignerResponse, type ICreateTagPayload, type ICreateWorkspacePayload, type IDocumentActivity, type IDocumentDetailsResponse, type IDocumentListItem, type IDocumentListParams, type IDocumentListResponse, type IDocumentStatusInfo, type IDocumentUploadOptions, type IDocumentUploadResponse, type IFieldDefinition, type IFieldType, type IFieldValidateMultipleEntry, type IFieldValidationResult, type IInlineTag, type IListParams, type ILoginResponse, type IMaskedApiKeyResponse, type IPaginatedResponse, type IPublicDocumentInfo, type IResendEmailResponse, type ISignFieldEntry, type ISigner, type ISignerListResponse, type ISigningProgress, type ITag, type ITemplateDetailsResponse, type ITemplateListItem, type ITemplateListResponse, type ITemplateRole, type ITemplateSigner, type IUpdateFieldPayload, type IUpdateSignerPayload, type IUpdateTagPayload, type IUpdateWorkspacePayload, type IUploadAndRequestSignaturesResult, type IUploadAndRequestSignaturesSigner, type IWebhookDispatch, type IWebhookDispatchListParams, type IWebhookEventTypeInfo, type IWebhookPayload, type IWebhookRegisterPayload, type IWebhookSubscription, type IWhatsAppNotification, type IWorkspaceListItem, type IWorkspaceListResponse, type IWorkspaceResponse, type Logger, NetworkError, type PaginatedResult, type PaginationMeta, type SendTokenChannel, SignerDocumentsResource, type SignerReference, SignerResource, TagResource, TemplateResource, ValidationError, type WebhookEventType, WebhookResource, WebhookVerifier, WorkspaceResource, buildAssignmentPayload };
|
|
1297
|
+
export { ApiError, type AssignmentMethod, type AssignmentNotificationMethod, AssignmentResource, type AssignmentVerificationMethod, AssinafyClient, type AssinafyClientOptions, AssinafyError, AuthenticationResource, type ClientConfigInput, DEFAULT_WEBHOOK_EVENTS, type DocumentArtifactName, DocumentResource, type DocumentStatus, type DocumentUploadSource, FieldsResource, type IApiKeyResponse, type IAssignment, type IAssignmentItem, type IAssignmentSigner, type ICostEstimate, type ICreateAssignmentPayload, type ICreateAssignmentResponse, type ICreateDocumentFromTemplateOptions, type ICreateFieldPayload, type ICreateSignerPayload, type ICreateSignerResponse, type ICreateTagPayload, type ICreateWorkspacePayload, type IDocumentActivity, type IDocumentDetailsResponse, type IDocumentListItem, type IDocumentListParams, type IDocumentListResponse, type IDocumentStatusInfo, type IDocumentUploadOptions, type IDocumentUploadResponse, type IFieldDefinition, type IFieldType, type IFieldValidateMultipleEntry, type IFieldValidationResult, type IInlineTag, type IListParams, type ILoginResponse, type IMaskedApiKeyResponse, type IPaginatedResponse, type IPublicDocumentInfo, type IResendCostEstimate, type IResendEmailResponse, type ISignFieldEntry, type ISigner, type ISignerListResponse, type ISigningProgress, type ITag, type ITemplateDetailsResponse, type ITemplateListItem, type ITemplateListResponse, type ITemplateRole, type ITemplateSigner, type IUpdateFieldPayload, type IUpdateSignerPayload, type IUpdateTagPayload, type IUpdateTemplatePayload, type IUpdateWorkspacePayload, type IUploadAndRequestSignaturesResult, type IUploadAndRequestSignaturesSigner, type IWebhookDispatch, type IWebhookDispatchListParams, type IWebhookEventTypeInfo, type IWebhookPayload, type IWebhookRegisterPayload, type IWebhookSubscription, type IWhatsAppNotification, type IWorkspaceListItem, type IWorkspaceListResponse, type IWorkspaceResponse, type Logger, NetworkError, type PaginatedResult, type PaginationMeta, type SendTokenChannel, SignerDocumentsResource, type SignerReference, SignerResource, TagResource, TemplateResource, ValidationError, type WebhookEventType, WebhookResource, WebhookVerifier, WorkspaceResource, buildAssignmentPayload };
|