@claritylabs/cl-sdk 3.0.29 → 3.0.31
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 +86 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3339,6 +3339,88 @@ function firstMatch(nodes, patterns) {
|
|
|
3339
3339
|
}
|
|
3340
3340
|
return void 0;
|
|
3341
3341
|
}
|
|
3342
|
+
var POLICY_NUMBER_PATTERNS = [
|
|
3343
|
+
/\bpolicy\s*(?:number|no\.?|#)\s*:?\s*([A-Z0-9][A-Z0-9,.-]{4,}[A-Z0-9])/i,
|
|
3344
|
+
/\bpolicy\s*[:#]\s*([A-Z0-9][A-Z0-9,.-]{4,}[A-Z0-9])/i
|
|
3345
|
+
];
|
|
3346
|
+
function policyNumberEvidenceScore(node) {
|
|
3347
|
+
const text = normalizeWhitespace3([node.path, nodeText(node)].filter(Boolean).join(" ")).toLowerCase();
|
|
3348
|
+
let score = 0;
|
|
3349
|
+
if (/\b(policy\s+summary|declarations?|declaration\s+page|schedule)\b/.test(text)) score += 80;
|
|
3350
|
+
if (/\b(plan|policy\s+date|insured\s+person|named\s+insured|insurance\s+amount|benefit\s+amount)\b/.test(text)) score += 35;
|
|
3351
|
+
if (node.kind === "table_row" || node.kind === "table_cell" || node.kind === "text") score += 20;
|
|
3352
|
+
if (node.kind === "page") score += 10;
|
|
3353
|
+
if (typeof node.pageStart === "number" && node.pageStart > 1 && node.pageStart <= 10) score += 20;
|
|
3354
|
+
if (typeof node.pageStart === "number" && node.pageStart === 1) score -= 30;
|
|
3355
|
+
if (/\b(notices?\s+and\s+jacket|policy\s+jacket|front\s+matter|table\s+of\s+contents)\b/.test(text)) score -= 70;
|
|
3356
|
+
if (node.kind === "page_group" || node.kind === "form") score -= 30;
|
|
3357
|
+
return score;
|
|
3358
|
+
}
|
|
3359
|
+
function policyNumberFromNodes(nodes) {
|
|
3360
|
+
const candidates = nodes.slice(0, 120).flatMap((node) => {
|
|
3361
|
+
const text = nodeText(node);
|
|
3362
|
+
for (const pattern of POLICY_NUMBER_PATTERNS) {
|
|
3363
|
+
const value = cleanValue(text.match(pattern)?.[1]);
|
|
3364
|
+
if (value) return [{ node, value, score: policyNumberEvidenceScore(node) }];
|
|
3365
|
+
}
|
|
3366
|
+
return [];
|
|
3367
|
+
}).sort(
|
|
3368
|
+
(left, right) => right.score - left.score || (left.node.pageStart ?? Number.MAX_SAFE_INTEGER) - (right.node.pageStart ?? Number.MAX_SAFE_INTEGER) || left.node.order - right.node.order
|
|
3369
|
+
);
|
|
3370
|
+
const candidate = candidates[0];
|
|
3371
|
+
return candidate ? valueFromNode(candidate.node, candidate.value, "high") : void 0;
|
|
3372
|
+
}
|
|
3373
|
+
function compactFactNodes(nodes) {
|
|
3374
|
+
return nodes.filter((node) => {
|
|
3375
|
+
if (node.kind === "document" || node.kind === "page_group" || node.kind === "form") return false;
|
|
3376
|
+
const text = nodeText(node);
|
|
3377
|
+
if (text.length > 900) return false;
|
|
3378
|
+
if (/\b(table of contents|provided solely for your convenience|not to be construed|actual policy issued)\b/i.test(text)) return false;
|
|
3379
|
+
return node.kind === "text" || node.kind === "table_row" || node.kind === "table_cell" || node.kind === "page";
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
function firstCleanMatch(nodes, patterns, clean) {
|
|
3383
|
+
for (const node of compactFactNodes(nodes)) {
|
|
3384
|
+
const text = nodeText(node);
|
|
3385
|
+
for (const pattern of patterns) {
|
|
3386
|
+
const raw = cleanValue(text.match(pattern)?.[1]);
|
|
3387
|
+
if (!raw) continue;
|
|
3388
|
+
const value = clean(raw);
|
|
3389
|
+
if (value) return valueFromNode(node, value, "high");
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
return void 0;
|
|
3393
|
+
}
|
|
3394
|
+
function cleanNamedInsured(value) {
|
|
3395
|
+
const clean = cleanValue(value.replace(/\bborn\s+on\b.*$/i, "").replace(/\bage\s+nearest\b.*$/i, "").replace(/\bbeneficiary\b.*$/i, ""));
|
|
3396
|
+
if (!clean || clean.length > 160) return void 0;
|
|
3397
|
+
if (/^(person|persons)\b/i.test(clean)) return void 0;
|
|
3398
|
+
if (/\b(table of contents|policy wording|provided solely|convenience|not to be construed|actual policy issued)\b/i.test(clean)) {
|
|
3399
|
+
return void 0;
|
|
3400
|
+
}
|
|
3401
|
+
return clean;
|
|
3402
|
+
}
|
|
3403
|
+
function namedInsuredFromNodes(nodes) {
|
|
3404
|
+
return firstCleanMatch(nodes, [
|
|
3405
|
+
/\b(?:named insured|insured name|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,
|
|
3406
|
+
/\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
|
|
3407
|
+
], cleanNamedInsured);
|
|
3408
|
+
}
|
|
3409
|
+
function cleanInsurer(value) {
|
|
3410
|
+
const clean = cleanValue(value);
|
|
3411
|
+
if (!clean || clean.length > 140) return void 0;
|
|
3412
|
+
if (/^(mean|means|we|us|our)\b/i.test(clean)) return void 0;
|
|
3413
|
+
if (/\b(table of contents|policy wording|provided solely|convenience)\b/i.test(clean)) return void 0;
|
|
3414
|
+
const known = clean.match(/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i)?.[1];
|
|
3415
|
+
return known ?? clean;
|
|
3416
|
+
}
|
|
3417
|
+
function insurerFromNodes(nodes) {
|
|
3418
|
+
return firstCleanMatch(nodes, [
|
|
3419
|
+
/\bunderwritten by\s+([^|;\n.]{3,160})/i,
|
|
3420
|
+
/\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
|
|
3421
|
+
/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i
|
|
3422
|
+
], cleanInsurer);
|
|
3423
|
+
}
|
|
3342
3424
|
function inferPolicyTypes(nodes) {
|
|
3343
3425
|
const text = nodes.slice(0, 40).map(nodeText).join(" ").toLowerCase();
|
|
3344
3426
|
const types = [];
|
|
@@ -3792,20 +3874,9 @@ function buildDeterministicOperationalProfile(params) {
|
|
|
3792
3874
|
const partial = {
|
|
3793
3875
|
documentType: inferDocumentType(nodes),
|
|
3794
3876
|
policyTypes: inferPolicyTypes(nodes),
|
|
3795
|
-
policyNumber:
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
]),
|
|
3799
|
-
namedInsured: firstMatch(nodes, [
|
|
3800
|
-
/\b(?:named insured|insured name|insured)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i,
|
|
3801
|
-
/\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
|
|
3802
|
-
]),
|
|
3803
|
-
insurer: firstMatch(nodes, [
|
|
3804
|
-
/\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
|
|
3805
|
-
/\bunderwritten by\s+([^|;\n]{3,120})/i
|
|
3806
|
-
]) ?? firstMatch(nodes, [
|
|
3807
|
-
/\b(Manulife)\b/i
|
|
3808
|
-
]),
|
|
3877
|
+
policyNumber: policyNumberFromNodes(nodes),
|
|
3878
|
+
namedInsured: namedInsuredFromNodes(nodes),
|
|
3879
|
+
insurer: insurerFromNodes(nodes),
|
|
3809
3880
|
broker: firstMatch(nodes, [
|
|
3810
3881
|
/\b(?:broker|producer|agent)\s*:?\s*([^|;\n]{3,120})/i
|
|
3811
3882
|
]),
|
|
@@ -11105,6 +11176,7 @@ Rules:
|
|
|
11105
11176
|
- Every returned value must include sourceNodeIds or sourceSpanIds from the provided nodes.
|
|
11106
11177
|
- If a value is not directly supported, omit it.
|
|
11107
11178
|
- Prefer declarations, schedules, premium tables, and endorsement schedules over generic policy wording.
|
|
11179
|
+
- For life, critical illness, disability, and long-term care policies, keep named benefit units and benefit subconditions as operational facts even when they do not have dollar limits. Examples include death benefit, disability benefit, total disability, catastrophic disability, return of premium, waiver, and conversion options. Put subcondition details in coverages[].limits with kind "other" when they belong under a broader benefit.
|
|
11108
11180
|
- Treat an endorsement as one coverage unit when it contains a schedule. Do not split an endorsement schedule into generic rows like "Aggregate Limit".
|
|
11109
11181
|
- For coverage schedules, put each claim, aggregate, sublimit, retention, deductible, and retroactive date values in coverages[].limits with labels and source IDs. Keep the legacy coverages[].limit as the primary display value only.
|
|
11110
11182
|
- Use coverageOrigin: "endorsement" for endorsement units and "core" for declarations/core policy coverage units.
|