@assinafy/cli 2.1.2 → 2.2.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.
@@ -1,6 +1,6 @@
1
1
  # TypeScript SDK reference
2
2
 
3
- The Node.js SDK is published with the CLI and requires Node.js `>=22.12.0` (Node.js 24 LTS is recommended). Responses containing Assinafy's `{ status, message, data }` envelope resolve to `data`; documented delete responses therefore resolve to `IEmptyResult` (`unknown[]`). Operations whose response has no `data` preserve the direct `IStatusResponse` (`{ status, message }`) body. `sendToken` preserves either that published body or the live legacy `{ document, channel, recipient }` body.
3
+ The Node.js SDK is published with the CLI and requires Node.js `>=22.12.0` (Node.js 24 LTS is recommended). Responses containing Assinafy's `{ status, message, data }` envelope resolve to `data`; operations with empty result data resolve to `IEmptyResult` (`unknown[]`). Responses without `data` remain unchanged, including direct `IStatusResponse` (`{ status, message }`) bodies. `sendToken` preserves either that published body or the production `{ document, channel, recipient }` body.
4
4
 
5
5
  The [API request/response reference](./api-reference.md) is the canonical source for every published HTTP payload and example. Complete TypeScript declarations are exported and packaged with `@assinafy/cli/api`.
6
6
 
@@ -149,13 +149,13 @@ interface IDocumentUploadOptions {
149
149
  }
150
150
  ```
151
151
 
152
- Uploads must be non-empty PDFs up to 25 MiB. `DocumentArtifactName` is `original | certificated | certificate-page | pades | bundle`; `bundle` is ZIP and the other document artifacts are PDF. Prefer the published `sendToken(documentId, { email })` form. The current sandbox rejects that form with HTTP 400, so use the string overload there; it sends the live-compatible legacy `{ recipient, channel }` body for email or WhatsApp integrations that still require it.
152
+ Uploads must be non-empty PDFs up to 25 MiB. `DocumentArtifactName` is `original | certificated | certificate-page | pades | bundle`; `bundle` is ZIP and the other document artifacts are PDF. For production email delivery, use `sendToken(documentId, 'signer@example.com', 'email')`, which sends `{ recipient, channel }`. The `{ email }` overload preserves the published request form for deployments that support it.
153
153
 
154
154
  Template document creation sends `{ signers, name?, message?, expires_at?, editor_fields?, tags? }`. Each signer is `{ role_id, id, verification_method?, notification_methods?, step? }`; each editor field is `{ field_id, value: string }`. Template cost estimation publishes `{ signers: Array<{ role_id, verification_method?, notification_methods? }> }`. The optional cost-signer `id` and `step` properties remain compatibility extensions for existing integrations.
155
155
 
156
156
  Document list params are `{ page?, per_page?, status?, method?, tags?, search?, sort? }`; search params omit `method`/`tags`. Supported sort values are `name`, `-name`, `updated_at`, and `-updated_at`.
157
157
 
158
- `replaceTags` and `addTags` take tag IDs, as required by the published request bodies. Values are still forwarded unchanged for compatibility with deployments that accept tag names; new integrations should use IDs from `client.tags.list()`.
158
+ In production, `replaceTags` and `addTags` accept tag names, reuse matching tags, and create missing names. Use `replaceTags(documentId, ['Contracts'])` or `addTags(documentId, ['Contracts'])`; an empty replacement removes all associations. Values are sent unchanged. Pass the tag ID from `listTags` to `detachTag`. Document-list tag filters also use IDs.
159
159
 
160
160
  Document responses expose typed `IDocumentArtifacts`, `IDocumentPage`, inline tags, assignment/signing state, decline state, and creation/update timestamps. `IPublicDocumentInfo` models the complete published public-document payload while retaining the older optional `page_count` and `created_by` fields.
161
161
 
@@ -192,8 +192,23 @@ Assignment payload:
192
192
  }
193
193
  ```
194
194
 
195
+ Production defaults `notification_methods: []` to `['Email']` and sends an invitation. An empty array is not a way to disable delivery. Choose the intended supported channel explicitly before creating an assignment.
196
+
195
197
  `buildAssignmentPayload(payload, options?)` is exported for callers that need the same normalization. It resolves synchronously to the JSON assignment body above; no HTTP call occurs. Options are `{ allowSignersWithoutId?: boolean; allowEmptySigners?: boolean; skipDigitalCertificateStepValidation?: boolean }`, all false by default. The first two support cost estimation; the third bypasses signing-order and certificate-step checks for estimates. `allowEmptySigners` applies only to `collect`. `create` requires at least one signer, enforces complete contiguous signing steps from 1 when supplied, and requires each digital-certificate signer to be alone in its step. The estimate schema has no `step`, so `estimateCost` does not apply that create-only rule and permits zero signers for `collect`. Assignment list params are pagination plus the compatible `sort?: 'created_at' | '-created_at'`; the runtime endpoint requires the SDK's `accountId` query even though the published parameter table omits it. Assignment `search` is unsupported and rejected locally.
