@assinafy/cli 2.8.0 → 2.10.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 (40) hide show
  1. package/README.en.md +70 -67
  2. package/README.md +28 -24
  3. package/THIRD_PARTY_NOTICES.md +9 -9
  4. package/dist/api.cjs +204 -55
  5. package/dist/api.cjs.map +1 -1
  6. package/dist/api.js +202 -55
  7. package/dist/api.js.map +1 -1
  8. package/dist/cli.cjs +1413 -559
  9. package/dist/types/api/client.d.ts +2 -0
  10. package/dist/types/api/client.d.ts.map +1 -1
  11. package/dist/types/api/index.d.ts +1 -0
  12. package/dist/types/api/index.d.ts.map +1 -1
  13. package/dist/types/api/resources/assignments.d.ts +7 -1
  14. package/dist/types/api/resources/assignments.d.ts.map +1 -1
  15. package/dist/types/api/resources/authentication.d.ts +1 -3
  16. package/dist/types/api/resources/authentication.d.ts.map +1 -1
  17. package/dist/types/api/resources/documents.d.ts +7 -1
  18. package/dist/types/api/resources/documents.d.ts.map +1 -1
  19. package/dist/types/api/resources/envelopes.d.ts +7 -1
  20. package/dist/types/api/resources/envelopes.d.ts.map +1 -1
  21. package/dist/types/api/resources/scheduled-sends.d.ts +11 -0
  22. package/dist/types/api/resources/scheduled-sends.d.ts.map +1 -0
  23. package/dist/types/api/types.d.ts +36 -2
  24. package/dist/types/api/types.d.ts.map +1 -1
  25. package/dist/types/api/utils.d.ts +3 -0
  26. package/dist/types/api/utils.d.ts.map +1 -1
  27. package/docs/README.md +3 -1
  28. package/docs/api-operations-staging.json +1262 -0
  29. package/docs/api-operations.json +89 -1
  30. package/docs/api-reference-staging.md +18466 -0
  31. package/docs/api-reference.md +1830 -323
  32. package/docs/assignments.md +46 -0
  33. package/docs/auth.md +3 -16
  34. package/docs/documents.md +47 -0
  35. package/docs/envelopes.md +29 -0
  36. package/docs/scheduled-sends.md +63 -0
  37. package/docs/sdk-reference.md +66 -4
  38. package/install.ps1 +1 -1
  39. package/install.sh +1 -1
  40. package/package.json +4 -4
