@assinafy/sdk 2.5.2 → 2.7.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/CHANGELOG.md +68 -1
- package/README.en.md +154 -70
- package/README.md +129 -61
- package/SECURITY.md +9 -4
- package/dist/index.d.mts +647 -79
- package/dist/index.d.ts +647 -79
- package/dist/index.js +665 -74
- package/dist/index.mjs +665 -74
- package/docs/API_COVERAGE.md +23 -10
- package/docs/COMPATIBILITY.md +45 -32
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,72 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.7.0] - 2026-10-10
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- The `documents.sendToken()` reference documents the published
|
|
15
|
+
`{ recipient, channel }` body and its `email` channel. The two-argument form
|
|
16
|
+
keeps sending `{ email }` and retries the documented shape when a deployment
|
|
17
|
+
requires `recipient`/`channel`.
|
|
18
|
+
- `assignments.resetExpiration()` documents that the `expires_at` key is always
|
|
19
|
+
sent and that `null` removes the expiration.
|
|
20
|
+
- `AssinafyClient.fromConfig()` resolves `max_retries` before `maxRetries`,
|
|
21
|
+
like every other snake_case/camelCase option pair.
|
|
22
|
+
- The document lifecycle walkthrough in both READMEs starts at workspace
|
|
23
|
+
selection and verifies the webhook signature before processing completion
|
|
24
|
+
events and downloading artifacts.
|
|
25
|
+
- The READMEs document `MAX_UPLOAD_BYTES`, `buildAssignmentPayload()`,
|
|
26
|
+
`DEFAULT_WEBHOOK_EVENTS`, `parseWwwAuthenticate()` and `ClientConfigInput`.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- `ApiError.fromResponse()` falls back to a non-empty message when the error
|
|
31
|
+
body carries empty `message` and `error` strings.
|
|
32
|
+
- `serializeJsonRecord()` keeps its specific "must serialize to a JSON object"
|
|
33
|
+
message instead of the generic serialization failure.
|
|
34
|
+
- JSDoc corrections: a `buildAssignmentPayload()` example that mixed stepped
|
|
35
|
+
and unstepped signers, a duplicated request-body block in
|
|
36
|
+
`auth.linkSocialLogin()`, the `mfa_token` note placement in `auth.login()`,
|
|
37
|
+
the request-body placement in `oauth.revokeToken()`, `fs.promises.writeFile`
|
|
38
|
+
in the binary-download examples, and the parameter list of the two-argument
|
|
39
|
+
`documents.sendToken()` overload.
|
|
40
|
+
|
|
41
|
+
## [2.6.0] - 2026-10-07
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- Multiple webhook endpoints: `webhooks.listEndpoints()`, `createEndpoint()`,
|
|
46
|
+
`getEndpoint()`, `updateEndpoint()` and `deleteEndpoint()`. Accounts have one
|
|
47
|
+
endpoint, or up to three on paid plans.
|
|
48
|
+
- Webhook signatures: `webhooks.getEndpointSecret()` and
|
|
49
|
+
`rotateEndpointSecret()`, and `webhookVerifier.verifySignature()`, which
|
|
50
|
+
verifies the Standard Webhooks `webhook-signature` header with a
|
|
51
|
+
`webhook-timestamp` replay window. Accepts Node/Express header objects and
|
|
52
|
+
Fetch `Headers`.
|
|
53
|
+
- `webhooks.listDispatches()` accepts an `endpoint_id` filter; dispatch records
|
|
54
|
+
carry `endpoint_id`.
|
|
55
|
+
- Two-factor authentication: `auth.verifyMfa()` completes a login that returned
|
|
56
|
+
an `mfa_token`, and `users.getMfa()`, `startTotpEnrollment()`,
|
|
57
|
+
`confirmTotpEnrollment()`, `regenerateRecoveryCodes()` and
|
|
58
|
+
`deleteMfaMethod()` manage authenticator apps and recovery codes.
|
|
59
|
+
- `signers.create()` accepts `government_id`, and signer responses type the
|
|
60
|
+
returned `government_id`.
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
- The subscription methods (`webhooks.register()`, `get()`, `inactivate()`)
|
|
65
|
+
are documented as acting on the account's oldest endpoint.
|
|
66
|
+
|
|
67
|
+
### Deprecated
|
|
68
|
+
|
|
69
|
+
- `webhookVerifier.verify()`; use `verifySignature()`.
|
|
70
|
+
|
|
71
|
+
### Fixed
|
|
72
|
+
|
|
73
|
+
- Signer `government_id` is sent as given instead of being reduced to digits,
|
|
74
|
+
so alphanumeric CNPJs keep their letters. The API normalizes the formatting.
|
|
75
|
+
|
|
10
76
|
## [2.5.2] - 2026-10-05
|
|
11
77
|
|
|
12
78
|
### Fixed
|
|
@@ -705,7 +771,8 @@ signer fields with `cpf` and `whatsapp_phone_number`.
|
|
|
705
771
|
- High-level `uploadAndRequestSignatures` helper on `AssinafyClient`.
|
|
706
772
|
- `PaginatedResult<T>` with parsed `X-Pagination-*` header meta.
|
|
707
773
|
|
|
708
|
-
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.
|
|
774
|
+
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.6.0...HEAD
|
|
775
|
+
[2.6.0]: https://github.com/assinafy/typescript-sdk/compare/v2.5.2...v2.6.0
|
|
709
776
|
[2.5.2]: https://github.com/assinafy/typescript-sdk/compare/v2.5.1...v2.5.2
|
|
710
777
|
[2.5.1]: https://github.com/assinafy/typescript-sdk/compare/v2.5.0...v2.5.1
|
|
711
778
|
[2.5.0]: https://github.com/assinafy/typescript-sdk/compare/v2.4.2...v2.5.0
|
package/README.en.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
TypeScript SDK for the [Assinafy API](https://api.assinafy.com.br/v1/docs) — a Brazilian digital signature platform.
|
|
6
6
|
|
|
7
|
-
Covers all
|
|
7
|
+
Covers all 106 operations in the current official OpenAPI document: accounts,
|
|
8
8
|
authentication, OAuth 2.1 applications, users, documents, assignments, signers,
|
|
9
9
|
signer-side flows, templates, tags, fields, webhooks, branding, statistics, and
|
|
10
10
|
the high-level `uploadAndRequestSignatures` workflow. Five additional
|
|
@@ -29,10 +29,11 @@ afterwards.
|
|
|
29
29
|
[Endpoint coverage](#endpoint-coverage)
|
|
30
30
|
|
|
31
31
|
**The end-to-end flow** — [Document lifecycle](#document-lifecycle):
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
32
|
+
[workspace selection](#1-select-the-workspace) → [upload](#2-upload-the-pdf) →
|
|
33
|
+
[signers](#3-create-or-reuse-the-email-signers) →
|
|
34
|
+
[price and request signatures](#4-price-then-request-signatures) →
|
|
35
|
+
[the signer's side](#5-complete-the-email-signer-flow) →
|
|
36
|
+
[completion and artifacts](#6-observe-completion-and-download-artifacts)
|
|
36
37
|
|
|
37
38
|
**Per-resource detail** — [Resource reference](#resource-reference):
|
|
38
39
|
[documents](#documents) · [signers](#signers) · [assignments](#assignments) ·
|
|
@@ -164,7 +165,7 @@ revocation and userinfo endpoints live on this API. Read both from discovery
|
|
|
164
165
|
rather than hardcoding them.
|
|
165
166
|
|
|
166
167
|
```ts
|
|
167
|
-
import { AssinafyClient, OAuthError } from '@assinafy/sdk';
|
|
168
|
+
import { AssinafyClient, ApiError, OAuthError } from '@assinafy/sdk';
|
|
168
169
|
|
|
169
170
|
const client = new AssinafyClient(); // no credentials needed
|
|
170
171
|
|
|
@@ -232,7 +233,7 @@ await client.oauth.getUserInfo(tokens.access_token); // OIDC claims; needs `open
|
|
|
232
233
|
| `templates:read` | Read templates |
|
|
233
234
|
| `templates:write` | Create and change templates |
|
|
234
235
|
| `account:read` | Read the workspace's profile, theme and logo |
|
|
235
|
-
| `webhooks:write` |
|
|
236
|
+
| `webhooks:write` | Create, change, deactivate and delete the workspace's webhook endpoints |
|
|
236
237
|
| `openid` | Receive an `id_token` identifying the user |
|
|
237
238
|
| `profile` | Read the user's name |
|
|
238
239
|
| `email` | Read the user's email and whether it is verified |
|
|
@@ -300,7 +301,7 @@ anything for them.
|
|
|
300
301
|
| `token` | string | — | Access token (sent as `Authorization: Bearer`). |
|
|
301
302
|
| `accountId` | string | — | Default workspace/account ID. |
|
|
302
303
|
| `baseUrl` | string | `https://api.assinafy.com.br/v1` | Absolute API base without credentials, query, or fragment. Must be `https` unless the host is loopback. |
|
|
303
|
-
| `webhookSecret` | string | — |
|
|
304
|
+
| `webhookSecret` | string | — | Webhook endpoint `whsec_…` secret; enables `webhookVerifier.verifySignature()`. |
|
|
304
305
|
| `timeout` | number | `30000` | Request timeout in milliseconds. |
|
|
305
306
|
| `maxRetries` | number | `2` | Auto-retries eligible HTTP 429 responses, honoring `Retry-After`. `0` disables. |
|
|
306
307
|
| `logger` | `Logger` | no-op | Optional `{debug,info,warn,error}` logger. |
|
|
@@ -329,9 +330,12 @@ const client = AssinafyClient.fromConfig({
|
|
|
329
330
|
});
|
|
330
331
|
```
|
|
331
332
|
|
|
333
|
+
The configuration object accepted by `fromConfig` has the exported type
|
|
334
|
+
`ClientConfigInput`.
|
|
335
|
+
|
|
332
336
|
## Endpoint coverage
|
|
333
337
|
|
|
334
|
-
All
|
|
338
|
+
All 106 operations documented at https://api.assinafy.com.br/v1/docs are
|
|
335
339
|
covered. The table below is the resource-level summary; the detailed operation
|
|
336
340
|
ledger is in [docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
337
341
|
|
|
@@ -339,17 +343,17 @@ ledger is in [docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
|
339
343
|
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
340
344
|
| `client.documents` | list, **search**, upload, details, get, **rename**, activities, waitUntilReady, download, thumbnail, downloadPage, statuses, delete, verify, createFromTemplate, estimateCostFromTemplate, getPublic, sendToken, listTags, replaceTags, addTags, detachTag, isFullySigned, getSigningProgress |
|
|
341
345
|
| `client.signers` | create, get, list, update, delete, findByEmail |
|
|
342
|
-
| `client.assignments` |
|
|
343
|
-
| `client.templates` |
|
|
346
|
+
| `client.assignments` | list, create, estimateCost, resetExpiration, resendNotification, estimateResendCost, listWhatsAppNotifications |
|
|
347
|
+
| `client.templates` | create, list, get, update, delete, downloadPage |
|
|
344
348
|
| `client.tags` | list, create, update, delete |
|
|
345
349
|
| `client.workspaces` | create, list, get, update, delete, getTheme, downloadLogo, uploadLogo, deleteLogo, getStats |
|
|
346
|
-
| `client.webhooks` | register, get, inactivate, listEventTypes, listDispatches, retryDispatch
|
|
350
|
+
| `client.webhooks` | listEndpoints, createEndpoint, getEndpoint, updateEndpoint, deleteEndpoint, getEndpointSecret, rotateEndpointSecret, register, get, inactivate, listEventTypes, listDispatches, retryDispatch |
|
|
347
351
|
| `client.fields` | create, list, get, update, delete, validate, validateMultiple, listTypes |
|
|
348
352
|
| `client.oauth` | **getProtectedResourceMetadata**, **getAuthorizationServerMetadata**, **createAuthorizationUrl**, **readAuthorizationCallback**, **exchangeCode**, **refreshToken**, **revokeToken**, **getUserInfo** |
|
|
349
|
-
| `client.auth` | getSocialLoginUrl, getSocialLoginCallbackUrl, login, socialLogin, linkSocialLogin, createApiKey, getApiKey, deleteApiKey, changePassword, requestPasswordReset, resetPassword |
|
|
350
|
-
| `client.users` | getCurrent, getStats, getNotificationPreferences, updateNotificationPreferences
|
|
351
|
-
| `client.signerDocuments` | getCurrent, list,
|
|
352
|
-
| `client.webhookVerifier` |
|
|
353
|
+
| `client.auth` | getSocialLoginUrl, getSocialLoginCallbackUrl, login, verifyMfa, socialLogin, linkSocialLogin, createApiKey, getApiKey, deleteApiKey, changePassword, requestPasswordReset, resetPassword |
|
|
354
|
+
| `client.users` | getCurrent, getStats, getNotificationPreferences, updateNotificationPreferences, getMfa, startTotpEnrollment, confirmTotpEnrollment, regenerateRecoveryCodes, deleteMfaMethod |
|
|
355
|
+
| `client.signerDocuments` | getCurrent, list, search, download, signMultiple, declineMultiple, self, acceptTerms, verifyEmail, confirmData, uploadSignature, downloadSignature, getAssignment, sign, decline |
|
|
356
|
+
| `client.webhookVerifier` | verifySignature, extractEvent, getEventType, getEventData |
|
|
353
357
|
|
|
354
358
|
Every HTTP wrapper has TypeScript-checked request/response shapes and
|
|
355
359
|
method-level JSDoc covering the wire payload, return shape, validation,
|
|
@@ -366,7 +370,22 @@ artifact phase. The example below keeps every signer on email and uses a
|
|
|
366
370
|
`virtual` assignment, so no page coordinates or paid notification channel are
|
|
367
371
|
required.
|
|
368
372
|
|
|
369
|
-
### 1.
|
|
373
|
+
### 1. Select the workspace
|
|
374
|
+
|
|
375
|
+
Every account-scoped operation happens inside a workspace. With an API key,
|
|
376
|
+
pass the `accountId` when building the client (or as the last argument of any
|
|
377
|
+
account-scoped method). With OAuth, list the user's workspaces and keep the
|
|
378
|
+
chosen `id` with the tokens — a token is bound to exactly one workspace (see
|
|
379
|
+
[OAuth applications](#oauth-applications)):
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
const { data: workspaces } = await client.workspaces.list();
|
|
383
|
+
const accountId = workspaces[0]?.id; // e.g. new AssinafyClient({ apiKey, accountId })
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
The examples below assume a `client` already pointing at the chosen workspace.
|
|
387
|
+
|
|
388
|
+
### 2. Upload the PDF
|
|
370
389
|
|
|
371
390
|
```ts
|
|
372
391
|
const uploaded = await client.documents.upload({ filePath: './contract.pdf' });
|
|
@@ -409,7 +428,8 @@ type DocumentUploadShape = {
|
|
|
409
428
|
`metadata_ready`, `pending_signature`, `expired`, `certificating`,
|
|
410
429
|
`certificated`, `rejected_by_signer`, `rejected_by_user`, and `failed`.
|
|
411
430
|
|
|
412
|
-
Uploads must be PDFs, at most 25 MB and at most 2,000 pages
|
|
431
|
+
Uploads must be PDFs, at most 25 MB and at most 2,000 pages (the byte limit is
|
|
432
|
+
exported as `MAX_UPLOAD_BYTES`). The SDK checks the
|
|
413
433
|
extension, size, and `%PDF-` header before sending. A new upload can have an
|
|
414
434
|
empty `pages` array until metadata processing finishes. Wait before creating a
|
|
415
435
|
`collect` assignment because its fields refer to rendered page IDs; a
|
|
@@ -422,7 +442,7 @@ const prepared = await client.documents.waitUntilReady(uploaded.id, {
|
|
|
422
442
|
});
|
|
423
443
|
```
|
|
424
444
|
|
|
425
|
-
###
|
|
445
|
+
### 3. Create or reuse the email signers
|
|
426
446
|
|
|
427
447
|
```ts
|
|
428
448
|
const signerA = await client.signers.create({
|
|
@@ -457,7 +477,7 @@ When an email is present, `signers.create()` first looks up that email in the
|
|
|
457
477
|
workspace and reuses the matching signer; a name-only or phone-only request
|
|
458
478
|
always creates a new signer.
|
|
459
479
|
|
|
460
|
-
###
|
|
480
|
+
### 4. Price, then request signatures
|
|
461
481
|
|
|
462
482
|
Cost estimation takes channel descriptors, not signer IDs:
|
|
463
483
|
|
|
@@ -530,7 +550,7 @@ type AssignmentShape = {
|
|
|
530
550
|
The URLs and delivered messages contain signer credentials; treat them as
|
|
531
551
|
secrets.
|
|
532
552
|
|
|
533
|
-
###
|
|
553
|
+
### 5. Complete the email signer flow
|
|
534
554
|
|
|
535
555
|
Assinafy sends each signer a link containing their access code and sends the
|
|
536
556
|
one-time verification code through the selected channel. Neither value is
|
|
@@ -579,11 +599,13 @@ before signing. A `DigitalCertificate` signer cannot call `sign`; that branch
|
|
|
579
599
|
uses Assinafy's certificate flow, described in
|
|
580
600
|
[ICP-Brasil digital certificate](#icp-brasil-digital-certificate).
|
|
581
601
|
|
|
582
|
-
###
|
|
602
|
+
### 6. Observe completion and download artifacts
|
|
583
603
|
|
|
584
|
-
Subscribe to `document_ready` for event-driven completion
|
|
585
|
-
`
|
|
586
|
-
|
|
604
|
+
Subscribe to `document_ready` for event-driven completion — on an endpoint with
|
|
605
|
+
`signing_enabled`, [verify the signature](#webhook-verification) of every
|
|
606
|
+
delivery before processing it — or fetch `documents.details(documentId)` until
|
|
607
|
+
`status === 'certificated'`. Webhook
|
|
608
|
+
deliveries can repeat, so use the `webhook-id` header as an
|
|
587
609
|
idempotency key. Once complete:
|
|
588
610
|
|
|
589
611
|
```ts
|
|
@@ -786,7 +808,13 @@ await client.assignments.create(documentId, {
|
|
|
786
808
|
}],
|
|
787
809
|
}],
|
|
788
810
|
});
|
|
811
|
+
```
|
|
789
812
|
|
|
813
|
+
To assemble an assignment body outside the client — for example, to inspect it
|
|
814
|
+
before sending — use the exported `buildAssignmentPayload()` helper, which
|
|
815
|
+
applies the same validation and normalization as `create()`.
|
|
816
|
+
|
|
817
|
+
```ts
|
|
790
818
|
// Estimate cost (the endpoint prices channel descriptors, not signer IDs) → ICostEstimate
|
|
791
819
|
await client.assignments.estimateCost(documentId, { signers: [{}] }); // default Email
|
|
792
820
|
// → {
|
|
@@ -796,8 +824,7 @@ await client.assignments.estimateCost(documentId, { signers: [{}] }); // default
|
|
|
796
824
|
// }
|
|
797
825
|
|
|
798
826
|
await client.assignments.resetExpiration(documentId, assignmentId, '2027-06-30T00:00:00Z');
|
|
799
|
-
//
|
|
800
|
-
// Confirm target support before using `null` to clear an expiration.
|
|
827
|
+
// The `expires_at` key is required by the contract; send `null` to remove the expiration.
|
|
801
828
|
await client.assignments.resetExpiration(documentId, assignmentId, null);
|
|
802
829
|
|
|
803
830
|
await client.assignments.resendNotification(documentId, assignmentId, signerId);
|
|
@@ -1082,7 +1109,13 @@ Most server-side integrations should just use `X-Api-Key` directly. Use these en
|
|
|
1082
1109
|
const oauthStart = client.auth.getSocialLoginUrl('google');
|
|
1083
1110
|
const oauthCallback = client.auth.getSocialLoginCallbackUrl();
|
|
1084
1111
|
|
|
1085
|
-
|
|
1112
|
+
let session = await client.auth.login('me@example.com', 'pw');
|
|
1113
|
+
// With two-factor authentication on, login returns `mfa_token`; exchange it
|
|
1114
|
+
// within 5 minutes for an authenticator code or a recovery code.
|
|
1115
|
+
if (session.mfa_token) {
|
|
1116
|
+
session = await client.auth.verifyMfa(session.mfa_token, '123456');
|
|
1117
|
+
}
|
|
1118
|
+
const { access_token, user, accounts } = session;
|
|
1086
1119
|
await client.auth.socialLogin({ provider: 'google', token: 'google-id-token', has_accepted_terms: true });
|
|
1087
1120
|
await client.auth.linkSocialLogin({ provider: 'google', token: 'google-id-token' });
|
|
1088
1121
|
|
|
@@ -1123,29 +1156,54 @@ await client.users.updateNotificationPreferences({
|
|
|
1123
1156
|
// the complete nine-key notification preference map.
|
|
1124
1157
|
```
|
|
1125
1158
|
|
|
1159
|
+
#### Two-factor authentication
|
|
1160
|
+
|
|
1161
|
+
Available in production. The TOTP secret and the recovery codes are shown once.
|
|
1162
|
+
|
|
1163
|
+
```ts
|
|
1164
|
+
const enrollment = await client.users.startTotpEnrollment('My phone');
|
|
1165
|
+
// → { id, secret, provisioning_uri } — render provisioning_uri as a QR code
|
|
1166
|
+
const { recovery_codes } = await client.users.confirmTotpEnrollment({
|
|
1167
|
+
id: enrollment.id,
|
|
1168
|
+
code: '123456', // current code from the new device
|
|
1169
|
+
});
|
|
1170
|
+
// From now on every login needs the second factor.
|
|
1171
|
+
|
|
1172
|
+
const { methods, recovery_codes_remaining } = await client.users.getMfa();
|
|
1173
|
+
await client.users.regenerateRecoveryCodes({ password: 'current-password' }); // or { code }
|
|
1174
|
+
await client.users.deleteMfaMethod(methods[0]!.id, { code: '123456' }); // → { is_mfa_enabled }
|
|
1175
|
+
```
|
|
1176
|
+
|
|
1177
|
+
Replacing an already confirmed authenticator also needs `password` or
|
|
1178
|
+
`reauth_code` in `confirmTotpEnrollment()`; first-time enrollment does not.
|
|
1179
|
+
|
|
1126
1180
|
### Webhooks
|
|
1127
1181
|
|
|
1128
|
-
|
|
1182
|
+
An account has 1 webhook endpoint, or up to 3 on paid plans. Every active
|
|
1183
|
+
endpoint subscribed to an event receives it independently. OAuth tokens need
|
|
1184
|
+
`account:read` to read endpoints and `webhooks:write` to change them; the
|
|
1185
|
+
signing secret is available only with an API key.
|
|
1129
1186
|
|
|
1130
1187
|
```ts
|
|
1131
|
-
await client.webhooks.
|
|
1188
|
+
const endpoint = await client.webhooks.createEndpoint({
|
|
1189
|
+
name: 'ERP',
|
|
1132
1190
|
url: 'https://example.com/webhooks/assinafy',
|
|
1133
|
-
email: '
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
events: [
|
|
1137
|
-
'document_ready',
|
|
1138
|
-
'document_prepared',
|
|
1139
|
-
'signer_signed_document',
|
|
1140
|
-
'signer_rejected_document',
|
|
1141
|
-
'document_processing_failed',
|
|
1142
|
-
],
|
|
1191
|
+
email: 'ops@example.com',
|
|
1192
|
+
events: ['document_ready', 'signer_signed_document', 'signer_rejected_document'],
|
|
1193
|
+
signing_enabled: true, // sign deliveries with Standard Webhooks
|
|
1143
1194
|
});
|
|
1195
|
+
// → { id, name, url, email, events, is_active, signing_enabled, created_at, updated_at }
|
|
1196
|
+
|
|
1197
|
+
const { secret } = await client.webhooks.getEndpointSecret(endpoint.id); // 'whsec_…'
|
|
1198
|
+
await client.webhooks.listEndpoints(); // IWebhookEndpoint[]
|
|
1199
|
+
await client.webhooks.getEndpoint(endpoint.id);
|
|
1200
|
+
await client.webhooks.updateEndpoint(endpoint.id, { is_active: false }); // only the fields sent
|
|
1201
|
+
await client.webhooks.rotateEndpointSecret(endpoint.id); // the old secret stops at once
|
|
1202
|
+
await client.webhooks.deleteEndpoint(endpoint.id); // frees the plan slot
|
|
1144
1203
|
|
|
1145
|
-
await client.webhooks.get(); // IWebhookSubscription | null
|
|
1146
|
-
await client.webhooks.inactivate(); // stop deliveries (no delete route exists)
|
|
1147
1204
|
await client.webhooks.listEventTypes();
|
|
1148
1205
|
const history = await client.webhooks.listDispatches({
|
|
1206
|
+
endpoint_id: endpoint.id,
|
|
1149
1207
|
delivered: false,
|
|
1150
1208
|
page: 1,
|
|
1151
1209
|
'per-page': 20,
|
|
@@ -1153,14 +1211,28 @@ const history = await client.webhooks.listDispatches({
|
|
|
1153
1211
|
const retried = await client.webhooks.retryDispatch(dispatchId); // IWebhookDispatch
|
|
1154
1212
|
```
|
|
1155
1213
|
|
|
1156
|
-
`
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
`
|
|
1163
|
-
|
|
1214
|
+
`createEndpoint()` returns `403` once the plan's limit is reached and `400`
|
|
1215
|
+
when another endpoint of the workspace already uses the same `url`. When
|
|
1216
|
+
`events` is omitted or empty, the SDK sends the exported
|
|
1217
|
+
`DEFAULT_WEBHOOK_EVENTS`: `document_ready`, `document_prepared`,
|
|
1218
|
+
`signer_signed_document`, `signer_rejected_document`, and
|
|
1219
|
+
`document_processing_failed`. In
|
|
1220
|
+
`updateEndpoint()`, `signing_enabled: true` generates a secret if there is none
|
|
1221
|
+
and `false` discards it.
|
|
1222
|
+
|
|
1223
|
+
The earlier routes remain and act on the account's oldest endpoint:
|
|
1224
|
+
`register()` (create or update), `get()` (`IWebhookSubscription | null`) and
|
|
1225
|
+
`inactivate()`.
|
|
1226
|
+
|
|
1227
|
+
Assinafy delivers each event as an HTTP `POST` with
|
|
1228
|
+
`Content-Type: application/json`, `Connection: close` and the headers
|
|
1229
|
+
`webhook-id` (identical on every attempt of the same event to the same
|
|
1230
|
+
endpoint — deduplicate on it), `webhook-timestamp` and, with signing on,
|
|
1231
|
+
`webhook-signature`. Any `2xx` is success. There are at most two attempts,
|
|
1232
|
+
three seconds apart. After ten consecutive failed events, ordinary delivery
|
|
1233
|
+
pauses and about 5% of later events are attempted until one succeeds; use
|
|
1234
|
+
`retryDispatch()` for an immediate redelivery. The dispatch history retains only
|
|
1235
|
+
the first 2,000 characters of the receiver's response body.
|
|
1164
1236
|
|
|
1165
1237
|
Each history or retry result is an `IWebhookDispatch`:
|
|
1166
1238
|
|
|
@@ -1170,6 +1242,7 @@ type WebhookDispatchShape = {
|
|
|
1170
1242
|
id: string;
|
|
1171
1243
|
event: string;
|
|
1172
1244
|
activity_id: number;
|
|
1245
|
+
endpoint_id?: string | null; // null once the endpoint is deleted
|
|
1173
1246
|
endpoint: string | null;
|
|
1174
1247
|
payload: IWebhookPayload | Record<string, unknown> | null;
|
|
1175
1248
|
delivered: boolean;
|
|
@@ -1229,46 +1302,45 @@ property before delivery.
|
|
|
1229
1302
|
|
|
1230
1303
|
### Webhook verification
|
|
1231
1304
|
|
|
1232
|
-
`
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1305
|
+
With `signing_enabled: true`, every delivery is signed following
|
|
1306
|
+
[Standard Webhooks](https://www.standardwebhooks.com): HMAC-SHA256 over
|
|
1307
|
+
`{webhook-id}.{webhook-timestamp}.{raw body}`, keyed with the base64 value after
|
|
1308
|
+
the `whsec_` prefix. `verifySignature()` compares in constant time and rejects a
|
|
1309
|
+
`webhook-timestamp` more than 5 minutes from the local clock. Pass the **raw**
|
|
1310
|
+
body, never re-serialized JSON.
|
|
1238
1311
|
|
|
1239
1312
|
```ts
|
|
1240
1313
|
import express from 'express';
|
|
1241
1314
|
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
throw new Error('This deployment has no confirmed webhook-signature contract');
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
const webhookClient = new AssinafyClient({ webhookSecret });
|
|
1315
|
+
const webhookClient = new AssinafyClient({
|
|
1316
|
+
webhookSecret: process.env.ASSINAFY_WEBHOOK_SECRET, // 'whsec_…' from getEndpointSecret()
|
|
1317
|
+
});
|
|
1249
1318
|
|
|
1250
1319
|
app.post('/webhooks/assinafy', express.raw({ type: 'application/json' }), (req, res) => {
|
|
1251
|
-
const signature = req.header(signatureHeader) ?? '';
|
|
1252
1320
|
const rawBody = req.body as Buffer;
|
|
1253
|
-
|
|
1254
|
-
if (!webhookClient.webhookVerifier.verify(rawBody, signature)) {
|
|
1321
|
+
if (!webhookClient.webhookVerifier.verifySignature(rawBody, req.headers)) {
|
|
1255
1322
|
return res.status(401).send('Invalid signature');
|
|
1256
1323
|
}
|
|
1257
1324
|
|
|
1258
1325
|
const event = webhookClient.webhookVerifier.extractEvent(rawBody);
|
|
1259
1326
|
const type = webhookClient.webhookVerifier.getEventType(event);
|
|
1260
1327
|
const data = webhookClient.webhookVerifier.getEventData(event);
|
|
1328
|
+
// Deduplicate on req.headers['webhook-id'] before processing.
|
|
1261
1329
|
|
|
1262
1330
|
switch (type) {
|
|
1263
|
-
case 'document_ready':
|
|
1264
|
-
case 'signer_signed_document':
|
|
1265
|
-
case 'signer_rejected_document':
|
|
1266
|
-
case 'document_processing_failed':break;
|
|
1331
|
+
case 'document_ready': break;
|
|
1332
|
+
case 'signer_signed_document': break;
|
|
1333
|
+
case 'signer_rejected_document': break;
|
|
1334
|
+
case 'document_processing_failed': break;
|
|
1267
1335
|
}
|
|
1268
1336
|
res.sendStatus(200);
|
|
1269
1337
|
});
|
|
1270
1338
|
```
|
|
1271
1339
|
|
|
1340
|
+
On Fetch runtimes (`Request`), pass `await request.text()` and
|
|
1341
|
+
`request.headers`. The clock tolerance is the optional third argument, in
|
|
1342
|
+
seconds. After `rotateEndpointSecret()`, update the receiver's secret at once.
|
|
1343
|
+
|
|
1272
1344
|
### Signer-side endpoints
|
|
1273
1345
|
|
|
1274
1346
|
For building custom signer portals. Most calls require the `signer-access-code`
|
|
@@ -1388,6 +1460,10 @@ try {
|
|
|
1388
1460
|
}
|
|
1389
1461
|
```
|
|
1390
1462
|
|
|
1463
|
+
`err.challenge` is an already-parsed `IAuthenticateChallenge`. The parser used
|
|
1464
|
+
internally is exported as `parseWwwAuthenticate()`, for reading the
|
|
1465
|
+
`WWW-Authenticate` header of responses received outside the SDK.
|
|
1466
|
+
|
|
1391
1467
|
## Environments
|
|
1392
1468
|
|
|
1393
1469
|
| | |
|
|
@@ -1430,6 +1506,14 @@ bun run lint:pkg # publint + arethetypeswrong
|
|
|
1430
1506
|
bun run verify # complete local release gate
|
|
1431
1507
|
```
|
|
1432
1508
|
|
|
1509
|
+
## Documentation
|
|
1510
|
+
|
|
1511
|
+
- **[README.md](README.md)** — a mesma referência completa, em português
|
|
1512
|
+
- [docs/API_COVERAGE.md](docs/API_COVERAGE.md) — operation map
|
|
1513
|
+
- [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md) — per-deployment request and response variants
|
|
1514
|
+
- [docs/RELEASING.md](docs/RELEASING.md) — publishing process
|
|
1515
|
+
- [API documentation](https://api.assinafy.com.br/v1/docs)
|
|
1516
|
+
|
|
1433
1517
|
## License
|
|
1434
1518
|
|
|
1435
1519
|
MIT
|