@assinafy/cli 2.6.0 → 2.6.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.
package/dist/api.cjs CHANGED
@@ -284,6 +284,13 @@ function validateSignerOptions(input) {
284
284
  throw new ValidationError("step must be an integer");
285
285
  }
286
286
  }
287
+ function validateDigitalCertificateMethod(method, signers) {
288
+ if (method !== "virtual" && signers.some((signer) => signer.verification_method === "DigitalCertificate")) {
289
+ throw new ValidationError("DigitalCertificate signers require method: virtual", {
290
+ code: "digital_certificate_requires_virtual"
291
+ });
292
+ }
293
+ }
287
294
  function validateSigningSteps(signers) {
288
295
  const withSteps = signers.filter((signer) => signer.step !== void 0);
289
296
  if (withSteps.length > 0) {
@@ -460,15 +467,17 @@ function buildAssignmentPayload(payload, options = {}) {
460
467
  signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
461
468
  });
462
469
  }
463
- if (payload.method === "collect" && !Array.isArray(payload.entries)) {
470
+ const method = payload.method ?? "virtual";
471
+ const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
472
+ validateDigitalCertificateMethod(method, normalisedSigners);
473
+ if (method === "collect" && !Array.isArray(payload.entries)) {
464
474
  throw new ValidationError("entries are required for collect assignments");
465
475
  }
466
- const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
467
476
  if (!options.skipDigitalCertificateStepValidation) {
468
477
  validateSigningSteps(normalisedSigners);
469
478
  }
470
479
  return stripEmpty({
471
- method: payload.method ?? "virtual",
480
+ method,
472
481
  signers: normalisedSigners,
473
482
  message: payload.message,
474
483
  expires_at: payload.expires_at === void 0 ? void 0 : requireIso8601(payload.expires_at, "expires_at"),
@@ -1072,6 +1081,7 @@ var DocumentResource = class extends BaseResource {
1072
1081
  if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag))) {
1073
1082
  throw new ValidationError("tags must contain non-empty tag names");
1074
1083
  }
1084
+ await this.validateCertificateTemplateMethod(tmplId, accId, signers);
1075
1085
  const body = { ...options, signers };
1076
1086
  this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
1077
1087
  return this.call(
@@ -1084,6 +1094,7 @@ var DocumentResource = class extends BaseResource {
1084
1094
  const tmplId = this.requireId(templateId, "Template ID");
1085
1095
  const accId = this.accountId(accountId);
1086
1096
  validateTemplateSigners(signers, { requireId: false });
1097
+ await this.validateCertificateTemplateMethod(tmplId, accId, signers);
1087
1098
  return this.call(
1088
1099
  "Failed to estimate cost from template",
1089
1100
  () => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents/estimate-cost`, { signers })
@@ -1162,6 +1173,15 @@ var DocumentResource = class extends BaseResource {
1162
1173
  const percentage = total > 0 ? Math.round(signed / total * 1e4) / 100 : 0;
1163
1174
  return { signed, total, pending, percentage };
1164
1175
  }
1176
+ async validateCertificateTemplateMethod(templateId, accountId, signers) {
1177
+ if (!signers.some((signer) => signer.verification_method === "DigitalCertificate")) return;
1178
+ const template = await this.call(
1179
+ "Failed to fetch template",
1180
+ () => this.http.get(`/accounts/${accountId}/templates/${templateId}`)
1181
+ );
1182
+ const method = template.pages?.some((page) => page.fields.length > 0) ? "collect" : "virtual";
1183
+ validateDigitalCertificateMethod(method, signers);
1184
+ }
1165
1185
  };
1166
1186
  function validateTemplateSigners(signers, options) {
1167
1187
  if (!Array.isArray(signers)) throw new ValidationError("signers must be an array");