@assinafy/cli 2.6.0 → 2.7.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 (37) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/README.en.md +50 -20
  3. package/README.md +38 -10
  4. package/THIRD_PARTY_NOTICES.md +1 -1
  5. package/dist/api.cjs +235 -34
  6. package/dist/api.cjs.map +1 -1
  7. package/dist/api.js +234 -34
  8. package/dist/api.js.map +1 -1
  9. package/dist/cli.cjs +365 -68
  10. package/dist/types/api/client.d.ts +2 -0
  11. package/dist/types/api/client.d.ts.map +1 -1
  12. package/dist/types/api/contract-types.d.ts +110 -0
  13. package/dist/types/api/contract-types.d.ts.map +1 -0
  14. package/dist/types/api/index.d.ts +2 -0
  15. package/dist/types/api/index.d.ts.map +1 -1
  16. package/dist/types/api/resources/assignments.d.ts +2 -2
  17. package/dist/types/api/resources/assignments.d.ts.map +1 -1
  18. package/dist/types/api/resources/authentication.d.ts +3 -3
  19. package/dist/types/api/resources/authentication.d.ts.map +1 -1
  20. package/dist/types/api/resources/contracts.d.ts +19 -0
  21. package/dist/types/api/resources/contracts.d.ts.map +1 -0
  22. package/dist/types/api/resources/documents.d.ts +4 -3
  23. package/dist/types/api/resources/documents.d.ts.map +1 -1
  24. package/dist/types/api/resources/webhooks.d.ts +4 -3
  25. package/dist/types/api/resources/webhooks.d.ts.map +1 -1
  26. package/dist/types/api/types.d.ts +69 -18
  27. package/dist/types/api/types.d.ts.map +1 -1
  28. package/dist/types/api/utils.d.ts +8 -2
  29. package/dist/types/api/utils.d.ts.map +1 -1
  30. package/docs/README.md +2 -1
  31. package/docs/api-operations.json +49 -1
  32. package/docs/api-reference.md +1454 -295
  33. package/docs/contracts.md +128 -0
  34. package/docs/documents.md +7 -4
  35. package/docs/oauth-guide.md +5 -5
  36. package/docs/sdk-reference.md +156 -15
  37. package/package.json +2 -2
package/dist/api.js CHANGED
@@ -192,6 +192,11 @@ function requireIso8601(value, name = "timestamp") {
192
192
  }
193
193
  return value;
194
194
  }
