@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.js
CHANGED
|
@@ -39,6 +39,8 @@ __export(index_exports, {
|
|
|
39
39
|
DEFAULT_WEBHOOK_EVENTS: () => DEFAULT_WEBHOOK_EVENTS,
|
|
40
40
|
DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD: () => DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD,
|
|
41
41
|
DocumentResource: () => DocumentResource,
|
|
42
|
+
EmbedResource: () => EmbedResource,
|
|
43
|
+
EnvelopeResource: () => EnvelopeResource,
|
|
42
44
|
FieldsResource: () => FieldsResource,
|
|
43
45
|
MAX_LIST_PAGE_SIZE: () => MAX_LIST_PAGE_SIZE,
|
|
44
46
|
MAX_UPLOAD_BYTES: () => MAX_UPLOAD_BYTES,
|
|
@@ -94,6 +96,24 @@ var AssinafyError = class extends Error {
|
|
|
94
96
|
var ApiError = class _ApiError extends AssinafyError {
|
|
95
97
|
statusCode;
|
|
96
98
|
responseData;
|
|
99
|
+
/**
|
|
100
|
+
* Machine-readable refusal code from the error body, on the refusals a
|
|
101
|
+
* client can act on: `PlanRestricted` (offer the upgrade, don't retry),
|
|
102
|
+
* `InsufficientScope`, `DocumentNotReady`, `CreditCeilingExceeded`,
|
|
103
|
+
* `IdempotencyKeyInUse`, `EnvelopeOpen`, `EnvelopeClosed`, `DocumentClosed`,
|
|
104
|
+
* `ContractChanged`, `NoContractTerms`, `TagInUse`, `embed_origins_missing`, ….
|
|
105
|
+
* `undefined` when the body has none.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* if (error instanceof ApiError && error.code === 'IdempotencyKeyInUse') {
|
|
110
|
+
* await sleep(1000); // the first request with this key is still running
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
code;
|
|
115
|
+
/** Each field a `400` refused, in the order the API reports them. */
|
|
116
|
+
fieldErrors;
|
|
97
117
|
/**
|
|
98
118
|
* Parsed `WWW-Authenticate` challenge, when the response carried one.
|
|
99
119
|
*
|
|
@@ -101,8 +121,8 @@ var ApiError = class _ApiError extends AssinafyError {
|
|
|
101
121
|
* means the OAuth token is valid but was never granted that permission:
|
|
102
122
|
* send the user through the authorization flow again asking for the scope
|
|
103
123
|
* named in `scope`. A `403` without a challenge has a different cause —
|
|
104
|
-
* another workspace, the user's role,
|
|
105
|
-
* reach — and reconnecting will not fix it.
|
|
124
|
+
* another workspace, the user's role, the plan (`code: 'PlanRestricted'`),
|
|
125
|
+
* or a surface OAuth tokens never reach — and reconnecting will not fix it.
|
|
106
126
|
*
|
|
107
127
|
* @example
|
|
108
128
|
* ```ts
|
|
@@ -149,6 +169,14 @@ var ApiError = class _ApiError extends AssinafyError {
|
|
|
149
169
|
this.name = "ApiError";
|
|
150
170
|
this.statusCode = statusCode;
|
|
151
171
|
this.responseData = responseData;
|
|
172
|
+
if (responseData !== null && typeof responseData === "object") {
|
|
173
|
+
const body = responseData;
|
|
174
|
+
if (typeof body["code"] === "string" && body["code"].length > 0) this.code = body["code"];
|
|
175
|
+
if (Array.isArray(body["errors"])) {
|
|
176
|
+
const fieldErrors = body["errors"].filter(isFieldError);
|
|
177
|
+
if (fieldErrors.length > 0) this.fieldErrors = fieldErrors;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
152
180
|
}
|
|
153
181
|
/**
|
|
154
182
|
* Convert a status/body pair into an {@link ApiError}.
|
|
@@ -281,6 +309,11 @@ var NetworkError = class extends AssinafyError {
|
|
|
281
309
|
this.name = "NetworkError";
|
|
282
310
|
}
|
|
283
311
|
};
|
|
312
|
+
function isFieldError(value) {
|
|
313
|
+
if (value === null || typeof value !== "object") return false;
|
|
314
|
+
const entry = value;
|
|
315
|
+
return (entry["field"] === null || typeof entry["field"] === "string") && typeof entry["code"] === "string" && typeof entry["message"] === "string";
|
|
316
|
+
}
|
|
284
317
|
|
|
285
318
|
// src/utils.ts
|
|
286
319
|
var import_axios = __toESM(require("axios"));
|
|
@@ -341,6 +374,7 @@ var SAFE_LOG_NUMBER_FIELDS = /* @__PURE__ */ new Set([
|
|
|
341
374
|
"delayMs",
|
|
342
375
|
"maxRetries",
|
|
343
376
|
"signerCount",
|
|
377
|
+
"documentCount",
|
|
344
378
|
"size"
|
|
345
379
|
]);
|
|
346
380
|
function handleAssinafyResponse(response) {
|
|
@@ -527,6 +561,34 @@ function assertExpirationDate(value, label) {
|
|
|
527
561
|
throw new ValidationError(`${label} must be an ISO-8601 date or date-time`);
|
|
528
562
|
}
|
|
529
563
|
}
|
|
564
|
+
function assertCreditCeiling(value) {
|
|
565
|
+
if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value) || value < 0)) {
|
|
566
|
+
throw new ValidationError("max_total_credits must be a finite number of credits, zero or more");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function idempotencyConfig(key) {
|
|
570
|
+
if (key === void 0) return {};
|
|
571
|
+
if (typeof key !== "string" || key.trim().length === 0) {
|
|
572
|
+
throw new ValidationError("idempotencyKey must be a non-empty string");
|
|
573
|
+
}
|
|
574
|
+
return { headers: { "Idempotency-Key": key } };
|
|
575
|
+
}
|
|
576
|
+
function assertBooleanMap(value, label, known) {
|
|
577
|
+
assertRecord(value, label);
|
|
578
|
+
const entries = Object.entries(value);
|
|
579
|
+
if (entries.length === 0) throw new ValidationError(`${label} must set at least one key`);
|
|
580
|
+
for (const [key, item] of entries) {
|
|
581
|
+
if (known && !known.has(key)) throw new ValidationError(`unknown ${label} key: ${key}`);
|
|
582
|
+
if (typeof item !== "boolean") throw new ValidationError(`${label}.${key} must be a boolean`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function expandParam(value, allowed) {
|
|
586
|
+
if (value === void 0) return {};
|
|
587
|
+
if (!Array.isArray(value) || value.some((item) => !allowed.has(item))) {
|
|
588
|
+
throw new ValidationError(`expand must list only ${[...allowed].join(", ")}`);
|
|
589
|
+
}
|
|
590
|
+
return value.length > 0 ? { expand: value.join(",") } : {};
|
|
591
|
+
}
|
|
530
592
|
function cleanParams(params) {
|
|
531
593
|
assertRecord(params, "params");
|
|
532
594
|
const out = {};
|
|
@@ -701,7 +763,7 @@ var import_axios2 = __toESM(require("axios"));
|
|
|
701
763
|
// package.json
|
|
702
764
|
var package_default = {
|
|
703
765
|
name: "@assinafy/sdk",
|
|
704
|
-
version: "
|
|
766
|
+
version: "3.0.1",
|
|
705
767
|
packageManager: "bun@1.4.4",
|
|
706
768
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
707
769
|
type: "commonjs",
|
|
@@ -1053,14 +1115,22 @@ function toInt(value) {
|
|
|
1053
1115
|
|
|
1054
1116
|
// src/resources/assignments.ts
|
|
1055
1117
|
var ASSIGNMENT_METHODS = /* @__PURE__ */ new Set(["virtual", "collect"]);
|
|
1056
|
-
var VERIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
1057
|
-
|
|
1118
|
+
var VERIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
1119
|
+
"Email",
|
|
1120
|
+
"Whatsapp",
|
|
1121
|
+
"DigitalCertificate",
|
|
1122
|
+
"IdDocumentFaceMatchBasic",
|
|
1123
|
+
"Bypass"
|
|
1124
|
+
]);
|
|
1125
|
+
var NOTIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1126
|
+
var EMBEDDED_VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1058
1127
|
var DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD = "digital_certificate_requires_virtual_method";
|
|
1059
1128
|
var ALLOWED_NOTIFICATION_METHODS = {
|
|
1060
1129
|
Email: /* @__PURE__ */ new Set(["Email"]),
|
|
1061
1130
|
Whatsapp: /* @__PURE__ */ new Set(["Whatsapp"]),
|
|
1062
1131
|
DigitalCertificate: NOTIFICATION_METHODS,
|
|
1063
|
-
IdDocumentFaceMatchBasic: NOTIFICATION_METHODS
|
|
1132
|
+
IdDocumentFaceMatchBasic: NOTIFICATION_METHODS,
|
|
1133
|
+
Bypass: NOTIFICATION_METHODS
|
|
1064
1134
|
};
|
|
1065
1135
|
function validateAssignmentSignerOptions(signer, label = "signer") {
|
|
1066
1136
|
if (signer.verification_method !== void 0 && (typeof signer.verification_method !== "string" || !VERIFICATION_METHODS.has(signer.verification_method))) {
|
|
@@ -1086,6 +1156,14 @@ function validateAssignmentSignerOptions(signer, label = "signer") {
|
|
|
1086
1156
|
}
|
|
1087
1157
|
}
|
|
1088
1158
|
}
|
|
1159
|
+
if (signer.embedded !== void 0 && typeof signer.embedded !== "boolean") {
|
|
1160
|
+
throw new ValidationError(`${label} embedded must be a boolean`);
|
|
1161
|
+
}
|
|
1162
|
+
if (signer.embedded === true && typeof signer.verification_method === "string" && !EMBEDDED_VERIFICATION_METHODS.has(signer.verification_method)) {
|
|
1163
|
+
throw new ValidationError(
|
|
1164
|
+
`${label} embedded signing supports only Email, Whatsapp and Bypass verification`
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1089
1167
|
if (signer.step !== void 0 && (typeof signer.step !== "number" || !Number.isSafeInteger(signer.step) || signer.step < 1)) {
|
|
1090
1168
|
throw new ValidationError(`${label} step must be a positive safe integer`);
|
|
1091
1169
|
}
|
|
@@ -1146,6 +1224,7 @@ function buildAssignmentPayload(payload) {
|
|
|
1146
1224
|
))) {
|
|
1147
1225
|
throw new ValidationError("copy_receivers must be an array of non-empty signer IDs");
|
|
1148
1226
|
}
|
|
1227
|
+
assertCreditCeiling(payload.max_total_credits);
|
|
1149
1228
|
const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref));
|
|
1150
1229
|
validateDigitalCertificateMethod(method, normalisedSigners);
|
|
1151
1230
|
validateSigningOrder(normalisedSigners, "assignment signers");
|
|
@@ -1155,7 +1234,8 @@ function buildAssignmentPayload(payload) {
|
|
|
1155
1234
|
message: payload.message,
|
|
1156
1235
|
expires_at: payload.expires_at,
|
|
1157
1236
|
copy_receivers: payload.copy_receivers,
|
|
1158
|
-
entries
|
|
1237
|
+
entries,
|
|
1238
|
+
max_total_credits: payload.max_total_credits
|
|
1159
1239
|
});
|
|
1160
1240
|
}
|
|
1161
1241
|
function buildAssignmentEstimatePayload(payload) {
|
|
@@ -1200,6 +1280,7 @@ function normaliseSignerRef(ref) {
|
|
|
1200
1280
|
id,
|
|
1201
1281
|
verification_method: input.verification_method,
|
|
1202
1282
|
notification_methods: input.notification_methods,
|
|
1283
|
+
embedded: input.embedded,
|
|
1203
1284
|
step: input.step
|
|
1204
1285
|
});
|
|
1205
1286
|
if (typeof id === "string" && id.trim().length > 0) {
|
|
@@ -1307,12 +1388,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1307
1388
|
/**
|
|
1308
1389
|
* List assignments across the workspace (`GET /assignments`).
|
|
1309
1390
|
*
|
|
1310
|
-
* The account is passed as
|
|
1311
|
-
*
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1391
|
+
* The account is passed as the camelCase `accountId` **query parameter**,
|
|
1392
|
+
* required unless an OAuth token names the workspace (the SDK always sends
|
|
1393
|
+
* it; for a token, its own workspace). `account_id` and an `X-Account-Id`
|
|
1394
|
+
* header are ignored.
|
|
1314
1395
|
*
|
|
1315
|
-
* @param params - `page`, `per-page
|
|
1396
|
+
* @param params - `page`, `per-page` (at most 50), and `sort`: `created_at`
|
|
1397
|
+
* (default, oldest first), `expires_at` or `id`, `-` prefix for descending.
|
|
1316
1398
|
* @param accountId - Override the client's default account ID.
|
|
1317
1399
|
* @returns Assignments, with pagination in `meta`. Each item is a full
|
|
1318
1400
|
* {@link IAssignment} (same shape as {@link AssignmentResource.create}
|
|
@@ -1380,13 +1462,15 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1380
1462
|
* "signing_urls": [
|
|
1381
1463
|
* {
|
|
1382
1464
|
* "signer_id": "19e6b92e7895332ed9708535d8c",
|
|
1383
|
-
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com"
|
|
1465
|
+
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com",
|
|
1466
|
+
* "embedded": false
|
|
1384
1467
|
* }
|
|
1385
1468
|
* ]
|
|
1386
1469
|
* }
|
|
1387
1470
|
* ```
|
|
1388
1471
|
* @throws {ValidationError} If no account ID is available.
|
|
1389
|
-
* @throws {ApiError}
|
|
1472
|
+
* @throws {ApiError} `400` when no workspace is named, `403` when a role or
|
|
1473
|
+
* OAuth scope refuses it, `404` for an unknown workspace.
|
|
1390
1474
|
*
|
|
1391
1475
|
* @example
|
|
1392
1476
|
* ```ts
|
|
@@ -1446,7 +1530,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1446
1530
|
* `message`, `expires_at`, `copy_receivers` (existing signer IDs, not
|
|
1447
1531
|
* addresses), and `collect`-mode `entries` with page-image geometry.
|
|
1448
1532
|
* `expires_at` accepts a date (ending at 23:59 UTC), a date-time without
|
|
1449
|
-
* an offset (UTC), or an offset-aware date-time.
|
|
1533
|
+
* an offset (UTC), or an offset-aware date-time, at least one hour ahead.
|
|
1534
|
+
* `max_total_credits` refuses the send above that many credits. Signers may
|
|
1535
|
+
* set `embedded: true` (Embed feature; `Email`, `Whatsapp` or `Bypass`
|
|
1536
|
+
* verification) to sign in your app through `embed.createSession()`.
|
|
1537
|
+
* This route takes no `Idempotency-Key`: a document takes one assignment,
|
|
1538
|
+
* so a retry after a lost response answers `400` and charges nothing —
|
|
1539
|
+
* read the document to see whether the first request went through.
|
|
1450
1540
|
* @returns The created {@link IAssignment}: `signers` (rich, with `step` /
|
|
1451
1541
|
* `notified` / `verification_method`), `items` (one row per signer × field),
|
|
1452
1542
|
* a `summary` count block, and per-signer `signing_urls`. Response shape:
|
|
@@ -1511,7 +1601,8 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1511
1601
|
* "signing_urls": [
|
|
1512
1602
|
* {
|
|
1513
1603
|
* "signer_id": "19e6b92e7895332ed9708535d8c",
|
|
1514
|
-
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com"
|
|
1604
|
+
* "url": "https://app.assinafy.com.br/sign/103033c950d865a248a11c5cf96c?email=signer%40example.com",
|
|
1605
|
+
* "embedded": false // an embedded signer has "url": null
|
|
1515
1606
|
* }
|
|
1516
1607
|
* ]
|
|
1517
1608
|
* }
|
|
@@ -1521,7 +1612,10 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1521
1612
|
* combined with `collect`. The last case has `errors.code ===
|
|
1522
1613
|
* 'digital_certificate_requires_virtual_method'`.
|
|
1523
1614
|
* @throws {ApiError} `400` for an invalid assignment or unmet verification
|
|
1524
|
-
* precondition;
|
|
1615
|
+
* precondition; `403` (`PlanRestricted` for a method or Embed the plan
|
|
1616
|
+
* lacks, `InsufficientScope`); `404` for a document outside the workspace;
|
|
1617
|
+
* `409` (`CreditCeilingExceeded`, with `total_credits` and
|
|
1618
|
+
* `max_total_credits` in `responseData`).
|
|
1525
1619
|
*
|
|
1526
1620
|
* @example
|
|
1527
1621
|
* ```ts
|
|
@@ -1530,7 +1624,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1530
1624
|
* message: 'Please sign this contract',
|
|
1531
1625
|
* });
|
|
1532
1626
|
* // → wire body: { method: 'virtual', signers: [{ id: '19e6…' }], message: 'Please sign this contract' }
|
|
1533
|
-
* console.log(assignment.signing_urls?.length); // one
|
|
1627
|
+
* console.log(assignment.signing_urls?.length); // one entry per notified signer; url is null for embedded or WhatsApp-only signers
|
|
1534
1628
|
* ```
|
|
1535
1629
|
*/
|
|
1536
1630
|
async create(documentId, payload) {
|
|
@@ -1722,7 +1816,11 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1722
1816
|
* }
|
|
1723
1817
|
* ```
|
|
1724
1818
|
* @throws {ValidationError} If any of the three IDs is missing.
|
|
1725
|
-
* @throws {ApiError}
|
|
1819
|
+
* @throws {ApiError} `400` when the document is not pending signature, the
|
|
1820
|
+
* signer already signed or waits for an earlier step, or credits are short;
|
|
1821
|
+
* `403`; `404`. The same verification code is resent, so an open embed frame
|
|
1822
|
+
* keeps working; envelope signers can be reminded of every document at once
|
|
1823
|
+
* with `envelopes.resendNotification()`.
|
|
1726
1824
|
*
|
|
1727
1825
|
* @example
|
|
1728
1826
|
* ```ts
|
|
@@ -1751,26 +1849,20 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1751
1849
|
* @param documentId - The document the assignment belongs to.
|
|
1752
1850
|
* @param assignmentId - The assignment containing the signer.
|
|
1753
1851
|
* @param signerId - The signer whose notification would be resent.
|
|
1754
|
-
* @returns An {@link IResendCostEstimate}:
|
|
1755
|
-
*
|
|
1756
|
-
*
|
|
1852
|
+
* @returns An {@link IResendCostEstimate}: the compact `total` /
|
|
1853
|
+
* `has_sufficient_credits` shape production returns, or the full
|
|
1854
|
+
* {@link ICostEstimate} on older deployments:
|
|
1757
1855
|
* ```jsonc
|
|
1758
1856
|
* {
|
|
1759
|
-
* "
|
|
1760
|
-
* "
|
|
1761
|
-
* "
|
|
1762
|
-
* "
|
|
1763
|
-
* "total_credits": 0,
|
|
1764
|
-
* "breakdown": [],
|
|
1765
|
-
* "document_balance": 67,
|
|
1766
|
-
* "credit_balance": 0,
|
|
1767
|
-
* "has_sufficient_resources": true,
|
|
1768
|
-
* "blocking_reason": null,
|
|
1769
|
-
* "message": null
|
|
1857
|
+
* "total": 0.45,
|
|
1858
|
+
* "breakdown": [{ "code": "NotificationWhatsappResend", "name": "WhatsApp Notification Resend", "cost": 0.45 }],
|
|
1859
|
+
* "credit_balance": 10, // null when credits are not limited
|
|
1860
|
+
* "has_sufficient_credits": true
|
|
1770
1861
|
* }
|
|
1771
1862
|
* ```
|
|
1772
1863
|
* @throws {ValidationError} If any of the three IDs is missing.
|
|
1773
|
-
* @throws {ApiError}
|
|
1864
|
+
* @throws {ApiError} `400` when the signer cannot be reminded (signed, not
|
|
1865
|
+
* yet notified, or notified only by `Bypass`), `403`, `404`.
|
|
1774
1866
|
*
|
|
1775
1867
|
* @example
|
|
1776
1868
|
* ```ts
|
|
@@ -1808,11 +1900,11 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1808
1900
|
* ```jsonc
|
|
1809
1901
|
* [
|
|
1810
1902
|
* {
|
|
1811
|
-
* "sent_at":
|
|
1903
|
+
* "sent_at": "2026-10-19T19:05:48Z",
|
|
1812
1904
|
* "header": "Assinafy",
|
|
1813
1905
|
* "body": "Você tem um documento para assinar.",
|
|
1814
1906
|
* "buttons": [
|
|
1815
|
-
* { "text": "Assinar documento"
|
|
1907
|
+
* { "text": "Assinar documento" } // production strips button URLs
|
|
1816
1908
|
* ],
|
|
1817
1909
|
* "phone_number": "+5511999998888",
|
|
1818
1910
|
* "signer_id": "19e6b92e7895332ed9708535d8c"
|
|
@@ -2271,7 +2363,11 @@ var DocumentResource = class extends BaseResource {
|
|
|
2271
2363
|
* `null`), rendered `pages`, and `artifacts`. `decline_reason` is returned
|
|
2272
2364
|
* only when the access token belongs to the document creator.
|
|
2273
2365
|
*
|
|
2366
|
+
* `expand: ['envelope_id']` adds the envelope the document is in and
|
|
2367
|
+
* `expand: ['envelope']` its `{ id, name }` (each `null` outside one).
|
|
2368
|
+
*
|
|
2274
2369
|
* @param documentId - The document to fetch.
|
|
2370
|
+
* @param options - `expand`: `envelope_id` and/or `envelope`.
|
|
2275
2371
|
* @returns The document. Response shape (once `metadata_ready`):
|
|
2276
2372
|
* ```jsonc
|
|
2277
2373
|
* {
|
|
@@ -2300,30 +2396,38 @@ var DocumentResource = class extends BaseResource {
|
|
|
2300
2396
|
* "download_url": "https://…/documents/103ad216…/pages/103ad216…/download"
|
|
2301
2397
|
* }
|
|
2302
2398
|
* ],
|
|
2399
|
+
* "has_contract": false,
|
|
2400
|
+
* "envelope_id": null, // with expand: ['envelope_id']
|
|
2401
|
+
* "envelope": null, // with expand: ['envelope']
|
|
2303
2402
|
* "created_at": "2026-07-19T17:24:43Z",
|
|
2304
2403
|
* "updated_at": "2026-07-19T17:24:46Z"
|
|
2305
2404
|
* }
|
|
2306
2405
|
* ```
|
|
2307
|
-
* @throws {ValidationError} If `documentId` is missing.
|
|
2308
|
-
* @throws {ApiError} `
|
|
2406
|
+
* @throws {ValidationError} If `documentId` is missing or `expand` is unknown.
|
|
2407
|
+
* @throws {ApiError} `403` when a role or OAuth scope refuses it, `404` if the
|
|
2408
|
+
* document does not exist.
|
|
2309
2409
|
*
|
|
2310
2410
|
* @example
|
|
2311
2411
|
* ```ts
|
|
2312
|
-
* const doc = await client.documents.details('103ad216846e6b90710cb9acef59'
|
|
2313
|
-
*
|
|
2412
|
+
* const doc = await client.documents.details('103ad216846e6b90710cb9acef59', {
|
|
2413
|
+
* expand: ['envelope'],
|
|
2414
|
+
* });
|
|
2415
|
+
* console.log(doc.status, doc.envelope?.name);
|
|
2314
2416
|
* ```
|
|
2315
2417
|
*/
|
|
2316
|
-
async details(documentId) {
|
|
2418
|
+
async details(documentId, options = {}) {
|
|
2317
2419
|
const id = this.requireId(documentId, "Document ID");
|
|
2318
|
-
return this.fetchDetails(id);
|
|
2319
|
-
}
|
|
2320
|
-
fetchDetails(id, signal) {
|
|
2420
|
+
return this.fetchDetails(id, void 0, options);
|
|
2421
|
+
}
|
|
2422
|
+
fetchDetails(id, signal, options = {}) {
|
|
2423
|
+
assertRecord(options, "document details options");
|
|
2424
|
+
const params = expandParam(options.expand, DETAIL_EXPANSIONS);
|
|
2425
|
+
const config = {};
|
|
2426
|
+
if (signal) config.signal = signal;
|
|
2427
|
+
if (params.expand) config.params = params;
|
|
2321
2428
|
return this.call(
|
|
2322
2429
|
"Failed to fetch document details",
|
|
2323
|
-
() => this.http.get(
|
|
2324
|
-
`/documents/${this.pathSegment(id, "Document ID")}`,
|
|
2325
|
-
signal ? { signal } : void 0
|
|
2326
|
-
)
|
|
2430
|
+
() => this.http.get(`/documents/${this.pathSegment(id, "Document ID")}`, config)
|
|
2327
2431
|
);
|
|
2328
2432
|
}
|
|
2329
2433
|
/**
|
|
@@ -2331,18 +2435,19 @@ var DocumentResource = class extends BaseResource {
|
|
|
2331
2435
|
* (`GET /documents/{documentId}`).
|
|
2332
2436
|
*
|
|
2333
2437
|
* @param documentId - The document to fetch.
|
|
2438
|
+
* @param options - `expand`, as on {@link DocumentResource.details}.
|
|
2334
2439
|
* @returns The document details (see {@link DocumentResource.details} for
|
|
2335
2440
|
* the response shape).
|
|
2336
2441
|
* @throws {ValidationError} If `documentId` is missing.
|
|
2337
|
-
* @throws {ApiError} `
|
|
2442
|
+
* @throws {ApiError} `403` or `404`, as on {@link DocumentResource.details}.
|
|
2338
2443
|
*
|
|
2339
2444
|
* @example
|
|
2340
2445
|
* ```ts
|
|
2341
2446
|
* const doc = await client.documents.get('103ad216846e6b90710cb9acef59');
|
|
2342
2447
|
* ```
|
|
2343
2448
|
*/
|
|
2344
|
-
async get(documentId) {
|
|
2345
|
-
return this.details(documentId);
|
|
2449
|
+
async get(documentId, options = {}) {
|
|
2450
|
+
return this.details(documentId, options);
|
|
2346
2451
|
}
|
|
2347
2452
|
/**
|
|
2348
2453
|
* Poll {@link DocumentResource.details} until the document reaches a ready
|
|
@@ -2456,10 +2561,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
2456
2561
|
* Download the document thumbnail image
|
|
2457
2562
|
* (`GET /documents/{documentId}/thumbnail`).
|
|
2458
2563
|
*
|
|
2564
|
+
* `artifact: 'certificated'` renders it as it is in the signed document.
|
|
2565
|
+
*
|
|
2459
2566
|
* @param documentId - The document whose thumbnail to fetch.
|
|
2460
|
-
* @
|
|
2461
|
-
* @
|
|
2462
|
-
* @throws {
|
|
2567
|
+
* @param options - `artifact: 'certificated'` for the signed render.
|
|
2568
|
+
* @returns A {@link Buffer} of the thumbnail image bytes (`image/*`).
|
|
2569
|
+
* @throws {ValidationError} If `documentId` is missing or `artifact` is unknown.
|
|
2570
|
+
* @throws {ApiError} `404` if the document, its thumbnail, or (with
|
|
2571
|
+
* `certificated`) its certification does not exist; `503` while the signed
|
|
2572
|
+
* render is still being produced — wait `rateLimit.retryAfter` seconds.
|
|
2463
2573
|
*
|
|
2464
2574
|
* @example
|
|
2465
2575
|
* ```ts
|
|
@@ -2467,28 +2577,29 @@ var DocumentResource = class extends BaseResource {
|
|
|
2467
2577
|
* await fs.promises.writeFile('thumb.jpg', thumb);
|
|
2468
2578
|
* ```
|
|
2469
2579
|
*/
|
|
2470
|
-
async thumbnail(documentId) {
|
|
2580
|
+
async thumbnail(documentId, options = {}) {
|
|
2471
2581
|
const id = this.requireId(documentId, "Document ID");
|
|
2582
|
+
const config = renderConfig(options);
|
|
2472
2583
|
return this.callBinary(
|
|
2473
2584
|
"Failed to download document thumbnail",
|
|
2474
|
-
() => this.http.get(
|
|
2475
|
-
`/documents/${this.pathSegment(id, "Document ID")}/thumbnail`,
|
|
2476
|
-
{ responseType: "arraybuffer" }
|
|
2477
|
-
)
|
|
2585
|
+
() => this.http.get(`/documents/${this.pathSegment(id, "Document ID")}/thumbnail`, config)
|
|
2478
2586
|
);
|
|
2479
2587
|
}
|
|
2480
2588
|
/**
|
|
2481
|
-
* Download a single rendered page
|
|
2589
|
+
* Download a single rendered page image
|
|
2482
2590
|
* (`GET /documents/{documentId}/pages/{pageId}/download`).
|
|
2483
2591
|
*
|
|
2484
2592
|
* The `pageId` comes from a page's `id` in {@link DocumentResource.details}
|
|
2485
|
-
* or {@link DocumentResource.list} (`pages[].id`).
|
|
2593
|
+
* or {@link DocumentResource.list} (`pages[].id`). `artifact: 'certificated'`
|
|
2594
|
+
* renders the page as it is in the signed document.
|
|
2486
2595
|
*
|
|
2487
2596
|
* @param documentId - The document the page belongs to.
|
|
2488
2597
|
* @param pageId - The page to download.
|
|
2489
|
-
* @
|
|
2490
|
-
* @
|
|
2491
|
-
* @throws {
|
|
2598
|
+
* @param options - `artifact: 'certificated'` for the signed render.
|
|
2599
|
+
* @returns A {@link Buffer} of the page image bytes (`image/*`).
|
|
2600
|
+
* @throws {ValidationError} If `documentId` or `pageId` is missing, or `artifact` is unknown.
|
|
2601
|
+
* @throws {ApiError} `404` if the document or page does not exist (or, with
|
|
2602
|
+
* `certificated`, is not certified); `503` while the signed render is pending.
|
|
2492
2603
|
*
|
|
2493
2604
|
* @example
|
|
2494
2605
|
* ```ts
|
|
@@ -2497,14 +2608,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
2497
2608
|
* await fs.promises.writeFile('page-1.jpg', page);
|
|
2498
2609
|
* ```
|
|
2499
2610
|
*/
|
|
2500
|
-
async downloadPage(documentId, pageId) {
|
|
2611
|
+
async downloadPage(documentId, pageId, options = {}) {
|
|
2501
2612
|
const docId = this.requireId(documentId, "Document ID");
|
|
2502
2613
|
const pid = this.requireId(pageId, "Page ID");
|
|
2614
|
+
const config = renderConfig(options);
|
|
2503
2615
|
return this.callBinary(
|
|
2504
2616
|
"Failed to download page",
|
|
2505
2617
|
() => this.http.get(
|
|
2506
2618
|
`/documents/${this.pathSegment(docId, "Document ID")}/pages/${this.pathSegment(pid, "Page ID")}/download`,
|
|
2507
|
-
|
|
2619
|
+
config
|
|
2508
2620
|
)
|
|
2509
2621
|
);
|
|
2510
2622
|
}
|
|
@@ -2521,7 +2633,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2521
2633
|
* @param documentId - The document whose activity log to fetch.
|
|
2522
2634
|
* @param params - Optional pagination and sorting parameters.
|
|
2523
2635
|
* @param params.page - Page number, starting at 1.
|
|
2524
|
-
* @param params.per-page - Entries per page (
|
|
2636
|
+
* @param params.per-page - Entries per page (default 20, at most 50; a larger value answers 50).
|
|
2525
2637
|
* @param params.per_page - Alias for `per-page`; explicit `per-page` wins.
|
|
2526
2638
|
* @param params.sort - `-id` (default, newest first) or `id` (oldest first).
|
|
2527
2639
|
* @returns The requested page of activity entries, or `[]`:
|
|
@@ -2551,7 +2663,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2551
2663
|
* @example
|
|
2552
2664
|
* ```ts
|
|
2553
2665
|
* const events = await client.documents.activities('doc-1', {
|
|
2554
|
-
* page: 2, 'per-page':
|
|
2666
|
+
* page: 2, 'per-page': 50, sort: 'id',
|
|
2555
2667
|
* });
|
|
2556
2668
|
* console.log(events.map((e) => e.event));
|
|
2557
2669
|
* ```
|
|
@@ -2571,7 +2683,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
2571
2683
|
* @param documentId - The document whose activity log to fetch.
|
|
2572
2684
|
* @param params - Optional pagination and sorting parameters.
|
|
2573
2685
|
* @param params.page - Page number, starting at 1.
|
|
2574
|
-
* @param params.per-page - Entries per page (
|
|
2686
|
+
* @param params.per-page - Entries per page (default 20, at most 50; a larger value answers 50).
|
|
2575
2687
|
* @param params.per_page - Alias for `per-page`; explicit `per-page` wins.
|
|
2576
2688
|
* @param params.sort - `-id` (default, newest first) or `id` (oldest first).
|
|
2577
2689
|
* @returns Activity entries and pagination metadata when the server supplies it:
|
|
@@ -2612,13 +2724,16 @@ var DocumentResource = class extends BaseResource {
|
|
|
2612
2724
|
* Only documents in a deletable status can be removed — the API returns
|
|
2613
2725
|
* `400` while the document is still `uploading` / `metadata_processing`
|
|
2614
2726
|
* (await {@link DocumentResource.waitUntilReady} first) or once it has been
|
|
2615
|
-
* certificated.
|
|
2727
|
+
* certificated. Deleting a `pending_signature` or `pending_identity_review`
|
|
2728
|
+
* document cancels it and notifies its signers. A document of an envelope
|
|
2729
|
+
* with an open document cannot be deleted on its own: cancel the envelope.
|
|
2616
2730
|
*
|
|
2617
2731
|
* @param documentId - The document to delete.
|
|
2618
2732
|
* @returns Nothing; resolves when the document is deleted.
|
|
2619
2733
|
* @throws {ValidationError} If `documentId` is missing.
|
|
2620
2734
|
* @throws {ApiError} `400` if the document is not in a deletable status;
|
|
2621
|
-
* `404` if it does not exist
|
|
2735
|
+
* `403` when a role or OAuth scope refuses it; `404` if it does not exist;
|
|
2736
|
+
* `409` (`EnvelopeOpen`) while its envelope has an open document.
|
|
2622
2737
|
*
|
|
2623
2738
|
* @example
|
|
2624
2739
|
* ```ts
|
|
@@ -2923,6 +3038,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
2923
3038
|
if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag.trim()))) {
|
|
2924
3039
|
throw new ValidationError("tags must be an array of non-empty tag names");
|
|
2925
3040
|
}
|
|
3041
|
+
assertCreditCeiling(options.max_total_credits);
|
|
3042
|
+
const config = idempotencyConfig(options.idempotencyKey);
|
|
2926
3043
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
2927
3044
|
const accId = this.accountId(accountId);
|
|
2928
3045
|
const body = {
|
|
@@ -2933,12 +3050,14 @@ var DocumentResource = class extends BaseResource {
|
|
|
2933
3050
|
if (options.expires_at !== void 0) body["expires_at"] = options.expires_at;
|
|
2934
3051
|
if (editorFields !== void 0) body["editor_fields"] = editorFields;
|
|
2935
3052
|
if (options.tags !== void 0) body["tags"] = [...options.tags];
|
|
3053
|
+
if (options.max_total_credits !== void 0) body["max_total_credits"] = options.max_total_credits;
|
|
2936
3054
|
this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
|
|
2937
3055
|
return this.call(
|
|
2938
3056
|
"Failed to create document from template",
|
|
2939
3057
|
() => this.http.post(
|
|
2940
3058
|
`/accounts/${this.pathSegment(accId, "Account ID")}/templates/${this.pathSegment(tmplId, "Template ID")}/documents`,
|
|
2941
|
-
body
|
|
3059
|
+
body,
|
|
3060
|
+
config
|
|
2942
3061
|
)
|
|
2943
3062
|
);
|
|
2944
3063
|
}
|
|
@@ -3072,13 +3191,14 @@ var DocumentResource = class extends BaseResource {
|
|
|
3072
3191
|
* { "code": "uploaded", "deletable": false },
|
|
3073
3192
|
* { "code": "metadata_processing", "deletable": false },
|
|
3074
3193
|
* { "code": "metadata_ready", "deletable": true },
|
|
3075
|
-
* { "code": "
|
|
3076
|
-
* { "code": "expired", "deletable": false },
|
|
3194
|
+
* { "code": "expired", "deletable": true },
|
|
3077
3195
|
* { "code": "certificating", "deletable": false },
|
|
3078
3196
|
* { "code": "certificated", "deletable": false },
|
|
3079
|
-
* { "code": "rejected_by_signer", "deletable":
|
|
3080
|
-
* { "code": "
|
|
3081
|
-
* { "code": "
|
|
3197
|
+
* { "code": "rejected_by_signer", "deletable": true },
|
|
3198
|
+
* { "code": "pending_signature", "deletable": true },
|
|
3199
|
+
* { "code": "pending_identity_review", "deletable": true }, // deleting cancels and notifies signers
|
|
3200
|
+
* { "code": "rejected_by_user", "deletable": true },
|
|
3201
|
+
* { "code": "failed", "deletable": true }
|
|
3082
3202
|
* ]
|
|
3083
3203
|
* ```
|
|
3084
3204
|
* @throws {ApiError} If the API rejects the request.
|
|
@@ -3307,11 +3427,21 @@ function normaliseTemplateSigners(signers) {
|
|
|
3307
3427
|
if (signer.notification_methods !== void 0) {
|
|
3308
3428
|
projected.notification_methods = [...signer.notification_methods];
|
|
3309
3429
|
}
|
|
3430
|
+
if (signer.embedded !== void 0) projected.embedded = signer.embedded;
|
|
3310
3431
|
if (signer.step !== void 0) projected.step = signer.step;
|
|
3311
3432
|
return projected;
|
|
3312
3433
|
});
|
|
3313
3434
|
return normalised;
|
|
3314
3435
|
}
|
|
3436
|
+
var DETAIL_EXPANSIONS = /* @__PURE__ */ new Set(["envelope_id", "envelope"]);
|
|
3437
|
+
function renderConfig(options) {
|
|
3438
|
+
assertRecord(options, "render options");
|
|
3439
|
+
if (options.artifact === void 0) return { responseType: "arraybuffer" };
|
|
3440
|
+
if (options.artifact !== "certificated") {
|
|
3441
|
+
throw new ValidationError("artifact must be certificated when given");
|
|
3442
|
+
}
|
|
3443
|
+
return { responseType: "arraybuffer", params: { artifact: options.artifact } };
|
|
3444
|
+
}
|
|
3315
3445
|
function normaliseTemplateEditorFields(fields) {
|
|
3316
3446
|
if (!Array.isArray(fields)) {
|
|
3317
3447
|
throw new ValidationError("editor_fields must be an array");
|
|
@@ -3592,7 +3722,7 @@ var SignerResource = class extends BaseResource {
|
|
|
3592
3722
|
"Failed to update signer",
|
|
3593
3723
|
() => this.http.put(
|
|
3594
3724
|
`/accounts/${this.pathSegment(id, "Account ID")}/signers/${this.pathSegment(sid, "Signer ID")}`,
|
|
3595
|
-
normaliseSignerPayload(payload)
|
|
3725
|
+
{ ...normaliseSignerPayload(payload), ...clearedContacts(payload) }
|
|
3596
3726
|
)
|
|
3597
3727
|
);
|
|
3598
3728
|
}
|
|
@@ -3718,13 +3848,19 @@ function validateUpdateSignerPayload(payload) {
|
|
|
3718
3848
|
if (payload.full_name !== void 0 && (typeof payload.full_name !== "string" || !payload.full_name.trim())) {
|
|
3719
3849
|
throw new ValidationError("full_name cannot be empty");
|
|
3720
3850
|
}
|
|
3721
|
-
if (payload.email !== void 0 && !isEmail(payload.email)) {
|
|
3851
|
+
if (payload.email !== void 0 && !isClear(payload.email) && !isEmail(payload.email)) {
|
|
3722
3852
|
throw new ValidationError("Invalid email address", { email: payload.email });
|
|
3723
3853
|
}
|
|
3724
|
-
const phone = payload
|
|
3725
|
-
validateOptionalPhone(phone);
|
|
3854
|
+
const phone = updatePhone(payload);
|
|
3855
|
+
if (!isClear(phone)) validateOptionalPhone(phone);
|
|
3726
3856
|
validateOptionalDigits(payload.cpf, "cpf");
|
|
3727
|
-
validateOptionalDigits(payload.government_id, "government_id");
|
|
3857
|
+
if (!isClear(payload.government_id)) validateOptionalDigits(payload.government_id, "government_id");
|
|
3858
|
+
}
|
|
3859
|
+
function isClear(value) {
|
|
3860
|
+
return value === null || value === "";
|
|
3861
|
+
}
|
|
3862
|
+
function updatePhone(payload) {
|
|
3863
|
+
return payload.whatsapp_phone_number !== void 0 ? payload.whatsapp_phone_number : payload.phone;
|
|
3728
3864
|
}
|
|
3729
3865
|
function validateOptionalDigits(value, field) {
|
|
3730
3866
|
if (value === void 0) return;
|
|
@@ -3755,6 +3891,18 @@ function normaliseSignerPayload(payload) {
|
|
|
3755
3891
|
}
|
|
3756
3892
|
return cleanParams(normalised);
|
|
3757
3893
|
}
|
|
3894
|
+
function clearedContacts(payload) {
|
|
3895
|
+
const cleared = {};
|
|
3896
|
+
const candidates = {
|
|
3897
|
+
email: payload.email,
|
|
3898
|
+
whatsapp_phone_number: updatePhone(payload),
|
|
3899
|
+
government_id: payload.government_id
|
|
3900
|
+
};
|
|
3901
|
+
for (const [key, value] of Object.entries(candidates)) {
|
|
3902
|
+
if (isClear(value)) cleared[key] = value;
|
|
3903
|
+
}
|
|
3904
|
+
return cleared;
|
|
3905
|
+
}
|
|
3758
3906
|
|
|
3759
3907
|
// src/support/stats.ts
|
|
3760
3908
|
var MONTH_RE = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
@@ -3875,7 +4023,13 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3875
4023
|
/**
|
|
3876
4024
|
* Fetch a single workspace (`GET /accounts/{accountId}`).
|
|
3877
4025
|
*
|
|
4026
|
+
* `expand: 'signing_features'` adds which signing methods the plan allows
|
|
4027
|
+
* (OAuth: `account:read`). A `false` feature makes creating or estimating an
|
|
4028
|
+
* assignment, template document or envelope with that method answer `403`
|
|
4029
|
+
* (`PlanRestricted`); check it before offering the method.
|
|
4030
|
+
*
|
|
3878
4031
|
* @param accountId - The workspace to fetch.
|
|
4032
|
+
* @param options - `expand: 'signing_features'`.
|
|
3879
4033
|
* @returns The workspace. `primary_color` / `secondary_color` are `null`
|
|
3880
4034
|
* until brand colours are set (6-char hex, no `#`, when present):
|
|
3881
4035
|
* ```jsonc
|
|
@@ -3888,22 +4042,154 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3888
4042
|
* "notification_sender_type": "User",
|
|
3889
4043
|
* "roles": ["owner"],
|
|
3890
4044
|
* "is_delete_allowed": true,
|
|
4045
|
+
* "limits": { "webhook_endpoints": 3 },
|
|
4046
|
+
* "signing_features": { // only with expand: 'signing_features'
|
|
4047
|
+
* "DigitalCertificate": true,
|
|
4048
|
+
* "VerificationIdDocumentFaceMatchBasic": true,
|
|
4049
|
+
* "WhatsappNotification": true,
|
|
4050
|
+
* "VerificationBypass": false,
|
|
4051
|
+
* "Embed": true
|
|
4052
|
+
* },
|
|
3891
4053
|
* "created_at": "2026-05-12T18:05:11Z"
|
|
3892
4054
|
* }
|
|
3893
4055
|
* ```
|
|
3894
|
-
* @throws {ValidationError} If `accountId` is missing.
|
|
3895
|
-
* @throws {ApiError} `
|
|
4056
|
+
* @throws {ValidationError} If `accountId` is missing or `expand` is unknown.
|
|
4057
|
+
* @throws {ApiError} `403` for another workspace's token, `404` if the
|
|
4058
|
+
* workspace does not exist.
|
|
3896
4059
|
*
|
|
3897
4060
|
* @example
|
|
3898
4061
|
* ```ts
|
|
3899
|
-
* const ws = await client.workspaces.get('acc_example');
|
|
4062
|
+
* const ws = await client.workspaces.get('acc_example', { expand: 'signing_features' });
|
|
4063
|
+
* if (ws.signing_features?.Embed) await client.embed.listOrigins();
|
|
3900
4064
|
* ```
|
|
3901
4065
|
*/
|
|
3902
|
-
async get(accountId) {
|
|
4066
|
+
async get(accountId, options = {}) {
|
|
3903
4067
|
const id = this.requireId(accountId, "Account ID");
|
|
4068
|
+
assertRecord(options, "workspace options");
|
|
4069
|
+
if (options.expand !== void 0 && options.expand !== "signing_features") {
|
|
4070
|
+
throw new ValidationError("expand must be signing_features");
|
|
4071
|
+
}
|
|
4072
|
+
const config = options.expand === void 0 ? {} : { params: { expand: options.expand } };
|
|
3904
4073
|
return this.call(
|
|
3905
4074
|
"Failed to fetch workspace",
|
|
3906
|
-
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}
|
|
4075
|
+
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}`, config)
|
|
4076
|
+
);
|
|
4077
|
+
}
|
|
4078
|
+
/**
|
|
4079
|
+
* Read the workspace's plan and balances (`GET /accounts/{accountId}/usage`).
|
|
4080
|
+
*
|
|
4081
|
+
* For a plan and credit meter; prices and payments are not included. Not
|
|
4082
|
+
* available to third-party OAuth applications (`403`), whatever their scopes.
|
|
4083
|
+
*
|
|
4084
|
+
* @param accountId - The workspace to read.
|
|
4085
|
+
* @returns The plan meter:
|
|
4086
|
+
* ```jsonc
|
|
4087
|
+
* {
|
|
4088
|
+
* "plan": "Pro", // null without a current plan
|
|
4089
|
+
* "documents_renewal_date": "2026-12-11",
|
|
4090
|
+
* "balances": {
|
|
4091
|
+
* "documents": { "balance": 97, "limit": 100, "spent": 3 },
|
|
4092
|
+
* "credits": { "balance": 12.5, "limit": null, "spent": 0.9 } // null: unlimited / not cycle-limited
|
|
4093
|
+
* }
|
|
4094
|
+
* }
|
|
4095
|
+
* ```
|
|
4096
|
+
* @throws {ValidationError} If `accountId` is missing.
|
|
4097
|
+
* @throws {ApiError} `403` for an OAuth application token, `404` for an unknown workspace.
|
|
4098
|
+
*
|
|
4099
|
+
* @example
|
|
4100
|
+
* ```ts
|
|
4101
|
+
* const { balances } = await client.workspaces.getUsage('acc_example');
|
|
4102
|
+
* ```
|
|
4103
|
+
*/
|
|
4104
|
+
async getUsage(accountId) {
|
|
4105
|
+
const id = this.requireId(accountId, "Account ID");
|
|
4106
|
+
return this.call(
|
|
4107
|
+
"Failed to fetch account usage",
|
|
4108
|
+
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}/usage`)
|
|
4109
|
+
);
|
|
4110
|
+
}
|
|
4111
|
+
/**
|
|
4112
|
+
* Read which document alerts the workspace sends
|
|
4113
|
+
* (`GET /accounts/{accountId}/notification-policy`).
|
|
4114
|
+
*
|
|
4115
|
+
* Every member can read it; `editable` says whether the caller (an owner)
|
|
4116
|
+
* can change it. Not available to third-party OAuth applications.
|
|
4117
|
+
*
|
|
4118
|
+
* @param accountId - The workspace to read.
|
|
4119
|
+
* @returns The policy; every event key is present:
|
|
4120
|
+
* ```jsonc
|
|
4121
|
+
* {
|
|
4122
|
+
* "editable": true,
|
|
4123
|
+
* "owners_receive_all": false, // owners also get push alerts for members' documents
|
|
4124
|
+
* "events": {
|
|
4125
|
+
* "DocumentCompleted": true, "SignerDeclined": true, "DocumentCancelled": true,
|
|
4126
|
+
* "DocumentAboutToExpire": true, "DocumentExpired": true, "DocumentExpirationReset": true,
|
|
4127
|
+
* "DocumentProcessingFailed": true, "TemplateProcessingFailed": true, "SignerWhatsappFailed": true,
|
|
4128
|
+
* "ContractRenewalNotice": true, "ContractExpiring": true, "ContractExpired": true,
|
|
4129
|
+
* "ContractRenewed": true, "SignerViewed": true, "SignerSigned": true,
|
|
4130
|
+
* "SignerIdentityReviewRequired": true
|
|
4131
|
+
* }
|
|
4132
|
+
* }
|
|
4133
|
+
* ```
|
|
4134
|
+
* @throws {ValidationError} If `accountId` is missing.
|
|
4135
|
+
* @throws {ApiError} `403` for an OAuth application token.
|
|
4136
|
+
*
|
|
4137
|
+
* @example
|
|
4138
|
+
* ```ts
|
|
4139
|
+
* const policy = await client.workspaces.getNotificationPolicy('acc_example');
|
|
4140
|
+
* ```
|
|
4141
|
+
*/
|
|
4142
|
+
async getNotificationPolicy(accountId) {
|
|
4143
|
+
const id = this.requireId(accountId, "Account ID");
|
|
4144
|
+
return this.call(
|
|
4145
|
+
"Failed to fetch notification policy",
|
|
4146
|
+
() => this.http.get(`/accounts/${this.pathSegment(id, "Account ID")}/notification-policy`)
|
|
4147
|
+
);
|
|
4148
|
+
}
|
|
4149
|
+
/**
|
|
4150
|
+
* Change which document alerts the workspace sends
|
|
4151
|
+
* (`PUT /accounts/{accountId}/notification-policy`).
|
|
4152
|
+
*
|
|
4153
|
+
* Owners only. Merges what is sent: an event set to `false` reaches nobody
|
|
4154
|
+
* in the workspace on any channel, whatever each member's preferences. The
|
|
4155
|
+
* identity-review e-mail is always sent, because the signer cannot continue
|
|
4156
|
+
* without it.
|
|
4157
|
+
*
|
|
4158
|
+
* @param accountId - The workspace to change.
|
|
4159
|
+
* @param payload - `events` keys to change and/or `owners_receive_all`.
|
|
4160
|
+
* @returns The full policy, as {@link WorkspaceResource.getNotificationPolicy} returns.
|
|
4161
|
+
* @throws {ValidationError} If nothing would change or a value is not a boolean.
|
|
4162
|
+
* @throws {ApiError} `400` for an unknown event code, `403` for a non-owner or
|
|
4163
|
+
* an OAuth application token.
|
|
4164
|
+
*
|
|
4165
|
+
* @example
|
|
4166
|
+
* ```ts
|
|
4167
|
+
* await client.workspaces.updateNotificationPolicy('acc_example', {
|
|
4168
|
+
* events: { SignerViewed: false },
|
|
4169
|
+
* owners_receive_all: true,
|
|
4170
|
+
* });
|
|
4171
|
+
* ```
|
|
4172
|
+
*/
|
|
4173
|
+
async updateNotificationPolicy(accountId, payload) {
|
|
4174
|
+
const id = this.requireId(accountId, "Account ID");
|
|
4175
|
+
assertRecord(payload, "notification policy");
|
|
4176
|
+
const body = {};
|
|
4177
|
+
if (payload.events !== void 0) {
|
|
4178
|
+
assertBooleanMap(payload.events, "events");
|
|
4179
|
+
body["events"] = { ...payload.events };
|
|
4180
|
+
}
|
|
4181
|
+
if (payload.owners_receive_all !== void 0) {
|
|
4182
|
+
if (typeof payload.owners_receive_all !== "boolean") {
|
|
4183
|
+
throw new ValidationError("owners_receive_all must be a boolean");
|
|
4184
|
+
}
|
|
4185
|
+
body["owners_receive_all"] = payload.owners_receive_all;
|
|
4186
|
+
}
|
|
4187
|
+
if (Object.keys(body).length === 0) {
|
|
4188
|
+
throw new ValidationError("notification policy update must change events or owners_receive_all");
|
|
4189
|
+
}
|
|
4190
|
+
return this.call(
|
|
4191
|
+
"Failed to update notification policy",
|
|
4192
|
+
() => this.http.put(`/accounts/${this.pathSegment(id, "Account ID")}/notification-policy`, body)
|
|
3907
4193
|
);
|
|
3908
4194
|
}
|
|
3909
4195
|
/**
|
|
@@ -3912,13 +4198,13 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3912
4198
|
* Request body/query: none.
|
|
3913
4199
|
*
|
|
3914
4200
|
* @param accountId - Account whose public branding should be returned.
|
|
3915
|
-
* @returns The unwrapped theme:
|
|
4201
|
+
* @returns The unwrapped theme. Colours fall back to the platform default:
|
|
3916
4202
|
* ```jsonc
|
|
3917
4203
|
* {
|
|
3918
4204
|
* "account_name": "Acme Inc.",
|
|
3919
|
-
* "primary_color": "aabbcc",
|
|
3920
|
-
* "secondary_color": "112233",
|
|
3921
|
-
* "logo": "https://api.assinafy.com.br/v1/accounts/account-id/logo"
|
|
4205
|
+
* "primary_color": "aabbcc", // button background
|
|
4206
|
+
* "secondary_color": "112233", // button text
|
|
4207
|
+
* "logo": "https://api.assinafy.com.br/v1/accounts/account-id/logo" // null without a logo
|
|
3922
4208
|
* }
|
|
3923
4209
|
* ```
|
|
3924
4210
|
* @throws {ValidationError} If `accountId` is empty.
|
|
@@ -4832,31 +5118,98 @@ var WebhookResource = class extends BaseResource {
|
|
|
4832
5118
|
/**
|
|
4833
5119
|
* Replace an endpoint's signing secret and return the new one
|
|
4834
5120
|
* (`POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret/rotate`).
|
|
4835
|
-
*
|
|
4836
|
-
*
|
|
4837
|
-
*
|
|
5121
|
+
*
|
|
5122
|
+
* Without `keep_previous` the old secret stops at once: update the receiver
|
|
5123
|
+
* immediately. With `keep_previous: true` both secrets sign deliveries for
|
|
5124
|
+
* 24 hours (each delivery carries one `v1,` entry per secret, which
|
|
5125
|
+
* `webhookVerifier.verifySignature()` already accepts), so the receiver can
|
|
5126
|
+
* switch without dropping events; rotating again ends the overlap. OAuth
|
|
5127
|
+
* tokens need the `webhooks:write` scope.
|
|
4838
5128
|
*
|
|
4839
5129
|
* @param endpointId - The endpoint ID.
|
|
4840
5130
|
* @param accountId - Override the client's default account ID.
|
|
5131
|
+
* @param options - `keep_previous`: keep the old secret signing for 24 hours.
|
|
4841
5132
|
* @returns The new secret:
|
|
4842
5133
|
* ```jsonc
|
|
4843
|
-
* {
|
|
5134
|
+
* {
|
|
5135
|
+
* "secret": "whsec_bmV3LWtleS1iYXNlNjQtZW5jb2RlZA==",
|
|
5136
|
+
* "previous_secret_expires_at": "2026-11-12T14:00:00Z" // only with keep_previous: true
|
|
5137
|
+
* }
|
|
4844
5138
|
* ```
|
|
4845
|
-
* @throws {ValidationError} If `endpointId` is empty
|
|
4846
|
-
* available.
|
|
5139
|
+
* @throws {ValidationError} If `endpointId` is empty, no account ID is
|
|
5140
|
+
* available, or `keep_previous` is not a boolean.
|
|
4847
5141
|
* @throws {ApiError} `400` when signing is disabled on the endpoint; `404`
|
|
4848
5142
|
* if it does not exist.
|
|
4849
5143
|
*
|
|
4850
5144
|
* @example
|
|
4851
5145
|
* ```ts
|
|
4852
|
-
* const { secret } = await client.webhooks.rotateEndpointSecret(endpoint.id
|
|
5146
|
+
* const { secret } = await client.webhooks.rotateEndpointSecret(endpoint.id, undefined, {
|
|
5147
|
+
* keep_previous: true,
|
|
5148
|
+
* });
|
|
4853
5149
|
* await secretStore.put('assinafy-webhook-secret', secret);
|
|
4854
5150
|
* ```
|
|
4855
5151
|
*/
|
|
4856
|
-
async rotateEndpointSecret(endpointId, accountId) {
|
|
5152
|
+
async rotateEndpointSecret(endpointId, accountId, options = {}) {
|
|
5153
|
+
assertRecord(options, "rotation options");
|
|
5154
|
+
if (options.keep_previous !== void 0 && typeof options.keep_previous !== "boolean") {
|
|
5155
|
+
throw new ValidationError("keep_previous must be a boolean");
|
|
5156
|
+
}
|
|
4857
5157
|
const path2 = `${this.endpointPath(endpointId, accountId)}/secret/rotate`;
|
|
5158
|
+
const body = options.keep_previous === void 0 ? void 0 : { keep_previous: options.keep_previous };
|
|
4858
5159
|
this.logger.info("Rotating webhook endpoint secret");
|
|
4859
|
-
return this.call("Failed to rotate webhook endpoint secret", () => this.http.post(path2));
|
|
5160
|
+
return this.call("Failed to rotate webhook endpoint secret", () => this.http.post(path2, body));
|
|
5161
|
+
}
|
|
5162
|
+
/**
|
|
5163
|
+
* Send the endpoint one `webhook_test` event now
|
|
5164
|
+
* (`POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/test`).
|
|
5165
|
+
*
|
|
5166
|
+
* Signed and sent like any delivery, to this endpoint only, also while it is
|
|
5167
|
+
* paused or inactive; it neither lifts nor counts toward a pause. The
|
|
5168
|
+
* endpoint has 10 seconds to answer. The event's `payload` and `origin` are
|
|
5169
|
+
* `null`, and its `subject`/`object` describe the endpoint (never its
|
|
5170
|
+
* secret). Up to 10 tests per user every 10 minutes; OAuth tokens need
|
|
5171
|
+
* `webhooks:write`.
|
|
5172
|
+
*
|
|
5173
|
+
* @param endpointId - The endpoint ID.
|
|
5174
|
+
* @param accountId - Override the client's default account ID.
|
|
5175
|
+
* @returns The delivery attempt, also listed in the delivery history:
|
|
5176
|
+
* ```jsonc
|
|
5177
|
+
* {
|
|
5178
|
+
* "resource": "activity_dispatching_history",
|
|
5179
|
+
* "id": "1052b3c4d5e6f7a8b9c0d1e2f3a4",
|
|
5180
|
+
* "event": "webhook_test",
|
|
5181
|
+
* "activity_id": 8240001,
|
|
5182
|
+
* "endpoint_id": "1052b0e1f2a3b4c5d6e7f8a9b0c1",
|
|
5183
|
+
* "endpoint": "https://hooks.example.com/assinafy",
|
|
5184
|
+
* "payload": { // the event as delivered
|
|
5185
|
+
* "id": 8240001, "event": "webhook_test", "payload": null, "origin": null,
|
|
5186
|
+
* "account_id": "acc_example", "subject": { "type": "ActivityEventSubscription" }
|
|
5187
|
+
* },
|
|
5188
|
+
* "delivered": true,
|
|
5189
|
+
* "webhook_id": "msg_2v9TQ0a7",
|
|
5190
|
+
* "attempt": 1,
|
|
5191
|
+
* "kind": "manual",
|
|
5192
|
+
* "will_retry": false,
|
|
5193
|
+
* "duration_ms": 182,
|
|
5194
|
+
* "http_status": 200,
|
|
5195
|
+
* "response_body": "ok",
|
|
5196
|
+
* "error": null,
|
|
5197
|
+
* "created_at": "2026-11-11T14:00:00Z",
|
|
5198
|
+
* "updated_at": "2026-11-11T14:00:00Z"
|
|
5199
|
+
* }
|
|
5200
|
+
* ```
|
|
5201
|
+
* @throws {ValidationError} If `endpointId` is empty or no account ID is available.
|
|
5202
|
+
* @throws {ApiError} `404` for an unknown endpoint, `429` past 10 tests in 10 minutes.
|
|
5203
|
+
*
|
|
5204
|
+
* @example
|
|
5205
|
+
* ```ts
|
|
5206
|
+
* const attempt = await client.webhooks.testEndpoint(endpoint.id);
|
|
5207
|
+
* if (!attempt.delivered) console.warn(attempt.http_status, attempt.error);
|
|
5208
|
+
* ```
|
|
5209
|
+
*/
|
|
5210
|
+
async testEndpoint(endpointId, accountId) {
|
|
5211
|
+
const path2 = `${this.endpointPath(endpointId, accountId)}/test`;
|
|
5212
|
+
return this.call("Failed to send webhook test delivery", () => this.http.post(path2));
|
|
4860
5213
|
}
|
|
4861
5214
|
endpointsPath(accountId) {
|
|
4862
5215
|
const id = this.pathSegment(this.accountId(accountId), "Account ID");
|
|
@@ -6143,7 +6496,10 @@ var OAuthResource = class extends BaseResource {
|
|
|
6143
6496
|
* `['documents:read', 'documents:write', 'offline_access']`. Ask for the
|
|
6144
6497
|
* minimum: the user approves all of them or none. Add `offline_access` to
|
|
6145
6498
|
* receive a refresh token and `openid` to receive an `id_token`.
|
|
6146
|
-
* `
|
|
6499
|
+
* `account:read` reads the workspace profile, theme, logo, KPIs, webhook
|
|
6500
|
+
* subscription and endpoints, and its signing features; `webhooks:write`
|
|
6501
|
+
* changes the subscription, manages endpoints, re-sends and tests
|
|
6502
|
+
* deliveries, and can obtain a new signing secret (signing on, or rotation).
|
|
6147
6503
|
* @param options.authorizationEndpoint - Skip discovery by supplying the
|
|
6148
6504
|
* endpoint yourself. Defaults to the discovered
|
|
6149
6505
|
* `authorization_endpoint`.
|
|
@@ -6369,6 +6725,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
6369
6725
|
* @throws {OAuthError} `invalid_grant` for a spent, expired, replayed or
|
|
6370
6726
|
* mismatched code; `invalid_client` for a bad `client_id`/`client_secret`;
|
|
6371
6727
|
* `invalid_target` for a `resource` mismatch.
|
|
6728
|
+
* @throws {ApiError} `429` when the caller's IP is rate limited; token calls
|
|
6729
|
+
* are never retried automatically, so wait `rateLimit.retryAfter` seconds.
|
|
6372
6730
|
*
|
|
6373
6731
|
* @example
|
|
6374
6732
|
* ```ts
|
|
@@ -6443,6 +6801,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
6443
6801
|
* @throws {OAuthError} `invalid_grant` when the refresh token was already
|
|
6444
6802
|
* used, expired, or the user reconnected with different permissions — ask
|
|
6445
6803
|
* the user to reconnect. `invalid_client` for bad client credentials.
|
|
6804
|
+
* @throws {ApiError} `429` when the caller's IP is rate limited (not retried
|
|
6805
|
+
* automatically: a replayed refresh token ends the connection).
|
|
6446
6806
|
*
|
|
6447
6807
|
* @example
|
|
6448
6808
|
* ```ts
|
|
@@ -6727,6 +7087,11 @@ function toSearchParams(params) {
|
|
|
6727
7087
|
|
|
6728
7088
|
// src/resources/fields.ts
|
|
6729
7089
|
var FieldsResource = class extends BaseResource {
|
|
7090
|
+
signerHttp;
|
|
7091
|
+
constructor(http, defaultAccountId, logger, publicHttp) {
|
|
7092
|
+
super(http, defaultAccountId, logger);
|
|
7093
|
+
this.signerHttp = withoutCredentials(publicHttp ?? http);
|
|
7094
|
+
}
|
|
6730
7095
|
/**
|
|
6731
7096
|
* Create a field definition (`POST /accounts/{accountId}/fields`).
|
|
6732
7097
|
*
|
|
@@ -6978,9 +7343,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
6978
7343
|
* Validate a single value against a field definition
|
|
6979
7344
|
* (`POST /accounts/{accountId}/fields/{fieldId}/validate`).
|
|
6980
7345
|
*
|
|
6981
|
-
*
|
|
6982
|
-
*
|
|
6983
|
-
*
|
|
7346
|
+
* Without `signerAccessCode` the call uses the workspace credentials. With
|
|
7347
|
+
* it, the code is sent as the `signer-access-code` query on the
|
|
7348
|
+
* credential-free transport, as a custom signing UI does.
|
|
6984
7349
|
*
|
|
6985
7350
|
* Request body (`application/json`):
|
|
6986
7351
|
* ```jsonc
|
|
@@ -6992,9 +7357,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
6992
7357
|
* @param fieldId - The field definition to validate against.
|
|
6993
7358
|
* @param value - The value to check (validated against the field's
|
|
6994
7359
|
* type/regex). Sent as `{ value }` in the request body.
|
|
6995
|
-
* @param options - Account override and optional
|
|
7360
|
+
* @param options - Account override and optional `signerAccessCode`.
|
|
6996
7361
|
* @param options.accountId - Override the client's default workspace.
|
|
6997
|
-
* @param options.signerAccessCode -
|
|
7362
|
+
* @param options.signerAccessCode - Authenticate as the signer instead of the workspace.
|
|
6998
7363
|
* @returns The validation result. Response shape:
|
|
6999
7364
|
* ```jsonc
|
|
7000
7365
|
* {
|
|
@@ -7005,7 +7370,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
7005
7370
|
* ```
|
|
7006
7371
|
* @throws {ValidationError} If `fieldId` or the account ID is missing, or
|
|
7007
7372
|
* `value` is `undefined`.
|
|
7008
|
-
* @throws {ApiError}
|
|
7373
|
+
* @throws {ApiError} `400` for a malformed request, `403` when the code or
|
|
7374
|
+
* credentials cannot reach the workspace, `404` for a field outside it, `410`
|
|
7375
|
+
* when the signer's access code is closed.
|
|
7009
7376
|
*
|
|
7010
7377
|
* @example
|
|
7011
7378
|
* ```ts
|
|
@@ -7027,7 +7394,7 @@ var FieldsResource = class extends BaseResource {
|
|
|
7027
7394
|
const params = options.signerAccessCode ? { "signer-access-code": options.signerAccessCode } : void 0;
|
|
7028
7395
|
return this.call(
|
|
7029
7396
|
"Failed to validate field value",
|
|
7030
|
-
() => this.
|
|
7397
|
+
() => this.transportFor(options.signerAccessCode).post(
|
|
7031
7398
|
`/accounts/${this.pathSegment(id, "Account ID")}/fields/${this.pathSegment(fid, "Field ID")}/validate`,
|
|
7032
7399
|
{ value },
|
|
7033
7400
|
{ params }
|
|
@@ -7039,9 +7406,8 @@ var FieldsResource = class extends BaseResource {
|
|
|
7039
7406
|
* (`POST /accounts/{accountId}/fields/validate-multiple`).
|
|
7040
7407
|
*
|
|
7041
7408
|
* The request body is the array of `{ field_id, value }` entries itself
|
|
7042
|
-
* (not wrapped in an object).
|
|
7043
|
-
*
|
|
7044
|
-
* {@link FieldsResource.validate}.
|
|
7409
|
+
* (not wrapped in an object). `signerAccessCode` authenticates as described
|
|
7410
|
+
* on {@link FieldsResource.validate}.
|
|
7045
7411
|
*
|
|
7046
7412
|
* Request body (`application/json`):
|
|
7047
7413
|
* ```jsonc
|
|
@@ -7054,9 +7420,9 @@ var FieldsResource = class extends BaseResource {
|
|
|
7054
7420
|
* ```
|
|
7055
7421
|
*
|
|
7056
7422
|
* @param entries - Non-empty array of `{ field_id, value }` pairs.
|
|
7057
|
-
* @param options - Account override and optional
|
|
7423
|
+
* @param options - Account override and optional `signerAccessCode`.
|
|
7058
7424
|
* @param options.accountId - Override the client's default workspace.
|
|
7059
|
-
* @param options.signerAccessCode -
|
|
7425
|
+
* @param options.signerAccessCode - Authenticate as the signer instead of the workspace.
|
|
7060
7426
|
* @returns One validation result per entry. Response shape:
|
|
7061
7427
|
* ```jsonc
|
|
7062
7428
|
* [
|
|
@@ -7065,7 +7431,7 @@ var FieldsResource = class extends BaseResource {
|
|
|
7065
7431
|
* ]
|
|
7066
7432
|
* ```
|
|
7067
7433
|
* @throws {ValidationError} If `entries` is empty or the account ID is missing.
|
|
7068
|
-
* @throws {ApiError}
|
|
7434
|
+
* @throws {ApiError} `400`, `403`, `404` or `410`, as for {@link FieldsResource.validate}.
|
|
7069
7435
|
*
|
|
7070
7436
|
* @example
|
|
7071
7437
|
* ```ts
|
|
@@ -7093,7 +7459,7 @@ var FieldsResource = class extends BaseResource {
|
|
|
7093
7459
|
}));
|
|
7094
7460
|
return this.call(
|
|
7095
7461
|
"Failed to validate field values",
|
|
7096
|
-
() => this.
|
|
7462
|
+
() => this.transportFor(options.signerAccessCode).post(
|
|
7097
7463
|
`/accounts/${this.pathSegment(id, "Account ID")}/fields/validate-multiple`,
|
|
7098
7464
|
body,
|
|
7099
7465
|
{ params }
|
|
@@ -7127,6 +7493,10 @@ var FieldsResource = class extends BaseResource {
|
|
|
7127
7493
|
async listTypes() {
|
|
7128
7494
|
return this.call("Failed to list field types", () => this.http.get("/field-types"));
|
|
7129
7495
|
}
|
|
7496
|
+
/** A signer access code must never travel with the workspace credentials. */
|
|
7497
|
+
transportFor(signerAccessCode) {
|
|
7498
|
+
return signerAccessCode === void 0 ? this.http : this.signerHttp;
|
|
7499
|
+
}
|
|
7130
7500
|
};
|
|
7131
7501
|
function validateFieldPayload(payload) {
|
|
7132
7502
|
if (payload.regex !== void 0 && payload.regex !== null && typeof payload.regex !== "string") {
|
|
@@ -7159,11 +7529,17 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7159
7529
|
* (`GET /signers/{signer_id}/document?signer-access-code=…`).
|
|
7160
7530
|
*
|
|
7161
7531
|
* The signer-side counterpart of {@link DocumentResource.details}, authorised
|
|
7162
|
-
* by the signer's access code rather than the workspace API key.
|
|
7532
|
+
* by the signer's access code rather than the workspace API key. Unlike
|
|
7533
|
+
* {@link SignerDocumentsResource.getAssignment} it does not record a view and
|
|
7534
|
+
* answers before a certificate or identity-check signer confirms their data,
|
|
7535
|
+
* so a link learns its envelope here.
|
|
7163
7536
|
*
|
|
7164
7537
|
* @param signerId - The signer whose current document is fetched.
|
|
7165
7538
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7166
|
-
* @
|
|
7539
|
+
* @param options - `expand: ['envelope']` adds the code's envelope (`{ id, name }`, or `null`).
|
|
7540
|
+
* @returns The {@link ISigningDocument}. Once the code is closed (30 minutes
|
|
7541
|
+
* after the signer is done) only `id`, `name`, `status`, `current_signer`,
|
|
7542
|
+
* `certified_copy` and `envelope` remain, with `is_signer_access_closed: true`:
|
|
7167
7543
|
* ```jsonc
|
|
7168
7544
|
* {
|
|
7169
7545
|
* "resource": "document",
|
|
@@ -7186,26 +7562,38 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7186
7562
|
* { "id": "103acccd5c73...", "number": 1, "height": 1651, "width": 1275,
|
|
7187
7563
|
* "download_url": "https://api.assinafy.com.br/v1/documents/103acccd.../pages/103acccd5c73.../download" }
|
|
7188
7564
|
* ],
|
|
7565
|
+
* "current_signer": {
|
|
7566
|
+
* "id": "19e6b92e7895332ed9708535d8c",
|
|
7567
|
+
* "full_name": "Example Signer",
|
|
7568
|
+
* "email": "signer@example.com",
|
|
7569
|
+
* "verification_method": "Email",
|
|
7570
|
+
* "notification_methods": ["Email"],
|
|
7571
|
+
* "completed": false
|
|
7572
|
+
* },
|
|
7573
|
+
* "is_signer_access_closed": false,
|
|
7574
|
+
* "certified_copy": { "available": false, "notification_method": "Email", "resends_left": null },
|
|
7575
|
+
* "envelope": { "id": "1052a1f0c3d4e5f6a7b8c9d0e1f2", "name": "Admission kit" }, // with expand
|
|
7189
7576
|
* "created_at": "2026-07-19T14:56:54Z",
|
|
7190
7577
|
* "updated_at": "2026-07-19T14:56:56Z"
|
|
7191
7578
|
* }
|
|
7192
7579
|
* ```
|
|
7193
7580
|
* @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
|
|
7194
|
-
* @throws {ApiError}
|
|
7581
|
+
* @throws {ApiError} `400` while the signer's step has not started, `401` for an
|
|
7582
|
+
* invalid code, `404` for an unknown signer.
|
|
7195
7583
|
*
|
|
7196
7584
|
* @example
|
|
7197
7585
|
* ```ts
|
|
7198
|
-
* const doc = await client.signerDocuments.getCurrent(signerId, accessCode);
|
|
7199
|
-
* console.log(doc.
|
|
7586
|
+
* const doc = await client.signerDocuments.getCurrent(signerId, accessCode, { expand: ['envelope'] });
|
|
7587
|
+
* if (doc.is_signer_access_closed) console.log(doc.certified_copy.available);
|
|
7200
7588
|
* ```
|
|
7201
7589
|
*/
|
|
7202
|
-
async getCurrent(signerId, signerAccessCode) {
|
|
7590
|
+
async getCurrent(signerId, signerAccessCode, options = {}) {
|
|
7203
7591
|
const sid = this.requireId(signerId, "Signer ID");
|
|
7204
7592
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7205
7593
|
return this.call(
|
|
7206
7594
|
"Failed to fetch current signer document",
|
|
7207
7595
|
() => this.http.get(`/signers/${this.pathSegment(sid, "Signer ID")}/document`, {
|
|
7208
|
-
params: { "signer-access-code": code }
|
|
7596
|
+
params: { "signer-access-code": code, ...signingReadParams(options) }
|
|
7209
7597
|
})
|
|
7210
7598
|
);
|
|
7211
7599
|
}
|
|
@@ -7220,9 +7608,10 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7220
7608
|
*
|
|
7221
7609
|
* @param signerId - The signer whose documents are listed.
|
|
7222
7610
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7223
|
-
* @param params -
|
|
7224
|
-
*
|
|
7225
|
-
* with pagination in `meta
|
|
7611
|
+
* @param params - `envelope_id` (only that envelope's documents) and pagination:
|
|
7612
|
+
* `page`, `per-page` (also accepts `per_page`).
|
|
7613
|
+
* @returns Matching documents with pagination in `meta`. Each carries its
|
|
7614
|
+
* `assignment` (without `signing_urls` when read with a code) and `pages`:
|
|
7226
7615
|
* ```jsonc
|
|
7227
7616
|
* {
|
|
7228
7617
|
* "data": [
|
|
@@ -7246,11 +7635,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7246
7635
|
* }
|
|
7247
7636
|
* ```
|
|
7248
7637
|
* @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
|
|
7249
|
-
* @throws {ApiError}
|
|
7638
|
+
* @throws {ApiError} `400` for a non-text `envelope_id` or a pending step,
|
|
7639
|
+
* `403` for another signer's code, `410` once the code is closed.
|
|
7250
7640
|
*
|
|
7251
7641
|
* @example
|
|
7252
7642
|
* ```ts
|
|
7253
7643
|
* const { data, meta } = await client.signerDocuments.list(signerId, accessCode, {
|
|
7644
|
+
* envelope_id: envelopeId,
|
|
7254
7645
|
* 'per-page': 20,
|
|
7255
7646
|
* });
|
|
7256
7647
|
* ```
|
|
@@ -7277,8 +7668,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7277
7668
|
* @param signerId - The signer whose documents are searched.
|
|
7278
7669
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7279
7670
|
* @param search - Free-text term matched against the document name.
|
|
7280
|
-
* @
|
|
7281
|
-
*
|
|
7671
|
+
* @param params - `envelope_id`: only that envelope's documents.
|
|
7672
|
+
* @returns Matching documents for that signer, with pagination in `meta`:
|
|
7282
7673
|
* ```jsonc
|
|
7283
7674
|
* {
|
|
7284
7675
|
* "data": [
|
|
@@ -7302,7 +7693,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7302
7693
|
* }
|
|
7303
7694
|
* ```
|
|
7304
7695
|
* @throws {ValidationError} If `signerId` or `signerAccessCode` is missing.
|
|
7305
|
-
* @throws {ApiError}
|
|
7696
|
+
* @throws {ApiError} `400`, `403` or `410`, as for {@link SignerDocumentsResource.list}.
|
|
7306
7697
|
*
|
|
7307
7698
|
* @example
|
|
7308
7699
|
* ```ts
|
|
@@ -7313,16 +7704,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7313
7704
|
* );
|
|
7314
7705
|
* ```
|
|
7315
7706
|
*/
|
|
7316
|
-
async search(signerId, signerAccessCode, search) {
|
|
7707
|
+
async search(signerId, signerAccessCode, search, params = {}) {
|
|
7317
7708
|
const sid = this.requireId(signerId, "Signer ID");
|
|
7318
7709
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7319
|
-
if (search !== void 0 && typeof search !== "string") {
|
|
7320
|
-
throw new ValidationError("search must be a string");
|
|
7321
|
-
}
|
|
7322
7710
|
return this.callList(
|
|
7323
7711
|
"Failed to search signer documents",
|
|
7324
7712
|
() => this.http.get(`/signers/${this.pathSegment(sid, "Signer ID")}/documents/search`, {
|
|
7325
|
-
params:
|
|
7713
|
+
params: { "signer-access-code": code, ...searchParams(search, params) }
|
|
7326
7714
|
})
|
|
7327
7715
|
);
|
|
7328
7716
|
}
|
|
@@ -7335,8 +7723,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7335
7723
|
* code. No `signer-access-code` is sent.
|
|
7336
7724
|
*
|
|
7337
7725
|
* @param signerId - The signer whose documents are listed.
|
|
7338
|
-
* @param params -
|
|
7339
|
-
* @returns Documents in the
|
|
7726
|
+
* @param params - `envelope_id` and pagination: `page`, `per-page` (also accepts `per_page`).
|
|
7727
|
+
* @returns Documents in the {@link IDocumentListItem} shape, with
|
|
7340
7728
|
* pagination in `meta` (same shape as {@link SignerDocumentsResource.list}):
|
|
7341
7729
|
* ```jsonc
|
|
7342
7730
|
* {
|
|
@@ -7345,7 +7733,8 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7345
7733
|
* }
|
|
7346
7734
|
* ```
|
|
7347
7735
|
* @throws {ValidationError} If `signerId` is missing.
|
|
7348
|
-
* @throws {ApiError} `401` if the workspace credentials are rejected
|
|
7736
|
+
* @throws {ApiError} `401` if the workspace credentials are rejected, `403` when a
|
|
7737
|
+
* role or OAuth scope refuses it, `404` for a signer outside the workspace.
|
|
7349
7738
|
*
|
|
7350
7739
|
* @example
|
|
7351
7740
|
* ```ts
|
|
@@ -7354,11 +7743,11 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7354
7743
|
*/
|
|
7355
7744
|
async listAsWorkspace(signerId, params = {}) {
|
|
7356
7745
|
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7746
|
+
const query = cleanListParams(params);
|
|
7747
|
+
delete query["signer-access-code"];
|
|
7357
7748
|
return this.callList(
|
|
7358
7749
|
"Failed to list signer documents",
|
|
7359
|
-
() => this.workspaceHttp.get(`/signers/${sid}/documents`, {
|
|
7360
|
-
params: cleanListParams(params)
|
|
7361
|
-
})
|
|
7750
|
+
() => this.workspaceHttp.get(`/signers/${sid}/documents`, { params: query })
|
|
7362
7751
|
);
|
|
7363
7752
|
}
|
|
7364
7753
|
/**
|
|
@@ -7371,53 +7760,45 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7371
7760
|
*
|
|
7372
7761
|
* @param signerId - The signer whose documents are searched.
|
|
7373
7762
|
* @param search - Free-text term matched against the document name.
|
|
7763
|
+
* @param params - `envelope_id`: only that envelope's documents.
|
|
7374
7764
|
* @returns Matching documents with pagination in `meta`, as
|
|
7375
7765
|
* {@link SignerDocumentsResource.listAsWorkspace} returns.
|
|
7376
7766
|
* @throws {ValidationError} If `signerId` is missing or `search` is not a string.
|
|
7377
|
-
* @throws {ApiError} `401`
|
|
7767
|
+
* @throws {ApiError} `401`, `403` or `404`, as for {@link SignerDocumentsResource.listAsWorkspace}.
|
|
7378
7768
|
*
|
|
7379
7769
|
* @example
|
|
7380
7770
|
* ```ts
|
|
7381
7771
|
* const { data } = await client.signerDocuments.searchAsWorkspace(signerId, 'agreement');
|
|
7382
7772
|
* ```
|
|
7383
7773
|
*/
|
|
7384
|
-
async searchAsWorkspace(signerId, search) {
|
|
7774
|
+
async searchAsWorkspace(signerId, search, params = {}) {
|
|
7385
7775
|
const sid = this.pathSegment(signerId, "Signer ID");
|
|
7386
|
-
if (search !== void 0 && typeof search !== "string") {
|
|
7387
|
-
throw new ValidationError("search must be a string");
|
|
7388
|
-
}
|
|
7389
7776
|
return this.callList(
|
|
7390
7777
|
"Failed to search signer documents",
|
|
7391
7778
|
() => this.workspaceHttp.get(`/signers/${sid}/documents/search`, {
|
|
7392
|
-
params:
|
|
7779
|
+
params: searchParams(search, params)
|
|
7393
7780
|
})
|
|
7394
7781
|
);
|
|
7395
7782
|
}
|
|
7396
7783
|
/**
|
|
7397
|
-
* Download
|
|
7398
|
-
* (`GET /signers/{signer_id}/documents/{document_id}/download/
|
|
7784
|
+
* Download the original PDF a signer is asked to sign
|
|
7785
|
+
* (`GET /signers/{signer_id}/documents/{document_id}/download/original`).
|
|
7399
7786
|
*
|
|
7400
|
-
*
|
|
7401
|
-
*
|
|
7402
|
-
*
|
|
7403
|
-
*
|
|
7404
|
-
*
|
|
7405
|
-
* `pades` exists only when the document had a Digital Certificate signer.
|
|
7406
|
-
* A bundle contains original, certificated, and certificate-page artifacts,
|
|
7407
|
-
* plus PAdES when present.
|
|
7787
|
+
* Only `original` is available with an access code; the certified copy is
|
|
7788
|
+
* sent to the signer instead (see {@link SignerDocumentsResource.resendCertifiedCopy}).
|
|
7789
|
+
* The API redirects a request it cannot serve to its expired-link page, so
|
|
7790
|
+
* the SDK does not follow redirects here: that case throws instead of
|
|
7791
|
+
* returning the page's HTML.
|
|
7408
7792
|
*
|
|
7409
7793
|
* @param signerId - The signer requesting the download.
|
|
7410
7794
|
* @param documentId - The document to download.
|
|
7411
|
-
* @param artifactName -
|
|
7412
|
-
*
|
|
7413
|
-
* @
|
|
7414
|
-
*
|
|
7415
|
-
* @
|
|
7416
|
-
*
|
|
7417
|
-
*
|
|
7418
|
-
* `artifactName` is not one of the five documented names, or an explicitly
|
|
7419
|
-
* supplied legacy `signerAccessCode` is blank.
|
|
7420
|
-
* @throws {ApiError} `404` if the artifact does not exist yet.
|
|
7795
|
+
* @param artifactName - `original`, the only artifact a signer can download.
|
|
7796
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7797
|
+
* @returns The PDF bytes as a Node `Buffer`.
|
|
7798
|
+
* @throws {ValidationError} If an ID or the code is missing, or the artifact is not `original`.
|
|
7799
|
+
* @throws {ApiError} `302` when the code is missing or closed, `400` while the
|
|
7800
|
+
* signer's step has not started, `403` for another artifact, `404` for a
|
|
7801
|
+
* document the code does not reach, `410` once the code is closed.
|
|
7421
7802
|
*
|
|
7422
7803
|
* @example
|
|
7423
7804
|
* ```ts
|
|
@@ -7425,6 +7806,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7425
7806
|
* signerId,
|
|
7426
7807
|
* documentId,
|
|
7427
7808
|
* 'original',
|
|
7809
|
+
* accessCode,
|
|
7428
7810
|
* );
|
|
7429
7811
|
* await fs.promises.writeFile('to-sign.pdf', pdf);
|
|
7430
7812
|
* ```
|
|
@@ -7432,16 +7814,15 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7432
7814
|
async download(signerId, documentId, artifactName, signerAccessCode) {
|
|
7433
7815
|
const sid = this.requireId(signerId, "Signer ID");
|
|
7434
7816
|
const did = this.requireId(documentId, "Document ID");
|
|
7435
|
-
|
|
7436
|
-
|
|
7817
|
+
if (artifactName !== "original") {
|
|
7818
|
+
throw new ValidationError("A signer can download only the original artifact");
|
|
7819
|
+
}
|
|
7820
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7437
7821
|
return this.callBinary(
|
|
7438
7822
|
"Failed to download signer document",
|
|
7439
7823
|
() => this.http.get(
|
|
7440
|
-
`/signers/${this.pathSegment(sid, "Signer ID")}/documents/${this.pathSegment(did, "Document ID")}/download
|
|
7441
|
-
|
|
7442
|
-
responseType: "arraybuffer",
|
|
7443
|
-
params: { "signer-access-code": code }
|
|
7444
|
-
}
|
|
7824
|
+
`/signers/${this.pathSegment(sid, "Signer ID")}/documents/${this.pathSegment(did, "Document ID")}/download/original`,
|
|
7825
|
+
{ ...BINARY_NO_REDIRECT, params: { "signer-access-code": code } }
|
|
7445
7826
|
)
|
|
7446
7827
|
);
|
|
7447
7828
|
}
|
|
@@ -7687,10 +8068,15 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7687
8068
|
* flag.
|
|
7688
8069
|
*
|
|
7689
8070
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7690
|
-
* @returns
|
|
7691
|
-
*
|
|
8071
|
+
* @returns The signer's acceptance state, or `null` from deployments that
|
|
8072
|
+
* acknowledge without data:
|
|
8073
|
+
* ```jsonc
|
|
8074
|
+
* { "full_name": "Example Signer", "email": "signer@example.com", "has_accepted_terms": true }
|
|
8075
|
+
* ```
|
|
7692
8076
|
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
7693
|
-
* @throws {ApiError}
|
|
8077
|
+
* @throws {ApiError} `400` while the signer's verification is not done (e.g.
|
|
8078
|
+
* the e-mail code) or their step has not started, `401` for an invalid code,
|
|
8079
|
+
* `410` once the code is closed.
|
|
7694
8080
|
*
|
|
7695
8081
|
* @example
|
|
7696
8082
|
* ```ts
|
|
@@ -7700,12 +8086,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7700
8086
|
*/
|
|
7701
8087
|
async acceptTerms(signerAccessCode) {
|
|
7702
8088
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7703
|
-
|
|
8089
|
+
const data = await this.call(
|
|
7704
8090
|
"Failed to accept terms",
|
|
7705
8091
|
() => this.http.put("/signers/accept-terms", void 0, {
|
|
7706
8092
|
params: { "signer-access-code": code }
|
|
7707
8093
|
})
|
|
7708
8094
|
);
|
|
8095
|
+
return data ?? null;
|
|
7709
8096
|
}
|
|
7710
8097
|
/**
|
|
7711
8098
|
* Verify the signer's email or WhatsApp one-time password
|
|
@@ -7756,12 +8143,56 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7756
8143
|
)
|
|
7757
8144
|
);
|
|
7758
8145
|
}
|
|
8146
|
+
/**
|
|
8147
|
+
* Confirm the signer's contact data before signing
|
|
8148
|
+
* (`PUT /documents/{documentId}/signers/confirm-data?signer-access-code=…`).
|
|
8149
|
+
*
|
|
8150
|
+
* Send the contact the signer's channel needs: `email` for e-mail
|
|
8151
|
+
* verification or notification, `whatsapp_phone_number` for WhatsApp. Each
|
|
8152
|
+
* is saved when the signer has none; otherwise it must be theirs, so it
|
|
8153
|
+
* cannot change the record. `has_accepted_terms: true` also records the
|
|
8154
|
+
* terms, which opens `getAssignment()` for a `DigitalCertificate` signer.
|
|
8155
|
+
* With an envelope code it acts on the document the route names. Only the
|
|
8156
|
+
* fields provided are sent.
|
|
8157
|
+
*
|
|
8158
|
+
* Request body (`application/json`):
|
|
8159
|
+
* ```jsonc
|
|
8160
|
+
* {
|
|
8161
|
+
* "email": "signer@example.com",
|
|
8162
|
+
* "has_accepted_terms": true
|
|
8163
|
+
* }
|
|
8164
|
+
* ```
|
|
8165
|
+
*
|
|
8166
|
+
* @param documentId - The document the signer is confirming data for.
|
|
8167
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8168
|
+
* @param payload - `email`, `whatsapp_phone_number` and `has_accepted_terms`.
|
|
8169
|
+
* `full_name`/`government_id` are forwarded only for older deployments.
|
|
8170
|
+
* @returns `null` on production, which answers `data: []`; older deployments
|
|
8171
|
+
* return the signer:
|
|
8172
|
+
* ```jsonc
|
|
8173
|
+
* { "resource": "signer", "id": "19e6b92e7895332ed9708535d8c", "full_name": "Example Signer",
|
|
8174
|
+
* "email": "signer@example.com", "whatsapp_phone_number": null, "has_accepted_terms": true }
|
|
8175
|
+
* ```
|
|
8176
|
+
* @throws {ValidationError} If `documentId` or `signerAccessCode` is missing,
|
|
8177
|
+
* or a supplied value is malformed.
|
|
8178
|
+
* @throws {ApiError} `400` when a contact the signer's methods need is missing,
|
|
8179
|
+
* invalid or not theirs, or their step has not started; `404` for a document
|
|
8180
|
+
* the code does not reach; `410` once the code is closed.
|
|
8181
|
+
*
|
|
8182
|
+
* @example
|
|
8183
|
+
* ```ts
|
|
8184
|
+
* await client.signerDocuments.confirmData(documentId, accessCode, {
|
|
8185
|
+
* email: 'signer@example.com',
|
|
8186
|
+
* has_accepted_terms: true,
|
|
8187
|
+
* });
|
|
8188
|
+
* ```
|
|
8189
|
+
*/
|
|
7759
8190
|
async confirmData(documentId, signerAccessCode, payload) {
|
|
7760
8191
|
assertRecord(payload, "signer confirmation payload");
|
|
7761
8192
|
validateConfirmDataPayload(payload);
|
|
7762
8193
|
const did = this.requireId(documentId, "Document ID");
|
|
7763
8194
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7764
|
-
|
|
8195
|
+
const data = await this.call(
|
|
7765
8196
|
"Failed to confirm signer data",
|
|
7766
8197
|
() => this.http.put(
|
|
7767
8198
|
`/documents/${this.pathSegment(did, "Document ID")}/signers/confirm-data`,
|
|
@@ -7775,6 +8206,7 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7775
8206
|
{ params: { "signer-access-code": code } }
|
|
7776
8207
|
)
|
|
7777
8208
|
);
|
|
8209
|
+
return data !== null && typeof data === "object" && !Array.isArray(data) ? data : null;
|
|
7778
8210
|
}
|
|
7779
8211
|
async uploadSignature(signerAccessCode, image, options = {}) {
|
|
7780
8212
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
@@ -7855,14 +8287,17 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7855
8287
|
* the SDK never automatically replays this particular `GET` after a `429`.
|
|
7856
8288
|
*
|
|
7857
8289
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7858
|
-
* @param
|
|
7859
|
-
*
|
|
7860
|
-
* `
|
|
7861
|
-
*
|
|
7862
|
-
*
|
|
7863
|
-
*
|
|
7864
|
-
*
|
|
7865
|
-
*
|
|
8290
|
+
* @param options - `true`/`false` (the `has_accepted_terms` query, kept for
|
|
8291
|
+
* existing calls) or an options object:
|
|
8292
|
+
* `hasAcceptedTerms` (an explicit `false` is still sent), `expand:
|
|
8293
|
+
* ['envelope']` (adds the code's envelope), and `documentId` (with an
|
|
8294
|
+
* envelope code, open another document of that envelope the signer is on).
|
|
8295
|
+
* @returns The {@link ISigningDocument}. Its `assignment` carries only this
|
|
8296
|
+
* signer's items — no other signers, `signing_urls`, copy receivers or
|
|
8297
|
+
* `summary` — from which the `itemId` / `fieldId` / `pageId` values for
|
|
8298
|
+
* {@link SignerDocumentsResource.sign} are read. A closed code returns
|
|
8299
|
+
* only `id`, `name`, `status`, `current_signer`, `certified_copy` and
|
|
8300
|
+
* `envelope`, with `is_signer_access_closed: true`:
|
|
7866
8301
|
* ```jsonc
|
|
7867
8302
|
* {
|
|
7868
8303
|
* "resource": "document",
|
|
@@ -7893,9 +8328,12 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7893
8328
|
* { "id": "item-1", "page": { "id": "page-1", "number": 1, "height": 1651, "width": 1275,
|
|
7894
8329
|
* "download_url": "https://..." }, "signer": { "id": "19e6b92e..." },
|
|
7895
8330
|
* "field": { "id": "field-1", "type": "signature" }, "value": null, "completed": false }
|
|
7896
|
-
* ]
|
|
7897
|
-
* "summary": { "signer_count": 1, "completed_count": 0, "signers": [] }
|
|
8331
|
+
* ]
|
|
7898
8332
|
* },
|
|
8333
|
+
* "current_signer": { "id": "19e6b92e7895332ed9708535d8c", "verification_method": "Email",
|
|
8334
|
+
* "notification_methods": ["Email"], "completed": false },
|
|
8335
|
+
* "is_signer_access_closed": false,
|
|
8336
|
+
* "certified_copy": { "available": false, "notification_method": "Email", "resends_left": null },
|
|
7899
8337
|
* "pages": [
|
|
7900
8338
|
* { "id": "103acccd5c73...", "number": 1, "height": 1651, "width": 1275,
|
|
7901
8339
|
* "download_url": "https://api.assinafy.com.br/v1/documents/103acccd.../pages/103acccd5c73.../download" }
|
|
@@ -7904,75 +8342,233 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
7904
8342
|
* "updated_at": "2026-07-19T14:56:56Z"
|
|
7905
8343
|
* }
|
|
7906
8344
|
* ```
|
|
7907
|
-
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
7908
|
-
* @throws {ApiError} `400` when DigitalCertificate
|
|
7909
|
-
*
|
|
7910
|
-
*
|
|
8345
|
+
* @throws {ValidationError} If `signerAccessCode` is missing or an option is malformed.
|
|
8346
|
+
* @throws {ApiError} `400` when a DigitalCertificate signer has not confirmed
|
|
8347
|
+
* data and terms, the signer's step has not started, or `documentId` is
|
|
8348
|
+
* not an ID; `401` for an invalid code; `404` when `documentId` is outside
|
|
8349
|
+
* the code's envelope; `409` (`DocumentNotReady`) while the document is
|
|
8350
|
+
* still being prepared.
|
|
7911
8351
|
*
|
|
7912
8352
|
* @example
|
|
7913
8353
|
* ```ts
|
|
7914
|
-
* // query → ?signer-access-code=<code>&has_accepted_terms=true
|
|
7915
|
-
* const
|
|
8354
|
+
* // query → ?signer-access-code=<code>&has_accepted_terms=true&expand=envelope
|
|
8355
|
+
* const doc = await client.signerDocuments.getAssignment(accessCode, {
|
|
8356
|
+
* hasAcceptedTerms: true,
|
|
8357
|
+
* expand: ['envelope'],
|
|
8358
|
+
* });
|
|
7916
8359
|
* ```
|
|
7917
8360
|
*/
|
|
7918
|
-
async getAssignment(signerAccessCode,
|
|
8361
|
+
async getAssignment(signerAccessCode, options) {
|
|
7919
8362
|
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
7920
|
-
|
|
8363
|
+
const read = typeof options === "object" && options !== null ? options : options === void 0 ? {} : { hasAcceptedTerms: options };
|
|
8364
|
+
assertRecord(read, "signing read options");
|
|
8365
|
+
if (read.hasAcceptedTerms !== void 0 && typeof read.hasAcceptedTerms !== "boolean") {
|
|
7921
8366
|
throw new ValidationError("hasAcceptedTerms must be a boolean");
|
|
7922
8367
|
}
|
|
8368
|
+
if (read.documentId !== void 0) this.requireId(read.documentId, "documentId");
|
|
7923
8369
|
return this.call(
|
|
7924
8370
|
"Failed to fetch signer assignment",
|
|
7925
8371
|
() => this.http.get("/sign", {
|
|
7926
8372
|
params: cleanParams({
|
|
7927
8373
|
"signer-access-code": code,
|
|
7928
|
-
has_accepted_terms: hasAcceptedTerms
|
|
8374
|
+
has_accepted_terms: read.hasAcceptedTerms,
|
|
8375
|
+
document_id: read.documentId,
|
|
8376
|
+
...signingReadParams(read)
|
|
7929
8377
|
})
|
|
7930
8378
|
})
|
|
7931
8379
|
);
|
|
7932
8380
|
}
|
|
7933
8381
|
/**
|
|
7934
|
-
*
|
|
7935
|
-
* (`POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…`).
|
|
8382
|
+
* Read the sending workspace's brand for the signing page (`GET /sign/theme`).
|
|
7936
8383
|
*
|
|
7937
|
-
*
|
|
7938
|
-
*
|
|
7939
|
-
*
|
|
7940
|
-
* {@link SignerDocumentsResource.
|
|
7941
|
-
* authenticates via the `signer-access-code` query param.
|
|
7942
|
-
* Virtual signers must call {@link SignerDocumentsResource.confirmData}
|
|
7943
|
-
* first. Digital Certificate signers cannot use this endpoint; use the
|
|
7944
|
-
* certificate start/complete API flow instead.
|
|
8384
|
+
* Available before verification and after the document is deleted.
|
|
8385
|
+
* `primary_color` is the button background and `secondary_color` its text
|
|
8386
|
+
* (6-digit hex without `#`). The `logo` URL carries no access code: fetch it
|
|
8387
|
+
* with {@link SignerDocumentsResource.downloadLogo}.
|
|
7945
8388
|
*
|
|
7946
|
-
*
|
|
8389
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8390
|
+
* @returns The brand:
|
|
7947
8391
|
* ```jsonc
|
|
7948
|
-
*
|
|
7949
|
-
*
|
|
7950
|
-
*
|
|
7951
|
-
*
|
|
7952
|
-
*
|
|
7953
|
-
*
|
|
7954
|
-
* }
|
|
7955
|
-
* ]
|
|
8392
|
+
* {
|
|
8393
|
+
* "account_name": "Example Ltda",
|
|
8394
|
+
* "primary_color": "1F6FEB",
|
|
8395
|
+
* "secondary_color": "FFFFFF",
|
|
8396
|
+
* "logo": "https://api.assinafy.com.br/v1/sign/logo" // null when the account has none
|
|
8397
|
+
* }
|
|
7956
8398
|
* ```
|
|
7957
|
-
*
|
|
7958
|
-
* @
|
|
7959
|
-
* @param assignmentId - The assignment within that document.
|
|
7960
|
-
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
7961
|
-
* @param entries - Non-empty array of {@link ISignFieldEntry}
|
|
7962
|
-
* (`itemId`, `fieldId`, `pageId`, `value`) — the body sent to the API.
|
|
7963
|
-
* @returns The API's signing result object. Its keys are operation-specific,
|
|
7964
|
-
* so the SDK preserves them as a {@link Record} without inventing fields.
|
|
7965
|
-
* @throws {ValidationError} If any of `documentId`, `assignmentId`, or
|
|
7966
|
-
* `signerAccessCode` is missing, or `entries` is empty.
|
|
7967
|
-
* @throws {ApiError} `400`/`409` if a value fails validation or the assignment
|
|
7968
|
-
* is no longer signable; `401`/`403` if the access code is invalid/expired.
|
|
8399
|
+
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
8400
|
+
* @throws {ApiError} `400` while the signer's step has not started, `401` for an invalid code.
|
|
7969
8401
|
*
|
|
7970
8402
|
* @example
|
|
7971
8403
|
* ```ts
|
|
7972
|
-
*
|
|
7973
|
-
*
|
|
7974
|
-
|
|
7975
|
-
|
|
8404
|
+
* const theme = await client.signerDocuments.getTheme(accessCode);
|
|
8405
|
+
* ```
|
|
8406
|
+
*/
|
|
8407
|
+
async getTheme(signerAccessCode) {
|
|
8408
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
8409
|
+
return this.call(
|
|
8410
|
+
"Failed to fetch signing theme",
|
|
8411
|
+
() => this.http.get("/sign/theme", { params: { "signer-access-code": code } })
|
|
8412
|
+
);
|
|
8413
|
+
}
|
|
8414
|
+
/**
|
|
8415
|
+
* Download the sending workspace's logo for the signing page (`GET /sign/logo`).
|
|
8416
|
+
*
|
|
8417
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8418
|
+
* @returns The image bytes (`image/*`).
|
|
8419
|
+
* @throws {ValidationError} If `signerAccessCode` is missing.
|
|
8420
|
+
* @throws {ApiError} `400` while the signer's step has not started, `401` for an
|
|
8421
|
+
* invalid code, `404` when the workspace has no logo.
|
|
8422
|
+
*
|
|
8423
|
+
* @example
|
|
8424
|
+
* ```ts
|
|
8425
|
+
* const logo = await client.signerDocuments.downloadLogo(accessCode);
|
|
8426
|
+
* ```
|
|
8427
|
+
*/
|
|
8428
|
+
async downloadLogo(signerAccessCode) {
|
|
8429
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
8430
|
+
return this.callBinary(
|
|
8431
|
+
"Failed to download signing logo",
|
|
8432
|
+
() => this.http.get("/sign/logo", {
|
|
8433
|
+
responseType: "arraybuffer",
|
|
8434
|
+
params: { "signer-access-code": code }
|
|
8435
|
+
})
|
|
8436
|
+
);
|
|
8437
|
+
}
|
|
8438
|
+
/**
|
|
8439
|
+
* Send the signer their certified copy again (`POST /sign/certified-copy`).
|
|
8440
|
+
*
|
|
8441
|
+
* The copy goes, with a download link valid for 30 minutes, on the signature
|
|
8442
|
+
* request's channel and only to the contact the signing messages went to.
|
|
8443
|
+
* Works after the signer signed, also once the code is closed. E-mail: once
|
|
8444
|
+
* every 2 minutes and 10 times a day; WhatsApp: once per request.
|
|
8445
|
+
* `certified_copy` on {@link SignerDocumentsResource.getAssignment} says
|
|
8446
|
+
* whether it is available.
|
|
8447
|
+
*
|
|
8448
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8449
|
+
* @param documentId - With an envelope code, another document of that envelope.
|
|
8450
|
+
* @returns What was sent:
|
|
8451
|
+
* ```jsonc
|
|
8452
|
+
* { "available": true, "notification_method": "Email", "resends_left": null, "sent_to": "j***@example.com" }
|
|
8453
|
+
* ```
|
|
8454
|
+
* @throws {ValidationError} If the code or `documentId` is blank.
|
|
8455
|
+
* @throws {ApiError} `400` while the signer's step has not started, `404` for a
|
|
8456
|
+
* document outside the envelope, `409` when the signer has not signed or the
|
|
8457
|
+
* document is not certified, `429` within the resend limits, `500` when the
|
|
8458
|
+
* message could not be sent (nothing used up; ask again).
|
|
8459
|
+
*
|
|
8460
|
+
* @example
|
|
8461
|
+
* ```ts
|
|
8462
|
+
* const { sent_to } = await client.signerDocuments.resendCertifiedCopy(accessCode);
|
|
8463
|
+
* ```
|
|
8464
|
+
*/
|
|
8465
|
+
async resendCertifiedCopy(signerAccessCode, documentId) {
|
|
8466
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
8467
|
+
const body = documentId === void 0 ? {} : { document_id: this.requireId(documentId, "documentId") };
|
|
8468
|
+
return this.call(
|
|
8469
|
+
"Failed to resend certified copy",
|
|
8470
|
+
() => this.http.post("/sign/certified-copy", body, { params: { "signer-access-code": code } })
|
|
8471
|
+
);
|
|
8472
|
+
}
|
|
8473
|
+
/**
|
|
8474
|
+
* Download the certified copy from a sent link (`GET /signers/downloads/{token}`).
|
|
8475
|
+
*
|
|
8476
|
+
* The token is the last path segment of the link in the completion and
|
|
8477
|
+
* re-send messages; it is a credential. Links last 7 days (completion) or
|
|
8478
|
+
* 30 minutes (re-send). An expired or unknown link redirects to the
|
|
8479
|
+
* expired-link page; the SDK does not follow it and throws instead.
|
|
8480
|
+
*
|
|
8481
|
+
* @param token - Link token.
|
|
8482
|
+
* @param artifact - `pades` for the PAdES version, when the document has one.
|
|
8483
|
+
* @returns The PDF bytes.
|
|
8484
|
+
* @throws {ValidationError} If `token` is blank or `artifact` is not `pades`.
|
|
8485
|
+
* @throws {ApiError} `302` for an expired or unknown link (ask for a new one
|
|
8486
|
+
* with {@link SignerDocumentsResource.resendCertifiedCopyFromLink}), `404`
|
|
8487
|
+
* for `pades` on a document without it.
|
|
8488
|
+
*
|
|
8489
|
+
* @example
|
|
8490
|
+
* ```ts
|
|
8491
|
+
* const pdf = await client.signerDocuments.downloadCertifiedCopy(token);
|
|
8492
|
+
* ```
|
|
8493
|
+
*/
|
|
8494
|
+
async downloadCertifiedCopy(token, artifact) {
|
|
8495
|
+
if (artifact !== void 0 && artifact !== "pades") {
|
|
8496
|
+
throw new ValidationError("artifact must be pades when given");
|
|
8497
|
+
}
|
|
8498
|
+
const path2 = `/signers/downloads/${this.pathSegment(token, "Download token")}`;
|
|
8499
|
+
return this.callBinary(
|
|
8500
|
+
"Failed to download certified copy",
|
|
8501
|
+
() => this.http.get(artifact ? `${path2}/pades` : path2, BINARY_NO_REDIRECT)
|
|
8502
|
+
);
|
|
8503
|
+
}
|
|
8504
|
+
/**
|
|
8505
|
+
* Send the certified copy again from an expired link
|
|
8506
|
+
* (`POST /signers/downloads/{token}/resend`).
|
|
8507
|
+
*
|
|
8508
|
+
* Works with the link's token after it expired, on the same terms as
|
|
8509
|
+
* {@link SignerDocumentsResource.resendCertifiedCopy}.
|
|
8510
|
+
*
|
|
8511
|
+
* @param token - Link token, from the expired link.
|
|
8512
|
+
* @returns What was sent, as {@link SignerDocumentsResource.resendCertifiedCopy} returns.
|
|
8513
|
+
* @throws {ValidationError} If `token` is blank.
|
|
8514
|
+
* @throws {ApiError} `404` for an unknown link, `409` when nothing can be sent
|
|
8515
|
+
* from it (copy receiver, Bypass signer, no contact, not certified), `429`
|
|
8516
|
+
* within the resend limits.
|
|
8517
|
+
*
|
|
8518
|
+
* @example
|
|
8519
|
+
* ```ts
|
|
8520
|
+
* await client.signerDocuments.resendCertifiedCopyFromLink(token);
|
|
8521
|
+
* ```
|
|
8522
|
+
*/
|
|
8523
|
+
async resendCertifiedCopyFromLink(token) {
|
|
8524
|
+
return this.call(
|
|
8525
|
+
"Failed to resend certified copy",
|
|
8526
|
+
() => this.http.post(`/signers/downloads/${this.pathSegment(token, "Download token")}/resend`)
|
|
8527
|
+
);
|
|
8528
|
+
}
|
|
8529
|
+
/**
|
|
8530
|
+
* Submit the signer's field values to sign an assignment
|
|
8531
|
+
* (`POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…`).
|
|
8532
|
+
*
|
|
8533
|
+
* The precise, field-by-field counterpart of
|
|
8534
|
+
* {@link SignerDocumentsResource.signMultiple}: the `entries` array is sent as
|
|
8535
|
+
* the request body, each entry addressing one item resolved from
|
|
8536
|
+
* {@link SignerDocumentsResource.getAssignment}. The access code
|
|
8537
|
+
* authenticates via the `signer-access-code` query param.
|
|
8538
|
+
* Virtual signers must call {@link SignerDocumentsResource.confirmData}
|
|
8539
|
+
* first. Digital Certificate signers cannot use this endpoint; use the
|
|
8540
|
+
* certificate start/complete API flow instead.
|
|
8541
|
+
*
|
|
8542
|
+
* Request body (`application/json`):
|
|
8543
|
+
* ```jsonc
|
|
8544
|
+
* [
|
|
8545
|
+
* {
|
|
8546
|
+
* "itemId": "item_example",
|
|
8547
|
+
* "fieldId": "field_example",
|
|
8548
|
+
* "pageId": "page_example",
|
|
8549
|
+
* "value": "Example Signer"
|
|
8550
|
+
* }
|
|
8551
|
+
* ]
|
|
8552
|
+
* ```
|
|
8553
|
+
*
|
|
8554
|
+
* @param documentId - The document being signed.
|
|
8555
|
+
* @param assignmentId - The assignment within that document.
|
|
8556
|
+
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
8557
|
+
* @param entries - Non-empty array of {@link ISignFieldEntry}
|
|
8558
|
+
* (`itemId`, `fieldId`, `pageId`, `value`) — the body sent to the API.
|
|
8559
|
+
* @returns The API's signing result object. Its keys are operation-specific,
|
|
8560
|
+
* so the SDK preserves them as a {@link Record} without inventing fields.
|
|
8561
|
+
* @throws {ValidationError} If any of `documentId`, `assignmentId`, or
|
|
8562
|
+
* `signerAccessCode` is missing, or `entries` is empty.
|
|
8563
|
+
* @throws {ApiError} `400`/`409` if a value fails validation or the assignment
|
|
8564
|
+
* is no longer signable; `401`/`403` if the access code is invalid/expired.
|
|
8565
|
+
*
|
|
8566
|
+
* @example
|
|
8567
|
+
* ```ts
|
|
8568
|
+
* // body → [{ itemId, fieldId, pageId, value: 'Example Signer' }]
|
|
8569
|
+
* await client.signerDocuments.sign(documentId, assignmentId, accessCode, [
|
|
8570
|
+
* { itemId: 'item-1', fieldId: 'field-1', pageId: 'page-1', value: 'Example Signer' },
|
|
8571
|
+
* ]);
|
|
7976
8572
|
* ```
|
|
7977
8573
|
*/
|
|
7978
8574
|
async sign(documentId, assignmentId, signerAccessCode, entries) {
|
|
@@ -8060,6 +8656,19 @@ function assertDocumentIds(documentIds) {
|
|
|
8060
8656
|
throw new ValidationError("documentIds must be a non-empty array of non-empty IDs");
|
|
8061
8657
|
}
|
|
8062
8658
|
}
|
|
8659
|
+
var BINARY_NO_REDIRECT = { responseType: "arraybuffer", maxRedirects: 0 };
|
|
8660
|
+
var SIGNING_EXPANSIONS = /* @__PURE__ */ new Set(["envelope"]);
|
|
8661
|
+
function signingReadParams(options) {
|
|
8662
|
+
assertRecord(options, "signing read options");
|
|
8663
|
+
return expandParam(options.expand, SIGNING_EXPANSIONS);
|
|
8664
|
+
}
|
|
8665
|
+
function searchParams(search, params) {
|
|
8666
|
+
if (search !== void 0 && typeof search !== "string") {
|
|
8667
|
+
throw new ValidationError("search must be a string");
|
|
8668
|
+
}
|
|
8669
|
+
assertRecord(params, "search params");
|
|
8670
|
+
return cleanParams({ search, envelope_id: params.envelope_id });
|
|
8671
|
+
}
|
|
8063
8672
|
function assertDeclineReason(declineReason) {
|
|
8064
8673
|
if (typeof declineReason !== "string" || !declineReason.trim()) {
|
|
8065
8674
|
throw new ValidationError("declineReason is required");
|
|
@@ -8281,12 +8890,70 @@ var UserResource = class extends BaseResource {
|
|
|
8281
8890
|
* ```
|
|
8282
8891
|
*/
|
|
8283
8892
|
async updateNotificationPreferences(preferences) {
|
|
8284
|
-
|
|
8893
|
+
assertBooleanMap(preferences, "notification preferences", NOTIFICATION_PREFERENCE_KEYS);
|
|
8285
8894
|
return this.call(
|
|
8286
8895
|
"Failed to update notification preferences",
|
|
8287
8896
|
() => this.http.put("/users/self/notification-preferences", preferences)
|
|
8288
8897
|
);
|
|
8289
8898
|
}
|
|
8899
|
+
/**
|
|
8900
|
+
* Read which document alerts reach the user as push notifications
|
|
8901
|
+
* (`GET /users/self/push-preferences`).
|
|
8902
|
+
*
|
|
8903
|
+
* Separate from the e-mail preferences. Every key is returned and defaults
|
|
8904
|
+
* to `true`; new keys may be added. Not available to third-party OAuth
|
|
8905
|
+
* applications (`403`).
|
|
8906
|
+
*
|
|
8907
|
+
* @returns The push preferences:
|
|
8908
|
+
* ```jsonc
|
|
8909
|
+
* {
|
|
8910
|
+
* "SignerViewed": true,
|
|
8911
|
+
* "SignerSigned": true,
|
|
8912
|
+
* "DocumentCompleted": true,
|
|
8913
|
+
* "SignerDeclined": true,
|
|
8914
|
+
* "DocumentAboutToExpire": true,
|
|
8915
|
+
* "DocumentExpired": true,
|
|
8916
|
+
* "SignerIdentityReviewRequired": true, // the review e-mail is always sent
|
|
8917
|
+
* "SignerWhatsappFailed": true
|
|
8918
|
+
* }
|
|
8919
|
+
* ```
|
|
8920
|
+
* @throws {ApiError} `401` for invalid credentials, `403` for an OAuth application token.
|
|
8921
|
+
*
|
|
8922
|
+
* @example
|
|
8923
|
+
* ```ts
|
|
8924
|
+
* const push = await client.users.getPushPreferences();
|
|
8925
|
+
* ```
|
|
8926
|
+
*/
|
|
8927
|
+
async getPushPreferences() {
|
|
8928
|
+
return this.call(
|
|
8929
|
+
"Failed to fetch push preferences",
|
|
8930
|
+
() => this.http.get("/users/self/push-preferences")
|
|
8931
|
+
);
|
|
8932
|
+
}
|
|
8933
|
+
/**
|
|
8934
|
+
* Change which document alerts reach the user as push notifications
|
|
8935
|
+
* (`PUT /users/self/push-preferences`).
|
|
8936
|
+
*
|
|
8937
|
+
* Merges the keys sent; `false` stops that push in every workspace the user
|
|
8938
|
+
* belongs to. E-mail is not affected.
|
|
8939
|
+
*
|
|
8940
|
+
* @param preferences - Keys to change, e.g. `{ SignerViewed: false }`.
|
|
8941
|
+
* @returns The full map, as {@link UserResource.getPushPreferences} returns.
|
|
8942
|
+
* @throws {ValidationError} If the map is empty or a value is not a boolean.
|
|
8943
|
+
* @throws {ApiError} `400` for an unknown code, `403` for an OAuth application token.
|
|
8944
|
+
*
|
|
8945
|
+
* @example
|
|
8946
|
+
* ```ts
|
|
8947
|
+
* await client.users.updatePushPreferences({ SignerViewed: false });
|
|
8948
|
+
* ```
|
|
8949
|
+
*/
|
|
8950
|
+
async updatePushPreferences(preferences) {
|
|
8951
|
+
assertBooleanMap(preferences, "push preferences");
|
|
8952
|
+
return this.call(
|
|
8953
|
+
"Failed to update push preferences",
|
|
8954
|
+
() => this.http.put("/users/self/push-preferences", { ...preferences })
|
|
8955
|
+
);
|
|
8956
|
+
}
|
|
8290
8957
|
/**
|
|
8291
8958
|
* List the user's enrolled two-factor methods (`GET /users/self/mfa`).
|
|
8292
8959
|
*
|
|
@@ -8482,21 +9149,6 @@ var NOTIFICATION_PREFERENCE_KEYS = /* @__PURE__ */ new Set([
|
|
|
8482
9149
|
"ContractExpired",
|
|
8483
9150
|
"ContractRenewed"
|
|
8484
9151
|
]);
|
|
8485
|
-
function validateNotificationPreferences(preferences) {
|
|
8486
|
-
assertRecord(preferences, "notification preferences");
|
|
8487
|
-
const entries = Object.entries(preferences);
|
|
8488
|
-
if (entries.length === 0) {
|
|
8489
|
-
throw new ValidationError("at least one notification preference is required");
|
|
8490
|
-
}
|
|
8491
|
-
for (const [key, value] of entries) {
|
|
8492
|
-
if (!NOTIFICATION_PREFERENCE_KEYS.has(key)) {
|
|
8493
|
-
throw new ValidationError(`unknown notification preference: ${key}`);
|
|
8494
|
-
}
|
|
8495
|
-
if (typeof value !== "boolean") {
|
|
8496
|
-
throw new ValidationError(`${key} must be a boolean`);
|
|
8497
|
-
}
|
|
8498
|
-
}
|
|
8499
|
-
}
|
|
8500
9152
|
|
|
8501
9153
|
// src/resources/contracts.ts
|
|
8502
9154
|
var CONTRACT_STATUSES = /* @__PURE__ */ new Set(["draft", "active", "expired", "terminated"]);
|
|
@@ -8626,14 +9278,14 @@ var ContractResource = class extends BaseResource {
|
|
|
8626
9278
|
* }
|
|
8627
9279
|
* ```
|
|
8628
9280
|
* @throws {ValidationError} If an ID is missing or invalid.
|
|
8629
|
-
* @throws {ApiError} `401` for invalid credentials, `404`
|
|
8630
|
-
*
|
|
9281
|
+
* @throws {ApiError} `401` for invalid credentials, `404` (`code:
|
|
9282
|
+
* 'NoContractTerms'` when the document exists without terms), or `500`.
|
|
8631
9283
|
*
|
|
8632
9284
|
* @example
|
|
8633
9285
|
* ```ts
|
|
8634
9286
|
* const contract = await client.contracts.get(document.id);
|
|
8635
|
-
* if (
|
|
8636
|
-
* console.log(contract.parent_document_id);
|
|
9287
|
+
* if ('parent_document_id' in contract) {
|
|
9288
|
+
* console.log(contract.parent_document_id); // an amendment, renewal or termination
|
|
8637
9289
|
* }
|
|
8638
9290
|
* ```
|
|
8639
9291
|
*/
|
|
@@ -8692,9 +9344,10 @@ var ContractResource = class extends BaseResource {
|
|
|
8692
9344
|
* }
|
|
8693
9345
|
* ```
|
|
8694
9346
|
* @throws {ValidationError} If the payload or an ID is malformed.
|
|
8695
|
-
* @throws {ApiError} `400` for invalid terms, `403`
|
|
8696
|
-
* include tracking, `404` for an
|
|
8697
|
-
*
|
|
9347
|
+
* @throws {ApiError} `400` for invalid terms (each in `fieldErrors`), `403`
|
|
9348
|
+
* (`PlanRestricted`) when the plan does not include tracking, `404` for an
|
|
9349
|
+
* unknown document or a `parent_document_id` outside the workspace, `409`
|
|
9350
|
+
* (`ContractChanged`) after a concurrent change, or `500` on a server error.
|
|
8698
9351
|
*
|
|
8699
9352
|
* @example
|
|
8700
9353
|
* ```ts
|
|
@@ -8724,6 +9377,7 @@ var ContractResource = class extends BaseResource {
|
|
|
8724
9377
|
*
|
|
8725
9378
|
* @param documentId - Any document in the contract family.
|
|
8726
9379
|
* @param accountId - Override the client's default account ID.
|
|
9380
|
+
* @param params - `expand: 'document'` embeds the root contract's document.
|
|
8727
9381
|
* @returns The root contract and ordered instruments:
|
|
8728
9382
|
* ```jsonc
|
|
8729
9383
|
* {
|
|
@@ -8775,10 +9429,15 @@ var ContractResource = class extends BaseResource {
|
|
|
8775
9429
|
* const family = await client.contracts.listRelated(amendmentDocument.id);
|
|
8776
9430
|
* ```
|
|
8777
9431
|
*/
|
|
8778
|
-
async listRelated(documentId, accountId) {
|
|
9432
|
+
async listRelated(documentId, accountId, params = {}) {
|
|
9433
|
+
assertRecord(params, "related contract params");
|
|
9434
|
+
if (params.expand !== void 0 && params.expand !== "document") {
|
|
9435
|
+
throw new ValidationError("expand must be document");
|
|
9436
|
+
}
|
|
9437
|
+
const config = params.expand === void 0 ? {} : { params: { expand: params.expand } };
|
|
8779
9438
|
return this.call(
|
|
8780
9439
|
"Failed to fetch related contracts",
|
|
8781
|
-
() => this.http.get(`${this.contractPath(documentId, accountId)}/related
|
|
9440
|
+
() => this.http.get(`${this.contractPath(documentId, accountId)}/related`, config)
|
|
8782
9441
|
);
|
|
8783
9442
|
}
|
|
8784
9443
|
/**
|
|
@@ -9081,15 +9740,708 @@ function validateExternalReferences(value) {
|
|
|
9081
9740
|
}
|
|
9082
9741
|
}
|
|
9083
9742
|
|
|
9743
|
+
// src/resources/envelopes.ts
|
|
9744
|
+
var EnvelopeResource = class extends BaseResource {
|
|
9745
|
+
/**
|
|
9746
|
+
* List the workspace's envelopes, most recent first
|
|
9747
|
+
* (`GET /accounts/{accountId}/envelopes`).
|
|
9748
|
+
*
|
|
9749
|
+
* @param params - Optional filters and pagination.
|
|
9750
|
+
* @param params.search - Part of the envelope name.
|
|
9751
|
+
* @param params.status - `open` (a document is still open) or `closed`
|
|
9752
|
+
* (every document signed, declined, cancelled, expired or failed).
|
|
9753
|
+
* @param params.page - One-based page number.
|
|
9754
|
+
* @param params.per-page - Page size: 20 by default, at most 50.
|
|
9755
|
+
* @param accountId - Override the client's default account ID.
|
|
9756
|
+
* @returns Envelopes and pagination metadata:
|
|
9757
|
+
* ```jsonc
|
|
9758
|
+
* {
|
|
9759
|
+
* "data": [{
|
|
9760
|
+
* "id": "1052a1f0c3d4e5f6a7b8c9d0e1f2",
|
|
9761
|
+
* "name": "Admission kit",
|
|
9762
|
+
* "message": "Please sign the documents below.",
|
|
9763
|
+
* "documents": [{
|
|
9764
|
+
* "id": "1052a1e9b8c7d6e5f4a3b2c1d0e9",
|
|
9765
|
+
* "position": 1,
|
|
9766
|
+
* "name": "contract.pdf",
|
|
9767
|
+
* "status": "pending_signature",
|
|
9768
|
+
* "artifacts": {
|
|
9769
|
+
* "original": "https://api.assinafy.com.br/v1/documents/1052a1e9b8c7d6e5f4a3b2c1d0e9/download/original",
|
|
9770
|
+
* "thumbnail": "https://api.assinafy.com.br/v1/documents/1052a1e9b8c7d6e5f4a3b2c1d0e9/thumbnail"
|
|
9771
|
+
* },
|
|
9772
|
+
* "signers": [{
|
|
9773
|
+
* "id": "1052a1d4c3b2a1f0e9d8c7b6a5f4",
|
|
9774
|
+
* "full_name": "Ana Souza",
|
|
9775
|
+
* "email": "ana@example.com",
|
|
9776
|
+
* "whatsapp_phone_number": null,
|
|
9777
|
+
* "completed": false,
|
|
9778
|
+
* "signed_at": null
|
|
9779
|
+
* }]
|
|
9780
|
+
* }],
|
|
9781
|
+
* "counts": { "pending_signature": 1 }, // documents per status; no envelope-level status
|
|
9782
|
+
* "signing_urls": [{
|
|
9783
|
+
* "signer_id": "1052a1d4c3b2a1f0e9d8c7b6a5f4",
|
|
9784
|
+
* "url": "https://app.assinafy.com.br/sign/1052a1e9b8c7d6e5f4a3b2c1d0e9?email=ana%40example.com",
|
|
9785
|
+
* "embedded": false
|
|
9786
|
+
* }],
|
|
9787
|
+
* "created_at": "2026-11-11T14:00:00Z"
|
|
9788
|
+
* }],
|
|
9789
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
|
|
9790
|
+
* }
|
|
9791
|
+
* ```
|
|
9792
|
+
* @throws {ValidationError} If no account ID is available.
|
|
9793
|
+
* @throws {ApiError} `400` for a filter of the wrong type, `403` for a token
|
|
9794
|
+
* without `documents:read`, `401` for invalid credentials.
|
|
9795
|
+
*
|
|
9796
|
+
* @example
|
|
9797
|
+
* ```ts
|
|
9798
|
+
* const { data: open } = await client.envelopes.list({ status: 'open' });
|
|
9799
|
+
* ```
|
|
9800
|
+
*/
|
|
9801
|
+
async list(params = {}, accountId) {
|
|
9802
|
+
assertRecord(params, "envelope list params");
|
|
9803
|
+
if (params.status !== void 0 && params.status !== "open" && params.status !== "closed") {
|
|
9804
|
+
throw new ValidationError("status must be open or closed");
|
|
9805
|
+
}
|
|
9806
|
+
return this.callList(
|
|
9807
|
+
"Failed to list envelopes",
|
|
9808
|
+
() => this.http.get(this.envelopesPath(accountId), { params: cleanListParams(params) })
|
|
9809
|
+
);
|
|
9810
|
+
}
|
|
9811
|
+
/**
|
|
9812
|
+
* Read one envelope (`GET /accounts/{accountId}/envelopes/{envelopeId}`).
|
|
9813
|
+
*
|
|
9814
|
+
* @param envelopeId - Envelope ID.
|
|
9815
|
+
* @param accountId - Override the client's default account ID.
|
|
9816
|
+
* @returns The envelope: its documents in order (`position`), each with its
|
|
9817
|
+
* status and signers, the per-status `counts` and one `signing_urls` entry
|
|
9818
|
+
* per signer. Same shape as each item of {@link EnvelopeResource.list}.
|
|
9819
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9820
|
+
* @throws {ApiError} `403` for a token without `documents:read`, `404` for an
|
|
9821
|
+
* unknown envelope.
|
|
9822
|
+
*
|
|
9823
|
+
* @example
|
|
9824
|
+
* ```ts
|
|
9825
|
+
* const envelope = await client.envelopes.get(envelopeId);
|
|
9826
|
+
* const pending = envelope.documents.filter((doc) => doc.status === 'pending_signature');
|
|
9827
|
+
* ```
|
|
9828
|
+
*/
|
|
9829
|
+
async get(envelopeId, accountId) {
|
|
9830
|
+
return this.call(
|
|
9831
|
+
"Failed to fetch envelope",
|
|
9832
|
+
() => this.http.get(this.envelopePath(envelopeId, accountId))
|
|
9833
|
+
);
|
|
9834
|
+
}
|
|
9835
|
+
/**
|
|
9836
|
+
* Send several documents to the same signers at once
|
|
9837
|
+
* (`POST /accounts/{accountId}/envelopes`).
|
|
9838
|
+
*
|
|
9839
|
+
* Every document must be uploaded, `metadata_ready` and unassigned; every
|
|
9840
|
+
* signer must be on at least one document. Signers all sign at once (no
|
|
9841
|
+
* `step`); a `DigitalCertificate` signer signs only `virtual` documents and
|
|
9842
|
+
* is alone on each. One invitation goes to each signer, and `200` means the
|
|
9843
|
+
* envelope exists even when a send fails (see each signer's
|
|
9844
|
+
* `notification_history`). The envelope is charged as one document, each
|
|
9845
|
+
* signer's notification and identity check once, and each certificate
|
|
9846
|
+
* signature on every document it is made on. A refused request creates and
|
|
9847
|
+
* charges nothing. Pass an `idempotencyKey` to retry safely after a lost
|
|
9848
|
+
* response; the SDK then also replays a `429`.
|
|
9849
|
+
*
|
|
9850
|
+
* @param payload - Envelope definition.
|
|
9851
|
+
* @param payload.name - 1–255 characters without `<`; invitations use it in
|
|
9852
|
+
* place of document names.
|
|
9853
|
+
* @param payload.message - Optional message for every signer.
|
|
9854
|
+
* @param payload.max_total_credits - Refuse with `409 CreditCeilingExceeded`
|
|
9855
|
+
* above this many credits.
|
|
9856
|
+
* @param payload.signers - 1–20 `{ id, verification_method?, notification_methods?, embedded? }`.
|
|
9857
|
+
* @param payload.documents - 1–20 `{ id, signer_ids, method?, entries?, expires_at?, copy_receiver_ids? }`,
|
|
9858
|
+
* in envelope order. `collect` documents need `entries` whose signers are
|
|
9859
|
+
* exactly `signer_ids`.
|
|
9860
|
+
* @param options - `idempotencyKey`: new for each envelope you mean to create.
|
|
9861
|
+
* @param accountId - Override the client's default account ID.
|
|
9862
|
+
* @returns The created envelope (see {@link EnvelopeResource.list}). An
|
|
9863
|
+
* embedded or WhatsApp-only signer has `url: null` in `signing_urls`.
|
|
9864
|
+
* @throws {ValidationError} If the payload is malformed, a signer's channels
|
|
9865
|
+
* do not pair, or a `collect` document has no `entries`.
|
|
9866
|
+
* @throws {ApiError} `400` with `fieldErrors` naming each field at fault, `403`
|
|
9867
|
+
* (`PlanRestricted` or `InsufficientScope`), `409` (`CreditCeilingExceeded`,
|
|
9868
|
+
* or `IdempotencyKeyInUse` while the first request with that key runs).
|
|
9869
|
+
*
|
|
9870
|
+
* @example
|
|
9871
|
+
* ```ts
|
|
9872
|
+
* const envelope = await client.envelopes.create({
|
|
9873
|
+
* name: 'Admission kit',
|
|
9874
|
+
* signers: [{ id: signerId }],
|
|
9875
|
+
* documents: [
|
|
9876
|
+
* { id: contractId, signer_ids: [signerId] },
|
|
9877
|
+
* { id: policyId, signer_ids: [signerId], expires_at: '2026-12-31' },
|
|
9878
|
+
* ],
|
|
9879
|
+
* }, { idempotencyKey: crypto.randomUUID() });
|
|
9880
|
+
* ```
|
|
9881
|
+
*/
|
|
9882
|
+
async create(payload, options = {}, accountId) {
|
|
9883
|
+
const body = buildEnvelopePayload(payload);
|
|
9884
|
+
assertRecord(options, "envelope options");
|
|
9885
|
+
const config = idempotencyConfig(options.idempotencyKey);
|
|
9886
|
+
this.logger.info("Creating envelope", {
|
|
9887
|
+
signerCount: body["signers"].length,
|
|
9888
|
+
documentCount: body["documents"].length
|
|
9889
|
+
});
|
|
9890
|
+
return this.call(
|
|
9891
|
+
"Failed to create envelope",
|
|
9892
|
+
() => this.http.post(this.envelopesPath(accountId), body, config)
|
|
9893
|
+
);
|
|
9894
|
+
}
|
|
9895
|
+
/**
|
|
9896
|
+
* Estimate what creating an envelope would cost
|
|
9897
|
+
* (`POST /accounts/{accountId}/envelopes/estimate-cost`).
|
|
9898
|
+
*
|
|
9899
|
+
* Takes the creation body and checks it the same way, creating and charging
|
|
9900
|
+
* nothing; `max_total_credits` is ignored. The envelope counts as one
|
|
9901
|
+
* document, each signer's notification and identity check once, and each
|
|
9902
|
+
* certificate signature per document.
|
|
9903
|
+
*
|
|
9904
|
+
* @param payload - The body {@link EnvelopeResource.create} would send.
|
|
9905
|
+
* @param accountId - Override the client's default account ID.
|
|
9906
|
+
* @returns A cost estimate:
|
|
9907
|
+
* ```jsonc
|
|
9908
|
+
* {
|
|
9909
|
+
* "documents": 1,
|
|
9910
|
+
* "credits": 1.45,
|
|
9911
|
+
* "needs_extra_document": false,
|
|
9912
|
+
* "extra_document_cost": 1,
|
|
9913
|
+
* "total_credits": 1.45,
|
|
9914
|
+
* "breakdown": [
|
|
9915
|
+
* { "code": "NotificationWhatsapp", "name": "WhatsApp notification", "cost": 0.45, "quantity": 1, "unit_cost": 0.45 },
|
|
9916
|
+
* { "code": "SignatureDigitalCertificate", "name": "Digital certificate signature", "cost": 1, "quantity": 2, "unit_cost": 0.5 }
|
|
9917
|
+
* ],
|
|
9918
|
+
* "document_balance": 97, // null when documents are not limited
|
|
9919
|
+
* "credit_balance": 10, // null when credits are not limited
|
|
9920
|
+
* "has_sufficient_resources": true,
|
|
9921
|
+
* "blocking_reason": null,
|
|
9922
|
+
* "message": null
|
|
9923
|
+
* }
|
|
9924
|
+
* ```
|
|
9925
|
+
* @throws {ValidationError} If the payload is malformed or a signer's channels do not pair.
|
|
9926
|
+
* @throws {ApiError} `400` for fields at fault, `403` (`PlanRestricted` or
|
|
9927
|
+
* `InsufficientScope`).
|
|
9928
|
+
*
|
|
9929
|
+
* @example
|
|
9930
|
+
* ```ts
|
|
9931
|
+
* const estimate = await client.envelopes.estimateCost(envelopeBody);
|
|
9932
|
+
* if (!estimate.has_sufficient_resources) console.warn(estimate.blocking_reason);
|
|
9933
|
+
* ```
|
|
9934
|
+
*/
|
|
9935
|
+
async estimateCost(payload, accountId) {
|
|
9936
|
+
const body = buildEnvelopePayload(payload);
|
|
9937
|
+
return this.call(
|
|
9938
|
+
"Failed to estimate envelope cost",
|
|
9939
|
+
() => this.http.post(`${this.envelopesPath(accountId)}/estimate-cost`, body)
|
|
9940
|
+
);
|
|
9941
|
+
}
|
|
9942
|
+
/**
|
|
9943
|
+
* Rename an envelope, change its message or reorder its documents
|
|
9944
|
+
* (`PATCH /accounts/{accountId}/envelopes/{envelopeId}`).
|
|
9945
|
+
*
|
|
9946
|
+
* Send only what changes. Nothing is sent to anyone; later reminders,
|
|
9947
|
+
* cancellations and additions use the new values. Works on closed envelopes.
|
|
9948
|
+
*
|
|
9949
|
+
* @param envelopeId - Envelope ID.
|
|
9950
|
+
* @param payload - At least one change.
|
|
9951
|
+
* @param payload.name - 1–255 characters without `<`.
|
|
9952
|
+
* @param payload.message - New message, or `null` for none.
|
|
9953
|
+
* @param payload.document_ids - Every document of the envelope, each once, in the new order.
|
|
9954
|
+
* @param accountId - Override the client's default account ID.
|
|
9955
|
+
* @returns The updated envelope (see {@link EnvelopeResource.list}).
|
|
9956
|
+
* @throws {ValidationError} If nothing would change or a value is malformed.
|
|
9957
|
+
* @throws {ApiError} `400` for fields at fault, `403` for a token without
|
|
9958
|
+
* `documents:write`, `404` for an unknown envelope.
|
|
9959
|
+
*
|
|
9960
|
+
* @example
|
|
9961
|
+
* ```ts
|
|
9962
|
+
* await client.envelopes.update(envelopeId, { name: 'Admission kit 2026', message: null });
|
|
9963
|
+
* ```
|
|
9964
|
+
*/
|
|
9965
|
+
async update(envelopeId, payload, accountId) {
|
|
9966
|
+
const body = buildUpdatePayload(payload);
|
|
9967
|
+
return this.call(
|
|
9968
|
+
"Failed to update envelope",
|
|
9969
|
+
() => this.http.patch(this.envelopePath(envelopeId, accountId), body)
|
|
9970
|
+
);
|
|
9971
|
+
}
|
|
9972
|
+
/**
|
|
9973
|
+
* Delete a closed envelope (`DELETE /accounts/{accountId}/envelopes/{envelopeId}`).
|
|
9974
|
+
*
|
|
9975
|
+
* Allowed once every document is certificated, declined, cancelled, expired
|
|
9976
|
+
* or failed; cancel it first otherwise. Its documents remain as ordinary
|
|
9977
|
+
* documents, and its `Idempotency-Key` no longer answers it.
|
|
9978
|
+
*
|
|
9979
|
+
* @param envelopeId - Envelope ID.
|
|
9980
|
+
* @param accountId - Override the client's default account ID.
|
|
9981
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9982
|
+
* @throws {ApiError} `403` for a token without `documents:write`, `404` for an
|
|
9983
|
+
* unknown envelope, `409` (`EnvelopeOpen`) while a document is still open.
|
|
9984
|
+
*
|
|
9985
|
+
* @example
|
|
9986
|
+
* ```ts
|
|
9987
|
+
* await client.envelopes.cancel(envelopeId);
|
|
9988
|
+
* await client.envelopes.delete(envelopeId);
|
|
9989
|
+
* ```
|
|
9990
|
+
*/
|
|
9991
|
+
async delete(envelopeId, accountId) {
|
|
9992
|
+
return this.callVoid(
|
|
9993
|
+
"Failed to delete envelope",
|
|
9994
|
+
() => this.http.delete(this.envelopePath(envelopeId, accountId))
|
|
9995
|
+
);
|
|
9996
|
+
}
|
|
9997
|
+
/**
|
|
9998
|
+
* Cancel every document that can still be cancelled
|
|
9999
|
+
* (`PUT /accounts/{accountId}/envelopes/{envelopeId}/cancel`).
|
|
10000
|
+
*
|
|
10001
|
+
* Each owner, signer and copy receiver is told once for the whole envelope.
|
|
10002
|
+
* Documents already closed, fully signed or being certificated are left as
|
|
10003
|
+
* they are. Safe to repeat: a second call cancels nothing.
|
|
10004
|
+
*
|
|
10005
|
+
* @param envelopeId - Envelope ID.
|
|
10006
|
+
* @param accountId - Override the client's default account ID.
|
|
10007
|
+
* @returns What happened to each document:
|
|
10008
|
+
* ```jsonc
|
|
10009
|
+
* [
|
|
10010
|
+
* { "id": "1052a1e9b8c7d6e5f4a3b2c1d0e9", "status": "cancelled", "cancelled": true },
|
|
10011
|
+
* { "id": "1052a1eaf9e8d7c6b5a4f3e2d1c0", "status": "certificated", "cancelled": false }
|
|
10012
|
+
* ]
|
|
10013
|
+
* ```
|
|
10014
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10015
|
+
* @throws {ApiError} `403` for a token without `documents:write`, `404` for an
|
|
10016
|
+
* unknown envelope.
|
|
10017
|
+
*
|
|
10018
|
+
* @example
|
|
10019
|
+
* ```ts
|
|
10020
|
+
* const results = await client.envelopes.cancel(envelopeId);
|
|
10021
|
+
* ```
|
|
10022
|
+
*/
|
|
10023
|
+
async cancel(envelopeId, accountId) {
|
|
10024
|
+
return this.call(
|
|
10025
|
+
"Failed to cancel envelope",
|
|
10026
|
+
() => this.http.put(`${this.envelopePath(envelopeId, accountId)}/cancel`)
|
|
10027
|
+
);
|
|
10028
|
+
}
|
|
10029
|
+
/**
|
|
10030
|
+
* Read the envelope's activity trail, newest first
|
|
10031
|
+
* (`GET /accounts/{accountId}/envelopes/{envelopeId}/activities`).
|
|
10032
|
+
*
|
|
10033
|
+
* Includes every document the envelope has had, including ones taken out;
|
|
10034
|
+
* each entry is a document activity that also names its document.
|
|
10035
|
+
*
|
|
10036
|
+
* @param envelopeId - Envelope ID.
|
|
10037
|
+
* @param params - `sort` (`-id`, the default, or `id` for oldest first),
|
|
10038
|
+
* `page`, and `per-page` (20 by default, at most 50).
|
|
10039
|
+
* @param accountId - Override the client's default account ID.
|
|
10040
|
+
* @returns Activity entries and pagination metadata:
|
|
10041
|
+
* ```jsonc
|
|
10042
|
+
* {
|
|
10043
|
+
* "data": [{
|
|
10044
|
+
* "id": 7731204,
|
|
10045
|
+
* "event": "signer_signed_document",
|
|
10046
|
+
* "message": "Ana Souza signed the document",
|
|
10047
|
+
* "payload": { "signer": { "id": "1052a1d4c3b2a1f0e9d8c7b6a5f4" } }, // same keys as that event's webhook
|
|
10048
|
+
* "origin": { "ip": "203.0.113.10", "user-agent": "Mozilla/5.0" },
|
|
10049
|
+
* "document_id": "1052a1e9b8c7d6e5f4a3b2c1d0e9",
|
|
10050
|
+
* "document_name": "contract.pdf",
|
|
10051
|
+
* "created_at": "2026-11-11T14:05:00Z"
|
|
10052
|
+
* }],
|
|
10053
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 }
|
|
10054
|
+
* }
|
|
10055
|
+
* ```
|
|
10056
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10057
|
+
* @throws {ApiError} `403` for a token without `documents:read`, `404` for an
|
|
10058
|
+
* unknown envelope.
|
|
10059
|
+
*
|
|
10060
|
+
* @example
|
|
10061
|
+
* ```ts
|
|
10062
|
+
* const { data } = await client.envelopes.listActivities(envelopeId, { sort: 'id' });
|
|
10063
|
+
* ```
|
|
10064
|
+
*/
|
|
10065
|
+
async listActivities(envelopeId, params = {}, accountId) {
|
|
10066
|
+
return this.callList(
|
|
10067
|
+
"Failed to fetch envelope activities",
|
|
10068
|
+
() => this.http.get(`${this.envelopePath(envelopeId, accountId)}/activities`, {
|
|
10069
|
+
params: cleanListParams(params)
|
|
10070
|
+
})
|
|
10071
|
+
);
|
|
10072
|
+
}
|
|
10073
|
+
/**
|
|
10074
|
+
* Download one artifact of every document as a zip
|
|
10075
|
+
* (`GET /accounts/{accountId}/envelopes/{envelopeId}/download/{artifactName}`).
|
|
10076
|
+
*
|
|
10077
|
+
* Files are named after their position (`1 - contract.pdf`); `bundle` gives
|
|
10078
|
+
* each document a folder. `certificated`, `certificate-page`, `pades` and
|
|
10079
|
+
* `bundle` include only the documents certified so far.
|
|
10080
|
+
*
|
|
10081
|
+
* @param envelopeId - Envelope ID.
|
|
10082
|
+
* @param artifactName - `original`, `certificated`, `certificate-page`, `pades` or `bundle`.
|
|
10083
|
+
* @param accountId - Override the client's default account ID.
|
|
10084
|
+
* @returns The zip archive bytes.
|
|
10085
|
+
* @throws {ValidationError} If an ID or the artifact name is invalid.
|
|
10086
|
+
* @throws {ApiError} `403` for a token without `documents:read`, `404` when no
|
|
10087
|
+
* document has the artifact.
|
|
10088
|
+
*
|
|
10089
|
+
* @example
|
|
10090
|
+
* ```ts
|
|
10091
|
+
* import { writeFile } from 'node:fs/promises';
|
|
10092
|
+
* await writeFile('envelope.zip', await client.envelopes.download(envelopeId, 'certificated'));
|
|
10093
|
+
* ```
|
|
10094
|
+
*/
|
|
10095
|
+
async download(envelopeId, artifactName, accountId) {
|
|
10096
|
+
assertDocumentArtifactName(artifactName);
|
|
10097
|
+
return this.callBinary(
|
|
10098
|
+
"Failed to download envelope artifacts",
|
|
10099
|
+
() => this.http.get(
|
|
10100
|
+
`${this.envelopePath(envelopeId, accountId)}/download/${this.pathSegment(artifactName, "Artifact name")}`,
|
|
10101
|
+
{ responseType: "arraybuffer" }
|
|
10102
|
+
)
|
|
10103
|
+
);
|
|
10104
|
+
}
|
|
10105
|
+
/**
|
|
10106
|
+
* Add a document to an open envelope for some of its signers
|
|
10107
|
+
* (`POST /accounts/{accountId}/envelopes/{envelopeId}/documents`).
|
|
10108
|
+
*
|
|
10109
|
+
* The document is checked as on creation and goes last. Only its
|
|
10110
|
+
* certificate signatures are charged; the chosen signers receive the
|
|
10111
|
+
* envelope invitation again, now listing it. No new signer can join, and an
|
|
10112
|
+
* envelope holds at most 20 documents.
|
|
10113
|
+
*
|
|
10114
|
+
* @param envelopeId - Envelope ID.
|
|
10115
|
+
* @param payload - `{ id, signer_ids, method?, entries?, expires_at?, copy_receiver_ids?, max_total_credits? }`.
|
|
10116
|
+
* @param accountId - Override the client's default account ID.
|
|
10117
|
+
* @returns The updated envelope (see {@link EnvelopeResource.list}).
|
|
10118
|
+
* @throws {ValidationError} If the document definition is malformed.
|
|
10119
|
+
* @throws {ApiError} `400` for fields at fault, `403` (`PlanRestricted` or
|
|
10120
|
+
* `InsufficientScope`), `409` (`EnvelopeClosed`, `CreditCeilingExceeded`).
|
|
10121
|
+
*
|
|
10122
|
+
* @example
|
|
10123
|
+
* ```ts
|
|
10124
|
+
* await client.envelopes.addDocument(envelopeId, { id: annexId, signer_ids: [signerId] });
|
|
10125
|
+
* ```
|
|
10126
|
+
*/
|
|
10127
|
+
async addDocument(envelopeId, payload, accountId) {
|
|
10128
|
+
const body = buildEnvelopeDocument(payload, "document");
|
|
10129
|
+
assertCreditCeiling(payload.max_total_credits);
|
|
10130
|
+
if (payload.max_total_credits !== void 0) body["max_total_credits"] = payload.max_total_credits;
|
|
10131
|
+
return this.call(
|
|
10132
|
+
"Failed to add document to envelope",
|
|
10133
|
+
() => this.http.post(`${this.envelopePath(envelopeId, accountId)}/documents`, body)
|
|
10134
|
+
);
|
|
10135
|
+
}
|
|
10136
|
+
/**
|
|
10137
|
+
* Take an open document out of the envelope
|
|
10138
|
+
* (`DELETE /accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}`).
|
|
10139
|
+
*
|
|
10140
|
+
* The document is cancelled and its people are told; the other documents
|
|
10141
|
+
* carry on, and links sent from it keep opening them.
|
|
10142
|
+
*
|
|
10143
|
+
* @param envelopeId - Envelope ID.
|
|
10144
|
+
* @param documentId - Document to take out.
|
|
10145
|
+
* @param accountId - Override the client's default account ID.
|
|
10146
|
+
* @returns The updated envelope (see {@link EnvelopeResource.list}).
|
|
10147
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10148
|
+
* @throws {ApiError} `403` for a token without `documents:write`, `404` when the
|
|
10149
|
+
* document is not in the envelope, `409` (`DocumentClosed`) when it can no
|
|
10150
|
+
* longer be cancelled.
|
|
10151
|
+
*
|
|
10152
|
+
* @example
|
|
10153
|
+
* ```ts
|
|
10154
|
+
* await client.envelopes.removeDocument(envelopeId, documentId);
|
|
10155
|
+
* ```
|
|
10156
|
+
*/
|
|
10157
|
+
async removeDocument(envelopeId, documentId, accountId) {
|
|
10158
|
+
return this.call(
|
|
10159
|
+
"Failed to remove document from envelope",
|
|
10160
|
+
() => this.http.delete(
|
|
10161
|
+
`${this.envelopePath(envelopeId, accountId)}/documents/${this.pathSegment(documentId, "Document ID")}`
|
|
10162
|
+
)
|
|
10163
|
+
);
|
|
10164
|
+
}
|
|
10165
|
+
/**
|
|
10166
|
+
* Remind a signer of the whole envelope
|
|
10167
|
+
* (`PUT /accounts/{accountId}/envelopes/{envelopeId}/signers/{signerId}/resend`).
|
|
10168
|
+
*
|
|
10169
|
+
* One message from their first link, listing the documents still to sign;
|
|
10170
|
+
* paid channels are charged once. A document's own reminder
|
|
10171
|
+
* (`assignments.resendNotification`) still goes per document.
|
|
10172
|
+
*
|
|
10173
|
+
* @param envelopeId - Envelope ID.
|
|
10174
|
+
* @param signerId - Signer of the envelope.
|
|
10175
|
+
* @param accountId - Override the client's default account ID.
|
|
10176
|
+
* @returns Delivery acknowledgement:
|
|
10177
|
+
* ```jsonc
|
|
10178
|
+
* { "is_sent": true, "envelope_id": "1052a1f0c3d4e5f6a7b8c9d0e1f2", "signer_id": "1052a1d4c3b2a1f0e9d8c7b6a5f4" }
|
|
10179
|
+
* ```
|
|
10180
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10181
|
+
* @throws {ApiError} `400` when the signer has nothing left to sign or credits
|
|
10182
|
+
* are short, `404` when the signer is not on the envelope, `409`
|
|
10183
|
+
* (`EnvelopeClosed`).
|
|
10184
|
+
*
|
|
10185
|
+
* @example
|
|
10186
|
+
* ```ts
|
|
10187
|
+
* await client.envelopes.resendNotification(envelopeId, signerId);
|
|
10188
|
+
* ```
|
|
10189
|
+
*/
|
|
10190
|
+
async resendNotification(envelopeId, signerId, accountId) {
|
|
10191
|
+
return this.call(
|
|
10192
|
+
"Failed to remind envelope signer",
|
|
10193
|
+
() => this.http.put(
|
|
10194
|
+
`${this.envelopePath(envelopeId, accountId)}/signers/${this.pathSegment(signerId, "Signer ID")}/resend`
|
|
10195
|
+
)
|
|
10196
|
+
);
|
|
10197
|
+
}
|
|
10198
|
+
envelopesPath(accountId) {
|
|
10199
|
+
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/envelopes`;
|
|
10200
|
+
}
|
|
10201
|
+
envelopePath(envelopeId, accountId) {
|
|
10202
|
+
return `${this.envelopesPath(accountId)}/${this.pathSegment(envelopeId, "Envelope ID")}`;
|
|
10203
|
+
}
|
|
10204
|
+
};
|
|
10205
|
+
function buildEnvelopePayload(payload) {
|
|
10206
|
+
assertRecord(payload, "envelope payload");
|
|
10207
|
+
assertNonEmptyString(payload.name, "name");
|
|
10208
|
+
assertMessage(payload.message);
|
|
10209
|
+
assertCreditCeiling(payload.max_total_credits);
|
|
10210
|
+
const signers = records(payload.signers, "signers").map((signer, index) => {
|
|
10211
|
+
const label = `signers[${index}]`;
|
|
10212
|
+
assertNonEmptyString(signer["id"], `${label}.id`);
|
|
10213
|
+
validateAssignmentSignerOptions(signer, label);
|
|
10214
|
+
const projected = { id: signer["id"] };
|
|
10215
|
+
for (const key of ["verification_method", "notification_methods", "embedded", "step"]) {
|
|
10216
|
+
if (signer[key] !== void 0) projected[key] = signer[key];
|
|
10217
|
+
}
|
|
10218
|
+
return projected;
|
|
10219
|
+
});
|
|
10220
|
+
const documents = records(payload.documents, "documents").map((document, index) => buildEnvelopeDocument(document, `documents[${index}]`));
|
|
10221
|
+
const body = { name: payload.name, signers, documents };
|
|
10222
|
+
if (payload.message !== void 0) body["message"] = payload.message;
|
|
10223
|
+
if (payload.max_total_credits !== void 0) body["max_total_credits"] = payload.max_total_credits;
|
|
10224
|
+
return body;
|
|
10225
|
+
}
|
|
10226
|
+
function buildEnvelopeDocument(document, label) {
|
|
10227
|
+
assertRecord(document, label);
|
|
10228
|
+
const input = document;
|
|
10229
|
+
assertNonEmptyString(input.id, `${label}.id`);
|
|
10230
|
+
const method = input.method ?? "virtual";
|
|
10231
|
+
if (method !== "virtual" && method !== "collect") {
|
|
10232
|
+
throw new ValidationError(`${label}.method must be virtual or collect`);
|
|
10233
|
+
}
|
|
10234
|
+
const entries = input.entries === void 0 ? void 0 : normaliseAssignmentEntries(input.entries);
|
|
10235
|
+
if (method === "collect" && !entries?.length) {
|
|
10236
|
+
throw new ValidationError(`${label}.entries is required for collect documents`);
|
|
10237
|
+
}
|
|
10238
|
+
if (input.expires_at !== void 0 && input.expires_at !== null) {
|
|
10239
|
+
assertExpirationDate(input.expires_at, `${label}.expires_at`);
|
|
10240
|
+
}
|
|
10241
|
+
const projected = {
|
|
10242
|
+
id: input.id,
|
|
10243
|
+
method,
|
|
10244
|
+
signer_ids: idList(input.signer_ids, `${label}.signer_ids`)
|
|
10245
|
+
};
|
|
10246
|
+
if (entries !== void 0) projected["entries"] = entries;
|
|
10247
|
+
if (input.expires_at !== void 0) projected["expires_at"] = input.expires_at;
|
|
10248
|
+
if (input.copy_receiver_ids !== void 0) {
|
|
10249
|
+
projected["copy_receiver_ids"] = idList(input.copy_receiver_ids, `${label}.copy_receiver_ids`);
|
|
10250
|
+
}
|
|
10251
|
+
return projected;
|
|
10252
|
+
}
|
|
10253
|
+
function buildUpdatePayload(payload) {
|
|
10254
|
+
assertRecord(payload, "envelope update");
|
|
10255
|
+
const body = {};
|
|
10256
|
+
if (payload.name !== void 0) {
|
|
10257
|
+
assertNonEmptyString(payload.name, "name");
|
|
10258
|
+
body["name"] = payload.name;
|
|
10259
|
+
}
|
|
10260
|
+
if (payload.message !== void 0) {
|
|
10261
|
+
assertMessage(payload.message);
|
|
10262
|
+
body["message"] = payload.message;
|
|
10263
|
+
}
|
|
10264
|
+
if (payload.document_ids !== void 0) {
|
|
10265
|
+
body["document_ids"] = idList(payload.document_ids, "document_ids");
|
|
10266
|
+
}
|
|
10267
|
+
if (Object.keys(body).length === 0) {
|
|
10268
|
+
throw new ValidationError("envelope update must change name, message or document_ids");
|
|
10269
|
+
}
|
|
10270
|
+
return body;
|
|
10271
|
+
}
|
|
10272
|
+
function assertMessage(message) {
|
|
10273
|
+
if (message !== void 0 && message !== null && typeof message !== "string") {
|
|
10274
|
+
throw new ValidationError("message must be a string or null");
|
|
10275
|
+
}
|
|
10276
|
+
}
|
|
10277
|
+
function records(value, label) {
|
|
10278
|
+
if (!Array.isArray(value)) throw new ValidationError(`${label} must be an array`);
|
|
10279
|
+
value.forEach((item, index) => assertRecord(item, `${label}[${index}]`));
|
|
10280
|
+
return value;
|
|
10281
|
+
}
|
|
10282
|
+
function idList(value, label) {
|
|
10283
|
+
if (!Array.isArray(value) || value.some((id) => typeof id !== "string" || !id.trim())) {
|
|
10284
|
+
throw new ValidationError(`${label} must be an array of IDs`);
|
|
10285
|
+
}
|
|
10286
|
+
return [...value];
|
|
10287
|
+
}
|
|
10288
|
+
|
|
10289
|
+
// src/resources/embed.ts
|
|
10290
|
+
var EmbedResource = class extends BaseResource {
|
|
10291
|
+
/**
|
|
10292
|
+
* List the origins allowed to embed signing pages, oldest first
|
|
10293
|
+
* (`GET /accounts/{accountId}/embed-origins`).
|
|
10294
|
+
*
|
|
10295
|
+
* @param accountId - Override the client's default account ID.
|
|
10296
|
+
* @returns Registered origins:
|
|
10297
|
+
* ```jsonc
|
|
10298
|
+
* [{ "id": "1052c7d8e9f0a1b2c3d4e5f6a7b8", "origin": "https://app.example.com", "created_at": "2026-11-04T12:05:00Z" }]
|
|
10299
|
+
* ```
|
|
10300
|
+
* @throws {ValidationError} If no account ID is available.
|
|
10301
|
+
* @throws {ApiError} `403` (`PlanRestricted`, or an OAuth application token).
|
|
10302
|
+
*
|
|
10303
|
+
* @example
|
|
10304
|
+
* ```ts
|
|
10305
|
+
* const origins = await client.embed.listOrigins();
|
|
10306
|
+
* ```
|
|
10307
|
+
*/
|
|
10308
|
+
async listOrigins(accountId) {
|
|
10309
|
+
return this.call("Failed to list embed origins", () => this.http.get(this.originsPath(accountId)));
|
|
10310
|
+
}
|
|
10311
|
+
/**
|
|
10312
|
+
* Allow one more origin to embed signing pages
|
|
10313
|
+
* (`POST /accounts/{accountId}/embed-origins`).
|
|
10314
|
+
*
|
|
10315
|
+
* An origin is an exact `https://host[:port]` (`http` only for `localhost`
|
|
10316
|
+
* and `127.0.0.1`) without path, query, fragment, credentials or wildcard;
|
|
10317
|
+
* the API lowercases the host and drops a default port. Up to 10 per account.
|
|
10318
|
+
*
|
|
10319
|
+
* @param origin - Origin of the page that will host the iframe.
|
|
10320
|
+
* @param accountId - Override the client's default account ID.
|
|
10321
|
+
* @returns The stored origin, e.g.
|
|
10322
|
+
* `{ "id": "1052c7d8e9f0a1b2c3d4e5f6a7b8", "origin": "https://app.example.com", "created_at": "2026-11-04T12:05:00Z" }`.
|
|
10323
|
+
* @throws {ValidationError} If `origin` is blank.
|
|
10324
|
+
* @throws {ApiError} `400` when it is invalid, already registered, or the
|
|
10325
|
+
* account has 10; `403` (`PlanRestricted`, or an OAuth application token).
|
|
10326
|
+
*
|
|
10327
|
+
* @example
|
|
10328
|
+
* ```ts
|
|
10329
|
+
* await client.embed.addOrigin('https://app.example.com');
|
|
10330
|
+
* ```
|
|
10331
|
+
*/
|
|
10332
|
+
async addOrigin(origin, accountId) {
|
|
10333
|
+
assertNonEmptyString(origin, "origin");
|
|
10334
|
+
return this.call(
|
|
10335
|
+
"Failed to add embed origin",
|
|
10336
|
+
() => this.http.post(this.originsPath(accountId), { origin })
|
|
10337
|
+
);
|
|
10338
|
+
}
|
|
10339
|
+
/**
|
|
10340
|
+
* Replace an allowed origin, keeping its ID
|
|
10341
|
+
* (`PUT /accounts/{accountId}/embed-origins/{originId}`).
|
|
10342
|
+
*
|
|
10343
|
+
* @param originId - Embed origin ID.
|
|
10344
|
+
* @param origin - New origin, with the rules of {@link EmbedResource.addOrigin}.
|
|
10345
|
+
* @param accountId - Override the client's default account ID.
|
|
10346
|
+
* @returns The updated origin.
|
|
10347
|
+
* @throws {ValidationError} If an ID or the origin is blank.
|
|
10348
|
+
* @throws {ApiError} `400` for an invalid or duplicate origin, `403`, `404` for
|
|
10349
|
+
* an unknown origin ID.
|
|
10350
|
+
*
|
|
10351
|
+
* @example
|
|
10352
|
+
* ```ts
|
|
10353
|
+
* await client.embed.updateOrigin(originId, 'https://sign.example.com');
|
|
10354
|
+
* ```
|
|
10355
|
+
*/
|
|
10356
|
+
async updateOrigin(originId, origin, accountId) {
|
|
10357
|
+
assertNonEmptyString(origin, "origin");
|
|
10358
|
+
return this.call(
|
|
10359
|
+
"Failed to update embed origin",
|
|
10360
|
+
() => this.http.put(this.originPath(originId, accountId), { origin })
|
|
10361
|
+
);
|
|
10362
|
+
}
|
|
10363
|
+
/**
|
|
10364
|
+
* Stop allowing an origin (`DELETE /accounts/{accountId}/embed-origins/{originId}`).
|
|
10365
|
+
*
|
|
10366
|
+
* Removing the last origin disables embedding: new sessions answer `409`
|
|
10367
|
+
* (`embed_origins_missing`).
|
|
10368
|
+
*
|
|
10369
|
+
* @param originId - Embed origin ID.
|
|
10370
|
+
* @param accountId - Override the client's default account ID.
|
|
10371
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10372
|
+
* @throws {ApiError} `403`, or `404` for an unknown origin ID.
|
|
10373
|
+
*
|
|
10374
|
+
* @example
|
|
10375
|
+
* ```ts
|
|
10376
|
+
* await client.embed.deleteOrigin(originId);
|
|
10377
|
+
* ```
|
|
10378
|
+
*/
|
|
10379
|
+
async deleteOrigin(originId, accountId) {
|
|
10380
|
+
return this.callVoid(
|
|
10381
|
+
"Failed to remove embed origin",
|
|
10382
|
+
() => this.http.delete(this.originPath(originId, accountId))
|
|
10383
|
+
);
|
|
10384
|
+
}
|
|
10385
|
+
/**
|
|
10386
|
+
* Mint a single-use embed URL for an `embedded` signer
|
|
10387
|
+
* (`POST /documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/embed-sessions`).
|
|
10388
|
+
*
|
|
10389
|
+
* Load the URL in an iframe on a registered origin within 5 minutes;
|
|
10390
|
+
* opening it spends the token, so mint a new one each time the frame is
|
|
10391
|
+
* shown, including reloads. Treat it as a credential: hand it only to that
|
|
10392
|
+
* signer's page and never store or log it. Limited to 30 sessions per signer
|
|
10393
|
+
* per hour. For an envelope signer, mint on any of their documents still
|
|
10394
|
+
* waiting for them; the frame lists every document they still have to sign.
|
|
10395
|
+
* Frame events are UI hints: confirm the outcome from webhooks.
|
|
10396
|
+
*
|
|
10397
|
+
* @param documentId - Document ID.
|
|
10398
|
+
* @param assignmentId - Assignment ID.
|
|
10399
|
+
* @param signerId - Signer created with `embedded: true`.
|
|
10400
|
+
* @returns The session:
|
|
10401
|
+
* ```jsonc
|
|
10402
|
+
* {
|
|
10403
|
+
* "url": "https://app.assinafy.com.br/embed/3b1f0c7e9a2d4c58b6e1f4a07d93c2e85a1b0f6d4c7e2a9183b5d6f0e4c8a712",
|
|
10404
|
+
* "expires_at": "2026-11-04T12:05:00Z"
|
|
10405
|
+
* }
|
|
10406
|
+
* ```
|
|
10407
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10408
|
+
* @throws {ApiError} `400` (`embed_not_enabled_for_signer`), `403`
|
|
10409
|
+
* (`PlanRestricted`), `404` for an unknown document, assignment or signer,
|
|
10410
|
+
* `409` (`already_signed`, `document_not_ready` — retry shortly,
|
|
10411
|
+
* `document_unavailable`, `embed_origins_missing`), `429` past 30 per hour.
|
|
10412
|
+
*
|
|
10413
|
+
* @example
|
|
10414
|
+
* ```ts
|
|
10415
|
+
* const { url } = await client.embed.createSession(document.id, assignment.id, signer.id);
|
|
10416
|
+
* response.json({ url }); // to the signer's browser only
|
|
10417
|
+
* ```
|
|
10418
|
+
*/
|
|
10419
|
+
async createSession(documentId, assignmentId, signerId) {
|
|
10420
|
+
return this.call(
|
|
10421
|
+
"Failed to create embed session",
|
|
10422
|
+
() => this.http.post(
|
|
10423
|
+
`/documents/${this.pathSegment(documentId, "Document ID")}/assignments/${this.pathSegment(assignmentId, "Assignment ID")}/signers/${this.pathSegment(signerId, "Signer ID")}/embed-sessions`
|
|
10424
|
+
)
|
|
10425
|
+
);
|
|
10426
|
+
}
|
|
10427
|
+
originsPath(accountId) {
|
|
10428
|
+
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/embed-origins`;
|
|
10429
|
+
}
|
|
10430
|
+
originPath(originId, accountId) {
|
|
10431
|
+
return `${this.originsPath(accountId)}/${this.pathSegment(originId, "Embed origin ID")}`;
|
|
10432
|
+
}
|
|
10433
|
+
};
|
|
10434
|
+
|
|
9084
10435
|
// src/support/webhook-verifier.ts
|
|
9085
10436
|
var import_node_crypto2 = require("crypto");
|
|
9086
10437
|
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
9087
10438
|
var WebhookVerifier = class {
|
|
9088
10439
|
webhookSecret;
|
|
9089
10440
|
/**
|
|
9090
|
-
* @param webhookSecret - The endpoint's `whsec_…` secret
|
|
9091
|
-
* `webhooks.
|
|
9092
|
-
* (
|
|
10441
|
+
* @param webhookSecret - The endpoint's `whsec_…` secret, as returned by
|
|
10442
|
+
* `webhooks.createEndpoint()` / `updateEndpoint()` when signing turns on,
|
|
10443
|
+
* `rotateEndpointSecret()`, or (API key only) `getEndpointSecret()`. Omit it
|
|
10444
|
+
* to keep verification disabled (every check returns `false`).
|
|
9093
10445
|
*
|
|
9094
10446
|
* @example
|
|
9095
10447
|
* ```ts
|
|
@@ -9142,6 +10494,7 @@ var WebhookVerifier = class {
|
|
|
9142
10494
|
const [version, signature] = entry.split(",", 2);
|
|
9143
10495
|
if (version !== "v1" || !signature) return false;
|
|
9144
10496
|
const actual = Buffer.from(signature, "base64");
|
|
10497
|
+
if (actual.toString("base64") !== signature) return false;
|
|
9145
10498
|
return actual.length === expected.length && (0, import_node_crypto2.timingSafeEqual)(actual, expected);
|
|
9146
10499
|
});
|
|
9147
10500
|
}
|
|
@@ -9269,6 +10622,8 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9269
10622
|
signerDocuments;
|
|
9270
10623
|
users;
|
|
9271
10624
|
contracts;
|
|
10625
|
+
envelopes;
|
|
10626
|
+
embed;
|
|
9272
10627
|
webhookVerifier;
|
|
9273
10628
|
/**
|
|
9274
10629
|
* Create a client. Supply `apiKey` (preferred, sent as `X-Api-Key`) or a
|
|
@@ -9378,7 +10733,12 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9378
10733
|
this.logger,
|
|
9379
10734
|
this.publicAxiosInstance
|
|
9380
10735
|
);
|
|
9381
|
-
this.fields = new FieldsResource(
|
|
10736
|
+
this.fields = new FieldsResource(
|
|
10737
|
+
this.axiosInstance,
|
|
10738
|
+
this.defaultAccountId,
|
|
10739
|
+
this.logger,
|
|
10740
|
+
this.publicAxiosInstance
|
|
10741
|
+
);
|
|
9382
10742
|
this.signerDocuments = new SignerDocumentsResource(
|
|
9383
10743
|
this.axiosInstance,
|
|
9384
10744
|
this.defaultAccountId,
|
|
@@ -9391,6 +10751,8 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9391
10751
|
this.defaultAccountId,
|
|
9392
10752
|
this.logger
|
|
9393
10753
|
);
|
|
10754
|
+
this.envelopes = new EnvelopeResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
10755
|
+
this.embed = new EmbedResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
9394
10756
|
this.webhookVerifier = new WebhookVerifier(this.webhookSecret);
|
|
9395
10757
|
}
|
|
9396
10758
|
/**
|
|
@@ -9563,7 +10925,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
9563
10925
|
* });
|
|
9564
10926
|
* console.log(document.status); // usually 'pending_signature'
|
|
9565
10927
|
* console.log(signer_ids.length); // 2
|
|
9566
|
-
* console.log(assignment.signing_urls?.length); // one
|
|
10928
|
+
* console.log(assignment.signing_urls?.length); // one entry per notified signer; url is null for embedded or WhatsApp-only signers
|
|
9567
10929
|
* ```
|
|
9568
10930
|
*/
|
|
9569
10931
|
async uploadAndRequestSignatures(options) {
|
|
@@ -9822,6 +11184,8 @@ function hasIdempotencyKey(headers) {
|
|
|
9822
11184
|
DEFAULT_WEBHOOK_EVENTS,
|
|
9823
11185
|
DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD,
|
|
9824
11186
|
DocumentResource,
|
|
11187
|
+
EmbedResource,
|
|
11188
|
+
EnvelopeResource,
|
|
9825
11189
|
FieldsResource,
|
|
9826
11190
|
MAX_LIST_PAGE_SIZE,
|
|
9827
11191
|
MAX_UPLOAD_BYTES,
|