@assinafy/cli 2.6.1 → 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.
Files changed (38) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/README.en.md +50 -20
  3. package/README.md +78 -391
  4. package/THIRD_PARTY_NOTICES.md +1 -1
  5. package/dist/api.cjs +221 -37
  6. package/dist/api.cjs.map +1 -1
  7. package/dist/api.js +220 -37
  8. package/dist/api.js.map +1 -1
  9. package/dist/cli.cjs +352 -75
  10. package/dist/types/api/client.d.ts +2 -0
  11. package/dist/types/api/client.d.ts.map +1 -1
  12. package/dist/types/api/contract-types.d.ts +110 -0
  13. package/dist/types/api/contract-types.d.ts.map +1 -0
  14. package/dist/types/api/index.d.ts +2 -0
  15. package/dist/types/api/index.d.ts.map +1 -1
  16. package/dist/types/api/resources/assignments.d.ts +2 -2
  17. package/dist/types/api/resources/assignments.d.ts.map +1 -1
  18. package/dist/types/api/resources/authentication.d.ts +3 -3
  19. package/dist/types/api/resources/authentication.d.ts.map +1 -1
  20. package/dist/types/api/resources/contracts.d.ts +19 -0
  21. package/dist/types/api/resources/contracts.d.ts.map +1 -0
  22. package/dist/types/api/resources/documents.d.ts +3 -3
  23. package/dist/types/api/resources/documents.d.ts.map +1 -1
  24. package/dist/types/api/resources/webhooks.d.ts +4 -3
  25. package/dist/types/api/resources/webhooks.d.ts.map +1 -1
  26. package/dist/types/api/types.d.ts +69 -18
  27. package/dist/types/api/types.d.ts.map +1 -1
  28. package/dist/types/api/utils.d.ts +3 -1
  29. package/dist/types/api/utils.d.ts.map +1 -1
  30. package/docs/README.md +2 -1
  31. package/docs/api-operations.json +49 -1
  32. package/docs/api-reference.md +1446 -295
  33. package/docs/contracts.md +128 -0
  34. package/docs/documents.md +7 -4
  35. package/docs/oauth-guide.md +5 -5
  36. package/docs/releasing.md +38 -12
  37. package/docs/sdk-reference.md +154 -13
  38. package/package.json +2 -2
package/CONTRIBUTING.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Contributing
2
2
 
3
- Use Node.js 24 LTS for development; Node.js 22.12 and 26 remain CI compatibility
3
+ Use Node.js 26 LTS for development; Node.js 22.12 and 24 remain CI compatibility
4
4
  targets. Install exactly from the lockfile and run the complete local gate:
5
5
 
