@assinafy/sdk 2.6.0 → 2.7.1
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 +61 -1
- package/README.en.md +69 -26
- package/README.md +54 -24
- package/SECURITY.md +9 -4
- package/dist/index.d.mts +173 -64
- package/dist/index.d.ts +173 -64
- package/dist/index.js +199 -76
- package/dist/index.mjs +199 -76
- package/docs/API_COVERAGE.md +9 -7
- package/docs/COMPATIBILITY.md +7 -17
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,64 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.7.1] - 2026-10-12
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `signerDocuments.listAsWorkspace()` and `searchAsWorkspace()` list and
|
|
15
|
+
search a signer's documents with the client's API key or OAuth token. They
|
|
16
|
+
never send a signer access code.
|
|
17
|
+
- `ApiError.rateLimit` exposes the `X-Rate-Limit-Limit`,
|
|
18
|
+
`X-Rate-Limit-Remaining`, `X-Rate-Limit-Reset` and `Retry-After` headers of
|
|
19
|
+
the failed response (new exported type `IRateLimitInfo`).
|
|
20
|
+
- `IOAuthTokenResponse.issued_token_type` and `ITemplateListItem.resource`,
|
|
21
|
+
as published in the API contract.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **`documents.sendToken()` follows the published contract**: it always sends
|
|
26
|
+
`{ "channel": "email", "recipient": "…" }` and resolves with the response
|
|
27
|
+
`data` (`{ document, channel, recipient }`, new type `ISendTokenResult`)
|
|
28
|
+
instead of `void`. The legacy `{ email }` body and its automatic retry are
|
|
29
|
+
gone. `SendTokenChannel` is now `'email'`; passing `'whatsapp'` or a
|
|
30
|
+
non-email recipient is rejected with a `ValidationError` before any request,
|
|
31
|
+
because the endpoint accepts only the email channel.
|
|
32
|
+
- `signerDocuments.decline()` and `declineMultiple()` reject a decline reason
|
|
33
|
+
longer than 2000 characters, the documented limit.
|
|
34
|
+
- `WebhookVerifier.verifySignature()` reads `webhook-*` headers from a plain
|
|
35
|
+
object regardless of letter case.
|
|
36
|
+
|
|
37
|
+
## [2.7.0] - 2026-10-10
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- The `documents.sendToken()` reference documents the published
|
|
42
|
+
`{ recipient, channel }` body and its `email` channel. The two-argument form
|
|
43
|
+
keeps sending `{ email }` and retries the documented shape when a deployment
|
|
44
|
+
requires `recipient`/`channel`.
|
|
45
|
+
- `assignments.resetExpiration()` documents that the `expires_at` key is always
|
|
46
|
+
sent and that `null` removes the expiration.
|
|
47
|
+
- `AssinafyClient.fromConfig()` resolves `max_retries` before `maxRetries`,
|
|
48
|
+
like every other snake_case/camelCase option pair.
|
|
49
|
+
- The document lifecycle walkthrough in both READMEs starts at workspace
|
|
50
|
+
selection and verifies the webhook signature before processing completion
|
|
51
|
+
events and downloading artifacts.
|
|
52
|
+
- The READMEs document `MAX_UPLOAD_BYTES`, `buildAssignmentPayload()`,
|
|
53
|
+
`DEFAULT_WEBHOOK_EVENTS`, `parseWwwAuthenticate()` and `ClientConfigInput`.
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- `ApiError.fromResponse()` falls back to a non-empty message when the error
|
|
58
|
+
body carries empty `message` and `error` strings.
|
|
59
|
+
- `serializeJsonRecord()` keeps its specific "must serialize to a JSON object"
|
|
60
|
+
message instead of the generic serialization failure.
|
|
61
|
+
- JSDoc corrections: a `buildAssignmentPayload()` example that mixed stepped
|
|
62
|
+
and unstepped signers, a duplicated request-body block in
|
|
63
|
+
`auth.linkSocialLogin()`, the `mfa_token` note placement in `auth.login()`,
|
|
64
|
+
the request-body placement in `oauth.revokeToken()`, `fs.promises.writeFile`
|
|
65
|
+
in the binary-download examples, and the parameter list of the two-argument
|
|
66
|
+
`documents.sendToken()` overload.
|
|
67
|
+
|
|
10
68
|
## [2.6.0] - 2026-10-07
|
|
11
69
|
|
|
12
70
|
### Added
|
|
@@ -740,7 +798,9 @@ signer fields with `cpf` and `whatsapp_phone_number`.
|
|
|
740
798
|
- High-level `uploadAndRequestSignatures` helper on `AssinafyClient`.
|
|
741
799
|
- `PaginatedResult<T>` with parsed `X-Pagination-*` header meta.
|
|
742
800
|
|
|
743
|
-
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.
|
|
801
|
+
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.7.1...HEAD
|
|
802
|
+
[2.7.1]: https://github.com/assinafy/typescript-sdk/compare/v2.7.0...v2.7.1
|
|
803
|
+
[2.7.0]: https://github.com/assinafy/typescript-sdk/compare/v2.6.0...v2.7.0
|
|
744
804
|
[2.6.0]: https://github.com/assinafy/typescript-sdk/compare/v2.5.2...v2.6.0
|
|
745
805
|
[2.5.2]: https://github.com/assinafy/typescript-sdk/compare/v2.5.1...v2.5.2
|
|
746
806
|
[2.5.1]: https://github.com/assinafy/typescript-sdk/compare/v2.5.0...v2.5.1
|
package/README.en.md
CHANGED
|
@@ -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
|
|
|
@@ -307,6 +308,10 @@ anything for them.
|
|
|
307
308
|
|
|
308
309
|
### Rate limiting
|
|
309
310
|
|
|
311
|
+
Once retries are spent, the `ApiError` carries `err.rateLimit` with `limit`,
|
|
312
|
+
`remaining`, `reset` (from `X-Rate-Limit-*`) and `retryAfter` (`Retry-After`,
|
|
313
|
+
in seconds).
|
|
314
|
+
|
|
310
315
|
On an HTTP `429`, the client automatically retries up to `maxRetries` times,
|
|
311
316
|
waiting for the server-provided `Retry-After` (or `X-Rate-Limit-Reset`) delay
|
|
312
317
|
before each attempt. Automatic replay is limited to read-safe `GET`, `HEAD`,
|
|
@@ -329,6 +334,9 @@ const client = AssinafyClient.fromConfig({
|
|
|
329
334
|
});
|
|
330
335
|
```
|
|
331
336
|
|
|
337
|
+
The configuration object accepted by `fromConfig` has the exported type
|
|
338
|
+
`ClientConfigInput`.
|
|
339
|
+
|
|
332
340
|
## Endpoint coverage
|
|
333
341
|
|
|
334
342
|
All 106 operations documented at https://api.assinafy.com.br/v1/docs are
|
|
@@ -339,8 +347,8 @@ ledger is in [docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
|
339
347
|
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
340
348
|
| `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
349
|
| `client.signers` | create, get, list, update, delete, findByEmail |
|
|
342
|
-
| `client.assignments` |
|
|
343
|
-
| `client.templates` |
|
|
350
|
+
| `client.assignments` | list, create, estimateCost, resetExpiration, resendNotification, estimateResendCost, listWhatsAppNotifications |
|
|
351
|
+
| `client.templates` | create, list, get, update, delete, downloadPage |
|
|
344
352
|
| `client.tags` | list, create, update, delete |
|
|
345
353
|
| `client.workspaces` | create, list, get, update, delete, getTheme, downloadLogo, uploadLogo, deleteLogo, getStats |
|
|
346
354
|
| `client.webhooks` | listEndpoints, createEndpoint, getEndpoint, updateEndpoint, deleteEndpoint, getEndpointSecret, rotateEndpointSecret, register, get, inactivate, listEventTypes, listDispatches, retryDispatch |
|
|
@@ -348,7 +356,7 @@ ledger is in [docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
|
348
356
|
| `client.oauth` | **getProtectedResourceMetadata**, **getAuthorizationServerMetadata**, **createAuthorizationUrl**, **readAuthorizationCallback**, **exchangeCode**, **refreshToken**, **revokeToken**, **getUserInfo** |
|
|
349
357
|
| `client.auth` | getSocialLoginUrl, getSocialLoginCallbackUrl, login, verifyMfa, socialLogin, linkSocialLogin, createApiKey, getApiKey, deleteApiKey, changePassword, requestPasswordReset, resetPassword |
|
|
350
358
|
| `client.users` | getCurrent, getStats, getNotificationPreferences, updateNotificationPreferences, getMfa, startTotpEnrollment, confirmTotpEnrollment, regenerateRecoveryCodes, deleteMfaMethod |
|
|
351
|
-
| `client.signerDocuments` | getCurrent, list,
|
|
359
|
+
| `client.signerDocuments` | getCurrent, list, search, listAsWorkspace, searchAsWorkspace, download, signMultiple, declineMultiple, self, acceptTerms, verifyEmail, confirmData, uploadSignature, downloadSignature, getAssignment, sign, decline |
|
|
352
360
|
| `client.webhookVerifier` | verifySignature, extractEvent, getEventType, getEventData |
|
|
353
361
|
|
|
354
362
|
Every HTTP wrapper has TypeScript-checked request/response shapes and
|
|
@@ -366,7 +374,22 @@ artifact phase. The example below keeps every signer on email and uses a
|
|
|
366
374
|
`virtual` assignment, so no page coordinates or paid notification channel are
|
|
367
375
|
required.
|
|
368
376
|
|
|
369
|
-
### 1.
|
|
377
|
+
### 1. Select the workspace
|
|
378
|
+
|
|
379
|
+
Every account-scoped operation happens inside a workspace. With an API key,
|
|
380
|
+
pass the `accountId` when building the client (or as the last argument of any
|
|
381
|
+
account-scoped method). With OAuth, list the user's workspaces and keep the
|
|
382
|
+
chosen `id` with the tokens — a token is bound to exactly one workspace (see
|
|
383
|
+
[OAuth applications](#oauth-applications)):
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
const { data: workspaces } = await client.workspaces.list();
|
|
387
|
+
const accountId = workspaces[0]?.id; // e.g. new AssinafyClient({ apiKey, accountId })
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
The examples below assume a `client` already pointing at the chosen workspace.
|
|
391
|
+
|
|
392
|
+
### 2. Upload the PDF
|
|
370
393
|
|
|
371
394
|
```ts
|
|
372
395
|
const uploaded = await client.documents.upload({ filePath: './contract.pdf' });
|
|
@@ -409,7 +432,8 @@ type DocumentUploadShape = {
|
|
|
409
432
|
`metadata_ready`, `pending_signature`, `expired`, `certificating`,
|
|
410
433
|
`certificated`, `rejected_by_signer`, `rejected_by_user`, and `failed`.
|
|
411
434
|
|
|
412
|
-
Uploads must be PDFs, at most 25 MB and at most 2,000 pages
|
|
435
|
+
Uploads must be PDFs, at most 25 MB and at most 2,000 pages (the byte limit is
|
|
436
|
+
exported as `MAX_UPLOAD_BYTES`). The SDK checks the
|
|
413
437
|
extension, size, and `%PDF-` header before sending. A new upload can have an
|
|
414
438
|
empty `pages` array until metadata processing finishes. Wait before creating a
|
|
415
439
|
`collect` assignment because its fields refer to rendered page IDs; a
|
|
@@ -422,7 +446,7 @@ const prepared = await client.documents.waitUntilReady(uploaded.id, {
|
|
|
422
446
|
});
|
|
423
447
|
```
|
|
424
448
|
|
|
425
|
-
###
|
|
449
|
+
### 3. Create or reuse the email signers
|
|
426
450
|
|
|
427
451
|
```ts
|
|
428
452
|
const signerA = await client.signers.create({
|
|
@@ -457,7 +481,7 @@ When an email is present, `signers.create()` first looks up that email in the
|
|
|
457
481
|
workspace and reuses the matching signer; a name-only or phone-only request
|
|
458
482
|
always creates a new signer.
|
|
459
483
|
|
|
460
|
-
###
|
|
484
|
+
### 4. Price, then request signatures
|
|
461
485
|
|
|
462
486
|
Cost estimation takes channel descriptors, not signer IDs:
|
|
463
487
|
|
|
@@ -530,7 +554,7 @@ type AssignmentShape = {
|
|
|
530
554
|
The URLs and delivered messages contain signer credentials; treat them as
|
|
531
555
|
secrets.
|
|
532
556
|
|
|
533
|
-
###
|
|
557
|
+
### 5. Complete the email signer flow
|
|
534
558
|
|
|
535
559
|
Assinafy sends each signer a link containing their access code and sends the
|
|
536
560
|
one-time verification code through the selected channel. Neither value is
|
|
@@ -579,11 +603,13 @@ before signing. A `DigitalCertificate` signer cannot call `sign`; that branch
|
|
|
579
603
|
uses Assinafy's certificate flow, described in
|
|
580
604
|
[ICP-Brasil digital certificate](#icp-brasil-digital-certificate).
|
|
581
605
|
|
|
582
|
-
###
|
|
606
|
+
### 6. Observe completion and download artifacts
|
|
583
607
|
|
|
584
|
-
Subscribe to `document_ready` for event-driven completion
|
|
585
|
-
`
|
|
586
|
-
|
|
608
|
+
Subscribe to `document_ready` for event-driven completion — on an endpoint with
|
|
609
|
+
`signing_enabled`, [verify the signature](#webhook-verification) of every
|
|
610
|
+
delivery before processing it — or fetch `documents.details(documentId)` until
|
|
611
|
+
`status === 'certificated'`. Webhook
|
|
612
|
+
deliveries can repeat, so use the `webhook-id` header as an
|
|
587
613
|
idempotency key. Once complete:
|
|
588
614
|
|
|
589
615
|
```ts
|
|
@@ -669,12 +695,8 @@ await client.documents.verify('FE32EDDADE7CBDDCBB934E7402047450B0E59C02');
|
|
|
669
695
|
|
|
670
696
|
// Public endpoints (no auth)
|
|
671
697
|
await client.documents.getPublic(doc.id);
|
|
672
|
-
//
|
|
673
|
-
await client.documents.sendToken(doc.id, '
|
|
674
|
-
|
|
675
|
-
// Explicit compatibility overload for older deployments:
|
|
676
|
-
// { recipient: '+5548999990000', channel: 'whatsapp' }
|
|
677
|
-
await client.documents.sendToken(doc.id, '+5548999990000', 'whatsapp');
|
|
698
|
+
// Body: { channel: 'email', recipient: 'signer@example.com' } (email only)
|
|
699
|
+
await client.documents.sendToken(doc.id, 'signer@example.com');
|
|
678
700
|
|
|
679
701
|
// The current OpenAPI contract requires existing tag IDs.
|
|
680
702
|
const contractsTag = await client.tags.create({ name: 'Contracts' });
|
|
@@ -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);
|
|
@@ -1185,7 +1212,11 @@ const retried = await client.webhooks.retryDispatch(dispatchId); // IWebhookDisp
|
|
|
1185
1212
|
```
|
|
1186
1213
|
|
|
1187
1214
|
`createEndpoint()` returns `403` once the plan's limit is reached and `400`
|
|
1188
|
-
when another endpoint of the workspace already uses the same `url`.
|
|
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
|
|
1189
1220
|
`updateEndpoint()`, `signing_enabled: true` generates a secret if there is none
|
|
1190
1221
|
and `false` discards it.
|
|
1191
1222
|
|
|
@@ -1429,6 +1460,10 @@ try {
|
|
|
1429
1460
|
}
|
|
1430
1461
|
```
|
|
1431
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
|
+
|
|
1432
1467
|
## Environments
|
|
1433
1468
|
|
|
1434
1469
|
| | |
|
|
@@ -1471,6 +1506,14 @@ bun run lint:pkg # publint + arethetypeswrong
|
|
|
1471
1506
|
bun run verify # complete local release gate
|
|
1472
1507
|
```
|
|
1473
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
|
+
|
|
1474
1517
|
## License
|
|
1475
1518
|
|
|
1476
1519
|
MIT
|
package/README.md
CHANGED
|
@@ -26,10 +26,11 @@ recurso. Leia na ordem na primeira vez; use como referência depois.
|
|
|
26
26
|
[Cobertura de endpoints](#cobertura-de-endpoints)
|
|
27
27
|
|
|
28
28
|
**O fluxo ponta a ponta** — [Ciclo de vida do documento](#ciclo-de-vida-do-documento):
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
29
|
+
[seleção do workspace](#1-selecione-o-workspace) → [envio do PDF](#2-envie-o-pdf) →
|
|
30
|
+
[signatários](#3-crie-ou-reaproveite-os-signatários-por-e-mail) →
|
|
31
|
+
[orçamento e pedido de assinatura](#4-orce-depois-peça-as-assinaturas) →
|
|
32
|
+
[o lado do signatário](#5-conclua-o-fluxo-do-signatário-por-e-mail) →
|
|
33
|
+
[conclusão e artefatos](#6-acompanhe-a-conclusão-e-baixe-os-artefatos)
|
|
33
34
|
|
|
34
35
|
**Detalhe por recurso** — [Referência de recursos](#referência-de-recursos):
|
|
35
36
|
[documentos](#documentos) · [signatários](#signatários) · [assignments](#assignments) ·
|
|
@@ -156,7 +157,7 @@ O fluxo passa por dois hosts de propósito: a tela de consentimento fica no serv
|
|
|
156
157
|
API. Leia os dois da descoberta em vez de fixá-los no código.
|
|
157
158
|
|
|
158
159
|
```ts
|
|
159
|
-
import { AssinafyClient, OAuthError } from '@assinafy/sdk';
|
|
160
|
+
import { AssinafyClient, ApiError, OAuthError } from '@assinafy/sdk';
|
|
160
161
|
|
|
161
162
|
const client = new AssinafyClient(); // nenhuma credencial necessária
|
|
162
163
|
|
|
@@ -295,6 +296,9 @@ configurações de conector; seus usuários não precisam que você registre nad
|
|
|
295
296
|
|
|
296
297
|
### Limite de requisições
|
|
297
298
|
|
|
299
|
+
Quando as tentativas se esgotam, o `ApiError` traz `err.rateLimit` com `limit`, `remaining`,
|
|
300
|
+
`reset` (de `X-Rate-Limit-*`) e `retryAfter` (`Retry-After`, em segundos).
|
|
301
|
+
|
|
298
302
|
Em um HTTP `429` o cliente retenta até `maxRetries` vezes, aguardando o `Retry-After` (ou
|
|
299
303
|
`X-Rate-Limit-Reset`) devolvido pelo servidor antes de cada tentativa. A repetição automática vale
|
|
300
304
|
apenas para `GET`, `HEAD`, `OPTIONS` e `DELETE`, que são seguros de repetir. `GET /sign` fica de
|
|
@@ -316,6 +320,8 @@ const client = AssinafyClient.fromConfig({
|
|
|
316
320
|
});
|
|
317
321
|
```
|
|
318
322
|
|
|
323
|
+
O objeto aceito por `fromConfig` tem o tipo exportado `ClientConfigInput`.
|
|
324
|
+
|
|
319
325
|
## Cobertura de endpoints
|
|
320
326
|
|
|
321
327
|
As 106 operações documentadas em https://api.assinafy.com.br/v1/docs estão cobertas. A tabela abaixo
|
|
@@ -335,7 +341,7 @@ As 106 operações documentadas em https://api.assinafy.com.br/v1/docs estão co
|
|
|
335
341
|
| `client.oauth` | **getProtectedResourceMetadata**, **getAuthorizationServerMetadata**, **createAuthorizationUrl**, **readAuthorizationCallback**, **exchangeCode**, **refreshToken**, **revokeToken**, **getUserInfo** |
|
|
336
342
|
| `client.auth` | getSocialLoginUrl, getSocialLoginCallbackUrl, login, verifyMfa, socialLogin, linkSocialLogin, createApiKey, getApiKey, deleteApiKey, changePassword, requestPasswordReset, resetPassword |
|
|
337
343
|
| `client.users` | getCurrent, getStats, getNotificationPreferences, updateNotificationPreferences, getMfa, startTotpEnrollment, confirmTotpEnrollment, regenerateRecoveryCodes, deleteMfaMethod |
|
|
338
|
-
| `client.signerDocuments` | getCurrent, list, search, download, signMultiple, declineMultiple, self, acceptTerms, verifyEmail, confirmData, uploadSignature, downloadSignature, getAssignment, sign, decline |
|
|
344
|
+
| `client.signerDocuments` | getCurrent, list, search, listAsWorkspace, searchAsWorkspace, download, signMultiple, declineMultiple, self, acceptTerms, verifyEmail, confirmData, uploadSignature, downloadSignature, getAssignment, sign, decline |
|
|
339
345
|
| `client.webhookVerifier` | verifySignature, extractEvent, getEventType, getEventData |
|
|
340
346
|
|
|
341
347
|
Todo wrapper HTTP tem tipos de requisição e resposta verificados pelo TypeScript e JSDoc por método,
|
|
@@ -348,7 +354,21 @@ A integração normal tem uma fase do dono da conta, uma fase do signatário e u
|
|
|
348
354
|
artefatos. O exemplo abaixo mantém todos os signatários no e-mail e usa um assignment `virtual`,
|
|
349
355
|
então não exige coordenadas de página nem canal pago de notificação.
|
|
350
356
|
|
|
351
|
-
### 1.
|
|
357
|
+
### 1. Selecione o workspace
|
|
358
|
+
|
|
359
|
+
Toda operação com escopo de conta acontece dentro de um workspace. Com chave de API, informe o
|
|
360
|
+
`accountId` ao construir o cliente (ou como último argumento de cada método com escopo de conta).
|
|
361
|
+
Com OAuth, liste os workspaces do usuário e guarde o `id` do escolhido junto com os tokens — um
|
|
362
|
+
token vale para exatamente um workspace (veja [Aplicações OAuth](#aplicações-oauth)):
|
|
363
|
+
|
|
364
|
+
```ts
|
|
365
|
+
const { data: workspaces } = await client.workspaces.list();
|
|
366
|
+
const accountId = workspaces[0]?.id; // ex.: new AssinafyClient({ apiKey, accountId })
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Os exemplos abaixo assumem um `client` já apontando para o workspace escolhido.
|
|
370
|
+
|
|
371
|
+
### 2. Envie o PDF
|
|
352
372
|
|
|
353
373
|
```ts
|
|
354
374
|
const enviado = await client.documents.upload({ filePath: './contrato.pdf' });
|
|
@@ -390,7 +410,8 @@ type DocumentUploadShape = {
|
|
|
390
410
|
`pending_signature`, `expired`, `certificating`, `certificated`, `rejected_by_signer`,
|
|
391
411
|
`rejected_by_user` e `failed`.
|
|
392
412
|
|
|
393
|
-
O envio precisa ser um PDF de no máximo 25 MB e 2.000 páginas
|
|
413
|
+
O envio precisa ser um PDF de no máximo 25 MB e 2.000 páginas (o limite em bytes está exportado
|
|
414
|
+
como `MAX_UPLOAD_BYTES`). O SDK confere extensão, tamanho e o
|
|
394
415
|
cabeçalho `%PDF-` antes de enviar. Um upload novo pode ter `pages` vazio até o processamento de
|
|
395
416
|
metadados terminar. Espere antes de criar um assignment `collect`, porque seus campos referenciam
|
|
396
417
|
IDs de páginas renderizadas; um assignment `virtual` pode ser criado imediatamente.
|
|
@@ -402,7 +423,7 @@ const preparado = await client.documents.waitUntilReady(enviado.id, {
|
|
|
402
423
|
});
|
|
403
424
|
```
|
|
404
425
|
|
|
405
|
-
###
|
|
426
|
+
### 3. Crie ou reaproveite os signatários por e-mail
|
|
406
427
|
|
|
407
428
|
```ts
|
|
408
429
|
const signatarioA = await client.signers.create({
|
|
@@ -436,7 +457,7 @@ type SignerShape = {
|
|
|
436
457
|
Quando há e-mail, `signers.create()` primeiro procura esse endereço no workspace e reaproveita o
|
|
437
458
|
signatário correspondente; uma requisição só com nome ou só com telefone sempre cria um novo.
|
|
438
459
|
|
|
439
|
-
###
|
|
460
|
+
### 4. Orce, depois peça as assinaturas
|
|
440
461
|
|
|
441
462
|
A estimativa de custo recebe descritores de canal, não IDs de signatário:
|
|
442
463
|
|
|
@@ -508,7 +529,7 @@ type AssignmentShape = {
|
|
|
508
529
|
|
|
509
530
|
As URLs e as mensagens entregues contêm credenciais do signatário; trate-as como segredo.
|
|
510
531
|
|
|
511
|
-
###
|
|
532
|
+
### 5. Conclua o fluxo do signatário por e-mail
|
|
512
533
|
|
|
513
534
|
A Assinafy envia a cada signatário um link com o código de acesso dele e manda o código de
|
|
514
535
|
verificação de uso único pelo canal escolhido. Nenhum dos dois valores é devolvido como campo
|
|
@@ -552,11 +573,13 @@ assinar. Um signatário `DigitalCertificate` não pode usar `sign`; esse ramo pa
|
|
|
552
573
|
certificado da Assinafy, descrito em
|
|
553
574
|
[Certificado digital ICP-Brasil](#certificado-digital-icp-brasil).
|
|
554
575
|
|
|
555
|
-
###
|
|
576
|
+
### 6. Acompanhe a conclusão e baixe os artefatos
|
|
556
577
|
|
|
557
|
-
Assine o evento `document_ready` para saber da conclusão por evento
|
|
558
|
-
`
|
|
559
|
-
|
|
578
|
+
Assine o evento `document_ready` para saber da conclusão por evento — em um endpoint com
|
|
579
|
+
`signing_enabled`, [verifique a assinatura](#verificação-de-webhooks) de cada entrega antes de
|
|
580
|
+
processá-la — ou consulte `documents.details(documentId)` até `status === 'certificated'`. As
|
|
581
|
+
entregas de webhook podem se repetir — use o cabeçalho `webhook-id` como chave de idempotência.
|
|
582
|
+
Concluído:
|
|
560
583
|
|
|
561
584
|
```ts
|
|
562
585
|
const documentoFinal = await client.documents.details(enviado.id);
|
|
@@ -640,12 +663,8 @@ await client.documents.verify('FE32EDDADE7CBDDCBB934E7402047450B0E59C02');
|
|
|
640
663
|
|
|
641
664
|
// Endpoints públicos (sem autenticação)
|
|
642
665
|
await client.documents.getPublic(doc.id);
|
|
643
|
-
// Corpo
|
|
644
|
-
await client.documents.sendToken(doc.id, '
|
|
645
|
-
|
|
646
|
-
// Sobrecarga explícita de compatibilidade para deploys mais antigos:
|
|
647
|
-
// { recipient: '+5548999990000', channel: 'whatsapp' }
|
|
648
|
-
await client.documents.sendToken(doc.id, '+5548999990000', 'whatsapp');
|
|
666
|
+
// Corpo: { channel: 'email', recipient: 'signer@example.com' } (só e-mail)
|
|
667
|
+
await client.documents.sendToken(doc.id, 'signer@example.com');
|
|
649
668
|
|
|
650
669
|
// O contrato OpenAPI atual exige IDs de tags já existentes.
|
|
651
670
|
const tagContratos = await client.tags.create({ name: 'Contratos' });
|
|
@@ -747,7 +766,13 @@ await client.assignments.create(documentId, {
|
|
|
747
766
|
}],
|
|
748
767
|
}],
|
|
749
768
|
});
|
|
769
|
+
```
|
|
750
770
|
|
|
771
|
+
Para montar o corpo de um assignment fora do cliente — por exemplo, para inspecioná-lo antes do
|
|
772
|
+
envio — use o helper exportado `buildAssignmentPayload()`, que aplica as mesmas validações e
|
|
773
|
+
normalizações de `create()`.
|
|
774
|
+
|
|
775
|
+
```ts
|
|
751
776
|
// Estimativa de custo (o endpoint orça descritores de canal, não IDs) → ICostEstimate
|
|
752
777
|
await client.assignments.estimateCost(documentId, { signers: [{}] }); // Email padrão
|
|
753
778
|
// → {
|
|
@@ -757,8 +782,7 @@ await client.assignments.estimateCost(documentId, { signers: [{}] }); // Email p
|
|
|
757
782
|
// }
|
|
758
783
|
|
|
759
784
|
await client.assignments.resetExpiration(documentId, assignmentId, '2027-06-30T00:00:00Z');
|
|
760
|
-
//
|
|
761
|
-
// Confirme o suporte do destino antes de usar `null` para limpar a expiração.
|
|
785
|
+
// A chave `expires_at` é exigida pelo contrato; envie `null` para remover a expiração.
|
|
762
786
|
await client.assignments.resetExpiration(documentId, assignmentId, null);
|
|
763
787
|
|
|
764
788
|
await client.assignments.resendNotification(documentId, assignmentId, signerId);
|
|
@@ -1158,7 +1182,9 @@ const reenviado = await client.webhooks.retryDispatch(dispatchId); // IWebhookDi
|
|
|
1158
1182
|
```
|
|
1159
1183
|
|
|
1160
1184
|
`createEndpoint()` devolve `403` quando o limite do plano foi atingido e `400` quando outro endpoint
|
|
1161
|
-
do workspace já usa a mesma `url`.
|
|
1185
|
+
do workspace já usa a mesma `url`. Quando `events` é omitido ou vazio, o SDK envia
|
|
1186
|
+
`DEFAULT_WEBHOOK_EVENTS` (exportado): `document_ready`, `document_prepared`,
|
|
1187
|
+
`signer_signed_document`, `signer_rejected_document` e `document_processing_failed`. Em `updateEndpoint()`, `signing_enabled: true` gera um segredo se
|
|
1162
1188
|
ainda não houver e `false` o descarta.
|
|
1163
1189
|
|
|
1164
1190
|
As rotas anteriores continuam disponíveis e operam sobre o endpoint mais antigo da conta:
|
|
@@ -1400,6 +1426,10 @@ try {
|
|
|
1400
1426
|
}
|
|
1401
1427
|
```
|
|
1402
1428
|
|
|
1429
|
+
`err.challenge` é um `IAuthenticateChallenge` já interpretado. O parser usado internamente está
|
|
1430
|
+
exportado como `parseWwwAuthenticate()`, para quem precisa ler o cabeçalho `WWW-Authenticate` de
|
|
1431
|
+
respostas recebidas fora do SDK.
|
|
1432
|
+
|
|
1403
1433
|
## Ambientes
|
|
1404
1434
|
|
|
1405
1435
|
| | |
|
package/SECURITY.md
CHANGED
|
@@ -62,10 +62,15 @@ opportunity to upgrade.
|
|
|
62
62
|
compared in constant time and `iss` must match the expected issuer. Do not
|
|
63
63
|
bypass `readAuthorizationCallback()` and exchange a code straight from the
|
|
64
64
|
query string.
|
|
65
|
-
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
`
|
|
65
|
+
- Signed webhook endpoints are verified before any event is processed. The API
|
|
66
|
+
generates the `whsec_…` secret (`webhooks.getEndpointSecret()`), and
|
|
67
|
+
`webhookVerifier.verifySignature()` checks the Standard Webhooks
|
|
68
|
+
`webhook-signature` header against the raw, unparsed request body — parse the
|
|
69
|
+
JSON only after verification. The default five-minute timestamp tolerance
|
|
70
|
+
blocks replayed deliveries; keep the receiver clock synchronized. Rotate the
|
|
71
|
+
secret with `webhooks.rotateEndpointSecret()` when it may have leaked —
|
|
72
|
+
rotation is immediate and the secret/rotate routes accept an API key only,
|
|
73
|
+
not OAuth tokens. See `docs/COMPATIBILITY.md`.
|
|
69
74
|
- Dependency changes must keep `bun.lock` synchronized and pass `bun run audit`.
|
|
70
75
|
GitHub Actions are pinned to immutable commit SHAs and updated through
|
|
71
76
|
Dependabot review.
|