@assinafy/cli 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.env.example +2 -0
  2. package/README.en.md +14 -8
  3. package/README.md +82 -415
  4. package/dist/api.cjs +524 -65
  5. package/dist/api.cjs.map +1 -1
  6. package/dist/api.js +521 -65
  7. package/dist/api.js.map +1 -1
  8. package/dist/cli.cjs +1017 -177
  9. package/dist/types/api/client.d.ts +5 -0
  10. package/dist/types/api/client.d.ts.map +1 -1
  11. package/dist/types/api/envelope-types.d.ts +73 -0
  12. package/dist/types/api/envelope-types.d.ts.map +1 -0
  13. package/dist/types/api/index.d.ts +3 -0
  14. package/dist/types/api/index.d.ts.map +1 -1
  15. package/dist/types/api/resources/assignments.d.ts.map +1 -1
  16. package/dist/types/api/resources/contracts.d.ts +3 -1
  17. package/dist/types/api/resources/contracts.d.ts.map +1 -1
  18. package/dist/types/api/resources/documents.d.ts +21 -6
  19. package/dist/types/api/resources/documents.d.ts.map +1 -1
  20. package/dist/types/api/resources/embed.d.ts +14 -0
  21. package/dist/types/api/resources/embed.d.ts.map +1 -0
  22. package/dist/types/api/resources/envelopes.d.ts +31 -0
  23. package/dist/types/api/resources/envelopes.d.ts.map +1 -0
  24. package/dist/types/api/resources/signer-documents.d.ts +23 -11
  25. package/dist/types/api/resources/signer-documents.d.ts.map +1 -1
  26. package/dist/types/api/resources/signers.d.ts +1 -1
  27. package/dist/types/api/resources/signers.d.ts.map +1 -1
  28. package/dist/types/api/resources/users.d.ts +3 -1
  29. package/dist/types/api/resources/users.d.ts.map +1 -1
  30. package/dist/types/api/resources/webhooks.d.ts +6 -2
  31. package/dist/types/api/resources/webhooks.d.ts.map +1 -1
  32. package/dist/types/api/resources/workspaces.d.ts +9 -2
  33. package/dist/types/api/resources/workspaces.d.ts.map +1 -1
  34. package/dist/types/api/types.d.ts +103 -7
  35. package/dist/types/api/types.d.ts.map +1 -1
  36. package/dist/types/api/utils.d.ts +6 -0
  37. package/dist/types/api/utils.d.ts.map +1 -1
  38. package/docs/README.md +3 -1
  39. package/docs/api-operations.json +234 -2
  40. package/docs/api-reference.md +11533 -3716
  41. package/docs/assignments.md +16 -14
  42. package/docs/contracts.md +4 -3
  43. package/docs/documents.md +44 -27
  44. package/docs/embed.md +119 -0
  45. package/docs/envelopes.md +210 -0
  46. package/docs/releasing.md +38 -12
  47. package/docs/sdk-reference.md +215 -29
  48. package/docs/send.md +15 -11
  49. package/docs/signer.md +84 -3
  50. package/docs/users.md +41 -0
  51. package/docs/webhooks.md +22 -6
  52. package/docs/workspaces.md +66 -3
  53. package/package.json +1 -1