6
6
  ```bash
package/README.en.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  The official command-line interface and Node.js SDK for the [Assinafy API](https://api.assinafy.com.br/v1/docs), a Brazilian digital-signature platform. Upload PDFs, manage signers, request signatures, track activity history, and download certified documents — from a terminal, a shell script, or an application.
6
6
 
7
- The CLI is a single self-contained executable. It prints human-readable tables by default and structured JSON with `--json`, so the same commands serve both interactive use and automation. The same package exposes a fully typed SDK at `@assinafy/cli/api` covering all 112 published API operations.
7
+ The CLI is a single self-contained executable. It prints human-readable tables by default and structured JSON with `--json`, so the same commands serve both interactive use and automation. The same package exposes a fully typed SDK at `@assinafy/cli/api` covering all 118 published API operations.
8
8
 
9
9
  This document reads top to bottom: install, authenticate, send your first signature request, then understand the model well enough to automate it. The [command reference](#command-reference) and [SDK](#nodejs-sdk) sections near the end are lookup tables you can jump to once the flow makes sense.
10
10
 
@@ -17,20 +17,21 @@ This document reads top to bottom: install, authenticate, send your first signat
17
17
  5. [How signing works](#how-signing-works)
18
18
  6. [The complete owner workflow](#the-complete-owner-workflow)
19
19
  7. [The signer side](#the-signer-side)
20
- 8. [Webhooks](#webhooks)
21
- 9. [Output and scripting](#output-and-scripting)
22
- 10. [Configuration](#configuration)
23
- 11. [Command reference](#command-reference)
24
- 12. [Node.js SDK](#nodejs-sdk)
25
- 13. [Security](#security)
26
- 14. [Development](#development)
27
- 15. [Release](#release)
28
- 16. [Contract boundaries](#contract-boundaries)
29
- 17. [License](#license)
20
+ 8. [Contract tracking (CLM)](#contract-tracking-clm)
21
+ 9. [Webhooks](#webhooks)
22
+ 10. [Output and scripting](#output-and-scripting)
23
+ 11. [Configuration](#configuration)
24
+ 12. [Command reference](#command-reference)
25
+ 13. [Node.js SDK](#nodejs-sdk)
26
+ 14. [Security](#security)
27
+ 15. [Development](#development)
28
+ 16. [Release](#release)
29
+ 17. [Contract boundaries](#contract-boundaries)
30
+ 18. [License](#license)
30
31
 
31
32
  ## Requirements
32
33
 
33
- - Node.js `>=22.12.0`. Node.js 24 LTS is recommended and is what CI publishes with; CI also tests 22 and 26.
34
+ - Node.js `>=22.12.0`. Node.js 26 LTS is recommended and is what CI publishes with; CI also tests 22 and 24.
34
35
  - HTTPS with TLS 1.2 or higher to reach the Assinafy API; supported Node.js versions use that minimum by default.
35
36
  - An Assinafy account and an API key or consented OAuth connection (see [Authentication](#authentication)).
36
37
  - Linux, macOS, or Windows. Release archives ship for `linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`, `windows-x64`, and `windows-arm64`.
@@ -250,7 +251,7 @@ Where email or WhatsApp verification is configured, the signer also confirms a 6
250
251
 
251
252
  For A1/A3 certificates, use Assinafy's hosted signing page or integrate Web PKI with the SDK. After document review and terms acceptance, `signer certificate-start --json` returns `{ "token": "..." }`. Have the browser sign that operation on the signer's device, then set `ASSINAFY_CERTIFICATE_TOKEN` to the same token and run `signer certificate-complete --json`; it returns `{ "signerName": "..." }`. Private keys and passwords/PINs stay on the device. Wait for `certificated` status and download `--artifact pades` or `bundle`. The ordinary `sign` command does not perform this handshake. These two production routes use the signing application's payloads and are not yet OpenAPI paths.
252
253
 
253
- Before estimating or creating a certificate assignment, set the signer's CPF/CNPJ with `signers.update(signerId, { government_id })`, or `assinafy signers update <signerId> --cpf '<signer-CPF-or-CNPJ>'`. The update command sends `government_id`. Creating a signer by email may reuse an existing record without updating it. Each certificate signer needs a matching certificate and an individual signing step.
254
+ Before estimating or creating a certificate assignment, set the signer's CPF/CNPJ with `signers.update(signerId, { government_id })`, or `assinafy signers update <signerId> --government-id '<signer-CPF-or-CNPJ>'`. The update command sends `government_id`. Creating a signer by email may reuse an existing record without updating it. Each certificate signer needs a matching certificate and an individual signing step.
254
255
 
255
256
  For biometrics, create or explicitly update the signer with a valid CPF, estimate cost and create an `IdDocumentFaceMatchBasic` assignment. Present the document, terms and biometric-processing consent, then use the signer's private access code:
256
257
 
@@ -282,6 +283,29 @@ Single-document confirmation, signing, and decline commands verify that the acce
282
283
 
283
284
  Owner API credentials are stripped from every public and signer-side request, so an access-code flow can never leak your workspace key. The published signer artifact download is public; passing `--access-code` adds an identity preflight that confirms the code belongs to the signer being downloaded for.
284
285
 
286
+ ## Contract tracking (CLM)
287
+
288
+ Contract tracking records counterparty, value, dates, renewal settings and signed amendments on an existing document. Upload and signing remain separate. Writes need a plan with contract tracking; reads remain available when that plan lapses. OAuth uses `documents:read` and `documents:write`.
289
+
290
+ Upload the document and persist its ID first. Set draft terms, activate them when lifecycle tracking should begin, and use separate uploaded documents for signed amendments. An amendment's delta applies after certification, in signing order.
291
+
292
+ ```bash
293
+ assinafy documents upload contract.pdf --wait --json
294
+ assinafy contracts set <documentId> --data '{"status":"draft","counterparty_name":"Example Company","value":1200.50,"currency":"BRL","start_date":"2027-01-01","end_date":"2027-12-31","auto_renew":false,"renewal_term_months":12,"notice_period_days":30}'
295
+ assinafy contracts get <documentId> --json
296
+ assinafy contracts set <documentId> --data '{"status":"active","updated_at":"<returned timestamp>"}'
297
+ assinafy contracts list --status active --ending-within-days 30 --expand document --page 1
298
+ assinafy contracts set <amendmentId> --data '{"parent_document_id":"<documentId>","relation_type":"amendment","value":1500}'
299
+ assinafy contracts related <amendmentId> --json
300
+ assinafy contracts renew <documentId> --data '{"term":1,"updated_at":"<returned timestamp>"}'
301
+ assinafy contracts terminate <documentId> --data '{"reason":"Agreed termination","updated_at":"<returned timestamp>"}'
302
+ assinafy documents activities <documentId> --page 2 --sort id
303
+ ```
304
+
305
+ Replace IDs and timestamps with your integration's values. Renew and terminate prompt for confirmation; `--yes` supports automation. Send the `updated_at` from your latest read with each write. A `409 ContractChanged` requires a fresh read and a decision about whether the change still applies. Renewal requires the current `term` or a later `end_date`, preventing a repeated request from renewing twice. The SDK never retries writes automatically.
306
+
307
+ Omitted terms stay unchanged; null clears them, and `external_references` replaces the complete list. On a pending amendment, null removes a proposed change; `parent_document_id: null` unlinks it. Applied amendments are read-only. Hourly lifecycle processing uses Brasília calendar days and may email the contract owner according to notification preferences. A lapsed plan pauses processing. Subscribe explicitly to contract webhook events and reconcile missed changes by paging `contracts list --sort=-updated_at`. See the [complete SDK payloads and responses](docs/sdk-reference.md#contracts-clientcontracts) and [command help](docs/contracts.md).
308
+
285
309
  ## Webhooks
286
310
 
287
311
  Polling works, but webhooks are the right way to react to signing events. A workspace can register 1 webhook endpoint, or up to 3 on paid plans. Each endpoint has its own URL, events, active flag, and signing setting, and every active endpoint subscribed to an event receives it independently.
@@ -306,9 +330,9 @@ assinafy webhooks retry <dispatchId> # redeliver one event
306
330
  assinafy webhooks verify body.json --id <webhook-id> --timestamp <webhook-timestamp> --signature <webhook-signature>
307
331
  ```