195
+ function requireExpiration(value, name = "expires_at") {
196
+ const timestamp = /^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T23:59:00Z` : /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(value) ? `${value}Z` : value;
197
+ requireIso8601(timestamp, name);
198
+ return value;
199
+ }
195
200
  function requireEmail(value) {
196
201
  if (!value || !EMAIL_RE.test(value)) {
197
202
  throw new ValidationError("Invalid email address", { email: value });
@@ -225,6 +230,13 @@ function validateSignerOptions(input) {
225
230
  throw new ValidationError("step must be an integer");
226
231
  }
227
232
  }
233
+ function validateDigitalCertificateMethod(method, signers) {
234
+ if (method !== "virtual" && signers.some((signer) => signer.verification_method === "DigitalCertificate")) {
235
+ throw new ValidationError("DigitalCertificate signers require method: virtual", {
236
+ code: "digital_certificate_requires_virtual"
237
+ });
238
+ }
239
+ }
228
240
  function validateSigningSteps(signers) {
229
241
  const withSteps = signers.filter((signer) => signer.step !== void 0);
230
242
  if (withSteps.length > 0) {
@@ -401,18 +413,20 @@ function buildAssignmentPayload(payload, options = {}) {
401
413
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
402
414
  });
403
415
  }
404
- if (payload.method === "collect" && !Array.isArray(payload.entries)) {
416
+ const method = payload.method ?? "virtual";
417
+ const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
418
+ validateDigitalCertificateMethod(method, normalisedSigners);
419
+ if (method === "collect" && !Array.isArray(payload.entries)) {
405
420
  throw new ValidationError("entries are required for collect assignments");
406
421
  }
407
- const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
408
422
  if (!options.skipDigitalCertificateStepValidation) {
409
423
  validateSigningSteps(normalisedSigners);
410
424
  }
411
425
  return stripEmpty({
412
- method: payload.method ?? "virtual",
426
+ method,
413
427
  signers: normalisedSigners,
414
428
  message: payload.message,
415
- expires_at: payload.expires_at === void 0 ? void 0 : requireIso8601(payload.expires_at, "expires_at"),
429
+ expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
416
430
  copy_receivers: payload.copy_receivers,
417
431
  entries: payload.entries
418
432
  });
@@ -550,13 +564,13 @@ var AssignmentResource = class extends BaseResource {
550
564
  }
551
565
  /**
552
566
  * Update the expiration date of an existing assignment.
553
- * The published API accepts an ISO 8601 timestamp. Deployments that support
554
- * clearing an expiration also accept `null`.
567
+ * Accepts an ISO 8601 timestamp, a UTC date/time without an offset, a date
568
+ * (23:59 UTC), or `null` to clear the expiration.
555
569
  */
556
570
  async resetExpiration(documentId, assignmentId, expiresAt) {
557
571
  const docId = this.requireId(documentId, "Document ID");
558
572
  const asgId = this.requireId(assignmentId, "Assignment ID");
559
- if (expiresAt !== null) requireIso8601(expiresAt, "expiresAt");
573
+ if (expiresAt !== null) requireExpiration(expiresAt, "expiresAt");
560
574
  return this.call(
561
575
  "Failed to update assignment expiration",
562
576
  () => this.http.put(`/documents/${docId}/assignments/${asgId}/reset-expiration`, {
@@ -608,7 +622,7 @@ function requireReauth(payload) {
608
622
  return payload;
609
623
  }
610
624
  var AuthenticationResource = class extends BaseResource {
611
- /** `POST /login` — exchange email + password for a JWT access token. */
625
+ /** `POST /login` — return an authenticated session or a two-factor challenge. */
612
626
  async login(email, password) {
613
627
  if (!email) throw new ValidationError("email is required");
614
628
  if (!password) throw new ValidationError("password is required");
@@ -751,6 +765,156 @@ var AuthenticationResource = class extends BaseResource {
751
765
  }
752
766
  };
753
767
 
768
+ // src/api/resources/contracts.ts
769
+ var statuses = ["draft", "active", "expired", "terminated"];
770
+ var ContractResource = class extends BaseResource {
771
+ /** List terms, optionally embedding documents; supports pagination and comma-separated statuses. */
772
+ async list(params = {}, accountId) {
773
+ const id = this.accountId(accountId);
774
+ const status = Array.isArray(params.status) ? params.status.join(",") : params.status;
775
+ if (status !== void 0 && (typeof status !== "string" || status.split(",").some((s) => !statuses.includes(s)))) {
776
+ throw new ValidationError("status must contain draft, active, expired or terminated");
777
+ }
778
+ for (const field of ["end_date_from", "end_date_to"]) {
779
+ if (params[field] !== void 0) requireDate(params[field], field, 0);
780
+ }
781
+ if (params.ending_within_days !== void 0)
782
+ requireInteger(params.ending_within_days, "ending_within_days", 0, 3650);
783
+ requireSort(params.sort, ["end_date", "-end_date", "updated_at", "-updated_at"]);
784
+ if (params.expand !== void 0 && params.expand !== "document")
785
+ throw new ValidationError("expand must be document");
786
+ return this.callList(
787
+ "Failed to list contracts",
788
+ () => this.http.get(`/accounts/${id}/contracts`, { params: cleanParams({ ...params, status }) })
789
+ );
790
+ }
791
+ /** Read a document's own terms or its amendment link. Missing terms return ApiError 404. */
792
+ async get(documentId, accountId) {
793
+ const id = this.accountId(accountId);
794
+ const did = this.requireId(documentId, "Document ID");
795
+ return this.call(
796
+ "Failed to get contract",
797
+ () => this.http.get(`/accounts/${id}/documents/${did}/contract`)
798
+ );
799
+ }
800
+ /** Set only supplied terms, or link/update/unlink a pending amendment. Preserve null clearing. */
801
+ async set(documentId, payload, accountId) {
802
+ const id = this.accountId(accountId);
803
+ const did = this.requireId(documentId, "Document ID");
804
+ requireBody(payload, true);
805
+ validateTerms(payload);
806
+ return this.call(
807
+ "Failed to set contract terms",
808
+ () => this.http.put(`/accounts/${id}/documents/${did}/contract`, payload)
809
+ );
810
+ }
811
+ /** Read the root contract and its amendments from any document in that family. */
812
+ async related(documentId, accountId) {
813
+ const id = this.accountId(accountId);
814
+ const did = this.requireId(documentId, "Document ID");
815
+ return this.call(
816
+ "Failed to get related contracts",
817
+ () => this.http.get(`/accounts/${id}/documents/${did}/contract/related`)
818
+ );
819
+ }
820
+ /** Advance from the supplied current term or to a later end date. No automatic retry. */
821
+ async renew(documentId, payload, accountId) {
822
+ const id = this.accountId(accountId);
823
+ const did = this.requireId(documentId, "Document ID");
824
+ requireBody(payload, true);
825
+ if (payload.term === void 0 && !payload.end_date)
826
+ throw new ValidationError("Renewal requires term or end_date");
827
+ if (payload.term !== void 0)
828
+ requireInteger(payload.term, "term", 1, Number.MAX_SAFE_INTEGER);
829
+ validateTerms({ ...payload, end_date: payload.end_date === "" ? null : payload.end_date });
830
+ return this.call(
831
+ "Failed to renew contract",
832
+ () => this.http.post(`/accounts/${id}/documents/${did}/contract/renew`, payload)
833
+ );
834
+ }
835
+ /** Terminate existing terms; an optional reason is recorded in document activities. */
836
+ async terminate(documentId, payload = {}, accountId) {
837
+ const id = this.accountId(accountId);
838
+ const did = this.requireId(documentId, "Document ID");
839
+ requireBody(payload);
840
+ if (payload.reason != null && (typeof payload.reason !== "string" || [...payload.reason].length > 500))
841
+ throw new ValidationError("reason must be text of at most 500 characters");
842
+ if (payload.updated_at != null) requireIso8601(payload.updated_at, "updated_at");
843
+ return this.call(
844
+ "Failed to terminate contract",
845
+ () => this.http.post(`/accounts/${id}/documents/${did}/contract/terminate`, payload)
846
+ );
847
+ }
848
+ };
849
+ function requireBody(value, nonempty = false) {
850
+ if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
851
+ throw new ValidationError("Contract body must be a JSON object");
852
+ }
853
+ if (nonempty && !Object.values(value).some((v) => v !== void 0))
854
+ throw new ValidationError("At least one contract attribute is required");
855
+ }
856
+ function requireDate(value, field, minYear = 1e3) {
857
+ if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value) || Number(value.slice(0, 4)) < minYear)
858
+ throw new ValidationError(`${field} must be a YYYY-MM-DD date from year ${minYear}`);
859
+ requireIso8601(`${value}T00:00:00Z`, field);
860
+ }
861
+ function requireInteger(value, field, min, max) {
862
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < min || value > max)
863
+ throw new ValidationError(`${field} must be an integer from ${min} to ${max}`);
864
+ }
865
+ function validateTerms(payload) {
866
+ for (const field of ["start_date", "end_date"])
867
+ if (payload[field] != null) requireDate(payload[field], field);
868
+ if (payload.start_date && payload.end_date && payload.end_date < payload.start_date)
869
+ throw new ValidationError("end_date must not precede start_date");
870
+ if (payload.updated_at != null) requireIso8601(payload.updated_at, "updated_at");
871
+ if (payload.status !== void 0 && !statuses.includes(payload.status))
872
+ throw new ValidationError("Invalid contract status");
873
+ if (payload.relation_type !== void 0 && !["amendment", "renewal", "termination"].includes(payload.relation_type))
874
+ throw new ValidationError("Invalid relation_type");
875
+ if (payload.auto_renew != null && typeof payload.auto_renew !== "boolean")
876
+ throw new ValidationError("auto_renew must be boolean or null");
877
+ if (payload.renewal_term_months != null)
878
+ requireInteger(payload.renewal_term_months, "renewal_term_months", 1, 600);
879
+ if (payload.notice_period_days != null)
880
+ requireInteger(payload.notice_period_days, "notice_period_days", 0, 3650);
881
+ if (payload.value != null && (typeof payload.value !== "number" || !Number.isFinite(payload.value) || payload.value < 0 || payload.value > 999999999999999e-2 || Number(payload.value.toFixed(2)) !== payload.value))
882
+ throw new ValidationError(
883
+ "value must be from 0 to 9999999999999.99 with at most two decimal places"
884
+ );
885
+ for (const [field, max] of [
886
+ ["counterparty_name", 255],
887
+ ["counterparty_taxpayer_id", 20],
888
+ ["owner_id", Infinity],
889
+ ["parent_document_id", Infinity]
890
+ ]) {
891
+ const value = payload[field];
892
+ if (value != null && (typeof value !== "string" || [...value].length > max))
893
+ throw new ValidationError(`${field} must be text of at most ${max} characters`);
894
+ }
895
+ if (payload.currency != null && (typeof payload.currency !== "string" || !/^[a-z]{3}$/i.test(payload.currency)))
896
+ throw new ValidationError("currency must be a three-letter code");
897
+ if (payload.metadata != null) {
898
+ requireBody(payload.metadata);
899
+ const entries = Object.entries(payload.metadata);
900
+ if (entries.length > 50 || entries.some(
901
+ ([key, value]) => !/^[a-z\d_.-]{1,40}$/i.test(key) || typeof value !== "string" || [...value].length > 500
902
+ ))
903
+ throw new ValidationError(
904
+ "metadata requires at most 50 valid keys with text values of at most 500 characters"
905
+ );
906
+ }
907
+ if (payload.external_references != null) {
908
+ if (!Array.isArray(payload.external_references) || payload.external_references.length > 20)
909
+ throw new ValidationError("external_references must be a list of at most 20 items");
910
+ for (const reference of payload.external_references) {
911
+ requireBody(reference);
912
+ if (typeof reference.system !== "string" || !/^[a-z\d_.-]{1,64}$/i.test(reference.system) || typeof reference.id !== "string" || !reference.id || [...reference.id].length > 255 || /[\u{10000}-\u{10ffff}]/u.test(reference.id))
913
+ throw new ValidationError("Each external reference requires a valid system and id");
914
+ }
915
+ }
916
+ }
917
+
754
918
  // src/api/resources/documents.ts
755
919
  import { promises as fs } from "fs";
756
920
  import path from "path";
@@ -846,7 +1010,7 @@ var DocumentResource = class extends BaseResource {
846
1010
  if (!name?.trim()) throw new ValidationError("name is required");
847
1011
  return this.call(
848
1012
  "Failed to rename document",
849
- () => this.http.patch(`/documents/${id}`, { name })
1013
+ () => this.http.patch(`/documents/${id}`, { name }, { params: { expand: "assignment" } })
850
1014
  );
851
1015
  }
852
1016
  /** Alias for {@link details}. */
@@ -934,12 +1098,13 @@ var DocumentResource = class extends BaseResource {
934
1098
  })
935
1099
  );
936
1100
  }
937
- /** Fetch the document activity log. */
938
- async activities(documentId) {
1101
+ /** Fetch one page of the document activity log (20 entries by default). */
1102
+ async activities(documentId, params = {}) {
939
1103
  const id = this.requireId(documentId, "Document ID");
1104
+ requireSort(params.sort, ["id", "-id"]);
940
1105
  const result = await this.call(
941
1106
  "Failed to fetch document activities",
942
- () => this.http.get(`/documents/${id}/activities`)
1107
+ () => this.http.get(`/documents/${id}/activities`, { params: cleanParams({ ...params }) })
943
1108
  );
944
1109
  return result ?? [];
945
1110
  }
@@ -1005,14 +1170,15 @@ var DocumentResource = class extends BaseResource {
1005
1170
  async createFromTemplate(templateId, signers, options = {}, accountId) {
1006
1171
  const tmplId = this.requireId(templateId, "Template ID");
1007
1172
  const accId = this.accountId(accountId);
1008
- validateTemplateSigners(signers, { requireId: true });
1009
- if (options.expires_at !== void 0) requireIso8601(options.expires_at, "expires_at");
1173
+ validateTemplateSigners(signers, { requireIdentity: true });
1174
+ if (options.expires_at !== void 0) requireExpiration(options.expires_at);
1010
1175
  if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
1011
1176
  throw new ValidationError("editor_fields must contain field_id and value");
1012
1177
  }
1013
1178
  if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag))) {
1014
1179
  throw new ValidationError("tags must contain non-empty tag names");
1015
1180
  }
1181
+ await this.validateCertificateTemplateMethod(tmplId, accId, signers);
1016
1182
  const body = { ...options, signers };
1017
1183
  this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
1018
1184
  return this.call(
@@ -1024,7 +1190,8 @@ var DocumentResource = class extends BaseResource {
1024
1190
  async estimateCostFromTemplate(templateId, signers, accountId) {
1025
1191
  const tmplId = this.requireId(templateId, "Template ID");
1026
1192
  const accId = this.accountId(accountId);
1027
- validateTemplateSigners(signers, { requireId: false });
1193
+ validateTemplateSigners(signers, { requireIdentity: false });
1194
+ await this.validateCertificateTemplateMethod(tmplId, accId, signers);
1028
1195
  return this.call(
1029
1196
  "Failed to estimate cost from template",
1030
1197
  () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents/estimate-cost`, { signers })
