@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.js CHANGED
@@ -88,6 +88,60 @@ var PartialWorkflowError = class extends AssinafyError {
88
88
  // src/api/utils.ts
89
89
  import { validateHeaderValue } from "http";
90
90
  import axios from "axios";
91
+
92
+ // src/api/types.ts
93
+ var SIGNER_CAPACITIES = [
94
+ "Sign",
95
+ "Approve",
96
+ "Acknowledge",
97
+ "Party",
98
+ "Witness",
99
+ "Intervening",
100
+ "Receipt",
101
+ "IssuerEndorserGuarantor",
102
+ "IssuerEndorserGuarantorSurety",
103
+ "Surety",
104
+ "PartySurety",
105
+ "JointDebtor",
106
+ "PartyJointDebtor",
107
+ "ContractingParty",
108
+ "ContractedParty",
109
+ "Landlord",
110
+ "Tenant",
111
+ "Buyer",
112
+ "Seller",
113
+ "AttorneyInFact",
114
+ "LegalRepresentative",
115
+ "Employer",
116
+ "Employee"
117
+ ];
118
+ var PUSH_PREFERENCE_CODES = [
119
+ "SignerViewed",
120
+ "SignerSigned",
121
+ "DocumentCompleted",
122
+ "SignerDeclined",
123
+ "DocumentAboutToExpire",
124
+ "DocumentExpired",
125
+ "SignerIdentityReviewRequired",
126
+ "SignerWhatsappFailed"
127
+ ];
128
+ var NOTIFICATION_PREFERENCE_CODES = [
129
+ "DocumentCompleted",
130
+ "SignerDeclined",
131
+ "DocumentCancelled",
132
+ "DocumentAboutToExpire",
133
+ "DocumentExpired",
134
+ "DocumentExpirationReset",
135
+ "DocumentProcessingFailed",
136
+ "TemplateProcessingFailed",
137
+ "SignerWhatsappFailed",
138
+ "ContractRenewalNotice",
139
+ "ContractExpiring",
140
+ "ContractExpired",
141
+ "ContractRenewed"
142
+ ];
143
+
144
+ // src/api/utils.ts
91
145
  var DOCUMENT_ARTIFACT_NAMES = [
92
146
  "original",
93
147
  "certificated",
@@ -198,6 +252,16 @@ function requireExpiration(value, name = "expires_at") {
198
252
  requireIso8601(timestamp, name);
199
253
  return value;
200
254
  }
255
+ function requireScheduledTime(value, name = "send_at") {
256
+ if (typeof value === "number") {
257
+ if (!Number.isSafeInteger(value))
258
+ throw new ValidationError(`${name} must be an integer Unix time`);
259
+ } else if (typeof value === "string") {
260
+ requireExpiration(value, name);
261
+ } else {
262
+ throw new ValidationError(`${name} must be an ISO 8601 time or integer Unix time`);
263
+ }
264
+ }
201
265
  function requireEmail(value) {
202
266
  if (!value || !EMAIL_RE.test(value)) {
203
267
  throw new ValidationError("Invalid email address", { email: value });
@@ -205,6 +269,9 @@ function requireEmail(value) {
205
269
  return value;
206
270
  }
207
271
  function validateSignerOptions(input) {
272
+ if (input.sign_as != null && !SIGNER_CAPACITIES.includes(input.sign_as)) {
273
+ throw new ValidationError("sign_as must be a published signer capacity or null");
274
+ }
208
275
  if (input.embedded !== void 0 && typeof input.embedded !== "boolean") {
209
276
  throw new ValidationError("embedded must be a boolean");
210
277
  }
@@ -403,7 +470,7 @@ var BaseResource = class {
403
470
  }
404
471
  };
405
472
  function safeIdentifier(value, name) {
406
- if (value === "." || value === ".." || /[\s/?#\\%]/.test(value)) {
473
+ if (typeof value !== "string" || value === "." || value === ".." || /[\s/?#\\%]/.test(value)) {
407
474
  throw new ValidationError(`${name} contains invalid URL characters`);
408
475
  }
409
476
  return value;
@@ -438,11 +505,15 @@ function toInt(value) {
438
505
 
439
506
  // src/api/resources/assignments.ts
440
507
  function buildAssignmentPayload(payload, options = {}) {
508
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
509
+ throw new ValidationError("Assignment payload must be an object");
510
+ }
441
511
  if (payload.method !== void 0 && payload.method !== "virtual" && payload.method !== "collect") {
442
512
  throw new ValidationError("method must be virtual or collect");
443
513
  }
444
514
  const signers = extractSignerRefs(payload);
445
515
  validateCreditCeiling(payload.max_total_credits);
516
+ if (payload.expires_at != null) requireScheduledTime(payload.expires_at, "expires_at");
446
517
  if (signers.length === 0) {
447
518
  throw new ValidationError("At least one signer is required", {
448
519
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
@@ -457,15 +528,17 @@ function buildAssignmentPayload(payload, options = {}) {
457
528
  if (!options.skipDigitalCertificateStepValidation) {
458
529
  validateSigningSteps(normalisedSigners);
459
530
  }
460
- return stripEmpty({
461
- method,
462
- signers: normalisedSigners,
463
- message: payload.message,
464
- expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
465
- copy_receivers: payload.copy_receivers,
466
- entries: payload.entries,
467
- max_total_credits: payload.max_total_credits
468
- });
531
+ return Object.fromEntries(
532
+ Object.entries({
533
+ method,
534
+ signers: normalisedSigners,
535
+ message: payload.message,
536
+ expires_at: payload.expires_at,
537
+ copy_receivers: payload.copy_receivers,
538
+ entries: payload.entries,
539
+ max_total_credits: payload.max_total_credits
540
+ }).filter(([, value]) => value !== void 0)
541
+ );
469
542
  }
470
543
  function extractSignerRefs(payload) {
471
544
  const populatedAliases = [payload.signers, payload.signer_ids, payload.signerIds].filter(
@@ -482,21 +555,24 @@ function extractSignerRefs(payload) {
482
555
  }
483
556
  function normaliseSignerRef(ref, options) {
484
557
  if (typeof ref === "string") {
485
- if (!ref) throw new ValidationError("Signer ID cannot be empty");
558
+ if (!ref.trim()) throw new ValidationError("Signer ID cannot be empty");
486
559
  return { id: ref };
487
560
  }
488
561
  if (ref && typeof ref === "object") {
489
562
  const input = ref;
490
563
  const id = input.id ?? input.signer_id;
491
564
  validateSignerOptions(input);
492
- const normalised = stripEmpty({
493
- id,
494
- verification_method: input.verification_method,
495
- notification_methods: input.notification_methods,
496
- step: input.step,
497
- embedded: input.embedded
498
- });
499
- if (typeof id === "string" && id.length > 0) {
565
+ const normalised = Object.fromEntries(
566
+ Object.entries({
567
+ id,
568
+ sign_as: input.sign_as,
569
+ verification_method: input.verification_method,
570
+ notification_methods: input.notification_methods,
571
+ step: input.step,
572
+ embedded: input.embedded
573
+ }).filter(([, value]) => value !== void 0)
574
+ );
575
+ if (typeof id === "string" && id.trim().length > 0) {
500
576
  return normalised;
501
577
  }
502
578
  if (options.allowSignersWithoutId && Object.keys(normalised).length > 0) {
@@ -509,6 +585,30 @@ function normaliseSignerRef(ref, options) {
509
585
  throw new ValidationError("Invalid signer reference", { ref });
510
586
  }
511
587
  var AssignmentResource = class extends BaseResource {
588
+ /** Keep a request for later; no invitation or charge until the server sends it (staging). */
589
+ async schedule(documentId, payload) {
590
+ const id = this.requireId(documentId, "Document ID");
591
+ requireScheduledTime(payload?.send_at);
592
+ const body = { ...buildAssignmentPayload(payload), send_at: payload.send_at };
593
+ return this.call(
594
+ "Failed to schedule assignment",
595
+ () => this.http.post(`/documents/${id}/scheduled-sends`, body)
596
+ );
597
+ }
598
+ async signerCapacities(documentId) {
599
+ const id = this.requireId(documentId, "Document ID");
600
+ return this.call(
601
+ "Failed to fetch signer capacities",
602
+ () => this.http.get(`/documents/${id}/signer-capacities`)
603
+ );
604
+ }
605
+ async notificationHistory(documentId) {
606
+ const id = this.requireId(documentId, "Document ID");
607
+ return this.call(
608
+ "Failed to fetch notification history",
609
+ () => this.http.get(`/documents/${id}/notification-history`)
610
+ );
611
+ }
512
612
  /** Fetch an account review and available evidence for a signer's identity verification. */
513
613
  async getIdentityVerification(documentId, assignmentId, signerId) {
514
614
  const docId = this.requireId(documentId, "Document ID");
@@ -972,6 +1072,25 @@ var FAILED_STATUSES = /* @__PURE__ */ new Set([
972
1072
  "expired"
973
1073
  ]);
974
1074
  var DocumentResource = class extends BaseResource {
1075
+ /** Read contacts who receive a completion email without document access (staging). */
1076
+ async listWatchers(documentId) {
1077
+ const id = this.requireId(documentId, "Document ID");
1078
+ return this.call(
1079
+ "Failed to list document watchers",
1080
+ () => this.http.get(`/documents/${id}/watchers`)
1081
+ );
1082
+ }
1083
+ /** Replace all watchers; an empty list clears them. Owner credentials required (staging). */
1084
+ async setWatchers(documentId, watcherIds) {
1085
+ const id = this.requireId(documentId, "Document ID");
1086
+ if (!Array.isArray(watcherIds) || new Set(watcherIds).size > 10 || watcherIds.some((value) => typeof value !== "string" || !value.trim())) {
1087
+ throw new ValidationError("watcher_ids must contain at most 10 nonblank contact IDs");
1088
+ }
1089
+ return this.call(
1090
+ "Failed to set document watchers",
1091
+ () => this.http.put(`/documents/${id}/watchers`, { watcher_ids: watcherIds })
1092
+ );
1093
+ }
975
1094
  /**
976
1095
  * Upload a PDF to the workspace.
977
1096
  *
@@ -1502,6 +1621,26 @@ function validateOrigin(value) {
1502
1621
 
1503
1622
  // src/api/resources/envelopes.ts
1504
1623
  var EnvelopeResource = class extends BaseResource {
1624
+ /** Schedule one envelope request; idempotency headers are not supported here (staging). */
1625
+ async schedule(payload, accountId) {
1626
+ const id = this.accountId(accountId);
1627
+ validateCreate(payload);
1628
+ requireScheduledTime(payload.send_at);
1629
+ return this.call(
1630
+ "Failed to schedule envelope",
1631
+ () => this.http.post(`/accounts/${id}/scheduled-sends`, payload)
1632
+ );
1633
+ }
1634
+ /** Estimate one reminder for the whole envelope without sending or charging (staging). */
1635
+ async estimateResendCost(envelopeId, signerId, accountId) {
1636
+ const id = this.accountId(accountId);
1637
+ const eid = this.requireId(envelopeId, "Envelope ID");
1638
+ const sid = this.requireId(signerId, "Signer ID");
1639
+ return this.call(
1640
+ "Failed to estimate envelope reminder cost",
1641
+ () => this.http.post(`/accounts/${id}/envelopes/${eid}/signers/${sid}/estimate-resend-cost`)
1642
+ );
1643
+ }
1505
1644
  async list(params = {}, accountId) {
1506
1645
  const id = this.accountId(accountId);
1507
1646
  if (params.status !== void 0 && !["open", "closed"].includes(params.status))
@@ -2001,6 +2140,35 @@ function httpsUrl(value, name) {
2001
2140
  return url;
2002
2141
  }
2003
2142
 
2143
+ // src/api/resources/scheduled-sends.ts
2144
+ var ScheduledSendResource = class extends BaseResource {
2145
+ async list(params = {}, accountId) {
2146
+ const id = this.accountId(accountId);
2147
+ return this.callList(
2148
+ "Failed to list scheduled sends",
2149
+ () => this.http.get(`/accounts/${id}/scheduled-sends`, { params: cleanParams({ ...params }) })
2150
+ );
2151
+ }
2152
+ /** Cancel only a pending request; nothing is sent or charged. */
2153
+ async cancel(scheduledSendId, accountId) {
2154
+ const id = this.accountId(accountId);
2155
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2156
+ return this.call(
2157
+ "Failed to cancel scheduled send",
2158
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/cancel`)
2159
+ );
2160
+ }
2161
+ /** Execute a pending request now, sending invitations and charging its current cost. */
2162
+ async send(scheduledSendId, accountId) {
2163
+ const id = this.accountId(accountId);
2164
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2165
+ return this.call(
2166
+ "Failed to send scheduled request",
2167
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/send`)
2168
+ );
2169
+ }
2170
+ };
2171
+
2004
2172
  // src/api/resources/signer-documents.ts
2005
2173
  var SignerDocumentsResource = class extends BaseResource {
2006
2174
  /** `GET /signers/{signer_id}/document?signer-access-code=…` */
@@ -2607,33 +2775,6 @@ var TemplateResource = class extends BaseResource {
2607
2775
  }
2608
2776
  };
2609
2777
 
2610
- // src/api/types.ts
2611
- var PUSH_PREFERENCE_CODES = [
2612
- "SignerViewed",
2613
- "SignerSigned",
2614
- "DocumentCompleted",
2615
- "SignerDeclined",
2616
- "DocumentAboutToExpire",
2617
- "DocumentExpired",
2618
- "SignerIdentityReviewRequired",
2619
- "SignerWhatsappFailed"
2620
- ];
2621
- var NOTIFICATION_PREFERENCE_CODES = [
2622
- "DocumentCompleted",
2623
- "SignerDeclined",
2624
- "DocumentCancelled",
2625
- "DocumentAboutToExpire",
2626
- "DocumentExpired",
2627
- "DocumentExpirationReset",
2628
- "DocumentProcessingFailed",
2629
- "TemplateProcessingFailed",
2630
- "SignerWhatsappFailed",
2631
- "ContractRenewalNotice",
2632
- "ContractExpiring",
2633
- "ContractExpired",
2634
- "ContractRenewed"
2635
- ];
2636
-
2637
2778
  // src/api/resources/users.ts
2638
2779
  var UsersResource = class extends BaseResource {
2639
2780
  /** Fetch the authenticated user's profile. */
@@ -3148,6 +3289,7 @@ var AssinafyClient = class _AssinafyClient {
3148
3289
  contracts;
3149
3290
  signers;
3150
3291
  workspaces;
3292
+ scheduledSends;
3151
3293
  assignments;
3152
3294
  webhooks;
3153
3295
  templates;
@@ -3222,6 +3364,11 @@ var AssinafyClient = class _AssinafyClient {
3222
3364
  this.defaultAccountId,
3223
3365
  this.logger
3224
3366
  );
3367
+ this.scheduledSends = new ScheduledSendResource(
3368
+ this.axiosInstance,
3369
+ this.defaultAccountId,
3370
+ this.logger
3371
+ );
3225
3372
  this.webhooks = new WebhookResource(this.axiosInstance, this.defaultAccountId, this.logger);
3226
3373
  this.templates = new TemplateResource(this.axiosInstance, this.defaultAccountId, this.logger);
3227
3374
  this.tags = new TagResource(this.axiosInstance, this.defaultAccountId, this.logger);
@@ -3293,7 +3440,8 @@ var AssinafyClient = class _AssinafyClient {
3293
3440
  verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
3294
3441
  notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
3295
3442
  step: signer.step,
3296
- embedded: signer.embedded
3443
+ embedded: signer.embedded,
3444
+ sign_as: signer.sign_as
3297
3445
  };
3298
3446
  validateSignerOptions(reference);
3299
3447
  return { reference, payload };
@@ -3366,6 +3514,8 @@ export {
3366
3514
  OAuthResource,
3367
3515
  PUSH_PREFERENCE_CODES,
3368
3516
  PartialWorkflowError,
3517
+ SIGNER_CAPACITIES,
3518
+ ScheduledSendResource,
3369
3519
  SignerDocumentsResource,
3370
3520
  SignerResource,
3371
3521
  TagResource,