@assinafy/cli 2.5.2 → 2.6.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/.env.example +1 -1
- package/README.en.md +24 -3
- package/README.md +22 -2
- package/dist/api.cjs +124 -29
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +124 -29
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +606 -418
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api/resources/assignments.d.ts +7 -1
- package/dist/types/api/resources/assignments.d.ts.map +1 -1
- package/dist/types/api/resources/documents.d.ts.map +1 -1
- package/dist/types/api/resources/signer-documents.d.ts +24 -11
- package/dist/types/api/resources/signer-documents.d.ts.map +1 -1
- package/dist/types/api/resources/webhooks.d.ts +10 -5
- package/dist/types/api/resources/webhooks.d.ts.map +1 -1
- package/dist/types/api/support/webhook-verifier.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +87 -4
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/api/utils.d.ts.map +1 -1
- package/docs/README.md +1 -1
- package/docs/api-operations.json +49 -1
- package/docs/api-reference.md +464 -45
- package/docs/assignments.md +67 -9
- package/docs/sdk-reference.md +86 -11
- package/docs/signer.md +27 -0
- package/docs/signers.md +14 -12
- package/docs/webhooks.md +18 -2
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -98,7 +98,8 @@ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
|
98
98
|
var VERIFICATION_METHODS = [
|
|
99
99
|
"Email",
|
|
100
100
|
"Whatsapp",
|
|
101
|
-
"DigitalCertificate"
|
|
101
|
+
"DigitalCertificate",
|
|
102
|
+
"IdDocumentFaceMatchBasic"
|
|
102
103
|
];
|
|
103
104
|
var NOTIFICATION_METHODS = ["Email", "Whatsapp"];
|
|
104
105
|
function handleAssinafyResponse(response) {
|
|
@@ -457,6 +458,53 @@ function normaliseSignerRef(ref, options) {
|
|
|
457
458
|
throw new ValidationError("Invalid signer reference", { ref });
|
|
458
459
|
}
|
|
459
460
|
var AssignmentResource = class extends BaseResource {
|
|
461
|
+
/** Fetch an account review and available evidence for a signer's identity verification. */
|
|
462
|
+
async getIdentityVerification(documentId, assignmentId, signerId) {
|
|
463
|
+
const docId = this.requireId(documentId, "Document ID");
|
|
464
|
+
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
465
|
+
const sid = this.requireId(signerId, "Signer ID");
|
|
466
|
+
return this.call(
|
|
467
|
+
"Failed to fetch signer identity review",
|
|
468
|
+
() => this.http.get(
|
|
469
|
+
`/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification`
|
|
470
|
+
)
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
/** Download JPEG/PNG evidence or the document PDF, available only while the review is open. */
|
|
474
|
+
async downloadIdentityVerificationImage(documentId, assignmentId, signerId, name) {
|
|
475
|
+
const docId = this.requireId(documentId, "Document ID");
|
|
476
|
+
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
477
|
+
const sid = this.requireId(signerId, "Signer ID");
|
|
478
|
+
if (!["document_front", "document_back", "document_pdf", "face"].includes(name)) {
|
|
479
|
+
throw new ValidationError("Unknown identity verification image name");
|
|
480
|
+
}
|
|
481
|
+
return this.callBinary(
|
|
482
|
+
"Failed to download identity review image",
|
|
483
|
+
() => this.http.get(
|
|
484
|
+
`/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification/images/${name}`,
|
|
485
|
+
{ responseType: "arraybuffer" }
|
|
486
|
+
)
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
/** Approve certification or reject/cancel the document; the optional note is private to reviewers. */
|
|
490
|
+
async reviewIdentityVerification(documentId, assignmentId, signerId, payload) {
|
|
491
|
+
const docId = this.requireId(documentId, "Document ID");
|
|
492
|
+
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
493
|
+
const sid = this.requireId(signerId, "Signer ID");
|
|
494
|
+
if (!payload || !["Approved", "Rejected"].includes(payload.decision)) {
|
|
495
|
+
throw new ValidationError("decision must be Approved or Rejected");
|
|
496
|
+
}
|
|
497
|
+
if (payload.note != null && (typeof payload.note !== "string" || [...payload.note].length > 2e3)) {
|
|
498
|
+
throw new ValidationError("note must contain at most 2000 characters");
|
|
499
|
+
}
|
|
500
|
+
return this.call(
|
|
501
|
+
"Failed to decide signer identity review",
|
|
502
|
+
() => this.http.post(
|
|
503
|
+
`/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification/review`,
|
|
504
|
+
{ decision: payload.decision, note: payload.note }
|
|
505
|
+
)
|
|
506
|
+
);
|
|
507
|
+
}
|
|
460
508
|
/**
|
|
461
509
|
* List assignments across the account (`GET /assignments`).
|
|
462
510
|
*
|
|
@@ -711,6 +759,7 @@ var DOCUMENT_SORTS = ["name", "-name", "updated_at", "-updated_at"];
|
|
|
711
759
|
var READY_STATUSES = /* @__PURE__ */ new Set([
|
|
712
760
|
"metadata_ready",
|
|
713
761
|
"pending_signature",
|
|
762
|
+
"pending_identity_review",
|
|
714
763
|
"certificated"
|
|
715
764
|
]);
|
|
716
765
|
var FAILED_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -1449,32 +1498,46 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
1449
1498
|
() => this.http.get(`/signers/${sid}/document`, signerAccessConfig(code))
|
|
1450
1499
|
);
|
|
1451
1500
|
}
|
|
1501
|
+
/** `GET /signers/{signer_id}/documents?signer-access-code=…` */
|
|
1502
|
+
async list(signerId, signerAccessCode, params = {}) {
|
|
1503
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
1504
|
+
return this.listDocuments(signerId, signerAccessConfig(code, { ...params }));
|
|
1505
|
+
}
|
|
1452
1506
|
/**
|
|
1453
|
-
* `GET /signers/{signer_id}/documents`
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
1507
|
+
* `GET /signers/{signer_id}/documents` with the client's owner credentials
|
|
1508
|
+
* (API key or token) instead of a signer access code. The signer must belong
|
|
1509
|
+
* to that workspace.
|
|
1456
1510
|
*/
|
|
1457
|
-
async
|
|
1511
|
+
async listAsOwner(signerId, params = {}) {
|
|
1512
|
+
return this.listDocuments(signerId, { params: cleanParams({ ...params }) });
|
|
1513
|
+
}
|
|
1514
|
+
/** `GET /signers/{signer_id}/documents/search?search=…&signer-access-code=…` */
|
|
1515
|
+
async search(signerId, search, signerAccessCode) {
|
|
1516
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
1517
|
+
return this.searchDocuments(signerId, signerAccessConfig(code, { search }));
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* `GET /signers/{signer_id}/documents/search?search=…` with the client's owner
|
|
1521
|
+
* credentials instead of a signer access code. The signer must belong to that
|
|
1522
|
+
* workspace.
|
|
1523
|
+
*/
|
|
1524
|
+
async searchAsOwner(signerId, search) {
|
|
1525
|
+
return this.searchDocuments(signerId, { params: cleanParams({ search }) });
|
|
1526
|
+
}
|
|
1527
|
+
listDocuments(signerId, config) {
|
|
1458
1528
|
const sid = this.requireId(signerId, "Signer ID");
|
|
1459
|
-
const config = this.signerOrOwnerConfig(signerAccessCode, { ...params });
|
|
1460
1529
|
return this.callList(
|
|
1461
1530
|
"Failed to list signer documents",
|
|
1462
1531
|
() => this.http.get(`/signers/${sid}/documents`, config)
|
|
1463
1532
|
);
|
|
1464
1533
|
}
|
|
1465
|
-
|
|
1466
|
-
async search(signerId, search, signerAccessCode) {
|
|
1534
|
+
searchDocuments(signerId, config) {
|
|
1467
1535
|
const sid = this.requireId(signerId, "Signer ID");
|
|
1468
|
-
const config = this.signerOrOwnerConfig(signerAccessCode, { search });
|
|
1469
1536
|
return this.callList(
|
|
1470
1537
|
"Failed to search signer documents",
|
|
1471
1538
|
() => this.http.get(`/signers/${sid}/documents/search`, config)
|
|
1472
1539
|
);
|
|
1473
1540
|
}
|
|
1474
|
-
signerOrOwnerConfig(signerAccessCode, params) {
|
|
1475
|
-
if (signerAccessCode === void 0) return { params: cleanParams(params) };
|
|
1476
|
-
return signerAccessConfig(this.requireId(signerAccessCode, "signer-access-code"), params);
|
|
1477
|
-
}
|
|
1478
1541
|
/**
|
|
1479
1542
|
* Public `GET /signers/{signer_id}/documents/{document_id}/download/{artifact}`.
|
|
1480
1543
|
* When an access code is supplied, the SDK first verifies that it belongs to
|
|
@@ -1540,6 +1603,25 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
1540
1603
|
() => this.http.get("/signers/self", signerAccessConfig(code))
|
|
1541
1604
|
);
|
|
1542
1605
|
}
|
|
1606
|
+
/** `GET /signers/identity-verification` — session status, capture URL and restart eligibility. */
|
|
1607
|
+
async getIdentityVerification(signerAccessCode) {
|
|
1608
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
1609
|
+
return this.call(
|
|
1610
|
+
"Failed to fetch identity verification",
|
|
1611
|
+
() => this.http.get("/signers/identity-verification", signerAccessConfig(code))
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
/** `POST /signers/identity-verification` — open a hosted session after the signer's explicit consent. */
|
|
1615
|
+
async startIdentityVerification(signerAccessCode, payload) {
|
|
1616
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
1617
|
+
if (payload?.consent !== true) {
|
|
1618
|
+
throw new ValidationError("Explicit biometric-processing consent is required");
|
|
1619
|
+
}
|
|
1620
|
+
return this.call(
|
|
1621
|
+
"Failed to start identity verification",
|
|
1622
|
+
() => this.http.post("/signers/identity-verification", { consent: true }, signerAccessConfig(code))
|
|
1623
|
+
);
|
|
1624
|
+
}
|
|
1543
1625
|
/**
|
|
1544
1626
|
* `PUT /signers/accept-terms?signer-access-code=…` — accept the platform
|
|
1545
1627
|
* terms as the signer.
|
|
@@ -1843,9 +1925,10 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
|
|
|
1843
1925
|
email: payload.email,
|
|
1844
1926
|
whatsapp_phone_number: payload.whatsapp_phone_number ?? payload.phone
|
|
1845
1927
|
};
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1928
|
+
if (payload.government_id !== void 0) {
|
|
1929
|
+
normalised.government_id = payload.government_id;
|
|
1930
|
+
} else if (payload.cpf) {
|
|
1931
|
+
const digits = payload.cpf.replace(/\D/g, "");
|
|
1849
1932
|
if (digits) normalised[useGovernmentId ? "government_id" : "cpf"] = digits;
|
|
1850
1933
|
}
|
|
1851
1934
|
if ("metadata" in payload && payload.metadata !== void 0) {
|
|
@@ -2084,19 +2167,21 @@ var WebhookResource = class extends BaseResource {
|
|
|
2084
2167
|
() => this.http.put(`/accounts/${id}/webhooks/inactivate`)
|
|
2085
2168
|
);
|
|
2086
2169
|
}
|
|
2087
|
-
/**
|
|
2088
|
-
async listEndpoints(accountId) {
|
|
2170
|
+
/** List webhook endpoints, oldest first; `url` matches the registered value exactly. */
|
|
2171
|
+
async listEndpoints(accountId, params = {}) {
|
|
2089
2172
|
const id = this.accountId(accountId);
|
|
2173
|
+
validateWebhookFields(params);
|
|
2090
2174
|
return this.call(
|
|
2091
2175
|
"Failed to list webhook endpoints",
|
|
2092
|
-
() => this.http.get(`/accounts/${id}/webhooks/endpoints
|
|
2176
|
+
() => this.http.get(`/accounts/${id}/webhooks/endpoints`, { params: cleanParams({ ...params }) })
|
|
2093
2177
|
);
|
|
2094
2178
|
}
|
|
2095
2179
|
/**
|
|
2096
2180
|
* `POST /accounts/{accountId}/webhooks/endpoints` — register another
|
|
2097
2181
|
* endpoint. Accounts allow 1 endpoint, or up to 3 on paid plans (`403` past
|
|
2098
2182
|
* the limit); URLs must be unique per workspace. Omitted `events` uses the
|
|
2099
|
-
* same default set as {@link register}.
|
|
2183
|
+
* same default set as {@link register}. Signed creation returns `secret`
|
|
2184
|
+
* once, including to OAuth applications; save it securely.
|
|
2100
2185
|
*/
|
|
2101
2186
|
async createEndpoint(payload, accountId) {
|
|
2102
2187
|
if (!payload.url) throw new ValidationError("Webhook URL is required");
|
|
@@ -2144,6 +2229,16 @@ var WebhookResource = class extends BaseResource {
|
|
|
2144
2229
|
() => this.http.delete(`/accounts/${id}/webhooks/endpoints/${eid}`)
|
|
2145
2230
|
);
|
|
2146
2231
|
}
|
|
2232
|
+
/** Delete the endpoint whose URL exactly matches `url`; returns 404 when none matches. */
|
|
2233
|
+
async deleteEndpointByUrl(url, accountId) {
|
|
2234
|
+
if (!url) throw new ValidationError("Webhook URL is required");
|
|
2235
|
+
validateWebhookFields({ url });
|
|
2236
|
+
const id = this.accountId(accountId);
|
|
2237
|
+
return this.call(
|
|
2238
|
+
"Failed to delete webhook endpoint by URL",
|
|
2239
|
+
() => this.http.delete(`/accounts/${id}/webhooks/endpoints`, { params: { url } })
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2147
2242
|
/**
|
|
2148
2243
|
* `GET …/endpoints/{endpointId}/secret` — the `whsec_` signing secret.
|
|
2149
2244
|
* Returns `400` when signing is disabled. Not available to OAuth applications.
|
|
@@ -2301,12 +2396,10 @@ function readHeader(headers, name) {
|
|
|
2301
2396
|
if (typeof headers.get === "function") {
|
|
2302
2397
|
return headers.get(name) ?? void 0;
|
|
2303
2398
|
}
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
}
|
|
2309
|
-
return void 0;
|
|
2399
|
+
const matches = Object.entries(headers).filter(([key]) => key.toLowerCase() === name);
|
|
2400
|
+
if (matches.length !== 1) return void 0;
|
|
2401
|
+
const value = matches[0]?.[1];
|
|
2402
|
+
return Array.isArray(value) ? value.length === 1 ? value[0] : void 0 : value;
|
|
2310
2403
|
}
|
|
2311
2404
|
var WebhookVerifier = class {
|
|
2312
2405
|
constructor(webhookSecret, options = {}) {
|
|
@@ -2331,7 +2424,8 @@ var WebhookVerifier = class {
|
|
|
2331
2424
|
if (!id || !timestamp || !signatures || !/^\d+$/.test(timestamp)) return false;
|
|
2332
2425
|
const tolerance = options.toleranceSeconds ?? 300;
|
|
2333
2426
|
const now = Math.floor((options.now ?? Date.now()) / 1e3);
|
|
2334
|
-
if (Math.abs(now - Number(timestamp)) > tolerance)
|
|
2427
|
+
if (!Number.isFinite(tolerance) || tolerance < 0 || !Number.isSafeInteger(now) || now < 0 || !Number.isSafeInteger(Number(timestamp)) || Math.abs(now - Number(timestamp)) > tolerance)
|
|
2428
|
+
return false;
|
|
2335
2429
|
const secret = this.webhookSecret.startsWith("whsec_") ? this.webhookSecret.slice("whsec_".length) : this.webhookSecret;
|
|
2336
2430
|
const key = Buffer.from(secret, "base64");
|
|
2337
2431
|
if (key.length === 0) return false;
|
|
@@ -2339,8 +2433,8 @@ var WebhookVerifier = class {
|
|
|
2339
2433
|
createHmac("sha256", key).update(`${id}.${timestamp}.`).update(typeof payload === "string" ? Buffer.from(payload, "utf8") : payload).digest("base64")
|
|
2340
2434
|
);
|
|
2341
2435
|
return signatures.split(" ").some((entry) => {
|
|
2342
|
-
const [version, value] = entry.split(","
|
|
2343
|
-
if (version !== "v1" || !value) return false;
|
|
2436
|
+
const [version, value, extra] = entry.split(",");
|
|
2437
|
+
if (version !== "v1" || !value || extra !== void 0) return false;
|
|
2344
2438
|
const provided = Buffer.from(value);
|
|
2345
2439
|
return provided.length === expected.length && timingSafeEqual2(provided, expected);
|
|
2346
2440
|
});
|
|
@@ -2545,6 +2639,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2545
2639
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
2546
2640
|
if (phone !== void 0) payload.whatsapp_phone_number = phone;
|
|
2547
2641
|
if (signer.cpf !== void 0) payload.cpf = signer.cpf;
|
|
2642
|
+
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2548
2643
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2549
2644
|
validateCreateSignerPayload(payload);
|
|
2550
2645
|
return { signer, payload, phone };
|