@claritylabs/cl-sdk 3.0.30 → 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.mjs CHANGED
@@ -3014,6 +3014,57 @@ function policyNumberFromNodes(nodes) {
3014
3014
  const candidate = candidates[0];
3015
3015
  return candidate ? valueFromNode(candidate.node, candidate.value, "high") : void 0;
3016
3016
  }
3017
+ function compactFactNodes(nodes) {
3018
+ return nodes.filter((node) => {
3019
+ if (node.kind === "document" || node.kind === "page_group" || node.kind === "form") return false;
3020
+ const text = nodeText(node);
3021
+ if (text.length > 900) return false;
3022
+ if (/\b(table of contents|provided solely for your convenience|not to be construed|actual policy issued)\b/i.test(text)) return false;
3023
+ return node.kind === "text" || node.kind === "table_row" || node.kind === "table_cell" || node.kind === "page";
3024
+ });
3025
+ }
3026
+ function firstCleanMatch(nodes, patterns, clean) {
3027
+ for (const node of compactFactNodes(nodes)) {
3028
+ const text = nodeText(node);
3029
+ for (const pattern of patterns) {
3030
+ const raw = cleanValue(text.match(pattern)?.[1]);
3031
+ if (!raw) continue;
3032
+ const value = clean(raw);
3033
+ if (value) return valueFromNode(node, value, "high");
3034
+ }
3035
+ }
3036
+ return void 0;
3037
+ }
3038
+ function cleanNamedInsured(value) {
3039
+ const clean = cleanValue(value.replace(/\bborn\s+on\b.*$/i, "").replace(/\bage\s+nearest\b.*$/i, "").replace(/\bbeneficiary\b.*$/i, ""));
3040
+ if (!clean || clean.length > 160) return void 0;
3041
+ if (/^(person|persons)\b/i.test(clean)) return void 0;
3042
+ if (/\b(table of contents|policy wording|provided solely|convenience|not to be construed|actual policy issued)\b/i.test(clean)) {
3043
+ return void 0;
3044
+ }
3045
+ return clean;
3046
+ }
3047
+ function namedInsuredFromNodes(nodes) {
3048
+ return firstCleanMatch(nodes, [
3049
+ /\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,
3050
+ /\b(?:applicant|policyholder)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i
3051
+ ], cleanNamedInsured);
3052
+ }
3053
+ function cleanInsurer(value) {
3054
+ const clean = cleanValue(value);
3055
+ if (!clean || clean.length > 140) return void 0;
3056
+ if (/^(mean|means|we|us|our)\b/i.test(clean)) return void 0;
3057
+ if (/\b(table of contents|policy wording|provided solely|convenience)\b/i.test(clean)) return void 0;
3058
+ const known = clean.match(/\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i)?.[1];
3059
+ return known ?? clean;
3060
+ }
3061
+ function insurerFromNodes(nodes) {
3062
+ return firstCleanMatch(nodes, [
3063
+ /\bunderwritten by\s+([^|;\n.]{3,160})/i,
3064
+ /\b(?:insurer|carrier|company|security)\s*:?\s*([^|;\n]{3,120})/i,
3065
+ /\b(Sun Life Assurance Company of Canada|Manulife|The Manufacturers Life Insurance Company)\b/i
3066
+ ], cleanInsurer);
3067
+ }
3017
3068
  function inferPolicyTypes(nodes) {
3018
3069
  const text = nodes.slice(0, 40).map(nodeText).join(" ").toLowerCase();
3019
3070
  const types = [];
@@ -3468,16 +3519,8 @@ function buildDeterministicOperationalProfile(params) {
3468
3519
  documentType: inferDocumentType(nodes),
3469
3520
  policyTypes: inferPolicyTypes(nodes),
3470
3521
  policyNumber: policyNumberFromNodes(nodes),
3471
- namedInsured: firstMatch(nodes, [
3472
- /\b(?:named insured|insured name|insured)\s*:?\s*(.+?)(?=\s+(?:coverage|policy number|insurer|carrier|premium|effective|expiration)\b|[|;\n]|$)/i,
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
- ]),
3522
+ namedInsured: namedInsuredFromNodes(nodes),
3523
+ insurer: insurerFromNodes(nodes),
3481
3524
  broker: firstMatch(nodes, [
3482
3525
  /\b(?:broker|producer|agent)\s*:?\s*([^|;\n]{3,120})/i
3483
3526
  ]),