@claritylabs/cl-sdk 3.0.30 → 3.0.32
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/index.js +76 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3313,6 +3313,15 @@ function moneyValue(value) {
|
|
|
3313
3313
|
if (/^\d{1,3}(?:,\d{3})*(?:\.\d{2})?$/.test(clean)) return `$${clean}`;
|
|
3314
3314
|
return clean;
|
|
3315
3315
|
}
|
|
3316
|
+
function premiumValue(value) {
|
|
3317
|
+
const clean = cleanValue(value);
|
|
3318
|
+
if (!clean) return void 0;
|
|
3319
|
+
if (/\$[A-Z0-9]/i.test(clean)) return clean;
|
|
3320
|
+
if (/\b(?:CAD|USD)\b/i.test(clean) && /(?:\d|X{2,})/i.test(clean)) return clean;
|
|
3321
|
+
if (/^\d{1,3}(?:,\d{3})+\.\d{2}$/.test(clean) || /^\d+\.\d{2}$/.test(clean)) return `$${clean}`;
|
|
3322
|
+
if (/^X{2,}(?:,X{3})*(?:\.X{2})$/i.test(clean)) return clean;
|
|
3323
|
+
return void 0;
|
|
3324
|
+
}
|
|
3316
3325
|
function nodeText(node) {
|
|
3317
3326
|
return normalizeWhitespace3([
|
|
3318
3327
|
node.title,
|
|
@@ -3370,6 +3379,62 @@ function policyNumberFromNodes(nodes) {
|
|
|
3370
3379
|
const candidate = candidates[0];
|
|
3371
3380
|
return candidate ? valueFromNode(candidate.node, candidate.value, "high") : void 0;
|
|
3372
3381
|
}
|
|
3382
|
+
function compactFactNodes(nodes) {
|
|
3383
|
+
return nodes.filter((node) => {
|
|
3384
|
+
if (node.kind === "document" || node.kind === "page_group" || node.kind === "form") return false;
|
|
3385
|
+
const text = nodeText(node);
|
|
3386
|
+
if (text.length > 900) return false;
|
|
3387
|
+
if (/\b(table of contents|provided solely for your convenience|not to be construed|actual policy issued)\b/i.test(text)) return false;
|
|
3388
|
+
return node.kind === "text" || node.kind === "table_row" || node.kind === "table_cell" || node.kind === "page";
|
|
3389
|
+
});
|
|
3390
|
+
}
|
|
3391
|
+
function firstCleanMatch(nodes, patterns, clean) {
|
|
3392
|
+
for (const node of compactFactNodes(nodes)) {
|
|
3393
|
+
const text = nodeText(node);
|
|
3394
|
+
for (const pattern of patterns) {
|
|
3395
|
+
const raw = cleanValue(text.match(pattern)?.[1]);
|
|
3396
|
+
if (!raw) continue;
|
|
3397
|
+
const value = clean(raw);
|
|
3398
|
+
if (value) return valueFromNode(node, value, "high");
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
return void 0;
|
|
3402
|
+
}
|
|
3403
|
+
function cleanNamedInsured(value) {
|
|
3404
|
+
const clean = cleanValue(value.replace(/\bborn\s+on\b.*$/i, "").replace(/\bage\s+nearest\b.*$/i, "").replace(/\bbeneficiary\b.*$/i, ""));
|
|
3405
|
+
if (!clean || clean.length > 160) return void 0;
|
|
3406
|
+
if (!/[A-Za-z0-9]/.test(clean)) return void 0;
|
|
3407
|
+
if (/^(person|persons)\b/i.test(clean)) return void 0;
|
|
3408
|
+
if (/^(insurance amount|benefit amount|policy number|policy date|owner|beneficiary|premium|coverage|risk classification)\b/i.test(clean)) {
|
|
3409
|
+
return void 0;
|
|
3410
|
+
}
|
|
3411
|
+
if (/\b(table of contents|policy wording|provided solely|convenience|not to be construed|actual policy issued)\b/i.test(clean)) {
|
|
3412
|
+
return void 0;
|
|
3413
|
+
}
|
|
3414
|
+
return clean;
|
|
3415
|
+
}
|
|
3416
|
+
function namedInsuredFromNodes(nodes) {
|
|
3417
|
+
return firstCleanMatch(nodes, [
|
|
3418
|
+
/\b(?:named insured|insured name)\s*:?\s*(.+?)(?=\s+(?:insurance amount|benefit amount|policy number|policy date|owner|beneficiary|premium|coverage|risk classification|date this)\b|[|;\n]|$)/i,
|
|
3419
|
+
/\b(?:insured persons?|insured person)\s*:\s*(.+?)(?=\s+(?:insurance amount|benefit amount|policy number|policy date|owner|beneficiary|premium|coverage|risk classification|date this)\b|[|;\n]|$)/i,
|
|
3420
|
+
/\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
|
|
3421
|
+
], cleanNamedInsured);
|
|
3422
|
+
}
|
|
3423
|
+
function cleanInsurer(value) {
|
|
3424
|
+
const clean = cleanValue(value);
|
|
3425
|
+
if (!clean || clean.length > 140) return void 0;
|
|
3426
|
+
if (/^(mean|means|we|us|our)\b/i.test(clean)) return void 0;
|
|
3427
|
+
if (/\b(table of contents|policy wording|provided solely|convenience)\b/i.test(clean)) return void 0;
|
|
3428
|
+
const known = clean.match(/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i)?.[1];
|
|
3429
|
+
return known ?? clean;
|
|
3430
|
+
}
|
|
3431
|
+
function insurerFromNodes(nodes) {
|
|
3432
|
+
return firstCleanMatch(nodes, [
|
|
3433
|
+
/\bunderwritten by\s+([^|;\n.]{3,160})/i,
|
|
3434
|
+
/\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
|
|
3435
|
+
/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i
|
|
3436
|
+
], cleanInsurer);
|
|
3437
|
+
}
|
|
3373
3438
|
function inferPolicyTypes(nodes) {
|
|
3374
3439
|
const text = nodes.slice(0, 40).map(nodeText).join(" ").toLowerCase();
|
|
3375
3440
|
const types = [];
|
|
@@ -3418,7 +3483,14 @@ function deductibleFromText(text) {
|
|
|
3418
3483
|
return moneyValue(text.match(/\b(?:deductible|retention|sir)\s*:?\s*(\$?\d[\d,]*(?:\.\d{2})?)/i)?.[1]);
|
|
3419
3484
|
}
|
|
3420
3485
|
function premiumFromText(text) {
|
|
3421
|
-
return
|
|
3486
|
+
return premiumValue(text.match(/\b(?:premium|total premium|total cost|amount due)\b(?:\s*(?:is|:|-))?\s*(\$?(?:\d[\d,]*(?:\.\d{2})?|X{2,}(?:,X{3})*(?:\.X{2})?))/i)?.[1]);
|
|
3487
|
+
}
|
|
3488
|
+
function premiumFromNodes(nodes) {
|
|
3489
|
+
for (const node of compactFactNodes(nodes)) {
|
|
3490
|
+
const value = premiumFromText(nodeText(node));
|
|
3491
|
+
if (value) return valueFromNode(node, value, "high");
|
|
3492
|
+
}
|
|
3493
|
+
return void 0;
|
|
3422
3494
|
}
|
|
3423
3495
|
function moneyAmount(value) {
|
|
3424
3496
|
const match = value?.match(/\$?\s*([0-9][0-9,]*(?:\.\d+)?)/);
|
|
@@ -3824,16 +3896,8 @@ function buildDeterministicOperationalProfile(params) {
|
|
|
3824
3896
|
documentType: inferDocumentType(nodes),
|
|
3825
3897
|
policyTypes: inferPolicyTypes(nodes),
|
|
3826
3898
|
policyNumber: policyNumberFromNodes(nodes),
|
|
3827
|
-
namedInsured:
|
|
3828
|
-
|
|
3829
|
-
/\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
|
|
3830
|
-
]),
|
|
3831
|
-
insurer: firstMatch(nodes, [
|
|
3832
|
-
/\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
|
|
3833
|
-
/\bunderwritten by\s+([^|;\n]{3,120})/i
|
|
3834
|
-
]) ?? firstMatch(nodes, [
|
|
3835
|
-
/\b(Manulife)\b/i
|
|
3836
|
-
]),
|
|
3899
|
+
namedInsured: namedInsuredFromNodes(nodes),
|
|
3900
|
+
insurer: insurerFromNodes(nodes),
|
|
3837
3901
|
broker: firstMatch(nodes, [
|
|
3838
3902
|
/\b(?:broker|producer|agent)\s*:?\s*([^|;\n]{3,120})/i
|
|
3839
3903
|
]),
|
|
@@ -3848,9 +3912,7 @@ function buildDeterministicOperationalProfile(params) {
|
|
|
3848
3912
|
retroactiveDate: firstMatch(nodes, [
|
|
3849
3913
|
/\bretroactive date\s*:?\s*([0-9]{1,2}[/-][0-9]{1,2}[/-][0-9]{2,4}|full prior acts|none)/i
|
|
3850
3914
|
]),
|
|
3851
|
-
premium:
|
|
3852
|
-
/\b(?:total premium|premium|total cost|amount due)\s*:?\s*(\$?\d[\d,]*(?:\.\d{2})?)/i
|
|
3853
|
-
])
|
|
3915
|
+
premium: premiumFromNodes(nodes)
|
|
3854
3916
|
};
|
|
3855
3917
|
const coverages = buildCoverages(nodes);
|
|
3856
3918
|
const coverageTypes = [...new Set(coverages.map((coverage) => coverage.name))];
|