@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.mjs
CHANGED
|
@@ -2957,6 +2957,15 @@ function moneyValue(value) {
|
|
|
2957
2957
|
if (/^\d{1,3}(?:,\d{3})*(?:\.\d{2})?$/.test(clean)) return `$${clean}`;
|
|
2958
2958
|
return clean;
|
|
2959
2959
|
}
|
|
2960
|
+
function premiumValue(value) {
|
|
2961
|
+
const clean = cleanValue(value);
|
|
2962
|
+
if (!clean) return void 0;
|
|
2963
|
+
if (/\$[A-Z0-9]/i.test(clean)) return clean;
|
|
2964
|
+
if (/\b(?:CAD|USD)\b/i.test(clean) && /(?:\d|X{2,})/i.test(clean)) return clean;
|
|
2965
|
+
if (/^\d{1,3}(?:,\d{3})+\.\d{2}$/.test(clean) || /^\d+\.\d{2}$/.test(clean)) return `$${clean}`;
|
|
2966
|
+
if (/^X{2,}(?:,X{3})*(?:\.X{2})$/i.test(clean)) return clean;
|
|
2967
|
+
return void 0;
|
|
2968
|
+
}
|
|
2960
2969
|
function nodeText(node) {
|
|
2961
2970
|
return normalizeWhitespace3([
|
|
2962
2971
|
node.title,
|
|
@@ -3014,6 +3023,62 @@ function policyNumberFromNodes(nodes) {
|
|
|
3014
3023
|
const candidate = candidates[0];
|
|
3015
3024
|
return candidate ? valueFromNode(candidate.node, candidate.value, "high") : void 0;
|
|
3016
3025
|
}
|
|
3026
|
+
function compactFactNodes(nodes) {
|
|
3027
|
+
return nodes.filter((node) => {
|
|
3028
|
+
if (node.kind === "document" || node.kind === "page_group" || node.kind === "form") return false;
|
|
3029
|
+
const text = nodeText(node);
|
|
3030
|
+
if (text.length > 900) return false;
|
|
3031
|
+
if (/\b(table of contents|provided solely for your convenience|not to be construed|actual policy issued)\b/i.test(text)) return false;
|
|
3032
|
+
return node.kind === "text" || node.kind === "table_row" || node.kind === "table_cell" || node.kind === "page";
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
function firstCleanMatch(nodes, patterns, clean) {
|
|
3036
|
+
for (const node of compactFactNodes(nodes)) {
|
|
3037
|
+
const text = nodeText(node);
|
|
3038
|
+
for (const pattern of patterns) {
|
|
3039
|
+
const raw = cleanValue(text.match(pattern)?.[1]);
|
|
3040
|
+
if (!raw) continue;
|
|
3041
|
+
const value = clean(raw);
|
|
3042
|
+
if (value) return valueFromNode(node, value, "high");
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
return void 0;
|
|
3046
|
+
}
|
|
3047
|
+
function cleanNamedInsured(value) {
|
|
3048
|
+
const clean = cleanValue(value.replace(/\bborn\s+on\b.*$/i, "").replace(/\bage\s+nearest\b.*$/i, "").replace(/\bbeneficiary\b.*$/i, ""));
|
|
3049
|
+
if (!clean || clean.length > 160) return void 0;
|
|
3050
|
+
if (!/[A-Za-z0-9]/.test(clean)) return void 0;
|
|
3051
|
+
if (/^(person|persons)\b/i.test(clean)) return void 0;
|
|
3052
|
+
if (/^(insurance amount|benefit amount|policy number|policy date|owner|beneficiary|premium|coverage|risk classification)\b/i.test(clean)) {
|
|
3053
|
+
return void 0;
|
|
3054
|
+
}
|
|
3055
|
+
if (/\b(table of contents|policy wording|provided solely|convenience|not to be construed|actual policy issued)\b/i.test(clean)) {
|
|
3056
|
+
return void 0;
|
|
3057
|
+
}
|
|
3058
|
+
return clean;
|
|
3059
|
+
}
|
|
3060
|
+
function namedInsuredFromNodes(nodes) {
|
|
3061
|
+
return firstCleanMatch(nodes, [
|
|
3062
|
+
/\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,
|
|
3063
|
+
/\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,
|
|
3064
|
+
/\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
|
|
3065
|
+
], cleanNamedInsured);
|
|
3066
|
+
}
|
|
3067
|
+
function cleanInsurer(value) {
|
|
3068
|
+
const clean = cleanValue(value);
|
|
3069
|
+
if (!clean || clean.length > 140) return void 0;
|
|
3070
|
+
if (/^(mean|means|we|us|our)\b/i.test(clean)) return void 0;
|
|
3071
|
+
if (/\b(table of contents|policy wording|provided solely|convenience)\b/i.test(clean)) return void 0;
|
|
3072
|
+
const known = clean.match(/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i)?.[1];
|
|
3073
|
+
return known ?? clean;
|
|
3074
|
+
}
|
|
3075
|
+
function insurerFromNodes(nodes) {
|
|
3076
|
+
return firstCleanMatch(nodes, [
|
|
3077
|
+
/\bunderwritten by\s+([^|;\n.]{3,160})/i,
|
|
3078
|
+
/\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
|
|
3079
|
+
/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i
|
|
3080
|
+
], cleanInsurer);
|
|
3081
|
+
}
|
|
3017
3082
|
function inferPolicyTypes(nodes) {
|
|
3018
3083
|
const text = nodes.slice(0, 40).map(nodeText).join(" ").toLowerCase();
|
|
3019
3084
|
const types = [];
|
|
@@ -3062,7 +3127,14 @@ function deductibleFromText(text) {
|
|
|
3062
3127
|
return moneyValue(text.match(/\b(?:deductible|retention|sir)\s*:?\s*(\$?\d[\d,]*(?:\.\d{2})?)/i)?.[1]);
|
|
3063
3128
|
}
|
|
3064
3129
|
function premiumFromText(text) {
|
|
3065
|
-
return
|
|
3130
|
+
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]);
|
|
3131
|
+
}
|
|
3132
|
+
function premiumFromNodes(nodes) {
|
|
3133
|
+
for (const node of compactFactNodes(nodes)) {
|
|
3134
|
+
const value = premiumFromText(nodeText(node));
|
|
3135
|
+
if (value) return valueFromNode(node, value, "high");
|
|
3136
|
+
}
|
|
3137
|
+
return void 0;
|
|
3066
3138
|
}
|
|
3067
3139
|
function moneyAmount(value) {
|
|
3068
3140
|
const match = value?.match(/\$?\s*([0-9][0-9,]*(?:\.\d+)?)/);
|
|
@@ -3468,16 +3540,8 @@ function buildDeterministicOperationalProfile(params) {
|
|
|
3468
3540
|
documentType: inferDocumentType(nodes),
|
|
3469
3541
|
policyTypes: inferPolicyTypes(nodes),
|
|
3470
3542
|
policyNumber: policyNumberFromNodes(nodes),
|
|
3471
|
-
namedInsured:
|
|
3472
|
-
|
|
3473
|
-
/\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
|
|
3474
|
-
]),
|
|
3475
|
-
insurer: firstMatch(nodes, [
|
|
3476
|
-
/\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
|
|
3477
|
-
/\bunderwritten by\s+([^|;\n]{3,120})/i
|
|
3478
|
-
]) ?? firstMatch(nodes, [
|
|
3479
|
-
/\b(Manulife)\b/i
|
|
3480
|
-
]),
|
|
3543
|
+
namedInsured: namedInsuredFromNodes(nodes),
|
|
3544
|
+
insurer: insurerFromNodes(nodes),
|
|
3481
3545
|
broker: firstMatch(nodes, [
|
|
3482
3546
|
/\b(?:broker|producer|agent)\s*:?\s*([^|;\n]{3,120})/i
|
|
3483
3547
|
]),
|
|
@@ -3492,9 +3556,7 @@ function buildDeterministicOperationalProfile(params) {
|
|
|
3492
3556
|
retroactiveDate: firstMatch(nodes, [
|
|
3493
3557
|
/\bretroactive date\s*:?\s*([0-9]{1,2}[/-][0-9]{1,2}[/-][0-9]{2,4}|full prior acts|none)/i
|
|
3494
3558
|
]),
|
|
3495
|
-
premium:
|
|
3496
|
-
/\b(?:total premium|premium|total cost|amount due)\s*:?\s*(\$?\d[\d,]*(?:\.\d{2})?)/i
|
|
3497
|
-
])
|
|
3559
|
+
premium: premiumFromNodes(nodes)
|
|
3498
3560
|
};
|
|
3499
3561
|
const coverages = buildCoverages(nodes);
|
|
3500
3562
|
const coverageTypes = [...new Set(coverages.map((coverage) => coverage.name))];
|