@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.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. */
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");
@@ -750,14 +850,6 @@ var AuthenticationResource = class extends BaseResource {
750
850
  () => this.http.post("/auth/link-social-login", payload)
751
851
  );
752
852
  }
753
- /** `POST /users/api-keys` — generate (and rotate) the current user's API key. */
754
- async createApiKey(password) {
755
- if (!password) throw new ValidationError("password is required");
756
- return this.call(
757
- "Failed to create API key",
758
- () => this.http.post("/users/api-keys", { password })
759
- );
760
- }
761
853
  /**
762
854
  * `GET /users/api-keys` — fetch a masked version of the current API key, or
763
855
  * `null` if no key has been generated yet.
@@ -972,6 +1064,25 @@ var FAILED_STATUSES = /* @__PURE__ */ new Set([
972
1064
  "expired"
973
1065
  ]);
974
1066
  var DocumentResource = class extends BaseResource {
1067
+ /** Read contacts who receive a completion email without document access. */
1068
+ async listWatchers(documentId) {
1069
+ const id = this.requireId(documentId, "Document ID");
1070
+ return this.call(
1071
+ "Failed to list document watchers",
1072
+ () => this.http.get(`/documents/${id}/watchers`)
1073
+ );
1074
+ }
1075
+ /** Replace all watchers; an empty list clears them. Owner credentials required. */
1076
+ async setWatchers(documentId, watcherIds) {
1077
+ const id = this.requireId(documentId, "Document ID");
1078
+ if (!Array.isArray(watcherIds) || new Set(watcherIds).size > 10 || watcherIds.some((value) => typeof value !== "string" || !value.trim())) {
1079
+ throw new ValidationError("watcher_ids must contain at most 10 nonblank contact IDs");
1080
+ }
1081
+ return this.call(
1082
+ "Failed to set document watchers",
1083
+ () => this.http.put(`/documents/${id}/watchers`, { watcher_ids: watcherIds })
1084
+ );
1085
+ }
975
1086
  /**
976
1087
  * Upload a PDF to the workspace.
977
1088
  *
@@ -1176,6 +1287,11 @@ var DocumentResource = class extends BaseResource {
1176
1287
  const id = this.requireId(documentId, "Document ID");
1177
1288
  return this.call("Failed to delete document", () => this.http.delete(`/documents/${id}`));
1178
1289
  }
1290
+ /** Cancel an open document while retaining its files and history. */
1291
+ async cancel(documentId) {
1292
+ const id = this.requireId(documentId, "Document ID");
1293
+ return this.call("Failed to cancel document", () => this.http.put(`/documents/${id}/cancel`));
1294
+ }
1179
1295
  /** List the tags attached to a document. */
1180
1296
  async listTags(documentId, accountId) {
1181
1297
  const accId = this.accountId(accountId);
@@ -1502,6 +1618,26 @@ function validateOrigin(value) {
1502
1618
 
1503
1619
  // src/api/resources/envelopes.ts
1504
1620
  var EnvelopeResource = class extends BaseResource {
1621
+ /** Schedule one envelope request; idempotency headers are not supported here. */
1622
+ async schedule(payload, accountId) {
1623
+ const id = this.accountId(accountId);
1624
+ validateCreate(payload);
1625
+ requireScheduledTime(payload.send_at);
1626
+ return this.call(
1627
+ "Failed to schedule envelope",
1628
+ () => this.http.post(`/accounts/${id}/scheduled-sends`, payload)
1629
+ );
1630
+ }
1631
+ /** Estimate one reminder for the whole envelope without sending or charging. */
1632
+ async estimateResendCost(envelopeId, signerId, accountId) {
1633
+ const id = this.accountId(accountId);
1634
+ const eid = this.requireId(envelopeId, "Envelope ID");
1635
+ const sid = this.requireId(signerId, "Signer ID");
1636
+ return this.call(
1637
+ "Failed to estimate envelope reminder cost",
1638
+ () => this.http.post(`/accounts/${id}/envelopes/${eid}/signers/${sid}/estimate-resend-cost`)
1639
+ );
1640
+ }
1505
1641
  async list(params = {}, accountId) {
1506
1642
  const id = this.accountId(accountId);
1507
1643
  if (params.status !== void 0 && !["open", "closed"].includes(params.status))
@@ -2001,6 +2137,35 @@ function httpsUrl(value, name) {
2001
2137
  return url;
2002
2138
  }
2003
2139
 
2140
+ // src/api/resources/scheduled-sends.ts
2141
+ var ScheduledSendResource = class extends BaseResource {
2142
+ async list(params = {}, accountId) {
2143
+ const id = this.accountId(accountId);
2144
+ return this.callList(
2145
+ "Failed to list scheduled sends",
2146
+ () => this.http.get(`/accounts/${id}/scheduled-sends`, { params: cleanParams({ ...params }) })
2147
+ );
2148
+ }
2149
+ /** Cancel only a pending request; nothing is sent or charged. */
2150
+ async cancel(scheduledSendId, accountId) {
2151
+ const id = this.accountId(accountId);
2152
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2153
+ return this.call(
2154
+ "Failed to cancel scheduled send",
2155
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/cancel`)
2156
+ );
2157
+ }
2158
+ /** Execute a pending request now, sending invitations and charging its current cost. */
2159
+ async send(scheduledSendId, accountId) {
2160
+ const id = this.accountId(accountId);
2161
+ const sid = this.requireId(scheduledSendId, "Scheduled send ID");
2162
+ return this.call(
2163
+ "Failed to send scheduled request",
2164
+ () => this.http.put(`/accounts/${id}/scheduled-sends/${sid}/send`)
2165
+ );
2166
+ }
2167
+ };
2168
+
2004
2169
  // src/api/resources/signer-documents.ts
2005
2170
  var SignerDocumentsResource = class extends BaseResource {
2006
2171
  /** `GET /signers/{signer_id}/document?signer-access-code=…` */
@@ -2607,33 +2772,6 @@ var TemplateResource = class extends BaseResource {
2607
2772
  }
2608
2773
  };
2609
2774
 
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
2775
  // src/api/resources/users.ts
2638
2776
  var UsersResource = class extends BaseResource {
2639
2777
  /** Fetch the authenticated user's profile. */
@@ -3148,6 +3286,7 @@ var AssinafyClient = class _AssinafyClient {
3148
3286
  contracts;
3149
3287
  signers;
3150
3288
  workspaces;
3289
+ scheduledSends;
3151
3290
  assignments;
3152
3291
  webhooks;
3153
3292
  templates;
@@ -3222,6 +3361,11 @@ var AssinafyClient = class _AssinafyClient {
3222
3361
  this.defaultAccountId,
3223
3362
  this.logger
3224
3363
  );
3364
+ this.scheduledSends = new ScheduledSendResource(
3365
+ this.axiosInstance,
3366
+ this.defaultAccountId,
3367
+ this.logger
3368
+ );
3225
3369
  this.webhooks = new WebhookResource(this.axiosInstance, this.defaultAccountId, this.logger);
3226
3370
  this.templates = new TemplateResource(this.axiosInstance, this.defaultAccountId, this.logger);
3227
3371
  this.tags = new TagResource(this.axiosInstance, this.defaultAccountId, this.logger);
@@ -3293,7 +3437,8 @@ var AssinafyClient = class _AssinafyClient {
3293
3437
  verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
3294
3438
  notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
3295
3439
  step: signer.step,
3296
- embedded: signer.embedded
3440
+ embedded: signer.embedded,
3441
+ sign_as: signer.sign_as
3297
3442
  };
3298
3443
  validateSignerOptions(reference);
3299
3444
  return { reference, payload };
@@ -3366,6 +3511,8 @@ export {
3366
3511
  OAuthResource,
3367
3512
  PUSH_PREFERENCE_CODES,
3368
3513
  PartialWorkflowError,
3514
+ SIGNER_CAPACITIES,
3515
+ ScheduledSendResource,
3369
3516
  SignerDocumentsResource,
3370
3517
  SignerResource,
3371
3518
  TagResource,