@assinafy/cli 1.0.2 → 2.0.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 (69) hide show
  1. package/README.md +86 -38
  2. package/THIRD_PARTY_NOTICES.md +972 -0
  3. package/dist/api.cjs +1965 -0
  4. package/dist/api.cjs.map +1 -0
  5. package/dist/api.js +1909 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/cli.cjs +3018 -1560
  8. package/dist/types/api/client.d.ts +88 -0
  9. package/dist/types/api/client.d.ts.map +1 -0
  10. package/dist/types/api/errors.d.ts +28 -0
  11. package/dist/types/api/errors.d.ts.map +1 -0
  12. package/dist/types/api/index.d.ts +21 -0
  13. package/dist/types/api/index.d.ts.map +1 -0
  14. package/dist/types/api/resources/assignments.d.ts +39 -0
  15. package/dist/types/api/resources/assignments.d.ts.map +1 -0
  16. package/dist/types/api/resources/authentication.d.ts +55 -0
  17. package/dist/types/api/resources/authentication.d.ts.map +1 -0
  18. package/dist/types/api/resources/base.d.ts +35 -0
  19. package/dist/types/api/resources/base.d.ts.map +1 -0
  20. package/dist/types/api/resources/documents.d.ts +124 -0
  21. package/dist/types/api/resources/documents.d.ts.map +1 -0
  22. package/dist/types/api/resources/fields.d.ts +57 -0
  23. package/dist/types/api/resources/fields.d.ts.map +1 -0
  24. package/dist/types/api/resources/signer-documents.d.ts +72 -0
  25. package/dist/types/api/resources/signer-documents.d.ts.map +1 -0
  26. package/dist/types/api/resources/signers.d.ts +25 -0
  27. package/dist/types/api/resources/signers.d.ts.map +1 -0
  28. package/dist/types/api/resources/tags.d.ts +37 -0
  29. package/dist/types/api/resources/tags.d.ts.map +1 -0
  30. package/dist/types/api/resources/templates.d.ts +21 -0
  31. package/dist/types/api/resources/templates.d.ts.map +1 -0
  32. package/dist/types/api/resources/users.d.ts +14 -0
  33. package/dist/types/api/resources/users.d.ts.map +1 -0
  34. package/dist/types/api/resources/webhooks.d.ts +17 -0
  35. package/dist/types/api/resources/webhooks.d.ts.map +1 -0
  36. package/dist/types/api/resources/workspaces.d.ts +32 -0
  37. package/dist/types/api/resources/workspaces.d.ts.map +1 -0
  38. package/dist/types/api/support/webhook-verifier.d.ts +43 -0
  39. package/dist/types/api/support/webhook-verifier.d.ts.map +1 -0
  40. package/dist/types/api/types.d.ts +926 -0
  41. package/dist/types/api/types.d.ts.map +1 -0
  42. package/dist/types/api/utils.d.ts +34 -0
  43. package/dist/types/api/utils.d.ts.map +1 -0
  44. package/docs/README.md +9 -1
  45. package/docs/api-operations.json +718 -0
  46. package/docs/api-reference.md +7228 -0
  47. package/docs/assignments.md +21 -1
  48. package/docs/auth.md +28 -12
  49. package/docs/config.md +0 -1
  50. package/docs/docs.md +0 -1
  51. package/docs/documents.md +45 -6
  52. package/docs/fields.md +4 -2
  53. package/docs/login.md +0 -1
  54. package/docs/logout.md +0 -1
  55. package/docs/migration-v2.md +20 -0
  56. package/docs/releasing.md +42 -0
  57. package/docs/sdk-reference.md +344 -0
  58. package/docs/send.md +1 -2
  59. package/docs/signer.md +44 -19
  60. package/docs/signers.md +2 -3
  61. package/docs/tags.md +0 -1
  62. package/docs/templates.md +3 -3
  63. package/docs/users.md +85 -0
  64. package/docs/webhooks.md +1 -16
  65. package/docs/whoami.md +0 -1
  66. package/docs/workspaces.md +109 -10
  67. package/install.ps1 +117 -13
  68. package/install.sh +165 -30
  69. package/package.json +37 -16
