@assinafy/sdk 2.8.1 → 2.9.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 CHANGED
@@ -7,6 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.9.1] - 2026-10-28
11
+
12
+ ### Fixed
13
+
14
+ - Live smoke tests accept all 13 notification preference fields, including the
15
+ four contract lifecycle notification settings.
16
+
17
+ ## [2.9.0] - 2026-10-28
18
+
19
+ ### Added
20
+
21
+ - Contract lifecycle management (CLM) through `client.contracts`: list tracked
22
+ contracts, read terms and related instruments, create or update terms, renew
23
+ a term, and terminate a contract. Request and response types include contract
24
+ status, counterparties, dates, values, owners, metadata, external references,
25
+ amendments, optimistic concurrency, filters, and pagination.
26
+ - Known webhook event types for contract updates, notices, expiration, renewal,
27
+ termination, and signed amendments.
28
+
29
+ ### Changed
30
+
31
+ - User notification preferences include the four contract lifecycle settings:
32
+ `ContractRenewalNotice`, `ContractExpiring`, `ContractExpired`, and
33
+ `ContractRenewed`.
34
+ - Document details expose `has_contract`, `verification_code`, and
35
+ `verification_url`; assignment signing URLs use the exported `ISigningUrl`
36
+ shape.
37
+ - The runtime dependency baseline is Axios 1.21.0.
38
+ - Development and CI use Bun 1.4.4.
39
+
40
+ ### Fixed
41
+
42
+ - Updated `follow-redirects` to 1.16.2 so sensitive headers remain protected
43
+ across redirects, including array-form and regular-expression edge cases.
44
+
10
45
  ## [2.8.1] - 2026-10-19
11
46
 
12
47
  ### Fixed
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 112 operations in the current official OpenAPI document: accounts,
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, templates, tags, fields, webhooks, branding, statistics, and
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), 24 (active LTS), and
56
- 26 (Current); Node 20 reached end-of-life in April 2026 and is unsupported.
57
- - or Bun 1.4.0 (the version pinned for development and CI)
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 112 operations documented at https://api.assinafy.com.br/v1/docs are
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
@@ -1214,9 +1319,10 @@ const preferences = await client.users.getNotificationPreferences();
1214
1319
  await client.users.updateNotificationPreferences({
1215
1320
  SignerDeclined: false,
1216
1321
  DocumentExpired: false,
1322
+ ContractExpiring: true,
1217
1323
  });
1218
1324
  // Updates merge: omitted keys keep their current value. Both methods return
1219
- // the complete nine-key notification preference map.
1325
+ // the complete thirteen-key notification preference map.
1220
1326
  ```
1221
1327
 
1222
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 112 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, templates, tags,
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), 24 (LTS ativo) e 26 (Current). O Node 20
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.0 (versão fixada no desenvolvimento e na CI)
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 112 operações documentadas em https://api.assinafy.com.br/v1/docs estão cobertas. A tabela abaixo
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
@@ -1183,9 +1285,10 @@ const preferencias = await client.users.getNotificationPreferences();
1183
1285
  await client.users.updateNotificationPreferences({
1184
1286
  SignerDeclined: false,
1185
1287
  DocumentExpired: false,
1288
+ ContractExpiring: true,
1186
1289
  });
1187
1290
  // A atualização é um merge: chaves omitidas mantêm o valor atual. Os dois
1188
- // métodos devolvem o mapa completo de nove preferências.
1291
+ // métodos devolvem o mapa completo de treze preferências.
1189
1292
  ```
1190
1293
 
1191
1294
  #### Autenticação em dois fatores