@assinafy/cli 2.1.2 → 2.1.3

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.js CHANGED
@@ -803,24 +803,24 @@ var DocumentResource = class extends BaseResource {
803
803
  );
804
804
  }
805
805
  /**
806
- * Replace the document's tag set with tag IDs. An empty array detaches all tags.
807
- * Values are forwarded unchanged for compatibility with deployments that also accept names.
806
+ * Replace the document's tag set. Production accepts tag names and creates missing tags.
807
+ * An empty array detaches all tags. Values are forwarded unchanged.
808
808
  */
809
809
  async replaceTags(documentId, tags, accountId) {
810
810
  const accId = this.accountId(accountId);
811
811
  const docId = this.requireId(documentId, "Document ID");
812
- if (!Array.isArray(tags)) throw new ValidationError("tags must be an array of tag IDs");
812
+ if (!Array.isArray(tags)) throw new ValidationError("tags must be an array");
813
813
  return this.call(
814
814
  "Failed to replace document tags",
815
815
  () => this.http.put(`/accounts/${accId}/documents/${docId}/tags`, { tags })
816
816
  );
817
817
  }
818
- /** Attach additional tag IDs without removing existing ones. */
818
+ /** Attach additional tag names without removing existing ones. Production creates missing tags. */
819
819
  async addTags(documentId, tags, accountId) {
820
820
  const accId = this.accountId(accountId);
821
821
  const docId = this.requireId(documentId, "Document ID");
822
822
  if (!Array.isArray(tags) || tags.length === 0) {
823
- throw new ValidationError("tags must be a non-empty array of tag IDs");
823
+ throw new ValidationError("tags must be a non-empty array");
824
824
  }
825
825
  return this.call(
826
826
  "Failed to add document tags",
@@ -1443,6 +1443,7 @@ var SignerDocumentsResource = class extends BaseResource {
1443
1443
  for (const [key, value] of Object.entries(payload)) {
1444
1444
  if (value !== void 0) body[key] = value;
1445
1445
  }
1446
+ await this.requireDocumentAccess(did, code);
1446
1447
  return this.call(
1447
1448
  "Failed to confirm signer data",
1448
1449
  () => this.http.put(`/documents/${did}/signers/confirm-data`, body, signerAccessConfig(code))
@@ -1495,13 +1496,20 @@ var SignerDocumentsResource = class extends BaseResource {
1495
1496
  () => this.http.get("/sign", signerAccessConfig(code, { has_accepted_terms: hasAcceptedTerms }))
1496
1497
  );
1497
1498
  }
1498
- /** `POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…` — sign. */
1499
+ /**
1500
+ * `POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…` — sign.
1501
+ * Virtual assignments accept `[]` after the signer confirms their data.
1502
+ */
1499
1503
  async sign(documentId, assignmentId, signerAccessCode, entries) {
1500
1504
  const did = this.requireId(documentId, "Document ID");
1501
1505
  const aid = this.requireId(assignmentId, "Assignment ID");
1502
1506
  const code = this.requireId(signerAccessCode, "signer-access-code");
1503
- if (!Array.isArray(entries) || entries.length === 0) {
1504
- throw new ValidationError("entries must be a non-empty array");
1507
+ if (!Array.isArray(entries)) {
1508
+ throw new ValidationError("entries must be an array");
1509
+ }
1510
+ const document = await this.requireDocumentAccess(did, code, aid);
1511
+ if (document.assignment?.method === "collect" && entries.length === 0) {
1512
+ throw new ValidationError("entries must be non-empty for collect assignments");
1505
1513
  }
1506
1514
  return this.call(
1507
1515
  "Failed to sign document",
@@ -1517,6 +1525,7 @@ var SignerDocumentsResource = class extends BaseResource {
1517
1525
  const aid = this.requireId(assignmentId, "Assignment ID");
1518
1526
  const code = this.requireId(signerAccessCode, "signer-access-code");
1519
1527
  validateDeclineReason(declineReason);
1528
+ await this.requireDocumentAccess(did, code, aid);
1520
1529
  return this.call(
1521
1530
  "Failed to decline assignment",
1522
1531
  () => this.http.put(
@@ -1526,6 +1535,13 @@ var SignerDocumentsResource = class extends BaseResource {
1526
1535
  )
1527
1536
  );
1528
1537
  }
1538
+ async requireDocumentAccess(documentId, signerAccessCode, assignmentId) {
1539
+ const document = await this.getAssignment(signerAccessCode);
1540
+ if (document.id !== documentId || assignmentId !== void 0 && document.assignment?.id !== assignmentId) {
1541
+ throw new ValidationError("Signer access code does not match the document or assignment");
1542
+ }
1543
+ return document;
1544
+ }
1529
1545
  };
1530
1546
  function validateDeclineReason(value) {
1531
1547
  if (typeof value !== "string" || !value.trim()) {