308
332
 
309
- Omitting `--events` subscribes to `document_ready`, `document_prepared`, `signer_signed_document`, `signer_rejected_document`, and `document_processing_failed`. `endpoints update` changes only the flags given (`--active`/`--inactive`, `--signing`/`--no-signing`, `--url`, `--email`, `--name`, `--events`); disabling signing discards the secret. `rotate-secret` invalidates the previous secret immediately. A duplicate URL within the workspace returns `400`; creating past the plan limit returns `403`. Secret read and rotation are not available to OAuth applications. `retry` re-sends only to that delivery's endpoint, and only while it is active.
333
+ Omitting `--events` subscribes to `document_ready`, `document_prepared`, `signer_signed_document`, `signer_rejected_document`, and `document_processing_failed`. `endpoints update` changes only the flags given (`--active`/`--inactive`, `--signing`/`--no-signing`, `--url`, `--email`, `--name`, `--events`); disabling signing discards the secret. `rotate-secret` invalidates the previous secret immediately. A duplicate URL within the workspace returns `400`; creating past the plan limit returns `403`. OAuth applications cannot read an existing signing secret; `webhooks:write` permits rotation and returns the new secret. Enabling signing on an existing endpoint also returns the new secret once. New or changed webhook URLs require HTTPS. `retry` re-sends only to that delivery's endpoint, and only while it is active.
310
334
 
