@assinafy/cli 2.5.3 → 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/.env.example +1 -1
- package/README.en.md +24 -3
- package/README.md +22 -2
- package/dist/api.cjs +121 -20
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +121 -20
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +601 -407
- 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 +1 -0
- 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 +5 -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 +473 -46
- package/docs/assignments.md +67 -9
- package/docs/sdk-reference.md +84 -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) {
|
|
@@ -224,6 +225,13 @@ function validateSignerOptions(input) {
|
|
|
224
225
|
throw new ValidationError("step must be an integer");
|
|
225
226
|
}
|
|
226
227
|
}
|
|
228
|
+
function validateDigitalCertificateMethod(method, signers) {
|
|
229
|
+
if (method !== "virtual" && signers.some((signer) => signer.verification_method === "DigitalCertificate")) {
|
|
230
|
+
throw new ValidationError("DigitalCertificate signers require method: virtual", {
|
|
231
|
+
code: "digital_certificate_requires_virtual"
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
227
235
|
function validateSigningSteps(signers) {
|
|
228
236
|
const withSteps = signers.filter((signer) => signer.step !== void 0);
|
|
229
237
|
if (withSteps.length > 0) {
|
|
@@ -400,15 +408,17 @@ function buildAssignmentPayload(payload, options = {}) {
|
|
|
400
408
|
signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
|
|
401
409
|
});
|
|
402
410
|
}
|
|
403
|
-
|
|
411
|
+
const method = payload.method ?? "virtual";
|
|
412
|
+
const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
|
|
413
|
+
validateDigitalCertificateMethod(method, normalisedSigners);
|
|
414
|
+
if (method === "collect" && !Array.isArray(payload.entries)) {
|
|
404
415
|
throw new ValidationError("entries are required for collect assignments");
|
|
405
416
|
}
|
|
406
|
-
const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
|
|
407
417
|
if (!options.skipDigitalCertificateStepValidation) {
|
|
408
418
|
validateSigningSteps(normalisedSigners);
|
|
409
419
|
}
|
|
410
420
|
return stripEmpty({
|
|
411
|
-
method
|
|
421
|
+
method,
|
|
412
422
|
signers: normalisedSigners,
|
|
413
423
|
message: payload.message,
|
|
414
424
|
expires_at: payload.expires_at === void 0 ? void 0 : requireIso8601(payload.expires_at, "expires_at"),
|
|
@@ -457,6 +467,53 @@ function normaliseSignerRef(ref, options) {
|
|
|
457
467
|
throw new ValidationError("Invalid signer reference", { ref });
|
|
458
468
|
}
|
|
459
469
|
var AssignmentResource = class extends BaseResource {
|
|
470
|
+
/** Fetch an account review and available evidence for a signer's identity verification. */
|
|
471
|
+
async getIdentityVerification(documentId, assignmentId, signerId) {
|
|
472
|
+
const docId = this.requireId(documentId, "Document ID");
|
|
473
|
+
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
474
|
+
const sid = this.requireId(signerId, "Signer ID");
|
|
475
|
+
return this.call(
|
|
476
|
+
"Failed to fetch signer identity review",
|
|
477
|
+
() => this.http.get(
|
|
478
|
+
`/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification`
|
|
479
|
+
)
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
/** Download JPEG/PNG evidence or the document PDF, available only while the review is open. */
|
|
483
|
+
async downloadIdentityVerificationImage(documentId, assignmentId, signerId, name) {
|
|
484
|
+
const docId = this.requireId(documentId, "Document ID");
|
|
485
|
+
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
486
|
+
const sid = this.requireId(signerId, "Signer ID");
|
|
487
|
+
if (!["document_front", "document_back", "document_pdf", "face"].includes(name)) {
|
|
488
|
+
throw new ValidationError("Unknown identity verification image name");
|
|
489
|
+
}
|
|
490
|
+
return this.callBinary(
|
|
491
|
+
"Failed to download identity review image",
|
|
492
|
+
() => this.http.get(
|
|
493
|
+
`/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification/images/${name}`,
|
|
494
|
+
{ responseType: "arraybuffer" }
|
|
495
|
+
)
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
/** Approve certification or reject/cancel the document; the optional note is private to reviewers. */
|
|
499
|
+
async reviewIdentityVerification(documentId, assignmentId, signerId, payload) {
|
|
500
|
+
const docId = this.requireId(documentId, "Document ID");
|
|
501
|
+
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
502
|
+
const sid = this.requireId(signerId, "Signer ID");
|
|
503
|
+
if (!payload || !["Approved", "Rejected"].includes(payload.decision)) {
|
|
504
|
+
throw new ValidationError("decision must be Approved or Rejected");
|
|
505
|
+
}
|
|
506
|
+
if (payload.note != null && (typeof payload.note !== "string" || [...payload.note].length > 2e3)) {
|
|
507
|
+
throw new ValidationError("note must contain at most 2000 characters");
|
|
508
|
+
}
|
|
509
|
+
return this.call(
|
|
510
|
+
"Failed to decide signer identity review",
|
|
511
|
+
() => this.http.post(
|
|
512
|
+
`/documents/${docId}/assignments/${asgId}/signers/${sid}/identity-verification/review`,
|
|
513
|
+
{ decision: payload.decision, note: payload.note }
|
|
514
|
+
)
|
|
515
|
+
);
|
|
516
|
+
}
|
|
460
517
|
/**
|
|
461
518
|
* List assignments across the account (`GET /assignments`).
|
|
462
519
|
*
|
|
@@ -711,6 +768,7 @@ var DOCUMENT_SORTS = ["name", "-name", "updated_at", "-updated_at"];
|
|
|
711
768
|
var READY_STATUSES = /* @__PURE__ */ new Set([
|
|
712
769
|
"metadata_ready",
|
|
713
770
|
"pending_signature",
|
|
771
|
+
"pending_identity_review",
|
|
714
772
|
"certificated"
|
|
715
773
|
]);
|
|
716
774
|
var FAILED_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -964,6 +1022,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
964
1022
|
if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag))) {
|
|
965
1023
|
throw new ValidationError("tags must contain non-empty tag names");
|
|
966
1024
|
}
|
|
1025
|
+
await this.validateCertificateTemplateMethod(tmplId, accId, signers);
|
|
967
1026
|
const body = { ...options, signers };
|
|
968
1027
|
this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
|
|
969
1028
|
return this.call(
|
|
@@ -976,6 +1035,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
976
1035
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
977
1036
|
const accId = this.accountId(accountId);
|
|
978
1037
|
validateTemplateSigners(signers, { requireId: false });
|
|
1038
|
+
await this.validateCertificateTemplateMethod(tmplId, accId, signers);
|
|
979
1039
|
return this.call(
|
|
980
1040
|
"Failed to estimate cost from template",
|
|
981
1041
|
() => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents/estimate-cost`, { signers })
|
|
@@ -1054,6 +1114,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
1054
1114
|
const percentage = total > 0 ? Math.round(signed / total * 1e4) / 100 : 0;
|
|
1055
1115
|
return { signed, total, pending, percentage };
|
|
1056
1116
|
}
|
|
1117
|
+
async validateCertificateTemplateMethod(templateId, accountId, signers) {
|
|
1118
|
+
if (!signers.some((signer) => signer.verification_method === "DigitalCertificate")) return;
|
|
1119
|
+
const template = await this.call(
|
|
1120
|
+
"Failed to fetch template",
|
|
1121
|
+
() => this.http.get(`/accounts/${accountId}/templates/${templateId}`)
|
|
1122
|
+
);
|
|
1123
|
+
const method = template.pages?.some((page) => page.fields.length > 0) ? "collect" : "virtual";
|
|
1124
|
+
validateDigitalCertificateMethod(method, signers);
|
|
1125
|
+
}
|
|
1057
1126
|
};
|
|
1058
1127
|
function validateTemplateSigners(signers, options) {
|
|
1059
1128
|
if (!Array.isArray(signers)) throw new ValidationError("signers must be an array");
|
|
@@ -1554,6 +1623,25 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
1554
1623
|
() => this.http.get("/signers/self", signerAccessConfig(code))
|
|
1555
1624
|
);
|
|
1556
1625
|
}
|
|
1626
|
+
/** `GET /signers/identity-verification` — session status, capture URL and restart eligibility. */
|
|
1627
|
+
async getIdentityVerification(signerAccessCode) {
|
|
1628
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
1629
|
+
return this.call(
|
|
1630
|
+
"Failed to fetch identity verification",
|
|
1631
|
+
() => this.http.get("/signers/identity-verification", signerAccessConfig(code))
|
|
1632
|
+
);
|
|
1633
|
+
}
|
|
1634
|
+
/** `POST /signers/identity-verification` — open a hosted session after the signer's explicit consent. */
|
|
1635
|
+
async startIdentityVerification(signerAccessCode, payload) {
|
|
1636
|
+
const code = this.requireId(signerAccessCode, "signer-access-code");
|
|
1637
|
+
if (payload?.consent !== true) {
|
|
1638
|
+
throw new ValidationError("Explicit biometric-processing consent is required");
|
|
1639
|
+
}
|
|
1640
|
+
return this.call(
|
|
1641
|
+
"Failed to start identity verification",
|
|
1642
|
+
() => this.http.post("/signers/identity-verification", { consent: true }, signerAccessConfig(code))
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1557
1645
|
/**
|
|
1558
1646
|
* `PUT /signers/accept-terms?signer-access-code=…` — accept the platform
|
|
1559
1647
|
* terms as the signer.
|
|
@@ -1857,9 +1945,10 @@ function normaliseSignerPayload(payload, useGovernmentId = false) {
|
|
|
1857
1945
|
email: payload.email,
|
|
1858
1946
|
whatsapp_phone_number: payload.whatsapp_phone_number ?? payload.phone
|
|
1859
1947
|
};
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1948
|
+
if (payload.government_id !== void 0) {
|
|
1949
|
+
normalised.government_id = payload.government_id;
|
|
1950
|
+
} else if (payload.cpf) {
|
|
1951
|
+
const digits = payload.cpf.replace(/\D/g, "");
|
|
1863
1952
|
if (digits) normalised[useGovernmentId ? "government_id" : "cpf"] = digits;
|
|
1864
1953
|
}
|
|
1865
1954
|
if ("metadata" in payload && payload.metadata !== void 0) {
|
|
@@ -2098,19 +2187,21 @@ var WebhookResource = class extends BaseResource {
|
|
|
2098
2187
|
() => this.http.put(`/accounts/${id}/webhooks/inactivate`)
|
|
2099
2188
|
);
|
|
2100
2189
|
}
|
|
2101
|
-
/**
|
|
2102
|
-
async listEndpoints(accountId) {
|
|
2190
|
+
/** List webhook endpoints, oldest first; `url` matches the registered value exactly. */
|
|
2191
|
+
async listEndpoints(accountId, params = {}) {
|
|
2103
2192
|
const id = this.accountId(accountId);
|
|
2193
|
+
validateWebhookFields(params);
|
|
2104
2194
|
return this.call(
|
|
2105
2195
|
"Failed to list webhook endpoints",
|
|
2106
|
-
() => this.http.get(`/accounts/${id}/webhooks/endpoints
|
|
2196
|
+
() => this.http.get(`/accounts/${id}/webhooks/endpoints`, { params: cleanParams({ ...params }) })
|
|
2107
2197
|
);
|
|
2108
2198
|
}
|
|
2109
2199
|
/**
|
|
2110
2200
|
* `POST /accounts/{accountId}/webhooks/endpoints` — register another
|
|
2111
2201
|
* endpoint. Accounts allow 1 endpoint, or up to 3 on paid plans (`403` past
|
|
2112
2202
|
* the limit); URLs must be unique per workspace. Omitted `events` uses the
|
|
2113
|
-
* same default set as {@link register}.
|
|
2203
|
+
* same default set as {@link register}. Signed creation returns `secret`
|
|
2204
|
+
* once, including to OAuth applications; save it securely.
|
|
2114
2205
|
*/
|
|
2115
2206
|
async createEndpoint(payload, accountId) {
|
|
2116
2207
|
if (!payload.url) throw new ValidationError("Webhook URL is required");
|
|
@@ -2158,6 +2249,16 @@ var WebhookResource = class extends BaseResource {
|
|
|
2158
2249
|
() => this.http.delete(`/accounts/${id}/webhooks/endpoints/${eid}`)
|
|
2159
2250
|
);
|
|
2160
2251
|
}
|
|
2252
|
+
/** Delete the endpoint whose URL exactly matches `url`; returns 404 when none matches. */
|
|
2253
|
+
async deleteEndpointByUrl(url, accountId) {
|
|
2254
|
+
if (!url) throw new ValidationError("Webhook URL is required");
|
|
2255
|
+
validateWebhookFields({ url });
|
|
2256
|
+
const id = this.accountId(accountId);
|
|
2257
|
+
return this.call(
|
|
2258
|
+
"Failed to delete webhook endpoint by URL",
|
|
2259
|
+
() => this.http.delete(`/accounts/${id}/webhooks/endpoints`, { params: { url } })
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2161
2262
|
/**
|
|
2162
2263
|
* `GET …/endpoints/{endpointId}/secret` — the `whsec_` signing secret.
|
|
2163
2264
|
* Returns `400` when signing is disabled. Not available to OAuth applications.
|
|
@@ -2315,12 +2416,10 @@ function readHeader(headers, name) {
|
|
|
2315
2416
|
if (typeof headers.get === "function") {
|
|
2316
2417
|
return headers.get(name) ?? void 0;
|
|
2317
2418
|
}
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
}
|
|
2323
|
-
return void 0;
|
|
2419
|
+
const matches = Object.entries(headers).filter(([key]) => key.toLowerCase() === name);
|
|
2420
|
+
if (matches.length !== 1) return void 0;
|
|
2421
|
+
const value = matches[0]?.[1];
|
|
2422
|
+
return Array.isArray(value) ? value.length === 1 ? value[0] : void 0 : value;
|
|
2324
2423
|
}
|
|
2325
2424
|
var WebhookVerifier = class {
|
|
2326
2425
|
constructor(webhookSecret, options = {}) {
|
|
@@ -2345,7 +2444,8 @@ var WebhookVerifier = class {
|
|
|
2345
2444
|
if (!id || !timestamp || !signatures || !/^\d+$/.test(timestamp)) return false;
|
|
2346
2445
|
const tolerance = options.toleranceSeconds ?? 300;
|
|
2347
2446
|
const now = Math.floor((options.now ?? Date.now()) / 1e3);
|
|
2348
|
-
if (Math.abs(now - Number(timestamp)) > tolerance)
|
|
2447
|
+
if (!Number.isFinite(tolerance) || tolerance < 0 || !Number.isSafeInteger(now) || now < 0 || !Number.isSafeInteger(Number(timestamp)) || Math.abs(now - Number(timestamp)) > tolerance)
|
|
2448
|
+
return false;
|
|
2349
2449
|
const secret = this.webhookSecret.startsWith("whsec_") ? this.webhookSecret.slice("whsec_".length) : this.webhookSecret;
|
|
2350
2450
|
const key = Buffer.from(secret, "base64");
|
|
2351
2451
|
if (key.length === 0) return false;
|
|
@@ -2353,8 +2453,8 @@ var WebhookVerifier = class {
|
|
|
2353
2453
|
createHmac("sha256", key).update(`${id}.${timestamp}.`).update(typeof payload === "string" ? Buffer.from(payload, "utf8") : payload).digest("base64")
|
|
2354
2454
|
);
|
|
2355
2455
|
return signatures.split(" ").some((entry) => {
|
|
2356
|
-
const [version, value] = entry.split(","
|
|
2357
|
-
if (version !== "v1" || !value) return false;
|
|
2456
|
+
const [version, value, extra] = entry.split(",");
|
|
2457
|
+
if (version !== "v1" || !value || extra !== void 0) return false;
|
|
2358
2458
|
const provided = Buffer.from(value);
|
|
2359
2459
|
return provided.length === expected.length && timingSafeEqual2(provided, expected);
|
|
2360
2460
|
});
|
|
@@ -2559,6 +2659,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2559
2659
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
2560
2660
|
if (phone !== void 0) payload.whatsapp_phone_number = phone;
|
|
2561
2661
|
if (signer.cpf !== void 0) payload.cpf = signer.cpf;
|
|
2662
|
+
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2562
2663
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2563
2664
|
validateCreateSignerPayload(payload);
|
|
2564
2665
|
return { signer, payload, phone };
|