package/dist/api.cjs CHANGED
@@ -37,10 +37,13 @@ __export(api_exports, {
37
37
  AuthenticationResource: () => AuthenticationResource,
38
38
  ContractResource: () => ContractResource,
39
39
  DocumentResource: () => DocumentResource,
40
+ EmbedResource: () => EmbedResource,
41
+ EnvelopeResource: () => EnvelopeResource,
40
42
  FieldsResource: () => FieldsResource,
41
43
  NOTIFICATION_PREFERENCE_CODES: () => NOTIFICATION_PREFERENCE_CODES,
42
44
  NetworkError: () => NetworkError,
43
45
  OAuthResource: () => OAuthResource,
46
+ PUSH_PREFERENCE_CODES: () => PUSH_PREFERENCE_CODES,
44
47
  PartialWorkflowError: () => PartialWorkflowError,
45
48
  SignerDocumentsResource: () => SignerDocumentsResource,
46
49
  SignerResource: () => SignerResource,
@@ -146,6 +149,7 @@ var PartialWorkflowError = class extends AssinafyError {
146
149
  };
147
150
 
148
151
  // src/api/utils.ts
152
+ var import_node_http = require("http");
149
153
  var import_axios = __toESM(require("axios"), 1);
150
154
  var DOCUMENT_ARTIFACT_NAMES = [
151
155
  "original",
@@ -264,6 +268,12 @@ function requireEmail(value) {
264
268
  return value;
265
269
  }
266
270
  function validateSignerOptions(input) {
271
+ if (input.embedded !== void 0 && typeof input.embedded !== "boolean") {
272
+ throw new ValidationError("embedded must be a boolean");
273
+ }
274
+ if (input.embedded === true && input.verification_method !== void 0 && !["Email", "Whatsapp"].includes(input.verification_method)) {
275
+ throw new ValidationError("Embedded signing requires Email or Whatsapp verification");
276
+ }
267
277
  if (input.verification_method !== void 0 && !VERIFICATION_METHODS.includes(input.verification_method)) {
268
278
  throw new ValidationError(
269
279
  `verification_method must be one of: ${VERIFICATION_METHODS.join(", ")}`
@@ -290,6 +300,33 @@ function validateSignerOptions(input) {
290
300
  throw new ValidationError("step must be an integer");
291
301
  }
292
302
  }
303
+ function validateCreditCeiling(value) {
304
+ if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value) || value < 0)) {
305
+ throw new ValidationError("max_total_credits must be a finite non-negative number");
306
+ }
307
+ }
308
+ function idempotencyHeaders(key) {
309
+ if (key === void 0) return void 0;
310
+ if (typeof key !== "string" || !key.trim()) {
311
+ throw new ValidationError("idempotencyKey must be nonblank text");
312
+ }
313
+ try {
314
+ (0, import_node_http.validateHeaderValue)("Idempotency-Key", key);
315
+ } catch {
316
+ throw new ValidationError("idempotencyKey must be a valid HTTP header value");
317
+ }
318
+ return { "Idempotency-Key": key };
319
+ }
320
+ function validateBooleanMap(payload, allowed) {
321
+ if (!payload || typeof payload !== "object" || Array.isArray(payload) || !Object.keys(payload).length) {
322
+ throw new ValidationError("At least one notification preference is required");
323
+ }
324
+ for (const [key, value] of Object.entries(payload)) {
325
+ if (!allowed.includes(key))
326
+ throw new ValidationError(`Unknown notification preference: ${key}`);
327
+ if (typeof value !== "boolean") throw new ValidationError(`${key} must be a boolean`);
328
+ }
329
+ }
293
330
  function validateDigitalCertificateMethod(method, signers) {
294
331
  if (method !== "virtual" && signers.some((signer) => signer.verification_method === "DigitalCertificate")) {
295
332
  throw new ValidationError("DigitalCertificate signers require method: virtual", {
@@ -468,6 +505,7 @@ function buildAssignmentPayload(payload, options = {}) {
468
505
  throw new ValidationError("method must be virtual or collect");
469
506
  }
470
507
  const signers = extractSignerRefs(payload);
508
+ validateCreditCeiling(payload.max_total_credits);
471
509
  if (signers.length === 0) {
472
510
  throw new ValidationError("At least one signer is required", {
473
511
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
@@ -488,7 +526,8 @@ function buildAssignmentPayload(payload, options = {}) {
488
526
  message: payload.message,
489
527
  expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
490
528
  copy_receivers: payload.copy_receivers,
491
- entries: payload.entries
529
+ entries: payload.entries,
530
+ max_total_credits: payload.max_total_credits
492
531
  });
493
532
  }
494
533
  function extractSignerRefs(payload) {
@@ -517,7 +556,8 @@ function normaliseSignerRef(ref, options) {
517
556
  id,
518
557
  verification_method: input.verification_method,
519
558
  notification_methods: input.notification_methods,
520
- step: input.step
559
+ step: input.step,
560
+ embedded: input.embedded
521
561
  });
522
562
  if (typeof id === "string" && id.length > 0) {
523
563
  return normalised;
@@ -869,12 +909,14 @@ var ContractResource = class extends BaseResource {
869
909
  );
870
910
  }
871
911
  /** Read the root contract and its amendments from any document in that family. */
872
- async related(documentId, accountId) {
912
+ async related(documentId, accountId, params = {}) {
873
913
  const id = this.accountId(accountId);
874
914
  const did = this.requireId(documentId, "Document ID");
875
915
  return this.call(
876
916
  "Failed to get related contracts",
877
- () => this.http.get(`/accounts/${id}/documents/${did}/contract/related`)
917
+ () => this.http.get(`/accounts/${id}/documents/${did}/contract/related`, {
918
+ params: cleanParams(params)
919
+ })
878
920
  );
879
921
  }
880
922
  /** Advance from the supplied current term or to a later end date. No automatic retry. */
@@ -1055,9 +1097,9 @@ var DocumentResource = class extends BaseResource {
1055
1097
  );
1056
1098
  }
1057
1099
  /** Get document details. */
1058
- async details(documentId) {
1100
+ async details(documentId, params = {}) {
1059
1101
  const id = this.requireId(documentId, "Document ID");
1060
- return this.fetchDetails(id);
1102
+ return this.fetchDetails(id, void 0, params);
1061
1103
  }
1062
1104
  /**
1063
1105
  * Rename a document (`PATCH /documents/{id}`).
@@ -1074,8 +1116,17 @@ var DocumentResource = class extends BaseResource {
1074
1116
  );
1075
1117
  }
1076
1118
  /** Alias for {@link details}. */
1077
- async get(documentId) {
1078
- return this.details(documentId);
1119
+ async get(documentId, params = {}) {
1120
+ return this.details(documentId, params);
1121
+ }
1122
+ /** Read only the assignment items visible to this signer. */
1123
+ async getAsSigner(documentId, signerAccessCode) {
1124
+ const id = this.requireId(documentId, "Document ID");
1125
+ const code = this.requireId(signerAccessCode, "signer-access-code");
1126
+ return this.call(
1127
+ "Failed to fetch signer document",
1128
+ () => this.http.get(`/documents/${id}`, signerAccessConfig(code))
1129
+ );
1079
1130
  }
1080
1131
  /** Poll document status until ready (or a terminal status / timeout). */
1081
1132
  async waitUntilReady(documentId, options = {}) {
@@ -1122,42 +1173,57 @@ var DocumentResource = class extends BaseResource {
1122
1173
  attempts
1123
1174
  });
1124
1175
  }
1125
- fetchDetails(documentId, timeout) {
1176
+ fetchDetails(documentId, timeout, params) {
1126
1177
  return this.call(
1127
1178
  "Failed to fetch document details",
1128
- () => this.http.get(`/documents/${documentId}`, timeout === void 0 ? void 0 : { timeout })
1179
+ () => this.http.get(`/documents/${documentId}`, { timeout, ...params?.expand ? { params } : {} })
1129
1180
  );
1130
1181
  }
1131
1182
  /** Download a document artifact. Defaults to the certificated (signed) PDF. */
1132
- async download(documentId, artifactName = "certificated") {
1183
+ async download(documentId, artifactName = "certificated", options = {}) {
1133
1184
  const id = this.requireId(documentId, "Document ID");
1134
1185
  const artifact = requireDocumentArtifactName(artifactName);
1186
+ const config = this.artifactConfig(options);
1135
1187
  return this.callBinary(
1136
1188
  "Failed to download document",
1137
1189
  () => this.http.get(`/documents/${id}/download/${artifact}`, {
1190
+ ...config,
1138
1191
  responseType: "arraybuffer"
1139
1192
  })
1140
1193
  );
1141
1194
  }
1142
1195
  /** Download the document thumbnail. */
1143
- async thumbnail(documentId) {
1196
+ async thumbnail(documentId, options = {}) {
1197
+ const config = this.artifactConfig(options);
1144
1198
  const id = this.requireId(documentId, "Document ID");
1145
1199
  return this.callBinary(
1146
1200
  "Failed to download document thumbnail",
1147
- () => this.http.get(`/documents/${id}/thumbnail`, { responseType: "arraybuffer" })
1201
+ () => this.http.get(`/documents/${id}/thumbnail`, {
1202
+ ...config,
1203
+ responseType: "arraybuffer"
1204
+ })
1148
1205
  );
1149
1206
  }
1150
1207
  /** Download a single page as a JPEG. */
1151
- async downloadPage(documentId, pageId) {
1208
+ async downloadPage(documentId, pageId, options = {}) {
1209
+ const config = this.artifactConfig(options);
1152
1210
  const docId = this.requireId(documentId, "Document ID");
1153
1211
  const pid = this.requireId(pageId, "Page ID");
1154
1212
  return this.callBinary(
1155
1213
  "Failed to download page",
1156
1214
  () => this.http.get(`/documents/${docId}/pages/${pid}/download`, {
1215
+ ...config,
1157
1216
  responseType: "arraybuffer"
1158
1217
  })
1159
1218
  );
1160
1219
  }
1220
+ artifactConfig(options) {
1221
+ if (options.artifact !== void 0 && options.artifact !== "certificated") {
1222
+ throw new ValidationError("artifact must be certificated");
1223
+ }
1224
+ const params = options.artifact === void 0 ? {} : { artifact: options.artifact };
1225
+ return options.signerAccessCode === void 0 ? { params } : signerAccessConfig(this.requireId(options.signerAccessCode, "signer-access-code"), params);
1226
+ }
1161
1227
  /** Fetch one page of the document activity log (20 entries by default). */
1162
1228
  async activities(documentId, params = {}) {
1163
1229
  const id = this.requireId(documentId, "Document ID");
@@ -1231,6 +1297,9 @@ var DocumentResource = class extends BaseResource {
1231
1297
  const tmplId = this.requireId(templateId, "Template ID");
1232
1298
  const accId = this.accountId(accountId);
1233
1299
  validateTemplateSigners(signers, { requireIdentity: true });
1300
+ validateCreditCeiling(options.max_total_credits);
1301
+ const { idempotencyKey, ...bodyOptions } = options;
1302
+ const headers = idempotencyHeaders(idempotencyKey);
1234
1303
  if (options.expires_at !== void 0) requireExpiration(options.expires_at);
1235
1304
  if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
1236
1305
  throw new ValidationError("editor_fields must contain field_id and value");
@@ -1239,11 +1308,11 @@ var DocumentResource = class extends BaseResource {
1239
1308
  throw new ValidationError("tags must contain non-empty tag names");
1240
1309
  }
1241
1310
  await this.validateCertificateTemplateMethod(tmplId, accId, signers);
1242
- const body = { ...options, signers };
1311
+ const body = { ...bodyOptions, signers };
1243
1312
  this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
1244
1313
  return this.call(
1245
1314
  "Failed to create document from template",
1246
- () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents`, body)
1315
+ () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents`, body, { headers })
1247
1316
  );
1248
1317
  }
1249
1318
  /** Estimate the credit cost of creating a document from a template. */
@@ -1422,6 +1491,265 @@ function sleep(ms) {
1422
1491
  return new Promise((resolve) => setTimeout(resolve, ms));
1423
1492
  }
1424
1493
 
1494
+ // src/api/resources/embed.ts
1495
+ var EmbedResource = class extends BaseResource {
1496
+ async listOrigins(accountId) {
1497
+ const id = this.accountId(accountId);
1498
+ return this.call(
1499
+ "Failed to list embed origins",
1500
+ () => this.http.get(`/accounts/${id}/embed-origins`)
1501
+ );
1502
+ }
1503
+ async createOrigin(origin, accountId) {
1504
+ const id = this.accountId(accountId);
1505
+ validateOrigin(origin);
1506
+ return this.call(
1507
+ "Failed to add embed origin",
1508
+ () => this.http.post(`/accounts/${id}/embed-origins`, { origin })
1509
+ );
1510
+ }
1511
+ async updateOrigin(originId, origin, accountId) {
1512
+ const id = this.accountId(accountId);
1513
+ const oid = this.requireId(originId, "Origin ID");
1514
+ validateOrigin(origin);
1515
+ return this.call(
1516
+ "Failed to update embed origin",
1517
+ () => this.http.put(`/accounts/${id}/embed-origins/${oid}`, { origin })
1518
+ );
1519
+ }
1520
+ async deleteOrigin(originId, accountId) {
1521
+ const id = this.accountId(accountId);
1522
+ const oid = this.requireId(originId, "Origin ID");
1523
+ return this.call(
1524
+ "Failed to delete embed origin",
1525
+ () => this.http.delete(`/accounts/${id}/embed-origins/${oid}`)
1526
+ );
1527
+ }
1528
+ /** Load the returned private URL in the iframe within five minutes. */
1529
+ async createSession(documentId, assignmentId, signerId) {
1530
+ const did = this.requireId(documentId, "Document ID");
1531
+ const aid = this.requireId(assignmentId, "Assignment ID");
1532
+ const sid = this.requireId(signerId, "Signer ID");
1533
+ return this.call(
1534
+ "Failed to create embed session",
1535
+ () => this.http.post(`/documents/${did}/assignments/${aid}/signers/${sid}/embed-sessions`)
1536
+ );
1537
+ }
1538
+ /** Used by Assinafy's embed page; consumes the token even on a 409. Never retry automatically. */
1539
+ async exchangeSession(token, parentOrigin) {
1540
+ const value = this.requireId(token, "Embed session token");
1541
+ if (parentOrigin !== void 0) validateOrigin(parentOrigin);
1542
+ return this.call(
1543
+ "Failed to exchange embed session",
1544
+ () => this.http.post(
1545
+ `/embed/sessions/${value}/exchange`,
1546
+ parentOrigin === void 0 ? void 0 : { parent_origin: parentOrigin },
1547
+ publicRequestConfig()
1548
+ )
1549
+ );
1550
+ }
1551
+ };
1552
+ function validateOrigin(value) {
1553
+ let url;
1554
+ try {
1555
+ url = new URL(value);
1556
+ } catch {
1557
+ throw new ValidationError("origin must be an absolute origin");
1558
+ }
1559
+ if (typeof value !== "string" || /[\s\\?#*]/.test(value) || !/^[a-z][a-z\d+.-]*:\/\/[^/]+\/?$/i.test(value) || url.username || url.password || url.pathname !== "/" || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname))) {
1560
+ throw new ValidationError(
1561
+ "origin must use HTTPS (HTTP only for localhost or 127.0.0.1) without path, credentials, query, fragment or wildcard"
1562
+ );
1563
+ }
1564
+ }
1565
+
1566
+ // src/api/resources/envelopes.ts
1567
+ var EnvelopeResource = class extends BaseResource {
1568
+ async list(params = {}, accountId) {
1569
+ const id = this.accountId(accountId);
1570
+ if (params.status !== void 0 && !["open", "closed"].includes(params.status))
1571
+ throw new ValidationError("status must be open or closed");
1572
+ return this.callList(
1573
+ "Failed to list envelopes",
1574
+ () => this.http.get(`/accounts/${id}/envelopes`, { params: cleanParams({ ...params }) })
1575
+ );
1576
+ }
1577
+ /** Creates assignments and sends invitations; persist the result before checking delivery. */
1578
+ async create(payload, options = {}) {
1579
+ const id = this.accountId(options.accountId);
1580
+ validateCreate(payload);
1581
+ const headers = idempotencyHeaders(options.idempotencyKey);
1582
+ return this.call(
1583
+ "Failed to create envelope",
1584
+ () => this.http.post(`/accounts/${id}/envelopes`, payload, { headers })
1585
+ );
1586
+ }
1587
+ async estimateCost(payload, accountId) {
1588
+ const id = this.accountId(accountId);
1589
+ validateCreate(payload);
1590
+ return this.call(
1591
+ "Failed to estimate envelope cost",
1592
+ () => this.http.post(`/accounts/${id}/envelopes/estimate-cost`, payload)
1593
+ );
1594
+ }
1595
+ async get(envelopeId, accountId) {
1596
+ const id = this.accountId(accountId);
1597
+ const eid = this.requireId(envelopeId, "Envelope ID");
1598
+ return this.call(
1599
+ "Failed to fetch envelope",
1600
+ () => this.http.get(`/accounts/${id}/envelopes/${eid}`)
1601
+ );
1602
+ }
1603
+ /** Renames, changes the message (null clears), or reorders every current document. */
1604
+ async update(envelopeId, payload, accountId) {
1605
+ const id = this.accountId(accountId);
1606
+ const eid = this.requireId(envelopeId, "Envelope ID");
1607
+ if (!payload || !["name", "message", "document_ids"].some(
1608
+ (key) => payload[key] !== void 0
1609
+ ))
1610
+ throw new ValidationError("At least one envelope field is required");
1611
+ if (payload.name !== void 0) validateName(payload.name);
1612
+ validateMessage(payload.message);
1613
+ if (payload.document_ids !== void 0) validateIds(payload.document_ids, "document_ids");
1614
+ return this.call(
1615
+ "Failed to update envelope",
1616
+ () => this.http.patch(`/accounts/${id}/envelopes/${eid}`, payload)
1617
+ );
1618
+ }
1619
+ /** Requires a closed envelope; its documents are retained by the server. */
1620
+ async delete(envelopeId, accountId) {
1621
+ const id = this.accountId(accountId);
1622
+ const eid = this.requireId(envelopeId, "Envelope ID");
1623
+ return this.call(
1624
+ "Failed to delete envelope",
1625
+ () => this.http.delete(`/accounts/${id}/envelopes/${eid}`)
1626
+ );
1627
+ }
1628
+ async activities(envelopeId, params = {}, accountId) {
1629
+ const id = this.accountId(accountId);
1630
+ const eid = this.requireId(envelopeId, "Envelope ID");
1631
+ requireSort(params.sort, ["id", "-id"]);
1632
+ return this.callList(
1633
+ "Failed to fetch envelope activities",
1634
+ () => this.http.get(`/accounts/${id}/envelopes/${eid}/activities`, {
1635
+ params: cleanParams({ ...params })
1636
+ })
1637
+ );
1638
+ }
1639
+ /** ZIP containing the requested artifact of each eligible document. */
1640
+ async download(envelopeId, artifactName = "certificated", accountId) {
1641
+ const id = this.accountId(accountId);
1642
+ const eid = this.requireId(envelopeId, "Envelope ID");
1643
+ const artifact = requireDocumentArtifactName(artifactName);
1644
+ return this.callBinary(
1645
+ "Failed to download envelope",
1646
+ () => this.http.get(`/accounts/${id}/envelopes/${eid}/download/${artifact}`, {
1647
+ responseType: "arraybuffer"
1648
+ })
1649
+ );
1650
+ }
1651
+ /** Cancels only cancellable documents and notifies their recipients. */
1652
+ async cancel(envelopeId, accountId) {
1653
+ const id = this.accountId(accountId);
1654
+ const eid = this.requireId(envelopeId, "Envelope ID");
1655
+ return this.call(
1656
+ "Failed to cancel envelope",
1657
+ () => this.http.put(`/accounts/${id}/envelopes/${eid}/cancel`)
1658
+ );
1659
+ }
1660
+ async resendNotification(envelopeId, signerId, accountId) {
1661
+ const id = this.accountId(accountId);
1662
+ const eid = this.requireId(envelopeId, "Envelope ID");
1663
+ const sid = this.requireId(signerId, "Signer ID");
1664
+ return this.call(
1665
+ "Failed to resend envelope notification",
1666
+ () => this.http.put(`/accounts/${id}/envelopes/${eid}/signers/${sid}/resend`)
1667
+ );
1668
+ }
1669
+ /** Adds a processed document for existing envelope signers and sends updated invitations. */
1670
+ async addDocument(envelopeId, payload, accountId) {
1671
+ const id = this.accountId(accountId);
1672
+ const eid = this.requireId(envelopeId, "Envelope ID");
1673
+ validateDocument(payload);
1674
+ validateCreditCeiling(payload.max_total_credits);
1675
+ return this.call(
1676
+ "Failed to add envelope document",
1677
+ () => this.http.post(`/accounts/${id}/envelopes/${eid}/documents`, payload)
1678
+ );
1679
+ }
1680
+ /** Cancels an open document, notifies its recipients, and removes it from the envelope. */
1681
+ async removeDocument(envelopeId, documentId, accountId) {
1682
+ const id = this.accountId(accountId);
1683
+ const eid = this.requireId(envelopeId, "Envelope ID");
1684
+ const did = this.requireId(documentId, "Document ID");
1685
+ return this.call(
1686
+ "Failed to remove envelope document",
1687
+ () => this.http.delete(`/accounts/${id}/envelopes/${eid}/documents/${did}`)
1688
+ );
1689
+ }
1690
+ };
1691
+ function validateName(value) {
1692
+ if (typeof value !== "string" || !value.trim() || [...value].length > 255 || value.includes("<"))
1693
+ throw new ValidationError("name must contain 1\u2013255 characters without <");
1694
+ }
1695
+ function validateMessage(value) {
1696
+ if (value != null && typeof value !== "string")
1697
+ throw new ValidationError("message must be text or null");
1698
+ }
1699
+ function validateIds(values, name) {
1700
+ if (!Array.isArray(values) || !values.length || values.some((id) => typeof id !== "string" || !id.trim()) || new Set(values).size !== values.length)
1701
+ throw new ValidationError(`${name} must contain distinct nonblank IDs`);
1702
+ }
1703
+ function validateDocument(payload) {
1704
+ if (!payload || typeof payload.id !== "string" || !payload.id.trim())
1705
+ throw new ValidationError("Document ID is required");
1706
+ validateIds(payload.signer_ids, "signer_ids");
1707
+ if (payload.method !== void 0 && !["virtual", "collect"].includes(payload.method))
1708
+ throw new ValidationError("method must be virtual or collect");
1709
+ if (payload.method === "collect" && (!Array.isArray(payload.entries) || !payload.entries.length))
1710
+ throw new ValidationError("entries are required for collect documents");
1711
+ if (payload.expires_at != null && typeof payload.expires_at !== "string" && (typeof payload.expires_at !== "number" || !Number.isFinite(payload.expires_at)))
1712
+ throw new ValidationError("expires_at must be a date string, Unix time or null");
1713
+ if (payload.copy_receiver_ids !== void 0 && (!Array.isArray(payload.copy_receiver_ids) || payload.copy_receiver_ids.some((id) => typeof id !== "string" || !id.trim())))
1714
+ throw new ValidationError("copy_receiver_ids must contain nonblank IDs");
1715
+ }
1716
+ function validateCreate(payload) {
1717
+ if (!payload) throw new ValidationError("Envelope payload is required");
1718
+ validateName(payload.name);
1719
+ validateMessage(payload.message);
1720
+ validateCreditCeiling(payload.max_total_credits);
1721
+ if (!Array.isArray(payload.signers) || !payload.signers.length || payload.signers.length > 20 || payload.signers.some((s) => !s || typeof s !== "object"))
1722
+ throw new ValidationError("signers must contain 1\u201320 signers");
1723
+ validateIds(
1724
+ payload.signers.map((s) => s.id),
1725
+ "signers"
1726
+ );
1727
+ for (const signer of payload.signers) {
1728
+ if ("step" in signer) throw new ValidationError("Envelope signers do not accept step");
1729
+ validateSignerOptions(signer);
1730
+ }
1731
+ if (!Array.isArray(payload.documents) || !payload.documents.length || payload.documents.length > 20)
1732
+ throw new ValidationError("documents must contain 1\u201320 documents");
1733
+ for (const document of payload.documents) {
1734
+ validateDocument(document);
1735
+ const signers = document.signer_ids.map((id) => payload.signers.find((s) => s.id === id));
1736
+ if (signers.some((s) => !s))
1737
+ throw new ValidationError("Every document signer must be listed in signers");
1738
+ const assigned = signers.filter((s) => s !== void 0);
1739
+ validateDigitalCertificateMethod(document.method ?? "virtual", assigned);
1740
+ if (assigned.length > 1 && assigned.some((s) => s.verification_method === "DigitalCertificate"))
1741
+ throw new ValidationError(
1742
+ "A DigitalCertificate signer must be alone on each envelope document"
1743
+ );
1744
+ }
1745
+ validateIds(
1746
+ payload.documents.map((d) => d.id),
1747
+ "documents"
1748
+ );
1749
+ if (payload.signers.some((s) => !payload.documents.some((d) => d.signer_ids.includes(s.id))))
1750
+ throw new ValidationError("Every signer must belong to at least one document");
1751
+ }
1752
+
1425
1753
  // src/api/resources/fields.ts
1426
1754
  var FieldsResource = class extends BaseResource {
1427
1755
  /** Create a field definition. */
@@ -1739,12 +2067,12 @@ function httpsUrl(value, name) {
1739
2067
  // src/api/resources/signer-documents.ts
1740
2068
  var SignerDocumentsResource = class extends BaseResource {
1741
2069
  /** `GET /signers/{signer_id}/document?signer-access-code=…` */
1742
- async getCurrent(signerId, signerAccessCode) {
2070
+ async getCurrent(signerId, signerAccessCode, params = {}) {
1743
2071
  const sid = this.requireId(signerId, "Signer ID");
1744
2072
  const code = this.requireId(signerAccessCode, "signer-access-code");
1745
2073
  return this.call(
1746
2074
  "Failed to fetch current signer document",
1747
- () => this.http.get(`/signers/${sid}/document`, signerAccessConfig(code))
2075
+ () => this.http.get(`/signers/${sid}/document`, signerAccessConfig(code, params))
1748
2076
  );
1749
2077
  }
1750
2078
  /** `GET /signers/{signer_id}/documents?signer-access-code=…` */
@@ -1761,17 +2089,17 @@ var SignerDocumentsResource = class extends BaseResource {
1761
2089
  return this.listDocuments(signerId, { params: cleanParams({ ...params }) });
1762
2090
  }
1763
2091
  /** `GET /signers/{signer_id}/documents/search?search=…&signer-access-code=…` */
1764
- async search(signerId, search, signerAccessCode) {
2092
+ async search(signerId, search, signerAccessCode, params = {}) {
1765
2093
  const code = this.requireId(signerAccessCode, "signer-access-code");
1766
- return this.searchDocuments(signerId, signerAccessConfig(code, { search }));
2094
+ return this.searchDocuments(signerId, signerAccessConfig(code, { ...params, search }));
1767
2095
  }
1768
2096
  /**
1769
2097
  * `GET /signers/{signer_id}/documents/search?search=…` with the client's owner
1770
2098
  * credentials instead of a signer access code. The signer must belong to that
1771
2099
  * workspace.
1772
2100
  */
1773
- async searchAsOwner(signerId, search) {
1774
- return this.searchDocuments(signerId, { params: cleanParams({ search }) });
2101
+ async searchAsOwner(signerId, search, params = {}) {
2102
+ return this.searchDocuments(signerId, { params: cleanParams({ ...params, search }) });
1775
2103
  }
1776
2104
  listDocuments(signerId, config) {
1777
2105
  const sid = this.requireId(signerId, "Signer ID");
@@ -1788,9 +2116,9 @@ var SignerDocumentsResource = class extends BaseResource {
1788
2116
  );
1789
2117
  }
1790
2118
  /**
1791
- * Public `GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`.
1792
- * When an access code is supplied, the SDK first verifies that it belongs to
1793
- * the requested signer for callers that want that additional check.
2119
+ * `GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`.
2120
+ * The current API permits only originals with a signer code. Other forms are
2121
+ * retained for compatibility; use downloadCertifiedCopy for completed PDFs.
1794
2122
  */
1795
2123
  async download(signerId, documentId, artifactName, signerAccessCode) {
1796
2124
  const sid = this.requireId(signerId, "Signer ID");
@@ -1904,13 +2232,16 @@ var SignerDocumentsResource = class extends BaseResource {
1904
2232
  * Returns `{ token }` for the signer's Web PKI client. This production route
1905
2233
  * is used by Assinafy's signing frontend but is absent from OpenAPI paths.
1906
2234
  */
1907
- async startCertificate(signerAccessCode) {
2235
+ async startCertificate(signerAccessCode, documentId) {
1908
2236
  const code = this.requireId(signerAccessCode, "signer-access-code");
1909
2237
  return this.call(
1910
2238
  "Failed to start certificate signature",
1911
2239
  () => this.http.post(
1912
2240
  "/signers/certificate/start",
1913
- { "signer-access-code": code },
2241
+ {
2242
+ "signer-access-code": code,
2243
+ ...documentId === void 0 ? {} : { document_id: this.requireId(documentId, "Document ID") }
2244
+ },
1914
2245
  signerAccessConfig(code)
1915
2246
  )
1916
2247
  );
@@ -1921,7 +2252,7 @@ var SignerDocumentsResource = class extends BaseResource {
1921
2252
  * successfully signs it. Returns `{ signerName }`; private keys stay local.
1922
2253
  * This production route is absent from OpenAPI paths.
1923
2254
  */
1924
- async completeCertificate(signerAccessCode, token) {
2255
+ async completeCertificate(signerAccessCode, token, documentId) {
1925
2256
  const code = this.requireId(signerAccessCode, "signer-access-code");
1926
2257
  if (typeof token !== "string" || !token.trim()) {
1927
2258
  throw new ValidationError("Certificate token is required");
@@ -1930,7 +2261,11 @@ var SignerDocumentsResource = class extends BaseResource {
1930
2261
  "Failed to complete certificate signature",
1931
2262
  () => this.http.post(
1932
2263
  "/signers/certificate/complete",
1933
- { "signer-access-code": code, token },
2264
+ {
2265
+ "signer-access-code": code,
2266
+ token,
2267
+ ...documentId === void 0 ? {} : { document_id: this.requireId(documentId, "Document ID") }
2268
+ },
1934
2269
  signerAccessConfig(code)
1935
2270
  )
1936
2271
  );
@@ -1995,11 +2330,15 @@ var SignerDocumentsResource = class extends BaseResource {
1995
2330
  );
1996
2331
  }
1997
2332
  /** `GET /sign?signer-access-code=…` — fetch the assignment as the signer sees it. */
1998
- async getAssignment(signerAccessCode, hasAcceptedTerms) {
2333
+ async getAssignment(signerAccessCode, hasAcceptedTerms, params = {}) {
1999
2334
  const code = this.requireId(signerAccessCode, "signer-access-code");
2335
+ if (params.document_id !== void 0) this.requireId(params.document_id, "Document ID");
2000
2336
  return this.call(
2001
2337
  "Failed to fetch signer assignment",
2002
- () => this.http.get("/sign", signerAccessConfig(code, { has_accepted_terms: hasAcceptedTerms }))
2338
+ () => this.http.get(
2339
+ "/sign",
2340
+ signerAccessConfig(code, { ...params, has_accepted_terms: hasAcceptedTerms })
2341
+ )
2003
2342
  );
2004
2343
  }
2005
2344
  /**
@@ -2042,12 +2381,59 @@ var SignerDocumentsResource = class extends BaseResource {
2042
2381
  );
2043
2382
  }
2044
2383
  async requireDocumentAccess(documentId, signerAccessCode, assignmentId) {
2045
- const document = await this.getAssignment(signerAccessCode);
2384
+ const document = assignmentId === void 0 ? await this.call(
2385
+ "Failed to fetch signer document",
2386
+ () => this.http.get(`/documents/${documentId}`, signerAccessConfig(signerAccessCode))
2387
+ ) : await this.getAssignment(signerAccessCode, void 0, { document_id: documentId });
2046
2388
  if (document.id !== documentId || assignmentId !== void 0 && document.assignment?.id !== assignmentId) {
2047
2389
  throw new ValidationError("Signer access code does not match the document or assignment");
2048
2390
  }
2049
2391
  return document;
2050
2392
  }
2393
+ async getTheme(signerAccessCode) {
2394
+ const code = this.requireId(signerAccessCode, "signer-access-code");
2395
+ return this.call(
2396
+ "Failed to fetch signing theme",
2397
+ () => this.http.get("/sign/theme", signerAccessConfig(code))
2398
+ );
2399
+ }
2400
+ async downloadLogo(signerAccessCode) {
2401
+ const code = this.requireId(signerAccessCode, "signer-access-code");
2402
+ return this.callBinary(
2403
+ "Failed to download signing logo",
2404
+ () => this.http.get("/sign/logo", {
2405
+ ...signerAccessConfig(code),
2406
+ responseType: "arraybuffer"
2407
+ })
2408
+ );
2409
+ }
2410
+ /** Sends a time-limited download link to the original signing contact. */
2411
+ async resendCertifiedCopy(signerAccessCode, documentId) {
2412
+ const code = this.requireId(signerAccessCode, "signer-access-code");
2413
+ const body = documentId === void 0 ? void 0 : { document_id: this.requireId(documentId, "Document ID") };
2414
+ return this.call(
2415
+ "Failed to send certified copy",
2416
+ () => this.http.post("/sign/certified-copy", body, signerAccessConfig(code))
2417
+ );
2418
+ }
2419
+ /** Expired tokens return an ApiError (302); redirects remain disabled. */
2420
+ async downloadCertifiedCopy(token, artifact = "certificated") {
2421
+ const value = this.requireId(token, "Download token");
2422
+ if (!["certificated", "pades"].includes(artifact))
2423
+ throw new ValidationError("artifact must be certificated or pades");
2424
+ const config = { ...publicRequestConfig(), responseType: "arraybuffer" };
2425
+ return this.callBinary(
2426
+ "Failed to download certified copy",
2427
+ () => artifact === "pades" ? this.http.get(`/signers/downloads/${value}/pades`, config) : this.http.get(`/signers/downloads/${value}`, config)
2428
+ );
2429
+ }
2430
+ async resendDownloadLink(token) {
2431
+ const value = this.requireId(token, "Download token");
2432
+ return this.call(
2433
+ "Failed to resend download link",
2434
+ () => this.http.post(`/signers/downloads/${value}/resend`, void 0, publicRequestConfig())
2435
+ );
2436
+ }
2051
2437
  };
2052
2438
  function validateDeclineReason(value) {
2053
2439
  if (typeof value !== "string" || !value.trim()) {
@@ -2120,14 +2506,14 @@ var SignerResource = class extends BaseResource {
2120
2506
  })
2121
2507
  );
2122
2508
  }
2123
- /** Update a signer. Fails if the signer has active assignments. */
2509
+ /** Update supplied fields; verified channels on in-flight documents cannot change. */
2124
2510
  async update(signerId, payload, accountId) {
2125
2511
  const id = this.accountId(accountId);
2126
2512
  const sid = this.requireId(signerId, "Signer ID");
2127
2513
  if (payload.full_name !== void 0 && !payload.full_name.trim()) {
2128
2514
  throw new ValidationError("Signer full name cannot be blank");
2129
2515
  }
2130
- if (payload.email !== void 0) requireEmail(payload.email);
2516
+ if (payload.email != null && payload.email !== "") requireEmail(payload.email);
2131
2517
  return this.call(
2132
2518
  "Failed to update signer",
2133
2519
  () => this.http.put(`/accounts/${id}/signers/${sid}`, normaliseSignerPayload(payload, true))
@@ -2148,13 +2534,13 @@ var SignerResource = class extends BaseResource {
2148
2534
  try {
2149
2535
  const lower = email.toLowerCase();
2150
2536
  for (let page = 1; page <= MAX_SEARCH_PAGES; page++) {
2151
- const { data, meta } = await this.list({ search: email, per_page: 100, page }, accountId);
2537
+ const { data, meta } = await this.list({ search: email, per_page: 50, page }, accountId);
2152
2538
  const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
2153
2539
  if (match) return match;
2154
2540
  if (!data.length) return null;
2155
2541
  if (meta?.last_page !== void 0) {
2156
2542
  if (page >= meta.last_page) return null;
2157
- } else if (data.length < 100) {
2543
+ } else if (data.length < 50) {
2158
2544
  return null;
2159
2545
  }
2160
2546
  }
@@ -2172,7 +2558,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
2172
2558
  const normalised = {
2173
2559
  full_name: payload.full_name,
2174
2560
  email: payload.email,
2175
- whatsapp_phone_number: payload.whatsapp_phone_number ?? payload.phone
2561
+ whatsapp_phone_number: payload.whatsapp_phone_number !== void 0 ? payload.whatsapp_phone_number : payload.phone
2176
2562
  };
2177
2563
  if (payload.government_id !== void 0) {
2178
2564
  normalised.government_id = payload.government_id;
@@ -2183,7 +2569,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
2183
2569
  if ("metadata" in payload && payload.metadata !== void 0) {
2184
2570
  normalised.metadata = payload.metadata;
2185
2571
  }
2186
- return stripEmpty(normalised);
2572
+ return useGovernmentId ? Object.fromEntries(Object.entries(normalised).filter(([, value]) => value !== void 0)) : stripEmpty(normalised);
2187
2573
  }
2188
2574
 
2189
2575
  // src/api/resources/tags.ts
@@ -2285,6 +2671,16 @@ var TemplateResource = class extends BaseResource {
2285
2671
  };
2286
2672
 
2287
2673
  // src/api/types.ts
2674
+ var PUSH_PREFERENCE_CODES = [
2675
+ "SignerViewed",
2676
+ "SignerSigned",
2677
+ "DocumentCompleted",
2678
+ "SignerDeclined",
2679
+ "DocumentAboutToExpire",
2680
+ "DocumentExpired",
2681
+ "SignerIdentityReviewRequired",
2682
+ "SignerWhatsappFailed"
2683
+ ];
2288
2684
  var NOTIFICATION_PREFERENCE_CODES = [
2289
2685
  "DocumentCompleted",
2290
2686
  "SignerDeclined",
@@ -2302,7 +2698,6 @@ var NOTIFICATION_PREFERENCE_CODES = [
2302
2698
  ];
2303
2699
 
2304
2700
  // src/api/resources/users.ts
2305
- var NOTIFICATION_PREFERENCES = new Set(NOTIFICATION_PREFERENCE_CODES);
2306
2701
  var UsersResource = class extends BaseResource {
2307
2702
  /** Fetch the authenticated user's profile. */
2308
2703
  async self() {
@@ -2324,26 +2719,25 @@ var UsersResource = class extends BaseResource {
2324
2719
  }
2325
2720
  /** Merge one or more owner-facing email notification preferences. */
2326
2721
  async updateNotificationPreferences(payload) {
2327
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
2328
- throw new ValidationError("Notification preferences must be an object");
2329
- }
2330
- const entries = Object.entries(payload);
2331
- if (entries.length === 0) {
2332
- throw new ValidationError("At least one notification preference is required");
2333
- }
2334
- for (const [key, value] of entries) {
2335
- if (!NOTIFICATION_PREFERENCES.has(key)) {
2336
- throw new ValidationError(`Unknown notification preference: ${key}`);
2337
- }
2338
- if (typeof value !== "boolean") {
2339
- throw new ValidationError(`${key} must be a boolean`);
2340
- }
2341
- }
2722
+ validateBooleanMap(payload, NOTIFICATION_PREFERENCE_CODES);
2342
2723
  return this.call(
2343
2724
  "Failed to update notification preferences",
2344
2725
  () => this.http.put("/users/self/notification-preferences", payload)
2345
2726
  );
2346
2727
  }
2728
+ async getPushPreferences() {
2729
+ return this.call(
2730
+ "Failed to fetch push preferences",
2731
+ () => this.http.get("/users/self/push-preferences")
2732
+ );
2733
+ }
2734
+ async updatePushPreferences(payload) {
2735
+ validateBooleanMap(payload, PUSH_PREFERENCE_CODES);
2736
+ return this.call(
2737
+ "Failed to update push preferences",
2738
+ () => this.http.put("/users/self/push-preferences", payload)
2739
+ );
2740
+ }
2347
2741
  };
2348
2742
 
2349
2743
  // src/api/resources/webhooks.ts
@@ -2354,7 +2748,7 @@ var DEFAULT_EVENTS = [
2354
2748
  "signer_rejected_document",
2355
2749
  "document_processing_failed"
2356
2750
  ];
2357
- function validateWebhookFields(payload) {
2751
+ function validateWebhookFields(payload, requireHttps = false) {
2358
2752
  if (payload.url !== void 0) {
2359
2753
  let webhookUrl;
2360
2754
  try {
@@ -2365,6 +2759,9 @@ function validateWebhookFields(payload) {
2365
2759
  if (webhookUrl.protocol !== "http:" && webhookUrl.protocol !== "https:") {
2366
2760
  throw new ValidationError("Webhook URL must be a valid HTTP(S) URL");
2367
2761
  }
2762
+ if (requireHttps && webhookUrl.protocol !== "https:") {
2763
+ throw new ValidationError("Webhook URL must use HTTPS");
2764
+ }
2368
2765
  }
2369
2766
  if (payload.email !== void 0) requireEmail(payload.email);
2370
2767
  if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event))) {
@@ -2380,6 +2777,15 @@ function validateWebhookFields(payload) {
2380
2777
  }
2381
2778
  }
2382
2779
  var WebhookResource = class extends BaseResource {
2780
+ /** Sends a webhook_test even to an inactive/held endpoint; does not change its state. */
2781
+ async testEndpoint(endpointId, accountId) {
2782
+ const id = this.accountId(accountId);
2783
+ const eid = this.requireId(endpointId, "Endpoint ID");
2784
+ return this.call(
2785
+ "Failed to send webhook test",
2786
+ () => this.http.post(`/accounts/${id}/webhooks/endpoints/${eid}/test`)
2787
+ );
2788
+ }
2383
2789
  /**
2384
2790
  * `PUT /accounts/{accountId}/webhooks/subscriptions` — create or replace the
2385
2791
  * account's oldest webhook endpoint. Use the endpoint methods for accounts
@@ -2387,7 +2793,7 @@ var WebhookResource = class extends BaseResource {
2387
2793
  */
2388
2794
  async register(payload, accountId) {
2389
2795
  if (!payload.url) throw new ValidationError("Webhook URL is required");
2390
- validateWebhookFields({ ...payload, email: payload.email ?? "" });
2796
+ validateWebhookFields({ ...payload, email: payload.email ?? "" }, true);
2391
2797
  const id = this.accountId(accountId);
2392
2798
  const body = {
2393
2799
  url: payload.url,
@@ -2438,7 +2844,7 @@ var WebhookResource = class extends BaseResource {
2438
2844
  */
2439
2845
  async createEndpoint(payload, accountId) {
2440
2846
  if (!payload.url) throw new ValidationError("Webhook URL is required");
2441
- validateWebhookFields({ ...payload, email: payload.email ?? "" });
2847
+ validateWebhookFields({ ...payload, email: payload.email ?? "" }, true);
2442
2848
  const id = this.accountId(accountId);
2443
2849
  const body = { ...payload, events: payload.events ?? DEFAULT_EVENTS };
2444
2850
  this.logger.info("Creating webhook endpoint", { eventCount: body.events.length });
@@ -2468,7 +2874,7 @@ var WebhookResource = class extends BaseResource {
2468
2874
  if (!payload || typeof payload !== "object" || Object.keys(payload).length === 0) {
2469
2875
  throw new ValidationError("At least one webhook endpoint field is required");
2470
2876
  }
2471
- validateWebhookFields(payload);
2877
+ validateWebhookFields(payload, true);
2472
2878
  return this.call(
2473
2879
  "Failed to update webhook endpoint",
2474
2880
  () => this.http.put(`/accounts/${id}/webhooks/endpoints/${eid}`, payload)
@@ -2507,15 +2913,21 @@ var WebhookResource = class extends BaseResource {
2507
2913
  }
2508
2914
  /**
2509
2915
  * `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
2510
- * The old secret stops working immediately. Requires `webhooks:write` for OAuth.
2916
+ * Set keep_previous to retain the replaced secret for 24 hours. Requires webhooks:write.
2511
2917
  */
2512
- async rotateEndpointSecret(endpointId, accountId) {
2918
+ async rotateEndpointSecret(endpointId, accountId, options = {}) {
2513
2919
  const id = this.accountId(accountId);
2514
2920
  const eid = this.requireId(endpointId, "Endpoint ID");
2921
+ if (options.keep_previous !== void 0 && typeof options.keep_previous !== "boolean") {
2922
+ throw new ValidationError("keep_previous must be a boolean");
2923
+ }
2515
2924
  this.logger.info("Rotating webhook endpoint secret");
2516
2925
  return this.call(
2517
2926
  "Failed to rotate webhook endpoint secret",
2518
- () => this.http.post(`/accounts/${id}/webhooks/endpoints/${eid}/secret/rotate`)
2927
+ () => this.http.post(
2928
+ `/accounts/${id}/webhooks/endpoints/${eid}/secret/rotate`,
2929
+ options.keep_previous === void 0 ? void 0 : { keep_previous: options.keep_previous }
2930
+ )
2519
2931
  );
2520
2932
  }
2521
2933
  /** List currently supported webhook event types. */
@@ -2566,9 +2978,46 @@ var WorkspaceResource = class extends BaseResource {
2566
2978
  );
2567
2979
  }
2568
2980
  /** Fetch a single workspace. */
2569
- async get(accountId) {
2981
+ async get(accountId, params = {}) {
2982
+ const id = this.requireId(accountId, "Account ID");
2983
+ return this.call(
2984
+ "Failed to fetch workspace",
2985
+ () => this.http.get(`/accounts/${id}`, { params })
2986
+ );
2987
+ }
2988
+ /** Plan allowance and balances; unavailable to third-party OAuth applications. */
2989
+ async usage(accountId) {
2990
+ const id = this.requireId(accountId, "Account ID");
2991
+ return this.call(
2992
+ "Failed to fetch workspace usage",
2993
+ () => this.http.get(`/accounts/${id}/usage`)
2994
+ );
2995
+ }
2996
+ async getNotificationPolicy(accountId) {
2997
+ const id = this.requireId(accountId, "Account ID");
2998
+ return this.call(
2999
+ "Failed to fetch notification policy",
3000
+ () => this.http.get(`/accounts/${id}/notification-policy`)
3001
+ );
3002
+ }
3003
+ /** Owner-only partial merge; false disables the alert workspace-wide. */
3004
+ async updateNotificationPolicy(accountId, payload) {
2570
3005
  const id = this.requireId(accountId, "Account ID");
2571
- return this.call("Failed to fetch workspace", () => this.http.get(`/accounts/${id}`));
3006
+ if (!payload || typeof payload !== "object" || Array.isArray(payload) || !Object.keys(payload).length || Object.keys(payload).some((key) => !["events", "owners_receive_all"].includes(key)))
3007
+ throw new ValidationError("Provide events and/or owners_receive_all");
3008
+ if (payload.owners_receive_all !== void 0 && typeof payload.owners_receive_all !== "boolean")
3009
+ throw new ValidationError("owners_receive_all must be a boolean");
3010
+ if (payload.events !== void 0)
3011
+ validateBooleanMap(payload.events, [
3012
+ ...NOTIFICATION_PREFERENCE_CODES,
3013
+ ...PUSH_PREFERENCE_CODES
3014
+ ]);
3015
+ if (payload.events === void 0 && payload.owners_receive_all === void 0)
3016
+ throw new ValidationError("At least one notification policy field is required");
3017
+ return this.call(
3018
+ "Failed to update notification policy",
3019
+ () => this.http.put(`/accounts/${id}/notification-policy`, payload)
3020
+ );
2572
3021
  }
2573
3022
  /** Fetch the workspace's public branding theme. */
2574
3023
  async getTheme(accountId) {
@@ -2769,6 +3218,8 @@ var AssinafyClient = class _AssinafyClient {
2769
3218
  auth;
2770
3219
  oauth;
2771
3220
  fields;
3221
+ envelopes;
3222
+ embed;
2772
3223
  users;
2773
3224
  signerDocuments;
2774
3225
  webhookVerifier;
@@ -2840,6 +3291,8 @@ var AssinafyClient = class _AssinafyClient {
2840
3291
  this.auth = new AuthenticationResource(this.axiosInstance, void 0, this.logger);
2841
3292
  this.oauth = new OAuthResource(this.axiosInstance, void 0, this.logger);
2842
3293
  this.fields = new FieldsResource(this.axiosInstance, this.defaultAccountId, this.logger);
3294
+ this.envelopes = new EnvelopeResource(this.axiosInstance, this.defaultAccountId, this.logger);
3295
+ this.embed = new EmbedResource(this.axiosInstance, this.defaultAccountId, this.logger);
2843
3296
  this.users = new UsersResource(this.axiosInstance, void 0, this.logger);
2844
3297
  this.signerDocuments = new SignerDocumentsResource(
2845
3298
  this.axiosInstance,
@@ -2885,6 +3338,7 @@ var AssinafyClient = class _AssinafyClient {
2885
3338
  throw new ValidationError("At least one signer is required");
2886
3339
  }
2887
3340
  if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
3341
+ validateCreditCeiling(options.maxTotalCredits);
2888
3342
  const preparedSigners = options.signers.map((signer) => {
2889
3343
  if (!signer || typeof signer !== "object") {
2890
3344
  throw new ValidationError("Each signer must be an object");
@@ -2901,7 +3355,8 @@ var AssinafyClient = class _AssinafyClient {
2901
3355
  const reference = {
2902
3356
  verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
2903
3357
  notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
2904
- step: signer.step
3358
+ step: signer.step,
3359
+ embedded: signer.embedded
2905
3360
  };
2906
3361
  validateSignerOptions(reference);
2907
3362
  return { reference, payload };
@@ -2930,7 +3385,8 @@ var AssinafyClient = class _AssinafyClient {
2930
3385
  }
2931
3386
  const assignmentPayload = {
2932
3387
  method: "virtual",
2933
- signers: assignmentSigners
3388
+ signers: assignmentSigners,
3389
+ max_total_credits: options.maxTotalCredits
2934
3390
  };
2935
3391
  if (options.message !== void 0) assignmentPayload.message = options.message;
2936
3392
  if (options.expiresAt !== void 0) assignmentPayload.expires_at = options.expiresAt;
@@ -2966,10 +3422,13 @@ var AssinafyClient = class _AssinafyClient {
2966
3422
  AuthenticationResource,
2967
3423
  ContractResource,
2968
3424
  DocumentResource,
3425
+ EmbedResource,
3426
+ EnvelopeResource,
2969
3427
  FieldsResource,
2970
3428
  NOTIFICATION_PREFERENCE_CODES,
2971
3429
  NetworkError,
2972
3430
  OAuthResource,
3431
+ PUSH_PREFERENCE_CODES,
2973
3432
  PartialWorkflowError,
2974
3433
  SignerDocumentsResource,
2975
3434
  SignerResource,