@@ -1103,6 +1270,25 @@ var DocumentResource = class extends BaseResource {
1103
1270
  const percentage = total > 0 ? Math.round(signed / total * 1e4) / 100 : 0;
1104
1271
  return { signed, total, pending, percentage };
1105
1272
  }
1273
+ async validateCertificateTemplateMethod(templateId, accountId, signers) {
1274
+ if (!signers.some((signer) => signer.verification_method === "DigitalCertificate")) return;
1275
+ const template = await this.call(
1276
+ "Failed to fetch template",
1277
+ () => this.http.get(`/accounts/${accountId}/templates/${templateId}`)
1278
+ );
1279
+ const nonSignerRoles = new Set(
1280
+ template.roles?.filter(
1281
+ (role) => role.assignment_type === "Editor" || role.assignment_type === "CopyReceiver"
1282
+ ).map((role) => role.id)
1283
+ );
1284
+ const method = template.pages?.some(
1285
+ (page) => page.fields.some((field) => !nonSignerRoles.has(field.role_id))
1286
+ ) ? "collect" : "virtual";
1287
+ validateDigitalCertificateMethod(
1288
+ method,
1289
+ signers.filter((signer) => !nonSignerRoles.has(signer.role_id))
1290
+ );
1291
+ }
1106
1292
  };
