@assinafy/cli 2.7.1 → 2.9.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.
Files changed (61) hide show
  1. package/.env.example +2 -0
  2. package/README.en.md +75 -67
  3. package/README.md +39 -25
  4. package/THIRD_PARTY_NOTICES.md +8 -8
  5. package/dist/api.cjs +701 -93
  6. package/dist/api.cjs.map +1 -1
  7. package/dist/api.js +696 -93
  8. package/dist/api.js.map +1 -1
  9. package/dist/cli.cjs +2390 -694
  10. package/dist/types/api/client.d.ts +7 -0
  11. package/dist/types/api/client.d.ts.map +1 -1
  12. package/dist/types/api/envelope-types.d.ts +73 -0
  13. package/dist/types/api/envelope-types.d.ts.map +1 -0
  14. package/dist/types/api/index.d.ts +4 -0
  15. package/dist/types/api/index.d.ts.map +1 -1
  16. package/dist/types/api/resources/assignments.d.ts +7 -1
  17. package/dist/types/api/resources/assignments.d.ts.map +1 -1
  18. package/dist/types/api/resources/contracts.d.ts +3 -1
  19. package/dist/types/api/resources/contracts.d.ts.map +1 -1
  20. package/dist/types/api/resources/documents.d.ts +25 -6
  21. package/dist/types/api/resources/documents.d.ts.map +1 -1
  22. package/dist/types/api/resources/embed.d.ts +14 -0
  23. package/dist/types/api/resources/embed.d.ts.map +1 -0
  24. package/dist/types/api/resources/envelopes.d.ts +37 -0
  25. package/dist/types/api/resources/envelopes.d.ts.map +1 -0
  26. package/dist/types/api/resources/scheduled-sends.d.ts +11 -0
  27. package/dist/types/api/resources/scheduled-sends.d.ts.map +1 -0
  28. package/dist/types/api/resources/signer-documents.d.ts +23 -11
  29. package/dist/types/api/resources/signer-documents.d.ts.map +1 -1
  30. package/dist/types/api/resources/signers.d.ts +1 -1
  31. package/dist/types/api/resources/signers.d.ts.map +1 -1
  32. package/dist/types/api/resources/users.d.ts +3 -1
  33. package/dist/types/api/resources/users.d.ts.map +1 -1
  34. package/dist/types/api/resources/webhooks.d.ts +6 -2
  35. package/dist/types/api/resources/webhooks.d.ts.map +1 -1
  36. package/dist/types/api/resources/workspaces.d.ts +9 -2
  37. package/dist/types/api/resources/workspaces.d.ts.map +1 -1
  38. package/dist/types/api/types.d.ts +138 -8
  39. package/dist/types/api/types.d.ts.map +1 -1
  40. package/dist/types/api/utils.d.ts +9 -0
  41. package/dist/types/api/utils.d.ts.map +1 -1
  42. package/docs/README.md +5 -1
  43. package/docs/api-operations-staging.json +1262 -0
  44. package/docs/api-operations.json +234 -2
  45. package/docs/api-reference-staging.md +18466 -0
  46. package/docs/api-reference.md +11562 -3718
  47. package/docs/assignments.md +62 -14
  48. package/docs/contracts.md +4 -3
  49. package/docs/documents.md +75 -27
  50. package/docs/embed.md +119 -0
  51. package/docs/envelopes.md +239 -0
  52. package/docs/scheduled-sends.md +63 -0
  53. package/docs/sdk-reference.md +278 -30
  54. package/docs/send.md +15 -11
  55. package/docs/signer.md +84 -3
  56. package/docs/users.md +41 -0
  57. package/docs/webhooks.md +22 -6
  58. package/docs/workspaces.md +66 -3
  59. package/install.ps1 +1 -1
  60. package/install.sh +1 -1
  61. package/package.json +4 -4
package/dist/api.cjs CHANGED
@@ -37,11 +37,16 @@ __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,
48
+ SIGNER_CAPACITIES: () => SIGNER_CAPACITIES,
49
+ ScheduledSendResource: () => ScheduledSendResource,
45
50
  SignerDocumentsResource: () => SignerDocumentsResource,
46
51
  SignerResource: () => SignerResource,
47
52
  TagResource: () => TagResource,
@@ -146,7 +151,62 @@ var PartialWorkflowError = class extends AssinafyError {
146
151
  };
147
152
 
148
153
  // src/api/utils.ts
154
+ var import_node_http = require("http");
149
155
  var import_axios = __toESM(require("axios"), 1);
