@claritylabs/cl-sdk 1.3.4 → 1.3.5
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 +14 -188
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -188
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3224,20 +3224,15 @@ function getCoveredReasons(memory) {
|
|
|
3224
3224
|
}
|
|
3225
3225
|
|
|
3226
3226
|
// src/extraction/promote.ts
|
|
3227
|
-
function
|
|
3228
|
-
|
|
3229
|
-
return Array.isArray(decl?.fields) ? decl.fields : [];
|
|
3227
|
+
function stringValue(value) {
|
|
3228
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
3230
3229
|
}
|
|
3231
|
-
function
|
|
3232
|
-
const
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
return
|
|
3237
|
-
}
|
|
3238
|
-
function findFieldValue(fields, patterns, reject) {
|
|
3239
|
-
const match = fields.find((f) => fieldMatches(f.field, patterns) && !reject?.(f));
|
|
3240
|
-
return match?.value;
|
|
3230
|
+
function findRawString(raw, keys) {
|
|
3231
|
+
for (const key of keys) {
|
|
3232
|
+
const value = stringValue(raw[key]);
|
|
3233
|
+
if (value) return value;
|
|
3234
|
+
}
|
|
3235
|
+
return void 0;
|
|
3241
3236
|
}
|
|
3242
3237
|
function promoteRawFields(raw, mappings) {
|
|
3243
3238
|
for (const { from, to } of mappings) {
|
|
@@ -3247,9 +3242,6 @@ function promoteRawFields(raw, mappings) {
|
|
|
3247
3242
|
delete raw[from];
|
|
3248
3243
|
}
|
|
3249
3244
|
}
|
|
3250
|
-
function findRawOrDeclarationValue(raw, fields, lookup) {
|
|
3251
|
-
return (lookup.rawKey ? raw[lookup.rawKey] : void 0) || findFieldValue(fields, lookup.patterns, lookup.reject);
|
|
3252
|
-
}
|
|
3253
3245
|
function promoteCarrierFields(doc) {
|
|
3254
3246
|
const raw = doc;
|
|
3255
3247
|
promoteRawFields(raw, [
|
|
@@ -3266,55 +3258,14 @@ function promoteCarrierFields(doc) {
|
|
|
3266
3258
|
};
|
|
3267
3259
|
}
|
|
3268
3260
|
}
|
|
3269
|
-
var BROKER_NAME_PATTERNS = [
|
|
3270
|
-
"brokerName",
|
|
3271
|
-
"broker",
|
|
3272
|
-
"agentName",
|
|
3273
|
-
"agent",
|
|
3274
|
-
"producerName",
|
|
3275
|
-
"producerAgency",
|
|
3276
|
-
"agencyName",
|
|
3277
|
-
"brokerAgency"
|
|
3278
|
-
];
|
|
3279
|
-
var BROKER_CONTACT_PATTERNS = [
|
|
3280
|
-
"brokerContactName",
|
|
3281
|
-
"brokerContact",
|
|
3282
|
-
"agentContactName",
|
|
3283
|
-
"producerContactName",
|
|
3284
|
-
"producerContact"
|
|
3285
|
-
];
|
|
3286
|
-
var BROKER_LICENSE_PATTERNS = [
|
|
3287
|
-
"brokerLicenseNumber",
|
|
3288
|
-
"brokerNumber",
|
|
3289
|
-
"agentLicenseNumber",
|
|
3290
|
-
"producerLicenseNumber",
|
|
3291
|
-
"producerNumber",
|
|
3292
|
-
"agentNumber"
|
|
3293
|
-
];
|
|
3294
|
-
var BROKER_PHONE_PATTERNS = ["brokerPhone", "agentPhone", "producerPhone"];
|
|
3295
|
-
var BROKER_EMAIL_PATTERNS = ["brokerEmail", "agentEmail", "producerEmail"];
|
|
3296
|
-
var BROKER_ADDRESS_PATTERNS = ["brokerAddress", "agentAddress", "producerAddress"];
|
|
3297
3261
|
function promoteBroker(doc) {
|
|
3298
3262
|
const raw = doc;
|
|
3299
|
-
const
|
|
3300
|
-
const
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
const
|
|
3305
|
-
rawKey: "brokerContactName",
|
|
3306
|
-
patterns: BROKER_CONTACT_PATTERNS
|
|
3307
|
-
});
|
|
3308
|
-
const brokerLicense = findRawOrDeclarationValue(raw, fields, {
|
|
3309
|
-
rawKey: "brokerLicenseNumber",
|
|
3310
|
-
patterns: BROKER_LICENSE_PATTERNS
|
|
3311
|
-
});
|
|
3312
|
-
const brokerPhone = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_PHONE_PATTERNS });
|
|
3313
|
-
const brokerEmail = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_EMAIL_PATTERNS });
|
|
3314
|
-
const brokerAddress = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_ADDRESS_PATTERNS });
|
|
3315
|
-
if (brokerAgency) raw.brokerAgency = brokerAgency;
|
|
3316
|
-
if (brokerContact) raw.brokerContactName = brokerContact;
|
|
3317
|
-
if (brokerLicense) raw.brokerLicenseNumber = brokerLicense;
|
|
3263
|
+
const brokerAgency = findRawString(raw, ["brokerAgency"]);
|
|
3264
|
+
const brokerContact = findRawString(raw, ["brokerContactName"]);
|
|
3265
|
+
const brokerLicense = findRawString(raw, ["brokerLicenseNumber"]);
|
|
3266
|
+
const brokerPhone = findRawString(raw, ["brokerPhone"]);
|
|
3267
|
+
const brokerEmail = findRawString(raw, ["brokerEmail"]);
|
|
3268
|
+
const brokerAddress = findRawString(raw, ["brokerAddress"]);
|
|
3318
3269
|
if (!raw.producer && brokerAgency) {
|
|
3319
3270
|
raw.producer = {
|
|
3320
3271
|
agencyName: brokerAgency,
|
|
@@ -3326,134 +3277,9 @@ function promoteBroker(doc) {
|
|
|
3326
3277
|
};
|
|
3327
3278
|
}
|
|
3328
3279
|
}
|
|
3329
|
-
var LOSS_PAYEE_NAME_PATTERNS = [
|
|
3330
|
-
"lossPayeeName",
|
|
3331
|
-
"lossPayee",
|
|
3332
|
-
"lossPayeeHolder"
|
|
3333
|
-
];
|
|
3334
|
-
var LOSS_PAYEE_ADDRESS_PATTERNS = ["lossPayeeAddress"];
|
|
3335
|
-
var MORTGAGE_HOLDER_NAME_PATTERNS = [
|
|
3336
|
-
"mortgagee",
|
|
3337
|
-
"mortgageHolder",
|
|
3338
|
-
"mortgageHolderName",
|
|
3339
|
-
"mortgageeName",
|
|
3340
|
-
"lienholder",
|
|
3341
|
-
"lienholderName"
|
|
3342
|
-
];
|
|
3343
|
-
var MORTGAGE_HOLDER_ADDRESS_PATTERNS = [
|
|
3344
|
-
"mortgageeAddress",
|
|
3345
|
-
"mortgageHolderAddress",
|
|
3346
|
-
"lienholderAddress"
|
|
3347
|
-
];
|
|
3348
|
-
function promoteLossPayees(doc) {
|
|
3349
|
-
const raw = doc;
|
|
3350
|
-
const fields = getDeclarationFields(doc);
|
|
3351
|
-
if (!raw.lossPayees || Array.isArray(raw.lossPayees) && raw.lossPayees.length === 0) {
|
|
3352
|
-
const name = findFieldValue(fields, LOSS_PAYEE_NAME_PATTERNS);
|
|
3353
|
-
if (name) {
|
|
3354
|
-
const address = findFieldValue(fields, LOSS_PAYEE_ADDRESS_PATTERNS);
|
|
3355
|
-
raw.lossPayees = [{
|
|
3356
|
-
name,
|
|
3357
|
-
role: "loss_payee",
|
|
3358
|
-
...address ? { address: { street1: address } } : {}
|
|
3359
|
-
}];
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
if (!raw.mortgageHolders || Array.isArray(raw.mortgageHolders) && raw.mortgageHolders.length === 0) {
|
|
3363
|
-
const name = findFieldValue(fields, MORTGAGE_HOLDER_NAME_PATTERNS);
|
|
3364
|
-
if (name) {
|
|
3365
|
-
const address = findFieldValue(fields, MORTGAGE_HOLDER_ADDRESS_PATTERNS);
|
|
3366
|
-
raw.mortgageHolders = [{
|
|
3367
|
-
name,
|
|
3368
|
-
role: "mortgage_holder",
|
|
3369
|
-
...address ? { address: { street1: address } } : {}
|
|
3370
|
-
}];
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
function promoteLocations(doc) {
|
|
3375
|
-
const raw = doc;
|
|
3376
|
-
if (Array.isArray(raw.locations) && raw.locations.length > 0) return;
|
|
3377
|
-
const fields = getDeclarationFields(doc);
|
|
3378
|
-
if (fields.length === 0) return;
|
|
3379
|
-
const locationGroups = /* @__PURE__ */ new Map();
|
|
3380
|
-
for (const f of fields) {
|
|
3381
|
-
const lower = f.field.toLowerCase().replace(/[\s_-]/g, "");
|
|
3382
|
-
if (lower.includes("locationnumber") || lower.includes("locnumber") || lower.includes("locno")) {
|
|
3383
|
-
const key = f.value;
|
|
3384
|
-
if (!locationGroups.has(key)) locationGroups.set(key, /* @__PURE__ */ new Map());
|
|
3385
|
-
locationGroups.get(key).set("number", f.value);
|
|
3386
|
-
continue;
|
|
3387
|
-
}
|
|
3388
|
-
if (lower.includes("buildingnumber") || lower.includes("bldgnumber") || lower.includes("bldgno")) {
|
|
3389
|
-
const lastKey2 = [...locationGroups.keys()].pop();
|
|
3390
|
-
if (lastKey2) locationGroups.get(lastKey2).set("buildingNumber", f.value);
|
|
3391
|
-
continue;
|
|
3392
|
-
}
|
|
3393
|
-
const section = (f.section ?? "").toLowerCase();
|
|
3394
|
-
const isLocationField = section.includes("location") || section.includes("building") || section.includes("premises") || section.includes("schedule of locations");
|
|
3395
|
-
if (!isLocationField) continue;
|
|
3396
|
-
if (locationGroups.size === 0) {
|
|
3397
|
-
locationGroups.set("1", /* @__PURE__ */ new Map([["number", "1"]]));
|
|
3398
|
-
}
|
|
3399
|
-
const lastKey = [...locationGroups.keys()].pop();
|
|
3400
|
-
const group = locationGroups.get(lastKey);
|
|
3401
|
-
if (lower.includes("construction") || lower.includes("constructiontype")) {
|
|
3402
|
-
group.set("constructionType", f.value);
|
|
3403
|
-
} else if (lower.includes("occupancy") || lower.includes("occupancytype")) {
|
|
3404
|
-
group.set("occupancy", f.value);
|
|
3405
|
-
} else if (lower.includes("yearbuilt")) {
|
|
3406
|
-
group.set("yearBuilt", f.value);
|
|
3407
|
-
} else if (lower.includes("squarefootage") || lower.includes("sqft") || lower.includes("area")) {
|
|
3408
|
-
group.set("squareFootage", f.value);
|
|
3409
|
-
} else if (lower.includes("protectionclass") || lower.includes("fireprotection")) {
|
|
3410
|
-
group.set("protectionClass", f.value);
|
|
3411
|
-
} else if (lower.includes("sprinkler")) {
|
|
3412
|
-
group.set("sprinklered", f.value);
|
|
3413
|
-
} else if (lower.includes("buildingvalue") || lower.includes("buildingamt") || lower.includes("buildingcoverage")) {
|
|
3414
|
-
group.set("buildingValue", f.value);
|
|
3415
|
-
} else if (lower.includes("contentsvalue") || lower.includes("contentsamt") || lower.includes("contentscoverage")) {
|
|
3416
|
-
group.set("contentsValue", f.value);
|
|
3417
|
-
} else if (lower.includes("businessincome") || lower.includes("bivalue") || lower.includes("businessincomevalue")) {
|
|
3418
|
-
group.set("businessIncomeValue", f.value);
|
|
3419
|
-
} else if (lower.includes("description") || lower.includes("buildingdescription") || lower.includes("locationdescription")) {
|
|
3420
|
-
group.set("description", f.value);
|
|
3421
|
-
} else if (lower.includes("address") || lower.includes("industryaddress") || lower.includes("locationaddress") || lower.includes("premisesaddress")) {
|
|
3422
|
-
group.set("address", f.value);
|
|
3423
|
-
} else if (lower.includes("alarm") || lower.includes("alarmtype")) {
|
|
3424
|
-
group.set("alarmType", f.value);
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
if (locationGroups.size === 0) return;
|
|
3428
|
-
const locations = [];
|
|
3429
|
-
for (const [, group] of locationGroups) {
|
|
3430
|
-
const num = parseInt(group.get("number") ?? "0", 10) || locations.length + 1;
|
|
3431
|
-
const addressStr = group.get("address");
|
|
3432
|
-
locations.push({
|
|
3433
|
-
number: num,
|
|
3434
|
-
address: addressStr ? { street1: addressStr } : { street1: "See declarations" },
|
|
3435
|
-
...group.get("description") ? { description: group.get("description") } : {},
|
|
3436
|
-
...group.get("constructionType") ? { constructionType: group.get("constructionType") } : {},
|
|
3437
|
-
...group.get("occupancy") ? { occupancy: group.get("occupancy") } : {},
|
|
3438
|
-
...group.get("yearBuilt") ? { yearBuilt: parseInt(group.get("yearBuilt"), 10) || void 0 } : {},
|
|
3439
|
-
...group.get("squareFootage") ? { squareFootage: parseInt(group.get("squareFootage").replace(/[^0-9]/g, ""), 10) || void 0 } : {},
|
|
3440
|
-
...group.get("protectionClass") ? { protectionClass: group.get("protectionClass") } : {},
|
|
3441
|
-
...group.get("sprinklered") ? { sprinklered: /yes|true/i.test(group.get("sprinklered")) } : {},
|
|
3442
|
-
...group.get("buildingValue") ? { buildingValue: group.get("buildingValue") } : {},
|
|
3443
|
-
...group.get("contentsValue") ? { contentsValue: group.get("contentsValue") } : {},
|
|
3444
|
-
...group.get("businessIncomeValue") ? { businessIncomeValue: group.get("businessIncomeValue") } : {},
|
|
3445
|
-
...group.get("alarmType") ? { alarmType: group.get("alarmType") } : {}
|
|
3446
|
-
});
|
|
3447
|
-
}
|
|
3448
|
-
if (locations.length > 0) {
|
|
3449
|
-
raw.locations = locations;
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
3452
3280
|
function promoteExtractedFields(doc) {
|
|
3453
3281
|
promoteCarrierFields(doc);
|
|
3454
3282
|
promoteBroker(doc);
|
|
3455
|
-
promoteLossPayees(doc);
|
|
3456
|
-
promoteLocations(doc);
|
|
3457
3283
|
}
|
|
3458
3284
|
|
|
3459
3285
|
// src/extraction/alignment.ts
|