196
198
 
199
+ `estimateResendCost(documentId, assignmentId, signerId)` sends a POST without a body. Its production result is:
200
+
201
+ ```json
202
+ {
203
+ "total": 0,
204
+ "breakdown": [{ "code": "NotificationEmailResend", "name": "Email Notification Resend", "cost": 0 }],
205
+ "credit_balance": 0,
206
+ "has_sufficient_credits": true
207
+ }
208
+ ```
209
+
210
+ `IResendCostEstimate` also accepts the published `IEstimateCostResponse` shape. Check `'total' in estimate` to select the production shape; use its `has_sufficient_credits` before resending. The published shape uses `total_credits` and `has_sufficient_resources`.
211
+
197
212
  ## Signers (`client.signers`)
198
213
 
199
214
  | SDK method | HTTP operation | Resolves to |
@@ -209,7 +224,7 @@ Create payload: `{ full_name: string; email?; whatsapp_phone_number?; phone?; cp
209
224
 
210
225
  ## Signer-side flows (`client.signerDocuments`)
211
226
 
212
- These methods use the one-time `signer-access-code`, not the workspace API key, except for the artifact download that the API publishes as a public route.
227
+ These methods use the private `signer-access-code`, not the workspace API key, except for the artifact download that the API publishes as a public route. For email verification, obtain the access code from the verification link and the OTP from the same email. An invitation containing only a document ID and recipient is not an access code. Call `self` and `getAssignment` to confirm the signer and document before submitting a decision; keep each document's verification credentials together.
213
228
 
214
229
  | SDK method | HTTP operation | Resolves to |
215
230
  | --- | --- | --- |
@@ -220,10 +235,13 @@ These methods use the one-time `signer-access-code`, not the workspace API key,
220
235
  | `signMultiple(documentIds, accessCode)` | [`PUT /signers/documents/sign-multiple`](./api-reference.md#sign-multiple-documents) | `unknown[]` |
221
236
  | `declineMultiple(documentIds, reason, accessCode)` | [`PUT /signers/documents/decline-multiple`](./api-reference.md#decline-multiple-documents) | `unknown[]` |
222
237
  | `self(accessCode)` | [`GET /signers/self`](./api-reference.md#get-current-signer) | `ISignerSelf` |
223
- | `acceptTerms(accessCode)` | [`PUT /signers/accept-terms`](./api-reference.md#accept-terms-signer) | `IStatusResponse` |
224
- | `verifyEmail({ signerAccessCode, verificationCode })` | [`POST /verify`](./api-reference.md#verify-signer-code-otp) | `IStatusResponse` |
225
- | `confirmData(documentId, accessCode, payload)` | [`PUT /documents/{documentId}/signers/confirm-data`](./api-reference.md#confirm-signer-data) | `ISigner` |
226
- | `uploadSignature(accessCode, image, options?)` | [`POST /signature`](./api-reference.md#upload-signature-image) | `IStatusResponse` |
238
+ | `acceptTerms(accessCode)` | [`PUT /signers/accept-terms`](./api-reference.md#accept-terms-signer) | `ISignerTermsAcceptance \| IStatusResponse` |
239
+ | `verifyCode(payload: IVerifySignerCodePayload)` | [`POST /verify`](./api-reference.md#verify-signer-code-otp); email or WhatsApp OTP | `IEmptyResult \| IStatusResponse` |
240
+ | `verifyEmail(payload: IVerifySignerCodePayload)` | Compatibility alias for `verifyCode` | `IEmptyResult \| IStatusResponse` |
241
+ | `startCertificate(accessCode)` | [`POST /signers/certificate/start`](#icp-brasil-a1a3-certificates) | `ICertificateStartResponse` (`{ token: string }`) |
242
+ | `completeCertificate(accessCode, token)` | [`POST /signers/certificate/complete`](#icp-brasil-a1a3-certificates) | `ICertificateCompleteResponse` (`{ signerName: string }`) |
243
+ | `confirmData(documentId, accessCode, payload)` | [`PUT /documents/{documentId}/signers/confirm-data`](./api-reference.md#confirm-signer-data) | `ISigner \| IEmptyResult` |
244
+ | `uploadSignature(accessCode, image, options?)` | [`POST /signature`](./api-reference.md#upload-signature-image) | `IEmptyResult \| IStatusResponse` |
227
245
  | `downloadSignature(accessCode, imageType?)` | [`GET /signature/{type}`](./api-reference.md#download-signature-image) | `Buffer` |
228
246
  | `getAssignment(accessCode, hasAcceptedTerms?)` | [`GET /sign`](./api-reference.md#view-document-to-sign) | `IDocumentDetailsResponse` |
229
247
  | `sign(documentId, assignmentId, accessCode, entries)` | [`POST /documents/{documentId}/assignments/{assignmentId}`](./api-reference.md#sign-assignment-items) | `Record<string, unknown>` |
@@ -231,8 +249,105 @@ These methods use the one-time `signer-access-code`, not the workspace API key,
231
249
 
232
250
  `confirmData` accepts `{ full_name?, email?, government_id?, whatsapp_phone_number?, has_accepted_terms? }`. `uploadSignature` accepts a non-empty image `Buffer` plus `{ imageType?: 'signature' | 'initial'; contentType?: string; reuse?: boolean }`. Each signing entry is `{ itemId, fieldId, pageId, value }`.
233
251
 
252
+ `confirmData`, `sign`, and `decline` first load `getAssignment(accessCode)` and reject a mismatched document or assignment before writing. These methods make one additional GET request. For virtual assignments, confirm the signer's data and then call `sign(documentId, assignmentId, accessCode, [])`. Collect assignments require a non-empty array with the actual assignment item, field, and page IDs. Signing resolves to the server's assignment result; poll document details until `certificated` before downloading final artifacts.
253
+
254
+ Each request below includes `?signer-access-code=<private-access-code>`. These are complete example bodies and SDK results for production:
255
+
256
+ | Operation | Request body | SDK result |
257
+ | --- | --- | --- |
258
+ | `PUT /signers/accept-terms` | No body; submit only after the signer accepts the terms. | `{ "full_name": "Ana Lima", "email": "ana@example.com", "has_accepted_terms": true }` (`email` may be `null`) |
259
+ | `POST /verify` | `{ "verification-code": "123456" }` | `[]` |
260
+ | `PUT /documents/{documentId}/signers/confirm-data` | `{ "full_name": "Ana Lima", "email": "ana@example.com" }` | `[]` |
261
+ | `POST /signature` | Raw PNG bytes with `Content-Type: image/png`; also pass `type=signature&reuse=false` in the query. | `[]` |
262
+
263
+ An empty result is successful acknowledgement, not a signer profile. Use `self(accessCode)` afterward when you need the updated profile, terms acceptance, or signature flags. The response types retain the published status/profile alternatives without converting or fabricating response fields.
264
+
234
265
  The artifact `download` route is public in the published API. If `accessCode` is supplied, the SDK first verifies it through `/signers/self` and confirms that it belongs to the requested signer before downloading.
235
266
 
267
+ ### Email and WhatsApp verification
268
+
269
+ Assignment and template signer descriptors use the same combinations:
270
+
271
+ | `verification_method` | `notification_methods` | Signer requirement |
272
+ | --- | --- | --- |
273
+ | `Email` | `["Email"]` | Email address |
274
+ | `Whatsapp` | `["Whatsapp"]` | `whatsapp_phone_number` and an eligible paid workspace |
275
+ | `DigitalCertificate` (A1 or A3) | `["Email"]` or `["Whatsapp"]` | CPF/CNPJ in `government_id`, matching certificate, delivery contact, and the Digital Certificate workspace feature |
276
+
277
+ Choose one notification channel. With neither field specified, the API defaults to Email; with only one specified, it infers the other. Estimate cost before creating assignments, including those created from templates: WhatsApp notifications and certificate signatures consume credits. Each certificate signer must be alone in its signing step.
278
+
279
+ `IVerifySignerCodePayload` is `{ signerAccessCode: string; verificationCode: string }`. Keep the OTP as a string to preserve leading zeroes. Email and WhatsApp use the same verification endpoint and response; the access code identifies the channel and document.
280
+
281
+ ```ts
282
+ // Choose the channel configured for this signer; these calls send messages.
283
+ await client.documents.sendToken('example_document', 'signer@example.com', 'email');
284
+ await client.documents.sendToken('example_document', '+5500000000000', 'whatsapp');
285
+
286
+ // Use the private link and OTP from the selected channel's same message.
287
+ await client.signerDocuments.verifyCode({
288
+ signerAccessCode: 'example_access_code',
289
+ verificationCode: '012345',
290
+ }); // [] on production success
291
+ ```
292
+
293
+ The delivery request bodies are `{ "recipient": "signer@example.com", "channel": "email" }` and `{ "recipient": "+5500000000000", "channel": "whatsapp" }`. `sendToken` preserves the response forms documented in [Documents](#documents-clientdocuments). Verification sends `{ "verification-code": "012345" }` with `?signer-access-code=example_access_code`; a successful envelope `{ "status": 200, "message": "", "data": [] }` resolves to `[]`. Invalid codes surface as `ApiError` with the server's status and message. `verifyEmail` remains a compatible alias. Continue with data confirmation and virtual/collect signing as described above.
294
+
295
+ ### ICP-Brasil A1/A3 certificates
296
+
297
+ Both A1 and A3 use `verification_method: "DigitalCertificate"`; they are not separate API method names. Assinafy's [signing documentation](https://api.assinafy.com.br/v1/docs) directs these signers to the certificate handshake. The two routes below follow the deployed [Assinafy signing application](https://app.assinafy.com.br), which supplies their request and response shapes; they are not yet OpenAPI paths and availability on other deployments may differ.
298
+
299
+ 1. Create or select the signer and set their CPF/CNPJ with `signers.update(signerId, { government_id })`. An existing signer returned by `create` is reused without updating their data. Configure an eligible workspace, estimate cost, then create the assignment with `DigitalCertificate` and one delivery channel. Use contiguous steps beginning at `1`, with each certificate signer alone in their step. The same descriptor works for template roles.
300
+ 2. Obtain the private signer access code through the delivered link. Load `self` and `getAssignment` to confirm the identity and document. Present the document and terms; call `acceptTerms` only after the signer agrees.
301
+ 3. Call `startCertificate(accessCode)` and retain its operation token with that signer session.
302
+ 4. On the signer's device, use an initialized Web PKI browser client to select their A1 certificate or A3 device and execute `pki.signWithRestPki({ thumbprint, token })`. Wait for its success callback. The private key, PFX password, and device PIN stay with the local certificate provider.
303
+ 5. Call `completeCertificate(accessCode, token)` with the **same operation token**, only after Web PKI succeeds. This returns the certificate signer's name. The API validates the certificate against the required CPF/CNPJ; normal `sign` and `signMultiple` do not perform certificate signing.
304
+ 6. Track document status until `certificated`, then download `pades` or `bundle`. The PAdES artifact exists only for documents with certificate signatures.
305
+
306
+ The SDK exposes the server handshake. Browser certificate selection, the Web PKI extension/native component, and signer approval belong to the signing application. For the hosted experience, use the Assinafy signing page reached through the invitation; no separate CLI certificate driver is required.
307
+
308
+ `startCertificate` sends this complete request, with no owner API key or bearer token:
309
+
310
+ ```http
311
+ POST /v1/signers/certificate/start?signer-access-code=example_access_code
312
+ Content-Type: application/json
313
+
314
+ { "signer-access-code": "example_access_code" }
315
+ ```
316
+
317
+ Example HTTP 200 response:
318
+
319
+ ```json
320
+ { "status": 200, "message": "", "data": { "token": "example_operation_token" } }
321
+ ```
322
+
323
+ The SDK unwraps it to `ICertificateStartResponse`: `{ token: "example_operation_token" }`.
324
+
325
+ After the browser signs the operation, `completeCertificate` sends:
326
+
327
+ ```http
328
+ POST /v1/signers/certificate/complete?signer-access-code=example_access_code
329
+ Content-Type: application/json
330
+
331
+ { "signer-access-code": "example_access_code", "token": "example_operation_token" }
332
+ ```
333
+
334
+ Example HTTP 200 response:
335
+
336
+ ```json
337
+ { "status": 200, "message": "", "data": { "signerName": "Example Signer" } }
338
+ ```
339
+
340
+ The SDK unwraps it to `ICertificateCompleteResponse`: `{ signerName: "Example Signer" }`. Both methods reject empty credentials locally and propagate server errors through the shared `ApiError` contract. They do not retry the operation automatically. An expired access code, unsigned token, certificate mismatch, unavailable feature, or failed signing step must be resolved before continuing; inspect the document after an ambiguous network failure.
341
+
342
+ CLI equivalents use `ASSINAFY_SIGNER_ACCESS_CODE` and `ASSINAFY_CERTIFICATE_TOKEN` to keep credentials out of command arguments:
343
+
344
+ ```bash
345
+ assinafy signer certificate-start --json
346
+ # Let Web PKI sign the returned token, then supply that same token securely.
347
+ assinafy signer certificate-complete --json
348
+ assinafy documents download example_document --artifact pades -o signed-pades.pdf
349
+ ```
350
+
236
351
  ## Workspaces (`client.workspaces`)
237
352
 
238
353
  | SDK method | HTTP operation | Resolves to |
@@ -436,6 +551,6 @@ Assinafy's published API does **not** define a signature header, algorithm, dige
436
551
  ## Contract boundaries
437
552
 
438
553
  - Production OpenAPI currently publishes 93 operations. Some sandbox deployments lag it; account/user statistics and user notification-preference routes may return route-level 404s even though production documentation includes them.
439
- - The API's digital-certificate description mentions certificate start/complete routes that are not defined as OpenAPI paths. The SDK does not invent undocumented request/response contracts for them.
554
+ - Certificate start/complete are deployed production extensions, exposed by `startCertificate` and `completeCertificate` with the signing application's payloads. They supplement the 93 OpenAPI operations; the API manifest contains only published paths.
440
555
  - The SDK retains the two template compatibility routes above and both published/legacy public `sendToken` payloads for compatible deployments.
441
556
  - Signer artifact downloads are public in the published contract. Supplying a signer access code opts into an SDK identity preflight; it does not change the server route into a private endpoint.
package/docs/signer.md CHANGED
@@ -17,7 +17,9 @@ Commands:
17
17
  download [options] <signerId> <documentId> <artifact> Download a signer document artifact
18
18
  self [options] Fetch the signer's own profile
19
19
  accept-terms [options] Accept the platform terms as the signer
20
- verify-email [options] Verify the email OTP for a signer
20
+ verify-code|verify-email [options] Verify an email or WhatsApp OTP for a signer
21
+ certificate-start [options] Start an ICP-Brasil A1/A3 signature and return the Web PKI token
22
+ certificate-complete [options] Complete an ICP-Brasil A1/A3 signature after Web PKI has signed the token
21
23
  confirm-data [options] <documentId> Confirm a signer's contact data
22
24
  upload-signature [options] Upload the signer's signature or initial image
23
25
  download-signature [options] Download the signer's signature or initial image
@@ -124,12 +126,12 @@ Options:
124
126
  -h, --help display help for command
125
127
  ```
