@assinafy/sdk 2.7.0 → 2.8.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.
- package/CHANGELOG.md +67 -1
- package/README.en.md +77 -17
- package/README.md +77 -17
- package/dist/index.d.mts +508 -63
- package/dist/index.d.ts +508 -63
- package/dist/index.js +513 -78
- package/dist/index.mjs +513 -78
- package/docs/API_COVERAGE.md +22 -14
- package/docs/COMPATIBILITY.md +58 -20
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -55,6 +55,25 @@ var ApiError = class _ApiError extends AssinafyError {
|
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
challenge;
|
|
58
|
+
/**
|
|
59
|
+
* Rate-limit headers carried by the failed response: `X-Rate-Limit-Limit`,
|
|
60
|
+
* `X-Rate-Limit-Remaining`, `X-Rate-Limit-Reset` and, on `429`,
|
|
61
|
+
* `Retry-After` (all in requests or seconds). `undefined` when the response
|
|
62
|
+
* carried none of them. The client already retries a `429` up to
|
|
63
|
+
* `maxRetries` times; this is what remains once those retries are spent.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* try {
|
|
68
|
+
* await client.documents.list();
|
|
69
|
+
* } catch (error) {
|
|
70
|
+
* if (error instanceof ApiError && error.statusCode === 429) {
|
|
71
|
+
* await sleep((error.rateLimit?.retryAfter ?? 60) * 1000);
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
rateLimit;
|
|
58
77
|
/**
|
|
59
78
|
* Create an error representing a non-success API response.
|
|
60
79
|
*
|
|
@@ -160,6 +179,7 @@ var OAuthError = class _OAuthError extends ApiError {
|
|
|
160
179
|
body
|
|
161
180
|
);
|
|
162
181
|
if (error.challenge !== void 0) upgraded.challenge = error.challenge;
|
|
182
|
+
if (error.rateLimit !== void 0) upgraded.rateLimit = error.rateLimit;
|
|
163
183
|
return upgraded;
|
|
164
184
|
}
|
|
165
185
|
};
|
|
@@ -237,6 +257,20 @@ function parseWwwAuthenticate(value) {
|
|
|
237
257
|
}
|
|
238
258
|
return challenge;
|
|
239
259
|
}
|
|
260
|
+
var RATE_LIMIT_HEADERS = [
|
|
261
|
+
["limit", "x-rate-limit-limit"],
|
|
262
|
+
["remaining", "x-rate-limit-remaining"],
|
|
263
|
+
["reset", "x-rate-limit-reset"],
|
|
264
|
+
["retryAfter", "retry-after"]
|
|
265
|
+
];
|
|
266
|
+
function parseRateLimit(headers) {
|
|
267
|
+
const info = {};
|
|
268
|
+
for (const [key, header2] of RATE_LIMIT_HEADERS) {
|
|
269
|
+
const value = readHeader(headers, header2)?.trim();
|
|
270
|
+
if (value !== void 0 && /^\d+$/u.test(value)) info[key] = Number(value);
|
|
271
|
+
}
|
|
272
|
+
return Object.keys(info).length > 0 ? info : void 0;
|
|
273
|
+
}
|
|
240
274
|
|
|
241
275
|
// src/utils.ts
|
|
242
276
|
var SAFE_LOG_NUMBER_FIELDS = /* @__PURE__ */ new Set([
|
|
@@ -283,10 +317,11 @@ function toSdkError(error, fallbackMessage) {
|
|
|
283
317
|
if (status) {
|
|
284
318
|
const body = decodeBinaryErrorBody(error.response?.data ?? null);
|
|
285
319
|
const apiError = ApiError.fromResponse(status, body ?? null);
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
);
|
|
320
|
+
const headers = error.response?.headers;
|
|
321
|
+
const challenge = parseWwwAuthenticate(readHeader(headers, "www-authenticate"));
|
|
289
322
|
if (challenge) apiError.challenge = challenge;
|
|
323
|
+
const rateLimit = parseRateLimit(headers);
|
|
324
|
+
if (rateLimit) apiError.rateLimit = rateLimit;
|
|
290
325
|
return apiError;
|
|
291
326
|
}
|
|
292
327
|
const cause = sanitiseNetworkCause(error);
|
|
@@ -470,6 +505,7 @@ import { AxiosError } from "axios";
|
|
|
470
505
|
|
|
471
506
|
// src/support/path.ts
|
|
472
507
|
function encodePathSegment(value) {
|
|
508
|
+
if (value === "." || value === "..") throw new Error("Dot segments are not resource IDs");
|
|
473
509
|
return encodeURIComponent(value).replace(
|
|
474
510
|
/[!'()*]/g,
|
|
475
511
|
(character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`
|
|
@@ -592,7 +628,7 @@ import axios2 from "axios";
|
|
|
592
628
|
// package.json
|
|
593
629
|
var package_default = {
|
|
594
630
|
name: "@assinafy/sdk",
|
|
595
|
-
version: "2.
|
|
631
|
+
version: "2.8.0",
|
|
596
632
|
packageManager: "bun@1.4.0",
|
|
597
633
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
598
634
|
type: "commonjs",
|
|
@@ -655,7 +691,7 @@ var package_default = {
|
|
|
655
691
|
bugs: {
|
|
656
692
|
url: "https://github.com/assinafy/typescript-sdk/issues"
|
|
657
693
|
},
|
|
658
|
-
homepage: "https://
|
|
694
|
+
homepage: "https://www.assinafy.com.br",
|
|
659
695
|
devDependencies: {
|
|
660
696
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
661
697
|
"@eslint/js": "^10.0.1",
|
|
@@ -724,7 +760,13 @@ function applySdkTransportDefaults(http) {
|
|
|
724
760
|
const guarded = (options, response, request) => {
|
|
725
761
|
guardRedirect(options, response, request);
|
|
726
762
|
if (current && typeof options["href"] === "string" && new URL(request.url).origin === new URL(options["href"]).origin) {
|
|
763
|
+
const destinationKeys = ["protocol", "host", "hostname", "port", "socketPath", "servername"];
|
|
764
|
+
const destination = destinationKeys.map((key) => options[key]);
|
|
765
|
+
const host = readHeader(options["headers"], "host");
|
|
727
766
|
current(options, response, request);
|
|
767
|
+
if (destinationKeys.some((key, index) => options[key] !== destination[index]) || readHeader(options["headers"], "host") !== host) {
|
|
768
|
+
throw new Error("Redirect hooks must not change the destination");
|
|
769
|
+
}
|
|
728
770
|
guardRedirect(options, response, request);
|
|
729
771
|
}
|
|
730
772
|
};
|
|
@@ -932,12 +974,13 @@ function toInt(value) {
|
|
|
932
974
|
|
|
933
975
|
// src/resources/assignments.ts
|
|
934
976
|
var ASSIGNMENT_METHODS = /* @__PURE__ */ new Set(["virtual", "collect"]);
|
|
935
|
-
var VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "DigitalCertificate"]);
|
|
977
|
+
var VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "DigitalCertificate", "IdDocumentFaceMatchBasic"]);
|
|
936
978
|
var NOTIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp"]);
|
|
937
979
|
var ALLOWED_NOTIFICATION_METHODS = {
|
|
938
980
|
Email: /* @__PURE__ */ new Set(["Email"]),
|
|
939
981
|
Whatsapp: /* @__PURE__ */ new Set(["Whatsapp"]),
|
|
940
|
-
DigitalCertificate: NOTIFICATION_METHODS
|
|
982
|
+
DigitalCertificate: NOTIFICATION_METHODS,
|
|
983
|
+
IdDocumentFaceMatchBasic: NOTIFICATION_METHODS
|
|
941
984
|
};
|
|
942
985
|
function validateAssignmentSignerOptions(signer, label = "signer") {
|
|
943
986
|
if (signer.verification_method !== void 0 && (typeof signer.verification_method !== "string" || !VERIFICATION_METHODS.has(signer.verification_method))) {
|
|
@@ -1277,8 +1320,10 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1277
1320
|
* {@link buildAssignmentPayload}. A `virtual` assignment may be created at
|
|
1278
1321
|
* `uploaded`, `metadata_processing`, or `metadata_ready` and is promoted
|
|
1279
1322
|
* automatically; `collect` requires rendered pages at `metadata_ready`.
|
|
1280
|
-
* `DigitalCertificate` costs
|
|
1323
|
+
* `DigitalCertificate` costs 0.5 credits, requires the feature plus a
|
|
1281
1324
|
* signer `government_id`, and that signer must be alone in its step.
|
|
1325
|
+
* `IdDocumentFaceMatchBasic` needs the ID Document + Face Match feature
|
|
1326
|
+
* and a valid CPF in the signer's `government_id`; estimate its fee first.
|
|
1282
1327
|
*
|
|
1283
1328
|
* Request body (`application/json`):
|
|
1284
1329
|
* ```jsonc
|
|
@@ -1414,7 +1459,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1414
1459
|
* only `verification_method` / `notification_methods` (or `{}` for the
|
|
1415
1460
|
* default Email channel). {@link buildAssignmentEstimatePayload} projects
|
|
1416
1461
|
* exactly the fields permitted by the estimate schema.
|
|
1417
|
-
* `DigitalCertificate` is priced at
|
|
1462
|
+
* `DigitalCertificate` is priced at 0.5 credits per signer and remains
|
|
1418
1463
|
* subject to the feature, identity, and one-signer-per-step requirements.
|
|
1419
1464
|
* Current documented unit prices are 1 credit for an extra document, 0 for
|
|
1420
1465
|
* email notification, and 0.45 for WhatsApp notification; a digital
|
|
@@ -1690,6 +1735,148 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1690
1735
|
)
|
|
1691
1736
|
);
|
|
1692
1737
|
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Read the account's signer identity review
|
|
1740
|
+
* (`GET /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification`).
|
|
1741
|
+
*
|
|
1742
|
+
* No request body. `InReview` lets the signer continue signing but holds
|
|
1743
|
+
* certification. Evidence is a summary without images or biometrics; a
|
|
1744
|
+
* directly approved verification exposes evidence on its activity instead.
|
|
1745
|
+
*
|
|
1746
|
+
* @param documentId - Document owning the assignment.
|
|
1747
|
+
* @param assignmentId - Assignment containing the signer.
|
|
1748
|
+
* @param signerId - Signer whose identity is under review.
|
|
1749
|
+
* @returns The complete review summary:
|
|
1750
|
+
* ```jsonc
|
|
1751
|
+
* {
|
|
1752
|
+
* "id": "verification_example", "status": "InReview",
|
|
1753
|
+
* "provider": "AssinafyVerify", "verification_method": "IdDocumentFaceMatchBasic",
|
|
1754
|
+
* "reason_codes": [{ "code": "NAME_MISMATCH", "description": "Name differs" }],
|
|
1755
|
+
* "evidence_available": true,
|
|
1756
|
+
* "expected": { "name": "Example Signer", "cpf": null },
|
|
1757
|
+
* "document": { "type": "CNH", "name": "EXAMPLE SIGNER", "cpf": null },
|
|
1758
|
+
* "matches": { "cpf": null, "name": 0.52, "birth_date": null },
|
|
1759
|
+
* "checks": [{ "name": "name", "result": "review", "score": 0.52, "reasons": ["NAME_MISMATCH"] }],
|
|
1760
|
+
* "images": ["document_front", "face"], // available only while InReview
|
|
1761
|
+
* "ruleset_version": "2026-10-12.2", "evidence_sha256": null,
|
|
1762
|
+
* "reviewed_by": null, "reviewed_at": null, "review_note": null, "completed_at": null
|
|
1763
|
+
* }
|
|
1764
|
+
* ```
|
|
1765
|
+
* @throws {ValidationError} If any ID is blank or invalid for a URL.
|
|
1766
|
+
* @throws {ApiError} `401` for invalid credentials; `404` for an unknown
|
|
1767
|
+
* assignment, signer or verification; `500` for a server failure.
|
|
1768
|
+
* @example
|
|
1769
|
+
* ```ts
|
|
1770
|
+
* const review = await client.assignments.getIdentityVerification('doc-1', 'asg-1', 'signer-1');
|
|
1771
|
+
* console.log(review.status, review.images.length);
|
|
1772
|
+
* ```
|
|
1773
|
+
*/
|
|
1774
|
+
async getIdentityVerification(documentId, assignmentId, signerId) {
|
|
1775
|
+
const path2 = this.identityVerificationPath(documentId, assignmentId, signerId);
|
|
1776
|
+
return this.call("Failed to fetch signer identity review", () => this.http.get(path2));
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* Download identity review evidence
|
|
1780
|
+
* (`GET /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification/images/{name}`).
|
|
1781
|
+
*
|
|
1782
|
+
* No request body. The provider supplies the bytes on each request; Assinafy
|
|
1783
|
+
* never stores them. Available only while the review is open. Keep these
|
|
1784
|
+
* sensitive bytes out of caches and logs (`Cache-Control: no-store`).
|
|
1785
|
+
*
|
|
1786
|
+
* @param documentId - Document owning the assignment.
|
|
1787
|
+
* @param assignmentId - Assignment containing the signer.
|
|
1788
|
+
* @param signerId - Signer whose evidence to view.
|
|
1789
|
+
* @param name - One of the review's `images`: `document_front`,
|
|
1790
|
+
* `document_back`, `document_pdf`, or `face`.
|
|
1791
|
+
* @returns Raw JPEG, PNG or PDF bytes as a `Buffer`.
|
|
1792
|
+
* @throws {ValidationError} If an ID or image name is invalid.
|
|
1793
|
+
* @throws {ApiError} `401` for invalid credentials; `404` for absent evidence
|
|
1794
|
+
* or a decided review; `500` for a provider/server failure.
|
|
1795
|
+
* @example
|
|
1796
|
+
* ```ts
|
|
1797
|
+
* const bytes = await client.assignments.downloadIdentityVerificationImage('doc-1', 'asg-1', 'signer-1', 'face');
|
|
1798
|
+
* ```
|
|
1799
|
+
*/
|
|
1800
|
+
async downloadIdentityVerificationImage(documentId, assignmentId, signerId, name) {
|
|
1801
|
+
const path2 = this.identityVerificationPath(documentId, assignmentId, signerId);
|
|
1802
|
+
if (!["document_front", "document_back", "document_pdf", "face"].includes(name)) {
|
|
1803
|
+
throw new ValidationError("Invalid identity verification image name");
|
|
1804
|
+
}
|
|
1805
|
+
return this.callBinary(
|
|
1806
|
+
"Failed to download identity review evidence",
|
|
1807
|
+
() => this.http.get(`${path2}/images/${name}`, { responseType: "arraybuffer" })
|
|
1808
|
+
);
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Decide a signer identity review
|
|
1812
|
+
* (`POST /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification/review`).
|
|
1813
|
+
*
|
|
1814
|
+
* Requires `InReview` and a document at `pending_signature` or
|
|
1815
|
+
* `pending_identity_review`. Approval allows certification once all signers
|
|
1816
|
+
* sign and every review is approved. Rejection cancels the document as
|
|
1817
|
+
* `rejected_by_user` and sends cancellation notices to signers and copy
|
|
1818
|
+
* receivers. The note is hidden from them; the provider receives the decision.
|
|
1819
|
+
*
|
|
1820
|
+
* Request body (`application/json`):
|
|
1821
|
+
* ```jsonc
|
|
1822
|
+
* { "decision": "Approved", "note": "Verified independently." }
|
|
1823
|
+
* ```
|
|
1824
|
+
* @param documentId - Document owning the assignment.
|
|
1825
|
+
* @param assignmentId - Assignment containing the signer.
|
|
1826
|
+
* @param signerId - Signer whose review to decide.
|
|
1827
|
+
* @param payload - Explicit account review decision.
|
|
1828
|
+
* @param payload.decision - `Approved` or `Rejected`.
|
|
1829
|
+
* @param payload.note - Optional nullable note, at most 2000 characters.
|
|
1830
|
+
* @returns The updated review, in the full
|
|
1831
|
+
* {@link AssignmentResource.getIdentityVerification} shape:
|
|
1832
|
+
* ```jsonc
|
|
1833
|
+
* {
|
|
1834
|
+
* "id": "verification_example", "status": "Approved",
|
|
1835
|
+
* "provider": "AssinafyVerify", "verification_method": "IdDocumentFaceMatchBasic",
|
|
1836
|
+
* "reason_codes": [{ "code": "NAME_MISMATCH", "description": "Name differs" }],
|
|
1837
|
+
* "evidence_available": true,
|
|
1838
|
+
* "expected": { "name": "Example Signer", "cpf": null },
|
|
1839
|
+
* "document": { "type": "CNH", "name": "EXAMPLE SIGNER", "cpf": null },
|
|
1840
|
+
* "matches": { "cpf": null, "name": 0.52, "birth_date": null },
|
|
1841
|
+
* "checks": [{ "name": "name", "result": "review", "score": 0.52, "reasons": ["NAME_MISMATCH"] }],
|
|
1842
|
+
* "images": [], "ruleset_version": "2026-10-12.2", "evidence_sha256": null,
|
|
1843
|
+
* "reviewed_by": { "id": "user_example", "name": "Example Reviewer" },
|
|
1844
|
+
* "reviewed_at": "2026-10-16T12:00:00Z", "review_note": "Verified independently.",
|
|
1845
|
+
* "completed_at": "2026-10-16T12:00:00Z"
|
|
1846
|
+
* }
|
|
1847
|
+
* ```
|
|
1848
|
+
* @throws {ValidationError} If IDs, decision or note are invalid.
|
|
1849
|
+
* @throws {ApiError} `400` for a closed review or invalid document state;
|
|
1850
|
+
* `401` for invalid credentials; `404` if absent; `500` for a server failure.
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```ts
|
|
1853
|
+
* await client.assignments.reviewIdentityVerification('doc-1', 'asg-1', 'signer-1', {
|
|
1854
|
+
* decision: 'Approved', note: 'Verified independently.',
|
|
1855
|
+
* });
|
|
1856
|
+
* ```
|
|
1857
|
+
*/
|
|
1858
|
+
async reviewIdentityVerification(documentId, assignmentId, signerId, payload) {
|
|
1859
|
+
const path2 = this.identityVerificationPath(documentId, assignmentId, signerId);
|
|
1860
|
+
assertRecord(payload, "identity review payload");
|
|
1861
|
+
if (payload.decision !== "Approved" && payload.decision !== "Rejected") {
|
|
1862
|
+
throw new ValidationError("decision must be Approved or Rejected");
|
|
1863
|
+
}
|
|
1864
|
+
if (payload.note !== void 0 && payload.note !== null && (typeof payload.note !== "string" || [...payload.note].length > 2e3)) {
|
|
1865
|
+
throw new ValidationError("note must be a string of at most 2000 characters, or null");
|
|
1866
|
+
}
|
|
1867
|
+
const body = { decision: payload.decision };
|
|
1868
|
+
if (payload.note !== void 0) body.note = payload.note;
|
|
1869
|
+
return this.call(
|
|
1870
|
+
"Failed to decide signer identity review",
|
|
1871
|
+
() => this.http.post(`${path2}/review`, body)
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
identityVerificationPath(documentId, assignmentId, signerId) {
|
|
1875
|
+
const docId = this.pathSegment(documentId, "Document ID");
|
|
1876
|
+
const asgId = this.pathSegment(assignmentId, "Assignment ID");
|
|
1877
|
+
const sid = this.pathSegment(signerId, "Signer ID");
|
|
1878
|
+
return `/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification`;
|
|
1879
|
+
}
|
|
1693
1880
|
};
|
|
1694
1881
|
|
|
1695
1882
|
// src/resources/documents.ts
|
|
@@ -1703,6 +1890,7 @@ function validateDocumentWaitOptions(options) {
|
|
|
1703
1890
|
var READY_STATUSES = /* @__PURE__ */ new Set([
|
|
1704
1891
|
"metadata_ready",
|
|
1705
1892
|
"pending_signature",
|
|
1893
|
+
"pending_identity_review",
|
|
1706
1894
|
"certificated"
|
|
1707
1895
|
]);
|
|
1708
1896
|
var FAILED_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -1729,6 +1917,9 @@ var DocumentResource = class extends BaseResource {
|
|
|
1729
1917
|
*
|
|
1730
1918
|
* @param source - The PDF to upload, as a file path or an in-memory buffer.
|
|
1731
1919
|
* @param options - Display name, metadata, and account override.
|
|
1920
|
+
* @param options.name - Multipart filename override; the API derives the display name from it.
|
|
1921
|
+
* @param options.metadata - JSON metadata (compatibility multipart part).
|
|
1922
|
+
* @param options.accountId - Override the client's default workspace.
|
|
1732
1923
|
* @returns The created document, freshly uploaded (`status: 'uploaded'`,
|
|
1733
1924
|
* empty `pages` until `metadata_ready`). Response shape:
|
|
1734
1925
|
* ```jsonc
|
|
@@ -1839,7 +2030,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
1839
2030
|
* method: 'virtual',
|
|
1840
2031
|
* 'per-page': 50,
|
|
1841
2032
|
* });
|
|
1842
|
-
* console.log(data[0]?.pages
|
|
2033
|
+
* console.log(data[0]?.pages?.length, meta?.total);
|
|
1843
2034
|
* ```
|
|
1844
2035
|
*/
|
|
1845
2036
|
async list(params = {}, accountId) {
|
|
@@ -2052,7 +2243,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2052
2243
|
}
|
|
2053
2244
|
/**
|
|
2054
2245
|
* Poll {@link DocumentResource.details} until the document reaches a ready
|
|
2055
|
-
* status (`metadata_ready`, `pending_signature`,
|
|
2246
|
+
* status (`metadata_ready`, `pending_signature`, `pending_identity_review`,
|
|
2247
|
+
* or `certificated`),
|
|
2056
2248
|
* throwing on a terminal failure status or timeout.
|
|
2057
2249
|
*
|
|
2058
2250
|
* Transient errors are tolerated — a `5xx` or `429` is retried on the next
|
|
@@ -2062,6 +2254,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2062
2254
|
* @param documentId - The document to wait on.
|
|
2063
2255
|
* @param options - `maxWaitMs` (default `30_000`) and `pollIntervalMs`
|
|
2064
2256
|
* (default `2_000`).
|
|
2257
|
+
* @param options.maxWaitMs - Finite non-negative wait budget in milliseconds; default `30_000`.
|
|
2258
|
+
* @param options.pollIntervalMs - Finite positive polling interval in milliseconds; default `2_000`.
|
|
2065
2259
|
* @returns The document details once it reaches a ready status (see
|
|
2066
2260
|
* {@link DocumentResource.details} for the shape).
|
|
2067
2261
|
* @throws {ValidationError} If `documentId` is missing, the document enters
|
|
@@ -2329,6 +2523,9 @@ var DocumentResource = class extends BaseResource {
|
|
|
2329
2523
|
* names are not portable identifiers and should not be used here. This
|
|
2330
2524
|
* overwrites the existing set — use
|
|
2331
2525
|
* {@link DocumentResource.addTags} to append.
|
|
2526
|
+
* Older sandbox deployments interpret these strings as names and create
|
|
2527
|
+
* ID-named tags for ID inputs; pass existing names intentionally there.
|
|
2528
|
+
* Strings are sent unchanged. See `docs/COMPATIBILITY.md` for this variant.
|
|
2332
2529
|
*
|
|
2333
2530
|
* Request body (`application/json`):
|
|
2334
2531
|
* ```jsonc
|
|
@@ -2380,6 +2577,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2380
2577
|
* `tags` is a non-empty array of tag **IDs**. Attaching an ID already
|
|
2381
2578
|
* present is a no-op. To replace the whole set instead, use
|
|
2382
2579
|
* {@link DocumentResource.replaceTags}.
|
|
2580
|
+
* On older name-based sandbox deployments, pass existing tag names
|
|
2581
|
+
* intentionally; ID inputs create ID-named tags. No automatic remapping occurs.
|
|
2383
2582
|
*
|
|
2384
2583
|
* Request body (`application/json`):
|
|
2385
2584
|
* ```jsonc
|
|
@@ -2499,10 +2698,17 @@ var DocumentResource = class extends BaseResource {
|
|
|
2499
2698
|
* plus optional `verification_method`, `notification_methods`, `step`).
|
|
2500
2699
|
* Only one notification method is allowed per signer; when only one of the
|
|
2501
2700
|
* verification/notification fields is supplied, the API infers the other.
|
|
2502
|
-
* `DigitalCertificate` costs
|
|
2701
|
+
* `DigitalCertificate` costs 0.5 credits, requires the feature plus a
|
|
2503
2702
|
* signer `government_id`, and that signer must be alone in its step.
|
|
2703
|
+
* `IdDocumentFaceMatchBasic` needs the ID Document + Face Match feature
|
|
2704
|
+
* and a valid CPF in `government_id`; estimate the per-signer fee first.
|
|
2504
2705
|
* @param options - Optional `name`, `message`, `expires_at`,
|
|
2505
2706
|
* `editor_fields`, `tags`.
|
|
2707
|
+
* @param options.name - Generated document display name.
|
|
2708
|
+
* @param options.message - Signing invitation message.
|
|
2709
|
+
* @param options.expires_at - ISO-8601 signature deadline.
|
|
2710
|
+
* @param options.editor_fields - Template editor values as `{ field_id, value }` entries.
|
|
2711
|
+
* @param options.tags - Tag names attached to the generated document.
|
|
2506
2712
|
* @param accountId - Override the client's default account ID.
|
|
2507
2713
|
* @returns The created document (an {@link IDocumentDetailsResponse} with
|
|
2508
2714
|
* `template_id` set and its `assignment` populated):
|
|
@@ -2574,7 +2780,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2574
2780
|
*
|
|
2575
2781
|
* A dry run: sends only `{ signers }` and consumes nothing. Use it to check
|
|
2576
2782
|
* balances before calling {@link DocumentResource.createFromTemplate}.
|
|
2577
|
-
* `DigitalCertificate` adds
|
|
2783
|
+
* `DigitalCertificate` adds 0.5 credits per signer and has the same feature,
|
|
2578
2784
|
* `government_id`, and signing-step prerequisites as document creation.
|
|
2579
2785
|
*
|
|
2580
2786
|
* Request body (`application/json`):
|
|
@@ -2764,32 +2970,63 @@ var DocumentResource = class extends BaseResource {
|
|
|
2764
2970
|
() => this.publicHttp.get(`/public/documents/${this.pathSegment(id, "Document ID")}`)
|
|
2765
2971
|
);
|
|
2766
2972
|
}
|
|
2767
|
-
|
|
2973
|
+
/**
|
|
2974
|
+
* Email the signer the verification token that unlocks a document
|
|
2975
|
+
* (`PUT /public/documents/{documentId}/send-token`).
|
|
2976
|
+
*
|
|
2977
|
+
* Part of the public signing flow: dispatches the 6-digit verification
|
|
2978
|
+
* token the signer enters to view the document. Runs on the
|
|
2979
|
+
* credential-free transport. The contract accepts only the `email`
|
|
2980
|
+
* channel, and both body fields are required.
|
|
2981
|
+
*
|
|
2982
|
+
* Request body (`application/json`):
|
|
2983
|
+
* ```jsonc
|
|
2984
|
+
* { "channel": "email", "recipient": "signer@example.com" }
|
|
2985
|
+
* ```
|
|
2986
|
+
*
|
|
2987
|
+
* @param documentId - The document to send the token for.
|
|
2988
|
+
* @param recipient - The signer's email address.
|
|
2989
|
+
* @param channel - Delivery channel; only `email` is accepted (default).
|
|
2990
|
+
* @returns The delivery confirmation (`data` of the envelope):
|
|
2991
|
+
* ```jsonc
|
|
2992
|
+
* {
|
|
2993
|
+
* "document": {
|
|
2994
|
+
* "resource": "document",
|
|
2995
|
+
* "id": "a1b2c3d4e5f6a7b8c9d0",
|
|
2996
|
+
* "name": "Contract.pdf",
|
|
2997
|
+
* "page_count": 3,
|
|
2998
|
+
* "created_by": "Jane Doe"
|
|
2999
|
+
* },
|
|
3000
|
+
* "channel": "email",
|
|
3001
|
+
* "recipient": "signer@example.com"
|
|
3002
|
+
* }
|
|
3003
|
+
* ```
|
|
3004
|
+
* @throws {ValidationError} If `documentId` is missing, `recipient` is not
|
|
3005
|
+
* a valid email address, or `channel` is not `email`.
|
|
3006
|
+
* @throws {ApiError} `400` if validation fails; `404` if the document does
|
|
3007
|
+
* not exist.
|
|
3008
|
+
*
|
|
3009
|
+
* @example
|
|
3010
|
+
* ```ts
|
|
3011
|
+
* const sent = await client.documents.sendToken('doc-1', 'signer@example.com');
|
|
3012
|
+
* console.log(sent.recipient);
|
|
3013
|
+
* ```
|
|
3014
|
+
*/
|
|
3015
|
+
async sendToken(documentId, recipient, channel = "email") {
|
|
2768
3016
|
const id = this.requireId(documentId, "Document ID");
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
if (channel === void 0 && !isEmail(recipient)) {
|
|
2772
|
-
throw new ValidationError("recipient must be a valid email address");
|
|
3017
|
+
if (channel !== "email") {
|
|
3018
|
+
throw new ValidationError('channel must be "email"', { channel });
|
|
2773
3019
|
}
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
return this.callVoid(
|
|
2777
|
-
"Failed to send signing token",
|
|
2778
|
-
() => this.publicHttp.put(path2, { recipient, channel })
|
|
2779
|
-
);
|
|
2780
|
-
}
|
|
2781
|
-
try {
|
|
2782
|
-
return await this.callVoid(
|
|
2783
|
-
"Failed to send signing token",
|
|
2784
|
-
() => this.publicHttp.put(path2, { email: recipient })
|
|
2785
|
-
);
|
|
2786
|
-
} catch (error) {
|
|
2787
|
-
if (!isLegacySendTokenValidation(error)) throw error;
|
|
2788
|
-
return this.callVoid(
|
|
2789
|
-
"Failed to send signing token",
|
|
2790
|
-
() => this.publicHttp.put(path2, { recipient, channel: "email" })
|
|
2791
|
-
);
|
|
3020
|
+
if (!isEmail(recipient)) {
|
|
3021
|
+
throw new ValidationError("recipient must be a valid email address");
|
|
2792
3022
|
}
|
|
3023
|
+
return this.call(
|
|
3024
|
+
"Failed to send signing token",
|
|
3025
|
+
() => this.publicHttp.put(
|
|
3026
|
+
`/public/documents/${this.pathSegment(id, "Document ID")}/send-token`,
|
|
3027
|
+
{ channel, recipient }
|
|
3028
|
+
)
|
|
3029
|
+
);
|
|
2793
3030
|
}
|
|
2794
3031
|
/**
|
|
2795
3032
|
* Quick boolean check (`GET /documents/{documentId}`): has every signer
|
|
@@ -2882,7 +3119,6 @@ function normaliseTemplateSigners(signers) {
|
|
|
2882
3119
|
if (signer.step !== void 0) projected.step = signer.step;
|
|
2883
3120
|
return projected;
|
|
2884
3121
|
});
|
|
2885
|
-
validateSigningOrder(normalised, "template signers");
|
|
2886
3122
|
return normalised;
|
|
2887
3123
|
}
|
|
2888
3124
|
function normaliseTemplateEditorFields(fields) {
|
|
@@ -2935,23 +3171,6 @@ function validateWaitOption(value, name) {
|
|
|
2935
3171
|
function sleep(ms) {
|
|
2936
3172
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2937
3173
|
}
|
|
2938
|
-
function isLegacySendTokenValidation(error) {
|
|
2939
|
-
if (!(error instanceof ApiError) || error.statusCode !== 400 && error.statusCode !== 422) {
|
|
2940
|
-
return false;
|
|
2941
|
-
}
|
|
2942
|
-
const namesLegacyField = /\b(?:channel|recipient)\b/iu.test(error.message);
|
|
2943
|
-
const saysRequired = /\b(?:required|obrigat[oó]ri[oa])\b/iu.test(error.message);
|
|
2944
|
-
if (namesLegacyField && saysRequired) return true;
|
|
2945
|
-
const response = error.responseData;
|
|
2946
|
-
if (!response || typeof response !== "object" || Array.isArray(response)) return false;
|
|
2947
|
-
const errors = response["errors"];
|
|
2948
|
-
if (!errors || typeof errors !== "object" || Array.isArray(errors)) return false;
|
|
2949
|
-
return ["channel", "recipient"].some((field) => {
|
|
2950
|
-
if (!Object.hasOwn(errors, field)) return false;
|
|
2951
|
-
const detail = JSON.stringify(errors[field]);
|
|
2952
|
-
return /required|obrigat[oó]ri[oa]/iu.test(detail);
|
|
2953
|
-
});
|
|
2954
|
-
}
|
|
2955
3174
|
|
|
2956
3175
|
// src/resources/signers.ts
|
|
2957
3176
|
var SignerResource = class extends BaseResource {
|
|
@@ -3219,9 +3438,8 @@ var SignerResource = class extends BaseResource {
|
|
|
3219
3438
|
* re-filtered here for an exact, case-insensitive email match.
|
|
3220
3439
|
*
|
|
3221
3440
|
* Page size is pinned to {@link MAX_LIST_PAGE_SIZE}, the largest page the
|
|
3222
|
-
* server actually returns.
|
|
3223
|
-
*
|
|
3224
|
-
* miss one — the API exposes no exact-email filter to rule that out.
|
|
3441
|
+
* server actually returns. Pages are searched until an exact match is found
|
|
3442
|
+
* or the result set ends, so substring matches cannot hide an existing signer.
|
|
3225
3443
|
*
|
|
3226
3444
|
* A `404` from the underlying list is treated as "no match" and mapped to
|
|
3227
3445
|
* `null`; any other {@link ApiError} propagates.
|
|
@@ -3251,12 +3469,16 @@ var SignerResource = class extends BaseResource {
|
|
|
3251
3469
|
async findByEmail(email, accountId) {
|
|
3252
3470
|
this.assertEmail(email);
|
|
3253
3471
|
try {
|
|
3254
|
-
const { data } = await this.list(
|
|
3255
|
-
{ search: email, "per-page": MAX_LIST_PAGE_SIZE },
|
|
3256
|
-
accountId
|
|
3257
|
-
);
|
|
3258
3472
|
const lower = email.toLowerCase();
|
|
3259
|
-
|
|
3473
|
+
for (let page = 1; ; page++) {
|
|
3474
|
+
const { data, meta } = await this.list(
|
|
3475
|
+
{ search: email, "per-page": MAX_LIST_PAGE_SIZE, page },
|
|
3476
|
+
accountId
|
|
3477
|
+
);
|
|
3478
|
+
const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
|
|
3479
|
+
if (match) return match;
|
|
3480
|
+
if (data.length === 0 || (meta?.last_page !== void 0 ? page >= meta.last_page : data.length < MAX_LIST_PAGE_SIZE)) return null;
|
|
3481
|
+
}
|
|
3260
3482
|
} catch (err) {
|
|
3261
3483
|
if (err instanceof ApiError && err.statusCode === 404) {
|
|
3262
3484
|
return null;
|
|
@@ -3611,6 +3833,8 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3611
3833
|
* @param accountId - Account to aggregate.
|
|
3612
3834
|
* @param params - Omit for 12 monthly rows, or request daily rows with
|
|
3613
3835
|
* `{ granularity: 'daily', month: '2026-06' }`.
|
|
3836
|
+
* @param params.granularity - `monthly` (default) or `daily`.
|
|
3837
|
+
* @param params.month - Month in `YYYY-MM` format; required for daily rows.
|
|
3614
3838
|
* @returns Zero-filled KPI rows:
|
|
3615
3839
|
* ```jsonc
|
|
3616
3840
|
* [{
|
|
@@ -3736,6 +3960,7 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3736
3960
|
* @param accountId - The workspace to delete.
|
|
3737
3961
|
* @param options - Set `force: true` to cancel an active paid subscription
|
|
3738
3962
|
* and proceed with deletion.
|
|
3963
|
+
* @param options.force - Cancel an active subscription and bypass deletion restrictions.
|
|
3739
3964
|
* @returns Nothing on success (`200` with no meaningful body).
|
|
3740
3965
|
* @throws {ValidationError} If `accountId` is missing.
|
|
3741
3966
|
* @throws {ApiError} `400` (with a `restrictions` list) when the workspace
|
|
@@ -4118,6 +4343,8 @@ var WebhookResource = class extends BaseResource {
|
|
|
4118
4343
|
* `account:read` scope.
|
|
4119
4344
|
*
|
|
4120
4345
|
* @param accountId - Override the client's default account ID.
|
|
4346
|
+
* @param params - Optional endpoint filters.
|
|
4347
|
+
* @param params.url - Match the exact registered endpoint URL.
|
|
4121
4348
|
* @returns Every endpoint (1 on free plans, up to 3 on paid plans):
|
|
4122
4349
|
* ```jsonc
|
|
4123
4350
|
* [
|
|
@@ -4143,9 +4370,14 @@ var WebhookResource = class extends BaseResource {
|
|
|
4143
4370
|
* const signed = endpoints.filter((endpoint) => endpoint.signing_enabled);
|
|
4144
4371
|
* ```
|
|
4145
4372
|
*/
|
|
4146
|
-
async listEndpoints(accountId) {
|
|
4373
|
+
async listEndpoints(accountId, params = {}) {
|
|
4374
|
+
assertRecord(params, "webhook endpoint filters");
|
|
4375
|
+
if (params.url !== void 0) validateWebhookUrl(params.url);
|
|
4147
4376
|
const path2 = this.endpointsPath(accountId);
|
|
4148
|
-
return this.call(
|
|
4377
|
+
return this.call(
|
|
4378
|
+
"Failed to list webhook endpoints",
|
|
4379
|
+
() => this.http.get(path2, params.url === void 0 ? void 0 : { params: { url: params.url } })
|
|
4380
|
+
);
|
|
4149
4381
|
}
|
|
4150
4382
|
/**
|
|
4151
4383
|
* Register a URL to receive the account's webhook events
|
|
@@ -4153,8 +4385,9 @@ var WebhookResource = class extends BaseResource {
|
|
|
4153
4385
|
*
|
|
4154
4386
|
* An account can have 1 endpoint, or up to 3 on paid plans. Each endpoint
|
|
4155
4387
|
* of a workspace needs a different `url`. With `signing_enabled: true` the
|
|
4156
|
-
* API
|
|
4157
|
-
* {@link WebhookResource.getEndpointSecret}
|
|
4388
|
+
* API returns a signing `secret` in this creation response. Store it now:
|
|
4389
|
+
* OAuth applications cannot call {@link WebhookResource.getEndpointSecret}
|
|
4390
|
+
* or rotate it later. When `events` is omitted or
|
|
4158
4391
|
* empty, {@link DEFAULT_WEBHOOK_EVENTS} is sent. OAuth tokens need the
|
|
4159
4392
|
* `webhooks:write` scope.
|
|
4160
4393
|
*
|
|
@@ -4184,6 +4417,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
4184
4417
|
* "events": ["document_ready", "signer_signed_document"],
|
|
4185
4418
|
* "is_active": true,
|
|
4186
4419
|
* "signing_enabled": true, // deliveries carry a `webhook-signature` header
|
|
4420
|
+
* "secret": "whsec_c2VjcmV0", // only in this response when signing is enabled
|
|
4187
4421
|
* "created_at": "2026-10-01T12:00:00Z",
|
|
4188
4422
|
* "updated_at": "2026-10-01T12:00:00Z"
|
|
4189
4423
|
* }
|
|
@@ -4203,7 +4437,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
4203
4437
|
* events: ['document_ready', 'signer_signed_document'],
|
|
4204
4438
|
* signing_enabled: true,
|
|
4205
4439
|
* });
|
|
4206
|
-
*
|
|
4440
|
+
* if (endpoint.secret) await secretStore.save(endpoint.id, endpoint.secret);
|
|
4207
4441
|
* ```
|
|
4208
4442
|
*/
|
|
4209
4443
|
async createEndpoint(payload, accountId) {
|
|
@@ -4328,6 +4562,32 @@ var WebhookResource = class extends BaseResource {
|
|
|
4328
4562
|
this.logger.info("Deleting webhook endpoint");
|
|
4329
4563
|
await this.callVoid("Failed to delete webhook endpoint", () => this.http.delete(path2));
|
|
4330
4564
|
}
|
|
4565
|
+
/**
|
|
4566
|
+
* Delete a webhook endpoint using its registered URL
|
|
4567
|
+
* (`DELETE /accounts/{accountId}/webhooks/endpoints?url=…`).
|
|
4568
|
+
*
|
|
4569
|
+
* No request body. The query URL must match the registered value exactly.
|
|
4570
|
+
* Frees its plan slot; OAuth applications need `webhooks:write`.
|
|
4571
|
+
*
|
|
4572
|
+
* @param url - Exact registered HTTP(S) endpoint URL, including its query.
|
|
4573
|
+
* @param accountId - Override the client's default workspace.
|
|
4574
|
+
* @returns Resolves on acknowledgement (`{ "status": 200, "data": [] }`).
|
|
4575
|
+
* @throws {ValidationError} If the URL is invalid or the account is missing.
|
|
4576
|
+
* @throws {ApiError} `400` for a missing URL; `401` for invalid credentials;
|
|
4577
|
+
* `403` for missing scope; `404` if no endpoint uses the URL; `500` on failure.
|
|
4578
|
+
* @example
|
|
4579
|
+
* ```ts
|
|
4580
|
+
* await client.webhooks.deleteEndpointByUrl('https://example.com/webhooks/assinafy');
|
|
4581
|
+
* ```
|
|
4582
|
+
*/
|
|
4583
|
+
async deleteEndpointByUrl(url, accountId) {
|
|
4584
|
+
validateWebhookUrl(url);
|
|
4585
|
+
const path2 = this.endpointsPath(accountId);
|
|
4586
|
+
return this.callVoid(
|
|
4587
|
+
"Failed to delete webhook endpoint",
|
|
4588
|
+
() => this.http.delete(path2, { params: { url } })
|
|
4589
|
+
);
|
|
4590
|
+
}
|
|
4331
4591
|
/**
|
|
4332
4592
|
* Return the secret that signs deliveries to an endpoint
|
|
4333
4593
|
* (`GET /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret`).
|
|
@@ -4450,6 +4710,8 @@ var TemplateResource = class extends BaseResource {
|
|
|
4450
4710
|
*
|
|
4451
4711
|
* @param source - The PDF to upload, as a file path or an in-memory buffer.
|
|
4452
4712
|
* @param options - `name` (display name) and an optional `accountId` override.
|
|
4713
|
+
* @param options.name - Multipart filename override, with a `.pdf` extension.
|
|
4714
|
+
* @param options.accountId - Override the client's default workspace.
|
|
4453
4715
|
* @returns The created template (envelope unwrapped). Response shape:
|
|
4454
4716
|
* ```jsonc
|
|
4455
4717
|
* {
|
|
@@ -4615,7 +4877,7 @@ var TemplateResource = class extends BaseResource {
|
|
|
4615
4877
|
* @example
|
|
4616
4878
|
* ```ts
|
|
4617
4879
|
* const tmpl = await client.templates.get('103ad2171db7979468c3e97eb067');
|
|
4618
|
-
* if (tmpl.status === 'Ready') console.log(tmpl.pages
|
|
4880
|
+
* if (tmpl.status === 'Ready') console.log(tmpl.pages?.length ?? 0);
|
|
4619
4881
|
* ```
|
|
4620
4882
|
*/
|
|
4621
4883
|
async get(templateId, accountId) {
|
|
@@ -4777,6 +5039,7 @@ var TagResource = class extends BaseResource {
|
|
|
4777
5039
|
*
|
|
4778
5040
|
* @param params - Optional filters. `search` matches tag names
|
|
4779
5041
|
* case-insensitively (substring).
|
|
5042
|
+
* @param params.search - Optional case-insensitive tag-name substring.
|
|
4780
5043
|
* @param accountId - Override the client's default account ID.
|
|
4781
5044
|
* @returns The matching tags (list items carry no `resource` field):
|
|
4782
5045
|
* ```jsonc
|
|
@@ -4950,6 +5213,8 @@ var TagResource = class extends BaseResource {
|
|
|
4950
5213
|
* @param tagId - The tag to delete.
|
|
4951
5214
|
* @param options - `force` to detach-and-delete when the tag is still in
|
|
4952
5215
|
* use, and `accountId` to override the client's default account ID.
|
|
5216
|
+
* @param options.force - Detach the tag from documents before deletion.
|
|
5217
|
+
* @param options.accountId - Override the client's default workspace.
|
|
4953
5218
|
* @returns `{ deleted: true }` when the tag was deleted.
|
|
4954
5219
|
* @throws {ValidationError} If `tagId` is missing, or no account ID is available.
|
|
4955
5220
|
* @throws {ApiError} `404` if the tag does not exist; `409` if the tag is
|
|
@@ -6515,6 +6780,8 @@ var FieldsResource = class extends BaseResource {
|
|
|
6515
6780
|
* @param value - The value to check (validated against the field's
|
|
6516
6781
|
* type/regex). Sent as `{ value }` in the request body.
|
|
6517
6782
|
* @param options - Account override and optional legacy `signerAccessCode`.
|
|
6783
|
+
* @param options.accountId - Override the client's default workspace.
|
|
6784
|
+
* @param options.signerAccessCode - Legacy signer code sent as a query parameter.
|
|
6518
6785
|
* @returns The validation result. Response shape:
|
|
6519
6786
|
* ```jsonc
|
|
6520
6787
|
* {
|
|
@@ -6575,6 +6842,8 @@ var FieldsResource = class extends BaseResource {
|
|
|
6575
6842
|
*
|
|
6576
6843
|
* @param entries - Non-empty array of `{ field_id, value }` pairs.
|
|
6577
6844
|
* @param options - Account override and optional legacy `signerAccessCode`.
|
|
6845
|
+
* @param options.accountId - Override the client's default workspace.
|
|
6846
|
+
* @param options.signerAccessCode - Legacy signer code sent as a query parameter.
|
|
6578
6847
|
* @returns One validation result per entry. Response shape:
|
|
6579
6848
|
* ```jsonc
|
|
6580
6849
|
* [
|
|
@@ -6664,7 +6933,14 @@ function validateSignerAccessCode(value) {
|
|
|
6664
6933
|
var SignerDocumentsResource = class extends BaseResource {
|
|
6665
6934
|
constructor(http, defaultAccountId, logger, publicHttp) {
|
|
6666
6935
|
super(withoutCredentials(publicHttp ?? http), defaultAccountId, logger);
|
|
6936
|
+
this.workspaceHttp = http;
|
|
6667
6937
|
}
|
|
6938
|
+
/**
|
|
6939
|
+
* Credentialed transport used only by the explicit `*AsWorkspace` methods.
|
|
6940
|
+
* Every access-code method stays on the credential-free `http`, so a
|
|
6941
|
+
* signer code and the API key or bearer token never share a request.
|
|
6942
|
+
*/
|
|
6943
|
+
workspaceHttp;
|
|
6668
6944
|
/**
|
|
6669
6945
|
* Fetch the document currently awaiting a given signer
|
|
6670
6946
|
* (`GET /signers/{signer_id}/document?signer-access-code=…`).
|
|
@@ -6837,6 +7113,73 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6837
7113
|
})
|
|
6838
7114
|
);
|
|
6839
7115
|
}
|
|
7116
|
+
/**
|
|
7117
|
+
* List a signer's documents with the workspace credentials
|
|
7118
|
+
* (`GET /signers/{signer_id}/documents`).
|
|
7119
|
+
*
|
|
7120
|
+
* The same operation as {@link SignerDocumentsResource.list}, authorised by
|
|
7121
|
+
* the client's API key or OAuth bearer token instead of a signer access
|
|
7122
|
+
* code. No `signer-access-code` is sent.
|
|
7123
|
+
*
|
|
7124
|
+
* @param signerId - The signer whose documents are listed.
|
|
7125
|
+
* @param params - Pagination: `page`, `per-page` (also accepts `per_page`).
|
|
7126
|
+
* @returns Documents in the compact {@link IDocumentListItem} shape, with
|
|
7127
|
+
* pagination in `meta` (same shape as {@link SignerDocumentsResource.list}):
|
|
7128
|
+
* ```jsonc
|
|
7129
|
+
* {
|
|
7130
|
+
* "data": [{ "id": "103acccd24234c07858ffddf6d84", "name": "Service agreement.pdf", "status": "pending_signature" }],
|
|
7131
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
|
|
7132
|
+
* }
|
|
7133
|
+
* ```
|
|
7134
|
+
* @throws {ValidationError} If `signerId` is missing.
|
|
7135
|
+
* @throws {ApiError} `401` if the workspace credentials are rejected.
|
|
7136
|
+
*
|
|
7137
|
+
* @example
|
|
7138
|
+
* ```ts
|
|
7139
|
+
* const { data } = await client.signerDocuments.listAsWorkspace(signerId, { page: 1 });
|
|
7140
|
+
* ```
|
|
7141
|
+
*/
|
|
7142
|
+
async listAsWorkspace(signerId, params = {}) {
|
|
7143
|
+
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7144
|
+
return this.callList(
|
|
7145
|
+
"Failed to list signer documents",
|
|
7146
|
+
() => this.workspaceHttp.get(`/signers/${sid}/documents`, {
|
|
7147
|
+
params: cleanListParams(params)
|
|
7148
|
+
})
|
|
7149
|
+
);
|
|
7150
|
+
}
|
|
7151
|
+
/**
|
|
7152
|
+
* Search a signer's documents with the workspace credentials
|
|
7153
|
+
* (`GET /signers/{signer_id}/documents/search`).
|
|
7154
|
+
*
|
|
7155
|
+
* The same operation as {@link SignerDocumentsResource.search}, authorised
|
|
7156
|
+
* by the client's API key or OAuth bearer token instead of a signer access
|
|
7157
|
+
* code. No `signer-access-code` is sent.
|
|
7158
|
+
*
|
|
7159
|
+
* @param signerId - The signer whose documents are searched.
|
|
7160
|
+
* @param search - Free-text term matched against the document name.
|
|
7161
|
+
* @returns Matching documents with pagination in `meta`, as
|
|
7162
|
+
* {@link SignerDocumentsResource.listAsWorkspace} returns.
|
|
7163
|
+
* @throws {ValidationError} If `signerId` is missing or `search` is not a string.
|
|
7164
|
+
* @throws {ApiError} `401` if the workspace credentials are rejected.
|
|
7165
|
+
*
|
|
7166
|
+
* @example
|
|
7167
|
+
* ```ts
|
|
7168
|
+
* const { data } = await client.signerDocuments.searchAsWorkspace(signerId, 'agreement');
|
|
7169
|
+
* ```
|
|
7170
|
+
*/
|
|
7171
|
+
async searchAsWorkspace(signerId, search) {
|
|
7172
|
+
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7173
|
+
if (search !== void 0 && typeof search !== "string") {
|
|
7174
|
+
throw new ValidationError("search must be a string");
|
|
7175
|
+
}
|
|
7176
|
+
return this.callList(
|
|
7177
|
+
"Failed to search signer documents",
|
|
7178
|
+
() => this.workspaceHttp.get(`/signers/${sid}/documents/search`, {
|
|
7179
|
+
params: cleanParams({ search })
|
|
7180
|
+
})
|
|
7181
|
+
);
|
|
7182
|
+
}
|
|
6840
7183
|
/**
|
|
6841
7184
|
* Download one of a signer's document artifacts as raw bytes
|
|
6842
7185
|
* (`GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`).
|
|
@@ -7011,7 +7354,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7011
7354
|
* "has_accepted_terms": false,
|
|
7012
7355
|
* "has_signature": false,
|
|
7013
7356
|
* "has_initial": false,
|
|
7014
|
-
* "is_signature_reusable": false
|
|
7357
|
+
* "is_signature_reusable": false,
|
|
7358
|
+
* "verification_method": "IdDocumentFaceMatchBasic"
|
|
7015
7359
|
* }
|
|
7016
7360
|
* ```
|
|
7017
7361
|
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
@@ -7032,6 +7376,92 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7032
7376
|
() => this.http.get("/signers/self", { params: { "signer-access-code": code } })
|
|
7033
7377
|
);
|
|
7034
7378
|
}
|
|
7379
|
+
/**
|
|
7380
|
+
* Read the signer's identity verification state
|
|
7381
|
+
* (`GET /signers/identity-verification?signer-access-code=…`).
|
|
7382
|
+
*
|
|
7383
|
+
* No request body or workspace credentials. Reads a pending provider
|
|
7384
|
+
* decision when available. A new session can start before the first capture
|
|
7385
|
+
* or after `Expired`; `Declined` and `Abandoned` require a new document and
|
|
7386
|
+
* assignment. `InReview` lets the signer continue; account approval gates
|
|
7387
|
+
* certification, with `pending_identity_review` after everyone signs.
|
|
7388
|
+
*
|
|
7389
|
+
* @param signerAccessCode - Access code from the signer's signing link.
|
|
7390
|
+
* @returns Provider state, with nullable fields before a session exists:
|
|
7391
|
+
* ```jsonc
|
|
7392
|
+
* {
|
|
7393
|
+
* "can_start": false, "status": "Pending",
|
|
7394
|
+
* "url": "https://verify.example.com/c/session#t=opaque",
|
|
7395
|
+
* "expires_at": "2026-10-16T12:30:00Z", "completed_at": null
|
|
7396
|
+
* }
|
|
7397
|
+
* ```
|
|
7398
|
+
* `url` exists only while Pending. It is a bearer link: open it intact,
|
|
7399
|
+
* including its fragment, and keep it out of logs and browser storage.
|
|
7400
|
+
* @throws {ValidationError} If the access code is blank.
|
|
7401
|
+
* @throws {ApiError} `401` for an invalid/expired code; `500` for a server failure.
|
|
7402
|
+
* @example
|
|
7403
|
+
* ```ts
|
|
7404
|
+
* const state = await client.signerDocuments.getIdentityVerification(accessCode);
|
|
7405
|
+
* console.log(state.status, state.can_start);
|
|
7406
|
+
* ```
|
|
7407
|
+
*/
|
|
7408
|
+
async getIdentityVerification(signerAccessCode) {
|
|
7409
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7410
|
+
return this.call(
|
|
7411
|
+
"Failed to fetch signer identity verification",
|
|
7412
|
+
() => this.http.get("/signers/identity-verification", { params: { "signer-access-code": code } })
|
|
7413
|
+
);
|
|
7414
|
+
}
|
|
7415
|
+
/**
|
|
7416
|
+
* Record biometric consent and open an identity verification session
|
|
7417
|
+
* (`POST /signers/identity-verification?signer-access-code=…`).
|
|
7418
|
+
*
|
|
7419
|
+
* Send only after the signer explicitly consents. Starts a session when
|
|
7420
|
+
* none exists or replaces an Expired session. Other states return `400`;
|
|
7421
|
+
* resending a notification never replaces a live session. The account is
|
|
7422
|
+
* billed at assignment creation, with no new charge for a restart.
|
|
7423
|
+
*
|
|
7424
|
+
* Request body (`application/json`):
|
|
7425
|
+
* ```jsonc
|
|
7426
|
+
* { "consent": true }
|
|
7427
|
+
* ```
|
|
7428
|
+
* @param signerAccessCode - Access code from the signer's signing link.
|
|
7429
|
+
* @param payload - Explicit consent from the signer.
|
|
7430
|
+
* @param payload.consent - Must be `true`; never default or infer consent.
|
|
7431
|
+
* @returns The newly opened provider session:
|
|
7432
|
+
* ```jsonc
|
|
7433
|
+
* {
|
|
7434
|
+
* "id": "verification_example",
|
|
7435
|
+
* "url": "https://verify.example.com/c/session#t=opaque",
|
|
7436
|
+
* "expires_at": "2026-10-16T12:30:00Z"
|
|
7437
|
+
* }
|
|
7438
|
+
* ```
|
|
7439
|
+
* `expires_at` can be null. Open the URL as-is; it is a bearer credential
|
|
7440
|
+
* and its fragment must survive navigation. Do not log or persist it in
|
|
7441
|
+
* browser storage. No workspace credential is attached to this call.
|
|
7442
|
+
* @throws {ValidationError} If the code is blank or consent is not `true`.
|
|
7443
|
+
* @throws {ApiError} `400` when a non-expired session already exists;
|
|
7444
|
+
* `401` for an invalid/expired code; `500` for a provider/server failure.
|
|
7445
|
+
* @example
|
|
7446
|
+
* ```ts
|
|
7447
|
+
* // Inside the handler for the signer's explicit consent action:
|
|
7448
|
+
* const session = await client.signerDocuments.startIdentityVerification(accessCode, { consent: true });
|
|
7449
|
+
* response.redirect(session.url);
|
|
7450
|
+
* ```
|
|
7451
|
+
*/
|
|
7452
|
+
async startIdentityVerification(signerAccessCode, payload) {
|
|
7453
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7454
|
+
assertRecord(payload, "identity verification payload");
|
|
7455
|
+
if (payload.consent !== true) {
|
|
7456
|
+
throw new ValidationError("Explicit biometric-processing consent is required");
|
|
7457
|
+
}
|
|
7458
|
+
return this.call(
|
|
7459
|
+
"Failed to start signer identity verification",
|
|
7460
|
+
() => this.http.post("/signers/identity-verification", { consent: true }, {
|
|
7461
|
+
params: { "signer-access-code": code }
|
|
7462
|
+
})
|
|
7463
|
+
);
|
|
7464
|
+
}
|
|
7035
7465
|
/**
|
|
7036
7466
|
* Accept the platform terms of use as the signer
|
|
7037
7467
|
* (`PUT /signers/accept-terms?signer-access-code=…`).
|
|
@@ -7065,10 +7495,10 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7065
7495
|
);
|
|
7066
7496
|
}
|
|
7067
7497
|
/**
|
|
7068
|
-
* Verify the signer's email one-time password
|
|
7498
|
+
* Verify the signer's email or WhatsApp one-time password
|
|
7069
7499
|
* (`POST /verify?signer-access-code=…`).
|
|
7070
7500
|
*
|
|
7071
|
-
* Confirms the 6-digit OTP
|
|
7501
|
+
* Confirms the 6-digit OTP sent through the selected channel. The access code
|
|
7072
7502
|
* authenticates via the `signer-access-code` **query param**; the request
|
|
7073
7503
|
* **body carries only `verification-code`** (putting the access code in the
|
|
7074
7504
|
* body leaves the request unauthenticated → `401`).
|
|
@@ -7082,6 +7512,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7082
7512
|
*
|
|
7083
7513
|
* @param payload - `signerAccessCode` (the signing-link code) and
|
|
7084
7514
|
* `verificationCode` (the OTP the signer received).
|
|
7515
|
+
* @param payload.signerAccessCode - Signing-link code sent only in the query.
|
|
7516
|
+
* @param payload.verificationCode - Email or WhatsApp OTP sent as `verification-code`.
|
|
7085
7517
|
* @returns Resolves when the API acknowledges the operation. The response
|
|
7086
7518
|
* envelope has no `data` field and is intentionally discarded.
|
|
7087
7519
|
* @throws {ValidationError} If `signerAccessCode` or `verificationCode` is
|
|
@@ -7242,7 +7674,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7242
7674
|
* "expires_at": null,
|
|
7243
7675
|
* "signers": [
|
|
7244
7676
|
* { "id": "19e6b92e7895332ed9708535d8c", "step": 1, "email": "signer@example.com",
|
|
7245
|
-
* "full_name": "Example Signer", "notified": true
|
|
7677
|
+
* "full_name": "Example Signer", "notified": true }
|
|
7246
7678
|
* ],
|
|
7247
7679
|
* "items": [
|
|
7248
7680
|
* { "id": "item-1", "page": { "id": "page-1", "number": 1, "height": 1651, "width": 1275,
|
|
@@ -7419,6 +7851,9 @@ function assertDeclineReason(declineReason) {
|
|
|
7419
7851
|
if (typeof declineReason !== "string" || !declineReason.trim()) {
|
|
7420
7852
|
throw new ValidationError("declineReason is required");
|
|
7421
7853
|
}
|
|
7854
|
+
if (declineReason.length > 2e3) {
|
|
7855
|
+
throw new ValidationError("declineReason must be at most 2000 characters");
|
|
7856
|
+
}
|
|
7422
7857
|
}
|
|
7423
7858
|
function validateConfirmDataPayload(payload) {
|
|
7424
7859
|
for (const key of ["full_name", "government_id"]) {
|
|
@@ -7852,7 +8287,8 @@ var WebhookVerifier = class {
|
|
|
7852
8287
|
* @param toleranceSeconds - Accepted clock distance. Defaults to `300`.
|
|
7853
8288
|
* @returns `true` only when a signature entry matches (constant-time) and
|
|
7854
8289
|
* the timestamp is fresh; `false` when verification is disabled, a header
|
|
7855
|
-
* is missing,
|
|
8290
|
+
* is missing, the tolerance is not finite and non-negative, or anything
|
|
8291
|
+
* does not match.
|
|
7856
8292
|
*
|
|
7857
8293
|
* @example
|
|
7858
8294
|
* ```ts
|
|
@@ -7868,7 +8304,7 @@ var WebhookVerifier = class {
|
|
|
7868
8304
|
*/
|
|
7869
8305
|
verifySignature(payload, headers, toleranceSeconds = DEFAULT_TOLERANCE_SECONDS) {
|
|
7870
8306
|
const key = decodeSecret(this.webhookSecret);
|
|
7871
|
-
if (!key || typeof payload !== "string" && !Buffer.isBuffer(payload) || !headers) {
|
|
8307
|
+
if (!key || typeof payload !== "string" && !Buffer.isBuffer(payload) || !headers || !Number.isFinite(toleranceSeconds) || toleranceSeconds < 0) {
|
|
7872
8308
|
return false;
|
|
7873
8309
|
}
|
|
7874
8310
|
const id = header(headers, "webhook-id");
|
|
@@ -7984,9 +8420,8 @@ function decodeSecret(secret) {
|
|
|
7984
8420
|
return key.length > 0 ? key : null;
|
|
7985
8421
|
}
|
|
7986
8422
|
function header(headers, name) {
|
|
7987
|
-
const value = typeof headers.get === "function" ? headers.get(name) : headers
|
|
7988
|
-
|
|
7989
|
-
return typeof first === "string" ? first.trim() : void 0;
|
|
8423
|
+
const value = typeof headers.get === "function" ? headers.get(name) ?? void 0 : readHeader(headers, name);
|
|
8424
|
+
return typeof value === "string" ? value.trim() : void 0;
|
|
7990
8425
|
}
|
|
7991
8426
|
function isRecord(value) {
|
|
7992
8427
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -8123,7 +8558,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
8123
8558
|
);
|
|
8124
8559
|
this.fields = new FieldsResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
8125
8560
|
this.signerDocuments = new SignerDocumentsResource(
|
|
8126
|
-
this.
|
|
8561
|
+
this.axiosInstance,
|
|
8127
8562
|
this.defaultAccountId,
|
|
8128
8563
|
this.logger,
|
|
8129
8564
|
this.publicAxiosInstance
|