311
- Creating a signed endpoint returns `secret` once, including through OAuth; store it securely. The CLI prints it in human and JSON output. OAuth applications that lose it must delete and recreate the endpoint. `endpoints list --url <url>` filters by the exact registered URL; `endpoints delete-by-url --url <url>` deletes by that URL and requires confirmation or `--yes`.
335
+ Creating a signed endpoint returns `secret` once, including through OAuth; store it securely. The CLI prints it in human and JSON output. OAuth applications that lose it can rotate the secret with `webhooks:write` and store the new value. `endpoints list --url <url>` filters by the exact registered URL; `endpoints delete-by-url --url <url>` deletes by that URL and requires confirmation or `--yes`.
312
336
 
313
337
  `webhooks register`, `webhooks get`, and `webhooks inactivate` remain and act on the workspace's oldest endpoint.
314
338
 
@@ -325,7 +349,7 @@ if (!verifier.verifyDelivery(rawBody, headers)) {
325
349
  const event = verifier.extractEvent(rawBody);
326
350
  ```
327
351
 
328
- `verifyDelivery` compares the HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{body}` in constant time and rejects timestamps more than 5 minutes from your clock. Answer with a `2xx` quickly: a failure is retried once after 3 seconds, and 10 consecutive failed events pause the endpoint until a delivery succeeds. `document_ready` means the last signer signed, not that upload processing finished. Treat events as signals and confirm state through the API before irreversible actions.
352
+ `verifyDelivery` compares the HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{body}` in constant time and rejects timestamps more than 5 minutes from your clock. Answer with a `2xx` quickly: connection errors, timeouts, `408`, `429` and `5xx` receive up to six total attempts about ten minutes apart; other failed statuses are final. Ten consecutive failures pause the endpoint until a probe succeeds; missed events then resume oldest first. `document_ready` means the last signer signed, not that upload processing finished. Treat events as signals and confirm state through the API before irreversible actions.
329
353
 
330
354
  ## Output and scripting
331
355
 
@@ -420,7 +444,7 @@ Assinafy runs a **separate sandbox** at `https://sandbox.assinafy.com.br/v1`. It
420
444
 
421
445
  ## Command reference
422
446
 
423
- Run `assinafy <command> --help` for the full flags of any command. Every command's help output is mirrored under [`docs/`](./docs), the [API reference](./docs/api-reference.md) holds the official request/response payloads for all 93 published operations, and the [SDK reference](./docs/sdk-reference.md) maps each SDK method to its operation.
447
+ Run `assinafy <command> --help` for the full flags of any command. Every command's help output is mirrored under [`docs/`](./docs), the [API reference](./docs/api-reference.md) holds the official request/response payloads for all 118 published operations, and the [SDK reference](./docs/sdk-reference.md) maps each SDK method to its operation.
424
448
 
425
449
  Global flags accepted by every command: `--api-key`, `--token`, `--account-id`, `--base-url`, `-p, --profile`, `--json`, `-q, --quiet`. `assinafy -v` prints the version.
426
450
 
@@ -489,6 +513,12 @@ assinafy assignments reset-expiration doc_123 asg_1 --expires-at "2026-12-31T23:
489
513
 
490
514
  `list [--search] [--sort]` · `get <id>` · `download-page <templateId> <pageId> [-o] [--force]`
491
515
 
516
+ ### `contracts`
517
+
518
+ `list` · `get <documentId>` · `set <documentId> --data <json>` · `related <documentId>` · `renew <documentId> --data <json> [-y]` · `terminate <documentId> [--data <json>] [-y]`
519
+
520
+ List filters, complete JSON payloads, conflict handling and lifecycle behavior are in [Contract tracking](#contract-tracking-clm) and the [SDK reference](docs/sdk-reference.md#contracts-clientcontracts).
521
+
492
522
  ### `tags`
493
523
 
494
524
  `list [--search]` · `create --name [--color]` · `update <id> [--name] [--color] [--clear-color]` · `delete <id> [--force] [-y]`
@@ -519,7 +549,7 @@ Field definitions are what `--method collect` assignments gather. Run `fields ty
519
549
 
520
550
  `document <signerId>` · `documents <signerId>` · `search <signerId> <query>` · `download <signerId> <documentId> <artifact>` · `self` · `accept-terms` · `verify-code --code` (alias `verify-email`) · `certificate-start` · `certificate-complete --certificate-token` · `confirm-data <documentId>` · `upload-signature --file` · `download-signature` · `assignment` · `sign <documentId> <assignmentId> --entries` · `decline <documentId> <assignmentId> --reason` · `sign-multiple --document-ids` · `decline-multiple --document-ids --reason`
521
551
 
522
- Every signer command except the public artifact `download` requires `--access-code <code>`; `download` accepts it optionally for an identity preflight. Use `ASSINAFY_SIGNER_ACCESS_CODE` to keep the code out of process arguments.
552
+ `documents` and `search` use owner authentication when `--access-code` is omitted. The public artifact `download` accepts it optionally for an identity preflight. Other signer commands require `--access-code <code>`. Use `ASSINAFY_SIGNER_ACCESS_CODE` to keep the code out of process arguments.
523
553
 
524
554
  ### `auth`
525
555
 
@@ -617,9 +647,9 @@ The [release runbook](./docs/releasing.md) covers tags, trusted publishing, and
617
647
 
618
648
  ## Contract boundaries
619
649
 
620
- - The production OpenAPI publishes 112 operations and the SDK implements all of them. Sandbox deployments can lag individual routes — account/user statistics and user notification preferences may return route-level 404s there despite being documented in production.
650
+ - The production OpenAPI publishes 118 operations and the SDK implements all of them. Sandbox deployments can lag individual routes — account/user statistics and user notification preferences may return route-level 404s there despite being documented in production.
621
651
  - The SDK keeps two platform-compatible template routes (`GET /accounts/{id}/templates/{id}` and its page download) that are absent from the published OpenAPI paths.
622
- - Certificate start/complete are deployed production extensions of the public signing frontend, exposed as `signerDocuments.startCertificate(accessCode)` and `signerDocuments.completeCertificate(accessCode, token)`. Start posts `{ "signer-access-code": code }` and returns `{ token }`; complete posts `{ "signer-access-code": code, token }` and returns `{ signerName }`. Both also carry the access code in the query string and strip owner credentials. They supplement, but are not part of, the 112 OpenAPI operations.
652
+ - Certificate start/complete are deployed production extensions of the public signing frontend, exposed as `signerDocuments.startCertificate(accessCode)` and `signerDocuments.completeCertificate(accessCode, token)`. Start posts `{ "signer-access-code": code }` and returns `{ token }`; complete posts `{ "signer-access-code": code, token }` and returns `{ signerName }`. Both also carry the access code in the query string and strip owner credentials. They supplement, but are not part of, the 118 OpenAPI operations.
623
653
  - `send-token` sends the email-only body `{ "channel": "email", "recipient": "..." }`; WhatsApp and the older `{ "email" }` body are rejected by the API with `400`.
624
654
  - `signer documents` and `signer search` accept the workspace API key or token when `--access-code` is omitted.
625
655
  - Webhook signatures follow Standard Webhooks; `WebhookVerifier.verifyDelivery` implements the published scheme. The older `verify(body, signature)` method is deprecated and does not match Assinafy deliveries.