@assinafy/sdk 2.8.0 → 2.9.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 +41 -1
- package/README.en.md +133 -15
- package/README.md +125 -13
- package/dist/index.d.mts +557 -31
- package/dist/index.d.ts +557 -31
- package/dist/index.js +687 -35
- package/dist/index.mjs +685 -35
- package/docs/API_COVERAGE.md +15 -4
- package/docs/COMPATIBILITY.md +39 -5
- package/docs/RELEASING.md +1 -1
- package/package.json +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.9.0] - 2026-10-28
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Contract lifecycle management (CLM) through `client.contracts`: list tracked
|
|
15
|
+
contracts, read terms and related instruments, create or update terms, renew
|
|
16
|
+
a term, and terminate a contract. Request and response types include contract
|
|
17
|
+
status, counterparties, dates, values, owners, metadata, external references,
|
|
18
|
+
amendments, optimistic concurrency, filters, and pagination.
|
|
19
|
+
- Known webhook event types for contract updates, notices, expiration, renewal,
|
|
20
|
+
termination, and signed amendments.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- User notification preferences include the four contract lifecycle settings:
|
|
25
|
+
`ContractRenewalNotice`, `ContractExpiring`, `ContractExpired`, and
|
|
26
|
+
`ContractRenewed`.
|
|
27
|
+
- Document details expose `has_contract`, `verification_code`, and
|
|
28
|
+
`verification_url`; assignment signing URLs use the exported `ISigningUrl`
|
|
29
|
+
shape.
|
|
30
|
+
- The runtime dependency baseline is Axios 1.21.0.
|
|
31
|
+
- Development and CI use Bun 1.4.4.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- Updated `follow-redirects` to 1.16.2 so sensitive headers remain protected
|
|
36
|
+
across redirects, including array-form and regular-expression edge cases.
|
|
37
|
+
|
|
38
|
+
## [2.8.1] - 2026-10-19
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- Reject `DigitalCertificate` signers unless an assignment is explicitly
|
|
43
|
+
`virtual`, before direct creation or cost estimation can invite or charge for
|
|
44
|
+
an unusable `collect` assignment. Template creation and estimation reject
|
|
45
|
+
certificate signers until the API enforces its server-derived method. All
|
|
46
|
+
paths expose the stable
|
|
47
|
+
`digital_certificate_requires_virtual_method` validation code.
|
|
48
|
+
|
|
10
49
|
## [2.8.0] - 2026-10-16
|
|
11
50
|
|
|
12
51
|
### Added
|
|
@@ -834,7 +873,8 @@ signer fields with `cpf` and `whatsapp_phone_number`.
|
|
|
834
873
|
- High-level `uploadAndRequestSignatures` helper on `AssinafyClient`.
|
|
835
874
|
- `PaginatedResult<T>` with parsed `X-Pagination-*` header meta.
|
|
836
875
|
|
|
837
|
-
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.8.
|
|
876
|
+
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.8.1...HEAD
|
|
877
|
+
[2.8.1]: https://github.com/assinafy/typescript-sdk/compare/v2.8.0...v2.8.1
|
|
838
878
|
[2.8.0]: https://github.com/assinafy/typescript-sdk/releases/tag/v2.8.0
|
|
839
879
|
[2.7.1]: https://github.com/assinafy/typescript-sdk/compare/v2.7.0...v2.7.1
|
|
840
880
|
[2.7.0]: https://github.com/assinafy/typescript-sdk/compare/v2.6.0...v2.7.0
|
package/README.en.md
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
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 118 operations in the current official OpenAPI document: accounts,
|
|
8
8
|
authentication, OAuth 2.1 applications, users, documents, assignments, signers,
|
|
9
|
-
signer-side flows,
|
|
9
|
+
signer-side flows, contract lifecycle management (CLM), templates, tags, fields,
|
|
10
|
+
webhooks, branding, statistics, and
|
|
10
11
|
the high-level `uploadAndRequestSignatures` workflow. Five additional
|
|
11
12
|
template-management routes used by existing integrations and two legacy browser
|
|
12
13
|
URL helpers are retained for compatibility.
|
|
@@ -37,6 +38,7 @@ afterwards.
|
|
|
37
38
|
|
|
38
39
|
**Per-resource detail** — [Resource reference](#resource-reference):
|
|
39
40
|
[documents](#documents) · [signers](#signers) · [assignments](#assignments) ·
|
|
41
|
+
[contract lifecycle management](#contract-lifecycle-management-clm) ·
|
|
40
42
|
[paid signing branches](#paid-signing-branches) · [templates](#templates) ·
|
|
41
43
|
[tags](#tags) · [workspaces](#workspaces) ·
|
|
42
44
|
[field definitions](#field-definitions) ·
|
|
@@ -52,9 +54,9 @@ afterwards.
|
|
|
52
54
|
## Requirements
|
|
53
55
|
|
|
54
56
|
- Node.js 22+ for the built-in `FormData` / `Blob` APIs used by uploads. Packed
|
|
55
|
-
CJS and ESM imports are tested on 22 (maintenance LTS)
|
|
56
|
-
|
|
57
|
-
- or Bun 1.4.
|
|
57
|
+
CJS and ESM imports are tested on 22 and 24 (maintenance LTS) and 26 (active
|
|
58
|
+
LTS); Node 20 reached end-of-life in April 2026 and is unsupported.
|
|
59
|
+
- or Bun 1.4.4 (the version pinned for development and CI)
|
|
58
60
|
- HTTPS with TLS 1.2 or higher, which the API requires; Node.js 22+ and Bun
|
|
59
61
|
negotiate it by default
|
|
60
62
|
|
|
@@ -339,7 +341,7 @@ The configuration object accepted by `fromConfig` has the exported type
|
|
|
339
341
|
|
|
340
342
|
## Endpoint coverage
|
|
341
343
|
|
|
342
|
-
All
|
|
344
|
+
All 118 operations documented at https://api.assinafy.com.br/v1/docs are
|
|
343
345
|
covered. The table below is the resource-level summary; the detailed operation
|
|
344
346
|
ledger is in [docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
345
347
|
|
|
@@ -348,6 +350,7 @@ ledger is in [docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
|
348
350
|
| `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 |
|
|
349
351
|
| `client.signers` | create, get, list, update, delete, findByEmail |
|
|
350
352
|
| `client.assignments` | list, create, estimateCost, resetExpiration, resendNotification, estimateResendCost, listWhatsAppNotifications, getIdentityVerification, downloadIdentityVerificationImage, reviewIdentityVerification |
|
|
353
|
+
| `client.contracts` | list, get, set, listRelated, renew, terminate |
|
|
351
354
|
| `client.templates` | create, list, get, update, delete, downloadPage |
|
|
352
355
|
| `client.tags` | list, create, update, delete |
|
|
353
356
|
| `client.workspaces` | create, list, get, update, delete, getTheme, downloadLogo, uploadLogo, deleteLogo, getStats |
|
|
@@ -776,6 +779,108 @@ both are silent rather than errors:
|
|
|
776
779
|
`page` rather than requesting a larger page, and trust `meta.per_page` over
|
|
777
780
|
the value you asked for.
|
|
778
781
|
|
|
782
|
+
### Contract lifecycle management (CLM)
|
|
783
|
+
|
|
784
|
+
Contract lifecycle management tracks the business terms attached to an existing
|
|
785
|
+
document without changing how that document is uploaded, sent, or signed. The
|
|
786
|
+
production API supports the complete flow below; a sandbox can lag a newly
|
|
787
|
+
released CLM route or plan entitlement (see
|
|
788
|
+
[compatibility notes](docs/COMPATIBILITY.md#contract-lifecycle-management-clm)).
|
|
789
|
+
|
|
790
|
+
```ts
|
|
791
|
+
// 1. Upload or select the contract document, then attach its terms.
|
|
792
|
+
const document = await client.documents.upload({ filePath: './agreement.pdf' });
|
|
793
|
+
const contract = await client.contracts.set(document.id, {
|
|
794
|
+
status: 'active',
|
|
795
|
+
counterparty_name: 'Example Ltda',
|
|
796
|
+
counterparty_taxpayer_id: '11.222.333/0001-81',
|
|
797
|
+
value: 120000.50,
|
|
798
|
+
currency: 'BRL',
|
|
799
|
+
start_date: '2026-11-01',
|
|
800
|
+
end_date: '2027-10-31',
|
|
801
|
+
auto_renew: true,
|
|
802
|
+
renewal_term_months: 12,
|
|
803
|
+
notice_period_days: 30,
|
|
804
|
+
metadata: { crm_stage: 'won' },
|
|
805
|
+
external_references: [{ system: 'crm', id: '98765' }],
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
// 2. Read or synchronize the portfolio. `updated_at` moves after every change.
|
|
809
|
+
const current = await client.contracts.get(document.id);
|
|
810
|
+
const endingSoon = await client.contracts.list({
|
|
811
|
+
status: ['active'],
|
|
812
|
+
ending_within_days: 30,
|
|
813
|
+
sort: 'end_date',
|
|
814
|
+
expand: 'document',
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
// 3. Use the value you read to reject a concurrent edit with HTTP 409.
|
|
818
|
+
if (current.resource === 'document_contract') {
|
|
819
|
+
await client.contracts.set(document.id, {
|
|
820
|
+
notice_period_days: 60,
|
|
821
|
+
updated_at: current.updated_at,
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// 4. A signed amendment is another document linked to the root contract.
|
|
826
|
+
const amendment = await client.documents.upload({ filePath: './amendment.pdf' });
|
|
827
|
+
await client.contracts.set(amendment.id, {
|
|
828
|
+
parent_document_id: document.id,
|
|
829
|
+
relation_type: 'amendment',
|
|
830
|
+
value: 130000,
|
|
831
|
+
end_date: '2028-06-30',
|
|
832
|
+
});
|
|
833
|
+
// Send and sign `amendment` through the ordinary assignment flow. Its delta is
|
|
834
|
+
// applied to the root after certification; inspect the complete family here:
|
|
835
|
+
const family = await client.contracts.listRelated(amendment.id);
|
|
836
|
+
|
|
837
|
+
// 5. Start a new term directly, or close the lifecycle.
|
|
838
|
+
const renewed = await client.contracts.renew(document.id, {
|
|
839
|
+
term: family.term,
|
|
840
|
+
value: 135000,
|
|
841
|
+
updated_at: family.updated_at,
|
|
842
|
+
});
|
|
843
|
+
await client.contracts.terminate(document.id, {
|
|
844
|
+
reason: 'Replaced by a new agreement',
|
|
845
|
+
updated_at: renewed.updated_at,
|
|
846
|
+
});
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
Writes need `documents:write` for OAuth and a workspace plan with contract
|
|
850
|
+
tracking. Reads need `documents:read` and continue working after the plan lapses.
|
|
851
|
+
The hourly lifecycle emits renewal-notice, expiring, expired, and renewed
|
|
852
|
+
notifications; configure the owner preferences and subscribe to the matching
|
|
853
|
+
webhook events when your integration must react:
|
|
854
|
+
|
|
855
|
+
```ts
|
|
856
|
+
await client.users.updateNotificationPreferences({
|
|
857
|
+
ContractRenewalNotice: true,
|
|
858
|
+
ContractExpiring: true,
|
|
859
|
+
ContractExpired: true,
|
|
860
|
+
ContractRenewed: true,
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
await client.webhooks.createEndpoint({
|
|
864
|
+
url: 'https://example.com/webhooks/assinafy',
|
|
865
|
+
email: 'operations@example.com',
|
|
866
|
+
events: [
|
|
867
|
+
'document_contract_updated',
|
|
868
|
+
'document_contract_renewal_notice',
|
|
869
|
+
'document_contract_expiring',
|
|
870
|
+
'document_contract_expired',
|
|
871
|
+
'document_contract_renewed',
|
|
872
|
+
'document_contract_terminated',
|
|
873
|
+
'document_contract_amended',
|
|
874
|
+
'document_contract_amendment_updated',
|
|
875
|
+
],
|
|
876
|
+
});
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
`set()`, `renew()`, and `terminate()` are not automatically retried. A lost
|
|
880
|
+
response is safe to resolve by reading the contract again: `updated_at`, the
|
|
881
|
+
current `term`, and the explicit renewal date provide the concurrency and
|
|
882
|
+
repeat protections documented by the API.
|
|
883
|
+
|
|
779
884
|
### Signers
|
|
780
885
|
|
|
781
886
|
```ts
|
|
@@ -908,7 +1013,7 @@ to `Email`.
|
|
|
908
1013
|
| --- | --- | --- | --- |
|
|
909
1014
|
| `Email` *(default)* | One-time code (OTP) by email | `Email` | Free |
|
|
910
1015
|
| `Whatsapp` | One-time code (OTP) by WhatsApp | `Whatsapp` | 0.45 credit (the notification), paid plans only |
|
|
911
|
-
| `DigitalCertificate` | The signer signs with their **own ICP-Brasil certificate — A1 or A3 —** through the Web PKI extension, producing a **qualified PAdES signature
|
|
1016
|
+
| `DigitalCertificate` | The signer signs with their **own ICP-Brasil certificate — A1 or A3 —** through the Web PKI extension, producing a **qualified PAdES signature**; requires `method: 'virtual'` | `Email` **or** `Whatsapp` | 0.5 credits + the notification |
|
|
912
1017
|
| `IdDocumentFaceMatchBasic` | Hosted identity-document, face and liveness verification | `Email` **or** `Whatsapp` | Use `estimateCost()` |
|
|
913
1018
|
|
|
914
1019
|
Exactly one notification method per signer. The SDK rejects an invalid
|
|
@@ -954,10 +1059,19 @@ forward them outside the signing flow.
|
|
|
954
1059
|
|
|
955
1060
|
#### ICP-Brasil digital certificate
|
|
956
1061
|
|
|
957
|
-
`DigitalCertificate` requires the account feature, a CPF
|
|
958
|
-
signer's `government_id`, and exactly one certificate signer in
|
|
959
|
-
step. It costs 0.5 credits per certificate signer in addition to
|
|
960
|
-
notification cost.
|
|
1062
|
+
`DigitalCertificate` requires `method: 'virtual'`, the account feature, a CPF
|
|
1063
|
+
or CNPJ in the signer's `government_id`, and exactly one certificate signer in
|
|
1064
|
+
that signing step. It costs 0.5 credits per certificate signer in addition to
|
|
1065
|
+
the selected notification cost. A certificate flow completes the signer's
|
|
1066
|
+
virtual item; it cannot submit placed fields through the ordinary `collect`
|
|
1067
|
+
signing endpoint.
|
|
1068
|
+
|
|
1069
|
+
The SDK rejects certificate signers on a `collect` assignment in both
|
|
1070
|
+
`create()` and `estimateCost()` before any request. Branch on
|
|
1071
|
+
`ValidationError.errors.code ===
|
|
1072
|
+
'digital_certificate_requires_virtual_method'`, or compare it with the
|
|
1073
|
+
exported `DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD` constant; do not match
|
|
1074
|
+
the human-readable message.
|
|
961
1075
|
|
|
962
1076
|
**A1 and A3 are certificate media**, chosen by the signer in their browser at
|
|
963
1077
|
signing time: A1 lives in software (a file on the machine) and A3 in hardware
|
|
@@ -1047,9 +1161,12 @@ await client.documents.estimateCostFromTemplate(templateId, [
|
|
|
1047
1161
|
// has_sufficient_resources: true, blocking_reason: null, breakdown: [], … }
|
|
1048
1162
|
```
|
|
1049
1163
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1164
|
+
The server derives a template assignment's method from its placed fields, and
|
|
1165
|
+
currently accepts certificate signers even when that produces an unusable
|
|
1166
|
+
`collect` assignment. Until the API enforces the virtual-only rule atomically,
|
|
1167
|
+
the SDK rejects `DigitalCertificate` in both `createFromTemplate()` and
|
|
1168
|
+
`estimateCostFromTemplate()` with the same stable validation code. Create a
|
|
1169
|
+
direct `virtual` assignment for certificate signers instead.
|
|
1053
1170
|
|
|
1054
1171
|
Template creation only uploads the PDF and provisions the default editor role —
|
|
1055
1172
|
configure roles/fields in the Assinafy editor (or the web UI) afterwards.
|
|
@@ -1202,9 +1319,10 @@ const preferences = await client.users.getNotificationPreferences();
|
|
|
1202
1319
|
await client.users.updateNotificationPreferences({
|
|
1203
1320
|
SignerDeclined: false,
|
|
1204
1321
|
DocumentExpired: false,
|
|
1322
|
+
ContractExpiring: true,
|
|
1205
1323
|
});
|
|
1206
1324
|
// Updates merge: omitted keys keep their current value. Both methods return
|
|
1207
|
-
// the complete
|
|
1325
|
+
// the complete thirteen-key notification preference map.
|
|
1208
1326
|
```
|
|
1209
1327
|
|
|
1210
1328
|
#### Two-factor authentication
|
package/README.md
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
SDK oficial em TypeScript para a [API Assinafy](https://api.assinafy.com.br/v1/docs) — plataforma
|
|
6
6
|
brasileira de assinatura eletrônica de documentos.
|
|
7
7
|
|
|
8
|
-
Cobre as
|
|
9
|
-
usuários, documentos, assignments, signatários, fluxos do lado do signatário,
|
|
8
|
+
Cobre as 118 operações do documento OpenAPI oficial: contas, autenticação, aplicações OAuth 2.1,
|
|
9
|
+
usuários, documentos, assignments, signatários, fluxos do lado do signatário, gestão do ciclo de
|
|
10
|
+
vida de contratos (CLM), templates, tags,
|
|
10
11
|
campos, webhooks, identidade visual, estatísticas e o fluxo de alto nível
|
|
11
12
|
`uploadAndRequestSignatures`. Cinco rotas adicionais de gestão de templates usadas por integrações
|
|
12
13
|
existentes e dois helpers de URL de navegador são mantidos por compatibilidade.
|
|
@@ -34,6 +35,7 @@ recurso. Leia na ordem na primeira vez; use como referência depois.
|
|
|
34
35
|
|
|
35
36
|
**Detalhe por recurso** — [Referência de recursos](#referência-de-recursos):
|
|
36
37
|
[documentos](#documentos) · [signatários](#signatários) · [assignments](#assignments) ·
|
|
38
|
+
[gestão do ciclo de vida de contratos](#gestão-do-ciclo-de-vida-de-contratos-clm) ·
|
|
37
39
|
[ramos pagos de assinatura](#ramos-pagos-de-assinatura) · [templates](#templates) · [tags](#tags) ·
|
|
38
40
|
[workspaces](#workspaces) · [definições de campo](#definições-de-campo) ·
|
|
39
41
|
[autenticação e chaves de API](#autenticação--gestão-de-chaves-de-api) ·
|
|
@@ -47,9 +49,9 @@ recurso. Leia na ordem na primeira vez; use como referência depois.
|
|
|
47
49
|
## Requisitos
|
|
48
50
|
|
|
49
51
|
- Node.js 22+ (usa as APIs nativas `FormData` / `Blob` para upload). Os imports CJS e ESM
|
|
50
|
-
empacotados são testados no 22 (LTS de manutenção)
|
|
52
|
+
empacotados são testados no 22 e 24 (LTS de manutenção) e 26 (LTS ativo). O Node 20
|
|
51
53
|
chegou ao fim da vida em abril de 2026 e não é suportado.
|
|
52
|
-
- ou Bun 1.4.
|
|
54
|
+
- ou Bun 1.4.4 (versão fixada no desenvolvimento e na CI)
|
|
53
55
|
- HTTPS com TLS 1.2 ou superior, exigido pela API; o Node.js 22+ e o Bun já negociam isso por padrão
|
|
54
56
|
|
|
55
57
|
## Instalação
|
|
@@ -324,7 +326,7 @@ O objeto aceito por `fromConfig` tem o tipo exportado `ClientConfigInput`.
|
|
|
324
326
|
|
|
325
327
|
## Cobertura de endpoints
|
|
326
328
|
|
|
327
|
-
As
|
|
329
|
+
As 118 operações documentadas em https://api.assinafy.com.br/v1/docs estão cobertas. A tabela abaixo
|
|
328
330
|
é o resumo por recurso; o mapa detalhado por operação está em
|
|
329
331
|
[docs/API_COVERAGE.md](docs/API_COVERAGE.md).
|
|
330
332
|
|
|
@@ -333,6 +335,7 @@ As 112 operações documentadas em https://api.assinafy.com.br/v1/docs estão co
|
|
|
333
335
|
| `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 |
|
|
334
336
|
| `client.signers` | create, get, list, update, delete, findByEmail |
|
|
335
337
|
| `client.assignments` | list, create, estimateCost, resetExpiration, resendNotification, estimateResendCost, listWhatsAppNotifications, getIdentityVerification, downloadIdentityVerificationImage, reviewIdentityVerification |
|
|
338
|
+
| `client.contracts` | list, get, set, listRelated, renew, terminate |
|
|
336
339
|
| `client.templates` | create, list, get, update, delete, downloadPage |
|
|
337
340
|
| `client.tags` | list, create, update, delete |
|
|
338
341
|
| `client.workspaces` | create, list, get, update, delete, getTheme, downloadLogo, uploadLogo, deleteLogo, getStats |
|
|
@@ -741,6 +744,105 @@ As listagens devolvem `{ data, meta }`, com `meta` preenchido a partir dos heade
|
|
|
741
744
|
`MAX_LIST_PAGE_SIZE` é esse teto; pagine com `page` em vez de pedir páginas maiores, e confie no
|
|
742
745
|
`meta.per_page` mais do que no valor pedido.
|
|
743
746
|
|
|
747
|
+
### Gestão do ciclo de vida de contratos (CLM)
|
|
748
|
+
|
|
749
|
+
A gestão do ciclo de vida de contratos (CLM) acompanha os termos comerciais ligados a um documento
|
|
750
|
+
existente sem mudar como ele é enviado ou assinado. A API de produção suporta o fluxo completo
|
|
751
|
+
abaixo; o sandbox pode demorar a disponibilizar uma rota nova de CLM ou o recurso do plano (veja as
|
|
752
|
+
[notas de compatibilidade](docs/COMPATIBILITY.md#contract-lifecycle-management-clm)).
|
|
753
|
+
|
|
754
|
+
```ts
|
|
755
|
+
// 1. Envie ou selecione o documento do contrato e registre seus termos.
|
|
756
|
+
const documento = await client.documents.upload({ filePath: './contrato.pdf' });
|
|
757
|
+
const contrato = await client.contracts.set(documento.id, {
|
|
758
|
+
status: 'active',
|
|
759
|
+
counterparty_name: 'Empresa Exemplo Ltda',
|
|
760
|
+
counterparty_taxpayer_id: '11.222.333/0001-81',
|
|
761
|
+
value: 120000.50,
|
|
762
|
+
currency: 'BRL',
|
|
763
|
+
start_date: '2026-11-01',
|
|
764
|
+
end_date: '2027-10-31',
|
|
765
|
+
auto_renew: true,
|
|
766
|
+
renewal_term_months: 12,
|
|
767
|
+
notice_period_days: 30,
|
|
768
|
+
metadata: { etapa_crm: 'ganho' },
|
|
769
|
+
external_references: [{ system: 'crm', id: '98765' }],
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
// 2. Leia ou sincronize a carteira. `updated_at` muda após toda alteração.
|
|
773
|
+
const atual = await client.contracts.get(documento.id);
|
|
774
|
+
const vencendo = await client.contracts.list({
|
|
775
|
+
status: ['active'],
|
|
776
|
+
ending_within_days: 30,
|
|
777
|
+
sort: 'end_date',
|
|
778
|
+
expand: 'document',
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
// 3. Envie o valor lido para rejeitar uma edição concorrente com HTTP 409.
|
|
782
|
+
if (atual.resource === 'document_contract') {
|
|
783
|
+
await client.contracts.set(documento.id, {
|
|
784
|
+
notice_period_days: 60,
|
|
785
|
+
updated_at: atual.updated_at,
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// 4. Um aditivo assinado é outro documento ligado ao contrato raiz.
|
|
790
|
+
const aditivo = await client.documents.upload({ filePath: './aditivo.pdf' });
|
|
791
|
+
await client.contracts.set(aditivo.id, {
|
|
792
|
+
parent_document_id: documento.id,
|
|
793
|
+
relation_type: 'amendment',
|
|
794
|
+
value: 130000,
|
|
795
|
+
end_date: '2028-06-30',
|
|
796
|
+
});
|
|
797
|
+
// Envie e assine `aditivo` pelo fluxo normal de assignment. O delta é aplicado
|
|
798
|
+
// ao contrato raiz depois da certificação; consulte a família completa assim:
|
|
799
|
+
const familia = await client.contracts.listRelated(aditivo.id);
|
|
800
|
+
|
|
801
|
+
// 5. Inicie um novo termo diretamente ou encerre o ciclo de vida.
|
|
802
|
+
const renovado = await client.contracts.renew(documento.id, {
|
|
803
|
+
term: familia.term,
|
|
804
|
+
value: 135000,
|
|
805
|
+
updated_at: familia.updated_at,
|
|
806
|
+
});
|
|
807
|
+
await client.contracts.terminate(documento.id, {
|
|
808
|
+
reason: 'Substituído por um novo contrato',
|
|
809
|
+
updated_at: renovado.updated_at,
|
|
810
|
+
});
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
As escritas exigem `documents:write` no OAuth e um plano com gestão de contratos. As leituras
|
|
814
|
+
exigem `documents:read` e continuam disponíveis se o plano deixar de incluir o recurso. O ciclo
|
|
815
|
+
horário emite notificações de aviso de renovação, proximidade do vencimento, vencimento e renovação;
|
|
816
|
+
configure as preferências do responsável e assine os eventos de webhook correspondentes:
|
|
817
|
+
|
|
818
|
+
```ts
|
|
819
|
+
await client.users.updateNotificationPreferences({
|
|
820
|
+
ContractRenewalNotice: true,
|
|
821
|
+
ContractExpiring: true,
|
|
822
|
+
ContractExpired: true,
|
|
823
|
+
ContractRenewed: true,
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
await client.webhooks.createEndpoint({
|
|
827
|
+
url: 'https://exemplo.com.br/webhooks/assinafy',
|
|
828
|
+
email: 'operacoes@exemplo.com.br',
|
|
829
|
+
events: [
|
|
830
|
+
'document_contract_updated',
|
|
831
|
+
'document_contract_renewal_notice',
|
|
832
|
+
'document_contract_expiring',
|
|
833
|
+
'document_contract_expired',
|
|
834
|
+
'document_contract_renewed',
|
|
835
|
+
'document_contract_terminated',
|
|
836
|
+
'document_contract_amended',
|
|
837
|
+
'document_contract_amendment_updated',
|
|
838
|
+
],
|
|
839
|
+
});
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
`set()`, `renew()` e `terminate()` não são repetidos automaticamente. Se a resposta se perder,
|
|
843
|
+
leia o contrato de novo: `updated_at`, o `term` atual e a data explícita de renovação fornecem as
|
|
844
|
+
proteções de concorrência e repetição documentadas pela API.
|
|
845
|
+
|
|
744
846
|
### Signatários
|
|
745
847
|
|
|
746
848
|
```ts
|
|
@@ -868,7 +970,7 @@ que faltar é inferido. Sem nenhum dos dois, ambos assumem `Email`.
|
|
|
868
970
|
| --- | --- | --- | --- |
|
|
869
971
|
| `Email` *(padrão)* | Código de uso único (OTP) por e-mail | `Email` | Gratuito |
|
|
870
972
|
| `Whatsapp` | Código de uso único (OTP) por WhatsApp | `Whatsapp` | 0,45 crédito (a notificação), só em planos pagos |
|
|
871
|
-
| `DigitalCertificate` | O signatário assina com o **próprio certificado ICP-Brasil — A1 ou A3 —** pela extensão Web PKI, gerando uma assinatura **PAdES qualificada
|
|
973
|
+
| `DigitalCertificate` | O signatário assina com o **próprio certificado ICP-Brasil — A1 ou A3 —** pela extensão Web PKI, gerando uma assinatura **PAdES qualificada**; exige `method: 'virtual'` | `Email` **ou** `Whatsapp` | 0,5 crédito + a notificação |
|
|
872
974
|
| `IdDocumentFaceMatchBasic` | Documento de identidade, foto e prova de vida em sessão hospedada | `Email` **ou** `Whatsapp` | Consulte `estimateCost()` |
|
|
873
975
|
|
|
874
976
|
Apenas um método de notificação por signatário. O SDK recusa uma combinação inválida antes da
|
|
@@ -913,9 +1015,16 @@ nem encaminhe fora do fluxo de assinatura.
|
|
|
913
1015
|
|
|
914
1016
|
#### Certificado digital ICP-Brasil
|
|
915
1017
|
|
|
916
|
-
`DigitalCertificate` exige o recurso **Certificado Digital** na conta (planos
|
|
917
|
-
CNPJ em `government_id` do signatário, e exatamente **um signatário por
|
|
918
|
-
assinatura**. Custa 0,5 crédito por signatário, além do custo da
|
|
1018
|
+
`DigitalCertificate` exige `method: 'virtual'`, o recurso **Certificado Digital** na conta (planos
|
|
1019
|
+
Standard e Pro), CPF ou CNPJ em `government_id` do signatário, e exatamente **um signatário por
|
|
1020
|
+
certificado naquele passo de assinatura**. Custa 0,5 crédito por signatário, além do custo da
|
|
1021
|
+
notificação escolhida. O fluxo por certificado conclui o item virtual do signatário; ele não consegue
|
|
1022
|
+
enviar campos posicionados pelo endpoint comum de assinatura `collect`.
|
|
1023
|
+
|
|
1024
|
+
O SDK rejeita signatários por certificado em assignments `collect`, tanto em `create()` quanto em
|
|
1025
|
+
`estimateCost()`, antes de qualquer requisição. Ramifique por
|
|
1026
|
+
`ValidationError.errors.code === 'digital_certificate_requires_virtual_method'`, ou compare com a
|
|
1027
|
+
constante exportada `DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD`; não dependa da mensagem legível.
|
|
919
1028
|
|
|
920
1029
|
**A1 e A3 são mídias de certificado**, escolhidas pelo próprio signatário no navegador na hora de
|
|
921
1030
|
assinar: A1 fica em software (um arquivo na máquina) e A3 em hardware (token ou cartão). A API
|
|
@@ -1015,9 +1124,11 @@ await client.documents.estimateCostFromTemplate(templateId, [
|
|
|
1015
1124
|
// has_sufficient_resources: true, blocking_reason: null, breakdown: [], … }
|
|
1016
1125
|
```
|
|
1017
1126
|
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1127
|
+
O servidor deduz o método do assignment de template a partir dos campos posicionados e hoje aceita
|
|
1128
|
+
signatários por certificado mesmo quando isso cria um assignment `collect` impossível de concluir.
|
|
1129
|
+
Até a API impor atomicamente a regra de método virtual, o SDK rejeita `DigitalCertificate` tanto em
|
|
1130
|
+
`createFromTemplate()` quanto em `estimateCostFromTemplate()`, com o mesmo código estável. Para
|
|
1131
|
+
certificados, crie diretamente um assignment `virtual`.
|
|
1021
1132
|
|
|
1022
1133
|
Criar um template apenas envia o PDF e provisiona o papel de editor padrão — configure papéis e
|
|
1023
1134
|
campos no editor da Assinafy depois. Os `download_url` dos objetos de página do template são URLs
|
|
@@ -1174,9 +1285,10 @@ const preferencias = await client.users.getNotificationPreferences();
|
|
|
1174
1285
|
await client.users.updateNotificationPreferences({
|
|
1175
1286
|
SignerDeclined: false,
|
|
1176
1287
|
DocumentExpired: false,
|
|
1288
|
+
ContractExpiring: true,
|
|
1177
1289
|
});
|
|
1178
1290
|
// A atualização é um merge: chaves omitidas mantêm o valor atual. Os dois
|
|
1179
|
-
// métodos devolvem o mapa completo de
|
|
1291
|
+
// métodos devolvem o mapa completo de treze preferências.
|
|
1180
1292
|
```
|
|
1181
1293
|
|
|
1182
1294
|
#### Autenticação em dois fatores
|