@assinafy/cli 2.1.2 → 2.2.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.
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",
@@ -1420,15 +1420,55 @@ var SignerDocumentsResource = class extends BaseResource {
1420
1420
  () => this.http.put("/signers/accept-terms", void 0, signerAccessConfig(code))
1421
1421
  );
1422
1422
  }
1423
- /** `POST /verify` — verify the email OTP for a signer. */
1424
- async verifyEmail(payload) {
1423
+ /** `POST /verify` — verify an email or WhatsApp OTP for a signer. */
1424
+ async verifyCode(payload) {
1425
1425
  const code = this.requireId(payload.signerAccessCode, "signer-access-code");
1426
1426
  const otp = this.requireId(payload.verificationCode, "verification-code");
1427
1427
  return this.call(
1428
- "Failed to verify signer email",
1428
+ "Failed to verify signer code",
1429
1429
  () => this.http.post("/verify", { "verification-code": otp }, signerAccessConfig(code))
1430
1430
  );
1431
1431
  }
1432
+ /** Compatibility alias for {@link verifyCode}; accepts email and WhatsApp OTPs. */
1433
+ async verifyEmail(payload) {
1434
+ return this.verifyCode(payload);
1435
+ }
1436
+ /**
1437
+ * `POST /signers/certificate/start` — start an ICP-Brasil A1/A3 signature.
1438
+ * Returns `{ token }` for the signer's Web PKI client. This production route
1439
+ * is used by Assinafy's signing frontend but is absent from OpenAPI paths.
1440
+ */
1441
+ async startCertificate(signerAccessCode) {
1442
+ const code = this.requireId(signerAccessCode, "signer-access-code");
1443
+ return this.call(
1444
+ "Failed to start certificate signature",
1445
+ () => this.http.post(
1446
+ "/signers/certificate/start",
1447
+ { "signer-access-code": code },
1448
+ signerAccessConfig(code)
1449
+ )
1450
+ );
1451
+ }
1452
+ /**
1453
+ * `POST /signers/certificate/complete` — finish an ICP-Brasil A1/A3 signature.
1454
+ * Pass the same token returned by {@link startCertificate}, after Web PKI
1455
+ * successfully signs it. Returns `{ signerName }`; private keys stay local.
1456
+ * This production route is absent from OpenAPI paths.
1457
+ */
1458
+ async completeCertificate(signerAccessCode, token) {
1459
+ const code = this.requireId(signerAccessCode, "signer-access-code");
1460
+ if (typeof token !== "string" || !token.trim()) {
1461
+ throw new ValidationError("Certificate token is required");
1462
+ }
1463
+ return this.call(
1464
+ "Failed to complete certificate signature",
1465
+ () => this.http.post(
1466
+ "/signers/certificate/complete",
1467
+ { "signer-access-code": code, token },
1468
+ signerAccessConfig(code)
1469
+ )
1470
+ );
1471
+ }
1432
1472
  /**
1433
1473
  * `PUT /documents/{documentId}/signers/confirm-data?signer-access-code=…`
1434
1474
  *
@@ -1443,6 +1483,7 @@ var SignerDocumentsResource = class extends BaseResource {
1443
1483
  for (const [key, value] of Object.entries(payload)) {
1444
1484
  if (value !== void 0) body[key] = value;
1445
1485
  }
1486
+ await this.requireDocumentAccess(did, code);
1446
1487
  return this.call(
1447
1488
  "Failed to confirm signer data",
1448
1489
  () => this.http.put(`/documents/${did}/signers/confirm-data`, body, signerAccessConfig(code))
@@ -1495,13 +1536,20 @@ var SignerDocumentsResource = class extends BaseResource {
1495
1536
  () => this.http.get("/sign", signerAccessConfig(code, { has_accepted_terms: hasAcceptedTerms }))
1496
1537
  );
1497
1538
  }
1498
- /** `POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…` — sign. */
1539
+ /**
1540
+ * `POST /documents/{documentId}/assignments/{assignmentId}?signer-access-code=…` — sign.
1541
+ * Virtual assignments accept `[]` after the signer confirms their data.
1542
+ */
1499
1543
  async sign(documentId, assignmentId, signerAccessCode, entries) {
1500
1544
  const did = this.requireId(documentId, "Document ID");
1501
1545
  const aid = this.requireId(assignmentId, "Assignment ID");
1502
1546
  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");
1547
+ if (!Array.isArray(entries)) {
1548
+ throw new ValidationError("entries must be an array");
1549
+ }
1550
+ const document = await this.requireDocumentAccess(did, code, aid);
1551
+ if (document.assignment?.method === "collect" && entries.length === 0) {
1552
+ throw new ValidationError("entries must be non-empty for collect assignments");
1505
1553
  }
1506
1554
  return this.call(
1507
1555
  "Failed to sign document",
@@ -1517,6 +1565,7 @@ var SignerDocumentsResource = class extends BaseResource {
1517
1565
  const aid = this.requireId(assignmentId, "Assignment ID");
1518
1566
  const code = this.requireId(signerAccessCode, "signer-access-code");
1519
1567
  validateDeclineReason(declineReason);
1568
+ await this.requireDocumentAccess(did, code, aid);
1520
1569
  return this.call(
1521
1570
  "Failed to decline assignment",
1522
1571
  () => this.http.put(
@@ -1526,6 +1575,13 @@ var SignerDocumentsResource = class extends BaseResource {
1526
1575
  )
1527
1576
  );
1528
1577
  }
1578
+ async requireDocumentAccess(documentId, signerAccessCode, assignmentId) {
1579
+ const document = await this.getAssignment(signerAccessCode);
1580
+ if (document.id !== documentId || assignmentId !== void 0 && document.assignment?.id !== assignmentId) {
1581
+ throw new ValidationError("Signer access code does not match the document or assignment");
1582
+ }
1583
+ return document;
1584
+ }
1529
1585
  };
1530
1586
  function validateDeclineReason(value) {
1531
1587
  if (typeof value !== "string" || !value.trim()) {