@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.js
CHANGED
|
@@ -115,6 +115,25 @@ var ApiError = class _ApiError extends AssinafyError {
|
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
117
|
challenge;
|
|
118
|
+
/**
|
|
119
|
+
* Rate-limit headers carried by the failed response: `X-Rate-Limit-Limit`,
|
|
120
|
+
* `X-Rate-Limit-Remaining`, `X-Rate-Limit-Reset` and, on `429`,
|
|
121
|
+
* `Retry-After` (all in requests or seconds). `undefined` when the response
|
|
122
|
+
* carried none of them. The client already retries a `429` up to
|
|
123
|
+
* `maxRetries` times; this is what remains once those retries are spent.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* try {
|
|
128
|
+
* await client.documents.list();
|
|
129
|
+
* } catch (error) {
|
|
130
|
+
* if (error instanceof ApiError && error.statusCode === 429) {
|
|
131
|
+
* await sleep((error.rateLimit?.retryAfter ?? 60) * 1000);
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
rateLimit;
|
|
118
137
|
/**
|
|
119
138
|
* Create an error representing a non-success API response.
|
|
120
139
|
*
|
|
@@ -220,6 +239,7 @@ var OAuthError = class _OAuthError extends ApiError {
|
|
|
220
239
|
body
|
|
221
240
|
);
|
|
222
241
|
if (error.challenge !== void 0) upgraded.challenge = error.challenge;
|
|
242
|
+
if (error.rateLimit !== void 0) upgraded.rateLimit = error.rateLimit;
|
|
223
243
|
return upgraded;
|
|
224
244
|
}
|
|
225
245
|
};
|
|
@@ -297,6 +317,20 @@ function parseWwwAuthenticate(value) {
|
|
|
297
317
|
}
|
|
298
318
|
return challenge;
|
|
299
319
|
}
|
|
320
|
+
var RATE_LIMIT_HEADERS = [
|
|
321
|
+
["limit", "x-rate-limit-limit"],
|
|
322
|
+
["remaining", "x-rate-limit-remaining"],
|
|
323
|
+
["reset", "x-rate-limit-reset"],
|
|
324
|
+
["retryAfter", "retry-after"]
|
|
325
|
+
];
|
|
326
|
+
function parseRateLimit(headers) {
|
|
327
|
+
const info = {};
|
|
328
|
+
for (const [key, header2] of RATE_LIMIT_HEADERS) {
|
|
329
|
+
const value = readHeader(headers, header2)?.trim();
|
|
330
|
+
if (value !== void 0 && /^\d+$/u.test(value)) info[key] = Number(value);
|
|
331
|
+
}
|
|
332
|
+
return Object.keys(info).length > 0 ? info : void 0;
|
|
333
|
+
}
|
|
300
334
|
|
|
301
335
|
// src/utils.ts
|
|
302
336
|
var SAFE_LOG_NUMBER_FIELDS = /* @__PURE__ */ new Set([
|
|
@@ -343,10 +377,11 @@ function toSdkError(error, fallbackMessage) {
|
|
|
343
377
|
if (status) {
|
|
344
378
|
const body = decodeBinaryErrorBody(error.response?.data ?? null);
|
|
345
379
|
const apiError = ApiError.fromResponse(status, body ?? null);
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
);
|
|
380
|
+
const headers = error.response?.headers;
|
|
381
|
+
const challenge = parseWwwAuthenticate(readHeader(headers, "www-authenticate"));
|
|
349
382
|
if (challenge) apiError.challenge = challenge;
|
|
383
|
+
const rateLimit = parseRateLimit(headers);
|
|
384
|
+
if (rateLimit) apiError.rateLimit = rateLimit;
|
|
350
385
|
return apiError;
|
|
351
386
|
}
|
|
352
387
|
const cause = sanitiseNetworkCause(error);
|
|
@@ -530,6 +565,7 @@ var import_axios3 = require("axios");
|
|
|
530
565
|
|
|
531
566
|
// src/support/path.ts
|
|
532
567
|
function encodePathSegment(value) {
|
|
568
|
+
if (value === "." || value === "..") throw new Error("Dot segments are not resource IDs");
|
|
533
569
|
return encodeURIComponent(value).replace(
|
|
534
570
|
/[!'()*]/g,
|
|
535
571
|
(character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`
|
|
@@ -652,7 +688,7 @@ var import_axios2 = __toESM(require("axios"));
|
|
|
652
688
|
// package.json
|
|
653
689
|
var package_default = {
|
|
654
690
|
name: "@assinafy/sdk",
|
|
655
|
-
version: "2.
|
|
691
|
+
version: "2.8.0",
|
|
656
692
|
packageManager: "bun@1.4.0",
|
|
657
693
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
658
694
|
type: "commonjs",
|
|
@@ -715,7 +751,7 @@ var package_default = {
|
|
|
715
751
|
bugs: {
|
|
716
752
|
url: "https://github.com/assinafy/typescript-sdk/issues"
|
|
717
753
|
},
|
|
718
|
-
homepage: "https://
|
|
754
|
+
homepage: "https://www.assinafy.com.br",
|
|
719
755
|
devDependencies: {
|
|
720
756
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
721
757
|
"@eslint/js": "^10.0.1",
|
|
@@ -784,7 +820,13 @@ function applySdkTransportDefaults(http) {
|
|
|
784
820
|
const guarded = (options, response, request) => {
|
|
785
821
|
guardRedirect(options, response, request);
|
|
786
822
|
if (current && typeof options["href"] === "string" && new URL(request.url).origin === new URL(options["href"]).origin) {
|
|
823
|
+
const destinationKeys = ["protocol", "host", "hostname", "port", "socketPath", "servername"];
|
|
824
|
+
const destination = destinationKeys.map((key) => options[key]);
|
|
825
|
+
const host = readHeader(options["headers"], "host");
|
|
787
826
|
current(options, response, request);
|
|
827
|
+
if (destinationKeys.some((key, index) => options[key] !== destination[index]) || readHeader(options["headers"], "host") !== host) {
|
|
828
|
+
throw new Error("Redirect hooks must not change the destination");
|
|
829
|
+
}
|
|
788
830
|
guardRedirect(options, response, request);
|
|
789
831
|
}
|
|
790
832
|
};
|
|
@@ -992,12 +1034,13 @@ function toInt(value) {
|
|
|
992
1034
|
|
|
993
1035
|
// src/resources/assignments.ts
|
|
994
1036
|
var ASSIGNMENT_METHODS = /* @__PURE__ */ new Set(["virtual", "collect"]);
|
|
995
|
-
var VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "DigitalCertificate"]);
|
|
1037
|
+
var VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "DigitalCertificate", "IdDocumentFaceMatchBasic"]);
|
|
996
1038
|
var NOTIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp"]);
|
|
997
1039
|
var ALLOWED_NOTIFICATION_METHODS = {
|
|
998
1040
|
Email: /* @__PURE__ */ new Set(["Email"]),
|
|
999
1041
|
Whatsapp: /* @__PURE__ */ new Set(["Whatsapp"]),
|
|
1000
|
-
DigitalCertificate: NOTIFICATION_METHODS
|
|
1042
|
+
DigitalCertificate: NOTIFICATION_METHODS,
|
|
1043
|
+
IdDocumentFaceMatchBasic: NOTIFICATION_METHODS
|
|
1001
1044
|
};
|
|
1002
1045
|
function validateAssignmentSignerOptions(signer, label = "signer") {
|
|
1003
1046
|
if (signer.verification_method !== void 0 && (typeof signer.verification_method !== "string" || !VERIFICATION_METHODS.has(signer.verification_method))) {
|
|
@@ -1337,8 +1380,10 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1337
1380
|
* {@link buildAssignmentPayload}. A `virtual` assignment may be created at
|
|
1338
1381
|
* `uploaded`, `metadata_processing`, or `metadata_ready` and is promoted
|
|
1339
1382
|
* automatically; `collect` requires rendered pages at `metadata_ready`.
|
|
1340
|
-
* `DigitalCertificate` costs
|
|
1383
|
+
* `DigitalCertificate` costs 0.5 credits, requires the feature plus a
|
|
1341
1384
|
* signer `government_id`, and that signer must be alone in its step.
|
|
1385
|
+
* `IdDocumentFaceMatchBasic` needs the ID Document + Face Match feature
|
|
1386
|
+
* and a valid CPF in the signer's `government_id`; estimate its fee first.
|
|
1342
1387
|
*
|
|
1343
1388
|
* Request body (`application/json`):
|
|
1344
1389
|
* ```jsonc
|
|
@@ -1474,7 +1519,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1474
1519
|
* only `verification_method` / `notification_methods` (or `{}` for the
|
|
1475
1520
|
* default Email channel). {@link buildAssignmentEstimatePayload} projects
|
|
1476
1521
|
* exactly the fields permitted by the estimate schema.
|
|
1477
|
-
* `DigitalCertificate` is priced at
|
|
1522
|
+
* `DigitalCertificate` is priced at 0.5 credits per signer and remains
|
|
1478
1523
|
* subject to the feature, identity, and one-signer-per-step requirements.
|
|
1479
1524
|
* Current documented unit prices are 1 credit for an extra document, 0 for
|
|
1480
1525
|
* email notification, and 0.45 for WhatsApp notification; a digital
|
|
@@ -1750,6 +1795,148 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1750
1795
|
)
|
|
1751
1796
|
);
|
|
1752
1797
|
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Read the account's signer identity review
|
|
1800
|
+
* (`GET /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification`).
|
|
1801
|
+
*
|
|
1802
|
+
* No request body. `InReview` lets the signer continue signing but holds
|
|
1803
|
+
* certification. Evidence is a summary without images or biometrics; a
|
|
1804
|
+
* directly approved verification exposes evidence on its activity instead.
|
|
1805
|
+
*
|
|
1806
|
+
* @param documentId - Document owning the assignment.
|
|
1807
|
+
* @param assignmentId - Assignment containing the signer.
|
|
1808
|
+
* @param signerId - Signer whose identity is under review.
|
|
1809
|
+
* @returns The complete review summary:
|
|
1810
|
+
* ```jsonc
|
|
1811
|
+
* {
|
|
1812
|
+
* "id": "verification_example", "status": "InReview",
|
|
1813
|
+
* "provider": "AssinafyVerify", "verification_method": "IdDocumentFaceMatchBasic",
|
|
1814
|
+
* "reason_codes": [{ "code": "NAME_MISMATCH", "description": "Name differs" }],
|
|
1815
|
+
* "evidence_available": true,
|
|
1816
|
+
* "expected": { "name": "Example Signer", "cpf": null },
|
|
1817
|
+
* "document": { "type": "CNH", "name": "EXAMPLE SIGNER", "cpf": null },
|
|
1818
|
+
* "matches": { "cpf": null, "name": 0.52, "birth_date": null },
|
|
1819
|
+
* "checks": [{ "name": "name", "result": "review", "score": 0.52, "reasons": ["NAME_MISMATCH"] }],
|
|
1820
|
+
* "images": ["document_front", "face"], // available only while InReview
|
|
1821
|
+
* "ruleset_version": "2026-10-12.2", "evidence_sha256": null,
|
|
1822
|
+
* "reviewed_by": null, "reviewed_at": null, "review_note": null, "completed_at": null
|
|
1823
|
+
* }
|
|
1824
|
+
* ```
|
|
1825
|
+
* @throws {ValidationError} If any ID is blank or invalid for a URL.
|
|
1826
|
+
* @throws {ApiError} `401` for invalid credentials; `404` for an unknown
|
|
1827
|
+
* assignment, signer or verification; `500` for a server failure.
|
|
1828
|
+
* @example
|
|
1829
|
+
* ```ts
|
|
1830
|
+
* const review = await client.assignments.getIdentityVerification('doc-1', 'asg-1', 'signer-1');
|
|
1831
|
+
* console.log(review.status, review.images.length);
|
|
1832
|
+
* ```
|
|
1833
|
+
*/
|
|
1834
|
+
async getIdentityVerification(documentId, assignmentId, signerId) {
|
|
1835
|
+
const path2 = this.identityVerificationPath(documentId, assignmentId, signerId);
|
|
1836
|
+
return this.call("Failed to fetch signer identity review", () => this.http.get(path2));
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* Download identity review evidence
|
|
1840
|
+
* (`GET /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification/images/{name}`).
|
|
1841
|
+
*
|
|
1842
|
+
* No request body. The provider supplies the bytes on each request; Assinafy
|
|
1843
|
+
* never stores them. Available only while the review is open. Keep these
|
|
1844
|
+
* sensitive bytes out of caches and logs (`Cache-Control: no-store`).
|
|
1845
|
+
*
|
|
1846
|
+
* @param documentId - Document owning the assignment.
|
|
1847
|
+
* @param assignmentId - Assignment containing the signer.
|
|
1848
|
+
* @param signerId - Signer whose evidence to view.
|
|
1849
|
+
* @param name - One of the review's `images`: `document_front`,
|
|
1850
|
+
* `document_back`, `document_pdf`, or `face`.
|
|
1851
|
+
* @returns Raw JPEG, PNG or PDF bytes as a `Buffer`.
|
|
1852
|
+
* @throws {ValidationError} If an ID or image name is invalid.
|
|
1853
|
+
* @throws {ApiError} `401` for invalid credentials; `404` for absent evidence
|
|
1854
|
+
* or a decided review; `500` for a provider/server failure.
|
|
1855
|
+
* @example
|
|
1856
|
+
* ```ts
|
|
1857
|
+
* const bytes = await client.assignments.downloadIdentityVerificationImage('doc-1', 'asg-1', 'signer-1', 'face');
|
|
1858
|
+
* ```
|
|
1859
|
+
*/
|
|
1860
|
+
async downloadIdentityVerificationImage(documentId, assignmentId, signerId, name) {
|
|
1861
|
+
const path2 = this.identityVerificationPath(documentId, assignmentId, signerId);
|
|
1862
|
+
if (!["document_front", "document_back", "document_pdf", "face"].includes(name)) {
|
|
1863
|
+
throw new ValidationError("Invalid identity verification image name");
|
|
1864
|
+
}
|
|
1865
|
+
return this.callBinary(
|
|
1866
|
+
"Failed to download identity review evidence",
|
|
1867
|
+
() => this.http.get(`${path2}/images/${name}`, { responseType: "arraybuffer" })
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Decide a signer identity review
|
|
1872
|
+
* (`POST /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification/review`).
|
|
1873
|
+
*
|
|
1874
|
+
* Requires `InReview` and a document at `pending_signature` or
|
|
1875
|
+
* `pending_identity_review`. Approval allows certification once all signers
|
|
1876
|
+
* sign and every review is approved. Rejection cancels the document as
|
|
1877
|
+
* `rejected_by_user` and sends cancellation notices to signers and copy
|
|
1878
|
+
* receivers. The note is hidden from them; the provider receives the decision.
|
|
1879
|
+
*
|
|
1880
|
+
* Request body (`application/json`):
|
|
1881
|
+
* ```jsonc
|
|
1882
|
+
* { "decision": "Approved", "note": "Verified independently." }
|
|
1883
|
+
* ```
|
|
1884
|
+
* @param documentId - Document owning the assignment.
|
|
1885
|
+
* @param assignmentId - Assignment containing the signer.
|
|
1886
|
+
* @param signerId - Signer whose review to decide.
|
|
1887
|
+
* @param payload - Explicit account review decision.
|
|
1888
|
+
* @param payload.decision - `Approved` or `Rejected`.
|
|
1889
|
+
* @param payload.note - Optional nullable note, at most 2000 characters.
|
|
1890
|
+
* @returns The updated review, in the full
|
|
1891
|
+
* {@link AssignmentResource.getIdentityVerification} shape:
|
|
1892
|
+
* ```jsonc
|
|
1893
|
+
* {
|
|
1894
|
+
* "id": "verification_example", "status": "Approved",
|
|
1895
|
+
* "provider": "AssinafyVerify", "verification_method": "IdDocumentFaceMatchBasic",
|
|
1896
|
+
* "reason_codes": [{ "code": "NAME_MISMATCH", "description": "Name differs" }],
|
|
1897
|
+
* "evidence_available": true,
|
|
1898
|
+
* "expected": { "name": "Example Signer", "cpf": null },
|
|
1899
|
+
* "document": { "type": "CNH", "name": "EXAMPLE SIGNER", "cpf": null },
|
|
1900
|
+
* "matches": { "cpf": null, "name": 0.52, "birth_date": null },
|
|
1901
|
+
* "checks": [{ "name": "name", "result": "review", "score": 0.52, "reasons": ["NAME_MISMATCH"] }],
|
|
1902
|
+
* "images": [], "ruleset_version": "2026-10-12.2", "evidence_sha256": null,
|
|
1903
|
+
* "reviewed_by": { "id": "user_example", "name": "Example Reviewer" },
|
|
1904
|
+
* "reviewed_at": "2026-10-16T12:00:00Z", "review_note": "Verified independently.",
|
|
1905
|
+
* "completed_at": "2026-10-16T12:00:00Z"
|
|
1906
|
+
* }
|
|
1907
|
+
* ```
|
|
1908
|
+
* @throws {ValidationError} If IDs, decision or note are invalid.
|
|
1909
|
+
* @throws {ApiError} `400` for a closed review or invalid document state;
|
|
1910
|
+
* `401` for invalid credentials; `404` if absent; `500` for a server failure.
|
|
1911
|
+
* @example
|
|
1912
|
+
* ```ts
|
|
1913
|
+
* await client.assignments.reviewIdentityVerification('doc-1', 'asg-1', 'signer-1', {
|
|
1914
|
+
* decision: 'Approved', note: 'Verified independently.',
|
|
1915
|
+
* });
|
|
1916
|
+
* ```
|
|
1917
|
+
*/
|
|
1918
|
+
async reviewIdentityVerification(documentId, assignmentId, signerId, payload) {
|
|
1919
|
+
const path2 = this.identityVerificationPath(documentId, assignmentId, signerId);
|
|
1920
|
+
assertRecord(payload, "identity review payload");
|
|
1921
|
+
if (payload.decision !== "Approved" && payload.decision !== "Rejected") {
|
|
1922
|
+
throw new ValidationError("decision must be Approved or Rejected");
|
|
1923
|
+
}
|
|
1924
|
+
if (payload.note !== void 0 && payload.note !== null && (typeof payload.note !== "string" || [...payload.note].length > 2e3)) {
|
|
1925
|
+
throw new ValidationError("note must be a string of at most 2000 characters, or null");
|
|
1926
|
+
}
|
|
1927
|
+
const body = { decision: payload.decision };
|
|
1928
|
+
if (payload.note !== void 0) body.note = payload.note;
|
|
1929
|
+
return this.call(
|
|
1930
|
+
"Failed to decide signer identity review",
|
|
1931
|
+
() => this.http.post(`${path2}/review`, body)
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
identityVerificationPath(documentId, assignmentId, signerId) {
|
|
1935
|
+
const docId = this.pathSegment(documentId, "Document ID");
|
|
1936
|
+
const asgId = this.pathSegment(assignmentId, "Assignment ID");
|
|
1937
|
+
const sid = this.pathSegment(signerId, "Signer ID");
|
|
1938
|
+
return `/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification`;
|
|
1939
|
+
}
|
|
1753
1940
|
};
|
|
1754
1941
|
|
|
1755
1942
|
// src/resources/documents.ts
|
|
@@ -1763,6 +1950,7 @@ function validateDocumentWaitOptions(options) {
|
|
|
1763
1950
|
var READY_STATUSES = /* @__PURE__ */ new Set([
|
|
1764
1951
|
"metadata_ready",
|
|
1765
1952
|
"pending_signature",
|
|
1953
|
+
"pending_identity_review",
|
|
1766
1954
|
"certificated"
|
|
1767
1955
|
]);
|
|
1768
1956
|
var FAILED_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -1789,6 +1977,9 @@ var DocumentResource = class extends BaseResource {
|
|
|
1789
1977
|
*
|
|
1790
1978
|
* @param source - The PDF to upload, as a file path or an in-memory buffer.
|
|
1791
1979
|
* @param options - Display name, metadata, and account override.
|
|
1980
|
+
* @param options.name - Multipart filename override; the API derives the display name from it.
|
|
1981
|
+
* @param options.metadata - JSON metadata (compatibility multipart part).
|
|
1982
|
+
* @param options.accountId - Override the client's default workspace.
|
|
1792
1983
|
* @returns The created document, freshly uploaded (`status: 'uploaded'`,
|
|
1793
1984
|
* empty `pages` until `metadata_ready`). Response shape:
|
|
1794
1985
|
* ```jsonc
|
|
@@ -1899,7 +2090,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
1899
2090
|
* method: 'virtual',
|
|
1900
2091
|
* 'per-page': 50,
|
|
1901
2092
|
* });
|
|
1902
|
-
* console.log(data[0]?.pages
|
|
2093
|
+
* console.log(data[0]?.pages?.length, meta?.total);
|
|
1903
2094
|
* ```
|
|
1904
2095
|
*/
|
|
1905
2096
|
async list(params = {}, accountId) {
|
|
@@ -2112,7 +2303,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2112
2303
|
}
|
|
2113
2304
|
/**
|
|
2114
2305
|
* Poll {@link DocumentResource.details} until the document reaches a ready
|
|
2115
|
-
* status (`metadata_ready`, `pending_signature`,
|
|
2306
|
+
* status (`metadata_ready`, `pending_signature`, `pending_identity_review`,
|
|
2307
|
+
* or `certificated`),
|
|
2116
2308
|
* throwing on a terminal failure status or timeout.
|
|
2117
2309
|
*
|
|
2118
2310
|
* Transient errors are tolerated — a `5xx` or `429` is retried on the next
|
|
@@ -2122,6 +2314,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2122
2314
|
* @param documentId - The document to wait on.
|
|
2123
2315
|
* @param options - `maxWaitMs` (default `30_000`) and `pollIntervalMs`
|
|
2124
2316
|
* (default `2_000`).
|
|
2317
|
+
* @param options.maxWaitMs - Finite non-negative wait budget in milliseconds; default `30_000`.
|
|
2318
|
+
* @param options.pollIntervalMs - Finite positive polling interval in milliseconds; default `2_000`.
|
|
2125
2319
|
* @returns The document details once it reaches a ready status (see
|
|
2126
2320
|
* {@link DocumentResource.details} for the shape).
|
|
2127
2321
|
* @throws {ValidationError} If `documentId` is missing, the document enters
|
|
@@ -2389,6 +2583,9 @@ var DocumentResource = class extends BaseResource {
|
|
|
2389
2583
|
* names are not portable identifiers and should not be used here. This
|
|
2390
2584
|
* overwrites the existing set — use
|
|
2391
2585
|
* {@link DocumentResource.addTags} to append.
|
|
2586
|
+
* Older sandbox deployments interpret these strings as names and create
|
|
2587
|
+
* ID-named tags for ID inputs; pass existing names intentionally there.
|
|
2588
|
+
* Strings are sent unchanged. See `docs/COMPATIBILITY.md` for this variant.
|
|
2392
2589
|
*
|
|
2393
2590
|
* Request body (`application/json`):
|
|
2394
2591
|
* ```jsonc
|
|
@@ -2440,6 +2637,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2440
2637
|
* `tags` is a non-empty array of tag **IDs**. Attaching an ID already
|
|
2441
2638
|
* present is a no-op. To replace the whole set instead, use
|
|
2442
2639
|
* {@link DocumentResource.replaceTags}.
|
|
2640
|
+
* On older name-based sandbox deployments, pass existing tag names
|
|
2641
|
+
* intentionally; ID inputs create ID-named tags. No automatic remapping occurs.
|
|
2443
2642
|
*
|
|
2444
2643
|
* Request body (`application/json`):
|
|
2445
2644
|
* ```jsonc
|
|
@@ -2559,10 +2758,17 @@ var DocumentResource = class extends BaseResource {
|
|
|
2559
2758
|
* plus optional `verification_method`, `notification_methods`, `step`).
|
|
2560
2759
|
* Only one notification method is allowed per signer; when only one of the
|
|
2561
2760
|
* verification/notification fields is supplied, the API infers the other.
|
|
2562
|
-
* `DigitalCertificate` costs
|
|
2761
|
+
* `DigitalCertificate` costs 0.5 credits, requires the feature plus a
|
|
2563
2762
|
* signer `government_id`, and that signer must be alone in its step.
|
|
2763
|
+
* `IdDocumentFaceMatchBasic` needs the ID Document + Face Match feature
|
|
2764
|
+
* and a valid CPF in `government_id`; estimate the per-signer fee first.
|
|
2564
2765
|
* @param options - Optional `name`, `message`, `expires_at`,
|
|
2565
2766
|
* `editor_fields`, `tags`.
|
|
2767
|
+
* @param options.name - Generated document display name.
|
|
2768
|
+
* @param options.message - Signing invitation message.
|
|
2769
|
+
* @param options.expires_at - ISO-8601 signature deadline.
|
|
2770
|
+
* @param options.editor_fields - Template editor values as `{ field_id, value }` entries.
|
|
2771
|
+
* @param options.tags - Tag names attached to the generated document.
|
|
2566
2772
|
* @param accountId - Override the client's default account ID.
|
|
2567
2773
|
* @returns The created document (an {@link IDocumentDetailsResponse} with
|
|
2568
2774
|
* `template_id` set and its `assignment` populated):
|
|
@@ -2634,7 +2840,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2634
2840
|
*
|
|
2635
2841
|
* A dry run: sends only `{ signers }` and consumes nothing. Use it to check
|
|
2636
2842
|
* balances before calling {@link DocumentResource.createFromTemplate}.
|
|
2637
|
-
* `DigitalCertificate` adds
|
|
2843
|
+
* `DigitalCertificate` adds 0.5 credits per signer and has the same feature,
|
|
2638
2844
|
* `government_id`, and signing-step prerequisites as document creation.
|
|
2639
2845
|
*
|
|
2640
2846
|
* Request body (`application/json`):
|
|
@@ -2824,32 +3030,63 @@ var DocumentResource = class extends BaseResource {
|
|
|
2824
3030
|
() => this.publicHttp.get(`/public/documents/${this.pathSegment(id, "Document ID")}`)
|
|
2825
3031
|
);
|
|
2826
3032
|
}
|
|
2827
|
-
|
|
3033
|
+
/**
|
|
3034
|
+
* Email the signer the verification token that unlocks a document
|
|
3035
|
+
* (`PUT /public/documents/{documentId}/send-token`).
|
|
3036
|
+
*
|
|
3037
|
+
* Part of the public signing flow: dispatches the 6-digit verification
|
|
3038
|
+
* token the signer enters to view the document. Runs on the
|
|
3039
|
+
* credential-free transport. The contract accepts only the `email`
|
|
3040
|
+
* channel, and both body fields are required.
|
|
3041
|
+
*
|
|
3042
|
+
* Request body (`application/json`):
|
|
3043
|
+
* ```jsonc
|
|
3044
|
+
* { "channel": "email", "recipient": "signer@example.com" }
|
|
3045
|
+
* ```
|
|
3046
|
+
*
|
|
3047
|
+
* @param documentId - The document to send the token for.
|
|
3048
|
+
* @param recipient - The signer's email address.
|
|
3049
|
+
* @param channel - Delivery channel; only `email` is accepted (default).
|
|
3050
|
+
* @returns The delivery confirmation (`data` of the envelope):
|
|
3051
|
+
* ```jsonc
|
|
3052
|
+
* {
|
|
3053
|
+
* "document": {
|
|
3054
|
+
* "resource": "document",
|
|
3055
|
+
* "id": "a1b2c3d4e5f6a7b8c9d0",
|
|
3056
|
+
* "name": "Contract.pdf",
|
|
3057
|
+
* "page_count": 3,
|
|
3058
|
+
* "created_by": "Jane Doe"
|
|
3059
|
+
* },
|
|
3060
|
+
* "channel": "email",
|
|
3061
|
+
* "recipient": "signer@example.com"
|
|
3062
|
+
* }
|
|
3063
|
+
* ```
|
|
3064
|
+
* @throws {ValidationError} If `documentId` is missing, `recipient` is not
|
|
3065
|
+
* a valid email address, or `channel` is not `email`.
|
|
3066
|
+
* @throws {ApiError} `400` if validation fails; `404` if the document does
|
|
3067
|
+
* not exist.
|
|
3068
|
+
*
|
|
3069
|
+
* @example
|
|
3070
|
+
* ```ts
|
|
3071
|
+
* const sent = await client.documents.sendToken('doc-1', 'signer@example.com');
|
|
3072
|
+
* console.log(sent.recipient);
|
|
3073
|
+
* ```
|
|
3074
|
+
*/
|
|
3075
|
+
async sendToken(documentId, recipient, channel = "email") {
|
|
2828
3076
|
const id = this.requireId(documentId, "Document ID");
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
if (channel === void 0 && !isEmail(recipient)) {
|
|
2832
|
-
throw new ValidationError("recipient must be a valid email address");
|
|
3077
|
+
if (channel !== "email") {
|
|
3078
|
+
throw new ValidationError('channel must be "email"', { channel });
|
|
2833
3079
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
return this.callVoid(
|
|
2837
|
-
"Failed to send signing token",
|
|
2838
|
-
() => this.publicHttp.put(path2, { recipient, channel })
|
|
2839
|
-
);
|
|
2840
|
-
}
|
|
2841
|
-
try {
|
|
2842
|
-
return await this.callVoid(
|
|
2843
|
-
"Failed to send signing token",
|
|
2844
|
-
() => this.publicHttp.put(path2, { email: recipient })
|
|
2845
|
-
);
|
|
2846
|
-
} catch (error) {
|
|
2847
|
-
if (!isLegacySendTokenValidation(error)) throw error;
|
|
2848
|
-
return this.callVoid(
|
|
2849
|
-
"Failed to send signing token",
|
|
2850
|
-
() => this.publicHttp.put(path2, { recipient, channel: "email" })
|
|
2851
|
-
);
|
|
3080
|
+
if (!isEmail(recipient)) {
|
|
3081
|
+
throw new ValidationError("recipient must be a valid email address");
|
|
2852
3082
|
}
|
|
3083
|
+
return this.call(
|
|
3084
|
+
"Failed to send signing token",
|
|
3085
|
+
() => this.publicHttp.put(
|
|
3086
|
+
`/public/documents/${this.pathSegment(id, "Document ID")}/send-token`,
|
|
3087
|
+
{ channel, recipient }
|
|
3088
|
+
)
|
|
3089
|
+
);
|
|
2853
3090
|
}
|
|
2854
3091
|
/**
|
|
2855
3092
|
* Quick boolean check (`GET /documents/{documentId}`): has every signer
|
|
@@ -2942,7 +3179,6 @@ function normaliseTemplateSigners(signers) {
|
|
|
2942
3179
|
if (signer.step !== void 0) projected.step = signer.step;
|
|
2943
3180
|
return projected;
|
|
2944
3181
|
});
|
|
2945
|
-
validateSigningOrder(normalised, "template signers");
|
|
2946
3182
|
return normalised;
|
|
2947
3183
|
}
|
|
2948
3184
|
function normaliseTemplateEditorFields(fields) {
|
|
@@ -2995,23 +3231,6 @@ function validateWaitOption(value, name) {
|
|
|
2995
3231
|
function sleep(ms) {
|
|
2996
3232
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2997
3233
|
}
|
|
2998
|
-
function isLegacySendTokenValidation(error) {
|
|
2999
|
-
if (!(error instanceof ApiError) || error.statusCode !== 400 && error.statusCode !== 422) {
|
|
3000
|
-
return false;
|
|
3001
|
-
}
|
|
3002
|
-
const namesLegacyField = /\b(?:channel|recipient)\b/iu.test(error.message);
|
|
3003
|
-
const saysRequired = /\b(?:required|obrigat[oó]ri[oa])\b/iu.test(error.message);
|
|
3004
|
-
if (namesLegacyField && saysRequired) return true;
|
|
3005
|
-
const response = error.responseData;
|
|
3006
|
-
if (!response || typeof response !== "object" || Array.isArray(response)) return false;
|
|
3007
|
-
const errors = response["errors"];
|
|
3008
|
-
if (!errors || typeof errors !== "object" || Array.isArray(errors)) return false;
|
|
3009
|
-
return ["channel", "recipient"].some((field) => {
|
|
3010
|
-
if (!Object.hasOwn(errors, field)) return false;
|
|
3011
|
-
const detail = JSON.stringify(errors[field]);
|
|
3012
|
-
return /required|obrigat[oó]ri[oa]/iu.test(detail);
|
|
3013
|
-
});
|
|
3014
|
-
}
|
|
3015
3234
|
|
|
3016
3235
|
// src/resources/signers.ts
|
|
3017
3236
|
var SignerResource = class extends BaseResource {
|
|
@@ -3279,9 +3498,8 @@ var SignerResource = class extends BaseResource {
|
|
|
3279
3498
|
* re-filtered here for an exact, case-insensitive email match.
|
|
3280
3499
|
*
|
|
3281
3500
|
* Page size is pinned to {@link MAX_LIST_PAGE_SIZE}, the largest page the
|
|
3282
|
-
* server actually returns.
|
|
3283
|
-
*
|
|
3284
|
-
* miss one — the API exposes no exact-email filter to rule that out.
|
|
3501
|
+
* server actually returns. Pages are searched until an exact match is found
|
|
3502
|
+
* or the result set ends, so substring matches cannot hide an existing signer.
|
|
3285
3503
|
*
|
|
3286
3504
|
* A `404` from the underlying list is treated as "no match" and mapped to
|
|
3287
3505
|
* `null`; any other {@link ApiError} propagates.
|
|
@@ -3311,12 +3529,16 @@ var SignerResource = class extends BaseResource {
|
|
|
3311
3529
|
async findByEmail(email, accountId) {
|
|
3312
3530
|
this.assertEmail(email);
|
|
3313
3531
|
try {
|
|
3314
|
-
const { data } = await this.list(
|
|
3315
|
-
{ search: email, "per-page": MAX_LIST_PAGE_SIZE },
|
|
3316
|
-
accountId
|
|
3317
|
-
);
|
|
3318
3532
|
const lower = email.toLowerCase();
|
|
3319
|
-
|
|
3533
|
+
for (let page = 1; ; page++) {
|
|
3534
|
+
const { data, meta } = await this.list(
|
|
3535
|
+
{ search: email, "per-page": MAX_LIST_PAGE_SIZE, page },
|
|
3536
|
+
accountId
|
|
3537
|
+
);
|
|
3538
|
+
const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
|
|
3539
|
+
if (match) return match;
|
|
3540
|
+
if (data.length === 0 || (meta?.last_page !== void 0 ? page >= meta.last_page : data.length < MAX_LIST_PAGE_SIZE)) return null;
|
|
3541
|
+
}
|
|
3320
3542
|
} catch (err) {
|
|
3321
3543
|
if (err instanceof ApiError && err.statusCode === 404) {
|
|
3322
3544
|
return null;
|
|
@@ -3671,6 +3893,8 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3671
3893
|
* @param accountId - Account to aggregate.
|
|
3672
3894
|
* @param params - Omit for 12 monthly rows, or request daily rows with
|
|
3673
3895
|
* `{ granularity: 'daily', month: '2026-06' }`.
|
|
3896
|
+
* @param params.granularity - `monthly` (default) or `daily`.
|
|
3897
|
+
* @param params.month - Month in `YYYY-MM` format; required for daily rows.
|
|
3674
3898
|
* @returns Zero-filled KPI rows:
|
|
3675
3899
|
* ```jsonc
|
|
3676
3900
|
* [{
|
|
@@ -3796,6 +4020,7 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3796
4020
|
* @param accountId - The workspace to delete.
|
|
3797
4021
|
* @param options - Set `force: true` to cancel an active paid subscription
|
|
3798
4022
|
* and proceed with deletion.
|
|
4023
|
+
* @param options.force - Cancel an active subscription and bypass deletion restrictions.
|
|
3799
4024
|
* @returns Nothing on success (`200` with no meaningful body).
|
|
3800
4025
|
* @throws {ValidationError} If `accountId` is missing.
|
|
3801
4026
|
* @throws {ApiError} `400` (with a `restrictions` list) when the workspace
|
|
@@ -4178,6 +4403,8 @@ var WebhookResource = class extends BaseResource {
|
|
|
4178
4403
|
* `account:read` scope.
|
|
4179
4404
|
*
|
|
4180
4405
|
* @param accountId - Override the client's default account ID.
|
|
4406
|
+
* @param params - Optional endpoint filters.
|
|
4407
|
+
* @param params.url - Match the exact registered endpoint URL.
|
|
4181
4408
|
* @returns Every endpoint (1 on free plans, up to 3 on paid plans):
|
|
4182
4409
|
* ```jsonc
|
|
4183
4410
|
* [
|
|
@@ -4203,9 +4430,14 @@ var WebhookResource = class extends BaseResource {
|
|
|
4203
4430
|
* const signed = endpoints.filter((endpoint) => endpoint.signing_enabled);
|
|
4204
4431
|
* ```
|
|
4205
4432
|
*/
|
|
4206
|
-
async listEndpoints(accountId) {
|
|
4433
|
+
async listEndpoints(accountId, params = {}) {
|
|
4434
|
+
assertRecord(params, "webhook endpoint filters");
|
|
4435
|
+
if (params.url !== void 0) validateWebhookUrl(params.url);
|
|
4207
4436
|
const path2 = this.endpointsPath(accountId);
|
|
4208
|
-
return this.call(
|
|
4437
|
+
return this.call(
|
|
4438
|
+
"Failed to list webhook endpoints",
|
|
4439
|
+
() => this.http.get(path2, params.url === void 0 ? void 0 : { params: { url: params.url } })
|
|
4440
|
+
);
|
|
4209
4441
|
}
|
|
4210
4442
|
/**
|
|
4211
4443
|
* Register a URL to receive the account's webhook events
|
|
@@ -4213,8 +4445,9 @@ var WebhookResource = class extends BaseResource {
|
|
|
4213
4445
|
*
|
|
4214
4446
|
* An account can have 1 endpoint, or up to 3 on paid plans. Each endpoint
|
|
4215
4447
|
* of a workspace needs a different `url`. With `signing_enabled: true` the
|
|
4216
|
-
* API
|
|
4217
|
-
* {@link WebhookResource.getEndpointSecret}
|
|
4448
|
+
* API returns a signing `secret` in this creation response. Store it now:
|
|
4449
|
+
* OAuth applications cannot call {@link WebhookResource.getEndpointSecret}
|
|
4450
|
+
* or rotate it later. When `events` is omitted or
|
|
4218
4451
|
* empty, {@link DEFAULT_WEBHOOK_EVENTS} is sent. OAuth tokens need the
|
|
4219
4452
|
* `webhooks:write` scope.
|
|
4220
4453
|
*
|
|
@@ -4244,6 +4477,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
4244
4477
|
* "events": ["document_ready", "signer_signed_document"],
|
|
4245
4478
|
* "is_active": true,
|
|
4246
4479
|
* "signing_enabled": true, // deliveries carry a `webhook-signature` header
|
|
4480
|
+
* "secret": "whsec_c2VjcmV0", // only in this response when signing is enabled
|
|
4247
4481
|
* "created_at": "2026-10-01T12:00:00Z",
|
|
4248
4482
|
* "updated_at": "2026-10-01T12:00:00Z"
|
|
4249
4483
|
* }
|
|
@@ -4263,7 +4497,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
4263
4497
|
* events: ['document_ready', 'signer_signed_document'],
|
|
4264
4498
|
* signing_enabled: true,
|
|
4265
4499
|
* });
|
|
4266
|
-
*
|
|
4500
|
+
* if (endpoint.secret) await secretStore.save(endpoint.id, endpoint.secret);
|
|
4267
4501
|
* ```
|
|
4268
4502
|
*/
|
|
4269
4503
|
async createEndpoint(payload, accountId) {
|
|
@@ -4388,6 +4622,32 @@ var WebhookResource = class extends BaseResource {
|
|
|
4388
4622
|
this.logger.info("Deleting webhook endpoint");
|
|
4389
4623
|
await this.callVoid("Failed to delete webhook endpoint", () => this.http.delete(path2));
|
|
4390
4624
|
}
|
|
4625
|
+
/**
|
|
4626
|
+
* Delete a webhook endpoint using its registered URL
|
|
4627
|
+
* (`DELETE /accounts/{accountId}/webhooks/endpoints?url=…`).
|
|
4628
|
+
*
|
|
4629
|
+
* No request body. The query URL must match the registered value exactly.
|
|
4630
|
+
* Frees its plan slot; OAuth applications need `webhooks:write`.
|
|
4631
|
+
*
|
|
4632
|
+
* @param url - Exact registered HTTP(S) endpoint URL, including its query.
|
|
4633
|
+
* @param accountId - Override the client's default workspace.
|
|
4634
|
+
* @returns Resolves on acknowledgement (`{ "status": 200, "data": [] }`).
|
|
4635
|
+
* @throws {ValidationError} If the URL is invalid or the account is missing.
|
|
4636
|
+
* @throws {ApiError} `400` for a missing URL; `401` for invalid credentials;
|
|
4637
|
+
* `403` for missing scope; `404` if no endpoint uses the URL; `500` on failure.
|
|
4638
|
+
* @example
|
|
4639
|
+
* ```ts
|
|
4640
|
+
* await client.webhooks.deleteEndpointByUrl('https://example.com/webhooks/assinafy');
|
|
4641
|
+
* ```
|
|
4642
|
+
*/
|
|
4643
|
+
async deleteEndpointByUrl(url, accountId) {
|
|
4644
|
+
validateWebhookUrl(url);
|
|
4645
|
+
const path2 = this.endpointsPath(accountId);
|
|
4646
|
+
return this.callVoid(
|
|
4647
|
+
"Failed to delete webhook endpoint",
|
|
4648
|
+
() => this.http.delete(path2, { params: { url } })
|
|
4649
|
+
);
|
|
4650
|
+
}
|
|
4391
4651
|
/**
|
|
4392
4652
|
* Return the secret that signs deliveries to an endpoint
|
|
4393
4653
|
* (`GET /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret`).
|
|
@@ -4510,6 +4770,8 @@ var TemplateResource = class extends BaseResource {
|
|
|
4510
4770
|
*
|
|
4511
4771
|
* @param source - The PDF to upload, as a file path or an in-memory buffer.
|
|
4512
4772
|
* @param options - `name` (display name) and an optional `accountId` override.
|
|
4773
|
+
* @param options.name - Multipart filename override, with a `.pdf` extension.
|
|
4774
|
+
* @param options.accountId - Override the client's default workspace.
|
|
4513
4775
|
* @returns The created template (envelope unwrapped). Response shape:
|
|
4514
4776
|
* ```jsonc
|
|
4515
4777
|
* {
|
|
@@ -4675,7 +4937,7 @@ var TemplateResource = class extends BaseResource {
|
|
|
4675
4937
|
* @example
|
|
4676
4938
|
* ```ts
|
|
4677
4939
|
* const tmpl = await client.templates.get('103ad2171db7979468c3e97eb067');
|
|
4678
|
-
* if (tmpl.status === 'Ready') console.log(tmpl.pages
|
|
4940
|
+
* if (tmpl.status === 'Ready') console.log(tmpl.pages?.length ?? 0);
|
|
4679
4941
|
* ```
|
|
4680
4942
|
*/
|
|
4681
4943
|
async get(templateId, accountId) {
|
|
@@ -4837,6 +5099,7 @@ var TagResource = class extends BaseResource {
|
|
|
4837
5099
|
*
|
|
4838
5100
|
* @param params - Optional filters. `search` matches tag names
|
|
4839
5101
|
* case-insensitively (substring).
|
|
5102
|
+
* @param params.search - Optional case-insensitive tag-name substring.
|
|
4840
5103
|
* @param accountId - Override the client's default account ID.
|
|
4841
5104
|
* @returns The matching tags (list items carry no `resource` field):
|
|
4842
5105
|
* ```jsonc
|
|
@@ -5010,6 +5273,8 @@ var TagResource = class extends BaseResource {
|
|
|
5010
5273
|
* @param tagId - The tag to delete.
|
|
5011
5274
|
* @param options - `force` to detach-and-delete when the tag is still in
|
|
5012
5275
|
* use, and `accountId` to override the client's default account ID.
|
|
5276
|
+
* @param options.force - Detach the tag from documents before deletion.
|
|
5277
|
+
* @param options.accountId - Override the client's default workspace.
|
|
5013
5278
|
* @returns `{ deleted: true }` when the tag was deleted.
|
|
5014
5279
|
* @throws {ValidationError} If `tagId` is missing, or no account ID is available.
|
|
5015
5280
|
* @throws {ApiError} `404` if the tag does not exist; `409` if the tag is
|
|
@@ -6575,6 +6840,8 @@ var FieldsResource = class extends BaseResource {
|
|
|
6575
6840
|
* @param value - The value to check (validated against the field's
|
|
6576
6841
|
* type/regex). Sent as `{ value }` in the request body.
|
|
6577
6842
|
* @param options - Account override and optional legacy `signerAccessCode`.
|
|
6843
|
+
* @param options.accountId - Override the client's default workspace.
|
|
6844
|
+
* @param options.signerAccessCode - Legacy signer code sent as a query parameter.
|
|
6578
6845
|
* @returns The validation result. Response shape:
|
|
6579
6846
|
* ```jsonc
|
|
6580
6847
|
* {
|
|
@@ -6635,6 +6902,8 @@ var FieldsResource = class extends BaseResource {
|
|
|
6635
6902
|
*
|
|
6636
6903
|
* @param entries - Non-empty array of `{ field_id, value }` pairs.
|
|
6637
6904
|
* @param options - Account override and optional legacy `signerAccessCode`.
|
|
6905
|
+
* @param options.accountId - Override the client's default workspace.
|
|
6906
|
+
* @param options.signerAccessCode - Legacy signer code sent as a query parameter.
|
|
6638
6907
|
* @returns One validation result per entry. Response shape:
|
|
6639
6908
|
* ```jsonc
|
|
6640
6909
|
* [
|
|
@@ -6724,7 +6993,14 @@ function validateSignerAccessCode(value) {
|
|
|
6724
6993
|
var SignerDocumentsResource = class extends BaseResource {
|
|
6725
6994
|
constructor(http, defaultAccountId, logger, publicHttp) {
|
|
6726
6995
|
super(withoutCredentials(publicHttp ?? http), defaultAccountId, logger);
|
|
6996
|
+
this.workspaceHttp = http;
|
|
6727
6997
|
}
|
|
6998
|
+
/**
|
|
6999
|
+
* Credentialed transport used only by the explicit `*AsWorkspace` methods.
|
|
7000
|
+
* Every access-code method stays on the credential-free `http`, so a
|
|
7001
|
+
* signer code and the API key or bearer token never share a request.
|
|
7002
|
+
*/
|
|
7003
|
+
workspaceHttp;
|
|
6728
7004
|
/**
|
|
6729
7005
|
* Fetch the document currently awaiting a given signer
|
|
6730
7006
|
* (`GET /signers/{signer_id}/document?signer-access-code=…`).
|
|
@@ -6897,6 +7173,73 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6897
7173
|
})
|
|
6898
7174
|
);
|
|
6899
7175
|
}
|
|
7176
|
+
/**
|
|
7177
|
+
* List a signer's documents with the workspace credentials
|
|
7178
|
+
* (`GET /signers/{signer_id}/documents`).
|
|
7179
|
+
*
|
|
7180
|
+
* The same operation as {@link SignerDocumentsResource.list}, authorised by
|
|
7181
|
+
* the client's API key or OAuth bearer token instead of a signer access
|
|
7182
|
+
* code. No `signer-access-code` is sent.
|
|
7183
|
+
*
|
|
7184
|
+
* @param signerId - The signer whose documents are listed.
|
|
7185
|
+
* @param params - Pagination: `page`, `per-page` (also accepts `per_page`).
|
|
7186
|
+
* @returns Documents in the compact {@link IDocumentListItem} shape, with
|
|
7187
|
+
* pagination in `meta` (same shape as {@link SignerDocumentsResource.list}):
|
|
7188
|
+
* ```jsonc
|
|
7189
|
+
* {
|
|
7190
|
+
* "data": [{ "id": "103acccd24234c07858ffddf6d84", "name": "Service agreement.pdf", "status": "pending_signature" }],
|
|
7191
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
|
|
7192
|
+
* }
|
|
7193
|
+
* ```
|
|
7194
|
+
* @throws {ValidationError} If `signerId` is missing.
|
|
7195
|
+
* @throws {ApiError} `401` if the workspace credentials are rejected.
|
|
7196
|
+
*
|
|
7197
|
+
* @example
|
|
7198
|
+
* ```ts
|
|
7199
|
+
* const { data } = await client.signerDocuments.listAsWorkspace(signerId, { page: 1 });
|
|
7200
|
+
* ```
|
|
7201
|
+
*/
|
|
7202
|
+
async listAsWorkspace(signerId, params = {}) {
|
|
7203
|
+
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7204
|
+
return this.callList(
|
|
7205
|
+
"Failed to list signer documents",
|
|
7206
|
+
() => this.workspaceHttp.get(`/signers/${sid}/documents`, {
|
|
7207
|
+
params: cleanListParams(params)
|
|
7208
|
+
})
|
|
7209
|
+
);
|
|
7210
|
+
}
|
|
7211
|
+
/**
|
|
7212
|
+
* Search a signer's documents with the workspace credentials
|
|
7213
|
+
* (`GET /signers/{signer_id}/documents/search`).
|
|
7214
|
+
*
|
|
7215
|
+
* The same operation as {@link SignerDocumentsResource.search}, authorised
|
|
7216
|
+
* by the client's API key or OAuth bearer token instead of a signer access
|
|
7217
|
+
* code. No `signer-access-code` is sent.
|
|
7218
|
+
*
|
|
7219
|
+
* @param signerId - The signer whose documents are searched.
|
|
7220
|
+
* @param search - Free-text term matched against the document name.
|
|
7221
|
+
* @returns Matching documents with pagination in `meta`, as
|
|
7222
|
+
* {@link SignerDocumentsResource.listAsWorkspace} returns.
|
|
7223
|
+
* @throws {ValidationError} If `signerId` is missing or `search` is not a string.
|
|
7224
|
+
* @throws {ApiError} `401` if the workspace credentials are rejected.
|
|
7225
|
+
*
|
|
7226
|
+
* @example
|
|
7227
|
+
* ```ts
|
|
7228
|
+
* const { data } = await client.signerDocuments.searchAsWorkspace(signerId, 'agreement');
|
|
7229
|
+
* ```
|
|
7230
|
+
*/
|
|
7231
|
+
async searchAsWorkspace(signerId, search) {
|
|
7232
|
+
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7233
|
+
if (search !== void 0 && typeof search !== "string") {
|
|
7234
|
+
throw new ValidationError("search must be a string");
|
|
7235
|
+
}
|
|
7236
|
+
return this.callList(
|
|
7237
|
+
"Failed to search signer documents",
|
|
7238
|
+
() => this.workspaceHttp.get(`/signers/${sid}/documents/search`, {
|
|
7239
|
+
params: cleanParams({ search })
|
|
7240
|
+
})
|
|
7241
|
+
);
|
|
7242
|
+
}
|
|
6900
7243
|
/**
|
|
6901
7244
|
* Download one of a signer's document artifacts as raw bytes
|
|
6902
7245
|
* (`GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`).
|
|
@@ -7071,7 +7414,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7071
7414
|
* "has_accepted_terms": false,
|
|
7072
7415
|
* "has_signature": false,
|
|
7073
7416
|
* "has_initial": false,
|
|
7074
|
-
* "is_signature_reusable": false
|
|
7417
|
+
* "is_signature_reusable": false,
|
|
7418
|
+
* "verification_method": "IdDocumentFaceMatchBasic"
|
|
7075
7419
|
* }
|
|
7076
7420
|
* ```
|
|
7077
7421
|
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
@@ -7092,6 +7436,92 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7092
7436
|
() => this.http.get("/signers/self", { params: { "signer-access-code": code } })
|
|
7093
7437
|
);
|
|
7094
7438
|
}
|
|
7439
|
+
/**
|
|
7440
|
+
* Read the signer's identity verification state
|
|
7441
|
+
* (`GET /signers/identity-verification?signer-access-code=…`).
|
|
7442
|
+
*
|
|
7443
|
+
* No request body or workspace credentials. Reads a pending provider
|
|
7444
|
+
* decision when available. A new session can start before the first capture
|
|
7445
|
+
* or after `Expired`; `Declined` and `Abandoned` require a new document and
|
|
7446
|
+
* assignment. `InReview` lets the signer continue; account approval gates
|
|
7447
|
+
* certification, with `pending_identity_review` after everyone signs.
|
|
7448
|
+
*
|
|
7449
|
+
* @param signerAccessCode - Access code from the signer's signing link.
|
|
7450
|
+
* @returns Provider state, with nullable fields before a session exists:
|
|
7451
|
+
* ```jsonc
|
|
7452
|
+
* {
|
|
7453
|
+
* "can_start": false, "status": "Pending",
|
|
7454
|
+
* "url": "https://verify.example.com/c/session#t=opaque",
|
|
7455
|
+
* "expires_at": "2026-10-16T12:30:00Z", "completed_at": null
|
|
7456
|
+
* }
|
|
7457
|
+
* ```
|
|
7458
|
+
* `url` exists only while Pending. It is a bearer link: open it intact,
|
|
7459
|
+
* including its fragment, and keep it out of logs and browser storage.
|
|
7460
|
+
* @throws {ValidationError} If the access code is blank.
|
|
7461
|
+
* @throws {ApiError} `401` for an invalid/expired code; `500` for a server failure.
|
|
7462
|
+
* @example
|
|
7463
|
+
* ```ts
|
|
7464
|
+
* const state = await client.signerDocuments.getIdentityVerification(accessCode);
|
|
7465
|
+
* console.log(state.status, state.can_start);
|
|
7466
|
+
* ```
|
|
7467
|
+
*/
|
|
7468
|
+
async getIdentityVerification(signerAccessCode) {
|
|
7469
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7470
|
+
return this.call(
|
|
7471
|
+
"Failed to fetch signer identity verification",
|
|
7472
|
+
() => this.http.get("/signers/identity-verification", { params: { "signer-access-code": code } })
|
|
7473
|
+
);
|
|
7474
|
+
}
|
|
7475
|
+
/**
|
|
7476
|
+
* Record biometric consent and open an identity verification session
|
|
7477
|
+
* (`POST /signers/identity-verification?signer-access-code=…`).
|
|
7478
|
+
*
|
|
7479
|
+
* Send only after the signer explicitly consents. Starts a session when
|
|
7480
|
+
* none exists or replaces an Expired session. Other states return `400`;
|
|
7481
|
+
* resending a notification never replaces a live session. The account is
|
|
7482
|
+
* billed at assignment creation, with no new charge for a restart.
|
|
7483
|
+
*
|
|
7484
|
+
* Request body (`application/json`):
|
|
7485
|
+
* ```jsonc
|
|
7486
|
+
* { "consent": true }
|
|
7487
|
+
* ```
|
|
7488
|
+
* @param signerAccessCode - Access code from the signer's signing link.
|
|
7489
|
+
* @param payload - Explicit consent from the signer.
|
|
7490
|
+
* @param payload.consent - Must be `true`; never default or infer consent.
|
|
7491
|
+
* @returns The newly opened provider session:
|
|
7492
|
+
* ```jsonc
|
|
7493
|
+
* {
|
|
7494
|
+
* "id": "verification_example",
|
|
7495
|
+
* "url": "https://verify.example.com/c/session#t=opaque",
|
|
7496
|
+
* "expires_at": "2026-10-16T12:30:00Z"
|
|
7497
|
+
* }
|
|
7498
|
+
* ```
|
|
7499
|
+
* `expires_at` can be null. Open the URL as-is; it is a bearer credential
|
|
7500
|
+
* and its fragment must survive navigation. Do not log or persist it in
|
|
7501
|
+
* browser storage. No workspace credential is attached to this call.
|
|
7502
|
+
* @throws {ValidationError} If the code is blank or consent is not `true`.
|
|
7503
|
+
* @throws {ApiError} `400` when a non-expired session already exists;
|
|
7504
|
+
* `401` for an invalid/expired code; `500` for a provider/server failure.
|
|
7505
|
+
* @example
|
|
7506
|
+
* ```ts
|
|
7507
|
+
* // Inside the handler for the signer's explicit consent action:
|
|
7508
|
+
* const session = await client.signerDocuments.startIdentityVerification(accessCode, { consent: true });
|
|
7509
|
+
* response.redirect(session.url);
|
|
7510
|
+
* ```
|
|
7511
|
+
*/
|
|
7512
|
+
async startIdentityVerification(signerAccessCode, payload) {
|
|
7513
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7514
|
+
assertRecord(payload, "identity verification payload");
|
|
7515
|
+
if (payload.consent !== true) {
|
|
7516
|
+
throw new ValidationError("Explicit biometric-processing consent is required");
|
|
7517
|
+
}
|
|
7518
|
+
return this.call(
|
|
7519
|
+
"Failed to start signer identity verification",
|
|
7520
|
+
() => this.http.post("/signers/identity-verification", { consent: true }, {
|
|
7521
|
+
params: { "signer-access-code": code }
|
|
7522
|
+
})
|
|
7523
|
+
);
|
|
7524
|
+
}
|
|
7095
7525
|
/**
|
|
7096
7526
|
* Accept the platform terms of use as the signer
|
|
7097
7527
|
* (`PUT /signers/accept-terms?signer-access-code=…`).
|
|
@@ -7125,10 +7555,10 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7125
7555
|
);
|
|
7126
7556
|
}
|
|
7127
7557
|
/**
|
|
7128
|
-
* Verify the signer's email one-time password
|
|
7558
|
+
* Verify the signer's email or WhatsApp one-time password
|
|
7129
7559
|
* (`POST /verify?signer-access-code=…`).
|
|
7130
7560
|
*
|
|
7131
|
-
* Confirms the 6-digit OTP
|
|
7561
|
+
* Confirms the 6-digit OTP sent through the selected channel. The access code
|
|
7132
7562
|
* authenticates via the `signer-access-code` **query param**; the request
|
|
7133
7563
|
* **body carries only `verification-code`** (putting the access code in the
|
|
7134
7564
|
* body leaves the request unauthenticated → `401`).
|
|
@@ -7142,6 +7572,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7142
7572
|
*
|
|
7143
7573
|
* @param payload - `signerAccessCode` (the signing-link code) and
|
|
7144
7574
|
* `verificationCode` (the OTP the signer received).
|
|
7575
|
+
* @param payload.signerAccessCode - Signing-link code sent only in the query.
|
|
7576
|
+
* @param payload.verificationCode - Email or WhatsApp OTP sent as `verification-code`.
|
|
7145
7577
|
* @returns Resolves when the API acknowledges the operation. The response
|
|
7146
7578
|
* envelope has no `data` field and is intentionally discarded.
|
|
7147
7579
|
* @throws {ValidationError} If `signerAccessCode` or `verificationCode` is
|
|
@@ -7302,7 +7734,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7302
7734
|
* "expires_at": null,
|
|
7303
7735
|
* "signers": [
|
|
7304
7736
|
* { "id": "19e6b92e7895332ed9708535d8c", "step": 1, "email": "signer@example.com",
|
|
7305
|
-
* "full_name": "Example Signer", "notified": true
|
|
7737
|
+
* "full_name": "Example Signer", "notified": true }
|
|
7306
7738
|
* ],
|
|
7307
7739
|
* "items": [
|
|
7308
7740
|
* { "id": "item-1", "page": { "id": "page-1", "number": 1, "height": 1651, "width": 1275,
|
|
@@ -7479,6 +7911,9 @@ function assertDeclineReason(declineReason) {
|
|
|
7479
7911
|
if (typeof declineReason !== "string" || !declineReason.trim()) {
|
|
7480
7912
|
throw new ValidationError("declineReason is required");
|
|
7481
7913
|
}
|
|
7914
|
+
if (declineReason.length > 2e3) {
|
|
7915
|
+
throw new ValidationError("declineReason must be at most 2000 characters");
|
|
7916
|
+
}
|
|
7482
7917
|
}
|
|
7483
7918
|
function validateConfirmDataPayload(payload) {
|
|
7484
7919
|
for (const key of ["full_name", "government_id"]) {
|
|
@@ -7912,7 +8347,8 @@ var WebhookVerifier = class {
|
|
|
7912
8347
|
* @param toleranceSeconds - Accepted clock distance. Defaults to `300`.
|
|
7913
8348
|
* @returns `true` only when a signature entry matches (constant-time) and
|
|
7914
8349
|
* the timestamp is fresh; `false` when verification is disabled, a header
|
|
7915
|
-
* is missing,
|
|
8350
|
+
* is missing, the tolerance is not finite and non-negative, or anything
|
|
8351
|
+
* does not match.
|
|
7916
8352
|
*
|
|
7917
8353
|
* @example
|
|
7918
8354
|
* ```ts
|
|
@@ -7928,7 +8364,7 @@ var WebhookVerifier = class {
|
|
|
7928
8364
|
*/
|
|
7929
8365
|
verifySignature(payload, headers, toleranceSeconds = DEFAULT_TOLERANCE_SECONDS) {
|
|
7930
8366
|
const key = decodeSecret(this.webhookSecret);
|
|
7931
|
-
if (!key || typeof payload !== "string" && !Buffer.isBuffer(payload) || !headers) {
|
|
8367
|
+
if (!key || typeof payload !== "string" && !Buffer.isBuffer(payload) || !headers || !Number.isFinite(toleranceSeconds) || toleranceSeconds < 0) {
|
|
7932
8368
|
return false;
|
|
7933
8369
|
}
|
|
7934
8370
|
const id = header(headers, "webhook-id");
|
|
@@ -8044,9 +8480,8 @@ function decodeSecret(secret) {
|
|
|
8044
8480
|
return key.length > 0 ? key : null;
|
|
8045
8481
|
}
|
|
8046
8482
|
function header(headers, name) {
|
|
8047
|
-
const value = typeof headers.get === "function" ? headers.get(name) : headers
|
|
8048
|
-
|
|
8049
|
-
return typeof first === "string" ? first.trim() : void 0;
|
|
8483
|
+
const value = typeof headers.get === "function" ? headers.get(name) ?? void 0 : readHeader(headers, name);
|
|
8484
|
+
return typeof value === "string" ? value.trim() : void 0;
|
|
8050
8485
|
}
|
|
8051
8486
|
function isRecord(value) {
|
|
8052
8487
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -8183,7 +8618,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
8183
8618
|
);
|
|
8184
8619
|
this.fields = new FieldsResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
8185
8620
|
this.signerDocuments = new SignerDocumentsResource(
|
|
8186
|
-
this.
|
|
8621
|
+
this.axiosInstance,
|
|
8187
8622
|
this.defaultAccountId,
|
|
8188
8623
|
this.logger,
|
|
8189
8624
|
this.publicAxiosInstance
|