156
+
157
+ // src/api/types.ts
158
+ var SIGNER_CAPACITIES = [
159
+ "Sign",
160
+ "Approve",
161
+ "Acknowledge",
162
+ "Party",
163
+ "Witness",
164
+ "Intervening",
165
+ "Receipt",
166
+ "IssuerEndorserGuarantor",
167
+ "IssuerEndorserGuarantorSurety",
168
+ "Surety",
169
+ "PartySurety",
170
+ "JointDebtor",
171
+ "PartyJointDebtor",
172
+ "ContractingParty",
173
+ "ContractedParty",
174
+ "Landlord",
175
+ "Tenant",
176
+ "Buyer",
177
+ "Seller",
178
+ "AttorneyInFact",
179
+ "LegalRepresentative",
180
+ "Employer",
181
+ "Employee"
182
+ ];
183
+ var PUSH_PREFERENCE_CODES = [
184
+ "SignerViewed",
185
+ "SignerSigned",
186
+ "DocumentCompleted",
187
+ "SignerDeclined",
188
+ "DocumentAboutToExpire",
189
+ "DocumentExpired",
190
+ "SignerIdentityReviewRequired",
191
+ "SignerWhatsappFailed"
192
+ ];
193
+ var NOTIFICATION_PREFERENCE_CODES = [
194
+ "DocumentCompleted",
195
+ "SignerDeclined",
196
+ "DocumentCancelled",
197
+ "DocumentAboutToExpire",
198
+ "DocumentExpired",
199
+ "DocumentExpirationReset",
200
+ "DocumentProcessingFailed",
201
+ "TemplateProcessingFailed",
202
+ "SignerWhatsappFailed",
203
+ "ContractRenewalNotice",
204
+ "ContractExpiring",
205
+ "ContractExpired",
206
+ "ContractRenewed"
207
+ ];
208
+
209
+ // src/api/utils.ts
150
210
  var DOCUMENT_ARTIFACT_NAMES = [
151
211
  "original",
152
212
  "certificated",
@@ -257,6 +317,16 @@ function requireExpiration(value, name = "expires_at") {
257
317
  requireIso8601(timestamp, name);
258
318
  return value;
259
319
  }
320
+ function requireScheduledTime(value, name = "send_at") {
321
+ if (typeof value === "number") {
322
+ if (!Number.isSafeInteger(value))
323
+ throw new ValidationError(`${name} must be an integer Unix time`);
324
+ } else if (typeof value === "string") {
325
+ requireExpiration(value, name);
326
+ } else {
327
+ throw new ValidationError(`${name} must be an ISO 8601 time or integer Unix time`);
328
+ }
329
+ }
260
330
  function requireEmail(value) {
261
331
  if (!value || !EMAIL_RE.test(value)) {
262
332
  throw new ValidationError("Invalid email address", { email: value });
@@ -264,6 +334,15 @@ function requireEmail(value) {
264
334
  return value;
265
335
  }
266
336
  function validateSignerOptions(input) {
337
+ if (input.sign_as != null && !SIGNER_CAPACITIES.includes(input.sign_as)) {
338
+ throw new ValidationError("sign_as must be a published signer capacity or null");
339
+ }
340
+ if (input.embedded !== void 0 && typeof input.embedded !== "boolean") {
341
+ throw new ValidationError("embedded must be a boolean");
342
+ }
343
+ if (input.embedded === true && input.verification_method !== void 0 && !["Email", "Whatsapp"].includes(input.verification_method)) {
344
+ throw new ValidationError("Embedded signing requires Email or Whatsapp verification");
345
+ }
267
346
  if (input.verification_method !== void 0 && !VERIFICATION_METHODS.includes(input.verification_method)) {
268
347
  throw new ValidationError(
269
348
  `verification_method must be one of: ${VERIFICATION_METHODS.join(", ")}`
@@ -290,6 +369,33 @@ function validateSignerOptions(input) {
290
369
  throw new ValidationError("step must be an integer");
291
370
  }
292
371
  }
372
+ function validateCreditCeiling(value) {
373
+ if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value) || value < 0)) {
374
+ throw new ValidationError("max_total_credits must be a finite non-negative number");
375
+ }
376
+ }
377
+ function idempotencyHeaders(key) {
378
+ if (key === void 0) return void 0;
379
+ if (typeof key !== "string" || !key.trim()) {
380
+ throw new ValidationError("idempotencyKey must be nonblank text");
381
+ }
382
+ try {
383
+ (0, import_node_http.validateHeaderValue)("Idempotency-Key", key);
384
+ } catch {
385
+ throw new ValidationError("idempotencyKey must be a valid HTTP header value");
386
+ }
387
+ return { "Idempotency-Key": key };
388
+ }
389
+ function validateBooleanMap(payload, allowed) {
390
+ if (!payload || typeof payload !== "object" || Array.isArray(payload) || !Object.keys(payload).length) {
391
+ throw new ValidationError("At least one notification preference is required");
392
+ }
393
+ for (const [key, value] of Object.entries(payload)) {
394
+ if (!allowed.includes(key))
395
+ throw new ValidationError(`Unknown notification preference: ${key}`);
396
+ if (typeof value !== "boolean") throw new ValidationError(`${key} must be a boolean`);
397
+ }
398
+ }
293
399
  function validateDigitalCertificateMethod(method, signers) {
294
400
  if (method !== "virtual" && signers.some((signer) => signer.verification_method === "DigitalCertificate")) {
295
401
  throw new ValidationError("DigitalCertificate signers require method: virtual", {
@@ -429,7 +535,7 @@ var BaseResource = class {
429
535
  }
430
536
  };
431
537
  function safeIdentifier(value, name) {
432
- if (value === "." || value === ".." || /[\s/?#\\%]/.test(value)) {
538
+ if (typeof value !== "string" || value === "." || value === ".." || /[\s/?#\\%]/.test(value)) {
433
539
  throw new ValidationError(`${name} contains invalid URL characters`);
434
540
  }
435
541
  return value;
@@ -464,10 +570,15 @@ function toInt(value) {
464
570
 
465
571
  // src/api/resources/assignments.ts
466
572
  function buildAssignmentPayload(payload, options = {}) {
573
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
574
+ throw new ValidationError("Assignment payload must be an object");
575
+ }
467
576
  if (payload.method !== void 0 && payload.method !== "virtual" && payload.method !== "collect") {
468
577
  throw new ValidationError("method must be virtual or collect");
469
578
  }
470
579
  const signers = extractSignerRefs(payload);
580
+ validateCreditCeiling(payload.max_total_credits);
581
+ if (payload.expires_at != null) requireScheduledTime(payload.expires_at, "expires_at");
471
582
  if (signers.length === 0) {
472
583
  throw new ValidationError("At least one signer is required", {
473
584
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
@@ -482,14 +593,17 @@ function buildAssignmentPayload(payload, options = {}) {
482
593
  if (!options.skipDigitalCertificateStepValidation) {
483
594
  validateSigningSteps(normalisedSigners);
484
595
  }
485
- return stripEmpty({
486
- method,
487
- signers: normalisedSigners,
488
- message: payload.message,
489
- expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
490
- copy_receivers: payload.copy_receivers,
491
- entries: payload.entries
492
- });
596
+ return Object.fromEntries(
597
+ Object.entries({
598
+ method,
599
+ signers: normalisedSigners,
600
+ message: payload.message,
601
+ expires_at: payload.expires_at,
602
+ copy_receivers: payload.copy_receivers,
603
+ entries: payload.entries,
604
+ max_total_credits: payload.max_total_credits
605
+ }).filter(([, value]) => value !== void 0)
606
+ );
493
607
  }
494
608
  function extractSignerRefs(payload) {
495
609
  const populatedAliases = [payload.signers, payload.signer_ids, payload.signerIds].filter(
@@ -506,20 +620,24 @@ function extractSignerRefs(payload) {
506
620
  }
507
621
  function normaliseSignerRef(ref, options) {
508
622
  if (typeof ref === "string") {
509
- if (!ref) throw new ValidationError("Signer ID cannot be empty");
623
+ if (!ref.trim()) throw new ValidationError("Signer ID cannot be empty");
510
624
  return { id: ref };
511
625
  }
512
626
  if (ref && typeof ref === "object") {
513
627
  const input = ref;
514
628
  const id = input.id ?? input.signer_id;
515
629
  validateSignerOptions(input);
516
- const normalised = stripEmpty({
517
- id,
518
- verification_method: input.verification_method,
519
- notification_methods: input.notification_methods,
520
- step: input.step
521
- });
522
- if (typeof id === "string" && id.length > 0) {
630
+ const normalised = Object.fromEntries(
631
+ Object.entries({
632
+ id,
633
+ sign_as: input.sign_as,
634
+ verification_method: input.verification_method,
635
+ notification_methods: input.notification_methods,
636
+ step: input.step,
637
+ embedded: input.embedded
638
+ }).filter(([, value]) => value !== void 0)
639
+ );
640
+ if (typeof id === "string" && id.trim().length > 0) {
523
641
  return normalised;
524
642
  }
525
643
  if (options.allowSignersWithoutId && Object.keys(normalised).length > 0) {
@@ -532,6 +650,30 @@ function normaliseSignerRef(ref, options) {
532
650
  throw new ValidationError("Invalid signer reference", { ref });
533
651
  }
534
652
  var AssignmentResource = class extends BaseResource {
653
+ /** Keep a request for later; no invitation or charge until the server sends it (staging). */
654
+ async schedule(documentId, payload) {
655
+ const id = this.requireId(documentId, "Document ID");
656
+ requireScheduledTime(payload?.send_at);
657
+ const body = { ...buildAssignmentPayload(payload), send_at: payload.send_at };
658
+ return this.call(
659
+ "Failed to schedule assignment",
660
+ () => this.http.post(`/documents/${id}/scheduled-sends`, body)
661
+ );
662
+ }
663
+ async signerCapacities(documentId) {
664
+ const id = this.requireId(documentId, "Document ID");
665
+ return this.call(
666
+ "Failed to fetch signer capacities",
667
+ () => this.http.get(`/documents/${id}/signer-capacities`)
668
+ );
669
+ }
670
+ async notificationHistory(documentId) {
671
+ const id = this.requireId(documentId, "Document ID");
672
+ return this.call(
673
+ "Failed to fetch notification history",
674
+ () => this.http.get(`/documents/${id}/notification-history`)
675
+ );
676
+ }
535
677
  /** Fetch an account review and available evidence for a signer's identity verification. */
536
678
  async getIdentityVerification(documentId, assignmentId, signerId) {
537
679
  const docId = this.requireId(documentId, "Document ID");
@@ -869,12 +1011,14 @@ var ContractResource = class extends BaseResource {
869
1011
  );
870
1012
  }
871
1013
  /** Read the root contract and its amendments from any document in that family. */
872
- async related(documentId, accountId) {
1014
+ async related(documentId, accountId, params = {}) {
873
1015
  const id = this.accountId(accountId);
874
1016
  const did = this.requireId(documentId, "Document ID");
875
1017
  return this.call(
876
1018
  "Failed to get related contracts",
877
- () => this.http.get(`/accounts/${id}/documents/${did}/contract/related`)
1019
+ () => this.http.get(`/accounts/${id}/documents/${did}/contract/related`, {
1020
+ params: cleanParams(params)
1021
+ })
878
1022
  );
879
1023
  }
880
1024
  /** Advance from the supplied current term or to a later end date. No automatic retry. */
@@ -993,6 +1137,25 @@ var FAILED_STATUSES = /* @__PURE__ */ new Set([
993
1137
  "expired"
994
1138
  ]);
995
1139
  var DocumentResource = class extends BaseResource {
1140
+ /** Read contacts who receive a completion email without document access (staging). */
1141
+ async listWatchers(documentId) {
1142
+ const id = this.requireId(documentId, "Document ID");
1143
+ return this.call(
1144
+ "Failed to list document watchers",
1145
+ () => this.http.get(`/documents/${id}/watchers`)
1146
+ );
1147
+ }
1148
+ /** Replace all watchers; an empty list clears them. Owner credentials required (staging). */
1149
+ async setWatchers(documentId, watcherIds) {
1150
+ const id = this.requireId(documentId, "Document ID");
1151
+ if (!Array.isArray(watcherIds) || new Set(watcherIds).size > 10 || watcherIds.some((value) => typeof value !== "string" || !value.trim())) {
1152
+ throw new ValidationError("watcher_ids must contain at most 10 nonblank contact IDs");
1153
+ }
1154
+ return this.call(
1155
+ "Failed to set document watchers",
1156
+ () => this.http.put(`/documents/${id}/watchers`, { watcher_ids: watcherIds })
1157
+ );
1158
+ }
996
1159
  /**
997
1160
  * Upload a PDF to the workspace.
998
1161
  *
@@ -1055,9 +1218,9 @@ var DocumentResource = class extends BaseResource {
1055
1218
  );
1056
1219
  }
1057
1220
  /** Get document details. */
1058
- async details(documentId) {
1221
+ async details(documentId, params = {}) {
1059
1222
  const id = this.requireId(documentId, "Document ID");
1060
- return this.fetchDetails(id);
1223
+ return this.fetchDetails(id, void 0, params);
1061
1224
  }
1062
1225
  /**
1063
1226
  * Rename a document (`PATCH /documents/{id}`).
@@ -1074,8 +1237,17 @@ var DocumentResource = class extends BaseResource {
1074
1237
  );
1075
1238
  }
1076
1239
  /** Alias for {@link details}. */
1077
- async get(documentId) {
1078
- return this.details(documentId);
1240
+ async get(documentId, params = {}) {
1241
+ return this.details(documentId, params);
1242
+ }
1243
+ /** Read only the assignment items visible to this signer. */
1244
+ async getAsSigner(documentId, signerAccessCode) {
1245
+ const id = this.requireId(documentId, "Document ID");
1246
+ const code = this.requireId(signerAccessCode, "signer-access-code");
1247
+ return this.call(
1248
+ "Failed to fetch signer document",
1249
+ () => this.http.get(`/documents/${id}`, signerAccessConfig(code))
1250
+ );
1079
1251
  }
1080
1252
  /** Poll document status until ready (or a terminal status / timeout). */
1081
1253
  async waitUntilReady(documentId, options = {}) {
@@ -1122,42 +1294,57 @@ var DocumentResource = class extends BaseResource {
1122
1294
  attempts
1123
1295
  });
1124
1296
  }
1125
- fetchDetails(documentId, timeout) {
1297
+ fetchDetails(documentId, timeout, params) {
1126
1298
  return this.call(
1127
1299
  "Failed to fetch document details",
1128
- () => this.http.get(`/documents/${documentId}`, timeout === void 0 ? void 0 : { timeout })
1300
+ () => this.http.get(`/documents/${documentId}`, { timeout, ...params?.expand ? { params } : {} })
1129
1301
  );
1130
1302
  }
1131
1303
  /** Download a document artifact. Defaults to the certificated (signed) PDF. */
1132
- async download(documentId, artifactName = "certificated") {
1304
+ async download(documentId, artifactName = "certificated", options = {}) {
1133
1305
  const id = this.requireId(documentId, "Document ID");
1134
1306
  const artifact = requireDocumentArtifactName(artifactName);
1307
+ const config = this.artifactConfig(options);
1135
1308
  return this.callBinary(
1136
1309
  "Failed to download document",
1137
1310
  () => this.http.get(`/documents/${id}/download/${artifact}`, {
1311
+ ...config,
1138
1312
  responseType: "arraybuffer"
1139
1313
  })
1140
1314
  );
1141
1315
  }
1142
1316
  /** Download the document thumbnail. */
1143
- async thumbnail(documentId) {
1317
+ async thumbnail(documentId, options = {}) {
1318
+ const config = this.artifactConfig(options);
1144
1319
  const id = this.requireId(documentId, "Document ID");
1145
1320
  return this.callBinary(
1146
1321
  "Failed to download document thumbnail",
1147
- () => this.http.get(`/documents/${id}/thumbnail`, { responseType: "arraybuffer" })
1322
+ () => this.http.get(`/documents/${id}/thumbnail`, {
1323
+ ...config,
1324
+ responseType: "arraybuffer"
1325
+ })
1148
1326
  );
1149
1327
  }
1150
1328
  /** Download a single page as a JPEG. */
1151
- async downloadPage(documentId, pageId) {
1329
+ async downloadPage(documentId, pageId, options = {}) {
1330
+ const config = this.artifactConfig(options);
1152
1331
  const docId = this.requireId(documentId, "Document ID");
1153
1332
  const pid = this.requireId(pageId, "Page ID");
1154
1333
  return this.callBinary(
1155
1334
  "Failed to download page",
1156
1335
  () => this.http.get(`/documents/${docId}/pages/${pid}/download`, {
1336
+ ...config,
1157
1337
  responseType: "arraybuffer"
1158
1338
  })
1159
1339
  );
1160
1340
  }
1341
+ artifactConfig(options) {
1342
+ if (options.artifact !== void 0 && options.artifact !== "certificated") {
1343
+ throw new ValidationError("artifact must be certificated");
1344
+ }
1345
+ const params = options.artifact === void 0 ? {} : { artifact: options.artifact };
1346
+ return options.signerAccessCode === void 0 ? { params } : signerAccessConfig(this.requireId(options.signerAccessCode, "signer-access-code"), params);
1347
+ }
1161
1348
  /** Fetch one page of the document activity log (20 entries by default). */
1162
1349
  async activities(documentId, params = {}) {
1163
1350
  const id = this.requireId(documentId, "Document ID");
@@ -1231,6 +1418,9 @@ var DocumentResource = class extends BaseResource {
1231
1418
  const tmplId = this.requireId(templateId, "Template ID");
1232
1419
  const accId = this.accountId(accountId);
1233
1420
  validateTemplateSigners(signers, { requireIdentity: true });
1421
+ validateCreditCeiling(options.max_total_credits);
1422
+ const { idempotencyKey, ...bodyOptions } = options;
1423
+ const headers = idempotencyHeaders(idempotencyKey);
1234
1424
  if (options.expires_at !== void 0) requireExpiration(options.expires_at);
1235
1425
  if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
1236
1426
  throw new ValidationError("editor_fields must contain field_id and value");
@@ -1239,11 +1429,11 @@ var DocumentResource = class extends BaseResource {
1239
1429
  throw new ValidationError("tags must contain non-empty tag names");
1240
1430
  }
1241
1431
  await this.validateCertificateTemplateMethod(tmplId, accId, signers);
1242
- const body = { ...options, signers };
1432
+ const body = { ...bodyOptions, signers };
1243
1433
  this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
1244
1434
  return this.call(
1245
1435
  "Failed to create document from template",
1246
- () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents`, body)
1436
+ () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents`, body, { headers })
1247
1437
  );
1248
1438
  }
1249
1439
  /** Estimate the credit cost of creating a document from a template. */
@@ -1422,6 +1612,285 @@ function sleep(ms) {
1422
1612
  return new Promise((resolve) => setTimeout(resolve, ms));
1423
1613
  }
1424
1614
 
1615
+ // src/api/resources/embed.ts
1616
+ var EmbedResource = class extends BaseResource {
1617
+ async listOrigins(accountId) {
1618
+ const id = this.accountId(accountId);
1619
+ return this.call(
1620
+ "Failed to list embed origins",
1621
+ () => this.http.get(`/accounts/${id}/embed-origins`)
1622
+ );
1623
+ }
1624
+ async createOrigin(origin, accountId) {
1625
+ const id = this.accountId(accountId);
1626
+ validateOrigin(origin);
1627
+ return this.call(
1628
+ "Failed to add embed origin",
1629
+ () => this.http.post(`/accounts/${id}/embed-origins`, { origin })
1630
+ );
1631
+ }
1632
+ async updateOrigin(originId, origin, accountId) {
1633
+ const id = this.accountId(accountId);
1634
+ const oid = this.requireId(originId, "Origin ID");
1635
+ validateOrigin(origin);
1636
+ return this.call(
1637
+ "Failed to update embed origin",
1638
+ () => this.http.put(`/accounts/${id}/embed-origins/${oid}`, { origin })
1639
+ );
1640
+ }
1641
+ async deleteOrigin(originId, accountId) {
1642
+ const id = this.accountId(accountId);
1643
+ const oid = this.requireId(originId, "Origin ID");
1644
+ return this.call(
1645
+ "Failed to delete embed origin",
1646
+ () => this.http.delete(`/accounts/${id}/embed-origins/${oid}`)
1647
+ );
1648
+ }
1649
+ /** Load the returned private URL in the iframe within five minutes. */
1650
+ async createSession(documentId, assignmentId, signerId) {
1651
+ const did = this.requireId(documentId, "Document ID");
1652
+ const aid = this.requireId(assignmentId, "Assignment ID");
1653
+ const sid = this.requireId(signerId, "Signer ID");
1654
+ return this.call(
1655
+ "Failed to create embed session",
1656
+ () => this.http.post(`/documents/${did}/assignments/${aid}/signers/${sid}/embed-sessions`)
1657
+ );
1658
+ }
1659
+ /** Used by Assinafy's embed page; consumes the token even on a 409. Never retry automatically. */
1660
+ async exchangeSession(token, parentOrigin) {
1661
+ const value = this.requireId(token, "Embed session token");
1662
+ if (parentOrigin !== void 0) validateOrigin(parentOrigin);
1663
+ return this.call(
1664
+ "Failed to exchange embed session",
1665
+ () => this.http.post(
1666
+ `/embed/sessions/${value}/exchange`,
1667
+ parentOrigin === void 0 ? void 0 : { parent_origin: parentOrigin },
1668
+ publicRequestConfig()
1669
+ )
1670
+ );
1671
+ }
1672
+ };
1673
+ function validateOrigin(value) {
1674
+ let url;
1675
+ try {
1676
+ url = new URL(value);
1677
+ } catch {
1678
+ throw new ValidationError("origin must be an absolute origin");
1679
+ }
1680
+ 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))) {
1681
+ throw new ValidationError(
1682
+ "origin must use HTTPS (HTTP only for localhost or 127.0.0.1) without path, credentials, query, fragment or wildcard"
1683
+ );
1684
+ }
1685
+ }
1686
+
1687
+ // src/api/resources/envelopes.ts
1688
+ var EnvelopeResource = class extends BaseResource {
1689
+ /** Schedule one envelope request; idempotency headers are not supported here (staging). */
1690
+ async schedule(payload, accountId) {
1691
+ const id = this.accountId(accountId);
1692
+ validateCreate(payload);
1693
+ requireScheduledTime(payload.send_at);
1694
+ return this.call(
1695
+ "Failed to schedule envelope",
1696
+ () => this.http.post(`/accounts/${id}/scheduled-sends`, payload)
1697
+ );
1698
+ }
1699
+ /** Estimate one reminder for the whole envelope without sending or charging (staging). */
1700
+ async estimateResendCost(envelopeId, signerId, accountId) {
1701
+ const id = this.accountId(accountId);
1702
+ const eid = this.requireId(envelopeId, "Envelope ID");
1703
+ const sid = this.requireId(signerId, "Signer ID");
1704
+ return this.call(
1705
+ "Failed to estimate envelope reminder cost",
1706
+ () => this.http.post(`/accounts/${id}/envelopes/${eid}/signers/${sid}/estimate-resend-cost`)
1707
+ );
1708
+ }
1709
+ async list(params = {}, accountId) {
1710
+ const id = this.accountId(accountId);
1711
+ if (params.status !== void 0 && !["open", "closed"].includes(params.status))
1712
+ throw new ValidationError("status must be open or closed");
1713
+ return this.callList(
1714
+ "Failed to list envelopes",
1715
+ () => this.http.get(`/accounts/${id}/envelopes`, { params: cleanParams({ ...params }) })
1716
+ );
1717
+ }
1718
+ /** Creates assignments and sends invitations; persist the result before checking delivery. */
1719
+ async create(payload, options = {}) {
1720
+ const id = this.accountId(options.accountId);
1721
+ validateCreate(payload);
1722
+ const headers = idempotencyHeaders(options.idempotencyKey);
1723
+ return this.call(
1724
+ "Failed to create envelope",
1725
+ () => this.http.post(`/accounts/${id}/envelopes`, payload, { headers })
1726
+ );
1727
+ }
1728
+ async estimateCost(payload, accountId) {
1729
+ const id = this.accountId(accountId);
1730
+ validateCreate(payload);
1731
+ return this.call(
1732
+ "Failed to estimate envelope cost",
1733
+ () => this.http.post(`/accounts/${id}/envelopes/estimate-cost`, payload)
1734
+ );
1735
+ }
1736
+ async get(envelopeId, accountId) {
1737
+ const id = this.accountId(accountId);
1738
+ const eid = this.requireId(envelopeId, "Envelope ID");
1739
+ return this.call(
1740
+ "Failed to fetch envelope",
1741
+ () => this.http.get(`/accounts/${id}/envelopes/${eid}`)
1742
+ );
1743
+ }
1744
+ /** Renames, changes the message (null clears), or reorders every current document. */
1745
+ async update(envelopeId, payload, accountId) {
1746
+ const id = this.accountId(accountId);
1747
+ const eid = this.requireId(envelopeId, "Envelope ID");
1748
+ if (!payload || !["name", "message", "document_ids"].some(
1749
+ (key) => payload[key] !== void 0
1750
+ ))
1751
+ throw new ValidationError("At least one envelope field is required");
1752
+ if (payload.name !== void 0) validateName(payload.name);
1753
+ validateMessage(payload.message);
1754
+ if (payload.document_ids !== void 0) validateIds(payload.document_ids, "document_ids");
1755
+ return this.call(
1756
+ "Failed to update envelope",
1757
+ () => this.http.patch(`/accounts/${id}/envelopes/${eid}`, payload)
1758
+ );
1759
+ }
1760
+ /** Requires a closed envelope; its documents are retained by the server. */
1761
+ async delete(envelopeId, accountId) {
1762
+ const id = this.accountId(accountId);
1763
+ const eid = this.requireId(envelopeId, "Envelope ID");
1764
+ return this.call(
1765
+ "Failed to delete envelope",
1766
+ () => this.http.delete(`/accounts/${id}/envelopes/${eid}`)
1767
+ );
1768
+ }
1769
+ async activities(envelopeId, params = {}, accountId) {
1770
+ const id = this.accountId(accountId);
1771
+ const eid = this.requireId(envelopeId, "Envelope ID");
1772
+ requireSort(params.sort, ["id", "-id"]);
1773
+ return this.callList(
1774
+ "Failed to fetch envelope activities",
1775
+ () => this.http.get(`/accounts/${id}/envelopes/${eid}/activities`, {
1776
+ params: cleanParams({ ...params })
1777
+ })
1778
+ );
1779
+ }
1780
+ /** ZIP containing the requested artifact of each eligible document. */
1781
+ async download(envelopeId, artifactName = "certificated", accountId) {
1782
+ const id = this.accountId(accountId);
1783
+ const eid = this.requireId(envelopeId, "Envelope ID");
1784
+ const artifact = requireDocumentArtifactName(artifactName);
1785
+ return this.callBinary(
1786
+ "Failed to download envelope",
1787
+ () => this.http.get(`/accounts/${id}/envelopes/${eid}/download/${artifact}`, {
1788
+ responseType: "arraybuffer"
1789
+ })
1790
+ );
1791
+ }
1792
+ /** Cancels only cancellable documents and notifies their recipients. */
1793
+ async cancel(envelopeId, accountId) {
1794
+ const id = this.accountId(accountId);
1795
+ const eid = this.requireId(envelopeId, "Envelope ID");
1796
+ return this.call(
1797
+ "Failed to cancel envelope",
1798
+ () => this.http.put(`/accounts/${id}/envelopes/${eid}/cancel`)
1799
+ );
1800
+ }
1801
+ async resendNotification(envelopeId, signerId, accountId) {
1802
+ const id = this.accountId(accountId);
1803
+ const eid = this.requireId(envelopeId, "Envelope ID");
1804
+ const sid = this.requireId(signerId, "Signer ID");
1805
+ return this.call(
1806
+ "Failed to resend envelope notification",
1807
+ () => this.http.put(`/accounts/${id}/envelopes/${eid}/signers/${sid}/resend`)
1808
+ );
1809
+ }
1810
+ /** Adds a processed document for existing envelope signers and sends updated invitations. */
1811
+ async addDocument(envelopeId, payload, accountId) {
1812
+ const id = this.accountId(accountId);
1813
+ const eid = this.requireId(envelopeId, "Envelope ID");
1814
+ validateDocument(payload);
1815
+ validateCreditCeiling(payload.max_total_credits);
1816
+ return this.call(
1817
+ "Failed to add envelope document",
1818
+ () => this.http.post(`/accounts/${id}/envelopes/${eid}/documents`, payload)
1819
+ );
1820
+ }
1821
+ /** Cancels an open document, notifies its recipients, and removes it from the envelope. */
1822
+ async removeDocument(envelopeId, documentId, accountId) {
1823
+ const id = this.accountId(accountId);
1824
+ const eid = this.requireId(envelopeId, "Envelope ID");
1825
+ const did = this.requireId(documentId, "Document ID");
1826
+ return this.call(
1827
+ "Failed to remove envelope document",
1828
+ () => this.http.delete(`/accounts/${id}/envelopes/${eid}/documents/${did}`)
1829
+ );
1830
+ }
1831
+ };
1832
+ function validateName(value) {
1833
+ if (typeof value !== "string" || !value.trim() || [...value].length > 255 || value.includes("<"))
1834
+ throw new ValidationError("name must contain 1\u2013255 characters without <");
1835
+ }
1836
+ function validateMessage(value) {
1837
+ if (value != null && typeof value !== "string")
1838
+ throw new ValidationError("message must be text or null");
1839
+ }
1840
+ function validateIds(values, name) {
1841
+ if (!Array.isArray(values) || !values.length || values.some((id) => typeof id !== "string" || !id.trim()) || new Set(values).size !== values.length)
1842
+ throw new ValidationError(`${name} must contain distinct nonblank IDs`);
1843
+ }
1844
+ function validateDocument(payload) {
1845
+ if (!payload || typeof payload.id !== "string" || !payload.id.trim())
1846
+ throw new ValidationError("Document ID is required");
1847
+ validateIds(payload.signer_ids, "signer_ids");
1848
+ if (payload.method !== void 0 && !["virtual", "collect"].includes(payload.method))
1849
+ throw new ValidationError("method must be virtual or collect");
1850
+ if (payload.method === "collect" && (!Array.isArray(payload.entries) || !payload.entries.length))
1851
+ throw new ValidationError("entries are required for collect documents");
1852
+ if (payload.expires_at != null && typeof payload.expires_at !== "string" && (typeof payload.expires_at !== "number" || !Number.isFinite(payload.expires_at)))
1853
+ throw new ValidationError("expires_at must be a date string, Unix time or null");
1854
+ if (payload.copy_receiver_ids !== void 0 && (!Array.isArray(payload.copy_receiver_ids) || payload.copy_receiver_ids.some((id) => typeof id !== "string" || !id.trim())))
1855
+ throw new ValidationError("copy_receiver_ids must contain nonblank IDs");
1856
+ }
1857
+ function validateCreate(payload) {
1858
+ if (!payload) throw new ValidationError("Envelope payload is required");
1859
+ validateName(payload.name);
1860
+ validateMessage(payload.message);
1861
+ validateCreditCeiling(payload.max_total_credits);
1862
+ if (!Array.isArray(payload.signers) || !payload.signers.length || payload.signers.length > 20 || payload.signers.some((s) => !s || typeof s !== "object"))
1863
+ throw new ValidationError("signers must contain 1\u201320 signers");
1864
+ validateIds(
1865
+ payload.signers.map((s) => s.id),
1866
+ "signers"
1867
+ );
1868
+ for (const signer of payload.signers) {
1869
+ if ("step" in signer) throw new ValidationError("Envelope signers do not accept step");
1870
+ validateSignerOptions(signer);
1871
+ }
1872
+ if (!Array.isArray(payload.documents) || !payload.documents.length || payload.documents.length > 20)
1873
+ throw new ValidationError("documents must contain 1\u201320 documents");
1874
+ for (const document of payload.documents) {
1875
+ validateDocument(document);
1876
+ const signers = document.signer_ids.map((id) => payload.signers.find((s) => s.id === id));
1877
+ if (signers.some((s) => !s))
1878
+ throw new ValidationError("Every document signer must be listed in signers");
1879
+ const assigned = signers.filter((s) => s !== void 0);
1880
+ validateDigitalCertificateMethod(document.method ?? "virtual", assigned);
1881
+ if (assigned.length > 1 && assigned.some((s) => s.verification_method === "DigitalCertificate"))
1882
+ throw new ValidationError(
1883
+ "A DigitalCertificate signer must be alone on each envelope document"
1884
+ );
1885
+ }
1886
+ validateIds(
1887
+ payload.documents.map((d) => d.id),
1888
+ "documents"
1889
+ );
1890
+ if (payload.signers.some((s) => !payload.documents.some((d) => d.signer_ids.includes(s.id))))
1891
+ throw new ValidationError("Every signer must belong to at least one document");
1892
+ }
1893
+
1425
1894
  // src/api/resources/fields.ts
1426
1895
  var FieldsResource = class extends BaseResource {
1427
1896
  /** Create a field definition. */
@@ -1736,15 +2205,44 @@ function httpsUrl(value, name) {
1736
2205
  return url;
1737
2206
  }
1738
2207
 
2208
+ // src/api/resources/scheduled-sends.ts
2209
+ var ScheduledSendResource = class extends BaseResource {
2210
+ async list(params = {}, accountId) {
2211
+ const id = this.accountId(accountId);
2212
+ return this.callList(
2213
+ "Failed to list scheduled sends",
2214
+ () => this.http.get(`/accounts/${id}/scheduled-sends`, { params: cleanParams({ ...params }) })
2215
+ );
2216
+ }
2217
+ /** Cancel only a pending request; nothing is sent or charged. */
2218
+ async cancel(scheduledSendId, accountId) {
2219
+ const id = this.accountId(accountId);
2220
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2221
+ return this.call(
2222
+ "Failed to cancel scheduled send",
2223
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/cancel`)
2224
+ );
2225
+ }
2226
+ /** Execute a pending request now, sending invitations and charging its current cost. */
2227
+ async send(scheduledSendId, accountId) {
2228
+ const id = this.accountId(accountId);
2229
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2230
+ return this.call(
2231
+ "Failed to send scheduled request",
2232
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/send`)
2233
+ );
2234
+ }
2235
+ };
2236
+
1739
2237
  // src/api/resources/signer-documents.ts
1740
2238
  var SignerDocumentsResource = class extends BaseResource {
1741
2239
  /** `GET /signers/{signer_id}/document?signer-access-code=…` */
1742
- async getCurrent(signerId, signerAccessCode) {
2240
+ async getCurrent(signerId, signerAccessCode, params = {}) {
1743
2241
  const sid = this.requireId(signerId, "Signer ID");
1744
2242
  const code = this.requireId(signerAccessCode, "signer-access-code");
1745
2243
  return this.call(
1746
2244
  "Failed to fetch current signer document",
1747
- () => this.http.get(`/signers/${sid}/document`, signerAccessConfig(code))
2245
+ () => this.http.get(`/signers/${sid}/document`, signerAccessConfig(code, params))
1748
2246
  );
1749
2247
  }
1750
2248
  /** `GET /signers/{signer_id}/documents?signer-access-code=…` */
@@ -1761,17 +2259,17 @@ var SignerDocumentsResource = class extends BaseResource {
1761
2259
  return this.listDocuments(signerId, { params: cleanParams({ ...params }) });
1762
2260
  }
1763
2261
  /** `GET /signers/{signer_id}/documents/search?search=…&signer-access-code=…` */
1764
- async search(signerId, search, signerAccessCode) {
2262
+ async search(signerId, search, signerAccessCode, params = {}) {
1765
2263
  const code = this.requireId(signerAccessCode, "signer-access-code");
1766
- return this.searchDocuments(signerId, signerAccessConfig(code, { search }));
2264
+ return this.searchDocuments(signerId, signerAccessConfig(code, { ...params, search }));
1767
2265
  }
1768
2266
  /**
1769
2267
  * `GET /signers/{signer_id}/documents/search?search=…` with the client's owner
1770
2268
  * credentials instead of a signer access code. The signer must belong to that
1771
2269
  * workspace.
1772
2270
  */
1773
- async searchAsOwner(signerId, search) {
1774
- return this.searchDocuments(signerId, { params: cleanParams({ search }) });
2271
+ async searchAsOwner(signerId, search, params = {}) {
2272
+ return this.searchDocuments(signerId, { params: cleanParams({ ...params, search }) });
1775
2273
  }
1776
2274
  listDocuments(signerId, config) {
1777
2275
  const sid = this.requireId(signerId, "Signer ID");
@@ -1788,9 +2286,9 @@ var SignerDocumentsResource = class extends BaseResource {
1788
2286
  );
1789
2287
  }
1790
2288
  /**
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.
2289
+ * `GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`.
2290
+ * The current API permits only originals with a signer code. Other forms are
2291
+ * retained for compatibility; use downloadCertifiedCopy for completed PDFs.
1794
2292
  */
1795
2293
  async download(signerId, documentId, artifactName, signerAccessCode) {
1796
2294
  const sid = this.requireId(signerId, "Signer ID");
@@ -1904,13 +2402,16 @@ var SignerDocumentsResource = class extends BaseResource {
1904
2402
  * Returns `{ token }` for the signer's Web PKI client. This production route
1905
2403
  * is used by Assinafy's signing frontend but is absent from OpenAPI paths.
1906
2404
  */
1907
- async startCertificate(signerAccessCode) {
2405
+ async startCertificate(signerAccessCode, documentId) {
1908
2406
  const code = this.requireId(signerAccessCode, "signer-access-code");
1909
2407
  return this.call(
1910
2408
  "Failed to start certificate signature",
1911
2409
  () => this.http.post(
1912
2410
  "/signers/certificate/start",
1913
- { "signer-access-code": code },
2411
+ {
2412
+ "signer-access-code": code,
2413
+ ...documentId === void 0 ? {} : { document_id: this.requireId(documentId, "Document ID") }
2414
+ },
1914
2415
  signerAccessConfig(code)
1915
2416
  )
1916
2417
  );
@@ -1921,7 +2422,7 @@ var SignerDocumentsResource = class extends BaseResource {
1921
2422
  * successfully signs it. Returns `{ signerName }`; private keys stay local.
1922
2423
  * This production route is absent from OpenAPI paths.
1923
2424
  */
1924
- async completeCertificate(signerAccessCode, token) {
2425
+ async completeCertificate(signerAccessCode, token, documentId) {
1925
2426
  const code = this.requireId(signerAccessCode, "signer-access-code");
1926
2427
  if (typeof token !== "string" || !token.trim()) {
1927
2428
  throw new ValidationError("Certificate token is required");
@@ -1930,7 +2431,11 @@ var SignerDocumentsResource = class extends BaseResource {
1930
2431
  "Failed to complete certificate signature",
1931
2432
  () => this.http.post(
1932
2433
  "/signers/certificate/complete",
1933
- { "signer-access-code": code, token },
2434
+ {
2435
+ "signer-access-code": code,
2436
+ token,
2437
+ ...documentId === void 0 ? {} : { document_id: this.requireId(documentId, "Document ID") }
2438
+ },
1934
2439
  signerAccessConfig(code)
1935
2440
  )
1936
2441
  );
@@ -1995,11 +2500,15 @@ var SignerDocumentsResource = class extends BaseResource {
1995
2500
  );
1996
2501
  }
1997
2502
  /** `GET /sign?signer-access-code=…` — fetch the assignment as the signer sees it. */
1998
- async getAssignment(signerAccessCode, hasAcceptedTerms) {
2503
+ async getAssignment(signerAccessCode, hasAcceptedTerms, params = {}) {
1999
2504
  const code = this.requireId(signerAccessCode, "signer-access-code");
2505
+ if (params.document_id !== void 0) this.requireId(params.document_id, "Document ID");
2000
2506
  return this.call(
2001
2507
  "Failed to fetch signer assignment",
2002
- () => this.http.get("/sign", signerAccessConfig(code, { has_accepted_terms: hasAcceptedTerms }))
2508
+ () => this.http.get(
2509
+ "/sign",
2510
+ signerAccessConfig(code, { ...params, has_accepted_terms: hasAcceptedTerms })
2511
+ )
2003
2512
  );
2004
2513
  }
2005
2514
  /**
@@ -2042,12 +2551,59 @@ var SignerDocumentsResource = class extends BaseResource {
2042
2551
  );
2043
2552
  }
2044
2553
  async requireDocumentAccess(documentId, signerAccessCode, assignmentId) {
2045
- const document = await this.getAssignment(signerAccessCode);
2554
+ const document = assignmentId === void 0 ? await this.call(
2555
+ "Failed to fetch signer document",
2556
+ () => this.http.get(`/documents/${documentId}`, signerAccessConfig(signerAccessCode))
2557
+ ) : await this.getAssignment(signerAccessCode, void 0, { document_id: documentId });
2046
2558
  if (document.id !== documentId || assignmentId !== void 0 && document.assignment?.id !== assignmentId) {
2047
2559
  throw new ValidationError("Signer access code does not match the document or assignment");
2048
2560
  }
2049
2561
  return document;
2050
2562
  }
2563
+ async getTheme(signerAccessCode) {
2564
+ const code = this.requireId(signerAccessCode, "signer-access-code");
2565
+ return this.call(
2566
+ "Failed to fetch signing theme",
2567
+ () => this.http.get("/sign/theme", signerAccessConfig(code))
2568
+ );
2569
+ }
2570
+ async downloadLogo(signerAccessCode) {
2571
+ const code = this.requireId(signerAccessCode, "signer-access-code");
2572
+ return this.callBinary(
2573
+ "Failed to download signing logo",
2574
+ () => this.http.get("/sign/logo", {
2575
+ ...signerAccessConfig(code),
2576
+ responseType: "arraybuffer"
2577
+ })
2578
+ );
2579
+ }
2580
+ /** Sends a time-limited download link to the original signing contact. */
2581
+ async resendCertifiedCopy(signerAccessCode, documentId) {
2582
+ const code = this.requireId(signerAccessCode, "signer-access-code");
2583
+ const body = documentId === void 0 ? void 0 : { document_id: this.requireId(documentId, "Document ID") };
2584
+ return this.call(
2585
+ "Failed to send certified copy",
2586
+ () => this.http.post("/sign/certified-copy", body, signerAccessConfig(code))
2587
+ );
2588
+ }
2589
+ /** Expired tokens return an ApiError (302); redirects remain disabled. */
2590
+ async downloadCertifiedCopy(token, artifact = "certificated") {
2591
+ const value = this.requireId(token, "Download token");
2592
+ if (!["certificated", "pades"].includes(artifact))
2593
+ throw new ValidationError("artifact must be certificated or pades");
2594
+ const config = { ...publicRequestConfig(), responseType: "arraybuffer" };
2595
+ return this.callBinary(
2596
+ "Failed to download certified copy",
2597
+ () => artifact === "pades" ? this.http.get(`/signers/downloads/${value}/pades`, config) : this.http.get(`/signers/downloads/${value}`, config)
2598
+ );
2599
+ }
2600
+ async resendDownloadLink(token) {
2601
+ const value = this.requireId(token, "Download token");
2602
+ return this.call(
2603
+ "Failed to resend download link",
2604
+ () => this.http.post(`/signers/downloads/${value}/resend`, void 0, publicRequestConfig())
2605
+ );
2606
+ }
2051
2607
  };
2052
2608
  function validateDeclineReason(value) {
2053
2609
  if (typeof value !== "string" || !value.trim()) {
@@ -2120,14 +2676,14 @@ var SignerResource = class extends BaseResource {
2120
2676
  })
2121
2677
  );
2122
2678
  }
2123
- /** Update a signer. Fails if the signer has active assignments. */
2679
+ /** Update supplied fields; verified channels on in-flight documents cannot change. */
2124
2680
  async update(signerId, payload, accountId) {
2125
2681
  const id = this.accountId(accountId);
2126
2682
  const sid = this.requireId(signerId, "Signer ID");
2127
2683
  if (payload.full_name !== void 0 && !payload.full_name.trim()) {
2128
2684
  throw new ValidationError("Signer full name cannot be blank");
2129
2685
  }
2130
- if (payload.email !== void 0) requireEmail(payload.email);
2686
+ if (payload.email != null && payload.email !== "") requireEmail(payload.email);
2131
2687
  return this.call(
2132
2688
  "Failed to update signer",
2133
2689
  () => this.http.put(`/accounts/${id}/signers/${sid}`, normaliseSignerPayload(payload, true))
@@ -2148,13 +2704,13 @@ var SignerResource = class extends BaseResource {
2148
2704
  try {
2149
2705
  const lower = email.toLowerCase();
2150
2706
  for (let page = 1; page <= MAX_SEARCH_PAGES; page++) {
2151
- const { data, meta } = await this.list({ search: email, per_page: 100, page }, accountId);
2707
+ const { data, meta } = await this.list({ search: email, per_page: 50, page }, accountId);
2152
2708
  const match = data.find((s) => (s.email ?? "").toLowerCase() === lower);
2153
2709
  if (match) return match;
2154
2710
  if (!data.length) return null;
2155
2711
  if (meta?.last_page !== void 0) {
2156
2712
  if (page >= meta.last_page) return null;
2157
- } else if (data.length < 100) {
2713
+ } else if (data.length < 50) {
2158
2714
  return null;
2159
2715
  }
2160
2716
  }
@@ -2172,7 +2728,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
2172
2728
  const normalised = {
2173
2729
  full_name: payload.full_name,
2174
2730
  email: payload.email,
2175
- whatsapp_phone_number: payload.whatsapp_phone_number ?? payload.phone
2731
+ whatsapp_phone_number: payload.whatsapp_phone_number !== void 0 ? payload.whatsapp_phone_number : payload.phone
2176
2732
  };
2177
2733
  if (payload.government_id !== void 0) {
2178
2734
  normalised.government_id = payload.government_id;
@@ -2183,7 +2739,7 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
2183
2739
  if ("metadata" in payload && payload.metadata !== void 0) {
2184
2740
  normalised.metadata = payload.metadata;
2185
2741
  }
2186
- return stripEmpty(normalised);
2742
+ return useGovernmentId ? Object.fromEntries(Object.entries(normalised).filter(([, value]) => value !== void 0)) : stripEmpty(normalised);
2187
2743
  }
2188
2744
 
2189
2745
  // src/api/resources/tags.ts
@@ -2284,25 +2840,7 @@ var TemplateResource = class extends BaseResource {
2284
2840
  }
2285
2841
  };
2286
2842
 
2287
- // src/api/types.ts
2288
- var NOTIFICATION_PREFERENCE_CODES = [
2289
- "DocumentCompleted",
2290
- "SignerDeclined",
2291
- "DocumentCancelled",
2292
- "DocumentAboutToExpire",
2293
- "DocumentExpired",
2294
- "DocumentExpirationReset",
2295
- "DocumentProcessingFailed",
2296
- "TemplateProcessingFailed",
2297
- "SignerWhatsappFailed",
2298
- "ContractRenewalNotice",
2299
- "ContractExpiring",
2300
- "ContractExpired",
2301
- "ContractRenewed"
2302
- ];
2303
-
2304
2843
  // src/api/resources/users.ts
2305
- var NOTIFICATION_PREFERENCES = new Set(NOTIFICATION_PREFERENCE_CODES);
2306
2844
  var UsersResource = class extends BaseResource {
2307
2845
  /** Fetch the authenticated user's profile. */
2308
2846
  async self() {
@@ -2324,26 +2862,25 @@ var UsersResource = class extends BaseResource {
2324
2862
  }
2325
2863
  /** Merge one or more owner-facing email notification preferences. */
2326
2864
  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
- }
2865
+ validateBooleanMap(payload, NOTIFICATION_PREFERENCE_CODES);
2342
2866
  return this.call(
2343
2867
  "Failed to update notification preferences",
2344
2868
  () => this.http.put("/users/self/notification-preferences", payload)
2345
2869
  );
2346
2870
  }
2871
+ async getPushPreferences() {
2872
+ return this.call(
2873
+ "Failed to fetch push preferences",
2874
+ () => this.http.get("/users/self/push-preferences")
2875
+ );
2876
+ }
2877
+ async updatePushPreferences(payload) {
2878
+ validateBooleanMap(payload, PUSH_PREFERENCE_CODES);
2879
+ return this.call(
2880
+ "Failed to update push preferences",
2881
+ () => this.http.put("/users/self/push-preferences", payload)
2882
+ );
2883
+ }
2347
2884
  };
2348
2885
 
2349
2886
  // src/api/resources/webhooks.ts
@@ -2383,6 +2920,15 @@ function validateWebhookFields(payload, requireHttps = false) {
2383
2920
  }
2384
2921
  }
2385
2922
  var WebhookResource = class extends BaseResource {
2923
+ /** Sends a webhook_test even to an inactive/held endpoint; does not change its state. */
2924
+ async testEndpoint(endpointId, accountId) {
2925
+ const id = this.accountId(accountId);
2926
+ const eid = this.requireId(endpointId, "Endpoint ID");
2927
+ return this.call(
2928
+ "Failed to send webhook test",
2929
+ () => this.http.post(`/accounts/${id}/webhooks/endpoints/${eid}/test`)
2930
+ );
2931
+ }
2386
2932
  /**
2387
2933
  * `PUT /accounts/{accountId}/webhooks/subscriptions` — create or replace the
2388
2934
  * account's oldest webhook endpoint. Use the endpoint methods for accounts
@@ -2510,15 +3056,21 @@ var WebhookResource = class extends BaseResource {
2510
3056
  }
2511
3057
  /**
2512
3058
  * `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
2513
- * The old secret stops working immediately. Requires `webhooks:write` for OAuth.
3059
+ * Set keep_previous to retain the replaced secret for 24 hours. Requires webhooks:write.
2514
3060
  */
2515
- async rotateEndpointSecret(endpointId, accountId) {
3061
+ async rotateEndpointSecret(endpointId, accountId, options = {}) {
2516
3062
  const id = this.accountId(accountId);
2517
3063
  const eid = this.requireId(endpointId, "Endpoint ID");
3064
+ if (options.keep_previous !== void 0 && typeof options.keep_previous !== "boolean") {
3065
+ throw new ValidationError("keep_previous must be a boolean");
3066
+ }
2518
3067
  this.logger.info("Rotating webhook endpoint secret");
2519
3068
  return this.call(
2520
3069
  "Failed to rotate webhook endpoint secret",
2521
- () => this.http.post(`/accounts/${id}/webhooks/endpoints/${eid}/secret/rotate`)
3070
+ () => this.http.post(
3071
+ `/accounts/${id}/webhooks/endpoints/${eid}/secret/rotate`,
3072
+ options.keep_previous === void 0 ? void 0 : { keep_previous: options.keep_previous }
3073
+ )
2522
3074
  );
2523
3075
  }
2524
3076
  /** List currently supported webhook event types. */
@@ -2569,9 +3121,46 @@ var WorkspaceResource = class extends BaseResource {
2569
3121
  );
2570
3122
  }
2571
3123
  /** Fetch a single workspace. */
2572
- async get(accountId) {
3124
+ async get(accountId, params = {}) {
3125
+ const id = this.requireId(accountId, "Account ID");
3126
+ return this.call(
3127
+ "Failed to fetch workspace",
3128
+ () => this.http.get(`/accounts/${id}`, { params })
3129
+ );
3130
+ }
3131
+ /** Plan allowance and balances; unavailable to third-party OAuth applications. */
3132
+ async usage(accountId) {
3133
+ const id = this.requireId(accountId, "Account ID");
3134
+ return this.call(
3135
+ "Failed to fetch workspace usage",
3136
+ () => this.http.get(`/accounts/${id}/usage`)
3137
+ );
3138
+ }
3139
+ async getNotificationPolicy(accountId) {
2573
3140
  const id = this.requireId(accountId, "Account ID");
2574
- return this.call("Failed to fetch workspace", () => this.http.get(`/accounts/${id}`));
3141
+ return this.call(
3142
+ "Failed to fetch notification policy",
3143
+ () => this.http.get(`/accounts/${id}/notification-policy`)
3144
+ );
3145
+ }
3146
+ /** Owner-only partial merge; false disables the alert workspace-wide. */
3147
+ async updateNotificationPolicy(accountId, payload) {
3148
+ const id = this.requireId(accountId, "Account ID");
3149
+ if (!payload || typeof payload !== "object" || Array.isArray(payload) || !Object.keys(payload).length || Object.keys(payload).some((key) => !["events", "owners_receive_all"].includes(key)))
3150
+ throw new ValidationError("Provide events and/or owners_receive_all");
3151
+ if (payload.owners_receive_all !== void 0 && typeof payload.owners_receive_all !== "boolean")
3152
+ throw new ValidationError("owners_receive_all must be a boolean");
3153
+ if (payload.events !== void 0)
3154
+ validateBooleanMap(payload.events, [
3155
+ ...NOTIFICATION_PREFERENCE_CODES,
3156
+ ...PUSH_PREFERENCE_CODES
3157
+ ]);
3158
+ if (payload.events === void 0 && payload.owners_receive_all === void 0)
3159
+ throw new ValidationError("At least one notification policy field is required");
3160
+ return this.call(
3161
+ "Failed to update notification policy",
3162
+ () => this.http.put(`/accounts/${id}/notification-policy`, payload)
3163
+ );
2575
3164
  }
2576
3165
  /** Fetch the workspace's public branding theme. */
2577
3166
  async getTheme(accountId) {
@@ -2765,6 +3354,7 @@ var AssinafyClient = class _AssinafyClient {
2765
3354
  contracts;
2766
3355
  signers;
2767
3356
  workspaces;
3357
+ scheduledSends;
2768
3358
  assignments;
2769
3359
  webhooks;
2770
3360
  templates;
@@ -2772,6 +3362,8 @@ var AssinafyClient = class _AssinafyClient {
2772
3362
  auth;
2773
3363
  oauth;
2774
3364
  fields;
3365
+ envelopes;
3366
+ embed;
2775
3367
  users;
2776
3368
  signerDocuments;
2777
3369
  webhookVerifier;
@@ -2837,12 +3429,19 @@ var AssinafyClient = class _AssinafyClient {
2837
3429
  this.defaultAccountId,
2838
3430
  this.logger
2839
3431
  );
3432
+ this.scheduledSends = new ScheduledSendResource(
3433
+ this.axiosInstance,
3434
+ this.defaultAccountId,
3435
+ this.logger
3436
+ );
2840
3437
  this.webhooks = new WebhookResource(this.axiosInstance, this.defaultAccountId, this.logger);
2841
3438
  this.templates = new TemplateResource(this.axiosInstance, this.defaultAccountId, this.logger);
2842
3439
  this.tags = new TagResource(this.axiosInstance, this.defaultAccountId, this.logger);
2843
3440
  this.auth = new AuthenticationResource(this.axiosInstance, void 0, this.logger);
2844
3441
  this.oauth = new OAuthResource(this.axiosInstance, void 0, this.logger);
2845
3442
  this.fields = new FieldsResource(this.axiosInstance, this.defaultAccountId, this.logger);
3443
+ this.envelopes = new EnvelopeResource(this.axiosInstance, this.defaultAccountId, this.logger);
3444
+ this.embed = new EmbedResource(this.axiosInstance, this.defaultAccountId, this.logger);
2846
3445
  this.users = new UsersResource(this.axiosInstance, void 0, this.logger);
2847
3446
  this.signerDocuments = new SignerDocumentsResource(
2848
3447
  this.axiosInstance,
@@ -2888,6 +3487,7 @@ var AssinafyClient = class _AssinafyClient {
2888
3487
  throw new ValidationError("At least one signer is required");
2889
3488
  }
2890
3489
  if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
3490
+ validateCreditCeiling(options.maxTotalCredits);
2891
3491
  const preparedSigners = options.signers.map((signer) => {
2892
3492
  if (!signer || typeof signer !== "object") {
2893
3493
  throw new ValidationError("Each signer must be an object");
@@ -2904,7 +3504,9 @@ var AssinafyClient = class _AssinafyClient {
2904
3504
  const reference = {
2905
3505
  verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
2906
3506
  notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
2907
- step: signer.step
3507
+ step: signer.step,
3508
+ embedded: signer.embedded,
3509
+ sign_as: signer.sign_as
2908
3510
  };
2909
3511
  validateSignerOptions(reference);
2910
3512
  return { reference, payload };
@@ -2933,7 +3535,8 @@ var AssinafyClient = class _AssinafyClient {
2933
3535
  }
2934
3536
  const assignmentPayload = {
2935
3537
  method: "virtual",
2936
- signers: assignmentSigners
3538
+ signers: assignmentSigners,
3539
+ max_total_credits: options.maxTotalCredits
2937
3540
  };
2938
3541
  if (options.message !== void 0) assignmentPayload.message = options.message;
2939
3542
  if (options.expiresAt !== void 0) assignmentPayload.expires_at = options.expiresAt;
@@ -2969,11 +3572,16 @@ var AssinafyClient = class _AssinafyClient {
2969
3572
  AuthenticationResource,
2970
3573
  ContractResource,
2971
3574
  DocumentResource,
3575
+ EmbedResource,
3576
+ EnvelopeResource,
2972
3577
  FieldsResource,
2973
3578
  NOTIFICATION_PREFERENCE_CODES,
2974
3579
  NetworkError,
2975
3580
  OAuthResource,
3581
+ PUSH_PREFERENCE_CODES,
2976
3582
  PartialWorkflowError,
3583
+ SIGNER_CAPACITIES,
3584
+ ScheduledSendResource,
2977
3585
  SignerDocumentsResource,
2978
3586
  SignerResource,
2979
3587
  TagResource,