@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.mjs
CHANGED
|
@@ -2896,20 +2896,15 @@ function getCoveredReasons(memory) {
|
|
|
2896
2896
|
}
|
|
2897
2897
|
|
|
2898
2898
|
// src/extraction/promote.ts
|
|
2899
|
-
function
|
|
2900
|
-
|
|
2901
|
-
return Array.isArray(decl?.fields) ? decl.fields : [];
|
|
2899
|
+
function stringValue(value) {
|
|
2900
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
2902
2901
|
}
|
|
2903
|
-
function
|
|
2904
|
-
const
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
return
|
|
2909
|
-
}
|
|
2910
|
-
function findFieldValue(fields, patterns, reject) {
|
|
2911
|
-
const match = fields.find((f) => fieldMatches(f.field, patterns) && !reject?.(f));
|
|
2912
|
-
return match?.value;
|
|
2902
|
+
function findRawString(raw, keys) {
|
|
2903
|
+
for (const key of keys) {
|
|
2904
|
+
const value = stringValue(raw[key]);
|
|
2905
|
+
if (value) return value;
|
|
2906
|
+
}
|
|
2907
|
+
return void 0;
|
|
2913
2908
|
}
|
|
2914
2909
|
function promoteRawFields(raw, mappings) {
|
|
2915
2910
|
for (const { from, to } of mappings) {
|
|
@@ -2919,9 +2914,6 @@ function promoteRawFields(raw, mappings) {
|
|
|
2919
2914
|
delete raw[from];
|
|
2920
2915
|
}
|
|
2921
2916
|
}
|
|
2922
|
-
function findRawOrDeclarationValue(raw, fields, lookup) {
|
|
2923
|
-
return (lookup.rawKey ? raw[lookup.rawKey] : void 0) || findFieldValue(fields, lookup.patterns, lookup.reject);
|
|
2924
|
-
}
|
|
2925
2917
|
function promoteCarrierFields(doc) {
|
|
2926
2918
|
const raw = doc;
|
|
2927
2919
|
promoteRawFields(raw, [
|
|
@@ -2938,55 +2930,14 @@ function promoteCarrierFields(doc) {
|
|
|
2938
2930
|
};
|
|
2939
2931
|
}
|
|
2940
2932
|
}
|
|
2941
|
-
var BROKER_NAME_PATTERNS = [
|
|
2942
|
-
"brokerName",
|
|
2943
|
-
"broker",
|
|
2944
|
-
"agentName",
|
|
2945
|
-
"agent",
|
|
2946
|
-
"producerName",
|
|
2947
|
-
"producerAgency",
|
|
2948
|
-
"agencyName",
|
|
2949
|
-
"brokerAgency"
|
|
2950
|
-
];
|
|
2951
|
-
var BROKER_CONTACT_PATTERNS = [
|
|
2952
|
-
"brokerContactName",
|
|
2953
|
-
"brokerContact",
|
|
2954
|
-
"agentContactName",
|
|
2955
|
-
"producerContactName",
|
|
2956
|
-
"producerContact"
|
|
2957
|
-
];
|
|
2958
|
-
var BROKER_LICENSE_PATTERNS = [
|
|
2959
|
-
"brokerLicenseNumber",
|
|
2960
|
-
"brokerNumber",
|
|
2961
|
-
"agentLicenseNumber",
|
|
2962
|
-
"producerLicenseNumber",
|
|
2963
|
-
"producerNumber",
|
|
2964
|
-
"agentNumber"
|
|
2965
|
-
];
|
|
2966
|
-
var BROKER_PHONE_PATTERNS = ["brokerPhone", "agentPhone", "producerPhone"];
|
|
2967
|
-
var BROKER_EMAIL_PATTERNS = ["brokerEmail", "agentEmail", "producerEmail"];
|
|
2968
|
-
var BROKER_ADDRESS_PATTERNS = ["brokerAddress", "agentAddress", "producerAddress"];
|
|
2969
2933
|
function promoteBroker(doc) {
|
|
2970
2934
|
const raw = doc;
|
|
2971
|
-
const
|
|
2972
|
-
const
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
const
|
|
2977
|
-
rawKey: "brokerContactName",
|
|
2978
|
-
patterns: BROKER_CONTACT_PATTERNS
|
|
2979
|
-
});
|
|
2980
|
-
const brokerLicense = findRawOrDeclarationValue(raw, fields, {
|
|
2981
|
-
rawKey: "brokerLicenseNumber",
|
|
2982
|
-
patterns: BROKER_LICENSE_PATTERNS
|
|
2983
|
-
});
|
|
2984
|
-
const brokerPhone = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_PHONE_PATTERNS });
|
|
2985
|
-
const brokerEmail = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_EMAIL_PATTERNS });
|
|
2986
|
-
const brokerAddress = findRawOrDeclarationValue(raw, fields, { patterns: BROKER_ADDRESS_PATTERNS });
|
|
2987
|
-
if (brokerAgency) raw.brokerAgency = brokerAgency;
|
|
2988
|
-
if (brokerContact) raw.brokerContactName = brokerContact;
|
|
2989
|
-
if (brokerLicense) raw.brokerLicenseNumber = brokerLicense;
|
|
2935
|
+
const brokerAgency = findRawString(raw, ["brokerAgency"]);
|
|
2936
|
+
const brokerContact = findRawString(raw, ["brokerContactName"]);
|
|
2937
|
+
const brokerLicense = findRawString(raw, ["brokerLicenseNumber"]);
|
|
2938
|
+
const brokerPhone = findRawString(raw, ["brokerPhone"]);
|
|
2939
|
+
const brokerEmail = findRawString(raw, ["brokerEmail"]);
|
|
2940
|
+
const brokerAddress = findRawString(raw, ["brokerAddress"]);
|
|
2990
2941
|
if (!raw.producer && brokerAgency) {
|
|
2991
2942
|
raw.producer = {
|
|
2992
2943
|
agencyName: brokerAgency,
|
|
@@ -2998,134 +2949,9 @@ function promoteBroker(doc) {
|
|
|
2998
2949
|
};
|
|
2999
2950
|
}
|
|
3000
2951
|
}
|
|
3001
|
-
var LOSS_PAYEE_NAME_PATTERNS = [
|
|
3002
|
-
"lossPayeeName",
|
|
3003
|
-
"lossPayee",
|
|
3004
|
-
"lossPayeeHolder"
|
|
3005
|
-
];
|
|
3006
|
-
var LOSS_PAYEE_ADDRESS_PATTERNS = ["lossPayeeAddress"];
|
|
3007
|
-
var MORTGAGE_HOLDER_NAME_PATTERNS = [
|
|
3008
|
-
"mortgagee",
|
|
3009
|
-
"mortgageHolder",
|
|
3010
|
-
"mortgageHolderName",
|
|
3011
|
-
"mortgageeName",
|
|
3012
|
-
"lienholder",
|
|
3013
|
-
"lienholderName"
|
|
3014
|
-
];
|
|
3015
|
-
var MORTGAGE_HOLDER_ADDRESS_PATTERNS = [
|
|
3016
|
-
"mortgageeAddress",
|
|
3017
|
-
"mortgageHolderAddress",
|
|
3018
|
-
"lienholderAddress"
|
|
3019
|
-
];
|
|
3020
|
-
function promoteLossPayees(doc) {
|
|
3021
|
-
const raw = doc;
|
|
3022
|
-
const fields = getDeclarationFields(doc);
|
|
3023
|
-
if (!raw.lossPayees || Array.isArray(raw.lossPayees) && raw.lossPayees.length === 0) {
|
|
3024
|
-
const name = findFieldValue(fields, LOSS_PAYEE_NAME_PATTERNS);
|
|
3025
|
-
if (name) {
|
|
3026
|
-
const address = findFieldValue(fields, LOSS_PAYEE_ADDRESS_PATTERNS);
|
|
3027
|
-
raw.lossPayees = [{
|
|
3028
|
-
name,
|
|
3029
|
-
role: "loss_payee",
|
|
3030
|
-
...address ? { address: { street1: address } } : {}
|
|
3031
|
-
}];
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
3034
|
-
if (!raw.mortgageHolders || Array.isArray(raw.mortgageHolders) && raw.mortgageHolders.length === 0) {
|
|
3035
|
-
const name = findFieldValue(fields, MORTGAGE_HOLDER_NAME_PATTERNS);
|
|
3036
|
-
if (name) {
|
|
3037
|
-
const address = findFieldValue(fields, MORTGAGE_HOLDER_ADDRESS_PATTERNS);
|
|
3038
|
-
raw.mortgageHolders = [{
|
|
3039
|
-
name,
|
|
3040
|
-
role: "mortgage_holder",
|
|
3041
|
-
...address ? { address: { street1: address } } : {}
|
|
3042
|
-
}];
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
function promoteLocations(doc) {
|
|
3047
|
-
const raw = doc;
|
|
3048
|
-
if (Array.isArray(raw.locations) && raw.locations.length > 0) return;
|
|
3049
|
-
const fields = getDeclarationFields(doc);
|
|
3050
|
-
if (fields.length === 0) return;
|
|
3051
|
-
const locationGroups = /* @__PURE__ */ new Map();
|
|
3052
|
-
for (const f of fields) {
|
|
3053
|
-
const lower = f.field.toLowerCase().replace(/[\s_-]/g, "");
|
|
3054
|
-
if (lower.includes("locationnumber") || lower.includes("locnumber") || lower.includes("locno")) {
|
|
3055
|
-
const key = f.value;
|
|
3056
|
-
if (!locationGroups.has(key)) locationGroups.set(key, /* @__PURE__ */ new Map());
|
|
3057
|
-
locationGroups.get(key).set("number", f.value);
|
|
3058
|
-
continue;
|
|
3059
|
-
}
|
|
3060
|
-
if (lower.includes("buildingnumber") || lower.includes("bldgnumber") || lower.includes("bldgno")) {
|
|
3061
|
-
const lastKey2 = [...locationGroups.keys()].pop();
|
|
3062
|
-
if (lastKey2) locationGroups.get(lastKey2).set("buildingNumber", f.value);
|
|
3063
|
-
continue;
|
|
3064
|
-
}
|
|
3065
|
-
const section = (f.section ?? "").toLowerCase();
|
|
3066
|
-
const isLocationField = section.includes("location") || section.includes("building") || section.includes("premises") || section.includes("schedule of locations");
|
|
3067
|
-
if (!isLocationField) continue;
|
|
3068
|
-
if (locationGroups.size === 0) {
|
|
3069
|
-
locationGroups.set("1", /* @__PURE__ */ new Map([["number", "1"]]));
|
|
3070
|
-
}
|
|
3071
|
-
const lastKey = [...locationGroups.keys()].pop();
|
|
3072
|
-
const group = locationGroups.get(lastKey);
|
|
3073
|
-
if (lower.includes("construction") || lower.includes("constructiontype")) {
|
|
3074
|
-
group.set("constructionType", f.value);
|
|
3075
|
-
} else if (lower.includes("occupancy") || lower.includes("occupancytype")) {
|
|
3076
|
-
group.set("occupancy", f.value);
|
|
3077
|
-
} else if (lower.includes("yearbuilt")) {
|
|
3078
|
-
group.set("yearBuilt", f.value);
|
|
3079
|
-
} else if (lower.includes("squarefootage") || lower.includes("sqft") || lower.includes("area")) {
|
|
3080
|
-
group.set("squareFootage", f.value);
|
|
3081
|
-
} else if (lower.includes("protectionclass") || lower.includes("fireprotection")) {
|
|
3082
|
-
group.set("protectionClass", f.value);
|
|
3083
|
-
} else if (lower.includes("sprinkler")) {
|
|
3084
|
-
group.set("sprinklered", f.value);
|
|
3085
|
-
} else if (lower.includes("buildingvalue") || lower.includes("buildingamt") || lower.includes("buildingcoverage")) {
|
|
3086
|
-
group.set("buildingValue", f.value);
|
|
3087
|
-
} else if (lower.includes("contentsvalue") || lower.includes("contentsamt") || lower.includes("contentscoverage")) {
|
|
3088
|
-
group.set("contentsValue", f.value);
|
|
3089
|
-
} else if (lower.includes("businessincome") || lower.includes("bivalue") || lower.includes("businessincomevalue")) {
|
|
3090
|
-
group.set("businessIncomeValue", f.value);
|
|
3091
|
-
} else if (lower.includes("description") || lower.includes("buildingdescription") || lower.includes("locationdescription")) {
|
|
3092
|
-
group.set("description", f.value);
|
|
3093
|
-
} else if (lower.includes("address") || lower.includes("industryaddress") || lower.includes("locationaddress") || lower.includes("premisesaddress")) {
|
|
3094
|
-
group.set("address", f.value);
|
|
3095
|
-
} else if (lower.includes("alarm") || lower.includes("alarmtype")) {
|
|
3096
|
-
group.set("alarmType", f.value);
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
if (locationGroups.size === 0) return;
|
|
3100
|
-
const locations = [];
|
|
3101
|
-
for (const [, group] of locationGroups) {
|
|
3102
|
-
const num = parseInt(group.get("number") ?? "0", 10) || locations.length + 1;
|
|
3103
|
-
const addressStr = group.get("address");
|
|
3104
|
-
locations.push({
|
|
3105
|
-
number: num,
|
|
3106
|
-
address: addressStr ? { street1: addressStr } : { street1: "See declarations" },
|
|
3107
|
-
...group.get("description") ? { description: group.get("description") } : {},
|
|
3108
|
-
...group.get("constructionType") ? { constructionType: group.get("constructionType") } : {},
|
|
3109
|
-
...group.get("occupancy") ? { occupancy: group.get("occupancy") } : {},
|
|
3110
|
-
...group.get("yearBuilt") ? { yearBuilt: parseInt(group.get("yearBuilt"), 10) || void 0 } : {},
|
|
3111
|
-
...group.get("squareFootage") ? { squareFootage: parseInt(group.get("squareFootage").replace(/[^0-9]/g, ""), 10) || void 0 } : {},
|
|
3112
|
-
...group.get("protectionClass") ? { protectionClass: group.get("protectionClass") } : {},
|
|
3113
|
-
...group.get("sprinklered") ? { sprinklered: /yes|true/i.test(group.get("sprinklered")) } : {},
|
|
3114
|
-
...group.get("buildingValue") ? { buildingValue: group.get("buildingValue") } : {},
|
|
3115
|
-
...group.get("contentsValue") ? { contentsValue: group.get("contentsValue") } : {},
|
|
3116
|
-
...group.get("businessIncomeValue") ? { businessIncomeValue: group.get("businessIncomeValue") } : {},
|
|
3117
|
-
...group.get("alarmType") ? { alarmType: group.get("alarmType") } : {}
|
|
3118
|
-
});
|
|
3119
|
-
}
|
|
3120
|
-
if (locations.length > 0) {
|
|
3121
|
-
raw.locations = locations;
|
|
3122
|
-
}
|
|
3123
|
-
}
|
|
3124
2952
|
function promoteExtractedFields(doc) {
|
|
3125
2953
|
promoteCarrierFields(doc);
|
|
3126
2954
|
promoteBroker(doc);
|
|
3127
|
-
promoteLossPayees(doc);
|
|
3128
|
-
promoteLocations(doc);
|
|
3129
2955
|
}
|
|
3130
2956
|
|
|
3131
2957
|
// src/extraction/alignment.ts
|