@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.mjs
CHANGED
|
@@ -3235,6 +3235,12 @@ function moneyAmount(value) {
|
|
|
3235
3235
|
function normalizeLabel(value) {
|
|
3236
3236
|
return normalizeWhitespace3(value ?? "").toLowerCase();
|
|
3237
3237
|
}
|
|
3238
|
+
function isGenericColumnLabel(value) {
|
|
3239
|
+
return /^column\s+\d+$/i.test(cleanValue(value) ?? "");
|
|
3240
|
+
}
|
|
3241
|
+
function isHeaderRow(row) {
|
|
3242
|
+
return row.metadata?.isHeader === true || row.metadata?.isHeader === "true";
|
|
3243
|
+
}
|
|
3238
3244
|
var OPERATIONAL_COVERAGE_TERM_KINDS = /* @__PURE__ */ new Set([
|
|
3239
3245
|
"each_claim_limit",
|
|
3240
3246
|
"each_occurrence_limit",
|
|
@@ -3255,6 +3261,7 @@ function termKind(label, value) {
|
|
|
3255
3261
|
if (/\bpremium\b/.test(text)) return "premium";
|
|
3256
3262
|
if (/\bsub[-\s]?limit\b/.test(text)) return "sublimit";
|
|
3257
3263
|
if (/\baggregate\b/.test(text)) return "aggregate_limit";
|
|
3264
|
+
if (/\beach\s+proceeding|per\s+proceeding\b/.test(text)) return "sublimit";
|
|
3258
3265
|
if (/\beach\s+claim|per\s+claim\b/.test(text)) return "each_claim_limit";
|
|
3259
3266
|
if (/\beach\s+occurrence|per\s+occurrence\b/.test(text)) return "each_occurrence_limit";
|
|
3260
3267
|
if (/\beach\s+loss|per\s+loss\b/.test(text)) return "each_loss_limit";
|
|
@@ -3281,9 +3288,13 @@ function isNameCell(label, value) {
|
|
|
3281
3288
|
const normalizedLabel = normalizeLabel(label);
|
|
3282
3289
|
const normalizedValue = normalizeLabel(value);
|
|
3283
3290
|
if (!value || moneyAmount(value) !== void 0) return false;
|
|
3291
|
+
if (/^item\s+\d+[.)]?\s*limits?\s+of\s+liability\b/.test(normalizedValue)) return false;
|
|
3284
3292
|
if (/\b(coverage|coverage part|insuring agreement|description|item|name)\b/.test(normalizedLabel)) {
|
|
3285
3293
|
return true;
|
|
3286
3294
|
}
|
|
3295
|
+
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)) {
|
|
3296
|
+
return true;
|
|
3297
|
+
}
|
|
3287
3298
|
if (/^column\s+1$/.test(normalizedLabel) && !/^(item\s+\d+|nwc-|iso-|cg |il |form\b|page\b)/i.test(normalizedValue)) {
|
|
3288
3299
|
return true;
|
|
3289
3300
|
}
|
|
@@ -3302,13 +3313,32 @@ function childMap(nodes) {
|
|
|
3302
3313
|
for (const group of children.values()) group.sort((left, right) => left.order - right.order);
|
|
3303
3314
|
return children;
|
|
3304
3315
|
}
|
|
3305
|
-
function
|
|
3316
|
+
function rawCellRows(row, children) {
|
|
3306
3317
|
return (children.get(row.id) ?? []).filter((child) => child.kind === "table_cell").map((cell) => ({
|
|
3307
3318
|
label: cleanValue(cell.title) ?? "Value",
|
|
3308
3319
|
value: cleanValue(cell.textExcerpt ?? cell.description ?? cell.title) ?? "",
|
|
3309
3320
|
node: cell
|
|
3310
3321
|
})).filter((cell) => cell.value);
|
|
3311
3322
|
}
|
|
3323
|
+
function headerLabelsForRow(row, children) {
|
|
3324
|
+
if (!row.parentId) return [];
|
|
3325
|
+
const labels = [];
|
|
3326
|
+
const siblingRows = (children.get(row.parentId) ?? []).filter((candidate) => candidate.kind === "table_row" && candidate.order < row.order).sort((left, right) => left.order - right.order);
|
|
3327
|
+
for (const sibling of siblingRows) {
|
|
3328
|
+
if (!isHeaderRow(sibling)) continue;
|
|
3329
|
+
for (const [index, cell] of rawCellRows(sibling, children).entries()) {
|
|
3330
|
+
const label = cleanValue(cell.value) ?? cleanValue(cell.label);
|
|
3331
|
+
if (label && !isGenericColumnLabel(label)) labels[index] = label;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
return labels;
|
|
3335
|
+
}
|
|
3336
|
+
function cellRows(row, children, headerLabels = []) {
|
|
3337
|
+
return rawCellRows(row, children).map((cell, index) => ({
|
|
3338
|
+
...cell,
|
|
3339
|
+
label: isGenericColumnLabel(cell.label) && headerLabels[index] ? headerLabels[index] : cell.label
|
|
3340
|
+
}));
|
|
3341
|
+
}
|
|
3312
3342
|
function directChildren(parent, children) {
|
|
3313
3343
|
return children.get(parent.id) ?? [];
|
|
3314
3344
|
}
|
|
@@ -3361,8 +3391,9 @@ function relabelGenericTerm(term, label) {
|
|
|
3361
3391
|
};
|
|
3362
3392
|
}
|
|
3363
3393
|
function termFromCell(params) {
|
|
3364
|
-
const value =
|
|
3394
|
+
const value = cleanCoverageTermValue(params.value);
|
|
3365
3395
|
if (!value) return void 0;
|
|
3396
|
+
if (isRejectedCoverageTermValue(params.label, value)) return void 0;
|
|
3366
3397
|
const nodes = [params.row, params.cell].filter((node) => Boolean(node));
|
|
3367
3398
|
const kind = termKind(params.label, value);
|
|
3368
3399
|
const amount = moneyAmount(value);
|
|
@@ -3375,20 +3406,38 @@ function termFromCell(params) {
|
|
|
3375
3406
|
...sourceIds(nodes)
|
|
3376
3407
|
};
|
|
3377
3408
|
}
|
|
3409
|
+
function cleanCoverageTermValue(value) {
|
|
3410
|
+
return cleanValue(value)?.replace(/\s+\/\s*$/, "").trim();
|
|
3411
|
+
}
|
|
3412
|
+
function isRejectedCoverageTermValue(label, value) {
|
|
3413
|
+
if (/\bshown\s+in\s+item\s*\d+\b/i.test(value) && moneyAmount(value) === void 0) return true;
|
|
3414
|
+
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) {
|
|
3415
|
+
return true;
|
|
3416
|
+
}
|
|
3417
|
+
if (/^for:\s*\(\d+\)/i.test(label) && moneyAmount(value) === void 0) return true;
|
|
3418
|
+
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;
|
|
3419
|
+
return false;
|
|
3420
|
+
}
|
|
3378
3421
|
function termsFromRow(row, children) {
|
|
3379
|
-
const cells = cellRows(row, children);
|
|
3422
|
+
const cells = cellRows(row, children, headerLabelsForRow(row, children));
|
|
3380
3423
|
if (cells.length > 0) {
|
|
3381
3424
|
const pairedTerms = [];
|
|
3425
|
+
const pairedIndexes = /* @__PURE__ */ new Set();
|
|
3382
3426
|
for (const [index, cell] of cells.entries()) {
|
|
3383
3427
|
const next = cells[index + 1];
|
|
3384
3428
|
if (!next) continue;
|
|
3429
|
+
if (!isGenericColumnLabel(cell.label) && isNameCell(cell.label, cell.value)) continue;
|
|
3385
3430
|
if (!isCoverageTermLabel(cell.value)) continue;
|
|
3386
3431
|
if (isCoverageTermLabel(next.value) && moneyAmount(next.value) === void 0) continue;
|
|
3387
3432
|
const term = termFromCell({ row, cell: next.node, label: cell.value, value: next.value });
|
|
3388
|
-
if (term)
|
|
3433
|
+
if (term) {
|
|
3434
|
+
pairedTerms.push(term);
|
|
3435
|
+
pairedIndexes.add(index);
|
|
3436
|
+
pairedIndexes.add(index + 1);
|
|
3437
|
+
}
|
|
3389
3438
|
}
|
|
3390
|
-
|
|
3391
|
-
return
|
|
3439
|
+
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));
|
|
3440
|
+
return [...pairedTerms, ...valueTerms];
|
|
3392
3441
|
}
|
|
3393
3442
|
const text = normalizeWhitespace3(row.textExcerpt ?? row.description ?? nodeText(row));
|
|
3394
3443
|
const terms = [];
|
|
@@ -3414,11 +3463,11 @@ function termsFromRow(row, children) {
|
|
|
3414
3463
|
return terms;
|
|
3415
3464
|
}
|
|
3416
3465
|
function nameFromRow(row, children) {
|
|
3417
|
-
const
|
|
3418
|
-
if (declarationName) return declarationName;
|
|
3419
|
-
const cells = cellRows(row, children);
|
|
3466
|
+
const cells = cellRows(row, children, headerLabelsForRow(row, children));
|
|
3420
3467
|
const named = cells.find((cell) => isNameCell(cell.label, cell.value));
|
|
3421
3468
|
if (named) return cleanValue(named.value);
|
|
3469
|
+
const declarationName = declarationCoverageNameFromRow(row, children);
|
|
3470
|
+
if (declarationName) return declarationName;
|
|
3422
3471
|
return coverageNameFromRow(row.textExcerpt ?? row.description ?? nodeText(row));
|
|
3423
3472
|
}
|
|
3424
3473
|
function legacyLimit(terms) {
|
|
@@ -3451,7 +3500,7 @@ function isOperationalCoverageRow(coverage) {
|
|
|
3451
3500
|
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)) {
|
|
3452
3501
|
return false;
|
|
3453
3502
|
}
|
|
3454
|
-
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);
|
|
3503
|
+
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);
|
|
3455
3504
|
}
|
|
3456
3505
|
function uniqueTerms(terms) {
|
|
3457
3506
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3465,7 +3514,7 @@ function uniqueTerms(terms) {
|
|
|
3465
3514
|
return result;
|
|
3466
3515
|
}
|
|
3467
3516
|
function coverageFromTableRow(row, children, byId) {
|
|
3468
|
-
if (row
|
|
3517
|
+
if (isHeaderRow(row)) return void 0;
|
|
3469
3518
|
const name = nameFromRow(row, children);
|
|
3470
3519
|
const terms = uniqueTerms(termsFromRow(row, children));
|
|
3471
3520
|
if (!name || terms.length === 0) return void 0;
|