1107
1293
  function validateTemplateSigners(signers, options) {
1108
1294
  if (!Array.isArray(signers)) throw new ValidationError("signers must be an array");
@@ -1114,17 +1300,20 @@ function validateTemplateSigners(signers, options) {
1114
1300
  if (typeof signer.role_id !== "string" || !signer.role_id) {
1115
1301
  throw new ValidationError("each template signer requires role_id");
1116
1302
  }
1117
- if ((options.requireId || signer.id !== void 0) && (typeof signer.id !== "string" || !signer.id)) {
1118
- throw new ValidationError("each template signer requires a valid id");
1119
- }
1120
- validateSignerOptions(signer);
1121
- if (options.requireId && signer.step !== void 0 && Number(signer.step) < 1) {
1122
- throw new ValidationError("template signer step must be a positive integer");
1303
+ if (signer.id !== void 0) {
1304
+ if (typeof signer.id !== "string" || !signer.id) {
1305
+ throw new ValidationError("each template signer requires a valid id");
1306
+ }
1307
+ } else if (options.requireIdentity) {
1308
+ if (typeof signer.email !== "string") {
1309
+ throw new ValidationError("each template signer requires an id or email");
1310
+ }
1311
+ requireEmail(signer.email);
1312
+ if (signer.name !== void 0 && (typeof signer.name !== "string" || !signer.name.trim())) {
1313
+ throw new ValidationError("template signer name cannot be blank");
1314
+ }
1123
1315
  }
1124
1316
  }
1125
- if (options.requireId) {
1126
- validateSigningSteps(signers);
1127
- }
1128
1317
  }
1129
1318
  async function loadSource(source) {
1130
1319
  if ("buffer" in source) {
@@ -2045,7 +2234,11 @@ var NOTIFICATION_PREFERENCE_CODES = [
2045
2234
  "DocumentExpirationReset",
2046
2235
  "DocumentProcessingFailed",
2047
2236
  "TemplateProcessingFailed",
2048
- "SignerWhatsappFailed"
2237
+ "SignerWhatsappFailed",
2238
+ "ContractRenewalNotice",
2239
+ "ContractExpiring",
2240
+ "ContractExpired",
2241
+ "ContractRenewed"
2049
2242
  ];
2050
2243
 
2051
2244
  // src/api/resources/users.ts
@@ -2207,6 +2400,7 @@ var WebhookResource = class extends BaseResource {
2207
2400
  * `PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}` — update only
2208
2401
  * the fields sent. Enabling signing creates a secret when none exists;
2209
2402
  * disabling it discards the secret.
2403
+ * Enabling signing returns the new secret once, including to OAuth applications.
2210
2404
  */
2211
2405
  async updateEndpoint(endpointId, payload, accountId) {
2212
2406
  const id = this.accountId(accountId);
@@ -2253,7 +2447,7 @@ var WebhookResource = class extends BaseResource {
2253
2447
  }
2254
2448
  /**
2255
2449
  * `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
2256
- * The old secret stops working immediately. Not available to OAuth applications.
2450
+ * The old secret stops working immediately. Requires `webhooks:write` for OAuth.
2257
2451
  */
2258
2452
  async rotateEndpointSecret(endpointId, accountId) {
2259
2453
  const id = this.accountId(accountId);
@@ -2505,6 +2699,7 @@ var AssinafyClient = class _AssinafyClient {
2505
2699
  logger;
2506
2700
  webhookSecret;
2507
2701
  documents;
2702
+ contracts;
2508
2703
  signers;
2509
2704
  workspaces;
2510
2705
  assignments;
@@ -2571,6 +2766,7 @@ var AssinafyClient = class _AssinafyClient {
2571
2766
  maxRedirects: 0
2572
2767
  });
2573
2768
  this.documents = new DocumentResource(this.axiosInstance, this.defaultAccountId, this.logger);
2769
+ this.contracts = new ContractResource(this.axiosInstance, this.defaultAccountId, this.logger);
2574
2770
  this.signers = new SignerResource(this.axiosInstance, this.defaultAccountId, this.logger);
2575
2771
  this.workspaces = new WorkspaceResource(this.axiosInstance, void 0, this.logger);
2576
2772
  this.assignments = new AssignmentResource(
@@ -2628,12 +2824,11 @@ var AssinafyClient = class _AssinafyClient {
2628
2824
  if (!Array.isArray(options.signers) || options.signers.length === 0) {
2629
2825
  throw new ValidationError("At least one signer is required");
2630
2826
  }
2631
- if (options.expiresAt !== void 0) requireIso8601(options.expiresAt, "expiresAt");
2827
+ if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
2632
2828
  const preparedSigners = options.signers.map((signer) => {
2633
2829
  if (!signer || typeof signer !== "object") {
2634
2830
  throw new ValidationError("Each signer must be an object");
2635
2831
  }
2636
- validateSignerOptions(signer);
2637
2832
  const payload = { full_name: signer.name };
2638
2833
  if (signer.email !== void 0) payload.email = signer.email;
2639
2834
  const phone = signer.whatsapp_phone_number ?? signer.phone;
@@ -2642,7 +2837,14 @@ var AssinafyClient = class _AssinafyClient {
2642
2837
  if (signer.government_id !== void 0) payload.government_id = signer.government_id;
2643
2838
  if (signer.metadata !== void 0) payload.metadata = signer.metadata;
2644
2839
  validateCreateSignerPayload(payload);
2645
- return { signer, payload, phone };
2840
+ const useWhatsapp = phone !== void 0 && signer.email === void 0;
2841
+ const reference = {
2842
+ verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
2843
+ notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
2844
+ step: signer.step
2845
+ };
2846
+ validateSignerOptions(reference);
2847
+ return { reference, payload };
2646
2848
  });
2647
2849
  validateSigningSteps(options.signers);
2648
2850
  this.logger.info("Starting upload + signature workflow", {
@@ -2658,15 +2860,12 @@ var AssinafyClient = class _AssinafyClient {
2658
2860
  await this.documents.waitUntilReady(document.id);
2659
2861
  }
2660
2862
  const assignmentSigners = [];
2661
- for (const { signer, payload, phone } of preparedSigners) {
2863
+ for (const { reference, payload } of preparedSigners) {
2662
2864
  const created = await this.signers.create(payload, options.accountId);
2663
2865
  signerIds.push(created.id);
2664
- const useWhatsapp = phone !== void 0 && signer.email === void 0;
2665
2866
  assignmentSigners.push({
2666
2867
  id: created.id,
2667
- verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
2668
- notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
2669
- step: signer.step
2868
+ ...reference
2670
2869
  });
2671
2870
  }
2672
2871
  const assignmentPayload = {
@@ -2704,6 +2903,7 @@ export {
2704
2903
  AssinafyClient,
2705
2904
  AssinafyError,
2706
2905
  AuthenticationResource,
2906
+ ContractResource,
2707
2907
  DocumentResource,
2708
2908
  FieldsResource,
2709
2909
  NOTIFICATION_PREFERENCE_CODES,