@claritylabs/cl-sdk 3.1.0 → 3.1.2
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 +60 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3611,6 +3611,12 @@ function moneyAmount(value) {
|
|
|
3611
3611
|
function normalizeLabel(value) {
|
|
3612
3612
|
return normalizeWhitespace3(value ?? "").toLowerCase();
|
|
3613
3613
|
}
|
|
3614
|
+
function isGenericColumnLabel(value) {
|
|
3615
|
+
return /^column\s+\d+$/i.test(cleanValue(value) ?? "");
|
|
3616
|
+
}
|
|
3617
|
+
function isHeaderRow(row) {
|
|
3618
|
+
return row.metadata?.isHeader === true || row.metadata?.isHeader === "true";
|
|
3619
|
+
}
|
|
3614
3620
|
var OPERATIONAL_COVERAGE_TERM_KINDS = /* @__PURE__ */ new Set([
|
|
3615
3621
|
"each_claim_limit",
|
|
3616
3622
|
"each_occurrence_limit",
|
|
@@ -3631,6 +3637,7 @@ function termKind(label, value) {
|
|
|
3631
3637
|
if (/\bpremium\b/.test(text)) return "premium";
|
|
3632
3638
|
if (/\bsub[-\s]?limit\b/.test(text)) return "sublimit";
|
|
3633
3639
|
if (/\baggregate\b/.test(text)) return "aggregate_limit";
|
|
3640
|
+
if (/\beach\s+proceeding|per\s+proceeding\b/.test(text)) return "sublimit";
|
|
3634
3641
|
if (/\beach\s+claim|per\s+claim\b/.test(text)) return "each_claim_limit";
|
|
3635
3642
|
if (/\beach\s+occurrence|per\s+occurrence\b/.test(text)) return "each_occurrence_limit";
|
|
3636
3643
|
if (/\beach\s+loss|per\s+loss\b/.test(text)) return "each_loss_limit";
|
|
@@ -3657,9 +3664,13 @@ function isNameCell(label, value) {
|
|
|
3657
3664
|
const normalizedLabel = normalizeLabel(label);
|
|
3658
3665
|
const normalizedValue = normalizeLabel(value);
|
|
3659
3666
|
if (!value || moneyAmount(value) !== void 0) return false;
|
|
3667
|
+
if (/^item\s+\d+[.)]?\s*limits?\s+of\s+liability\b/.test(normalizedValue)) return false;
|
|
3660
3668
|
if (/\b(coverage|coverage part|insuring agreement|description|item|name)\b/.test(normalizedLabel)) {
|
|
3661
3669
|
return true;
|
|
3662
3670
|
}
|
|
3671
|
+
if (/\b(sub[-\s]?limit|aggregate(?:\s+policy)?\s+limit|limit\s+of\s+liability)\b/.test(normalizedLabel) && /\b[a-z][a-z0-9&/ -]{2,}\b/.test(normalizedValue) && !/\bcoverage\s+part\s+[a-z]\)?$/.test(normalizedValue)) {
|
|
3672
|
+
return true;
|
|
3673
|
+
}
|
|
3663
3674
|
if (/^column\s+1$/.test(normalizedLabel) && !/^(item\s+\d+|nwc-|iso-|cg |il |form\b|page\b)/i.test(normalizedValue)) {
|
|
3664
3675
|
return true;
|
|
3665
3676
|
}
|
|
@@ -3678,13 +3689,32 @@ function childMap(nodes) {
|
|
|
3678
3689
|
for (const group of children.values()) group.sort((left, right) => left.order - right.order);
|
|
3679
3690
|
return children;
|
|
3680
3691
|
}
|
|
3681
|
-
function
|
|
3692
|
+
function rawCellRows(row, children) {
|
|
3682
3693
|
return (children.get(row.id) ?? []).filter((child) => child.kind === "table_cell").map((cell) => ({
|
|
3683
3694
|
label: cleanValue(cell.title) ?? "Value",
|
|
3684
3695
|
value: cleanValue(cell.textExcerpt ?? cell.description ?? cell.title) ?? "",
|
|
3685
3696
|
node: cell
|
|
3686
3697
|
})).filter((cell) => cell.value);
|
|
3687
3698
|
}
|
|
3699
|
+
function headerLabelsForRow(row, children) {
|
|
3700
|
+
if (!row.parentId) return [];
|
|
3701
|
+
const labels = [];
|
|
3702
|
+
const siblingRows = (children.get(row.parentId) ?? []).filter((candidate) => candidate.kind === "table_row" && candidate.order < row.order).sort((left, right) => left.order - right.order);
|
|
3703
|
+
for (const sibling of siblingRows) {
|
|
3704
|
+
if (!isHeaderRow(sibling)) continue;
|
|
3705
|
+
for (const [index, cell] of rawCellRows(sibling, children).entries()) {
|
|
3706
|
+
const label = cleanValue(cell.value) ?? cleanValue(cell.label);
|
|
3707
|
+
if (label && !isGenericColumnLabel(label)) labels[index] = label;
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
return labels;
|
|
3711
|
+
}
|
|
3712
|
+
function cellRows(row, children, headerLabels = []) {
|
|
3713
|
+
return rawCellRows(row, children).map((cell, index) => ({
|
|
3714
|
+
...cell,
|
|
3715
|
+
label: isGenericColumnLabel(cell.label) && headerLabels[index] ? headerLabels[index] : cell.label
|
|
3716
|
+
}));
|
|
3717
|
+
}
|
|
3688
3718
|
function directChildren(parent, children) {
|
|
3689
3719
|
return children.get(parent.id) ?? [];
|
|
3690
3720
|
}
|
|
@@ -3737,8 +3767,9 @@ function relabelGenericTerm(term, label) {
|
|
|
3737
3767
|
};
|
|
3738
3768
|
}
|
|
3739
3769
|
function termFromCell(params) {
|
|
3740
|
-
const value =
|
|
3770
|
+
const value = cleanCoverageTermValue(params.value);
|
|
3741
3771
|
if (!value) return void 0;
|
|
3772
|
+
if (isRejectedCoverageTermValue(params.label, value)) return void 0;
|
|
3742
3773
|
const nodes = [params.row, params.cell].filter((node) => Boolean(node));
|
|
3743
3774
|
const kind = termKind(params.label, value);
|
|
3744
3775
|
const amount = moneyAmount(value);
|
|
@@ -3751,20 +3782,38 @@ function termFromCell(params) {
|
|
|
3751
3782
|
...sourceIds(nodes)
|
|
3752
3783
|
};
|
|
3753
3784
|
}
|
|
3785
|
+
function cleanCoverageTermValue(value) {
|
|
3786
|
+
return cleanValue(value)?.replace(/\s+\/\s*$/, "").trim();
|
|
3787
|
+
}
|
|
3788
|
+
function isRejectedCoverageTermValue(label, value) {
|
|
3789
|
+
if (/\bshown\s+in\s+item\s*\d+\b/i.test(value) && moneyAmount(value) === void 0) return true;
|
|
3790
|
+
if (/\b(does not afford coverage|doesn't afford coverage|no coverage|remains excluded|is excluded|are excluded|shall not cover|will not cover)\b/i.test(value) && moneyAmount(value) === void 0) {
|
|
3791
|
+
return true;
|
|
3792
|
+
}
|
|
3793
|
+
if (/^for:\s*\(\d+\)/i.test(label) && moneyAmount(value) === void 0) return true;
|
|
3794
|
+
if (value.length > 80 && /\b(exclusion|excluded|shall not|will not|does not|failure to)\b/i.test(value) && moneyAmount(value) === void 0) return true;
|
|
3795
|
+
return false;
|
|
3796
|
+
}
|
|
3754
3797
|
function termsFromRow(row, children) {
|
|
3755
|
-
const cells = cellRows(row, children);
|
|
3798
|
+
const cells = cellRows(row, children, headerLabelsForRow(row, children));
|
|
3756
3799
|
if (cells.length > 0) {
|
|
3757
3800
|
const pairedTerms = [];
|
|
3801
|
+
const pairedIndexes = /* @__PURE__ */ new Set();
|
|
3758
3802
|
for (const [index, cell] of cells.entries()) {
|
|
3759
3803
|
const next = cells[index + 1];
|
|
3760
3804
|
if (!next) continue;
|
|
3805
|
+
if (!isGenericColumnLabel(cell.label) && isNameCell(cell.label, cell.value)) continue;
|
|
3761
3806
|
if (!isCoverageTermLabel(cell.value)) continue;
|
|
3762
3807
|
if (isCoverageTermLabel(next.value) && moneyAmount(next.value) === void 0) continue;
|
|
3763
3808
|
const term = termFromCell({ row, cell: next.node, label: cell.value, value: next.value });
|
|
3764
|
-
if (term)
|
|
3809
|
+
if (term) {
|
|
3810
|
+
pairedTerms.push(term);
|
|
3811
|
+
pairedIndexes.add(index);
|
|
3812
|
+
pairedIndexes.add(index + 1);
|
|
3813
|
+
}
|
|
3765
3814
|
}
|
|
3766
|
-
|
|
3767
|
-
return
|
|
3815
|
+
const valueTerms = cells.filter((_, index) => !pairedIndexes.has(index)).filter((cell) => isValueCell(cell.label, cell.value)).map((cell) => termFromCell({ row, cell: cell.node, label: cell.label, value: cell.value })).filter((term) => Boolean(term));
|
|
3816
|
+
return [...pairedTerms, ...valueTerms];
|
|
3768
3817
|
}
|
|
3769
3818
|
const text = normalizeWhitespace3(row.textExcerpt ?? row.description ?? nodeText(row));
|
|
3770
3819
|
const terms = [];
|
|
@@ -3790,11 +3839,11 @@ function termsFromRow(row, children) {
|
|
|
3790
3839
|
return terms;
|
|
3791
3840
|
}
|
|
3792
3841
|
function nameFromRow(row, children) {
|
|
3793
|
-
const
|
|
3794
|
-
if (declarationName) return declarationName;
|
|
3795
|
-
const cells = cellRows(row, children);
|
|
3842
|
+
const cells = cellRows(row, children, headerLabelsForRow(row, children));
|
|
3796
3843
|
const named = cells.find((cell) => isNameCell(cell.label, cell.value));
|
|
3797
3844
|
if (named) return cleanValue(named.value);
|
|
3845
|
+
const declarationName = declarationCoverageNameFromRow(row, children);
|
|
3846
|
+
if (declarationName) return declarationName;
|
|
3798
3847
|
return coverageNameFromRow(row.textExcerpt ?? row.description ?? nodeText(row));
|
|
3799
3848
|
}
|
|
3800
3849
|
function legacyLimit(terms) {
|
|
@@ -3827,7 +3876,7 @@ function isOperationalCoverageRow(coverage) {
|
|
|
3827
3876
|
if (coverage.name.split(/\s+/).length > 16 && !/\b(coverage|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence)|limit)\b/i.test(coverage.name)) {
|
|
3828
3877
|
return false;
|
|
3829
3878
|
}
|
|
3830
|
-
return /\b(coverage|coverage part|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence)|bricking|cyber|privacy|media|regulatory|defense|ai\/ml|errors?\s*&?\s*omissions|technology)\b/i.test(coverage.name);
|
|
3879
|
+
return /\b(coverage|coverage part|liability|sub[-\s]?limit|aggregate|each\s+(claim|loss|occurrence|proceeding)|bricking|cyber|privacy|media|regulatory|defense|fraud|social engineering|ai\/ml|errors?\s*&?\s*omissions|technology)\b/i.test(coverage.name);
|
|
3831
3880
|
}
|
|
3832
3881
|
function uniqueTerms(terms) {
|
|
3833
3882
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3841,7 +3890,7 @@ function uniqueTerms(terms) {
|
|
|
3841
3890
|
return result;
|
|
3842
3891
|
}
|
|
3843
3892
|
function coverageFromTableRow(row, children, byId) {
|
|
3844
|
-
if (row
|
|
3893
|
+
if (isHeaderRow(row)) return void 0;
|
|
3845
3894
|
const name = nameFromRow(row, children);
|
|
3846
3895
|
const terms = uniqueTerms(termsFromRow(row, children));
|
|
3847
3896
|
if (!name || terms.length === 0) return void 0;
|