@assinafy/cli 2.5.3 → 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 +98 -17
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +98 -17
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +578 -404
- 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 +8 -4
- 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 +81 -8
- 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([
|
|
@@ -1554,6 +1603,25 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
1554
1603
|
() => this.http.get("/signers/self", signerAccessConfig(code))
|
|
1555
1604
|
);
|
|
1556
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
|
+
}
|
|
1557
1625
|
/**
|
|
1558
1626
|
* `PUT /signers/accept-terms?signer-access-code=…` — accept the platform
|
|
1559
1627
|
* terms as the signer.
|
|
@@ -1857,9 +1925,10 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
|
|
|
1857
1925
|
email: payload.email,
|
|
1858
1926
|
whatsapp_phone_number: payload.whatsapp_phone_number ?? payload.phone
|
|
1859
1927
|
};
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
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, "");
|
|
1863
1932
|
if (digits) normalised[useGovernmentId ? "government_id" : "cpf"] = digits;
|
|
1864
1933
|
}
|
|
1865
1934
|
if ("metadata" in payload && payload.metadata !== void 0) {
|
|
@@ -2098,19 +2167,21 @@ var WebhookResource = class extends BaseResource {
|
|
|
2098
2167
|
() => this.http.put(`/accounts/${id}/webhooks/inactivate`)
|
|
2099
2168
|
);
|
|
2100
2169
|
}
|
|
2101
|
-
/**
|
|
2102
|
-
async listEndpoints(accountId) {
|
|
2170
|
+
/** List webhook endpoints, oldest first; `url` matches the registered value exactly. */
|
|
2171
|
+
async listEndpoints(accountId, params = {}) {
|
|
2103
2172
|
const id = this.accountId(accountId);
|
|
2173
|
+
validateWebhookFields(params);
|
|
2104
2174
|
return this.call(
|
|
2105
2175
|
"Failed to list webhook endpoints",
|
|
2106
|
-
() => this.http.get(`/accounts/${id}/webhooks/endpoints
|
|
2176
|
+
() => this.http.get(`/accounts/${id}/webhooks/endpoints`, { params: cleanParams({ ...params }) })
|
|
2107
2177
|
);
|
|
2108
2178
|
}
|
|
2109
2179
|
/**
|
|
2110
2180
|
* `POST /accounts/{accountId}/webhooks/endpoints` — register another
|
|
2111
2181
|
* endpoint. Accounts allow 1 endpoint, or up to 3 on paid plans (`403` past
|
|
2112
2182
|
* the limit); URLs must be unique per workspace. Omitted `events` uses the
|
|
2113
|
-
* 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.
|
|
2114
2185
|
*/
|
|
2115
2186
|
async createEndpoint(payload, accountId) {
|
|
2116
2187
|
if (!payload.url) throw new ValidationError("Webhook URL is required");
|
|
@@ -2158,6 +2229,16 @@ var WebhookResource = class extends BaseResource {
|
|
|
2158
2229
|
() => this.http.delete(`/accounts/${id}/webhooks/endpoints/${eid}`)
|
|
2159
2230
|
);
|
|
2160
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
|
+
}
|
|
2161
2242
|
/**
|
|
2162
2243
|
* `GET …/endpoints/{endpointId}/secret` — the `whsec_` signing secret.
|
|
2163
2244
|
* Returns `400` when signing is disabled. Not available to OAuth applications.
|
|
@@ -2315,12 +2396,10 @@ function readHeader(headers, name) {
|
|
|
2315
2396
|
if (typeof headers.get === "function") {
|
|
2316
2397
|
return headers.get(name) ?? void 0;
|
|
2317
2398
|
}
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
}
|
|
2323
|
-
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;
|
|
2324
2403
|
}
|
|
2325
2404
|
var WebhookVerifier = class {
|
|
2326
2405
|
constructor(webhookSecret, options = {}) {
|
|
@@ -2345,7 +2424,8 @@ var WebhookVerifier = class {
|
|
|
2345
2424
|
if (!id || !timestamp || !signatures || !/^\d+$/.test(timestamp)) return false;
|
|
2346
2425
|
const tolerance = options.toleranceSeconds ?? 300;
|
|
2347
2426
|
const now = Math.floor((options.now ?? Date.now()) / 1e3);
|
|
2348
|
-
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;
|
|
2349
2429
|
const secret = this.webhookSecret.startsWith("whsec_") ? this.webhookSecret.slice("whsec_".length) : this.webhookSecret;
|
|
2350
2430
|
const key = Buffer.from(secret, "base64");
|
|
2351
2431
|
if (key.length === 0) return false;
|
|
@@ -2353,8 +2433,8 @@ var WebhookVerifier = class {
|
|
|
2353
2433
|
createHmac("sha256", key).update(`${id}.${timestamp}.`).update(typeof payload === "string" ? Buffer.from(payload, "utf8") : payload).digest("base64")
|
|
2354
2434
|
);
|
|
2355
2435
|
return signatures.split(" ").some((entry) => {
|
|
2356
|
-
const [version, value] = entry.split(","
|
|
2357
|
-
if (version !== "v1" || !value) return false;
|
|
2436
|
+
const [version, value, extra] = entry.split(",");
|
|
2437
|
+
if (version !== "v1" || !value || extra !== void 0) return false;
|
|
2358
2438
|
const provided = Buffer.from(value);
|
|
2359
2439
|
return provided.length === expected.length && timingSafeEqual2(provided, expected);
|
|
2360
2440
|
});
|
|
@@ -2559,6 +2639,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2559
2639
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
2560
2640
|
if (phone !== void 0) payload.whatsapp_phone_number = phone;
|
|
2561
2641
|
if (signer.cpf !== void 0) payload.cpf = signer.cpf;
|
|
2642
|
+
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2562
2643
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2563
2644
|
validateCreateSignerPayload(payload);
|
|
2564
2645
|
return { signer, payload, phone };
|