package/dist/api.cjs CHANGED
@@ -45,6 +45,8 @@ __export(api_exports, {
45
45
  OAuthResource: () => OAuthResource,
46
46
  PUSH_PREFERENCE_CODES: () => PUSH_PREFERENCE_CODES,
47
47
  PartialWorkflowError: () => PartialWorkflowError,
48
+ SIGNER_CAPACITIES: () => SIGNER_CAPACITIES,
49
+ ScheduledSendResource: () => ScheduledSendResource,
48
50
  SignerDocumentsResource: () => SignerDocumentsResource,
49
51
  SignerResource: () => SignerResource,
50
52
  TagResource: () => TagResource,
@@ -151,6 +153,60 @@ var PartialWorkflowError = class extends AssinafyError {
151
153
  // src/api/utils.ts
152
154
  var import_node_http = require("http");
153
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
154
210
  var DOCUMENT_ARTIFACT_NAMES = [
155
211
  "original",
156
212
  "certificated",
@@ -261,6 +317,16 @@ function requireExpiration(value, name = "expires_at") {
261
317
  requireIso8601(timestamp, name);
262
318
  return value;
263
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
+ }
264
330
  function requireEmail(value) {
265
331
  if (!value || !EMAIL_RE.test(value)) {
266
332
  throw new ValidationError("Invalid email address", { email: value });
@@ -268,6 +334,9 @@ function requireEmail(value) {
268
334
  return value;
269
335
  }
270
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
+ }
271
340
  if (input.embedded !== void 0 && typeof input.embedded !== "boolean") {
272
341
  throw new ValidationError("embedded must be a boolean");
273
342
  }
@@ -466,7 +535,7 @@ var BaseResource = class {
466
535
  }
467
536
  };
468
537
  function safeIdentifier(value, name) {
469
- if (value === "." || value === ".." || /[\s/?#\\%]/.test(value)) {
538
+ if (typeof value !== "string" || value === "." || value === ".." || /[\s/?#\\%]/.test(value)) {
470
539
  throw new ValidationError(`${name} contains invalid URL characters`);
471
540
  }
472
541
  return value;
@@ -501,11 +570,15 @@ function toInt(value) {
501
570
 
502
571
  // src/api/resources/assignments.ts
503
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
+ }
504
576
  if (payload.method !== void 0 && payload.method !== "virtual" && payload.method !== "collect") {
505
577
  throw new ValidationError("method must be virtual or collect");
506
578
  }
507
579
  const signers = extractSignerRefs(payload);
508
580
  validateCreditCeiling(payload.max_total_credits);
581
+ if (payload.expires_at != null) requireScheduledTime(payload.expires_at, "expires_at");
509
582
  if (signers.length === 0) {
510
583
  throw new ValidationError("At least one signer is required", {
511
584
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
@@ -520,15 +593,17 @@ function buildAssignmentPayload(payload, options = {}) {
520
593
  if (!options.skipDigitalCertificateStepValidation) {
521
594
  validateSigningSteps(normalisedSigners);
522
595
  }
523
- return stripEmpty({
524
- method,
525
- signers: normalisedSigners,
526
- message: payload.message,
527
- expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
528
- copy_receivers: payload.copy_receivers,
529
- entries: payload.entries,
530
- max_total_credits: payload.max_total_credits
531
- });
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
+ );
532
607
  }
533
608
  function extractSignerRefs(payload) {
534
609
  const populatedAliases = [payload.signers, payload.signer_ids, payload.signerIds].filter(
@@ -545,21 +620,24 @@ function extractSignerRefs(payload) {
545
620
  }
546
621
  function normaliseSignerRef(ref, options) {
547
622
  if (typeof ref === "string") {
548
- if (!ref) throw new ValidationError("Signer ID cannot be empty");
623
+ if (!ref.trim()) throw new ValidationError("Signer ID cannot be empty");
549
624
  return { id: ref };
550
625
  }
551
626
  if (ref && typeof ref === "object") {
552
627
  const input = ref;
553
628
  const id = input.id ?? input.signer_id;
554
629
  validateSignerOptions(input);
555
- const normalised = stripEmpty({
556
- id,
557
- verification_method: input.verification_method,
558
- notification_methods: input.notification_methods,
559
- step: input.step,
560
- embedded: input.embedded
561
- });
562
- 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) {
563
641
  return normalised;
564
642
  }
565
643
  if (options.allowSignersWithoutId && Object.keys(normalised).length > 0) {
@@ -572,6 +650,30 @@ function normaliseSignerRef(ref, options) {
572
650
  throw new ValidationError("Invalid signer reference", { ref });
573
651
  }
574
652
  var AssignmentResource = class extends BaseResource {
653
+ /** Keep a request for later; no invitation or charge until the server sends it. */
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
+ }
575
677
  /** Fetch an account review and available evidence for a signer's identity verification. */
576
678
  async getIdentityVerification(documentId, assignmentId, signerId) {
577
679
  const docId = this.requireId(documentId, "Document ID");
@@ -813,14 +915,6 @@ var AuthenticationResource = class extends BaseResource {
813
915
  () => this.http.post("/auth/link-social-login", payload)
814
916
  );
815
917
  }
816
- /** `POST /users/api-keys` — generate (and rotate) the current user's API key. */
817
- async createApiKey(password) {
818
- if (!password) throw new ValidationError("password is required");
819
- return this.call(
820
- "Failed to create API key",
821
- () => this.http.post("/users/api-keys", { password })
822
- );
823
- }
824
918
  /**
825
919
  * `GET /users/api-keys` — fetch a masked version of the current API key, or
826
920
  * `null` if no key has been generated yet.
@@ -1035,6 +1129,25 @@ var FAILED_STATUSES = /* @__PURE__ */ new Set([
1035
1129
  "expired"
1036
1130
  ]);
1037
1131
  var DocumentResource = class extends BaseResource {
1132
+ /** Read contacts who receive a completion email without document access. */
1133
+ async listWatchers(documentId) {
1134
+ const id = this.requireId(documentId, "Document ID");
1135
+ return this.call(
1136
+ "Failed to list document watchers",
1137
+ () => this.http.get(`/documents/${id}/watchers`)
1138
+ );
1139
+ }
1140
+ /** Replace all watchers; an empty list clears them. Owner credentials required. */
1141
+ async setWatchers(documentId, watcherIds) {
1142
+ const id = this.requireId(documentId, "Document ID");
1143
+ if (!Array.isArray(watcherIds) || new Set(watcherIds).size > 10 || watcherIds.some((value) => typeof value !== "string" || !value.trim())) {
1144
+ throw new ValidationError("watcher_ids must contain at most 10 nonblank contact IDs");
1145
+ }
1146
+ return this.call(
1147
+ "Failed to set document watchers",
1148
+ () => this.http.put(`/documents/${id}/watchers`, { watcher_ids: watcherIds })
1149
+ );
1150
+ }
1038
1151
  /**
1039
1152
  * Upload a PDF to the workspace.
1040
1153
  *
@@ -1239,6 +1352,11 @@ var DocumentResource = class extends BaseResource {
1239
1352
  const id = this.requireId(documentId, "Document ID");
1240
1353
  return this.call("Failed to delete document", () => this.http.delete(`/documents/${id}`));
1241
1354
  }
1355
+ /** Cancel an open document while retaining its files and history. */
1356
+ async cancel(documentId) {
1357
+ const id = this.requireId(documentId, "Document ID");
1358
+ return this.call("Failed to cancel document", () => this.http.put(`/documents/${id}/cancel`));
1359
+ }
1242
1360
  /** List the tags attached to a document. */
1243
1361
  async listTags(documentId, accountId) {
1244
1362
  const accId = this.accountId(accountId);
@@ -1565,6 +1683,26 @@ function validateOrigin(value) {
1565
1683
 
1566
1684
  // src/api/resources/envelopes.ts
1567
1685
  var EnvelopeResource = class extends BaseResource {
1686
+ /** Schedule one envelope request; idempotency headers are not supported here. */
1687
+ async schedule(payload, accountId) {
1688
+ const id = this.accountId(accountId);
1689
+ validateCreate(payload);
1690
+ requireScheduledTime(payload.send_at);
1691
+ return this.call(
1692
+ "Failed to schedule envelope",
1693
+ () => this.http.post(`/accounts/${id}/scheduled-sends`, payload)
1694
+ );
1695
+ }
1696
+ /** Estimate one reminder for the whole envelope without sending or charging. */
1697
+ async estimateResendCost(envelopeId, signerId, accountId) {
1698
+ const id = this.accountId(accountId);
1699
+ const eid = this.requireId(envelopeId, "Envelope ID");
1700
+ const sid = this.requireId(signerId, "Signer ID");
1701
+ return this.call(
1702
+ "Failed to estimate envelope reminder cost",
1703
+ () => this.http.post(`/accounts/${id}/envelopes/${eid}/signers/${sid}/estimate-resend-cost`)
1704
+ );
1705
+ }
1568
1706
  async list(params = {}, accountId) {
1569
1707
  const id = this.accountId(accountId);
1570
1708
  if (params.status !== void 0 && !["open", "closed"].includes(params.status))
@@ -2064,6 +2202,35 @@ function httpsUrl(value, name) {
2064
2202
  return url;
2065
2203
  }
2066
2204
 
2205
+ // src/api/resources/scheduled-sends.ts
2206
+ var ScheduledSendResource = class extends BaseResource {
2207
+ async list(params = {}, accountId) {
2208
+ const id = this.accountId(accountId);
2209
+ return this.callList(
2210
+ "Failed to list scheduled sends",
2211
+ () => this.http.get(`/accounts/${id}/scheduled-sends`, { params: cleanParams({ ...params }) })
2212
+ );
2213
+ }
2214
+ /** Cancel only a pending request; nothing is sent or charged. */
2215
+ async cancel(scheduledSendId, accountId) {
2216
+ const id = this.accountId(accountId);
2217
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2218
+ return this.call(
2219
+ "Failed to cancel scheduled send",
2220
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/cancel`)
2221
+ );
2222
+ }
2223
+ /** Execute a pending request now, sending invitations and charging its current cost. */
2224
+ async send(scheduledSendId, accountId) {
2225
+ const id = this.accountId(accountId);
2226
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2227
+ return this.call(
2228
+ "Failed to send scheduled request",
2229
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/send`)
2230
+ );
2231
+ }
2232
+ };
2233
+
2067
2234
  // src/api/resources/signer-documents.ts
2068
2235
  var SignerDocumentsResource = class extends BaseResource {
2069
2236
  /** `GET /signers/{signer_id}/document?signer-access-code=…` */
@@ -2670,33 +2837,6 @@ var TemplateResource = class extends BaseResource {
2670
2837
  }
2671
2838
  };
2672
2839
 
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
- ];
2684
- var NOTIFICATION_PREFERENCE_CODES = [
2685
- "DocumentCompleted",
2686
- "SignerDeclined",
2687
- "DocumentCancelled",
2688
- "DocumentAboutToExpire",
2689
- "DocumentExpired",
2690
- "DocumentExpirationReset",
2691
- "DocumentProcessingFailed",
2692
- "TemplateProcessingFailed",
2693
- "SignerWhatsappFailed",
2694
- "ContractRenewalNotice",
2695
- "ContractExpiring",
2696
- "ContractExpired",
2697
- "ContractRenewed"
2698
- ];
2699
-
2700
2840
  // src/api/resources/users.ts
2701
2841
  var UsersResource = class extends BaseResource {
2702
2842
  /** Fetch the authenticated user's profile. */
@@ -3211,6 +3351,7 @@ var AssinafyClient = class _AssinafyClient {
3211
3351
  contracts;
3212
3352
  signers;
3213
3353
  workspaces;
3354
+ scheduledSends;
3214
3355
  assignments;
3215
3356
  webhooks;
3216
3357
  templates;
@@ -3285,6 +3426,11 @@ var AssinafyClient = class _AssinafyClient {
3285
3426
  this.defaultAccountId,
3286
3427
  this.logger
3287
3428
  );
3429
+ this.scheduledSends = new ScheduledSendResource(
3430
+ this.axiosInstance,
3431
+ this.defaultAccountId,
3432
+ this.logger
3433
+ );
3288
3434
  this.webhooks = new WebhookResource(this.axiosInstance, this.defaultAccountId, this.logger);
3289
3435
  this.templates = new TemplateResource(this.axiosInstance, this.defaultAccountId, this.logger);
3290
3436
  this.tags = new TagResource(this.axiosInstance, this.defaultAccountId, this.logger);
@@ -3356,7 +3502,8 @@ var AssinafyClient = class _AssinafyClient {
3356
3502
  verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
3357
3503
  notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
3358
3504
  step: signer.step,
3359
- embedded: signer.embedded
3505
+ embedded: signer.embedded,
3506
+ sign_as: signer.sign_as
3360
3507
  };
3361
3508
  validateSignerOptions(reference);
3362
3509
  return { reference, payload };
@@ -3430,6 +3577,8 @@ var AssinafyClient = class _AssinafyClient {
3430
3577
  OAuthResource,
3431
3578
  PUSH_PREFERENCE_CODES,
3432
3579
  PartialWorkflowError,
3580
+ SIGNER_CAPACITIES,
3581
+ ScheduledSendResource,
3433
3582
  SignerDocumentsResource,
3434
3583
  SignerResource,
3435
3584
  TagResource,