@@ -0,0 +1,344 @@
1
+ # TypeScript SDK reference
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.
4
+
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
+
7
+ ## Install and import
8
+
9
+ ```bash
10
+ npm install @assinafy/cli
11
+ ```
12
+
13
+ ES modules:
14
+
15
+ ```ts
16
+ import { AssinafyClient, ApiError } from '@assinafy/cli/api';
17
+
18
+ const client = new AssinafyClient({
19
+ apiKey: process.env.ASSINAFY_API_KEY!,
20
+ accountId: process.env.ASSINAFY_ACCOUNT_ID!,
21
+ });
22
+ ```
23
+
24
+ CommonJS:
25
+
26
+ ```js
27
+ const { AssinafyClient, ApiError } = require('@assinafy/cli/api');
28
+
29
+ const client = AssinafyClient.create(
30
+ process.env.ASSINAFY_API_KEY,
31
+ process.env.ASSINAFY_ACCOUNT_ID,
32
+ );
33
+ ```
34
+
35
+ For the sandbox, add `baseUrl: 'https://sandbox.assinafy.com.br/v1'`. Create an unauthenticated client only for public or signer-access-code endpoints:
36
+
37
+ ```ts
38
+ const publicClient = new AssinafyClient({ allowUnauthenticated: true });
39
+ ```
40
+
41
+ ## Client
42
+
43
+ `AssinafyClientOptions`:
44
+
45
+ | Field | Type | Behavior |
46
+ | --- | --- | --- |
47
+ | `apiKey` | `string` | Preferred credential; sent as `X-Api-Key`. |
48
+ | `token` | `string` | JWT fallback; sent as `Authorization: Bearer`. `apiKey` wins when both are set. |
49
+ | `accountId` | `string` | Default for account-scoped methods; most methods also accept an override. |
50
+ | `baseUrl` | `string` | HTTPS URL; defaults to `https://api.assinafy.com.br/v1`. Redirects are rejected. |
51
+ | `allowInsecureHttp` | `boolean` | Explicit opt-in for isolated local development only. |
52
+ | `timeout` | `number` | Request timeout in milliseconds; default `30_000`. |
53
+ | `logger` | `Logger` | Optional `debug`/`info`/`warn`/`error` functions; otherwise no-op. |
54
+ | `allowUnauthenticated` | `boolean` | Permit construction without `apiKey`/`token`; use only for public and signer-code flows. |
55
+ | `webhookSecret` | `string` | Used only by the experimental `webhookVerifier`; see [Webhook verification](#webhook-verification-experimental). |
56
+
57
+ | API | Result |
58
+ | --- | --- |
59
+ | `new AssinafyClient(options: AssinafyClientOptions)` | Client with `documents`, `signers`, `workspaces`, `assignments`, `webhooks`, `templates`, `tags`, `auth`, `fields`, `users`, `signerDocuments`, and `webhookVerifier`. |
60
+ | `AssinafyClient.create(apiKey, accountId, options?)` | Convenience constructor. |
61
+ | `AssinafyClient.fromConfig(config: ClientConfigInput)` | Accepts snake-case or camel-case configuration keys. |
62
+ | `client.uploadAndRequestSignatures(options)` | Uploads a PDF, optionally waits for processing, creates/reuses signers, and creates a virtual assignment; returns `IUploadAndRequestSignaturesResult`. |
63
+ | `client.getAxiosInstance()` | Underlying `AxiosInstance` for interceptors or endpoints not represented by the SDK. |
64
+
65
+ `uploadAndRequestSignatures` accepts:
66
+
67
+ ```ts
68
+ {
69
+ source: DocumentUploadSource;
70
+ signers: Array<{
71
+ name: string;
72
+ email?: string;
73
+ whatsapp_phone_number?: string;
74
+ phone?: string;
75
+ cpf?: string;
76
+ metadata?: Record<string, unknown>;
77
+ verification_method?: 'Email' | 'Whatsapp' | 'DigitalCertificate';
78
+ notification_methods?: Array<'Email' | 'Whatsapp'>;
79
+ step?: number;
80
+ }>;
81
+ message?: string;
82
+ metadata?: Record<string, unknown>;
83
+ waitForReady?: boolean;
84
+ expiresAt?: string;
85
+ copyReceivers?: string[];
86
+ accountId?: string;
87
+ }
88
+ ```
89
+
90
+ It resolves to `{ document: IDocumentUploadResponse; assignment: IAssignment; signer_ids: string[] }`. A phone-only signer defaults to WhatsApp verification and notification unless those controls are supplied explicitly. The workflow is not transactional: if a later step fails, previously created documents/signers remain available for caller-directed cleanup.
91
+
92
+ ## Documents (`client.documents`)
93
+
94
+ | SDK method | HTTP operation | Resolves to |
95
+ | --- | --- | --- |
96
+ | `upload(source, options?)` | [`POST /accounts/{accountId}/documents`](./api-reference.md#upload-and-create-document) | `IDocumentUploadResponse` |
97
+ | `list(params?, accountId?)` | [`GET /accounts/{accountId}/documents`](./api-reference.md#list-documents) | `IDocumentListResponse` |
98
+ | `search(params?, accountId?)` | [`GET /accounts/{accountId}/documents/search`](./api-reference.md#search-documents-lightweight) | `IDocumentListResponse` |
99
+ | `details(documentId)` | [`GET /documents/{documentId}`](./api-reference.md#get-document) | `IDocumentDetailsResponse` |
100
+ | `get(documentId)` | Same as `details` | `IDocumentDetailsResponse` |
101
+ | `rename(documentId, name)` | [`PATCH /documents/{documentId}`](./api-reference.md#rename-document) | `IDocumentDetailsResponse` |
102
+ | `waitUntilReady(documentId, { maxWaitMs?, pollIntervalMs? }?)` | Polls [Get document](./api-reference.md#get-document) | `IDocumentDetailsResponse`; rejects on terminal failure, permanent 4xx, or timeout |
103
+ | `download(documentId, artifactName?)` | [`GET /documents/{documentId}/download/{artifact}`](./api-reference.md#download-document-artifact) | `Buffer` |
104
+ | `thumbnail(documentId)` | [`GET /documents/{documentId}/thumbnail`](./api-reference.md#download-document-thumbnail) | JPEG `Buffer` |
105
+ | `downloadPage(documentId, pageId)` | [`GET /documents/{documentId}/pages/{pageId}/download`](./api-reference.md#download-document-page) | JPEG `Buffer` |
106
+ | `activities(documentId)` | [`GET /documents/{documentId}/activities`](./api-reference.md#list-document-activities) | `IDocumentActivity[]` |
107
+ | `delete(documentId)` | [`DELETE /documents/{documentId}`](./api-reference.md#delete-document) | `IEmptyResult` (`unknown[]`) |
108
+ | `listTags(documentId, accountId?)` | [`GET /accounts/{accountId}/documents/{documentId}/tags`](./api-reference.md#list-document-tags) | `ITag[]` |
109
+ | `replaceTags(documentId, tags, accountId?)` | [`PUT /accounts/{accountId}/documents/{documentId}/tags`](./api-reference.md#replace-document-tags) | `ITag[]` |
110
+ | `addTags(documentId, tags, accountId?)` | [`POST /accounts/{accountId}/documents/{documentId}/tags`](./api-reference.md#attach-document-tags) | `ITag[]` |
111
+ | `detachTag(documentId, tagId, accountId?)` | [`DELETE /accounts/{accountId}/documents/{documentId}/tags/{tagId}`](./api-reference.md#detach-document-tag) | `IDetachTagResponse` (`{ detached: boolean }`) |
112
+ | `createFromTemplate(templateId, signers, options?, accountId?)` | [`POST /accounts/{accountId}/templates/{templateId}/documents`](./api-reference.md#create-document-from-template) | `IDocumentDetailsResponse` |
113
+ | `estimateCostFromTemplate(templateId, signers, accountId?)` | [`POST /accounts/{accountId}/templates/{templateId}/documents/estimate-cost`](./api-reference.md#estimate-document-from-template-cost) | `IEstimateCostResponse` |
114
+ | `verify(hash)` | [`GET /documents/{signatureHash}/verify`](./api-reference.md#verify-a-signed-document) | `IDocumentVerifyResponse` |
115
+ | `statuses()` | [`GET /documents/statuses`](./api-reference.md#list-document-statuses) | `IDocumentStatusInfo[]` |
116
+ | `getPublic(documentId)` | [`GET /public/documents/{documentId}`](./api-reference.md#view-public-document) | `IPublicDocumentInfo` |
117
+ | `sendToken(documentId, { email })` or `sendToken(documentId, recipient, channel?)` | [`PUT /public/documents/{documentId}/send-token`](./api-reference.md#send-access-token-for-public-document) | `ISendTokenResponse` (`{ status; message }` or `{ document; channel; recipient }`) |
118
+ | `isFullySigned(documentId)` | SDK helper over `details` | `boolean` |
119
+ | `getSigningProgress(documentId)` | SDK helper over `details` | `{ signed; total; pending; percentage }` |
120
+
121
+ Upload input and options:
122
+
123
+ ```ts
124
+ type DocumentUploadSource =
125
+ | { filePath: string; fileName?: string }
126
+ | { buffer: Buffer; fileName: string };
127
+
128
+ interface IDocumentUploadOptions {
129
+ name?: string; // display name, independent of the physical .pdf file name
130
+ metadata?: Record<string, unknown>;
131
+ accountId?: string;
132
+ }
133
+ ```
134
+
135
+ 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 string overload sends the live-compatible legacy `{ recipient, channel }` body for email or WhatsApp integrations that still require it.
136
+
137
+ 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`.
138
+
139
+ 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.
140
+
141
+ ## Assignments (`client.assignments`)
142
+
143
+ | SDK method | HTTP operation | Resolves to |
144
+ | --- | --- | --- |
145
+ | `list(params?, accountId?)` | [`GET /assignments?accountId=…`](./api-reference.md#list-assignments) | `PaginatedResult<IAssignment>` |
146
+ | `create(documentId, payload)` | [`POST /documents/{documentId}/assignments`](./api-reference.md#create-assignment-request-signatures) | `IAssignment` |
147
+ | `estimateCost(documentId, payload)` | [`POST /documents/{documentId}/assignments/estimate-cost`](./api-reference.md#estimate-assignment-cost) | `IEstimateCostResponse` |
148
+ | `resetExpiration(documentId, assignmentId, expiresAt)` | [`PUT …/reset-expiration`](./api-reference.md#reset-assignment-expiration) | `IAssignment`; pass `null` to remove expiration |
149
+ | `resendNotification(documentId, assignmentId, signerId)` | [`PUT …/signers/{signerId}/resend`](./api-reference.md#resend-signature-request) | `IResendEmailResponse` |
150
+ | `estimateResendCost(documentId, assignmentId, signerId)` | [`POST …/estimate-resend-cost`](./api-reference.md#estimate-resend-cost) | `IResendCostEstimate` |
151
+ | `listWhatsAppNotifications(documentId, assignmentId)` | [`GET …/whatsapp-notifications`](./api-reference.md#list-whatsapp-notifications) | `IWhatsAppNotification[]` |
152
+
153
+ Assignment payload:
154
+
155
+ ```ts
156
+ {
157
+ method?: 'virtual' | 'collect';
158
+ signers?: Array<string | {
159
+ id?: string;
160
+ signer_id?: string;
161
+ verification_method?: 'Email' | 'Whatsapp' | 'DigitalCertificate';
162
+ notification_methods?: Array<'Email' | 'Whatsapp'>;
163
+ step?: number;
164
+ }>;
165
+ signer_ids?: string[]; // compatibility alias
166
+ signerIds?: string[]; // compatibility alias
167
+ message?: string;
168
+ expires_at?: string;
169
+ copy_receivers?: string[];
170
+ entries?: ICollectAssignmentEntry[];
171
+ }
172
+ ```
173
+
174
+ `buildAssignmentPayload(payload, options?)` is exported for callers that need the same normalization. `create` requires at least one signer; `estimateCost` permits zero signers for `collect`. Assignment list params are pagination plus the live-verified `sort?: 'created_at' | '-created_at'`; the runtime endpoint requires the SDK's `accountId` query even though the published parameter table omits it. The sandbox ignored an assignment `search` query, so the SDK does not expose it.
175
+
176
+ ## Signers (`client.signers`)
177
+
178
+ | SDK method | HTTP operation | Resolves to |
179
+ | --- | --- | --- |
180
+ | `create(payload, accountId?)` | [`POST /accounts/{accountId}/signers`](./api-reference.md#create-signer) | `ISigner` |
181
+ | `get(signerId, accountId?)` | [`GET /accounts/{accountId}/signers/{signerId}`](./api-reference.md#get-signer) | `ISigner` |
182
+ | `list(params?, accountId?)` | [`GET /accounts/{accountId}/signers`](./api-reference.md#list-signers) | `ISignerListResponse` |
183
+ | `update(signerId, payload, accountId?)` | [`PUT /accounts/{accountId}/signers/{signerId}`](./api-reference.md#update-signer) | `ISigner` |
184
+ | `delete(signerId, accountId?)` | [`DELETE /accounts/{accountId}/signers/{signerId}`](./api-reference.md#delete-signer) | `IEmptyResult` (`unknown[]`) |
185
+ | `findByEmail(email, accountId?)` | SDK helper over `list({ search: email })` | `ISigner | null` |
186
+
187
+ Create payload: `{ full_name: string; email?; whatsapp_phone_number?; phone?; cpf?; metadata? }`. Update payload: `{ full_name?; email?; whatsapp_phone_number?; phone?; government_id?; cpf? }`. `phone` and update-time `cpf` are compatibility aliases. Creation is idempotent by exact case-insensitive email when email is supplied; full-name-only signers are valid. List params support published `search` and live-verified `sort?: 'full_name' | '-full_name'`; ignored sort fields are rejected locally.
188
+
189
+ ## Signer-side flows (`client.signerDocuments`)
190
+
191
+ These methods use the one-time `signer-access-code`, not the workspace API key.
192
+
193
+ | SDK method | HTTP operation | Resolves to |
194
+ | --- | --- | --- |
195
+ | `getCurrent(signerId, accessCode)` | [`GET /signers/{signerId}/document`](./api-reference.md#get-signers-document) | `IDocumentDetailsResponse` |
196
+ | `list(signerId, accessCode, params?)` | [`GET /signers/{signerId}/documents`](./api-reference.md#list-signers-documents) | `IDocumentListResponse` |
197
+ | `search(signerId, search, accessCode)` | [`GET /signers/{signerId}/documents/search`](./api-reference.md#search-signers-documents) | `IDocumentListResponse` |
198
+ | `download(signerId, documentId, artifact, accessCode)` | [`GET /signers/{signerId}/documents/{documentId}/download/{artifact}`](./api-reference.md#download-signers-document-artifact) | `Buffer` |
199
+ | `signMultiple(documentIds, accessCode)` | [`PUT /signers/documents/sign-multiple`](./api-reference.md#sign-multiple-documents) | `unknown[]` |
200
+ | `declineMultiple(documentIds, reason, accessCode)` | [`PUT /signers/documents/decline-multiple`](./api-reference.md#decline-multiple-documents) | `unknown[]` |
201
+ | `self(accessCode)` | [`GET /signers/self`](./api-reference.md#get-current-signer) | `ISignerSelf` |
202
+ | `acceptTerms(accessCode)` | [`PUT /signers/accept-terms`](./api-reference.md#accept-terms-signer) | `IStatusResponse` |
203
+ | `verifyEmail({ signerAccessCode, verificationCode })` | [`POST /verify`](./api-reference.md#verify-signer-code-otp) | `IStatusResponse` |
204
+ | `confirmData(documentId, accessCode, payload)` | [`PUT /documents/{documentId}/signers/confirm-data`](./api-reference.md#confirm-signer-data) | `ISigner` |
205
+ | `uploadSignature(accessCode, image, options?)` | [`POST /signature`](./api-reference.md#upload-signature-image) | `IStatusResponse` |
206
+ | `downloadSignature(accessCode, imageType?)` | [`GET /signature/{type}`](./api-reference.md#download-signature-image) | `Buffer` |
207
+ | `getAssignment(accessCode, hasAcceptedTerms?)` | [`GET /sign`](./api-reference.md#view-document-to-sign) | `IDocumentDetailsResponse` |
208
+ | `sign(documentId, assignmentId, accessCode, entries)` | [`POST /documents/{documentId}/assignments/{assignmentId}`](./api-reference.md#sign-assignment-items) | `Record<string, unknown>` |
209
+ | `decline(documentId, assignmentId, accessCode, reason)` | [`PUT …/reject`](./api-reference.md#reject-decline-assignment) | `unknown[]` |
210
+
211
+ `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 }`.
212
+
213
+ `download` first verifies the access code through `/signers/self` and confirms that it belongs to the requested signer. This SDK-side check mitigates a sandbox defect where the raw artifact route returned a document for an invalid access code; the upstream route must still be fixed before it can be treated as a secure trust boundary.
214
+
215
+ ## Workspaces (`client.workspaces`)
216
+
217
+ | SDK method | HTTP operation | Resolves to |
218
+ | --- | --- | --- |
219
+ | `create(payload)` | [`POST /accounts`](./api-reference.md#create-account) | `IWorkspaceResponse` |
220
+ | `list()` | [`GET /accounts`](./api-reference.md#list-my-accounts) | `IWorkspaceListResponse` |
221
+ | `get(accountId)` | [`GET /accounts/{accountId}`](./api-reference.md#get-account) | `IWorkspaceResponse` |
222
+ | `getTheme(accountId)` | [`GET /accounts/{accountId}/theme`](./api-reference.md#get-account-theme) | `IAccountTheme` |
223
+ | `downloadLogo(accountId)` | [`GET /accounts/{accountId}/logo`](./api-reference.md#download-account-logo) | image `Buffer` |
224
+ | `uploadLogo(accountId, logo, options?)` | [`POST /accounts/{accountId}/logo`](./api-reference.md#upload-account-logo) | `IStatusResponse` |
225
+ | `deleteLogo(accountId)` | [`DELETE /accounts/{accountId}/logo`](./api-reference.md#delete-account-logo) | `IStatusResponse` |
226
+ | `stats(accountId, params?)` | [`GET /accounts/{accountId}/stats`](./api-reference.md#account-document-kpis) | `IDocumentStatsRow[]` |
227
+ | `update(accountId, payload)` | [`PUT /accounts/{accountId}`](./api-reference.md#update-account) | `IWorkspaceResponse` |
228
+ | `delete(accountId, { force? }?)` | [`DELETE /accounts/{accountId}`](./api-reference.md#delete-account) | `IEmptyResult` (`unknown[]`) |
229
+
230
+ Create/update payloads use `name` and `notification_sender_type?: 'User' | 'Account'`; legacy color fields remain accepted for compatibility. List/detail responses include `resource`, `id`, `name`, nullable colors, `notification_sender_type`, roles, delete permission, and `created_at`. `IAccountTheme` is `{ account_name; primary_color; secondary_color: string | null; logo: string | null }`. Logo options are `{ fileName?, contentType? }`. Statistics params are `{ granularity?: 'monthly' | 'daily'; month?: 'YYYY-MM' }`; `month` is required for daily data.
231
+
232
+ ## Users (`client.users`)
233
+
234
+ | SDK method | HTTP operation | Resolves to |
235
+ | --- | --- | --- |
236
+ | `self()` | [`GET /users/self`](./api-reference.md#get-the-authenticated-user) | `IUserSelfResponse` |
237
+ | `stats(params?)` | [`GET /users/self/stats`](./api-reference.md#my-cross-account-document-kpis) | `IDocumentStatsRow[]` |
238
+ | `getNotificationPreferences()` | [`GET /users/self/notification-preferences`](./api-reference.md#get-my-notification-preferences) | `INotificationPreferences` |
239
+ | `updateNotificationPreferences(payload)` | [`PUT /users/self/notification-preferences`](./api-reference.md#update-my-notification-preferences) | `INotificationPreferences` |
240
+
241
+ `IUserSelfResponse` accepts the published user object and the sandbox-observed `{ user, accounts }` envelope. Preference payloads are a non-empty partial mapping of the exported `NOTIFICATION_PREFERENCE_CODES` to booleans. The production OpenAPI publishes these routes; a lagging sandbox deployment may return route-level 404s for statistics/preferences.
242
+
243
+ ## Authentication (`client.auth`)
244
+
245
+ | SDK method | HTTP operation | Request / result |
246
+ | --- | --- | --- |
247
+ | `login(email, password)` | [`POST /login`](./api-reference.md#login) | `{ email, password }` → `ILoginResponse` |
248
+ | `socialLogin({ provider, token, has_accepted_terms })` | [`POST /authentication/social-login`](./api-reference.md#social-login) | Google token → `ILoginResponse` |
249
+ | `linkSocialLogin({ provider, token })` | [`POST /auth/link-social-login`](./api-reference.md#link-social-login) | Google token → `IStatusResponse` |
250
+ | `changePassword({ email, password, new_password })` | [`PUT /authentication/change-password`](./api-reference.md#change-password) | `{ email }` |
251
+ | `requestPasswordReset(email)` | [`PUT /authentication/request-password-reset`](./api-reference.md#request-password-reset) | `{ email }` |
252
+ | `resetPassword({ email, token?, new_password })` | [`PUT /authentication/reset-password`](./api-reference.md#reset-password) | `{ email }` |
253
+ | `createApiKey(password)` | [`POST /users/api-keys`](./api-reference.md#create-api-key) | `IApiKeyResponse` |
254
+ | `getApiKey()` | [`GET /users/api-keys`](./api-reference.md#get-api-key) | `IApiKeyResponse | null`; 404 means no key |
255
+ | `deleteApiKey()` | [`DELETE /users/api-keys`](./api-reference.md#delete-api-key) | `IEmptyResult` (`unknown[]`) |
256
+
257
+ Login/social/reset bootstrap calls can use an unauthenticated client. The published authenticated user endpoints permit either a bearer JWT or `X-Api-Key`; use the credential type appropriate to the account and endpoint policy.
258
+
259
+ ## Fields (`client.fields`)
260
+
261
+ | SDK method | HTTP operation | Resolves to |
262
+ | --- | --- | --- |
263
+ | `create(payload, accountId?)` | [`POST /accounts/{accountId}/fields`](./api-reference.md#create-field) | `IFieldDefinition` |
264
+ | `list(params?, accountId?)` | [`GET /accounts/{accountId}/fields`](./api-reference.md#list-fields) | `IFieldDefinition[]` |
265
+ | `get(fieldId, accountId?)` | [`GET /accounts/{accountId}/fields/{fieldId}`](./api-reference.md#get-field) | `IFieldDefinition` |
266
+ | `update(fieldId, payload, accountId?)` | [`PUT /accounts/{accountId}/fields/{fieldId}`](./api-reference.md#update-field) | `IFieldDefinition` |
267
+ | `delete(fieldId, accountId?)` | [`DELETE /accounts/{accountId}/fields/{fieldId}`](./api-reference.md#delete-field) | `IEmptyResult` (`unknown[]`) |
268
+ | `validate(fieldId, value, options?)` | [`POST …/fields/{fieldId}/validate`](./api-reference.md#validate-field-value) | `IFieldValidationResult` |
269
+ | `validateMultiple(entries, options?)` | [`POST …/fields/validate-multiple`](./api-reference.md#validate-multiple-field-values) | `IFieldValidationResult[]` |
270
+ | `listTypes()` | [`GET /field-types`](./api-reference.md#list-field-types) | `IFieldType[]` |
271
+
272
+ Create payload: `{ type: string; name: string; regex?; is_required?; is_active? }`. Update makes each field optional and allows `regex: null`. List params are `{ include_inactive?, include_standard? }`. Validation options are `{ signerAccessCode?, accountId? }`; multiple entries are `{ field_id, value }[]`. When a signer code is supplied, the SDK removes any configured owner API-key/bearer headers from that request.
273
+
274
+ ## Tags (`client.tags`)
275
+
276
+ | SDK method | HTTP operation | Resolves to |
277
+ | --- | --- | --- |
278
+ | `list({ search? }?, accountId?)` | [`GET /accounts/{accountId}/tags`](./api-reference.md#list-tags) | `ITag[]` |
279
+ | `create({ name, color? }, accountId?)` | [`POST /accounts/{accountId}/tags`](./api-reference.md#create-tag) | `ITag` |
280
+ | `update(tagId, { name?, color? }, accountId?)` | [`PUT /accounts/{accountId}/tags/{tagId}`](./api-reference.md#update-tag) | `ITag`; `color: null` clears it |
281
+ | `delete(tagId, { force?, accountId? }?)` | [`DELETE /accounts/{accountId}/tags/{tagId}`](./api-reference.md#delete-tag) | `IDeleteTagResponse` (`{ deleted: boolean }`) |
282
+
283
+ ## Templates (`client.templates`)
284
+
285
+ | SDK method | HTTP operation | Resolves to |
286
+ | --- | --- | --- |
287
+ | `list(params?, accountId?)` | [`GET /accounts/{accountId}/templates`](./api-reference.md#list-templates) | `ITemplateListResponse` |
288
+ | `get(templateId, accountId?)` | `GET /accounts/{accountId}/templates/{templateId}` | `ITemplateDetailsResponse` |
289
+ | `downloadPage(templateId, pageId, accountId?)` | `GET /accounts/{accountId}/templates/{templateId}/pages/{pageId}/download` | JPEG `Buffer` |
290
+
291
+ The last two compatibility routes are supported by the platform/official PHP SDK but are absent from the published OpenAPI document, so they have no generated payload section.
292
+
293
+ Template list params support pagination, published `search`, and live-verified `sort?: 'name' | '-name'`; ignored sort fields are rejected locally. `ITemplatePage` contains document page dimensions/URL plus typed `ITemplateField[]` entries (`id`, `field_id`, `role_id`, `label`, `display_settings`, and timestamps). Template document creation accepts `editor_fields?: Array<{ field_id: string; value: unknown }>`.
294
+
295
+ ## Webhooks (`client.webhooks`)
296
+
297
+ | SDK method | HTTP operation | Resolves to |
298
+ | --- | --- | --- |
299
+ | `register(payload, accountId?)` | [`PUT /accounts/{accountId}/webhooks/subscriptions`](./api-reference.md#update-webhook-subscription) | `IWebhookSubscription` |
300
+ | `get(accountId?)` | [`GET /accounts/{accountId}/webhooks/subscriptions`](./api-reference.md#get-webhook-subscription) | `IWebhookSubscription | null` |
301
+ | `inactivate(accountId?)` | [`PUT /accounts/{accountId}/webhooks/inactivate`](./api-reference.md#inactivate-webhook-subscription) | `IWebhookSubscription` |
302
+ | `listEventTypes()` | [`GET /webhooks/event-types`](./api-reference.md#list-webhook-event-types) | `IWebhookEventTypeInfo[]` |
303
+ | `listDispatches(params?, accountId?)` | [`GET /accounts/{accountId}/webhooks`](./api-reference.md#list-webhook-deliveries) | `PaginatedResult<IWebhookDispatch>` |
304
+ | `retryDispatch(dispatchId, accountId?)` | [`POST /accounts/{accountId}/webhooks/{dispatchId}/retry`](./api-reference.md#retry-webhook-delivery) | `IWebhookDispatch` |
305
+
306
+ Registration payload: `{ url: string; email: string; events?: string[]; is_active?: boolean }`. When `events` is omitted the SDK uses `document_ready`, `document_prepared`, `signer_signed_document`, `signer_rejected_document`, and `document_processing_failed`; pass `[]` deliberately for none. Dispatch filters extend pagination with `{ event?, delivered?, from?, to?, sort?: 'created_at' | '-created_at' }`; sort is a live-verified extension. The sandbox ignored dispatch `search`, so it is rejected locally. The API does not expose a delete-subscription operation; use `inactivate`.
307
+
308
+ ## Responses, pagination, errors, and binary data
309
+
310
+ - JSON responses with `data` are unwrapped from the API envelope; direct status bodies remain `IStatusResponse`. Paginated calls resolve to `{ data: T[]; meta?: { current_page?, last_page?, per_page?, total? } }`; metadata comes from `X-Pagination-*` headers.
311
+ - Binary methods resolve to Node.js `Buffer`; the SDK is not a browser package. It never writes downloaded data to disk.
312
+ - `ValidationError` means local input validation failed before a request. `ApiError` exposes `statusCode` and `responseData`. `NetworkError` covers timeout/DNS/transport failures. All extend `AssinafyError`, which exposes `context` and preserves `cause` where available.
313
+ - `normalizeBaseUrl(url)` is exported and removes one trailing slash.
314
+
315
+ Exported error constructors/helpers are `new AssinafyError(message, context?, { cause? }?)`, `new ApiError(message, statusCode, responseData?, { cause? }?)`, `ApiError.fromResponse(statusCode, responseData)`, `new ValidationError(message?, errors?)`, and `new NetworkError(message, { cause? }?)`. Resource classes and all named request/response types are also exported for dependency injection and type annotations; normal applications should obtain resource instances from `AssinafyClient`.
316
+
317
+ ```ts
318
+ try {
319
+ await client.documents.get('document-id');
320
+ } catch (error) {
321
+ if (error instanceof ApiError) {
322
+ console.error(error.statusCode, error.responseData);
323
+ }
324
+ }
325
+ ```
326
+
327
+ ## Webhook verification (experimental)
328
+
329
+ | API | Result |
330
+ | --- | --- |
331
+ | `new WebhookVerifier(secret?, { algorithm?, encoding? }?)` | Compatibility verifier; defaults to `sha256` and `hex`. |
332
+ | `verify(rawBody, signature)` | `boolean`; HMAC comparison under the configured, assumed scheme. |
333
+ | `extractEvent(rawBody)` | Parsed `IWebhookPayload`, or `null` for invalid JSON/non-object data. |
334
+ | `getEventType(event)` | `event`/`type` string, or `null`. |
335
+ | `getEventData(event)` | First object found at `payload`, `data`, or `object`; otherwise `{}`. |
336
+
337
+ Assinafy's published API does **not** define a signature header, algorithm, digest encoding, timestamp, or replay-protection scheme. Therefore this helper is experimental and unverified; do not use it as a production trust boundary until Assinafy publishes the scheme or you validate every detail against real deliveries. Preserve the exact raw request bytes for any future verification.
338
+
339
+ ## Contract boundaries
340
+
341
+ - Production OpenAPI currently publishes 89 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.
342
+ - 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.
343
+ - The SDK retains the two template compatibility routes above and both published/legacy public `sendToken` payloads until the upstream contract converges.
344
+ - The sandbox raw signer-artifact route ignored an invalid access code during sandbox verification. The SDK adds the identity preflight described above, but direct HTTP consumers remain exposed until Assinafy fixes the route.
package/docs/send.md CHANGED
@@ -13,7 +13,7 @@ Arguments:
13
13
  Options:
14
14
  --signer <spec> Signer as "Name <email-or-phone>" (repeatable)
15
15
  (default: [])
16
- --signers <json> JSON array of signer objects (overrides --signer)
16
+ --signers <json> JSON array of signer objects
17
17
  --message <message> Message shown to signers
18
18
  --expires-at <iso8601> Expiration timestamp
19
19
  --copy-receivers <csv> Comma-separated signer IDs to receive a copy of the
@@ -22,4 +22,3 @@ Options:
22
22
  --no-wait Do not wait for the document to finish processing
23
23
  -h, --help display help for command
24
24
  ```
25
-
package/docs/signer.md CHANGED
@@ -13,6 +13,7 @@ Options:
13
13
  Commands:
14
14
  document [options] <signerId> Fetch the signer's current document
15
15
  documents [options] <signerId> List the signer's documents
16
+ search [options] <signerId> <query> Search the signer's documents
16
17
  download [options] <signerId> <documentId> <artifact> Download a signer document artifact
17
18
  self [options] Fetch the signer's own profile
18
19
  accept-terms [options] Accept the platform terms as the signer
@@ -39,7 +40,7 @@ Arguments:
39
40
  signerId Signer ID
40
41
 
41
42
  Options:
42
- --access-code <code> Signer access code
43
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
43
44
  -h, --help display help for command
44
45
  ```
45
46
 
@@ -54,11 +55,27 @@ Arguments:
54
55
  signerId Signer ID
55
56
 
56
57
  Options:
57
- --access-code <code> Signer access code
58
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
58
59
  --page <n> Page number to fetch
59
60
  --per-page <n> Items per page
60
- --search <query> Filter results by a search query
61
- --sort <field> Sort by field (prefix with - for descending)
61
+ --search <query> Filter by a search query
62
+ --sort <field> Sort by field
63
+ -h, --help display help for command
64
+ ```
65
+
66
+ ### `assinafy signer search`
67
+
68
+ ```text
69
+ Usage: assinafy signer search [options] <signerId> <query>
70
+
71
+ Search the signer's documents
72
+
73
+ Arguments:
74
+ signerId Signer ID
75
+ query Search text
76
+
77
+ Options:
78
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
62
79
  -h, --help display help for command
63
80
  ```
64
81
 
@@ -72,11 +89,13 @@ Download a signer document artifact
72
89
  Arguments:
73
90
  signerId Signer ID
74
91
  documentId Document ID
75
- artifact original | certificated | certificate-page | bundle
92
+ artifact original | certificated | certificate-page | pades |
93
+ bundle
76
94
 
77
95
  Options:
78
- --access-code <code> Signer access code
96
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
79
97
  -o, --output <path> Output file path
98
+ --force Overwrite the output file if it already exists
80
99
  -h, --help display help for command
81
100
  ```
82
101
 
@@ -88,7 +107,7 @@ Usage: assinafy signer self [options]
88
107
  Fetch the signer's own profile
89
108
 
90
109
  Options:
91
- --access-code <code> Signer access code
110
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
92
111
  -h, --help display help for command
93
112
  ```
94
113
 
@@ -100,7 +119,7 @@ Usage: assinafy signer accept-terms [options]
100
119
  Accept the platform terms as the signer
101
120
 
102
121
  Options:
103
- --access-code <code> Signer access code
122
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
104
123
  -h, --help display help for command
105
124
  ```
106
125
 
@@ -112,8 +131,8 @@ Usage: assinafy signer verify-email [options]
112
131
  Verify the email OTP for a signer
113
132
 
114
133
  Options:
115
- --access-code <code> Signer access code
116
- --code <otp> Verification code
134
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
135
+ --code <otp> Verification code (env: ASSINAFY_VERIFICATION_CODE)
117
136
  -h, --help display help for command
118
137
  ```
119
138
 
@@ -128,9 +147,11 @@ Arguments:
128
147
  documentId Document ID
129
148
 
130
149
  Options:
131
- --access-code <code> Signer access code
150
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
151
+ --full-name <name> Full name to confirm
132
152
  --email <email> Email to confirm
133
153
  --phone <number> WhatsApp phone number to confirm
154
+ --government-id <id> Government ID (e.g. CPF) to confirm
134
155
  --accept-terms Also accept the platform terms
135
156
  -h, --help display help for command
136
157
  ```
@@ -143,10 +164,14 @@ Usage: assinafy signer upload-signature [options]
143
164
  Upload the signer's signature or initial image
144
165
 
145
166
  Options:
146
- --access-code <code> Signer access code
167
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
147
168
  --file <path> Path to the signature image (PNG)
148
169
  --type <type> signature or initial (default: "signature")
149
170
  --content-type <mime> Image MIME type (default: "image/png")
171
+ --reuse Mark the signer's signature as reusable in future
172
+ processes
173
+ --no-reuse Disable reuse of the signer's signature in future
174
+ processes
150
175
  -h, --help display help for command
151
176
  ```
152
177
 
@@ -158,9 +183,10 @@ Usage: assinafy signer download-signature [options]
158
183
  Download the signer's signature or initial image
159
184
 
160
185
  Options:
161
- --access-code <code> Signer access code
186
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
162
187
  --type <type> signature or initial (default: "signature")
163
188
  -o, --output <path> Output file path
189
+ --force Overwrite the output file if it already exists
164
190
  -h, --help display help for command
165
191
  ```
166
192
 
@@ -172,7 +198,7 @@ Usage: assinafy signer assignment [options]
172
198
  Fetch the assignment as the signer sees it
173
199
 
174
200
  Options:
175
- --access-code <code> Signer access code
201
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
176
202
  --accept-terms Pass has_accepted_terms=true
177
203
  -h, --help display help for command
178
204
  ```
@@ -189,7 +215,7 @@ Arguments:
189
215
  assignmentId Assignment ID
190
216
 
191
217
  Options:
192
- --access-code <code> Signer access code
218
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
193
219
  --entries <json> JSON array of { itemId, fieldId, pageId, value } entries
194
220
  -h, --help display help for command
195
221
  ```
@@ -206,7 +232,7 @@ Arguments:
206
232
  assignmentId Assignment ID
207
233
 
208
234
  Options:
209
- --access-code <code> Signer access code
235
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
210
236
  --reason <reason> Reason for declining
211
237
  -h, --help display help for command
212
238
  ```
@@ -219,7 +245,7 @@ Usage: assinafy signer sign-multiple [options]
219
245
  Sign multiple documents at once
220
246
 
221
247
  Options:
222
- --access-code <code> Signer access code
248
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
223
249
  --document-ids <csv> Comma-separated document IDs
224
250
  -h, --help display help for command
225
251
  ```
@@ -232,9 +258,8 @@ Usage: assinafy signer decline-multiple [options]
232
258
  Decline multiple documents at once
233
259
 
234
260
  Options:
235
- --access-code <code> Signer access code
261
+ --access-code <code> Signer access code (env: ASSINAFY_SIGNER_ACCESS_CODE)
236
262
  --document-ids <csv> Comma-separated document IDs
237
263
  --reason <reason> Reason for declining
238
264
  -h, --help display help for command
239
265
  ```
240
-
package/docs/signers.md CHANGED
@@ -47,8 +47,8 @@ List signers in the workspace
47
47
  Options:
48
48
  --page <n> Page number to fetch
49
49
  --per-page <n> Items per page
50
- --search <query> Filter results by a search query
51
- --sort <field> Sort by field (prefix with - for descending)
50
+ --search <query> Filter by a search query
51
+ --sort <field> Sort by full_name (prefix with - for descending)
52
52
  -h, --help display help for command
53
53
  ```
54
54
 
@@ -112,4 +112,3 @@ Arguments:
112
112
  Options:
113
113
  -h, --help display help for command
114
114
  ```
115
-
package/docs/tags.md CHANGED
@@ -75,4 +75,3 @@ Options:
75
75
  -y, --yes Skip the confirmation prompt
76
76
  -h, --help display help for command
77
77
  ```
78
-
package/docs/templates.md CHANGED
@@ -27,8 +27,8 @@ List templates in the workspace
27
27
  Options:
28
28
  --page <n> Page number to fetch
29
29
  --per-page <n> Items per page
30
- --search <query> Filter results by a search query
31
- --sort <field> Sort by field (prefix with - for descending)
30
+ --search <query> Filter by a search query
31
+ --sort <field> Sort by name (prefix with - for descending)
32
32
  -h, --help display help for command
33
33
  ```
34
34
 
@@ -59,6 +59,6 @@ Arguments:
59
59
 
60
60
  Options:
61
61
  -o, --output <path> Output file path
62
+ --force Overwrite the output file if it already exists
62
63
  -h, --help display help for command
63
64
  ```
64
-