@assinafy/sdk 2.5.0 → 2.5.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/dist/index.mjs CHANGED
@@ -80,7 +80,9 @@ var ApiError = class _ApiError extends AssinafyError {
80
80
  * ones with no structured body to explain them. Anything else falls back to
81
81
  * the stable message.
82
82
  * @returns An `ApiError` retaining the original response body in
83
- * {@link ApiError.responseData}; `message` is truncated for legibility.
83
+ * {@link ApiError.responseData}. A JSON `message` is used verbatim; only an
84
+ * unstructured text body is whitespace-collapsed and truncated for
85
+ * legibility.
84
86
  *
85
87
  * @example
86
88
  * ```ts
@@ -133,6 +135,16 @@ var OAuthError = class _OAuthError extends ApiError {
133
135
  * @param error - Any thrown value.
134
136
  * @returns An `OAuthError` when the body carries a non-empty string
135
137
  * `error`, else the original value.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const apiError = ApiError.fromResponse(400, {
142
+ * error: 'invalid_grant',
143
+ * error_description: 'The provided authorization grant is invalid.',
144
+ * });
145
+ * const upgraded = OAuthError.upgrade(apiError);
146
+ * // upgraded instanceof OAuthError → true, .error → 'invalid_grant'
147
+ * ```
136
148
  */
137
149
  static upgrade(error) {
138
150
  if (!(error instanceof ApiError) || error instanceof _OAuthError) return error;
@@ -574,7 +586,7 @@ import axios2 from "axios";
574
586
  // package.json
575
587
  var package_default = {
576
588
  name: "@assinafy/sdk",
577
- version: "2.5.0",
589
+ version: "2.5.1",
578
590
  packageManager: "bun@1.4.0",
579
591
  description: "TypeScript SDK for Assinafy API - Digital signature platform",
580
592
  type: "commonjs",
@@ -1380,11 +1392,11 @@ var AssignmentResource = class extends BaseResource {
1380
1392
  * @param documentId - The document the assignment would be created on.
1381
1393
  * @param payload - `method` plus channel-only signer descriptors and/or
1382
1394
  * `collect`-mode `entries`. Create-only fields and signer IDs are not part
1383
- * of this request schema. `blocking_reason` may be `PendingPayment`,
1384
- * `InsufficientDocuments`, or `InsufficientCredits`.
1395
+ * of this request schema.
1385
1396
  * @returns an {@link ICostEstimate} with `total_credits`, balances, a
1386
- * line-item `breakdown`, and a `has_sufficient_resources` gate. Response
1387
- * shape:
1397
+ * line-item `breakdown`, and a `has_sufficient_resources` gate.
1398
+ * `blocking_reason` may be `PendingPayment`, `InsufficientDocuments`, or
1399
+ * `InsufficientCredits`. Response shape:
1388
1400
  * ```jsonc
1389
1401
  * {
1390
1402
  * "documents": 1,
@@ -1937,8 +1949,7 @@ var DocumentResource = class extends BaseResource {
1937
1949
  * "updated_at": "2026-07-19T17:24:46Z"
1938
1950
  * }
1939
1951
  * ```
1940
- * @throws {ValidationError} If `documentId` is missing or `artifactName` is
1941
- * not one of the five documented artifact names.
1952
+ * @throws {ValidationError} If `documentId` is missing.
1942
1953
  * @throws {ApiError} `404` if the document does not exist.
1943
1954
  *
1944
1955
  * @example
@@ -2658,7 +2669,8 @@ var DocumentResource = class extends BaseResource {
2658
2669
  }
2659
2670
  }
2660
2671
  /**
2661
- * Quick boolean check: has every signer completed their assignment?
2672
+ * Quick boolean check (`GET /documents/{documentId}`): has every signer
2673
+ * completed their assignment?
2662
2674
  *
2663
2675
  * A computed convenience over {@link DocumentResource.details} (one `GET
2664
2676
  * /documents/{documentId}`). Returns `true` when the document status is
@@ -2688,7 +2700,8 @@ var DocumentResource = class extends BaseResource {
2688
2700
  return false;
2689
2701
  }
2690
2702
  /**
2691
- * Summarise signing progress for UI display.
2703
+ * Summarise signing progress for UI display
2704
+ * (`GET /documents/{documentId}`).
2692
2705
  *
2693
2706
  * A computed convenience over {@link DocumentResource.details} (one `GET
2694
2707
  * /documents/{documentId}`). `total` and `signed` come from the assignment
@@ -3672,7 +3685,7 @@ var WebhookResource = class extends BaseResource {
3672
3685
  events: [...payload.events && payload.events.length > 0 ? payload.events : DEFAULT_WEBHOOK_EVENTS],
3673
3686
  is_active: payload.is_active ?? true
3674
3687
  };
3675
- this.logger.info("Registering webhook", { url: payload.url });
3688
+ this.logger.info("Registering webhook");
3676
3689
  return this.call(
3677
3690
  "Failed to register webhook",
3678
3691
  () => this.http.put(
@@ -4530,7 +4543,7 @@ var AuthenticationResource = class extends BaseResource {
4530
4543
  * "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…",
4531
4544
  * "user": {
4532
4545
  * "id": "md3j6p9w8b7y6qvqaoy5er42",
4533
- * "name": "Multica Test",
4546
+ * "name": "Empresa Exemplo",
4534
4547
  * "email": "user@example.com",
4535
4548
  * "telephone": null,
4536
4549
  * "government_id": "",
@@ -4542,7 +4555,7 @@ var AuthenticationResource = class extends BaseResource {
4542
4555
  * "accounts": [
4543
4556
  * {
4544
4557
  * "id": "acc_example",
4545
- * "name": "Multica Test",
4558
+ * "name": "Empresa Exemplo",
4546
4559
  * "roles": ["Owner"],
4547
4560
  * "is_delete_allowed": true,
4548
4561
  * "created_at": "2026-05-12T13:45:11Z"
@@ -4588,7 +4601,7 @@ var AuthenticationResource = class extends BaseResource {
4588
4601
  * "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…",
4589
4602
  * "user": {
4590
4603
  * "id": "md3j6p9w8b7y6qvqaoy5er42",
4591
- * "name": "Multica Test",
4604
+ * "name": "Empresa Exemplo",
4592
4605
  * "email": "user@example.com",
4593
4606
  * "telephone": null,
4594
4607
  * "government_id": "",
@@ -4600,7 +4613,7 @@ var AuthenticationResource = class extends BaseResource {
4600
4613
  * "accounts": [
4601
4614
  * {
4602
4615
  * "id": "acc_example",
4603
- * "name": "Multica Test",
4616
+ * "name": "Empresa Exemplo",
4604
4617
  * "roles": ["Owner"],
4605
4618
  * "is_delete_allowed": true,
4606
4619
  * "created_at": "2026-05-12T13:45:11Z"
@@ -6015,8 +6028,7 @@ var SignerDocumentsResource = class extends BaseResource {
6015
6028
  * "updated_at": "2026-07-19T14:56:56Z"
6016
6029
  * }
6017
6030
  * ```
6018
- * @throws {ValidationError} If `signerId` or `signerAccessCode` is missing,
6019
- * or a supplied `search` value is not a string.
6031
+ * @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
6020
6032
  * @throws {ApiError} If the access code is invalid or expired.
6021
6033
  *
6022
6034
  * @example
@@ -6104,7 +6116,29 @@ var SignerDocumentsResource = class extends BaseResource {
6104
6116
  * @param signerAccessCode - The signer's access code, from their signing link.
6105
6117
  * @param search - Free-text term matched against the document name.
6106
6118
  * @returns Matching documents for that signer, in the compact
6107
- * {@link IDocumentListItem} shape, with pagination in `meta`.
6119
+ * {@link IDocumentListItem} shape, with pagination in `meta`:
6120
+ * ```jsonc
6121
+ * {
6122
+ * "data": [
6123
+ * {
6124
+ * "id": "103acccd24234c07858ffddf6d84",
6125
+ * "account_id": "acc_example",
6126
+ * "template_id": null,
6127
+ * "name": "Service agreement.pdf",
6128
+ * "status": "pending_signature",
6129
+ * "artifacts": { "original": "https://...", "thumbnail": "https://..." },
6130
+ * "is_closed": false,
6131
+ * "signing_url": "https://app.assinafy.com.br/sign/103acccd...",
6132
+ * "decline_reason": null,
6133
+ * "declined_by": null,
6134
+ * "tags": [],
6135
+ * "created_at": "2026-07-19T14:56:54Z",
6136
+ * "updated_at": "2026-07-19T14:56:56Z"
6137
+ * }
6138
+ * ],
6139
+ * "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
6140
+ * }
6141
+ * ```
6108
6142
  * @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
6109
6143
  * @throws {ApiError} If the access code is invalid or expired.
6110
6144
  *
@@ -6212,9 +6246,7 @@ var SignerDocumentsResource = class extends BaseResource {
6212
6246
  * ```
6213
6247
  */
6214
6248
  async signMultiple(documentIds, signerAccessCode) {
6215
- if (!Array.isArray(documentIds) || documentIds.length === 0 || documentIds.some((id) => typeof id !== "string" || !id.trim())) {
6216
- throw new ValidationError("documentIds must be a non-empty array of non-empty IDs");
6217
- }
6249
+ assertDocumentIds(documentIds);
6218
6250
  const code = this.requireId(signerAccessCode, "signer-access-code");
6219
6251
  return this.callVoid(
6220
6252
  "Failed to sign multiple documents",
@@ -6254,12 +6286,8 @@ var SignerDocumentsResource = class extends BaseResource {
6254
6286
  * ```
6255
6287
  */
6256
6288
  async declineMultiple(documentIds, declineReason, signerAccessCode) {
6257
- if (!Array.isArray(documentIds) || documentIds.length === 0 || documentIds.some((id) => typeof id !== "string" || !id.trim())) {
6258
- throw new ValidationError("documentIds must be a non-empty array of non-empty IDs");
6259
- }
6260
- if (typeof declineReason !== "string" || !declineReason.trim()) {
6261
- throw new ValidationError("declineReason is required");
6262
- }
6289
+ assertDocumentIds(documentIds);
6290
+ assertDeclineReason(declineReason);
6263
6291
  const code = this.requireId(signerAccessCode, "signer-access-code");
6264
6292
  return this.callVoid(
6265
6293
  "Failed to decline multiple documents",
@@ -6490,7 +6518,48 @@ var SignerDocumentsResource = class extends BaseResource {
6490
6518
  * @returns The document to sign, including its `assignment` (the
6491
6519
  * {@link IAssignment} shape: `signers`, `items`, `summary`, `signing_urls`)
6492
6520
  * from which the `itemId` / `fieldId` / `pageId` values for
6493
- * {@link SignerDocumentsResource.sign} are read.
6521
+ * {@link SignerDocumentsResource.sign} are read:
6522
+ * ```jsonc
6523
+ * {
6524
+ * "resource": "document",
6525
+ * "id": "103acccd24234c07858ffddf6d84",
6526
+ * "account_id": "acc_example",
6527
+ * "template_id": null,
6528
+ * "name": "Service agreement.pdf",
6529
+ * "status": "pending_signature",
6530
+ * "artifacts": {
6531
+ * "original": "https://api.assinafy.com.br/v1/documents/103acccd.../download/original",
6532
+ * "thumbnail": "https://api.assinafy.com.br/v1/documents/103acccd.../thumbnail"
6533
+ * },
6534
+ * "is_closed": false,
6535
+ * "signing_url": "https://app.assinafy.com.br/sign/103acccd...",
6536
+ * "decline_reason": null,
6537
+ * "declined_by": null,
6538
+ * "tags": [],
6539
+ * "assignment": {
6540
+ * "id": "1032c55c58bb00a8dc35db916751",
6541
+ * "method": "virtual",
6542
+ * "sender_email": "sender@example.com",
6543
+ * "expires_at": null,
6544
+ * "signers": [
6545
+ * { "id": "19e6b92e7895332ed9708535d8c", "step": 1, "email": "signer@example.com",
6546
+ * "full_name": "Example Signer", "notified": true, "completed": false }
6547
+ * ],
6548
+ * "items": [
6549
+ * { "id": "item-1", "page": { "id": "page-1", "number": 1, "height": 1651, "width": 1275,
6550
+ * "download_url": "https://..." }, "signer": { "id": "19e6b92e..." },
6551
+ * "field": { "id": "field-1", "type": "signature" }, "value": null, "completed": false }
6552
+ * ],
6553
+ * "summary": { "signer_count": 1, "completed_count": 0, "signers": [] }
6554
+ * },
6555
+ * "pages": [
6556
+ * { "id": "103acccd5c73...", "number": 1, "height": 1651, "width": 1275,
6557
+ * "download_url": "https://api.assinafy.com.br/v1/documents/103acccd.../pages/103acccd5c73.../download" }
6558
+ * ],
6559
+ * "created_at": "2026-07-19T14:56:54Z",
6560
+ * "updated_at": "2026-07-19T14:56:56Z"
6561
+ * }
6562
+ * ```
6494
6563
  * @throws {ValidationError} If `signerAccessCode` is missing.
6495
6564
  * @throws {ApiError} `400` when DigitalCertificate identity/terms are not
6496
6565
  * confirmed; `401`/`403` if the access code is invalid or expired; `409`
@@ -6612,9 +6681,7 @@ var SignerDocumentsResource = class extends BaseResource {
6612
6681
  const did = this.requireId(documentId, "Document ID");
6613
6682
  const aid = this.requireId(assignmentId, "Assignment ID");
6614
6683
  const code = this.requireId(signerAccessCode, "signer-access-code");
6615
- if (typeof declineReason !== "string" || !declineReason.trim()) {
6616
- throw new ValidationError("declineReason is required");
6617
- }
6684
+ assertDeclineReason(declineReason);
6618
6685
  return this.callVoid(
6619
6686
  "Failed to decline assignment",
6620
6687
  () => this.http.put(
@@ -6625,6 +6692,16 @@ var SignerDocumentsResource = class extends BaseResource {
6625
6692
  );
6626
6693
  }
6627
6694
  };
6695
+ function assertDocumentIds(documentIds) {
6696
+ if (!Array.isArray(documentIds) || documentIds.length === 0 || documentIds.some((id) => typeof id !== "string" || !id.trim())) {
6697
+ throw new ValidationError("documentIds must be a non-empty array of non-empty IDs");
6698
+ }
6699
+ }
6700
+ function assertDeclineReason(declineReason) {
6701
+ if (typeof declineReason !== "string" || !declineReason.trim()) {
6702
+ throw new ValidationError("declineReason is required");
6703
+ }
6704
+ }
6628
6705
  function validateConfirmDataPayload(payload) {
6629
6706
  for (const key of ["full_name", "government_id"]) {
6630
6707
  if (payload[key] !== void 0 && typeof payload[key] !== "string") {
@@ -6770,8 +6847,20 @@ var UserResource = class extends BaseResource {
6770
6847
  * ```json
6771
6848
  * { "DocumentCompleted": true, "SignerDeclined": false }
6772
6849
  * ```
6773
- * @returns The complete updated map; its shape is identical to
6774
- * {@link UserResource.getNotificationPreferences}.
6850
+ * @returns The complete updated nine-key preference map:
6851
+ * ```json
6852
+ * {
6853
+ * "DocumentCompleted": true,
6854
+ * "SignerDeclined": false,
6855
+ * "DocumentCancelled": true,
6856
+ * "DocumentAboutToExpire": true,
6857
+ * "DocumentExpired": false,
6858
+ * "DocumentExpirationReset": true,
6859
+ * "DocumentProcessingFailed": true,
6860
+ * "TemplateProcessingFailed": true,
6861
+ * "SignerWhatsappFailed": true
6862
+ * }
6863
+ * ```
6775
6864
  * @throws {ValidationError} Before requesting when the map is empty, has an
6776
6865
  * unknown key, or contains a non-boolean value.
6777
6866
  * @throws {ApiError} `400` if the API rejects the map, `401` for invalid
@@ -7223,7 +7312,10 @@ var AssinafyClient = class _AssinafyClient {
7223
7312
  * the upload is empty / non-PDF / larger than 25 MB, or `waitForReady` is
7224
7313
  * enabled and processing exceeds the {@link DocumentResource.waitUntilReady}
7225
7314
  * timeout.
7226
- * @throws {ApiError} If any underlying API call is rejected.
7315
+ * @throws {ApiError} If any underlying API call is rejected — see the
7316
+ * `@throws` of {@link DocumentResource.upload}, {@link SignerResource.create},
7317
+ * {@link AssignmentResource.create}, and
7318
+ * {@link DocumentResource.waitUntilReady} for the per-step statuses.
7227
7319
  *
7228
7320
  * @example
7229
7321
  * ```ts
@@ -200,6 +200,17 @@ coverage count.
200
200
  | `DELETE` | `/v1/accounts/{accountId}/templates/{templateId}` | `client.templates.delete(templateId, accountId?)` | Compatibility extension |
201
201
  | `GET` | `/v1/accounts/{accountId}/templates/{templateId}/pages/{pageId}/download` | `client.templates.downloadPage(templateId, pageId, accountId?)` | Compatibility extension |
202
202
 
203
+ ## Browser URL helpers
204
+
205
+ Two browser URL helpers used by older deployments are live but absent from the
206
+ current OpenAPI path set, so they are likewise excluded from the official
207
+ 93-operation coverage count.
208
+
209
+ | Method | Path | SDK method | Status |
210
+ | --- | --- | --- | --- |
211
+ | `GET` | `/v1/auth/authenticate` | `client.auth.getSocialLoginUrl()` | Compatibility extension |
212
+ | `GET` | `/v1/login-callback` | `client.auth.getSocialLoginCallbackUrl()` | Compatibility extension |
213
+
203
214
  ## SDK conveniences
204
215
 
205
216
  These helpers compose or derive official operations and therefore do not add to
@@ -35,7 +35,7 @@ GET /v1/login-callback
35
35
 
36
36
  They map to `auth.getSocialLoginUrl()` and
37
37
  `auth.getSocialLoginCallbackUrl()` and are not part of the official
38
- 89-operation total.
38
+ 93-operation total.
39
39
 
40
40
  The SDK also includes the production contract additions for:
41
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assinafy/sdk",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "packageManager": "bun@1.4.0",
5
5
  "description": "TypeScript SDK for Assinafy API - Digital signature platform",
6
6
  "type": "commonjs",