@assinafy/sdk 2.11.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -1
- package/README.en.md +89 -1669
- package/README.md +87 -1628
- package/dist/index.d.mts +1549 -291
- package/dist/index.d.ts +1549 -291
- package/dist/index.js +1626 -262
- package/dist/index.mjs +1624 -262
- package/docs/API_COVERAGE.md +67 -20
- package/docs/COMPATIBILITY.md +99 -38
- package/docs/README.en.md +1863 -0
- package/docs/README.md +1818 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,24 @@ var AssinafyError = class extends Error {
|
|
|
32
32
|
var ApiError = class _ApiError extends AssinafyError {
|
|
33
33
|
statusCode;
|
|
34
34
|
responseData;
|
|
35
|
+
/**
|
|
36
|
+
* Machine-readable refusal code from the error body, on the refusals a
|
|
37
|
+
* client can act on: `PlanRestricted` (offer the upgrade, don't retry),
|
|
38
|
+
* `InsufficientScope`, `DocumentNotReady`, `CreditCeilingExceeded`,
|
|
39
|
+
* `IdempotencyKeyInUse`, `EnvelopeOpen`, `EnvelopeClosed`, `DocumentClosed`,
|
|
40
|
+
* `ContractChanged`, `NoContractTerms`, `TagInUse`, `embed_origins_missing`, ….
|
|
41
|
+
* `undefined` when the body has none.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* if (error instanceof ApiError && error.code === 'IdempotencyKeyInUse') {
|
|
46
|
+
* await sleep(1000); // the first request with this key is still running
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
code;
|
|
51
|
+
/** Each field a `400` refused, in the order the API reports them. */
|
|
52
|
+
fieldErrors;
|
|
35
53
|
/**
|
|
36
54
|
* Parsed `WWW-Authenticate` challenge, when the response carried one.
|
|
37
55
|
*
|
|
@@ -39,8 +57,8 @@ var ApiError = class _ApiError extends AssinafyError {
|
|
|
39
57
|
* means the OAuth token is valid but was never granted that permission:
|
|
40
58
|
* send the user through the authorization flow again asking for the scope
|
|
41
59
|
* named in `scope`. A `403` without a challenge has a different cause —
|
|
42
|
-
* another workspace, the user's role,
|
|
43
|
-
* reach — and reconnecting will not fix it.
|
|
60
|
+
* another workspace, the user's role, the plan (`code: 'PlanRestricted'`),
|
|
61
|
+
* or a surface OAuth tokens never reach — and reconnecting will not fix it.
|
|
44
62
|
*
|
|
45
63
|
* @example
|
|
46
64
|
* ```ts
|
|
@@ -87,6 +105,14 @@ var ApiError = class _ApiError extends AssinafyError {
|
|
|
87
105
|
this.name = "ApiError";
|
|
88
106
|
this.statusCode = statusCode;
|
|
89
107
|
this.responseData = responseData;
|
|
108
|
+
if (responseData !== null && typeof responseData === "object") {
|
|
109
|
+
const body = responseData;
|
|
110
|
+
if (typeof body["code"] === "string" && body["code"].length > 0) this.code = body["code"];
|
|
111
|
+
if (Array.isArray(body["errors"])) {
|
|
112
|
+
const fieldErrors = body["errors"].filter(isFieldError);
|
|
113
|
+
if (fieldErrors.length > 0) this.fieldErrors = fieldErrors;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
90
116
|
}
|
|
91
117
|
/**
|
|
92
118
|
* Convert a status/body pair into an {@link ApiError}.
|
|
@@ -219,6 +245,11 @@ var NetworkError = class extends AssinafyError {
|
|
|
219
245
|
this.name = "NetworkError";
|
|
220
246
|
}
|
|
221
247
|
};
|
|
248
|
+
function isFieldError(value) {
|
|
249
|
+
if (value === null || typeof value !== "object") return false;
|
|
250
|
+
const entry = value;
|
|
251
|
+
return (entry["field"] === null || typeof entry["field"] === "string") && typeof entry["code"] === "string" && typeof entry["message"] === "string";
|
|
252
|
+
}
|
|
222
253
|
|
|
223
254
|
// src/utils.ts
|
|
224
255
|
import axios from "axios";
|
|
@@ -279,6 +310,7 @@ var SAFE_LOG_NUMBER_FIELDS = /* @__PURE__ */ new Set([
|
|
|
279
310
|
"delayMs",
|
|
280
311
|
"maxRetries",
|
|
281
312
|
"signerCount",
|
|
313
|
+
"documentCount",
|
|
282
314
|
"size"
|
|
283
315
|
]);
|
|
284
316
|
function handleAssinafyResponse(response) {
|
|
@@ -465,6 +497,34 @@ function assertExpirationDate(value, label) {
|
|
|
465
497
|
throw new ValidationError(`${label} must be an ISO-8601 date or date-time`);
|
|
466
498
|
}
|
|
467
499
|
}
|
|
500
|
+
function assertCreditCeiling(value) {
|
|
501
|
+
if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value) || value < 0)) {
|
|
502
|
+
throw new ValidationError("max_total_credits must be a finite number of credits, zero or more");
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function idempotencyConfig(key) {
|
|
506
|
+
if (key === void 0) return {};
|
|
507
|
+
if (typeof key !== "string" || key.trim().length === 0) {
|
|
508
|
+
throw new ValidationError("idempotencyKey must be a non-empty string");
|
|
509
|
+
}
|
|
510
|
+
return { headers: { "Idempotency-Key": key } };
|
|
511
|
+
}
|
|
512
|
+
function assertBooleanMap(value, label, known) {
|
|
513
|
+
assertRecord(value, label);
|
|
514
|
+
const entries = Object.entries(value);
|
|
515
|
+
if (entries.length === 0) throw new ValidationError(`${label} must set at least one key`);
|
|
516
|
+
for (const [key, item] of entries) {
|
|
517
|
+
if (known && !known.has(key)) throw new ValidationError(`unknown ${label} key: ${key}`);
|
|
518
|
+
if (typeof item !== "boolean") throw new ValidationError(`${label}.${key} must be a boolean`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function expandParam(value, allowed) {
|
|
522
|
+
if (value === void 0) return {};
|
|
523
|
+
if (!Array.isArray(value) || value.some((item) => !allowed.has(item))) {
|
|
524
|
+
throw new ValidationError(`expand must list only ${[...allowed].join(", ")}`);
|
|
525
|
+
}
|
|
526
|
+
return value.length > 0 ? { expand: value.join(",") } : {};
|
|
527
|
+
}
|
|
468
528
|
function cleanParams(params) {
|
|
469
529
|
assertRecord(params, "params");
|
|
470
530
|
const out = {};
|
|
@@ -639,7 +699,7 @@ import axios2 from "axios";
|
|
|
639
699
|
// package.json
|
|
640
700
|
var package_default = {
|
|
641
701
|
name: "@assinafy/sdk",
|
|
642
|
-
version: "
|
|
702
|
+
version: "3.0.1",
|
|
643
703
|
packageManager: "bun@1.4.4",
|
|
644
704
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
645
705
|
type: "commonjs",
|
|
@@ -991,14 +1051,22 @@ function toInt(value) {
|
|
|
991
1051
|
|
|
992
1052
|
// src/resources/assignments.ts
|
|
993
1053
|
var ASSIGNMENT_METHODS = /* @__PURE__ */ new Set(["virtual", "collect"]);
|
|
994
|
-
var VERIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
995
|
-
|
|
1054
|
+
var VERIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
1055
|
+
"Email",
|
|
1056
|
+
"Whatsapp",
|
|
1057
|
+
"DigitalCertificate",
|
|
1058
|
+
"IdDocumentFaceMatchBasic",
|
|
1059
|
+
"Bypass"
|
|
1060
|
+
]);
|
|
1061
|
+
var NOTIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1062
|
+
var EMBEDDED_VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
996
1063
|
var DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD = "digital_certificate_requires_virtual_method";
|
|
997
1064
|
var ALLOWED_NOTIFICATION_METHODS = {
|
|
998
1065
|
Email: /* @__PURE__ */ new Set(["Email"]),
|
|
999
1066
|
Whatsapp: /* @__PURE__ */ new Set(["Whatsapp"]),
|
|
1000
1067
|
DigitalCertificate: NOTIFICATION_METHODS,
|
|
1001
|
-
IdDocumentFaceMatchBasic: NOTIFICATION_METHODS
|
|
1068
|
+
IdDocumentFaceMatchBasic: NOTIFICATION_METHODS,
|
|
1069
|
+
Bypass: NOTIFICATION_METHODS
|
|
1002
1070
|
};
|
|
1003
1071
|
function validateAssignmentSignerOptions(signer, label = "signer") {
|
|
1004
1072
|
if (signer.verification_method !== void 0 && (typeof signer.verification_method !== "string" || !VERIFICATION_METHODS.has(signer.verification_method))) {
|
|
@@ -1024,6 +1092,14 @@ function validateAssignmentSignerOptions(signer, label = "signer") {
|
|
|
1024
1092
|
}
|
|
1025
1093
|
}
|
|
1026
1094
|
}
|
|
1095
|
+
if (signer.embedded !== void 0 && typeof signer.embedded !== "boolean") {
|
|
1096
|
+
throw new ValidationError(`${label} embedded must be a boolean`);
|
|
1097
|
+
}
|
|
1098
|
+
if (signer.embedded === true && typeof signer.verification_method === "string" && !EMBEDDED_VERIFICATION_METHODS.has(signer.verification_method)) {
|
|
1099
|
+
throw new ValidationError(
|
|
1100
|
+
`${label} embedded signing supports only Email, Whatsapp and Bypass verification`
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1027
1103
|
if (signer.step !== void 0 && (typeof signer.step !== "number" || !Number.isSafeInteger(signer.step) || signer.step < 1)) {
|
|
1028
1104
|
throw new ValidationError(`${label} step must be a positive safe integer`);
|
|
1029
1105
|
}
|
|
@@ -1084,6 +1160,7 @@ function buildAssignmentPayload(payload) {
|
|
|
1084
1160
|
))) {
|
|
1085
1161
|
throw new ValidationError("copy_receivers must be an array of non-empty signer IDs");
|
|
1086
1162
|
}
|
|
1163
|
+
assertCreditCeiling(payload.max_total_credits);
|
|
1087
1164
|
const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref));
|
|
1088
1165
|
validateDigitalCertificateMethod(method, normalisedSigners);
|
|
1089
1166
|
validateSigningOrder(normalisedSigners, "assignment signers");
|
|
@@ -1093,7 +1170,8 @@ function buildAssignmentPayload(payload) {
|
|
|
1093
1170
|
message: payload.message,
|
|
1094
1171
|
expires_at: payload.expires_at,
|
|
1095
1172
|
copy_receivers: payload.copy_receivers,
|
|
1096
|
-
entries
|
|
1173
|
+
entries,
|
|
1174
|
+
max_total_credits: payload.max_total_credits
|
|
1097
1175
|
});
|
|
1098
1176
|
}
|
|
1099
1177
|
function buildAssignmentEstimatePayload(payload) {
|
|
@@ -1138,6 +1216,7 @@ function normaliseSignerRef(ref) {
|
|
|
1138
1216
|
id,
|
|
1139
1217
|
verification_method: input.verification_method,
|
|
1140
1218
|
notification_methods: input.notification_methods,
|
|
1219
|
+
embedded: input.embedded,
|
|
1141
1220
|
step: input.step
|
|
1142
1221
|
});
|
|
1143
1222
|
if (typeof id === "string" && id.trim().length > 0) {
|
|
@@ -1245,12 +1324,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1245
1324
|
/**
|
|
1246
1325
|
* List assignments across the workspace (`GET /assignments`).
|
|
1247
1326
|
*
|
|
1248
|
-
* The account is passed as
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1327
|
+
* The account is passed as the camelCase `accountId` **query parameter**,
|
|
1328
|
+
* required unless an OAuth token names the workspace (the SDK always sends
|
|
1329
|
+
* it; for a token, its own workspace). `account_id` and an `X-Account-Id`
|
|
1330
|
+
* header are ignored.
|
|
1252
1331
|
*
|
|
1253
|
-
* @param params - `page`, `per-page
|
|
1332
|
+
* @param params - `page`, `per-page` (at most 50), and `sort`: `created_at`
|
|
1333
|
+
* (default, oldest first), `expires_at` or `id`, `-` prefix for descending.
|
|
1254
1334
|
* @param accountId - Override the client's default account ID.
|
|
1255
1335
|
* @returns Assignments, with pagination in `meta`. Each item is a full
|
|
1256
1336
|
* {@link IAssignment} (same shape as {@link AssignmentResource.create}
|
|
@@ -1318,13 +1398,15 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1318
1398
|
* "signing_urls": [
|
|
1319
1399
|
* {
|
|
1320
1400
|
* "signer_id": "19e6b92e7895332ed9708535d8c",
|
|
1321
|
-
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com"
|
|
1401
|
+
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com",
|
|
1402
|
+
* "embedded": false
|
|
1322
1403
|
* }
|
|
1323
1404
|
* ]
|
|
1324
1405
|
* }
|
|
1325
1406
|
* ```
|
|
1326
1407
|
* @throws {ValidationError} If no account ID is available.
|
|
1327
|
-
* @throws {ApiError}
|
|
1408
|
+
* @throws {ApiError} `400` when no workspace is named, `403` when a role or
|
|
1409
|
+
* OAuth scope refuses it, `404` for an unknown workspace.
|
|
1328
1410
|
*
|
|
1329
1411
|
* @example
|
|
1330
1412
|
* ```ts
|
|
@@ -1384,7 +1466,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1384
1466
|
* `message`, `expires_at`, `copy_receivers` (existing signer IDs, not
|
|
1385
1467
|
* addresses), and `collect`-mode `entries` with page-image geometry.
|
|
1386
1468
|
* `expires_at` accepts a date (ending at 23:59 UTC), a date-time without
|
|
1387
|
-
* an offset (UTC), or an offset-aware date-time.
|
|
1469
|
+
* an offset (UTC), or an offset-aware date-time, at least one hour ahead.
|
|
1470
|
+
* `max_total_credits` refuses the send above that many credits. Signers may
|
|
1471
|
+
* set `embedded: true` (Embed feature; `Email`, `Whatsapp` or `Bypass`
|
|
1472
|
+
* verification) to sign in your app through `embed.createSession()`.
|
|
1473
|
+
* This route takes no `Idempotency-Key`: a document takes one assignment,
|
|
1474
|
+
* so a retry after a lost response answers `400` and charges nothing —
|
|
1475
|
+
* read the document to see whether the first request went through.
|
|
1388
1476
|
* @returns The created {@link IAssignment}: `signers` (rich, with `step` /
|
|
1389
1477
|
* `notified` / `verification_method`), `items` (one row per signer × field),
|
|
1390
1478
|
* a `summary` count block, and per-signer `signing_urls`. Response shape:
|
|
@@ -1449,7 +1537,8 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1449
1537
|
* "signing_urls": [
|
|
1450
1538
|
* {
|
|
1451
1539
|
* "signer_id": "19e6b92e7895332ed9708535d8c",
|
|
1452
|
-
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com"
|
|
1540
|
+
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com",
|
|
1541
|
+
* "embedded": false // an embedded signer has "url": null
|
|
1453
1542
|
* }
|
|
1454
1543
|
* ]
|
|
1455
1544
|
* }
|
|
@@ -1459,7 +1548,10 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1459
1548
|
* combined with `collect`. The last case has `errors.code ===
|
|
1460
1549
|
* 'digital_certificate_requires_virtual_method'`.
|
|
1461
1550
|
* @throws {ApiError} `400` for an invalid assignment or unmet verification
|
|
1462
|
-
* precondition;
|
|
1551
|
+
* precondition; `403` (`PlanRestricted` for a method or Embed the plan
|
|
1552
|
+
* lacks, `InsufficientScope`); `404` for a document outside the workspace;
|
|
1553
|
+
* `409` (`CreditCeilingExceeded`, with `total_credits` and
|
|
1554
|
+
* `max_total_credits` in `responseData`).
|
|
1463
1555
|
*
|
|
1464
1556
|
* @example
|
|
1465
1557
|
* ```ts
|
|
@@ -1468,7 +1560,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1468
1560
|
* message: 'Please sign this contract',
|
|
1469
1561
|
* });
|
|
1470
1562
|
* // → wire body: { method: 'virtual', signers: [{ id: '19e6…' }], message: 'Please sign this contract' }
|
|
1471
|
-
* console.log(assignment.signing_urls?.length); // one
|
|
1563
|
+
* console.log(assignment.signing_urls?.length); // one entry per notified signer; url is null for embedded or WhatsApp-only signers
|
|
1472
1564
|
* ```
|
|
1473
1565
|
*/
|
|
1474
1566
|
async create(documentId, payload) {
|
|
@@ -1660,7 +1752,11 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1660
1752
|
* }
|
|
1661
1753
|
* ```
|
|
1662
1754
|
* @throws {ValidationError} If any of the three IDs is missing.
|
|
1663
|
-
* @throws {ApiError}
|
|
1755
|
+
* @throws {ApiError} `400` when the document is not pending signature, the
|
|
1756
|
+
* signer already signed or waits for an earlier step, or credits are short;
|
|
1757
|
+
* `403`; `404`. The same verification code is resent, so an open embed frame
|
|
1758
|
+
* keeps working; envelope signers can be reminded of every document at once
|
|
1759
|
+
* with `envelopes.resendNotification()`.
|
|
1664
1760
|
*
|
|
1665
1761
|
* @example
|
|
1666
1762
|
* ```ts
|
|
@@ -1689,26 +1785,20 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1689
1785
|
* @param documentId - The document the assignment belongs to.
|
|
1690
1786
|
* @param assignmentId - The assignment containing the signer.
|
|
1691
1787
|
* @param signerId - The signer whose notification would be resent.
|
|
1692
|
-
* @returns An {@link IResendCostEstimate}:
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1788
|
+
* @returns An {@link IResendCostEstimate}: the compact `total` /
|
|
1789
|
+
* `has_sufficient_credits` shape production returns, or the full
|
|
1790
|
+
* {@link ICostEstimate} on older deployments:
|
|
1695
1791
|
* ```jsonc
|
|
1696
1792
|
* {
|
|
1697
|
-
* "
|
|
1698
|
-
* "
|
|
1699
|
-
* "
|
|
1700
|
-
* "
|
|
1701
|
-
* "total_credits": 0,
|
|
1702
|
-
* "breakdown": [],
|
|
1703
|
-
* "document_balance": 67,
|
|
1704
|
-
* "credit_balance": 0,
|
|
1705
|
-
* "has_sufficient_resources": true,
|
|
1706
|
-
* "blocking_reason": null,
|
|
1707
|
-
* "message": null
|
|
1793
|
+
* "total": 0.45,
|
|
1794
|
+
* "breakdown": [{ "code": "NotificationWhatsappResend", "name": "WhatsApp Notification Resend", "cost": 0.45 }],
|
|
1795
|
+
* "credit_balance": 10, // null when credits are not limited
|
|
1796
|
+
* "has_sufficient_credits": true
|
|
1708
1797
|
* }
|
|
1709
1798
|
* ```
|
|
1710
1799
|
* @throws {ValidationError} If any of the three IDs is missing.
|
|
1711
|
-
* @throws {ApiError}
|
|
1800
|
+
* @throws {ApiError} `400` when the signer cannot be reminded (signed, not
|
|
1801
|
+
* yet notified, or notified only by `Bypass`), `403`, `404`.
|
|
1712
1802
|
*
|
|
1713
1803
|
* @example
|
|
1714
1804
|
* ```ts
|
|
@@ -1746,11 +1836,11 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1746
1836
|
* ```jsonc
|
|
1747
1837
|
* [
|
|
1748
1838
|
* {
|
|
1749
|
-
* "sent_at":
|
|
1839
|
+
* "sent_at": "2026-10-19T19:05:48Z",
|
|
1750
1840
|
* "header": "Assinafy",
|
|
1751
1841
|
* "body": "Você tem um documento para assinar.",
|
|
1752
1842
|
* "buttons": [
|
|
1753
|
-
* { "text": "Assinar documento"
|
|
1843
|
+
* { "text": "Assinar documento" } // production strips button URLs
|
|
1754
1844
|
* ],
|
|
1755
1845
|
* "phone_number": "+5511999998888",
|
|
1756
1846
|
* "signer_id": "19e6b92e7895332ed9708535d8c"
|
|
@@ -2209,7 +2299,11 @@ var DocumentResource = class extends BaseResource {
|
|
|
2209
2299
|
* `null`), rendered `pages`, and `artifacts`. `decline_reason` is returned
|
|
2210
2300
|
* only when the access token belongs to the document creator.
|
|
2211
2301
|
*
|
|
2302
|
+
* `expand: ['envelope_id']` adds the envelope the document is in and
|
|
2303
|
+
* `expand: ['envelope']` its `{ id, name }` (each `null` outside one).
|
|
2304
|
+
*
|
|
2212
2305
|
* @param documentId - The document to fetch.
|
|
2306
|
+
* @param options - `expand`: `envelope_id` and/or `envelope`.
|
|
2213
2307
|
* @returns The document. Response shape (once `metadata_ready`):
|
|
2214
2308
|
* ```jsonc
|
|
2215
2309
|
* {
|
|
@@ -2238,30 +2332,38 @@ var DocumentResource = class extends BaseResource {
|
|
|
2238
2332
|
* "download_url": "https://…/documents/103ad216…/pages/103ad216…/download"
|
|
2239
2333
|
* }
|
|
2240
2334
|
* ],
|
|
2335
|
+
* "has_contract": false,
|
|
2336
|
+
* "envelope_id": null, // with expand: ['envelope_id']
|
|
2337
|
+
* "envelope": null, // with expand: ['envelope']
|
|
2241
2338
|
* "created_at": "2026-07-19T17:24:43Z",
|
|
2242
2339
|
* "updated_at": "2026-07-19T17:24:46Z"
|
|
2243
2340
|
* }
|
|
2244
2341
|
* ```
|
|
2245
|
-
* @throws {ValidationError} If `documentId` is missing.
|
|
2246
|
-
* @throws {ApiError} `
|
|
2342
|
+
* @throws {ValidationError} If `documentId` is missing or `expand` is unknown.
|
|
2343
|
+
* @throws {ApiError} `403` when a role or OAuth scope refuses it, `404` if the
|
|
2344
|
+
* document does not exist.
|
|
2247
2345
|
*
|
|
2248
2346
|
* @example
|
|
2249
2347
|
* ```ts
|
|
2250
|
-
* const doc = await client.documents.details('103ad216846e6b90710cb9acef59'
|
|
2251
|
-
*
|
|
2348
|
+
* const doc = await client.documents.details('103ad216846e6b90710cb9acef59', {
|
|
2349
|
+
* expand: ['envelope'],
|
|
2350
|
+
* });
|
|
2351
|
+
* console.log(doc.status, doc.envelope?.name);
|
|
2252
2352
|
* ```
|
|
2253
2353
|
*/
|
|
2254
|
-
async details(documentId) {
|
|
2354
|
+
async details(documentId, options = {}) {
|
|
2255
2355
|
const id = this.requireId(documentId, "Document ID");
|
|
2256
|
-
return this.fetchDetails(id);
|
|
2257
|
-
}
|
|
2258
|
-
fetchDetails(id, signal) {
|
|
2356
|
+
return this.fetchDetails(id, void 0, options);
|
|
2357
|
+
}
|
|
2358
|
+
fetchDetails(id, signal, options = {}) {
|
|
2359
|
+
assertRecord(options, "document details options");
|
|
2360
|
+
const params = expandParam(options.expand, DETAIL_EXPANSIONS);
|
|
2361
|
+
const config = {};
|
|
2362
|
+
if (signal) config.signal = signal;
|
|
2363
|
+
if (params.expand) config.params = params;
|
|
2259
2364
|
return this.call(
|
|
2260
2365
|
"Failed to fetch document details",
|
|
2261
|
-
() => this.http.get(
|
|
2262
|
-
`/documents/${this.pathSegment(id, "Document ID")}`,
|
|
2263
|
-
signal ? { signal } : void 0
|
|
2264
|
-
)
|
|
2366
|
+
() => this.http.get(`/documents/${this.pathSegment(id, "Document ID")}`, config)
|
|
2265
2367
|
);
|
|
2266
2368
|
}
|
|
2267
2369
|
/**
|
|
@@ -2269,18 +2371,19 @@ var DocumentResource = class extends BaseResource {
|
|
|
2269
2371
|
* (`GET /documents/{documentId}`).
|
|
2270
2372
|
*
|
|
2271
2373
|
* @param documentId - The document to fetch.
|
|
2374
|
+
* @param options - `expand`, as on {@link DocumentResource.details}.
|
|
2272
2375
|
* @returns The document details (see {@link DocumentResource.details} for
|
|
2273
2376
|
* the response shape).
|
|
2274
2377
|
* @throws {ValidationError} If `documentId` is missing.
|
|
2275
|
-
* @throws {ApiError} `
|
|
2378
|
+
* @throws {ApiError} `403` or `404`, as on {@link DocumentResource.details}.
|
|
2276
2379
|
*
|
|
2277
2380
|
* @example
|
|
2278
2381
|
* ```ts
|
|
2279
2382
|
* const doc = await client.documents.get('103ad216846e6b90710cb9acef59');
|
|
2280
2383
|
* ```
|
|
2281
2384
|
*/
|
|
2282
|
-
async get(documentId) {
|
|
2283
|
-
return this.details(documentId);
|
|
2385
|
+
async get(documentId, options = {}) {
|
|
2386
|
+
return this.details(documentId, options);
|
|
2284
2387
|
}
|
|
2285
2388
|
/**
|
|
2286
2389
|
* Poll {@link DocumentResource.details} until the document reaches a ready
|
|
@@ -2394,10 +2497,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
2394
2497
|
* Download the document thumbnail image
|
|
2395
2498
|
* (`GET /documents/{documentId}/thumbnail`).
|
|
2396
2499
|
*
|
|
2500
|
+
* `artifact: 'certificated'` renders it as it is in the signed document.
|
|
2501
|
+
*
|
|
2397
2502
|
* @param documentId - The document whose thumbnail to fetch.
|
|
2398
|
-
* @
|
|
2399
|
-
* @
|
|
2400
|
-
* @throws {
|
|
2503
|
+
* @param options - `artifact: 'certificated'` for the signed render.
|
|
2504
|
+
* @returns A {@link Buffer} of the thumbnail image bytes (`image/*`).
|
|
2505
|
+
* @throws {ValidationError} If `documentId` is missing or `artifact` is unknown.
|
|
2506
|
+
* @throws {ApiError} `404` if the document, its thumbnail, or (with
|
|
2507
|
+
* `certificated`) its certification does not exist; `503` while the signed
|
|
2508
|
+
* render is still being produced — wait `rateLimit.retryAfter` seconds.
|
|
2401
2509
|
*
|
|
2402
2510
|
* @example
|
|
2403
2511
|
* ```ts
|
|
@@ -2405,28 +2513,29 @@ var DocumentResource = class extends BaseResource {
|
|
|
2405
2513
|
* await fs.promises.writeFile('thumb.jpg', thumb);
|
|
2406
2514
|
* ```
|
|
2407
2515
|
*/
|
|
2408
|
-
async thumbnail(documentId) {
|
|
2516
|
+
async thumbnail(documentId, options = {}) {
|
|
2409
2517
|
const id = this.requireId(documentId, "Document ID");
|
|
2518
|
+
const config = renderConfig(options);
|
|
2410
2519
|
return this.callBinary(
|
|
2411
2520
|
"Failed to download document thumbnail",
|
|
2412
|
-
() => this.http.get(
|
|
2413
|
-
`/documents/${this.pathSegment(id, "Document ID")}/thumbnail`,
|
|
2414
|
-
{ responseType: "arraybuffer" }
|
|
2415
|
-
)
|
|
2521
|
+
() => this.http.get(`/documents/${this.pathSegment(id, "Document ID")}/thumbnail`, config)
|
|
2416
2522
|
);
|
|
2417
2523
|
}
|
|
2418
2524
|
/**
|
|
2419
|
-
* Download a single rendered page
|
|
2525
|
+
* Download a single rendered page image
|
|
2420
2526
|
* (`GET /documents/{documentId}/pages/{pageId}/download`).
|
|
2421
2527
|
*
|
|
2422
2528
|
* The `pageId` comes from a page's `id` in {@link DocumentResource.details}
|
|
2423
|
-
* or {@link DocumentResource.list} (`pages[].id`).
|
|
2529
|
+
* or {@link DocumentResource.list} (`pages[].id`). `artifact: 'certificated'`
|
|
2530
|
+
* renders the page as it is in the signed document.
|
|
2424
2531
|
*
|
|
2425
2532
|
* @param documentId - The document the page belongs to.
|
|
2426
2533
|
* @param pageId - The page to download.
|
|
2427
|
-
* @
|
|
2428
|
-
* @
|
|
2429
|
-
* @throws {
|
|
2534
|
+
* @param options - `artifact: 'certificated'` for the signed render.
|
|
2535
|
+
* @returns A {@link Buffer} of the page image bytes (`image/*`).
|
|
2536
|
+
* @throws {ValidationError} If `documentId` or `pageId` is missing, or `artifact` is unknown.
|
|
2537
|
+
* @throws {ApiError} `404` if the document or page does not exist (or, with
|
|
2538
|
+
* `certificated`, is not certified); `503` while the signed render is pending.
|
|
2430
2539
|
*
|
|
2431
2540
|
* @example
|
|
2432
2541
|
* ```ts
|
|
@@ -2435,14 +2544,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
2435
2544
|
* await fs.promises.writeFile('page-1.jpg', page);
|
|
2436
2545
|
* ```
|
|
2437
2546
|
*/
|
|
2438
|
-
async downloadPage(documentId, pageId) {
|
|
2547
|
+
async downloadPage(documentId, pageId, options = {}) {
|
|
2439
2548
|
const docId = this.requireId(documentId, "Document ID");
|
|
2440
2549
|
const pid = this.requireId(pageId, "Page ID");
|
|
2550
|
+
const config = renderConfig(options);
|
|
2441
2551
|
return this.callBinary(
|
|
2442
2552
|
"Failed to download page",
|
|
2443
2553
|
() => this.http.get(
|
|
2444
2554
|
`/documents/${this.pathSegment(docId, "Document ID")}/pages/${this.pathSegment(pid, "Page ID")}/download`,
|
|
2445
|
-
|
|
2555
|
+
config
|
|
2446
2556
|
)
|
|
2447
2557
|
);
|
|
2448
2558
|
}
|
|
@@ -2459,7 +2569,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2459
2569
|
* @param documentId - The document whose activity log to fetch.
|
|
2460
2570
|
* @param params - Optional pagination and sorting parameters.
|
|
2461
2571
|
* @param params.page - Page number, starting at 1.
|
|
2462
|
-
* @param params.per-page - Entries per page (
|
|
2572
|
+
* @param params.per-page - Entries per page (default 20, at most 50; a larger value answers 50).
|
|
2463
2573
|
* @param params.per_page - Alias for `per-page`; explicit `per-page` wins.
|
|
2464
2574
|
* @param params.sort - `-id` (default, newest first) or `id` (oldest first).
|
|
2465
2575
|
* @returns The requested page of activity entries, or `[]`:
|
|
@@ -2489,7 +2599,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2489
2599
|
* @example
|
|
2490
2600
|
* ```ts
|
|
2491
2601
|
* const events = await client.documents.activities('doc-1', {
|
|
2492
|
-
* page: 2, 'per-page':
|
|
2602
|
+
* page: 2, 'per-page': 50, sort: 'id',
|
|
2493
2603
|
* });
|
|
2494
2604
|
* console.log(events.map((e) => e.event));
|
|
2495
2605
|
* ```
|
|
@@ -2509,7 +2619,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2509
2619
|
* @param documentId - The document whose activity log to fetch.
|
|
2510
2620
|
* @param params - Optional pagination and sorting parameters.
|
|
2511
2621
|
* @param params.page - Page number, starting at 1.
|
|
2512
|
-
* @param params.per-page - Entries per page (
|
|
2622
|
+
* @param params.per-page - Entries per page (default 20, at most 50; a larger value answers 50).
|
|
2513
2623
|
* @param params.per_page - Alias for `per-page`; explicit `per-page` wins.
|
|
2514
2624
|
* @param params.sort - `-id` (default, newest first) or `id` (oldest first).
|
|
2515
2625
|
* @returns Activity entries and pagination metadata when the server supplies it:
|
|
@@ -2550,13 +2660,16 @@ var DocumentResource = class extends BaseResource {
|
|
|
2550
2660
|
* Only documents in a deletable status can be removed — the API returns
|
|
2551
2661
|
* `400` while the document is still `uploading` / `metadata_processing`
|
|
2552
2662
|
* (await {@link DocumentResource.waitUntilReady} first) or once it has been
|
|
2553
|
-
* certificated.
|
|
2663
|
+
* certificated. Deleting a `pending_signature` or `pending_identity_review`
|
|
2664
|
+
* document cancels it and notifies its signers. A document of an envelope
|
|
2665
|
+
* with an open document cannot be deleted on its own: cancel the envelope.
|
|
2554
2666
|
*
|
|
2555
2667
|
* @param documentId - The document to delete.
|
|
2556
2668
|
* @returns Nothing; resolves when the document is deleted.
|
|
2557
2669
|
* @throws {ValidationError} If `documentId` is missing.
|
|
2558
2670
|
* @throws {ApiError} `400` if the document is not in a deletable status;
|
|
2559
|
-
* `404` if it does not exist
|
|
2671
|
+
* `403` when a role or OAuth scope refuses it; `404` if it does not exist;
|
|
2672
|
+
* `409` (`EnvelopeOpen`) while its envelope has an open document.
|
|
2560
2673
|
*
|
|
2561
2674
|
* @example
|
|
2562
2675
|
* ```ts
|
|
@@ -2861,6 +2974,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2861
2974
|
if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag.trim()))) {
|
|
2862
2975
|
throw new ValidationError("tags must be an array of non-empty tag names");
|
|
2863
2976
|
}
|
|
2977
|
+
assertCreditCeiling(options.max_total_credits);
|
|
2978
|
+
const config = idempotencyConfig(options.idempotencyKey);
|
|
2864
2979
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
2865
2980
|
const accId = this.accountId(accountId);
|
|
2866
2981
|
const body = {
|
|
@@ -2871,12 +2986,14 @@ var DocumentResource = class extends BaseResource {
|
|
|
2871
2986
|
if (options.expires_at !== void 0) body["expires_at"] = options.expires_at;
|
|
2872
2987
|
if (editorFields !== void 0) body["editor_fields"] = editorFields;
|
|
2873
2988
|
if (options.tags !== void 0) body["tags"] = [...options.tags];
|
|
2989
|
+
if (options.max_total_credits !== void 0) body["max_total_credits"] = options.max_total_credits;
|
|
2874
2990
|
this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
|
|
2875
2991
|
return this.call(
|
|
2876
2992
|
"Failed to create document from template",
|
|
2877
2993
|
() => this.http.post(
|
|
2878
2994
|
`/accounts/${this.pathSegment(accId, "Account ID")}/templates/${this.pathSegment(tmplId, "Template ID")}/documents`,
|
|
2879
|
-
body
|
|
2995
|
+
body,
|
|
2996
|
+
config
|
|
2880
2997
|
)
|
|
2881
2998
|
);
|
|
2882
2999
|
}
|
|
@@ -3010,13 +3127,14 @@ var DocumentResource = class extends BaseResource {
|
|
|
3010
3127
|
* { "code": "uploaded", "deletable": false },
|
|
3011
3128
|
* { "code": "metadata_processing", "deletable": false },
|
|
3012
3129
|
* { "code": "metadata_ready", "deletable": true },
|
|
3013
|
-
* { "code": "
|
|
3014
|
-
* { "code": "expired", "deletable": false },
|
|
3130
|
+
* { "code": "expired", "deletable": true },
|
|
3015
3131
|
* { "code": "certificating", "deletable": false },
|
|
3016
3132
|
* { "code": "certificated", "deletable": false },
|
|
3017
|
-
* { "code": "rejected_by_signer", "deletable":
|
|
3018
|
-
* { "code": "
|
|
3019
|
-
* { "code": "
|
|
3133
|
+
* { "code": "rejected_by_signer", "deletable": true },
|
|
3134
|
+
* { "code": "pending_signature", "deletable": true },
|
|
3135
|
+
* { "code": "pending_identity_review", "deletable": true }, // deleting cancels and notifies signers
|
|
3136
|
+
* { "code": "rejected_by_user", "deletable": true },
|
|
3137
|
+
* { "code": "failed", "deletable": true }
|
|
3020
3138
|
* ]
|
|
3021
3139
|
* ```
|
|
3022
3140
|
* @throws {ApiError} If the API rejects the request.
|
|
@@ -3245,11 +3363,21 @@ function normaliseTemplateSigners(signers) {
|
|
|
3245
3363
|
if (signer.notification_methods !== void 0) {
|
|
3246
3364
|
projected.notification_methods = [...signer.notification_methods];
|
|
3247
3365
|
}
|
|
3366
|
+
if (signer.embedded !== void 0) projected.embedded = signer.embedded;
|
|
3248
3367
|
if (signer.step !== void 0) projected.step = signer.step;
|
|
3249
3368
|
return projected;
|
|
3250
3369
|
});
|
|
3251
3370
|
return normalised;
|
|
3252
3371
|
}
|
|
3372
|
+
var DETAIL_EXPANSIONS = /* @__PURE__ */ new Set(["envelope_id", "envelope"]);
|
|
3373
|
+
function renderConfig(options) {
|
|
3374
|
+
assertRecord(options, "render options");
|
|
3375
|
+
if (options.artifact === void 0) return { responseType: "arraybuffer" };
|
|
3376
|
+
if (options.artifact !== "certificated") {
|
|
3377
|
+
throw new ValidationError("artifact must be certificated when given");
|
|
3378
|
+
}
|
|
3379
|
+
return { responseType: "arraybuffer", params: { artifact: options.artifact } };
|
|
3380
|
+
}
|
|
3253
3381
|
function normaliseTemplateEditorFields(fields) {
|
|
3254
3382
|
if (!Array.isArray(fields)) {
|
|
3255
3383
|
throw new ValidationError("editor_fields must be an array");
|
|
@@ -3530,7 +3658,7 @@ var SignerResource = class extends BaseResource {
|
|
|
3530
3658
|
"Failed to update signer",
|
|
3531
3659
|
() => this.http.put(
|
|
3532
3660
|
`/accounts/${this.pathSegment(id, "Account ID")}/signers/${this.pathSegment(sid, "Signer ID")}`,
|
|
3533
|
-
normaliseSignerPayload(payload)
|
|
3661
|
+
{ ...normaliseSignerPayload(payload), ...clearedContacts(payload) }
|
|
3534
3662
|
)
|
|
3535
3663
|
);
|
|
3536
3664
|
}
|
|
@@ -3656,13 +3784,19 @@ function validateUpdateSignerPayload(payload) {
|
|
|
3656
3784
|
if (payload.full_name !== void 0 && (typeof payload.full_name !== "string" || !payload.full_name.trim())) {
|
|
3657
3785
|
throw new ValidationError("full_name cannot be empty");
|
|
3658
3786
|
}
|
|
3659
|
-
if (payload.email !== void 0 && !isEmail(payload.email)) {
|
|
3787
|
+
if (payload.email !== void 0 && !isClear(payload.email) && !isEmail(payload.email)) {
|
|
3660
3788
|
throw new ValidationError("Invalid email address", { email: payload.email });
|
|
3661
3789
|
}
|
|
3662
|
-
const phone = payload
|
|
3663
|
-
validateOptionalPhone(phone);
|
|
3790
|
+
const phone = updatePhone(payload);
|
|
3791
|
+
if (!isClear(phone)) validateOptionalPhone(phone);
|
|
3664
3792
|
validateOptionalDigits(payload.cpf, "cpf");
|
|
3665
|
-
validateOptionalDigits(payload.government_id, "government_id");
|
|
3793
|
+
if (!isClear(payload.government_id)) validateOptionalDigits(payload.government_id, "government_id");
|
|
3794
|
+
}
|
|
3795
|
+
function isClear(value) {
|
|
3796
|
+
return value === null || value === "";
|
|
3797
|
+
}
|
|
3798
|
+
function updatePhone(payload) {
|
|
3799
|
+
return payload.whatsapp_phone_number !== void 0 ? payload.whatsapp_phone_number : payload.phone;
|
|
3666
3800
|
}
|
|
3667
3801
|
function validateOptionalDigits(value, field) {
|
|
3668
3802
|
if (value === void 0) return;
|
|
@@ -3693,6 +3827,18 @@ function normaliseSignerPayload(payload) {
|
|
|
3693
3827
|
}
|
|
3694
3828
|
return cleanParams(normalised);
|
|
3695
3829
|
}
|
|
3830
|
+
function clearedContacts(payload) {
|
|
3831
|
+
const cleared = {};
|
|
3832
|
+
const candidates = {
|
|
3833
|
+
email: payload.email,
|
|
3834
|
+
whatsapp_phone_number: updatePhone(payload),
|
|
3835
|
+
government_id: payload.government_id
|
|
3836
|
+
};
|
|
3837
|
+
for (const [key, value] of Object.entries(candidates)) {
|
|
3838
|
+
if (isClear(value)) cleared[key] = value;
|
|
3839
|
+
}
|
|
3840
|
+
return cleared;
|
|
3841
|
+
}
|
|
3696
3842
|
|
|
3697
3843
|
// src/support/stats.ts
|
|
3698
3844
|
var MONTH_RE = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
@@ -3813,7 +3959,13 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3813
3959
|
/**
|
|
3814
3960
|
* Fetch a single workspace (`GET /accounts/{accountId}`).
|
|
3815
3961
|
*
|
|
3962
|
+
* `expand: 'signing_features'` adds which signing methods the plan allows
|
|
3963
|
+
* (OAuth: `account:read`). A `false` feature makes creating or estimating an
|
|
3964
|
+
* assignment, template document or envelope with that method answer `403`
|
|
3965
|
+
* (`PlanRestricted`); check it before offering the method.
|
|
3966
|
+
*
|
|
3816
3967
|
* @param accountId - The workspace to fetch.
|
|
3968
|
+
* @param options - `expand: 'signing_features'`.
|
|
3817
3969
|
* @returns The workspace. `primary_color` / `secondary_color` are `null`
|
|
3818
3970
|
* until brand colours are set (6-char hex, no `#`, when present):
|
|
3819
3971
|
* ```jsonc
|
|
@@ -3826,22 +3978,154 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3826
3978
|
* "notification_sender_type": "User",
|
|
3827
3979
|
* "roles": ["owner"],
|
|
3828
3980
|
* "is_delete_allowed": true,
|
|
3981
|
+
* "limits": { "webhook_endpoints": 3 },
|
|
3982
|
+
* "signing_features": { // only with expand: 'signing_features'
|
|
3983
|
+
* "DigitalCertificate": true,
|
|
3984
|
+
* "VerificationIdDocumentFaceMatchBasic": true,
|
|
3985
|
+
* "WhatsappNotification": true,
|
|
3986
|
+
* "VerificationBypass": false,
|
|
3987
|
+
* "Embed": true
|
|
3988
|
+
* },
|
|
3829
3989
|
* "created_at": "2026-05-12T18:05:11Z"
|
|
3830
3990
|
* }
|
|
3831
3991
|
* ```
|
|
3832
|
-
* @throws {ValidationError} If `accountId` is missing.
|
|
3833
|
-
* @throws {ApiError} `
|
|
3992
|
+
* @throws {ValidationError} If `accountId` is missing or `expand` is unknown.
|
|
3993
|
+
* @throws {ApiError} `403` for another workspace's token, `404` if the
|
|
3994
|
+
* workspace does not exist.
|
|
3834
3995
|
*
|
|
3835
3996
|
* @example
|
|
3836
3997
|
* ```ts
|
|
3837
|
-
* const ws = await client.workspaces.get('acc_example');
|
|
3998
|
+
* const ws = await client.workspaces.get('acc_example', { expand: 'signing_features' });
|
|
3999
|
+
* if (ws.signing_features?.Embed) await client.embed.listOrigins();
|
|
3838
4000
|
* ```
|
|
3839
4001
|
*/
|
|
3840
|
-
async get(accountId) {
|
|
4002
|
+
async get(accountId, options = {}) {
|
|
3841
4003
|
const id = this.requireId(accountId, "Account ID");
|
|
4004
|
+
assertRecord(options, "workspace options");
|
|
4005
|
+
if (options.expand !== void 0 && options.expand !== "signing_features") {
|
|
4006
|
+
throw new ValidationError("expand must be signing_features");
|
|
4007
|
+
}
|
|
4008
|
+
const config = options.expand === void 0 ? {} : { params: { expand: options.expand } };
|
|
3842
4009
|
return this.call(
|
|
3843
4010
|
"Failed to fetch workspace",
|
|
3844
|
-
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}
|
|
4011
|
+
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}`, config)
|
|
4012
|
+
);
|
|
4013
|
+
}
|
|
4014
|
+
/**
|
|
4015
|
+
* Read the workspace's plan and balances (`GET /accounts/{accountId}/usage`).
|
|
4016
|
+
*
|
|
4017
|
+
* For a plan and credit meter; prices and payments are not included. Not
|
|
4018
|
+
* available to third-party OAuth applications (`403`), whatever their scopes.
|
|
4019
|
+
*
|
|
4020
|
+
* @param accountId - The workspace to read.
|
|
4021
|
+
* @returns The plan meter:
|
|
4022
|
+
* ```jsonc
|
|
4023
|
+
* {
|
|
4024
|
+
* "plan": "Pro", // null without a current plan
|
|
4025
|
+
* "documents_renewal_date": "2026-12-11",
|
|
4026
|
+
* "balances": {
|
|
4027
|
+
* "documents": { "balance": 97, "limit": 100, "spent": 3 },
|
|
4028
|
+
* "credits": { "balance": 12.5, "limit": null, "spent": 0.9 } // null: unlimited / not cycle-limited
|
|
4029
|
+
* }
|
|
4030
|
+
* }
|
|
4031
|
+
* ```
|
|
4032
|
+
* @throws {ValidationError} If `accountId` is missing.
|
|
4033
|
+
* @throws {ApiError} `403` for an OAuth application token, `404` for an unknown workspace.
|
|
4034
|
+
*
|
|
4035
|
+
* @example
|
|
4036
|
+
* ```ts
|
|
4037
|
+
* const { balances } = await client.workspaces.getUsage('acc_example');
|
|
4038
|
+
* ```
|
|
4039
|
+
*/
|
|
4040
|
+
async getUsage(accountId) {
|
|
4041
|
+
const id = this.requireId(accountId, "Account ID");
|
|
4042
|
+
return this.call(
|
|
4043
|
+
"Failed to fetch account usage",
|
|
4044
|
+
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}/usage`)
|
|
4045
|
+
);
|
|
4046
|
+
}
|
|
4047
|
+
/**
|
|
4048
|
+
* Read which document alerts the workspace sends
|
|
4049
|
+
* (`GET /accounts/{accountId}/notification-policy`).
|
|
4050
|
+
*
|
|
4051
|
+
* Every member can read it; `editable` says whether the caller (an owner)
|
|
4052
|
+
* can change it. Not available to third-party OAuth applications.
|
|
4053
|
+
*
|
|
4054
|
+
* @param accountId - The workspace to read.
|
|
4055
|
+
* @returns The policy; every event key is present:
|
|
4056
|
+
* ```jsonc
|
|
4057
|
+
* {
|
|
4058
|
+
* "editable": true,
|
|
4059
|
+
* "owners_receive_all": false, // owners also get push alerts for members' documents
|
|
4060
|
+
* "events": {
|
|
4061
|
+
* "DocumentCompleted": true, "SignerDeclined": true, "DocumentCancelled": true,
|
|
4062
|
+
* "DocumentAboutToExpire": true, "DocumentExpired": true, "DocumentExpirationReset": true,
|
|
4063
|
+
* "DocumentProcessingFailed": true, "TemplateProcessingFailed": true, "SignerWhatsappFailed": true,
|
|
4064
|
+
* "ContractRenewalNotice": true, "ContractExpiring": true, "ContractExpired": true,
|
|
4065
|
+
* "ContractRenewed": true, "SignerViewed": true, "SignerSigned": true,
|
|
4066
|
+
* "SignerIdentityReviewRequired": true
|
|
4067
|
+
* }
|
|
4068
|
+
* }
|
|
4069
|
+
* ```
|
|
4070
|
+
* @throws {ValidationError} If `accountId` is missing.
|
|
4071
|
+
* @throws {ApiError} `403` for an OAuth application token.
|
|
4072
|
+
*
|
|
4073
|
+
* @example
|
|
4074
|
+
* ```ts
|
|
4075
|
+
* const policy = await client.workspaces.getNotificationPolicy('acc_example');
|
|
4076
|
+
* ```
|
|
4077
|
+
*/
|
|
4078
|
+
async getNotificationPolicy(accountId) {
|
|
4079
|
+
const id = this.requireId(accountId, "Account ID");
|
|
4080
|
+
return this.call(
|
|
4081
|
+
"Failed to fetch notification policy",
|
|
4082
|
+
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}/notification-policy`)
|
|
4083
|
+
);
|
|
4084
|
+
}
|
|
4085
|
+
/**
|
|
4086
|
+
* Change which document alerts the workspace sends
|
|
4087
|
+
* (`PUT /accounts/{accountId}/notification-policy`).
|
|
4088
|
+
*
|
|
4089
|
+
* Owners only. Merges what is sent: an event set to `false` reaches nobody
|
|
4090
|
+
* in the workspace on any channel, whatever each member's preferences. The
|
|
4091
|
+
* identity-review e-mail is always sent, because the signer cannot continue
|
|
4092
|
+
* without it.
|
|
4093
|
+
*
|
|
4094
|
+
* @param accountId - The workspace to change.
|
|
4095
|
+
* @param payload - `events` keys to change and/or `owners_receive_all`.
|
|
4096
|
+
* @returns The full policy, as {@link WorkspaceResource.getNotificationPolicy} returns.
|
|
4097
|
+
* @throws {ValidationError} If nothing would change or a value is not a boolean.
|
|
4098
|
+
* @throws {ApiError} `400` for an unknown event code, `403` for a non-owner or
|
|
4099
|
+
* an OAuth application token.
|
|
4100
|
+
*
|
|
4101
|
+
* @example
|
|
4102
|
+
* ```ts
|
|
4103
|
+
* await client.workspaces.updateNotificationPolicy('acc_example', {
|
|
4104
|
+
* events: { SignerViewed: false },
|
|
4105
|
+
* owners_receive_all: true,
|
|
4106
|
+
* });
|
|
4107
|
+
* ```
|
|
4108
|
+
*/
|
|
4109
|
+
async updateNotificationPolicy(accountId, payload) {
|
|
4110
|
+
const id = this.requireId(accountId, "Account ID");
|
|
4111
|
+
assertRecord(payload, "notification policy");
|
|
4112
|
+
const body = {};
|
|
4113
|
+
if (payload.events !== void 0) {
|
|
4114
|
+
assertBooleanMap(payload.events, "events");
|
|
4115
|
+
body["events"] = { ...payload.events };
|
|
4116
|
+
}
|
|
4117
|
+
if (payload.owners_receive_all !== void 0) {
|
|
4118
|
+
if (typeof payload.owners_receive_all !== "boolean") {
|
|
4119
|
+
throw new ValidationError("owners_receive_all must be a boolean");
|
|
4120
|
+
}
|
|
4121
|
+
body["owners_receive_all"] = payload.owners_receive_all;
|
|
4122
|
+
}
|
|
4123
|
+
if (Object.keys(body).length === 0) {
|
|
4124
|
+
throw new ValidationError("notification policy update must change events or owners_receive_all");
|
|
4125
|
+
}
|
|
4126
|
+
return this.call(
|
|
4127
|
+
"Failed to update notification policy",
|
|
4128
|
+
() => this.http.put(`/accounts/${this.pathSegment(id, "Account ID")}/notification-policy`, body)
|
|
3845
4129
|
);
|
|
3846
4130
|
}
|
|
3847
4131
|
/**
|
|
@@ -3850,13 +4134,13 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3850
4134
|
* Request body/query: none.
|
|
3851
4135
|
*
|
|
3852
4136
|
* @param accountId - Account whose public branding should be returned.
|
|
3853
|
-
* @returns The unwrapped theme:
|
|
4137
|
+
* @returns The unwrapped theme. Colours fall back to the platform default:
|
|
3854
4138
|
* ```jsonc
|
|
3855
4139
|
* {
|
|
3856
4140
|
* "account_name": "Acme Inc.",
|
|
3857
|
-
* "primary_color": "aabbcc",
|
|
3858
|
-
* "secondary_color": "112233",
|
|
3859
|
-
* "logo": "https://api.assinafy.com.br/v1/accounts/account-id/logo"
|
|
4141
|
+
* "primary_color": "aabbcc", // button background
|
|
4142
|
+
* "secondary_color": "112233", // button text
|
|
4143
|
+
* "logo": "https://api.assinafy.com.br/v1/accounts/account-id/logo" // null without a logo
|
|
3860
4144
|
* }
|
|
3861
4145
|
* ```
|
|
3862
4146
|
* @throws {ValidationError} If `accountId` is empty.
|
|
@@ -4770,31 +5054,98 @@ var WebhookResource = class extends BaseResource {
|
|
|
4770
5054
|
/**
|
|
4771
5055
|
* Replace an endpoint's signing secret and return the new one
|
|
4772
5056
|
* (`POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret/rotate`).
|
|
4773
|
-
*
|
|
4774
|
-
*
|
|
4775
|
-
*
|
|
5057
|
+
*
|
|
5058
|
+
* Without `keep_previous` the old secret stops at once: update the receiver
|
|
5059
|
+
* immediately. With `keep_previous: true` both secrets sign deliveries for
|
|
5060
|
+
* 24 hours (each delivery carries one `v1,` entry per secret, which
|
|
5061
|
+
* `webhookVerifier.verifySignature()` already accepts), so the receiver can
|
|
5062
|
+
* switch without dropping events; rotating again ends the overlap. OAuth
|
|
5063
|
+
* tokens need the `webhooks:write` scope.
|
|
4776
5064
|
*
|
|
4777
5065
|
* @param endpointId - The endpoint ID.
|
|
4778
5066
|
* @param accountId - Override the client's default account ID.
|
|
5067
|
+
* @param options - `keep_previous`: keep the old secret signing for 24 hours.
|
|
4779
5068
|
* @returns The new secret:
|
|
4780
5069
|
* ```jsonc
|
|
4781
|
-
* {
|
|
5070
|
+
* {
|
|
5071
|
+
* "secret": "whsec_bmV3LWtleS1iYXNlNjQtZW5jb2RlZA==",
|
|
5072
|
+
* "previous_secret_expires_at": "2026-11-12T14:00:00Z" // only with keep_previous: true
|
|
5073
|
+
* }
|
|
4782
5074
|
* ```
|
|
4783
|
-
* @throws {ValidationError} If `endpointId` is empty
|
|
4784
|
-
* available.
|
|
5075
|
+
* @throws {ValidationError} If `endpointId` is empty, no account ID is
|
|
5076
|
+
* available, or `keep_previous` is not a boolean.
|
|
4785
5077
|
* @throws {ApiError} `400` when signing is disabled on the endpoint; `404`
|
|
4786
5078
|
* if it does not exist.
|
|
4787
5079
|
*
|
|
4788
5080
|
* @example
|
|
4789
5081
|
* ```ts
|
|
4790
|
-
* const { secret } = await client.webhooks.rotateEndpointSecret(endpoint.id
|
|
5082
|
+
* const { secret } = await client.webhooks.rotateEndpointSecret(endpoint.id, undefined, {
|
|
5083
|
+
* keep_previous: true,
|
|
5084
|
+
* });
|
|
4791
5085
|
* await secretStore.put('assinafy-webhook-secret', secret);
|
|
4792
5086
|
* ```
|
|
4793
5087
|
*/
|
|
4794
|
-
async rotateEndpointSecret(endpointId, accountId) {
|
|
5088
|
+
async rotateEndpointSecret(endpointId, accountId, options = {}) {
|
|
5089
|
+
assertRecord(options, "rotation options");
|
|
5090
|
+
if (options.keep_previous !== void 0 && typeof options.keep_previous !== "boolean") {
|
|
5091
|
+
throw new ValidationError("keep_previous must be a boolean");
|
|
5092
|
+
}
|
|
4795
5093
|
const path2 = `${this.endpointPath(endpointId, accountId)}/secret/rotate`;
|
|
5094
|
+
const body = options.keep_previous === void 0 ? void 0 : { keep_previous: options.keep_previous };
|
|
4796
5095
|
this.logger.info("Rotating webhook endpoint secret");
|
|
4797
|
-
return this.call("Failed to rotate webhook endpoint secret", () => this.http.post(path2));
|
|
5096
|
+
return this.call("Failed to rotate webhook endpoint secret", () => this.http.post(path2, body));
|
|
5097
|
+
}
|
|
5098
|
+
/**
|
|
5099
|
+
* Send the endpoint one `webhook_test` event now
|
|
5100
|
+
* (`POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/test`).
|
|
5101
|
+
*
|
|
5102
|
+
* Signed and sent like any delivery, to this endpoint only, also while it is
|
|
5103
|
+
* paused or inactive; it neither lifts nor counts toward a pause. The
|
|
5104
|
+
* endpoint has 10 seconds to answer. The event's `payload` and `origin` are
|
|
5105
|
+
* `null`, and its `subject`/`object` describe the endpoint (never its
|
|
5106
|
+
* secret). Up to 10 tests per user every 10 minutes; OAuth tokens need
|
|
5107
|
+
* `webhooks:write`.
|
|
5108
|
+
*
|
|
5109
|
+
* @param endpointId - The endpoint ID.
|
|
5110
|
+
* @param accountId - Override the client's default account ID.
|
|
5111
|
+
* @returns The delivery attempt, also listed in the delivery history:
|
|
5112
|
+
* ```jsonc
|
|
5113
|
+
* {
|
|
5114
|
+
* "resource": "activity_dispatching_history",
|
|
5115
|
+
* "id": "1052b3c4d5e6f7a8b9c0d1e2f3a4",
|
|
5116
|
+
* "event": "webhook_test",
|
|
5117
|
+
* "activity_id": 8240001,
|
|
5118
|
+
* "endpoint_id": "1052b0e1f2a3b4c5d6e7f8a9b0c1",
|
|
5119
|
+
* "endpoint": "https://hooks.example.com/assinafy",
|
|
5120
|
+
* "payload": { // the event as delivered
|
|
5121
|
+
* "id": 8240001, "event": "webhook_test", "payload": null, "origin": null,
|
|
5122
|
+
* "account_id": "acc_example", "subject": { "type": "ActivityEventSubscription" }
|
|
5123
|
+
* },
|
|
5124
|
+
* "delivered": true,
|
|
5125
|
+
* "webhook_id": "msg_2v9TQ0a7",
|
|
5126
|
+
* "attempt": 1,
|
|
5127
|
+
* "kind": "manual",
|
|
5128
|
+
* "will_retry": false,
|
|
5129
|
+
* "duration_ms": 182,
|
|
5130
|
+
* "http_status": 200,
|
|
5131
|
+
* "response_body": "ok",
|
|
5132
|
+
* "error": null,
|
|
5133
|
+
* "created_at": "2026-11-11T14:00:00Z",
|
|
5134
|
+
* "updated_at": "2026-11-11T14:00:00Z"
|
|
5135
|
+
* }
|
|
5136
|
+
* ```
|
|
5137
|
+
* @throws {ValidationError} If `endpointId` is empty or no account ID is available.
|
|
5138
|
+
* @throws {ApiError} `404` for an unknown endpoint, `429` past 10 tests in 10 minutes.
|
|
5139
|
+
*
|
|
5140
|
+
* @example
|
|
5141
|
+
* ```ts
|
|
5142
|
+
* const attempt = await client.webhooks.testEndpoint(endpoint.id);
|
|
5143
|
+
* if (!attempt.delivered) console.warn(attempt.http_status, attempt.error);
|
|
5144
|
+
* ```
|
|
5145
|
+
*/
|
|
5146
|
+
async testEndpoint(endpointId, accountId) {
|
|
5147
|
+
const path2 = `${this.endpointPath(endpointId, accountId)}/test`;
|
|
5148
|
+
return this.call("Failed to send webhook test delivery", () => this.http.post(path2));
|
|
4798
5149
|
}
|
|
4799
5150
|
endpointsPath(accountId) {
|
|
4800
5151
|
const id = this.pathSegment(this.accountId(accountId), "Account ID");
|
|
@@ -6081,7 +6432,10 @@ var OAuthResource = class extends BaseResource {
|
|
|
6081
6432
|
* `['documents:read', 'documents:write', 'offline_access']`. Ask for the
|
|
6082
6433
|
* minimum: the user approves all of them or none. Add `offline_access` to
|
|
6083
6434
|
* receive a refresh token and `openid` to receive an `id_token`.
|
|
6084
|
-
* `
|
|
6435
|
+
* `account:read` reads the workspace profile, theme, logo, KPIs, webhook
|
|
6436
|
+
* subscription and endpoints, and its signing features; `webhooks:write`
|
|
6437
|
+
* changes the subscription, manages endpoints, re-sends and tests
|
|
6438
|
+
* deliveries, and can obtain a new signing secret (signing on, or rotation).
|
|
6085
6439
|
* @param options.authorizationEndpoint - Skip discovery by supplying the
|
|
6086
6440
|
* endpoint yourself. Defaults to the discovered
|
|
6087
6441
|
* `authorization_endpoint`.
|
|
@@ -6307,6 +6661,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
6307
6661
|
* @throws {OAuthError} `invalid_grant` for a spent, expired, replayed or
|
|
6308
6662
|
* mismatched code; `invalid_client` for a bad `client_id`/`client_secret`;
|
|
6309
6663
|
* `invalid_target` for a `resource` mismatch.
|
|
6664
|
+
* @throws {ApiError} `429` when the caller's IP is rate limited; token calls
|
|
6665
|
+
* are never retried automatically, so wait `rateLimit.retryAfter` seconds.
|
|
6310
6666
|
*
|
|
6311
6667
|
* @example
|
|
6312
6668
|
* ```ts
|
|
@@ -6381,6 +6737,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
6381
6737
|
* @throws {OAuthError} `invalid_grant` when the refresh token was already
|
|
6382
6738
|
* used, expired, or the user reconnected with different permissions — ask
|
|
6383
6739
|
* the user to reconnect. `invalid_client` for bad client credentials.
|
|
6740
|
+
* @throws {ApiError} `429` when the caller's IP is rate limited (not retried
|
|
6741
|
+
* automatically: a replayed refresh token ends the connection).
|
|
6384
6742
|
*
|
|
6385
6743
|
* @example
|
|
6386
6744
|
* ```ts
|
|
@@ -6665,6 +7023,11 @@ function toSearchParams(params) {
|
|
|
6665
7023
|
|
|
6666
7024
|
// src/resources/fields.ts
|
|
6667
7025
|
var FieldsResource = class extends BaseResource {
|
|
7026
|
+
signerHttp;
|
|
7027
|
+
constructor(http, defaultAccountId, logger, publicHttp) {
|
|
7028
|
+
super(http, defaultAccountId, logger);
|
|
7029
|
+
this.signerHttp = withoutCredentials(publicHttp ?? http);
|
|
7030
|
+
}
|
|
6668
7031
|
/**
|
|
6669
7032
|
* Create a field definition (`POST /accounts/{accountId}/fields`).
|
|
6670
7033
|
*
|
|
@@ -6916,9 +7279,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
6916
7279
|
* Validate a single value against a field definition
|
|
6917
7280
|
* (`POST /accounts/{accountId}/fields/{fieldId}/validate`).
|
|
6918
7281
|
*
|
|
6919
|
-
*
|
|
6920
|
-
*
|
|
6921
|
-
*
|
|
7282
|
+
* Without `signerAccessCode` the call uses the workspace credentials. With
|
|
7283
|
+
* it, the code is sent as the `signer-access-code` query on the
|
|
7284
|
+
* credential-free transport, as a custom signing UI does.
|
|
6922
7285
|
*
|
|
6923
7286
|
* Request body (`application/json`):
|
|
6924
7287
|
* ```jsonc
|
|
@@ -6930,9 +7293,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
6930
7293
|
* @param fieldId - The field definition to validate against.
|
|
6931
7294
|
* @param value - The value to check (validated against the field's
|
|
6932
7295
|
* type/regex). Sent as `{ value }` in the request body.
|
|
6933
|
-
* @param options - Account override and optional
|
|
7296
|
+
* @param options - Account override and optional `signerAccessCode`.
|
|
6934
7297
|
* @param options.accountId - Override the client's default workspace.
|
|
6935
|
-
* @param options.signerAccessCode -
|
|
7298
|
+
* @param options.signerAccessCode - Authenticate as the signer instead of the workspace.
|
|
6936
7299
|
* @returns The validation result. Response shape:
|
|
6937
7300
|
* ```jsonc
|
|
6938
7301
|
* {
|
|
@@ -6943,7 +7306,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
6943
7306
|
* ```
|
|
6944
7307
|
* @throws {ValidationError} If `fieldId` or the account ID is missing, or
|
|
6945
7308
|
* `value` is `undefined`.
|
|
6946
|
-
* @throws {ApiError}
|
|
7309
|
+
* @throws {ApiError} `400` for a malformed request, `403` when the code or
|
|
7310
|
+
* credentials cannot reach the workspace, `404` for a field outside it, `410`
|
|
7311
|
+
* when the signer's access code is closed.
|
|
6947
7312
|
*
|
|
6948
7313
|
* @example
|
|
6949
7314
|
* ```ts
|
|
@@ -6965,7 +7330,7 @@ var FieldsResource = class extends BaseResource {
|
|
|
6965
7330
|
const params = options.signerAccessCode ? { "signer-access-code": options.signerAccessCode } : void 0;
|
|
6966
7331
|
return this.call(
|
|
6967
7332
|
"Failed to validate field value",
|
|
6968
|
-
() => this.
|
|
7333
|
+
() => this.transportFor(options.signerAccessCode).post(
|
|
6969
7334
|
`/accounts/${this.pathSegment(id, "Account ID")}/fields/${this.pathSegment(fid, "Field ID")}/validate`,
|
|
6970
7335
|
{ value },
|
|
6971
7336
|
{ params }
|
|
@@ -6977,9 +7342,8 @@ var FieldsResource = class extends BaseResource {
|
|
|
6977
7342
|
* (`POST /accounts/{accountId}/fields/validate-multiple`).
|
|
6978
7343
|
*
|
|
6979
7344
|
* The request body is the array of `{ field_id, value }` entries itself
|
|
6980
|
-
* (not wrapped in an object).
|
|
6981
|
-
*
|
|
6982
|
-
* {@link FieldsResource.validate}.
|
|
7345
|
+
* (not wrapped in an object). `signerAccessCode` authenticates as described
|
|
7346
|
+
* on {@link FieldsResource.validate}.
|
|
6983
7347
|
*
|
|
6984
7348
|
* Request body (`application/json`):
|
|
6985
7349
|
* ```jsonc
|
|
@@ -6992,9 +7356,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
6992
7356
|
* ```
|
|
6993
7357
|
*
|
|
6994
7358
|
* @param entries - Non-empty array of `{ field_id, value }` pairs.
|
|
6995
|
-
* @param options - Account override and optional
|
|
7359
|
+
* @param options - Account override and optional `signerAccessCode`.
|
|
6996
7360
|
* @param options.accountId - Override the client's default workspace.
|
|
6997
|
-
* @param options.signerAccessCode -
|
|
7361
|
+
* @param options.signerAccessCode - Authenticate as the signer instead of the workspace.
|
|
6998
7362
|
* @returns One validation result per entry. Response shape:
|
|
6999
7363
|
* ```jsonc
|
|
7000
7364
|
* [
|
|
@@ -7003,7 +7367,7 @@ var FieldsResource = class extends BaseResource {
|
|
|
7003
7367
|
* ]
|
|
7004
7368
|
* ```
|
|
7005
7369
|
* @throws {ValidationError} If `entries` is empty or the account ID is missing.
|
|
7006
|
-
* @throws {ApiError}
|
|
7370
|
+
* @throws {ApiError} `400`, `403`, `404` or `410`, as for {@link FieldsResource.validate}.
|
|
7007
7371
|
*
|
|
7008
7372
|
* @example
|
|
7009
7373
|
* ```ts
|
|
@@ -7031,7 +7395,7 @@ var FieldsResource = class extends BaseResource {
|
|
|
7031
7395
|
}));
|
|
7032
7396
|
return this.call(
|
|
7033
7397
|
"Failed to validate field values",
|
|
7034
|
-
() => this.
|
|
7398
|
+
() => this.transportFor(options.signerAccessCode).post(
|
|
7035
7399
|
`/accounts/${this.pathSegment(id, "Account ID")}/fields/validate-multiple`,
|
|
7036
7400
|
body,
|
|
7037
7401
|
{ params }
|
|
@@ -7065,6 +7429,10 @@ var FieldsResource = class extends BaseResource {
|
|
|
7065
7429
|
async listTypes() {
|
|
7066
7430
|
return this.call("Failed to list field types", () => this.http.get("/field-types"));
|
|
7067
7431
|
}
|
|
7432
|
+
/** A signer access code must never travel with the workspace credentials. */
|
|
7433
|
+
transportFor(signerAccessCode) {
|
|
7434
|
+
return signerAccessCode === void 0 ? this.http : this.signerHttp;
|
|
7435
|
+
}
|
|
7068
7436
|
};
|
|
7069
7437
|
function validateFieldPayload(payload) {
|
|
7070
7438
|
if (payload.regex !== void 0 && payload.regex !== null && typeof payload.regex !== "string") {
|
|
@@ -7097,11 +7465,17 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7097
7465
|
* (`GET /signers/{signer_id}/document?signer-access-code=…`).
|
|
7098
7466
|
*
|
|
7099
7467
|
* The signer-side counterpart of {@link DocumentResource.details}, authorised
|
|
7100
|
-
* by the signer's access code rather than the workspace API key.
|
|
7468
|
+
* by the signer's access code rather than the workspace API key. Unlike
|
|
7469
|
+
* {@link SignerDocumentsResource.getAssignment} it does not record a view and
|
|
7470
|
+
* answers before a certificate or identity-check signer confirms their data,
|
|
7471
|
+
* so a link learns its envelope here.
|
|
7101
7472
|
*
|
|
7102
7473
|
* @param signerId - The signer whose current document is fetched.
|
|
7103
7474
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7104
|
-
* @
|
|
7475
|
+
* @param options - `expand: ['envelope']` adds the code's envelope (`{ id, name }`, or `null`).
|
|
7476
|
+
* @returns The {@link ISigningDocument}. Once the code is closed (30 minutes
|
|
7477
|
+
* after the signer is done) only `id`, `name`, `status`, `current_signer`,
|
|
7478
|
+
* `certified_copy` and `envelope` remain, with `is_signer_access_closed: true`:
|
|
7105
7479
|
* ```jsonc
|
|
7106
7480
|
* {
|
|
7107
7481
|
* "resource": "document",
|
|
@@ -7124,26 +7498,38 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7124
7498
|
* { "id": "103acccd5c73...", "number": 1, "height": 1651, "width": 1275,
|
|
7125
7499
|
* "download_url": "https://api.assinafy.com.br/v1/documents/103acccd.../pages/103acccd5c73.../download" }
|
|
7126
7500
|
* ],
|
|
7501
|
+
* "current_signer": {
|
|
7502
|
+
* "id": "19e6b92e7895332ed9708535d8c",
|
|
7503
|
+
* "full_name": "Example Signer",
|
|
7504
|
+
* "email": "signer@example.com",
|
|
7505
|
+
* "verification_method": "Email",
|
|
7506
|
+
* "notification_methods": ["Email"],
|
|
7507
|
+
* "completed": false
|
|
7508
|
+
* },
|
|
7509
|
+
* "is_signer_access_closed": false,
|
|
7510
|
+
* "certified_copy": { "available": false, "notification_method": "Email", "resends_left": null },
|
|
7511
|
+
* "envelope": { "id": "1052a1f0c3d4e5f6a7b8c9d0e1f2", "name": "Admission kit" }, // with expand
|
|
7127
7512
|
* "created_at": "2026-07-19T14:56:54Z",
|
|
7128
7513
|
* "updated_at": "2026-07-19T14:56:56Z"
|
|
7129
7514
|
* }
|
|
7130
7515
|
* ```
|
|
7131
7516
|
* @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
|
|
7132
|
-
* @throws {ApiError}
|
|
7517
|
+
* @throws {ApiError} `400` while the signer's step has not started, `401` for an
|
|
7518
|
+
* invalid code, `404` for an unknown signer.
|
|
7133
7519
|
*
|
|
7134
7520
|
* @example
|
|
7135
7521
|
* ```ts
|
|
7136
|
-
* const doc = await client.signerDocuments.getCurrent(signerId, accessCode);
|
|
7137
|
-
* console.log(doc.
|
|
7522
|
+
* const doc = await client.signerDocuments.getCurrent(signerId, accessCode, { expand: ['envelope'] });
|
|
7523
|
+
* if (doc.is_signer_access_closed) console.log(doc.certified_copy.available);
|
|
7138
7524
|
* ```
|
|
7139
7525
|
*/
|
|
7140
|
-
async getCurrent(signerId, signerAccessCode) {
|
|
7526
|
+
async getCurrent(signerId, signerAccessCode, options = {}) {
|
|
7141
7527
|
const sid = this.requireId(signerId, "Signer ID");
|
|
7142
7528
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7143
7529
|
return this.call(
|
|
7144
7530
|
"Failed to fetch current signer document",
|
|
7145
7531
|
() => this.http.get(`/signers/${this.pathSegment(sid, "Signer ID")}/document`, {
|
|
7146
|
-
params: { "signer-access-code": code }
|
|
7532
|
+
params: { "signer-access-code": code, ...signingReadParams(options) }
|
|
7147
7533
|
})
|
|
7148
7534
|
);
|
|
7149
7535
|
}
|
|
@@ -7158,9 +7544,10 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7158
7544
|
*
|
|
7159
7545
|
* @param signerId - The signer whose documents are listed.
|
|
7160
7546
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7161
|
-
* @param params -
|
|
7162
|
-
*
|
|
7163
|
-
* with pagination in `meta
|
|
7547
|
+
* @param params - `envelope_id` (only that envelope's documents) and pagination:
|
|
7548
|
+
* `page`, `per-page` (also accepts `per_page`).
|
|
7549
|
+
* @returns Matching documents with pagination in `meta`. Each carries its
|
|
7550
|
+
* `assignment` (without `signing_urls` when read with a code) and `pages`:
|
|
7164
7551
|
* ```jsonc
|
|
7165
7552
|
* {
|
|
7166
7553
|
* "data": [
|
|
@@ -7184,11 +7571,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7184
7571
|
* }
|
|
7185
7572
|
* ```
|
|
7186
7573
|
* @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
|
|
7187
|
-
* @throws {ApiError}
|
|
7574
|
+
* @throws {ApiError} `400` for a non-text `envelope_id` or a pending step,
|
|
7575
|
+
* `403` for another signer's code, `410` once the code is closed.
|
|
7188
7576
|
*
|
|
7189
7577
|
* @example
|
|
7190
7578
|
* ```ts
|
|
7191
7579
|
* const { data, meta } = await client.signerDocuments.list(signerId, accessCode, {
|
|
7580
|
+
* envelope_id: envelopeId,
|
|
7192
7581
|
* 'per-page': 20,
|
|
7193
7582
|
* });
|
|
7194
7583
|
* ```
|
|
@@ -7215,8 +7604,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7215
7604
|
* @param signerId - The signer whose documents are searched.
|
|
7216
7605
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7217
7606
|
* @param search - Free-text term matched against the document name.
|
|
7218
|
-
* @
|
|
7219
|
-
*
|
|
7607
|
+
* @param params - `envelope_id`: only that envelope's documents.
|
|
7608
|
+
* @returns Matching documents for that signer, with pagination in `meta`:
|
|
7220
7609
|
* ```jsonc
|
|
7221
7610
|
* {
|
|
7222
7611
|
* "data": [
|
|
@@ -7240,7 +7629,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7240
7629
|
* }
|
|
7241
7630
|
* ```
|
|
7242
7631
|
* @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
|
|
7243
|
-
* @throws {ApiError}
|
|
7632
|
+
* @throws {ApiError} `400`, `403` or `410`, as for {@link SignerDocumentsResource.list}.
|
|
7244
7633
|
*
|
|
7245
7634
|
* @example
|
|
7246
7635
|
* ```ts
|
|
@@ -7251,16 +7640,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7251
7640
|
* );
|
|
7252
7641
|
* ```
|
|
7253
7642
|
*/
|
|
7254
|
-
async search(signerId, signerAccessCode, search) {
|
|
7643
|
+
async search(signerId, signerAccessCode, search, params = {}) {
|
|
7255
7644
|
const sid = this.requireId(signerId, "Signer ID");
|
|
7256
7645
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7257
|
-
if (search !== void 0 && typeof search !== "string") {
|
|
7258
|
-
throw new ValidationError("search must be a string");
|
|
7259
|
-
}
|
|
7260
7646
|
return this.callList(
|
|
7261
7647
|
"Failed to search signer documents",
|
|
7262
7648
|
() => this.http.get(`/signers/${this.pathSegment(sid, "Signer ID")}/documents/search`, {
|
|
7263
|
-
params:
|
|
7649
|
+
params: { "signer-access-code": code, ...searchParams(search, params) }
|
|
7264
7650
|
})
|
|
7265
7651
|
);
|
|
7266
7652
|
}
|
|
@@ -7273,8 +7659,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7273
7659
|
* code. No `signer-access-code` is sent.
|
|
7274
7660
|
*
|
|
7275
7661
|
* @param signerId - The signer whose documents are listed.
|
|
7276
|
-
* @param params -
|
|
7277
|
-
* @returns Documents in the
|
|
7662
|
+
* @param params - `envelope_id` and pagination: `page`, `per-page` (also accepts `per_page`).
|
|
7663
|
+
* @returns Documents in the {@link IDocumentListItem} shape, with
|
|
7278
7664
|
* pagination in `meta` (same shape as {@link SignerDocumentsResource.list}):
|
|
7279
7665
|
* ```jsonc
|
|
7280
7666
|
* {
|
|
@@ -7283,7 +7669,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7283
7669
|
* }
|
|
7284
7670
|
* ```
|
|
7285
7671
|
* @throws {ValidationError} If `signerId` is missing.
|
|
7286
|
-
* @throws {ApiError} `401` if the workspace credentials are rejected
|
|
7672
|
+
* @throws {ApiError} `401` if the workspace credentials are rejected, `403` when a
|
|
7673
|
+
* role or OAuth scope refuses it, `404` for a signer outside the workspace.
|
|
7287
7674
|
*
|
|
7288
7675
|
* @example
|
|
7289
7676
|
* ```ts
|
|
@@ -7292,11 +7679,11 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7292
7679
|
*/
|
|
7293
7680
|
async listAsWorkspace(signerId, params = {}) {
|
|
7294
7681
|
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7682
|
+
const query = cleanListParams(params);
|
|
7683
|
+
delete query["signer-access-code"];
|
|
7295
7684
|
return this.callList(
|
|
7296
7685
|
"Failed to list signer documents",
|
|
7297
|
-
() => this.workspaceHttp.get(`/signers/${sid}/documents`, {
|
|
7298
|
-
params: cleanListParams(params)
|
|
7299
|
-
})
|
|
7686
|
+
() => this.workspaceHttp.get(`/signers/${sid}/documents`, { params: query })
|
|
7300
7687
|
);
|
|
7301
7688
|
}
|
|
7302
7689
|
/**
|
|
@@ -7309,53 +7696,45 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7309
7696
|
*
|
|
7310
7697
|
* @param signerId - The signer whose documents are searched.
|
|
7311
7698
|
* @param search - Free-text term matched against the document name.
|
|
7699
|
+
* @param params - `envelope_id`: only that envelope's documents.
|
|
7312
7700
|
* @returns Matching documents with pagination in `meta`, as
|
|
7313
7701
|
* {@link SignerDocumentsResource.listAsWorkspace} returns.
|
|
7314
7702
|
* @throws {ValidationError} If `signerId` is missing or `search` is not a string.
|
|
7315
|
-
* @throws {ApiError} `401`
|
|
7703
|
+
* @throws {ApiError} `401`, `403` or `404`, as for {@link SignerDocumentsResource.listAsWorkspace}.
|
|
7316
7704
|
*
|
|
7317
7705
|
* @example
|
|
7318
7706
|
* ```ts
|
|
7319
7707
|
* const { data } = await client.signerDocuments.searchAsWorkspace(signerId, 'agreement');
|
|
7320
7708
|
* ```
|
|
7321
7709
|
*/
|
|
7322
|
-
async searchAsWorkspace(signerId, search) {
|
|
7710
|
+
async searchAsWorkspace(signerId, search, params = {}) {
|
|
7323
7711
|
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7324
|
-
if (search !== void 0 && typeof search !== "string") {
|
|
7325
|
-
throw new ValidationError("search must be a string");
|
|
7326
|
-
}
|
|
7327
7712
|
return this.callList(
|
|
7328
7713
|
"Failed to search signer documents",
|
|
7329
7714
|
() => this.workspaceHttp.get(`/signers/${sid}/documents/search`, {
|
|
7330
|
-
params:
|
|
7715
|
+
params: searchParams(search, params)
|
|
7331
7716
|
})
|
|
7332
7717
|
);
|
|
7333
7718
|
}
|
|
7334
7719
|
/**
|
|
7335
|
-
* Download
|
|
7336
|
-
* (`GET /signers/{signer_id}/documents/{document_id}/download/
|
|
7720
|
+
* Download the original PDF a signer is asked to sign
|
|
7721
|
+
* (`GET /signers/{signer_id}/documents/{document_id}/download/original`).
|
|
7337
7722
|
*
|
|
7338
|
-
*
|
|
7339
|
-
*
|
|
7340
|
-
*
|
|
7341
|
-
*
|
|
7342
|
-
*
|
|
7343
|
-
* `pades` exists only when the document had a Digital Certificate signer.
|
|
7344
|
-
* A bundle contains original, certificated, and certificate-page artifacts,
|
|
7345
|
-
* plus PAdES when present.
|
|
7723
|
+
* Only `original` is available with an access code; the certified copy is
|
|
7724
|
+
* sent to the signer instead (see {@link SignerDocumentsResource.resendCertifiedCopy}).
|
|
7725
|
+
* The API redirects a request it cannot serve to its expired-link page, so
|
|
7726
|
+
* the SDK does not follow redirects here: that case throws instead of
|
|
7727
|
+
* returning the page's HTML.
|
|
7346
7728
|
*
|
|
7347
7729
|
* @param signerId - The signer requesting the download.
|
|
7348
7730
|
* @param documentId - The document to download.
|
|
7349
|
-
* @param artifactName -
|
|
7350
|
-
*
|
|
7351
|
-
* @
|
|
7352
|
-
*
|
|
7353
|
-
* @
|
|
7354
|
-
*
|
|
7355
|
-
*
|
|
7356
|
-
* `artifactName` is not one of the five documented names, or an explicitly
|
|
7357
|
-
* supplied legacy `signerAccessCode` is blank.
|
|
7358
|
-
* @throws {ApiError} `404` if the artifact does not exist yet.
|
|
7731
|
+
* @param artifactName - `original`, the only artifact a signer can download.
|
|
7732
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7733
|
+
* @returns The PDF bytes as a Node `Buffer`.
|
|
7734
|
+
* @throws {ValidationError} If an ID or the code is missing, or the artifact is not `original`.
|
|
7735
|
+
* @throws {ApiError} `302` when the code is missing or closed, `400` while the
|
|
7736
|
+
* signer's step has not started, `403` for another artifact, `404` for a
|
|
7737
|
+
* document the code does not reach, `410` once the code is closed.
|
|
7359
7738
|
*
|
|
7360
7739
|
* @example
|
|
7361
7740
|
* ```ts
|
|
@@ -7363,6 +7742,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7363
7742
|
* signerId,
|
|
7364
7743
|
* documentId,
|
|
7365
7744
|
* 'original',
|
|
7745
|
+
* accessCode,
|
|
7366
7746
|
* );
|
|
7367
7747
|
* await fs.promises.writeFile('to-sign.pdf', pdf);
|
|
7368
7748
|
* ```
|
|
@@ -7370,16 +7750,15 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7370
7750
|
async download(signerId, documentId, artifactName, signerAccessCode) {
|
|
7371
7751
|
const sid = this.requireId(signerId, "Signer ID");
|
|
7372
7752
|
const did = this.requireId(documentId, "Document ID");
|
|
7373
|
-
|
|
7374
|
-
|
|
7753
|
+
if (artifactName !== "original") {
|
|
7754
|
+
throw new ValidationError("A signer can download only the original artifact");
|
|
7755
|
+
}
|
|
7756
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7375
7757
|
return this.callBinary(
|
|
7376
7758
|
"Failed to download signer document",
|
|
7377
7759
|
() => this.http.get(
|
|
7378
|
-
`/signers/${this.pathSegment(sid, "Signer ID")}/documents/${this.pathSegment(did, "Document ID")}/download
|
|
7379
|
-
|
|
7380
|
-
responseType: "arraybuffer",
|
|
7381
|
-
params: { "signer-access-code": code }
|
|
7382
|
-
}
|
|
7760
|
+
`/signers/${this.pathSegment(sid, "Signer ID")}/documents/${this.pathSegment(did, "Document ID")}/download/original`,
|
|
7761
|
+
{ ...BINARY_NO_REDIRECT, params: { "signer-access-code": code } }
|
|
7383
7762
|
)
|
|
7384
7763
|
);
|
|
7385
7764
|
}
|
|
@@ -7625,10 +8004,15 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7625
8004
|
* flag.
|
|
7626
8005
|
*
|
|
7627
8006
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7628
|
-
* @returns
|
|
7629
|
-
*
|
|
8007
|
+
* @returns The signer's acceptance state, or `null` from deployments that
|
|
8008
|
+
* acknowledge without data:
|
|
8009
|
+
* ```jsonc
|
|
8010
|
+
* { "full_name": "Example Signer", "email": "signer@example.com", "has_accepted_terms": true }
|
|
8011
|
+
* ```
|
|
7630
8012
|
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
7631
|
-
* @throws {ApiError}
|
|
8013
|
+
* @throws {ApiError} `400` while the signer's verification is not done (e.g.
|
|
8014
|
+
* the e-mail code) or their step has not started, `401` for an invalid code,
|
|
8015
|
+
* `410` once the code is closed.
|
|
7632
8016
|
*
|
|
7633
8017
|
* @example
|
|
7634
8018
|
* ```ts
|
|
@@ -7638,12 +8022,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7638
8022
|
*/
|
|
7639
8023
|
async acceptTerms(signerAccessCode) {
|
|
7640
8024
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7641
|
-
|
|
8025
|
+
const data = await this.call(
|
|
7642
8026
|
"Failed to accept terms",
|
|
7643
8027
|
() => this.http.put("/signers/accept-terms", void 0, {
|
|
7644
8028
|
params: { "signer-access-code": code }
|
|
7645
8029
|
})
|
|
7646
8030
|
);
|
|
8031
|
+
return data ?? null;
|
|
7647
8032
|
}
|
|
7648
8033
|
/**
|
|
7649
8034
|
* Verify the signer's email or WhatsApp one-time password
|
|
@@ -7694,12 +8079,56 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7694
8079
|
)
|
|
7695
8080
|
);
|
|
7696
8081
|
}
|
|
8082
|
+
/**
|
|
8083
|
+
* Confirm the signer's contact data before signing
|
|
8084
|
+
* (`PUT /documents/{documentId}/signers/confirm-data?signer-access-code=…`).
|
|
8085
|
+
*
|
|
8086
|
+
* Send the contact the signer's channel needs: `email` for e-mail
|
|
8087
|
+
* verification or notification, `whatsapp_phone_number` for WhatsApp. Each
|
|
8088
|
+
* is saved when the signer has none; otherwise it must be theirs, so it
|
|
8089
|
+
* cannot change the record. `has_accepted_terms: true` also records the
|
|
8090
|
+
* terms, which opens `getAssignment()` for a `DigitalCertificate` signer.
|
|
8091
|
+
* With an envelope code it acts on the document the route names. Only the
|
|
8092
|
+
* fields provided are sent.
|
|
8093
|
+
*
|
|
8094
|
+
* Request body (`application/json`):
|
|
8095
|
+
* ```jsonc
|
|
8096
|
+
* {
|
|
8097
|
+
* "email": "signer@example.com",
|
|
8098
|
+
* "has_accepted_terms": true
|
|
8099
|
+
* }
|
|
8100
|
+
* ```
|
|
8101
|
+
*
|
|
8102
|
+
* @param documentId - The document the signer is confirming data for.
|
|
8103
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8104
|
+
* @param payload - `email`, `whatsapp_phone_number` and `has_accepted_terms`.
|
|
8105
|
+
* `full_name`/`government_id` are forwarded only for older deployments.
|
|
8106
|
+
* @returns `null` on production, which answers `data: []`; older deployments
|
|
8107
|
+
* return the signer:
|
|
8108
|
+
* ```jsonc
|
|
8109
|
+
* { "resource": "signer", "id": "19e6b92e7895332ed9708535d8c", "full_name": "Example Signer",
|
|
8110
|
+
* "email": "signer@example.com", "whatsapp_phone_number": null, "has_accepted_terms": true }
|
|
8111
|
+
* ```
|
|
8112
|
+
* @throws {ValidationError} If `documentId` or `signerAccessCode` is missing,
|
|
8113
|
+
* or a supplied value is malformed.
|
|
8114
|
+
* @throws {ApiError} `400` when a contact the signer's methods need is missing,
|
|
8115
|
+
* invalid or not theirs, or their step has not started; `404` for a document
|
|
8116
|
+
* the code does not reach; `410` once the code is closed.
|
|
8117
|
+
*
|
|
8118
|
+
* @example
|
|
8119
|
+
* ```ts
|
|
8120
|
+
* await client.signerDocuments.confirmData(documentId, accessCode, {
|
|
8121
|
+
* email: 'signer@example.com',
|
|
8122
|
+
* has_accepted_terms: true,
|
|
8123
|
+
* });
|
|
8124
|
+
* ```
|
|
8125
|
+
*/
|
|
7697
8126
|
async confirmData(documentId, signerAccessCode, payload) {
|
|
7698
8127
|
assertRecord(payload, "signer confirmation payload");
|
|
7699
8128
|
validateConfirmDataPayload(payload);
|
|
7700
8129
|
const did = this.requireId(documentId, "Document ID");
|
|
7701
8130
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7702
|
-
|
|
8131
|
+
const data = await this.call(
|
|
7703
8132
|
"Failed to confirm signer data",
|
|
7704
8133
|
() => this.http.put(
|
|
7705
8134
|
`/documents/${this.pathSegment(did, "Document ID")}/signers/confirm-data`,
|
|
@@ -7713,6 +8142,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7713
8142
|
{ params: { "signer-access-code": code } }
|
|
7714
8143
|
)
|
|
7715
8144
|
);
|
|
8145
|
+
return data !== null && typeof data === "object" && !Array.isArray(data) ? data : null;
|
|
7716
8146
|
}
|
|
7717
8147
|
async uploadSignature(signerAccessCode, image, options = {}) {
|
|
7718
8148
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
@@ -7793,14 +8223,17 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7793
8223
|
* the SDK never automatically replays this particular `GET` after a `429`.
|
|
7794
8224
|
*
|
|
7795
8225
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7796
|
-
* @param
|
|
7797
|
-
*
|
|
7798
|
-
* `
|
|
7799
|
-
*
|
|
7800
|
-
*
|
|
7801
|
-
*
|
|
7802
|
-
*
|
|
7803
|
-
*
|
|
8226
|
+
* @param options - `true`/`false` (the `has_accepted_terms` query, kept for
|
|
8227
|
+
* existing calls) or an options object:
|
|
8228
|
+
* `hasAcceptedTerms` (an explicit `false` is still sent), `expand:
|
|
8229
|
+
* ['envelope']` (adds the code's envelope), and `documentId` (with an
|
|
8230
|
+
* envelope code, open another document of that envelope the signer is on).
|
|
8231
|
+
* @returns The {@link ISigningDocument}. Its `assignment` carries only this
|
|
8232
|
+
* signer's items — no other signers, `signing_urls`, copy receivers or
|
|
8233
|
+
* `summary` — from which the `itemId` / `fieldId` / `pageId` values for
|
|
8234
|
+
* {@link SignerDocumentsResource.sign} are read. A closed code returns
|
|
8235
|
+
* only `id`, `name`, `status`, `current_signer`, `certified_copy` and
|
|
8236
|
+
* `envelope`, with `is_signer_access_closed: true`:
|
|
7804
8237
|
* ```jsonc
|
|
7805
8238
|
* {
|
|
7806
8239
|
* "resource": "document",
|
|
@@ -7831,9 +8264,12 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7831
8264
|
* { "id": "item-1", "page": { "id": "page-1", "number": 1, "height": 1651, "width": 1275,
|
|
7832
8265
|
* "download_url": "https://..." }, "signer": { "id": "19e6b92e..." },
|
|
7833
8266
|
* "field": { "id": "field-1", "type": "signature" }, "value": null, "completed": false }
|
|
7834
|
-
* ]
|
|
7835
|
-
* "summary": { "signer_count": 1, "completed_count": 0, "signers": [] }
|
|
8267
|
+
* ]
|
|
7836
8268
|
* },
|
|
8269
|
+
* "current_signer": { "id": "19e6b92e7895332ed9708535d8c", "verification_method": "Email",
|
|
8270
|
+
* "notification_methods": ["Email"], "completed": false },
|
|
8271
|
+
* "is_signer_access_closed": false,
|
|
8272
|
+
* "certified_copy": { "available": false, "notification_method": "Email", "resends_left": null },
|
|
7837
8273
|
* "pages": [
|
|
7838
8274
|
* { "id": "103acccd5c73...", "number": 1, "height": 1651, "width": 1275,
|
|
7839
8275
|
* "download_url": "https://api.assinafy.com.br/v1/documents/103acccd.../pages/103acccd5c73.../download" }
|
|
@@ -7842,75 +8278,233 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7842
8278
|
* "updated_at": "2026-07-19T14:56:56Z"
|
|
7843
8279
|
* }
|
|
7844
8280
|
* ```
|
|
7845
|
-
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
7846
|
-
* @throws {ApiError} `400` when DigitalCertificate
|
|
7847
|
-
*
|
|
7848
|
-
*
|
|
8281
|
+
* @throws {ValidationError} If `signerAccessCode` is missing or an option is malformed.
|
|
8282
|
+
* @throws {ApiError} `400` when a DigitalCertificate signer has not confirmed
|
|
8283
|
+
* data and terms, the signer's step has not started, or `documentId` is
|
|
8284
|
+
* not an ID; `401` for an invalid code; `404` when `documentId` is outside
|
|
8285
|
+
* the code's envelope; `409` (`DocumentNotReady`) while the document is
|
|
8286
|
+
* still being prepared.
|
|
7849
8287
|
*
|
|
7850
8288
|
* @example
|
|
7851
8289
|
* ```ts
|
|
7852
|
-
* // query → ?signer-access-code=<code>&has_accepted_terms=true
|
|
7853
|
-
* const
|
|
8290
|
+
* // query → ?signer-access-code=<code>&has_accepted_terms=true&expand=envelope
|
|
8291
|
+
* const doc = await client.signerDocuments.getAssignment(accessCode, {
|
|
8292
|
+
* hasAcceptedTerms: true,
|
|
8293
|
+
* expand: ['envelope'],
|
|
8294
|
+
* });
|
|
7854
8295
|
* ```
|
|
7855
8296
|
*/
|
|
7856
|
-
async getAssignment(signerAccessCode,
|
|
8297
|
+
async getAssignment(signerAccessCode, options) {
|
|
7857
8298
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7858
|
-
|
|
8299
|
+
const read = typeof options === "object" && options !== null ? options : options === void 0 ? {} : { hasAcceptedTerms: options };
|
|
8300
|
+
assertRecord(read, "signing read options");
|
|
8301
|
+
if (read.hasAcceptedTerms !== void 0 && typeof read.hasAcceptedTerms !== "boolean") {
|
|
7859
8302
|
throw new ValidationError("hasAcceptedTerms must be a boolean");
|
|
7860
8303
|
}
|
|
8304
|
+
if (read.documentId !== void 0) this.requireId(read.documentId, "documentId");
|
|
7861
8305
|
return this.call(
|
|
7862
8306
|
"Failed to fetch signer assignment",
|
|
7863
8307
|
() => this.http.get("/sign", {
|
|
7864
8308
|
params: cleanParams({
|
|
7865
8309
|
"signer-access-code": code,
|
|
7866
|
-
has_accepted_terms: hasAcceptedTerms
|
|
8310
|
+
has_accepted_terms: read.hasAcceptedTerms,
|
|
8311
|
+
document_id: read.documentId,
|
|
8312
|
+
...signingReadParams(read)
|
|
7867
8313
|
})
|
|
7868
8314
|
})
|
|
7869
8315
|
);
|
|
7870
8316
|
}
|
|
7871
8317
|
/**
|
|
7872
|
-
*
|
|
7873
|
-
* (`POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…`).
|
|
8318
|
+
* Read the sending workspace's brand for the signing page (`GET /sign/theme`).
|
|
7874
8319
|
*
|
|
7875
|
-
*
|
|
7876
|
-
*
|
|
7877
|
-
*
|
|
7878
|
-
* {@link SignerDocumentsResource.
|
|
7879
|
-
* authenticates via the `signer-access-code` query param.
|
|
7880
|
-
* Virtual signers must call {@link SignerDocumentsResource.confirmData}
|
|
7881
|
-
* first. Digital Certificate signers cannot use this endpoint; use the
|
|
7882
|
-
* certificate start/complete API flow instead.
|
|
8320
|
+
* Available before verification and after the document is deleted.
|
|
8321
|
+
* `primary_color` is the button background and `secondary_color` its text
|
|
8322
|
+
* (6-digit hex without `#`). The `logo` URL carries no access code: fetch it
|
|
8323
|
+
* with {@link SignerDocumentsResource.downloadLogo}.
|
|
7883
8324
|
*
|
|
7884
|
-
*
|
|
8325
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8326
|
+
* @returns The brand:
|
|
7885
8327
|
* ```jsonc
|
|
7886
|
-
*
|
|
7887
|
-
*
|
|
7888
|
-
*
|
|
7889
|
-
*
|
|
7890
|
-
*
|
|
7891
|
-
*
|
|
7892
|
-
* }
|
|
7893
|
-
* ]
|
|
8328
|
+
* {
|
|
8329
|
+
* "account_name": "Example Ltda",
|
|
8330
|
+
* "primary_color": "1F6FEB",
|
|
8331
|
+
* "secondary_color": "FFFFFF",
|
|
8332
|
+
* "logo": "https://api.assinafy.com.br/v1/sign/logo" // null when the account has none
|
|
8333
|
+
* }
|
|
7894
8334
|
* ```
|
|
7895
|
-
*
|
|
7896
|
-
* @
|
|
7897
|
-
* @param assignmentId - The assignment within that document.
|
|
7898
|
-
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7899
|
-
* @param entries - Non-empty array of {@link ISignFieldEntry}
|
|
7900
|
-
* (`itemId`, `fieldId`, `pageId`, `value`) — the body sent to the API.
|
|
7901
|
-
* @returns The API's signing result object. Its keys are operation-specific,
|
|
7902
|
-
* so the SDK preserves them as a {@link Record} without inventing fields.
|
|
7903
|
-
* @throws {ValidationError} If any of `documentId`, `assignmentId`, or
|
|
7904
|
-
* `signerAccessCode` is missing, or `entries` is empty.
|
|
7905
|
-
* @throws {ApiError} `400`/`409` if a value fails validation or the assignment
|
|
7906
|
-
* is no longer signable; `401`/`403` if the access code is invalid/expired.
|
|
8335
|
+
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
8336
|
+
* @throws {ApiError} `400` while the signer's step has not started, `401` for an invalid code.
|
|
7907
8337
|
*
|
|
7908
8338
|
* @example
|
|
7909
8339
|
* ```ts
|
|
7910
|
-
*
|
|
7911
|
-
*
|
|
7912
|
-
|
|
7913
|
-
|
|
8340
|
+
* const theme = await client.signerDocuments.getTheme(accessCode);
|
|
8341
|
+
* ```
|
|
8342
|
+
*/
|
|
8343
|
+
async getTheme(signerAccessCode) {
|
|
8344
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
8345
|
+
return this.call(
|
|
8346
|
+
"Failed to fetch signing theme",
|
|
8347
|
+
() => this.http.get("/sign/theme", { params: { "signer-access-code": code } })
|
|
8348
|
+
);
|
|
8349
|
+
}
|
|
8350
|
+
/**
|
|
8351
|
+
* Download the sending workspace's logo for the signing page (`GET /sign/logo`).
|
|
8352
|
+
*
|
|
8353
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8354
|
+
* @returns The image bytes (`image/*`).
|
|
8355
|
+
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
8356
|
+
* @throws {ApiError} `400` while the signer's step has not started, `401` for an
|
|
8357
|
+
* invalid code, `404` when the workspace has no logo.
|
|
8358
|
+
*
|
|
8359
|
+
* @example
|
|
8360
|
+
* ```ts
|
|
8361
|
+
* const logo = await client.signerDocuments.downloadLogo(accessCode);
|
|
8362
|
+
* ```
|
|
8363
|
+
*/
|
|
8364
|
+
async downloadLogo(signerAccessCode) {
|
|
8365
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
8366
|
+
return this.callBinary(
|
|
8367
|
+
"Failed to download signing logo",
|
|
8368
|
+
() => this.http.get("/sign/logo", {
|
|
8369
|
+
responseType: "arraybuffer",
|
|
8370
|
+
params: { "signer-access-code": code }
|
|
8371
|
+
})
|
|
8372
|
+
);
|
|
8373
|
+
}
|
|
8374
|
+
/**
|
|
8375
|
+
* Send the signer their certified copy again (`POST /sign/certified-copy`).
|
|
8376
|
+
*
|
|
8377
|
+
* The copy goes, with a download link valid for 30 minutes, on the signature
|
|
8378
|
+
* request's channel and only to the contact the signing messages went to.
|
|
8379
|
+
* Works after the signer signed, also once the code is closed. E-mail: once
|
|
8380
|
+
* every 2 minutes and 10 times a day; WhatsApp: once per request.
|
|
8381
|
+
* `certified_copy` on {@link SignerDocumentsResource.getAssignment} says
|
|
8382
|
+
* whether it is available.
|
|
8383
|
+
*
|
|
8384
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8385
|
+
* @param documentId - With an envelope code, another document of that envelope.
|
|
8386
|
+
* @returns What was sent:
|
|
8387
|
+
* ```jsonc
|
|
8388
|
+
* { "available": true, "notification_method": "Email", "resends_left": null, "sent_to": "j***@example.com" }
|
|
8389
|
+
* ```
|
|
8390
|
+
* @throws {ValidationError} If the code or `documentId` is blank.
|
|
8391
|
+
* @throws {ApiError} `400` while the signer's step has not started, `404` for a
|
|
8392
|
+
* document outside the envelope, `409` when the signer has not signed or the
|
|
8393
|
+
* document is not certified, `429` within the resend limits, `500` when the
|
|
8394
|
+
* message could not be sent (nothing used up; ask again).
|
|
8395
|
+
*
|
|
8396
|
+
* @example
|
|
8397
|
+
* ```ts
|
|
8398
|
+
* const { sent_to } = await client.signerDocuments.resendCertifiedCopy(accessCode);
|
|
8399
|
+
* ```
|
|
8400
|
+
*/
|
|
8401
|
+
async resendCertifiedCopy(signerAccessCode, documentId) {
|
|
8402
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
8403
|
+
const body = documentId === void 0 ? {} : { document_id: this.requireId(documentId, "documentId") };
|
|
8404
|
+
return this.call(
|
|
8405
|
+
"Failed to resend certified copy",
|
|
8406
|
+
() => this.http.post("/sign/certified-copy", body, { params: { "signer-access-code": code } })
|
|
8407
|
+
);
|
|
8408
|
+
}
|
|
8409
|
+
/**
|
|
8410
|
+
* Download the certified copy from a sent link (`GET /signers/downloads/{token}`).
|
|
8411
|
+
*
|
|
8412
|
+
* The token is the last path segment of the link in the completion and
|
|
8413
|
+
* re-send messages; it is a credential. Links last 7 days (completion) or
|
|
8414
|
+
* 30 minutes (re-send). An expired or unknown link redirects to the
|
|
8415
|
+
* expired-link page; the SDK does not follow it and throws instead.
|
|
8416
|
+
*
|
|
8417
|
+
* @param token - Link token.
|
|
8418
|
+
* @param artifact - `pades` for the PAdES version, when the document has one.
|
|
8419
|
+
* @returns The PDF bytes.
|
|
8420
|
+
* @throws {ValidationError} If `token` is blank or `artifact` is not `pades`.
|
|
8421
|
+
* @throws {ApiError} `302` for an expired or unknown link (ask for a new one
|
|
8422
|
+
* with {@link SignerDocumentsResource.resendCertifiedCopyFromLink}), `404`
|
|
8423
|
+
* for `pades` on a document without it.
|
|
8424
|
+
*
|
|
8425
|
+
* @example
|
|
8426
|
+
* ```ts
|
|
8427
|
+
* const pdf = await client.signerDocuments.downloadCertifiedCopy(token);
|
|
8428
|
+
* ```
|
|
8429
|
+
*/
|
|
8430
|
+
async downloadCertifiedCopy(token, artifact) {
|
|
8431
|
+
if (artifact !== void 0 && artifact !== "pades") {
|
|
8432
|
+
throw new ValidationError("artifact must be pades when given");
|
|
8433
|
+
}
|
|
8434
|
+
const path2 = `/signers/downloads/${this.pathSegment(token, "Download token")}`;
|
|
8435
|
+
return this.callBinary(
|
|
8436
|
+
"Failed to download certified copy",
|
|
8437
|
+
() => this.http.get(artifact ? `${path2}/pades` : path2, BINARY_NO_REDIRECT)
|
|
8438
|
+
);
|
|
8439
|
+
}
|
|
8440
|
+
/**
|
|
8441
|
+
* Send the certified copy again from an expired link
|
|
8442
|
+
* (`POST /signers/downloads/{token}/resend`).
|
|
8443
|
+
*
|
|
8444
|
+
* Works with the link's token after it expired, on the same terms as
|
|
8445
|
+
* {@link SignerDocumentsResource.resendCertifiedCopy}.
|
|
8446
|
+
*
|
|
8447
|
+
* @param token - Link token, from the expired link.
|
|
8448
|
+
* @returns What was sent, as {@link SignerDocumentsResource.resendCertifiedCopy} returns.
|
|
8449
|
+
* @throws {ValidationError} If `token` is blank.
|
|
8450
|
+
* @throws {ApiError} `404` for an unknown link, `409` when nothing can be sent
|
|
8451
|
+
* from it (copy receiver, Bypass signer, no contact, not certified), `429`
|
|
8452
|
+
* within the resend limits.
|
|
8453
|
+
*
|
|
8454
|
+
* @example
|
|
8455
|
+
* ```ts
|
|
8456
|
+
* await client.signerDocuments.resendCertifiedCopyFromLink(token);
|
|
8457
|
+
* ```
|
|
8458
|
+
*/
|
|
8459
|
+
async resendCertifiedCopyFromLink(token) {
|
|
8460
|
+
return this.call(
|
|
8461
|
+
"Failed to resend certified copy",
|
|
8462
|
+
() => this.http.post(`/signers/downloads/${this.pathSegment(token, "Download token")}/resend`)
|
|
8463
|
+
);
|
|
8464
|
+
}
|
|
8465
|
+
/**
|
|
8466
|
+
* Submit the signer's field values to sign an assignment
|
|
8467
|
+
* (`POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…`).
|
|
8468
|
+
*
|
|
8469
|
+
* The precise, field-by-field counterpart of
|
|
8470
|
+
* {@link SignerDocumentsResource.signMultiple}: the `entries` array is sent as
|
|
8471
|
+
* the request body, each entry addressing one item resolved from
|
|
8472
|
+
* {@link SignerDocumentsResource.getAssignment}. The access code
|
|
8473
|
+
* authenticates via the `signer-access-code` query param.
|
|
8474
|
+
* Virtual signers must call {@link SignerDocumentsResource.confirmData}
|
|
8475
|
+
* first. Digital Certificate signers cannot use this endpoint; use the
|
|
8476
|
+
* certificate start/complete API flow instead.
|
|
8477
|
+
*
|
|
8478
|
+
* Request body (`application/json`):
|
|
8479
|
+
* ```jsonc
|
|
8480
|
+
* [
|
|
8481
|
+
* {
|
|
8482
|
+
* "itemId": "item_example",
|
|
8483
|
+
* "fieldId": "field_example",
|
|
8484
|
+
* "pageId": "page_example",
|
|
8485
|
+
* "value": "Example Signer"
|
|
8486
|
+
* }
|
|
8487
|
+
* ]
|
|
8488
|
+
* ```
|
|
8489
|
+
*
|
|
8490
|
+
* @param documentId - The document being signed.
|
|
8491
|
+
* @param assignmentId - The assignment within that document.
|
|
8492
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8493
|
+
* @param entries - Non-empty array of {@link ISignFieldEntry}
|
|
8494
|
+
* (`itemId`, `fieldId`, `pageId`, `value`) — the body sent to the API.
|
|
8495
|
+
* @returns The API's signing result object. Its keys are operation-specific,
|
|
8496
|
+
* so the SDK preserves them as a {@link Record} without inventing fields.
|
|
8497
|
+
* @throws {ValidationError} If any of `documentId`, `assignmentId`, or
|
|
8498
|
+
* `signerAccessCode` is missing, or `entries` is empty.
|
|
8499
|
+
* @throws {ApiError} `400`/`409` if a value fails validation or the assignment
|
|
8500
|
+
* is no longer signable; `401`/`403` if the access code is invalid/expired.
|
|
8501
|
+
*
|
|
8502
|
+
* @example
|
|
8503
|
+
* ```ts
|
|
8504
|
+
* // body → [{ itemId, fieldId, pageId, value: 'Example Signer' }]
|
|
8505
|
+
* await client.signerDocuments.sign(documentId, assignmentId, accessCode, [
|
|
8506
|
+
* { itemId: 'item-1', fieldId: 'field-1', pageId: 'page-1', value: 'Example Signer' },
|
|
8507
|
+
* ]);
|
|
7914
8508
|
* ```
|
|
7915
8509
|
*/
|
|
7916
8510
|
async sign(documentId, assignmentId, signerAccessCode, entries) {
|
|
@@ -7998,6 +8592,19 @@ function assertDocumentIds(documentIds) {
|
|
|
7998
8592
|
throw new ValidationError("documentIds must be a non-empty array of non-empty IDs");
|
|
7999
8593
|
}
|
|
8000
8594
|
}
|
|
8595
|
+
var BINARY_NO_REDIRECT = { responseType: "arraybuffer", maxRedirects: 0 };
|
|
8596
|
+
var SIGNING_EXPANSIONS = /* @__PURE__ */ new Set(["envelope"]);
|
|
8597
|
+
function signingReadParams(options) {
|
|
8598
|
+
assertRecord(options, "signing read options");
|
|
8599
|
+
return expandParam(options.expand, SIGNING_EXPANSIONS);
|
|
8600
|
+
}
|
|
8601
|
+
function searchParams(search, params) {
|
|
8602
|
+
if (search !== void 0 && typeof search !== "string") {
|
|
8603
|
+
throw new ValidationError("search must be a string");
|
|
8604
|
+
}
|
|
8605
|
+
assertRecord(params, "search params");
|
|
8606
|
+
return cleanParams({ search, envelope_id: params.envelope_id });
|
|
8607
|
+
}
|
|
8001
8608
|
function assertDeclineReason(declineReason) {
|
|
8002
8609
|
if (typeof declineReason !== "string" || !declineReason.trim()) {
|
|
8003
8610
|
throw new ValidationError("declineReason is required");
|
|
@@ -8219,12 +8826,70 @@ var UserResource = class extends BaseResource {
|
|
|
8219
8826
|
* ```
|
|
8220
8827
|
*/
|
|
8221
8828
|
async updateNotificationPreferences(preferences) {
|
|
8222
|
-
|
|
8829
|
+
assertBooleanMap(preferences, "notification preferences", NOTIFICATION_PREFERENCE_KEYS);
|
|
8223
8830
|
return this.call(
|
|
8224
8831
|
"Failed to update notification preferences",
|
|
8225
8832
|
() => this.http.put("/users/self/notification-preferences", preferences)
|
|
8226
8833
|
);
|
|
8227
8834
|
}
|
|
8835
|
+
/**
|
|
8836
|
+
* Read which document alerts reach the user as push notifications
|
|
8837
|
+
* (`GET /users/self/push-preferences`).
|
|
8838
|
+
*
|
|
8839
|
+
* Separate from the e-mail preferences. Every key is returned and defaults
|
|
8840
|
+
* to `true`; new keys may be added. Not available to third-party OAuth
|
|
8841
|
+
* applications (`403`).
|
|
8842
|
+
*
|
|
8843
|
+
* @returns The push preferences:
|
|
8844
|
+
* ```jsonc
|
|
8845
|
+
* {
|
|
8846
|
+
* "SignerViewed": true,
|
|
8847
|
+
* "SignerSigned": true,
|
|
8848
|
+
* "DocumentCompleted": true,
|
|
8849
|
+
* "SignerDeclined": true,
|
|
8850
|
+
* "DocumentAboutToExpire": true,
|
|
8851
|
+
* "DocumentExpired": true,
|
|
8852
|
+
* "SignerIdentityReviewRequired": true, // the review e-mail is always sent
|
|
8853
|
+
* "SignerWhatsappFailed": true
|
|
8854
|
+
* }
|
|
8855
|
+
* ```
|
|
8856
|
+
* @throws {ApiError} `401` for invalid credentials, `403` for an OAuth application token.
|
|
8857
|
+
*
|
|
8858
|
+
* @example
|
|
8859
|
+
* ```ts
|
|
8860
|
+
* const push = await client.users.getPushPreferences();
|
|
8861
|
+
* ```
|
|
8862
|
+
*/
|
|
8863
|
+
async getPushPreferences() {
|
|
8864
|
+
return this.call(
|
|
8865
|
+
"Failed to fetch push preferences",
|
|
8866
|
+
() => this.http.get("/users/self/push-preferences")
|
|
8867
|
+
);
|
|
8868
|
+
}
|
|
8869
|
+
/**
|
|
8870
|
+
* Change which document alerts reach the user as push notifications
|
|
8871
|
+
* (`PUT /users/self/push-preferences`).
|
|
8872
|
+
*
|
|
8873
|
+
* Merges the keys sent; `false` stops that push in every workspace the user
|
|
8874
|
+
* belongs to. E-mail is not affected.
|
|
8875
|
+
*
|
|
8876
|
+
* @param preferences - Keys to change, e.g. `{ SignerViewed: false }`.
|
|
8877
|
+
* @returns The full map, as {@link UserResource.getPushPreferences} returns.
|
|
8878
|
+
* @throws {ValidationError} If the map is empty or a value is not a boolean.
|
|
8879
|
+
* @throws {ApiError} `400` for an unknown code, `403` for an OAuth application token.
|
|
8880
|
+
*
|
|
8881
|
+
* @example
|
|
8882
|
+
* ```ts
|
|
8883
|
+
* await client.users.updatePushPreferences({ SignerViewed: false });
|
|
8884
|
+
* ```
|
|
8885
|
+
*/
|
|
8886
|
+
async updatePushPreferences(preferences) {
|
|
8887
|
+
assertBooleanMap(preferences, "push preferences");
|
|
8888
|
+
return this.call(
|
|
8889
|
+
"Failed to update push preferences",
|
|
8890
|
+
() => this.http.put("/users/self/push-preferences", { ...preferences })
|
|
8891
|
+
);
|
|
8892
|
+
}
|
|
8228
8893
|
/**
|
|
8229
8894
|
* List the user's enrolled two-factor methods (`GET /users/self/mfa`).
|
|
8230
8895
|
*
|
|
@@ -8420,21 +9085,6 @@ var NOTIFICATION_PREFERENCE_KEYS = /* @__PURE__ */ new Set([
|
|
|
8420
9085
|
"ContractExpired",
|
|
8421
9086
|
"ContractRenewed"
|
|
8422
9087
|
]);
|
|
8423
|
-
function validateNotificationPreferences(preferences) {
|
|
8424
|
-
assertRecord(preferences, "notification preferences");
|
|
8425
|
-
const entries = Object.entries(preferences);
|
|
8426
|
-
if (entries.length === 0) {
|
|
8427
|
-
throw new ValidationError("at least one notification preference is required");
|
|
8428
|
-
}
|
|
8429
|
-
for (const [key, value] of entries) {
|
|
8430
|
-
if (!NOTIFICATION_PREFERENCE_KEYS.has(key)) {
|
|
8431
|
-
throw new ValidationError(`unknown notification preference: ${key}`);
|
|
8432
|
-
}
|
|
8433
|
-
if (typeof value !== "boolean") {
|
|
8434
|
-
throw new ValidationError(`${key} must be a boolean`);
|
|
8435
|
-
}
|
|
8436
|
-
}
|
|
8437
|
-
}
|
|
8438
9088
|
|
|
8439
9089
|
// src/resources/contracts.ts
|
|
8440
9090
|
var CONTRACT_STATUSES = /* @__PURE__ */ new Set(["draft", "active", "expired", "terminated"]);
|
|
@@ -8564,14 +9214,14 @@ var ContractResource = class extends BaseResource {
|
|
|
8564
9214
|
* }
|
|
8565
9215
|
* ```
|
|
8566
9216
|
* @throws {ValidationError} If an ID is missing or invalid.
|
|
8567
|
-
* @throws {ApiError} `401` for invalid credentials, `404`
|
|
8568
|
-
*
|
|
9217
|
+
* @throws {ApiError} `401` for invalid credentials, `404` (`code:
|
|
9218
|
+
* 'NoContractTerms'` when the document exists without terms), or `500`.
|
|
8569
9219
|
*
|
|
8570
9220
|
* @example
|
|
8571
9221
|
* ```ts
|
|
8572
9222
|
* const contract = await client.contracts.get(document.id);
|
|
8573
|
-
* if (
|
|
8574
|
-
* console.log(contract.parent_document_id);
|
|
9223
|
+
* if ('parent_document_id' in contract) {
|
|
9224
|
+
* console.log(contract.parent_document_id); // an amendment, renewal or termination
|
|
8575
9225
|
* }
|
|
8576
9226
|
* ```
|
|
8577
9227
|
*/
|
|
@@ -8630,9 +9280,10 @@ var ContractResource = class extends BaseResource {
|
|
|
8630
9280
|
* }
|
|
8631
9281
|
* ```
|
|
8632
9282
|
* @throws {ValidationError} If the payload or an ID is malformed.
|
|
8633
|
-
* @throws {ApiError} `400` for invalid terms, `403`
|
|
8634
|
-
* include tracking, `404` for an
|
|
8635
|
-
*
|
|
9283
|
+
* @throws {ApiError} `400` for invalid terms (each in `fieldErrors`), `403`
|
|
9284
|
+
* (`PlanRestricted`) when the plan does not include tracking, `404` for an
|
|
9285
|
+
* unknown document or a `parent_document_id` outside the workspace, `409`
|
|
9286
|
+
* (`ContractChanged`) after a concurrent change, or `500` on a server error.
|
|
8636
9287
|
*
|
|
8637
9288
|
* @example
|
|
8638
9289
|
* ```ts
|
|
@@ -8662,6 +9313,7 @@ var ContractResource = class extends BaseResource {
|
|
|
8662
9313
|
*
|
|
8663
9314
|
* @param documentId - Any document in the contract family.
|
|
8664
9315
|
* @param accountId - Override the client's default account ID.
|
|
9316
|
+
* @param params - `expand: 'document'` embeds the root contract's document.
|
|
8665
9317
|
* @returns The root contract and ordered instruments:
|
|
8666
9318
|
* ```jsonc
|
|
8667
9319
|
* {
|
|
@@ -8713,10 +9365,15 @@ var ContractResource = class extends BaseResource {
|
|
|
8713
9365
|
* const family = await client.contracts.listRelated(amendmentDocument.id);
|
|
8714
9366
|
* ```
|
|
8715
9367
|
*/
|
|
8716
|
-
async listRelated(documentId, accountId) {
|
|
9368
|
+
async listRelated(documentId, accountId, params = {}) {
|
|
9369
|
+
assertRecord(params, "related contract params");
|
|
9370
|
+
if (params.expand !== void 0 && params.expand !== "document") {
|
|
9371
|
+
throw new ValidationError("expand must be document");
|
|
9372
|
+
}
|
|
9373
|
+
const config = params.expand === void 0 ? {} : { params: { expand: params.expand } };
|
|
8717
9374
|
return this.call(
|
|
8718
9375
|
"Failed to fetch related contracts",
|
|
8719
|
-
() => this.http.get(`${this.contractPath(documentId, accountId)}/related
|
|
9376
|
+
() => this.http.get(`${this.contractPath(documentId, accountId)}/related`, config)
|
|
8720
9377
|
);
|
|
8721
9378
|
}
|
|
8722
9379
|
/**
|
|
@@ -9019,15 +9676,708 @@ function validateExternalReferences(value) {
|
|
|
9019
9676
|
}
|
|
9020
9677
|
}
|
|
9021
9678
|
|
|
9679
|
+
// src/resources/envelopes.ts
|
|
9680
|
+
var EnvelopeResource = class extends BaseResource {
|
|
9681
|
+
/**
|
|
9682
|
+
* List the workspace's envelopes, most recent first
|
|
9683
|
+
* (`GET /accounts/{accountId}/envelopes`).
|
|
9684
|
+
*
|
|
9685
|
+
* @param params - Optional filters and pagination.
|
|
9686
|
+
* @param params.search - Part of the envelope name.
|
|
9687
|
+
* @param params.status - `open` (a document is still open) or `closed`
|
|
9688
|
+
* (every document signed, declined, cancelled, expired or failed).
|
|
9689
|
+
* @param params.page - One-based page number.
|
|
9690
|
+
* @param params.per-page - Page size: 20 by default, at most 50.
|
|
9691
|
+
* @param accountId - Override the client's default account ID.
|
|
9692
|
+
* @returns Envelopes and pagination metadata:
|
|
9693
|
+
* ```jsonc
|
|
9694
|
+
* {
|
|
9695
|
+
* "data": [{
|
|
9696
|
+
* "id": "1052a1f0c3d4e5f6a7b8c9d0e1f2",
|
|
9697
|
+
* "name": "Admission kit",
|
|
9698
|
+
* "message": "Please sign the documents below.",
|
|
9699
|
+
* "documents": [{
|
|
9700
|
+
* "id": "1052a1e9b8c7d6e5f4a3b2c1d0e9",
|
|
9701
|
+
* "position": 1,
|
|
9702
|
+
* "name": "contract.pdf",
|
|
9703
|
+
* "status": "pending_signature",
|
|
9704
|
+
* "artifacts": {
|
|
9705
|
+
* "original": "https://api.assinafy.com.br/v1/documents/1052a1e9b8c7d6e5f4a3b2c1d0e9/download/original",
|
|
9706
|
+
* "thumbnail": "https://api.assinafy.com.br/v1/documents/1052a1e9b8c7d6e5f4a3b2c1d0e9/thumbnail"
|
|
9707
|
+
* },
|
|
9708
|
+
* "signers": [{
|
|
9709
|
+
* "id": "1052a1d4c3b2a1f0e9d8c7b6a5f4",
|
|
9710
|
+
* "full_name": "Ana Souza",
|
|
9711
|
+
* "email": "ana@example.com",
|
|
9712
|
+
* "whatsapp_phone_number": null,
|
|
9713
|
+
* "completed": false,
|
|
9714
|
+
* "signed_at": null
|
|
9715
|
+
* }]
|
|
9716
|
+
* }],
|
|
9717
|
+
* "counts": { "pending_signature": 1 }, // documents per status; no envelope-level status
|
|
9718
|
+
* "signing_urls": [{
|
|
9719
|
+
* "signer_id": "1052a1d4c3b2a1f0e9d8c7b6a5f4",
|
|
9720
|
+
* "url": "https://app.assinafy.com.br/sign/1052a1e9b8c7d6e5f4a3b2c1d0e9?email=ana%40example.com",
|
|
9721
|
+
* "embedded": false
|
|
9722
|
+
* }],
|
|
9723
|
+
* "created_at": "2026-11-11T14:00:00Z"
|
|
9724
|
+
* }],
|
|
9725
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
|
|
9726
|
+
* }
|
|
9727
|
+
* ```
|
|
9728
|
+
* @throws {ValidationError} If no account ID is available.
|
|
9729
|
+
* @throws {ApiError} `400` for a filter of the wrong type, `403` for a token
|
|
9730
|
+
* without `documents:read`, `401` for invalid credentials.
|
|
9731
|
+
*
|
|
9732
|
+
* @example
|
|
9733
|
+
* ```ts
|
|
9734
|
+
* const { data: open } = await client.envelopes.list({ status: 'open' });
|
|
9735
|
+
* ```
|
|
9736
|
+
*/
|
|
9737
|
+
async list(params = {}, accountId) {
|
|
9738
|
+
assertRecord(params, "envelope list params");
|
|
9739
|
+
if (params.status !== void 0 && params.status !== "open" && params.status !== "closed") {
|
|
9740
|
+
throw new ValidationError("status must be open or closed");
|
|
9741
|
+
}
|
|
9742
|
+
return this.callList(
|
|
9743
|
+
"Failed to list envelopes",
|
|
9744
|
+
() => this.http.get(this.envelopesPath(accountId), { params: cleanListParams(params) })
|
|
9745
|
+
);
|
|
9746
|
+
}
|
|
9747
|
+
/**
|
|
9748
|
+
* Read one envelope (`GET /accounts/{accountId}/envelopes/{envelopeId}`).
|
|
9749
|
+
*
|
|
9750
|
+
* @param envelopeId - Envelope ID.
|
|
9751
|
+
* @param accountId - Override the client's default account ID.
|
|
9752
|
+
* @returns The envelope: its documents in order (`position`), each with its
|
|
9753
|
+
* status and signers, the per-status `counts` and one `signing_urls` entry
|
|
9754
|
+
* per signer. Same shape as each item of {@link EnvelopeResource.list}.
|
|
9755
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9756
|
+
* @throws {ApiError} `403` for a token without `documents:read`, `404` for an
|
|
9757
|
+
* unknown envelope.
|
|
9758
|
+
*
|
|
9759
|
+
* @example
|
|
9760
|
+
* ```ts
|
|
9761
|
+
* const envelope = await client.envelopes.get(envelopeId);
|
|
9762
|
+
* const pending = envelope.documents.filter((doc) => doc.status === 'pending_signature');
|
|
9763
|
+
* ```
|
|
9764
|
+
*/
|
|
9765
|
+
async get(envelopeId, accountId) {
|
|
9766
|
+
return this.call(
|
|
9767
|
+
"Failed to fetch envelope",
|
|
9768
|
+
() => this.http.get(this.envelopePath(envelopeId, accountId))
|
|
9769
|
+
);
|
|
9770
|
+
}
|
|
9771
|
+
/**
|
|
9772
|
+
* Send several documents to the same signers at once
|
|
9773
|
+
* (`POST /accounts/{accountId}/envelopes`).
|
|
9774
|
+
*
|
|
9775
|
+
* Every document must be uploaded, `metadata_ready` and unassigned; every
|
|
9776
|
+
* signer must be on at least one document. Signers all sign at once (no
|
|
9777
|
+
* `step`); a `DigitalCertificate` signer signs only `virtual` documents and
|
|
9778
|
+
* is alone on each. One invitation goes to each signer, and `200` means the
|
|
9779
|
+
* envelope exists even when a send fails (see each signer's
|
|
9780
|
+
* `notification_history`). The envelope is charged as one document, each
|
|
9781
|
+
* signer's notification and identity check once, and each certificate
|
|
9782
|
+
* signature on every document it is made on. A refused request creates and
|
|
9783
|
+
* charges nothing. Pass an `idempotencyKey` to retry safely after a lost
|
|
9784
|
+
* response; the SDK then also replays a `429`.
|
|
9785
|
+
*
|
|
9786
|
+
* @param payload - Envelope definition.
|
|
9787
|
+
* @param payload.name - 1–255 characters without `<`; invitations use it in
|
|
9788
|
+
* place of document names.
|
|
9789
|
+
* @param payload.message - Optional message for every signer.
|
|
9790
|
+
* @param payload.max_total_credits - Refuse with `409 CreditCeilingExceeded`
|
|
9791
|
+
* above this many credits.
|
|
9792
|
+
* @param payload.signers - 1–20 `{ id, verification_method?, notification_methods?, embedded? }`.
|
|
9793
|
+
* @param payload.documents - 1–20 `{ id, signer_ids, method?, entries?, expires_at?, copy_receiver_ids? }`,
|
|
9794
|
+
* in envelope order. `collect` documents need `entries` whose signers are
|
|
9795
|
+
* exactly `signer_ids`.
|
|
9796
|
+
* @param options - `idempotencyKey`: new for each envelope you mean to create.
|
|
9797
|
+
* @param accountId - Override the client's default account ID.
|
|
9798
|
+
* @returns The created envelope (see {@link EnvelopeResource.list}). An
|
|
9799
|
+
* embedded or WhatsApp-only signer has `url: null` in `signing_urls`.
|
|
9800
|
+
* @throws {ValidationError} If the payload is malformed, a signer's channels
|
|
9801
|
+
* do not pair, or a `collect` document has no `entries`.
|
|
9802
|
+
* @throws {ApiError} `400` with `fieldErrors` naming each field at fault, `403`
|
|
9803
|
+
* (`PlanRestricted` or `InsufficientScope`), `409` (`CreditCeilingExceeded`,
|
|
9804
|
+
* or `IdempotencyKeyInUse` while the first request with that key runs).
|
|
9805
|
+
*
|
|
9806
|
+
* @example
|
|
9807
|
+
* ```ts
|
|
9808
|
+
* const envelope = await client.envelopes.create({
|
|
9809
|
+
* name: 'Admission kit',
|
|
9810
|
+
* signers: [{ id: signerId }],
|
|
9811
|
+
* documents: [
|
|
9812
|
+
* { id: contractId, signer_ids: [signerId] },
|
|
9813
|
+
* { id: policyId, signer_ids: [signerId], expires_at: '2026-12-31' },
|
|
9814
|
+
* ],
|
|
9815
|
+
* }, { idempotencyKey: crypto.randomUUID() });
|
|
9816
|
+
* ```
|
|
9817
|
+
*/
|
|
9818
|
+
async create(payload, options = {}, accountId) {
|
|
9819
|
+
const body = buildEnvelopePayload(payload);
|
|
9820
|
+
assertRecord(options, "envelope options");
|
|
9821
|
+
const config = idempotencyConfig(options.idempotencyKey);
|
|
9822
|
+
this.logger.info("Creating envelope", {
|
|
9823
|
+
signerCount: body["signers"].length,
|
|
9824
|
+
documentCount: body["documents"].length
|
|
9825
|
+
});
|
|
9826
|
+
return this.call(
|
|
9827
|
+
"Failed to create envelope",
|
|
9828
|
+
() => this.http.post(this.envelopesPath(accountId), body, config)
|
|
9829
|
+
);
|
|
9830
|
+
}
|
|
9831
|
+
/**
|
|
9832
|
+
* Estimate what creating an envelope would cost
|
|
9833
|
+
* (`POST /accounts/{accountId}/envelopes/estimate-cost`).
|
|
9834
|
+
*
|
|
9835
|
+
* Takes the creation body and checks it the same way, creating and charging
|
|
9836
|
+
* nothing; `max_total_credits` is ignored. The envelope counts as one
|
|
9837
|
+
* document, each signer's notification and identity check once, and each
|
|
9838
|
+
* certificate signature per document.
|
|
9839
|
+
*
|
|
9840
|
+
* @param payload - The body {@link EnvelopeResource.create} would send.
|
|
9841
|
+
* @param accountId - Override the client's default account ID.
|
|
9842
|
+
* @returns A cost estimate:
|
|
9843
|
+
* ```jsonc
|
|
9844
|
+
* {
|
|
9845
|
+
* "documents": 1,
|
|
9846
|
+
* "credits": 1.45,
|
|
9847
|
+
* "needs_extra_document": false,
|
|
9848
|
+
* "extra_document_cost": 1,
|
|
9849
|
+
* "total_credits": 1.45,
|
|
9850
|
+
* "breakdown": [
|
|
9851
|
+
* { "code": "NotificationWhatsapp", "name": "WhatsApp notification", "cost": 0.45, "quantity": 1, "unit_cost": 0.45 },
|
|
9852
|
+
* { "code": "SignatureDigitalCertificate", "name": "Digital certificate signature", "cost": 1, "quantity": 2, "unit_cost": 0.5 }
|
|
9853
|
+
* ],
|
|
9854
|
+
* "document_balance": 97, // null when documents are not limited
|
|
9855
|
+
* "credit_balance": 10, // null when credits are not limited
|
|
9856
|
+
* "has_sufficient_resources": true,
|
|
9857
|
+
* "blocking_reason": null,
|
|
9858
|
+
* "message": null
|
|
9859
|
+
* }
|
|
9860
|
+
* ```
|
|
9861
|
+
* @throws {ValidationError} If the payload is malformed or a signer's channels do not pair.
|
|
9862
|
+
* @throws {ApiError} `400` for fields at fault, `403` (`PlanRestricted` or
|
|
9863
|
+
* `InsufficientScope`).
|
|
9864
|
+
*
|
|
9865
|
+
* @example
|
|
9866
|
+
* ```ts
|
|
9867
|
+
* const estimate = await client.envelopes.estimateCost(envelopeBody);
|
|
9868
|
+
* if (!estimate.has_sufficient_resources) console.warn(estimate.blocking_reason);
|
|
9869
|
+
* ```
|
|
9870
|
+
*/
|
|
9871
|
+
async estimateCost(payload, accountId) {
|
|
9872
|
+
const body = buildEnvelopePayload(payload);
|
|
9873
|
+
return this.call(
|
|
9874
|
+
"Failed to estimate envelope cost",
|
|
9875
|
+
() => this.http.post(`${this.envelopesPath(accountId)}/estimate-cost`, body)
|
|
9876
|
+
);
|
|
9877
|
+
}
|
|
9878
|
+
/**
|
|
9879
|
+
* Rename an envelope, change its message or reorder its documents
|
|
9880
|
+
* (`PATCH /accounts/{accountId}/envelopes/{envelopeId}`).
|
|
9881
|
+
*
|
|
9882
|
+
* Send only what changes. Nothing is sent to anyone; later reminders,
|
|
9883
|
+
* cancellations and additions use the new values. Works on closed envelopes.
|
|
9884
|
+
*
|
|
9885
|
+
* @param envelopeId - Envelope ID.
|
|
9886
|
+
* @param payload - At least one change.
|
|
9887
|
+
* @param payload.name - 1–255 characters without `<`.
|
|
9888
|
+
* @param payload.message - New message, or `null` for none.
|
|
9889
|
+
* @param payload.document_ids - Every document of the envelope, each once, in the new order.
|
|
9890
|
+
* @param accountId - Override the client's default account ID.
|
|
9891
|
+
* @returns The updated envelope (see {@link EnvelopeResource.list}).
|
|
9892
|
+
* @throws {ValidationError} If nothing would change or a value is malformed.
|
|
9893
|
+
* @throws {ApiError} `400` for fields at fault, `403` for a token without
|
|
9894
|
+
* `documents:write`, `404` for an unknown envelope.
|
|
9895
|
+
*
|
|
9896
|
+
* @example
|
|
9897
|
+
* ```ts
|
|
9898
|
+
* await client.envelopes.update(envelopeId, { name: 'Admission kit 2026', message: null });
|
|
9899
|
+
* ```
|
|
9900
|
+
*/
|
|
9901
|
+
async update(envelopeId, payload, accountId) {
|
|
9902
|
+
const body = buildUpdatePayload(payload);
|
|
9903
|
+
return this.call(
|
|
9904
|
+
"Failed to update envelope",
|
|
9905
|
+
() => this.http.patch(this.envelopePath(envelopeId, accountId), body)
|
|
9906
|
+
);
|
|
9907
|
+
}
|
|
9908
|
+
/**
|
|
9909
|
+
* Delete a closed envelope (`DELETE /accounts/{accountId}/envelopes/{envelopeId}`).
|
|
9910
|
+
*
|
|
9911
|
+
* Allowed once every document is certificated, declined, cancelled, expired
|
|
9912
|
+
* or failed; cancel it first otherwise. Its documents remain as ordinary
|
|
9913
|
+
* documents, and its `Idempotency-Key` no longer answers it.
|
|
9914
|
+
*
|
|
9915
|
+
* @param envelopeId - Envelope ID.
|
|
9916
|
+
* @param accountId - Override the client's default account ID.
|
|
9917
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9918
|
+
* @throws {ApiError} `403` for a token without `documents:write`, `404` for an
|
|
9919
|
+
* unknown envelope, `409` (`EnvelopeOpen`) while a document is still open.
|
|
9920
|
+
*
|
|
9921
|
+
* @example
|
|
9922
|
+
* ```ts
|
|
9923
|
+
* await client.envelopes.cancel(envelopeId);
|
|
9924
|
+
* await client.envelopes.delete(envelopeId);
|
|
9925
|
+
* ```
|
|
9926
|
+
*/
|
|
9927
|
+
async delete(envelopeId, accountId) {
|
|
9928
|
+
return this.callVoid(
|
|
9929
|
+
"Failed to delete envelope",
|
|
9930
|
+
() => this.http.delete(this.envelopePath(envelopeId, accountId))
|
|
9931
|
+
);
|
|
9932
|
+
}
|
|
9933
|
+
/**
|
|
9934
|
+
* Cancel every document that can still be cancelled
|
|
9935
|
+
* (`PUT /accounts/{accountId}/envelopes/{envelopeId}/cancel`).
|
|
9936
|
+
*
|
|
9937
|
+
* Each owner, signer and copy receiver is told once for the whole envelope.
|
|
9938
|
+
* Documents already closed, fully signed or being certificated are left as
|
|
9939
|
+
* they are. Safe to repeat: a second call cancels nothing.
|
|
9940
|
+
*
|
|
9941
|
+
* @param envelopeId - Envelope ID.
|
|
9942
|
+
* @param accountId - Override the client's default account ID.
|
|
9943
|
+
* @returns What happened to each document:
|
|
9944
|
+
* ```jsonc
|
|
9945
|
+
* [
|
|
9946
|
+
* { "id": "1052a1e9b8c7d6e5f4a3b2c1d0e9", "status": "cancelled", "cancelled": true },
|
|
9947
|
+
* { "id": "1052a1eaf9e8d7c6b5a4f3e2d1c0", "status": "certificated", "cancelled": false }
|
|
9948
|
+
* ]
|
|
9949
|
+
* ```
|
|
9950
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9951
|
+
* @throws {ApiError} `403` for a token without `documents:write`, `404` for an
|
|
9952
|
+
* unknown envelope.
|
|
9953
|
+
*
|
|
9954
|
+
* @example
|
|
9955
|
+
* ```ts
|
|
9956
|
+
* const results = await client.envelopes.cancel(envelopeId);
|
|
9957
|
+
* ```
|
|
9958
|
+
*/
|
|
9959
|
+
async cancel(envelopeId, accountId) {
|
|
9960
|
+
return this.call(
|
|
9961
|
+
"Failed to cancel envelope",
|
|
9962
|
+
() => this.http.put(`${this.envelopePath(envelopeId, accountId)}/cancel`)
|
|
9963
|
+
);
|
|
9964
|
+
}
|
|
9965
|
+
/**
|
|
9966
|
+
* Read the envelope's activity trail, newest first
|
|
9967
|
+
* (`GET /accounts/{accountId}/envelopes/{envelopeId}/activities`).
|
|
9968
|
+
*
|
|
9969
|
+
* Includes every document the envelope has had, including ones taken out;
|
|
9970
|
+
* each entry is a document activity that also names its document.
|
|
9971
|
+
*
|
|
9972
|
+
* @param envelopeId - Envelope ID.
|
|
9973
|
+
* @param params - `sort` (`-id`, the default, or `id` for oldest first),
|
|
9974
|
+
* `page`, and `per-page` (20 by default, at most 50).
|
|
9975
|
+
* @param accountId - Override the client's default account ID.
|
|
9976
|
+
* @returns Activity entries and pagination metadata:
|
|
9977
|
+
* ```jsonc
|
|
9978
|
+
* {
|
|
9979
|
+
* "data": [{
|
|
9980
|
+
* "id": 7731204,
|
|
9981
|
+
* "event": "signer_signed_document",
|
|
9982
|
+
* "message": "Ana Souza signed the document",
|
|
9983
|
+
* "payload": { "signer": { "id": "1052a1d4c3b2a1f0e9d8c7b6a5f4" } }, // same keys as that event's webhook
|
|
9984
|
+
* "origin": { "ip": "203.0.113.10", "user-agent": "Mozilla/5.0" },
|
|
9985
|
+
* "document_id": "1052a1e9b8c7d6e5f4a3b2c1d0e9",
|
|
9986
|
+
* "document_name": "contract.pdf",
|
|
9987
|
+
* "created_at": "2026-11-11T14:05:00Z"
|
|
9988
|
+
* }],
|
|
9989
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
|
|
9990
|
+
* }
|
|
9991
|
+
* ```
|
|
9992
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9993
|
+
* @throws {ApiError} `403` for a token without `documents:read`, `404` for an
|
|
9994
|
+
* unknown envelope.
|
|
9995
|
+
*
|
|
9996
|
+
* @example
|
|
9997
|
+
* ```ts
|
|
9998
|
+
* const { data } = await client.envelopes.listActivities(envelopeId, { sort: 'id' });
|
|
9999
|
+
* ```
|
|
10000
|
+
*/
|
|
10001
|
+
async listActivities(envelopeId, params = {}, accountId) {
|
|
10002
|
+
return this.callList(
|
|
10003
|
+
"Failed to fetch envelope activities",
|
|
10004
|
+
() => this.http.get(`${this.envelopePath(envelopeId, accountId)}/activities`, {
|
|
10005
|
+
params: cleanListParams(params)
|
|
10006
|
+
})
|
|
10007
|
+
);
|
|
10008
|
+
}
|
|
10009
|
+
/**
|
|
10010
|
+
* Download one artifact of every document as a zip
|
|
10011
|
+
* (`GET /accounts/{accountId}/envelopes/{envelopeId}/download/{artifactName}`).
|
|
10012
|
+
*
|
|
10013
|
+
* Files are named after their position (`1 - contract.pdf`); `bundle` gives
|
|
10014
|
+
* each document a folder. `certificated`, `certificate-page`, `pades` and
|
|
10015
|
+
* `bundle` include only the documents certified so far.
|
|
10016
|
+
*
|
|
10017
|
+
* @param envelopeId - Envelope ID.
|
|
10018
|
+
* @param artifactName - `original`, `certificated`, `certificate-page`, `pades` or `bundle`.
|
|
10019
|
+
* @param accountId - Override the client's default account ID.
|
|
10020
|
+
* @returns The zip archive bytes.
|
|
10021
|
+
* @throws {ValidationError} If an ID or the artifact name is invalid.
|
|
10022
|
+
* @throws {ApiError} `403` for a token without `documents:read`, `404` when no
|
|
10023
|
+
* document has the artifact.
|
|
10024
|
+
*
|
|
10025
|
+
* @example
|
|
10026
|
+
* ```ts
|
|
10027
|
+
* import { writeFile } from 'node:fs/promises';
|
|
10028
|
+
* await writeFile('envelope.zip', await client.envelopes.download(envelopeId, 'certificated'));
|
|
10029
|
+
* ```
|
|
10030
|
+
*/
|
|
10031
|
+
async download(envelopeId, artifactName, accountId) {
|
|
10032
|
+
assertDocumentArtifactName(artifactName);
|
|
10033
|
+
return this.callBinary(
|
|
10034
|
+
"Failed to download envelope artifacts",
|
|
10035
|
+
() => this.http.get(
|
|
10036
|
+
`${this.envelopePath(envelopeId, accountId)}/download/${this.pathSegment(artifactName, "Artifact name")}`,
|
|
10037
|
+
{ responseType: "arraybuffer" }
|
|
10038
|
+
)
|
|
10039
|
+
);
|
|
10040
|
+
}
|
|
10041
|
+
/**
|
|
10042
|
+
* Add a document to an open envelope for some of its signers
|
|
10043
|
+
* (`POST /accounts/{accountId}/envelopes/{envelopeId}/documents`).
|
|
10044
|
+
*
|
|
10045
|
+
* The document is checked as on creation and goes last. Only its
|
|
10046
|
+
* certificate signatures are charged; the chosen signers receive the
|
|
10047
|
+
* envelope invitation again, now listing it. No new signer can join, and an
|
|
10048
|
+
* envelope holds at most 20 documents.
|
|
10049
|
+
*
|
|
10050
|
+
* @param envelopeId - Envelope ID.
|
|
10051
|
+
* @param payload - `{ id, signer_ids, method?, entries?, expires_at?, copy_receiver_ids?, max_total_credits? }`.
|
|
10052
|
+
* @param accountId - Override the client's default account ID.
|
|
10053
|
+
* @returns The updated envelope (see {@link EnvelopeResource.list}).
|
|
10054
|
+
* @throws {ValidationError} If the document definition is malformed.
|
|
10055
|
+
* @throws {ApiError} `400` for fields at fault, `403` (`PlanRestricted` or
|
|
10056
|
+
* `InsufficientScope`), `409` (`EnvelopeClosed`, `CreditCeilingExceeded`).
|
|
10057
|
+
*
|
|
10058
|
+
* @example
|
|
10059
|
+
* ```ts
|
|
10060
|
+
* await client.envelopes.addDocument(envelopeId, { id: annexId, signer_ids: [signerId] });
|
|
10061
|
+
* ```
|
|
10062
|
+
*/
|
|
10063
|
+
async addDocument(envelopeId, payload, accountId) {
|
|
10064
|
+
const body = buildEnvelopeDocument(payload, "document");
|
|
10065
|
+
assertCreditCeiling(payload.max_total_credits);
|
|
10066
|
+
if (payload.max_total_credits !== void 0) body["max_total_credits"] = payload.max_total_credits;
|
|
10067
|
+
return this.call(
|
|
10068
|
+
"Failed to add document to envelope",
|
|
10069
|
+
() => this.http.post(`${this.envelopePath(envelopeId, accountId)}/documents`, body)
|
|
10070
|
+
);
|
|
10071
|
+
}
|
|
10072
|
+
/**
|
|
10073
|
+
* Take an open document out of the envelope
|
|
10074
|
+
* (`DELETE /accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}`).
|
|
10075
|
+
*
|
|
10076
|
+
* The document is cancelled and its people are told; the other documents
|
|
10077
|
+
* carry on, and links sent from it keep opening them.
|
|
10078
|
+
*
|
|
10079
|
+
* @param envelopeId - Envelope ID.
|
|
10080
|
+
* @param documentId - Document to take out.
|
|
10081
|
+
* @param accountId - Override the client's default account ID.
|
|
10082
|
+
* @returns The updated envelope (see {@link EnvelopeResource.list}).
|
|
10083
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10084
|
+
* @throws {ApiError} `403` for a token without `documents:write`, `404` when the
|
|
10085
|
+
* document is not in the envelope, `409` (`DocumentClosed`) when it can no
|
|
10086
|
+
* longer be cancelled.
|
|
10087
|
+
*
|
|
10088
|
+
* @example
|
|
10089
|
+
* ```ts
|
|
10090
|
+
* await client.envelopes.removeDocument(envelopeId, documentId);
|
|
10091
|
+
* ```
|
|
10092
|
+
*/
|
|
10093
|
+
async removeDocument(envelopeId, documentId, accountId) {
|
|
10094
|
+
return this.call(
|
|
10095
|
+
"Failed to remove document from envelope",
|
|
10096
|
+
() => this.http.delete(
|
|
10097
|
+
`${this.envelopePath(envelopeId, accountId)}/documents/${this.pathSegment(documentId, "Document ID")}`
|
|
10098
|
+
)
|
|
10099
|
+
);
|
|
10100
|
+
}
|
|
10101
|
+
/**
|
|
10102
|
+
* Remind a signer of the whole envelope
|
|
10103
|
+
* (`PUT /accounts/{accountId}/envelopes/{envelopeId}/signers/{signerId}/resend`).
|
|
10104
|
+
*
|
|
10105
|
+
* One message from their first link, listing the documents still to sign;
|
|
10106
|
+
* paid channels are charged once. A document's own reminder
|
|
10107
|
+
* (`assignments.resendNotification`) still goes per document.
|
|
10108
|
+
*
|
|
10109
|
+
* @param envelopeId - Envelope ID.
|
|
10110
|
+
* @param signerId - Signer of the envelope.
|
|
10111
|
+
* @param accountId - Override the client's default account ID.
|
|
10112
|
+
* @returns Delivery acknowledgement:
|
|
10113
|
+
* ```jsonc
|
|
10114
|
+
* { "is_sent": true, "envelope_id": "1052a1f0c3d4e5f6a7b8c9d0e1f2", "signer_id": "1052a1d4c3b2a1f0e9d8c7b6a5f4" }
|
|
10115
|
+
* ```
|
|
10116
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10117
|
+
* @throws {ApiError} `400` when the signer has nothing left to sign or credits
|
|
10118
|
+
* are short, `404` when the signer is not on the envelope, `409`
|
|
10119
|
+
* (`EnvelopeClosed`).
|
|
10120
|
+
*
|
|
10121
|
+
* @example
|
|
10122
|
+
* ```ts
|
|
10123
|
+
* await client.envelopes.resendNotification(envelopeId, signerId);
|
|
10124
|
+
* ```
|
|
10125
|
+
*/
|
|
10126
|
+
async resendNotification(envelopeId, signerId, accountId) {
|
|
10127
|
+
return this.call(
|
|
10128
|
+
"Failed to remind envelope signer",
|
|
10129
|
+
() => this.http.put(
|
|
10130
|
+
`${this.envelopePath(envelopeId, accountId)}/signers/${this.pathSegment(signerId, "Signer ID")}/resend`
|
|
10131
|
+
)
|
|
10132
|
+
);
|
|
10133
|
+
}
|
|
10134
|
+
envelopesPath(accountId) {
|
|
10135
|
+
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/envelopes`;
|
|
10136
|
+
}
|
|
10137
|
+
envelopePath(envelopeId, accountId) {
|
|
10138
|
+
return `${this.envelopesPath(accountId)}/${this.pathSegment(envelopeId, "Envelope ID")}`;
|
|
10139
|
+
}
|
|
10140
|
+
};
|
|
10141
|
+
function buildEnvelopePayload(payload) {
|
|
10142
|
+
assertRecord(payload, "envelope payload");
|
|
10143
|
+
assertNonEmptyString(payload.name, "name");
|
|
10144
|
+
assertMessage(payload.message);
|
|
10145
|
+
assertCreditCeiling(payload.max_total_credits);
|
|
10146
|
+
const signers = records(payload.signers, "signers").map((signer, index) => {
|
|
10147
|
+
const label = `signers[${index}]`;
|
|
10148
|
+
assertNonEmptyString(signer["id"], `${label}.id`);
|
|
10149
|
+
validateAssignmentSignerOptions(signer, label);
|
|
10150
|
+
const projected = { id: signer["id"] };
|
|
10151
|
+
for (const key of ["verification_method", "notification_methods", "embedded", "step"]) {
|
|
10152
|
+
if (signer[key] !== void 0) projected[key] = signer[key];
|
|
10153
|
+
}
|
|
10154
|
+
return projected;
|
|
10155
|
+
});
|
|
10156
|
+
const documents = records(payload.documents, "documents").map((document, index) => buildEnvelopeDocument(document, `documents[${index}]`));
|
|
10157
|
+
const body = { name: payload.name, signers, documents };
|
|
10158
|
+
if (payload.message !== void 0) body["message"] = payload.message;
|
|
10159
|
+
if (payload.max_total_credits !== void 0) body["max_total_credits"] = payload.max_total_credits;
|
|
10160
|
+
return body;
|
|
10161
|
+
}
|
|
10162
|
+
function buildEnvelopeDocument(document, label) {
|
|
10163
|
+
assertRecord(document, label);
|
|
10164
|
+
const input = document;
|
|
10165
|
+
assertNonEmptyString(input.id, `${label}.id`);
|
|
10166
|
+
const method = input.method ?? "virtual";
|
|
10167
|
+
if (method !== "virtual" && method !== "collect") {
|
|
10168
|
+
throw new ValidationError(`${label}.method must be virtual or collect`);
|
|
10169
|
+
}
|
|
10170
|
+
const entries = input.entries === void 0 ? void 0 : normaliseAssignmentEntries(input.entries);
|
|
10171
|
+
if (method === "collect" && !entries?.length) {
|
|
10172
|
+
throw new ValidationError(`${label}.entries is required for collect documents`);
|
|
10173
|
+
}
|
|
10174
|
+
if (input.expires_at !== void 0 && input.expires_at !== null) {
|
|
10175
|
+
assertExpirationDate(input.expires_at, `${label}.expires_at`);
|
|
10176
|
+
}
|
|
10177
|
+
const projected = {
|
|
10178
|
+
id: input.id,
|
|
10179
|
+
method,
|
|
10180
|
+
signer_ids: idList(input.signer_ids, `${label}.signer_ids`)
|
|
10181
|
+
};
|
|
10182
|
+
if (entries !== void 0) projected["entries"] = entries;
|
|
10183
|
+
if (input.expires_at !== void 0) projected["expires_at"] = input.expires_at;
|
|
10184
|
+
if (input.copy_receiver_ids !== void 0) {
|
|
10185
|
+
projected["copy_receiver_ids"] = idList(input.copy_receiver_ids, `${label}.copy_receiver_ids`);
|
|
10186
|
+
}
|
|
10187
|
+
return projected;
|
|
10188
|
+
}
|
|
10189
|
+
function buildUpdatePayload(payload) {
|
|
10190
|
+
assertRecord(payload, "envelope update");
|
|
10191
|
+
const body = {};
|
|
10192
|
+
if (payload.name !== void 0) {
|
|
10193
|
+
assertNonEmptyString(payload.name, "name");
|
|
10194
|
+
body["name"] = payload.name;
|
|
10195
|
+
}
|
|
10196
|
+
if (payload.message !== void 0) {
|
|
10197
|
+
assertMessage(payload.message);
|
|
10198
|
+
body["message"] = payload.message;
|
|
10199
|
+
}
|
|
10200
|
+
if (payload.document_ids !== void 0) {
|
|
10201
|
+
body["document_ids"] = idList(payload.document_ids, "document_ids");
|
|
10202
|
+
}
|
|
10203
|
+
if (Object.keys(body).length === 0) {
|
|
10204
|
+
throw new ValidationError("envelope update must change name, message or document_ids");
|
|
10205
|
+
}
|
|
10206
|
+
return body;
|
|
10207
|
+
}
|
|
10208
|
+
function assertMessage(message) {
|
|
10209
|
+
if (message !== void 0 && message !== null && typeof message !== "string") {
|
|
10210
|
+
throw new ValidationError("message must be a string or null");
|
|
10211
|
+
}
|
|
10212
|
+
}
|
|
10213
|
+
function records(value, label) {
|
|
10214
|
+
if (!Array.isArray(value)) throw new ValidationError(`${label} must be an array`);
|
|
10215
|
+
value.forEach((item, index) => assertRecord(item, `${label}[${index}]`));
|
|
10216
|
+
return value;
|
|
10217
|
+
}
|
|
10218
|
+
function idList(value, label) {
|
|
10219
|
+
if (!Array.isArray(value) || value.some((id) => typeof id !== "string" || !id.trim())) {
|
|
10220
|
+
throw new ValidationError(`${label} must be an array of IDs`);
|
|
10221
|
+
}
|
|
10222
|
+
return [...value];
|
|
10223
|
+
}
|
|
10224
|
+
|
|
10225
|
+
// src/resources/embed.ts
|
|
10226
|
+
var EmbedResource = class extends BaseResource {
|
|
10227
|
+
/**
|
|
10228
|
+
* List the origins allowed to embed signing pages, oldest first
|
|
10229
|
+
* (`GET /accounts/{accountId}/embed-origins`).
|
|
10230
|
+
*
|
|
10231
|
+
* @param accountId - Override the client's default account ID.
|
|
10232
|
+
* @returns Registered origins:
|
|
10233
|
+
* ```jsonc
|
|
10234
|
+
* [{ "id": "1052c7d8e9f0a1b2c3d4e5f6a7b8", "origin": "https://app.example.com", "created_at": "2026-11-04T12:05:00Z" }]
|
|
10235
|
+
* ```
|
|
10236
|
+
* @throws {ValidationError} If no account ID is available.
|
|
10237
|
+
* @throws {ApiError} `403` (`PlanRestricted`, or an OAuth application token).
|
|
10238
|
+
*
|
|
10239
|
+
* @example
|
|
10240
|
+
* ```ts
|
|
10241
|
+
* const origins = await client.embed.listOrigins();
|
|
10242
|
+
* ```
|
|
10243
|
+
*/
|
|
10244
|
+
async listOrigins(accountId) {
|
|
10245
|
+
return this.call("Failed to list embed origins", () => this.http.get(this.originsPath(accountId)));
|
|
10246
|
+
}
|
|
10247
|
+
/**
|
|
10248
|
+
* Allow one more origin to embed signing pages
|
|
10249
|
+
* (`POST /accounts/{accountId}/embed-origins`).
|
|
10250
|
+
*
|
|
10251
|
+
* An origin is an exact `https://host[:port]` (`http` only for `localhost`
|
|
10252
|
+
* and `127.0.0.1`) without path, query, fragment, credentials or wildcard;
|
|
10253
|
+
* the API lowercases the host and drops a default port. Up to 10 per account.
|
|
10254
|
+
*
|
|
10255
|
+
* @param origin - Origin of the page that will host the iframe.
|
|
10256
|
+
* @param accountId - Override the client's default account ID.
|
|
10257
|
+
* @returns The stored origin, e.g.
|
|
10258
|
+
* `{ "id": "1052c7d8e9f0a1b2c3d4e5f6a7b8", "origin": "https://app.example.com", "created_at": "2026-11-04T12:05:00Z" }`.
|
|
10259
|
+
* @throws {ValidationError} If `origin` is blank.
|
|
10260
|
+
* @throws {ApiError} `400` when it is invalid, already registered, or the
|
|
10261
|
+
* account has 10; `403` (`PlanRestricted`, or an OAuth application token).
|
|
10262
|
+
*
|
|
10263
|
+
* @example
|
|
10264
|
+
* ```ts
|
|
10265
|
+
* await client.embed.addOrigin('https://app.example.com');
|
|
10266
|
+
* ```
|
|
10267
|
+
*/
|
|
10268
|
+
async addOrigin(origin, accountId) {
|
|
10269
|
+
assertNonEmptyString(origin, "origin");
|
|
10270
|
+
return this.call(
|
|
10271
|
+
"Failed to add embed origin",
|
|
10272
|
+
() => this.http.post(this.originsPath(accountId), { origin })
|
|
10273
|
+
);
|
|
10274
|
+
}
|
|
10275
|
+
/**
|
|
10276
|
+
* Replace an allowed origin, keeping its ID
|
|
10277
|
+
* (`PUT /accounts/{accountId}/embed-origins/{originId}`).
|
|
10278
|
+
*
|
|
10279
|
+
* @param originId - Embed origin ID.
|
|
10280
|
+
* @param origin - New origin, with the rules of {@link EmbedResource.addOrigin}.
|
|
10281
|
+
* @param accountId - Override the client's default account ID.
|
|
10282
|
+
* @returns The updated origin.
|
|
10283
|
+
* @throws {ValidationError} If an ID or the origin is blank.
|
|
10284
|
+
* @throws {ApiError} `400` for an invalid or duplicate origin, `403`, `404` for
|
|
10285
|
+
* an unknown origin ID.
|
|
10286
|
+
*
|
|
10287
|
+
* @example
|
|
10288
|
+
* ```ts
|
|
10289
|
+
* await client.embed.updateOrigin(originId, 'https://sign.example.com');
|
|
10290
|
+
* ```
|
|
10291
|
+
*/
|
|
10292
|
+
async updateOrigin(originId, origin, accountId) {
|
|
10293
|
+
assertNonEmptyString(origin, "origin");
|
|
10294
|
+
return this.call(
|
|
10295
|
+
"Failed to update embed origin",
|
|
10296
|
+
() => this.http.put(this.originPath(originId, accountId), { origin })
|
|
10297
|
+
);
|
|
10298
|
+
}
|
|
10299
|
+
/**
|
|
10300
|
+
* Stop allowing an origin (`DELETE /accounts/{accountId}/embed-origins/{originId}`).
|
|
10301
|
+
*
|
|
10302
|
+
* Removing the last origin disables embedding: new sessions answer `409`
|
|
10303
|
+
* (`embed_origins_missing`).
|
|
10304
|
+
*
|
|
10305
|
+
* @param originId - Embed origin ID.
|
|
10306
|
+
* @param accountId - Override the client's default account ID.
|
|
10307
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10308
|
+
* @throws {ApiError} `403`, or `404` for an unknown origin ID.
|
|
10309
|
+
*
|
|
10310
|
+
* @example
|
|
10311
|
+
* ```ts
|
|
10312
|
+
* await client.embed.deleteOrigin(originId);
|
|
10313
|
+
* ```
|
|
10314
|
+
*/
|
|
10315
|
+
async deleteOrigin(originId, accountId) {
|
|
10316
|
+
return this.callVoid(
|
|
10317
|
+
"Failed to remove embed origin",
|
|
10318
|
+
() => this.http.delete(this.originPath(originId, accountId))
|
|
10319
|
+
);
|
|
10320
|
+
}
|
|
10321
|
+
/**
|
|
10322
|
+
* Mint a single-use embed URL for an `embedded` signer
|
|
10323
|
+
* (`POST /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/embed-sessions`).
|
|
10324
|
+
*
|
|
10325
|
+
* Load the URL in an iframe on a registered origin within 5 minutes;
|
|
10326
|
+
* opening it spends the token, so mint a new one each time the frame is
|
|
10327
|
+
* shown, including reloads. Treat it as a credential: hand it only to that
|
|
10328
|
+
* signer's page and never store or log it. Limited to 30 sessions per signer
|
|
10329
|
+
* per hour. For an envelope signer, mint on any of their documents still
|
|
10330
|
+
* waiting for them; the frame lists every document they still have to sign.
|
|
10331
|
+
* Frame events are UI hints: confirm the outcome from webhooks.
|
|
10332
|
+
*
|
|
10333
|
+
* @param documentId - Document ID.
|
|
10334
|
+
* @param assignmentId - Assignment ID.
|
|
10335
|
+
* @param signerId - Signer created with `embedded: true`.
|
|
10336
|
+
* @returns The session:
|
|
10337
|
+
* ```jsonc
|
|
10338
|
+
* {
|
|
10339
|
+
* "url": "https://app.assinafy.com.br/embed/3b1f0c7e9a2d4c58b6e1f4a07d93c2e85a1b0f6d4c7e2a9183b5d6f0e4c8a712",
|
|
10340
|
+
* "expires_at": "2026-11-04T12:05:00Z"
|
|
10341
|
+
* }
|
|
10342
|
+
* ```
|
|
10343
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10344
|
+
* @throws {ApiError} `400` (`embed_not_enabled_for_signer`), `403`
|
|
10345
|
+
* (`PlanRestricted`), `404` for an unknown document, assignment or signer,
|
|
10346
|
+
* `409` (`already_signed`, `document_not_ready` — retry shortly,
|
|
10347
|
+
* `document_unavailable`, `embed_origins_missing`), `429` past 30 per hour.
|
|
10348
|
+
*
|
|
10349
|
+
* @example
|
|
10350
|
+
* ```ts
|
|
10351
|
+
* const { url } = await client.embed.createSession(document.id, assignment.id, signer.id);
|
|
10352
|
+
* response.json({ url }); // to the signer's browser only
|
|
10353
|
+
* ```
|
|
10354
|
+
*/
|
|
10355
|
+
async createSession(documentId, assignmentId, signerId) {
|
|
10356
|
+
return this.call(
|
|
10357
|
+
"Failed to create embed session",
|
|
10358
|
+
() => this.http.post(
|
|
10359
|
+
`/documents/${this.pathSegment(documentId, "Document ID")}/assignments/${this.pathSegment(assignmentId, "Assignment ID")}/signers/${this.pathSegment(signerId, "Signer ID")}/embed-sessions`
|
|
10360
|
+
)
|
|
10361
|
+
);
|
|
10362
|
+
}
|
|
10363
|
+
originsPath(accountId) {
|
|
10364
|
+
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/embed-origins`;
|
|
10365
|
+
}
|
|
10366
|
+
originPath(originId, accountId) {
|
|
10367
|
+
return `${this.originsPath(accountId)}/${this.pathSegment(originId, "Embed origin ID")}`;
|
|
10368
|
+
}
|
|
10369
|
+
};
|
|
10370
|
+
|
|
9022
10371
|
// src/support/webhook-verifier.ts
|
|
9023
10372
|
import { createHmac, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
9024
10373
|
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
9025
10374
|
var WebhookVerifier = class {
|
|
9026
10375
|
webhookSecret;
|
|
9027
10376
|
/**
|
|
9028
|
-
* @param webhookSecret - The endpoint's `whsec_…` secret
|
|
9029
|
-
* `webhooks.
|
|
9030
|
-
* (
|
|
10377
|
+
* @param webhookSecret - The endpoint's `whsec_…` secret, as returned by
|
|
10378
|
+
* `webhooks.createEndpoint()` / `updateEndpoint()` when signing turns on,
|
|
10379
|
+
* `rotateEndpointSecret()`, or (API key only) `getEndpointSecret()`. Omit it
|
|
10380
|
+
* to keep verification disabled (every check returns `false`).
|
|
9031
10381
|
*
|
|
9032
10382
|
* @example
|
|
9033
10383
|
* ```ts
|
|
@@ -9080,6 +10430,7 @@ var WebhookVerifier = class {
|
|
|
9080
10430
|
const [version, signature] = entry.split(",", 2);
|
|
9081
10431
|
if (version !== "v1" || !signature) return false;
|
|
9082
10432
|
const actual = Buffer.from(signature, "base64");
|
|
10433
|
+
if (actual.toString("base64") !== signature) return false;
|
|
9083
10434
|
return actual.length === expected.length && timingSafeEqual2(actual, expected);
|
|
9084
10435
|
});
|
|
9085
10436
|
}
|
|
@@ -9207,6 +10558,8 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9207
10558
|
signerDocuments;
|
|
9208
10559
|
users;
|
|
9209
10560
|
contracts;
|
|
10561
|
+
envelopes;
|
|
10562
|
+
embed;
|
|
9210
10563
|
webhookVerifier;
|
|
9211
10564
|
/**
|
|
9212
10565
|
* Create a client. Supply `apiKey` (preferred, sent as `X-Api-Key`) or a
|
|
@@ -9316,7 +10669,12 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9316
10669
|
this.logger,
|
|
9317
10670
|
this.publicAxiosInstance
|
|
9318
10671
|
);
|
|
9319
|
-
this.fields = new FieldsResource(
|
|
10672
|
+
this.fields = new FieldsResource(
|
|
10673
|
+
this.axiosInstance,
|
|
10674
|
+
this.defaultAccountId,
|
|
10675
|
+
this.logger,
|
|
10676
|
+
this.publicAxiosInstance
|
|
10677
|
+
);
|
|
9320
10678
|
this.signerDocuments = new SignerDocumentsResource(
|
|
9321
10679
|
this.axiosInstance,
|
|
9322
10680
|
this.defaultAccountId,
|
|
@@ -9329,6 +10687,8 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9329
10687
|
this.defaultAccountId,
|
|
9330
10688
|
this.logger
|
|
9331
10689
|
);
|
|
10690
|
+
this.envelopes = new EnvelopeResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
10691
|
+
this.embed = new EmbedResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
9332
10692
|
this.webhookVerifier = new WebhookVerifier(this.webhookSecret);
|
|
9333
10693
|
}
|
|
9334
10694
|
/**
|
|
@@ -9501,7 +10861,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9501
10861
|
* });
|
|
9502
10862
|
* console.log(document.status); // usually 'pending_signature'
|
|
9503
10863
|
* console.log(signer_ids.length); // 2
|
|
9504
|
-
* console.log(assignment.signing_urls?.length); // one
|
|
10864
|
+
* console.log(assignment.signing_urls?.length); // one entry per notified signer; url is null for embedded or WhatsApp-only signers
|
|
9505
10865
|
* ```
|
|
9506
10866
|
*/
|
|
9507
10867
|
async uploadAndRequestSignatures(options) {
|
|
@@ -9759,6 +11119,8 @@ export {
|
|
|
9759
11119
|
DEFAULT_WEBHOOK_EVENTS,
|
|
9760
11120
|
DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD,
|
|
9761
11121
|
DocumentResource,
|
|
11122
|
+
EmbedResource,
|
|
11123
|
+
EnvelopeResource,
|
|
9762
11124
|
FieldsResource,
|
|
9763
11125
|
MAX_LIST_PAGE_SIZE,
|
|
9764
11126
|
MAX_UPLOAD_BYTES,
|