@assinafy/cli 2.8.0 → 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 (37) hide show
  1. package/README.en.md +61 -59
  2. package/README.md +29 -23
  3. package/THIRD_PARTY_NOTICES.md +8 -8
  4. package/dist/api.cjs +199 -47
  5. package/dist/api.cjs.map +1 -1
  6. package/dist/api.js +197 -47
  7. package/dist/api.js.map +1 -1
  8. package/dist/cli.cjs +1388 -532
  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/documents.d.ts +5 -1
  16. package/dist/types/api/resources/documents.d.ts.map +1 -1
  17. package/dist/types/api/resources/envelopes.d.ts +7 -1
  18. package/dist/types/api/resources/envelopes.d.ts.map +1 -1
  19. package/dist/types/api/resources/scheduled-sends.d.ts +11 -0
  20. package/dist/types/api/resources/scheduled-sends.d.ts.map +1 -0
  21. package/dist/types/api/types.d.ts +35 -1
  22. package/dist/types/api/types.d.ts.map +1 -1
  23. package/dist/types/api/utils.d.ts +3 -0
  24. package/dist/types/api/utils.d.ts.map +1 -1
  25. package/docs/README.md +2 -0
  26. package/docs/api-operations-staging.json +1262 -0
  27. package/docs/api-operations.json +1 -1
  28. package/docs/api-reference-staging.md +18466 -0
  29. package/docs/api-reference.md +34 -7
  30. package/docs/assignments.md +46 -0
  31. package/docs/documents.md +31 -0
  32. package/docs/envelopes.md +29 -0
  33. package/docs/scheduled-sends.md +63 -0
  34. package/docs/sdk-reference.md +64 -2
  35. package/install.ps1 +1 -1
  36. package/install.sh +1 -1
  37. 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 (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
+ }
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");
@@ -1035,6 +1137,25 @@ var FAILED_STATUSES = /* @__PURE__ */ new Set([
1035
1137
  "expired"
1036
1138
  ]);
1037
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
+ }
1038
1159
  /**
1039
1160
  * Upload a PDF to the workspace.
1040
1161
  *
@@ -1565,6 +1686,26 @@ function validateOrigin(value) {
1565
1686
 
1566
1687
  // src/api/resources/envelopes.ts
1567
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
+ }
1568
1709
  async list(params = {}, accountId) {
1569
1710
  const id = this.accountId(accountId);
1570
1711
  if (params.status !== void 0 && !["open", "closed"].includes(params.status))
@@ -2064,6 +2205,35 @@ function httpsUrl(value, name) {
2064
2205
  return url;
2065
2206
  }
2066
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
+
2067
2237
  // src/api/resources/signer-documents.ts
2068
2238
  var SignerDocumentsResource = class extends BaseResource {
2069
2239
  /** `GET /signers/{signer_id}/document?signer-access-code=…` */
@@ -2670,33 +2840,6 @@ var TemplateResource = class extends BaseResource {
2670
2840
  }
2671
2841
  };
2672
2842
 
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
2843
  // src/api/resources/users.ts
2701
2844
  var UsersResource = class extends BaseResource {
2702
2845
  /** Fetch the authenticated user's profile. */
@@ -3211,6 +3354,7 @@ var AssinafyClient = class _AssinafyClient {
3211
3354
  contracts;
3212
3355
  signers;
3213
3356
  workspaces;
3357
+ scheduledSends;
3214
3358
  assignments;
3215
3359
  webhooks;
3216
3360
  templates;
@@ -3285,6 +3429,11 @@ var AssinafyClient = class _AssinafyClient {
3285
3429
  this.defaultAccountId,
3286
3430
  this.logger
3287
3431
  );
3432
+ this.scheduledSends = new ScheduledSendResource(
3433
+ this.axiosInstance,
3434
+ this.defaultAccountId,
3435
+ this.logger
3436
+ );
3288
3437
  this.webhooks = new WebhookResource(this.axiosInstance, this.defaultAccountId, this.logger);
3289
3438
  this.templates = new TemplateResource(this.axiosInstance, this.defaultAccountId, this.logger);
3290
3439
  this.tags = new TagResource(this.axiosInstance, this.defaultAccountId, this.logger);
@@ -3356,7 +3505,8 @@ var AssinafyClient = class _AssinafyClient {
3356
3505
  verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
3357
3506
  notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
3358
3507
  step: signer.step,
3359
- embedded: signer.embedded
3508
+ embedded: signer.embedded,
3509
+ sign_as: signer.sign_as
3360
3510
  };
3361
3511
  validateSignerOptions(reference);
3362
3512
  return { reference, payload };
@@ -3430,6 +3580,8 @@ var AssinafyClient = class _AssinafyClient {
3430
3580
  OAuthResource,
3431
3581
  PUSH_PREFERENCE_CODES,
3432
3582
  PartialWorkflowError,
3583
+ SIGNER_CAPACITIES,
3584
+ ScheduledSendResource,
3433
3585
  SignerDocumentsResource,
3434
3586
  SignerResource,
3435
3587
  TagResource,