126
128
 
127
- ### `assinafy signer verify-email`
129
+ ### `assinafy signer verify-code`
128
130
 
129
131
  ```text
130
- Usage: assinafy signer verify-email [options]
132
+ Usage: assinafy signer verify-code|verify-email [options]
131
133
 
132
- Verify the email OTP for a signer
134
+ Verify an email or WhatsApp OTP for a signer
133
135
 
134
136
  Options:
135
137
  --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
@@ -137,6 +139,33 @@ Options:
137
139
  -h, --help display help for command
138
140
  ```
139
141
 
142
+ ### `assinafy signer certificate-start`
143
+
144
+ ```text
145
+ Usage: assinafy signer certificate-start [options]
146
+
147
+ Start an ICP-Brasil A1/A3 signature and return the Web PKI token
148
+
149
+ Options:
150
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
151
+ -h, --help display help for command
152
+ ```
153
+
154
+ ### `assinafy signer certificate-complete`
155
+
156
+ ```text
157
+ Usage: assinafy signer certificate-complete [options]
158
+
159
+ Complete an ICP-Brasil A1/A3 signature after Web PKI has signed the token
160
+
161
+ Options:
162
+ --access-code <code> Signer access code (env:
163
+ ASSINAFY_SIGNER_ACCESS_CODE)
164
+ --certificate-token <token> Operation token returned by certificate-start
165
+ (env: ASSINAFY_CERTIFICATE_TOKEN)
166
+ -h, --help display help for command
167
+ ```
168
+
140
169
  ### `assinafy signer confirm-data`
141
170
 
142
171
  ```text
@@ -217,7 +246,8 @@ Arguments:
217
246
 
218
247
  Options:
219
248
  --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
220
- --entries <json> JSON array of { itemId, fieldId, pageId, value } entries
249
+ --entries <json> JSON array of { itemId, fieldId, pageId, value }
250
+ entries; use [] for virtual assignments
221
251
  -h, --help display help for command
222
252
  ```
223
253
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assinafy/cli",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "The official command-line interface for the Assinafy digital-signature API",
5
5
  "license": "MIT",
6
6
  "type": "module",