stand_socotra_policy_transformer 3.0.5 → 3.0.7
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/__tests__/__utils__/payloads/claims_new_policy.json +117 -0
- package/__tests__/__utils__/payloads/claims_socotra_payload.json +764 -0
- package/__tests__/__utils__/payloads/sample_retool.json +0 -9
- package/__tests__/package_version.test.js +1 -1
- package/__tests__/retool_utils/socotra_payload.test.js +41 -1
- package/dist/stand_underwriter.js +1 -1
- package/package.json +1 -1
- package/src/retool_utils/socotra_payloads.js +4 -1
- package/src/retool_utils/socotra_structure_helper.js +149 -19
- package/src/retool_utils/versions/stand_v3_entries.js +26 -3
package/package.json
CHANGED
|
@@ -92,7 +92,10 @@ class SocotraPayloadConverter {
|
|
|
92
92
|
const retool_id_parts = entry.retool_id ? entry.retool_id.split('.') : [];
|
|
93
93
|
const parent_key = retool_id_parts[0];
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
// Special handling for has_any_claim_history field which depends on claims_data
|
|
96
|
+
if (entry.socotra_id === 'has_any_claim_history' && retool_payload.claims_data) {
|
|
97
|
+
entry.socotra_update(retool_payload, payload);
|
|
98
|
+
} else if (Object.keys(retool_payload).includes(entry.retool_id) ||
|
|
96
99
|
(parent_key && Object.keys(retool_payload).includes(parent_key))) {
|
|
97
100
|
if(entry instanceof SocotraGroupEntry){
|
|
98
101
|
entry.socotra_update(retool_payload, payload, old_payload)
|
|
@@ -5,6 +5,7 @@ const socotra_locations = Object.freeze([
|
|
|
5
5
|
'policy.fields.array',
|
|
6
6
|
'policy.fields.group',
|
|
7
7
|
'exposure.dwelling.fields',
|
|
8
|
+
'exposure.dwelling.fields.group',
|
|
8
9
|
'policy.group',
|
|
9
10
|
'policy',
|
|
10
11
|
'exposure.dwelling.group',
|
|
@@ -99,6 +100,28 @@ class SocotraEntry {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
socotra_update(retool_payload, socotra_response){
|
|
103
|
+
// Special handling for has_any_claim_history field
|
|
104
|
+
if (this.socotra_id === 'has_any_claim_history') {
|
|
105
|
+
// Use the entire retool_payload for evaluation, not just the field value
|
|
106
|
+
let value = this.to_scotra_func(retool_payload)
|
|
107
|
+
|
|
108
|
+
if(value === ""){
|
|
109
|
+
value = []
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Ensure updateExposures[0].fieldValues exists
|
|
113
|
+
if (!socotra_response.updateExposures) {
|
|
114
|
+
socotra_response.updateExposures = [{ fieldValues: {} }]
|
|
115
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
116
|
+
socotra_response.updateExposures[0] = { fieldValues: {} }
|
|
117
|
+
} else if (!socotra_response.updateExposures[0].fieldValues) {
|
|
118
|
+
socotra_response.updateExposures[0].fieldValues = {}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
socotra_response.updateExposures[0].fieldValues[this.socotra_id] = value
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
102
125
|
let value = this.to_scotra_func(retool_payload[this.retool_id])
|
|
103
126
|
|
|
104
127
|
if(value === ""){
|
|
@@ -108,6 +131,15 @@ class SocotraEntry {
|
|
|
108
131
|
if(this.socotra_location.includes('policy.fields')){
|
|
109
132
|
socotra_response.fieldValues[this.socotra_id] = value
|
|
110
133
|
} else if (this.socotra_location === 'exposure.dwelling.fields') {
|
|
134
|
+
// Ensure updateExposures[0].fieldValues exists
|
|
135
|
+
if (!socotra_response.updateExposures) {
|
|
136
|
+
socotra_response.updateExposures = [{ fieldValues: {} }]
|
|
137
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
138
|
+
socotra_response.updateExposures[0] = { fieldValues: {} }
|
|
139
|
+
} else if (!socotra_response.updateExposures[0].fieldValues) {
|
|
140
|
+
socotra_response.updateExposures[0].fieldValues = {}
|
|
141
|
+
}
|
|
142
|
+
|
|
111
143
|
socotra_response.updateExposures[0].fieldValues[this.socotra_id] = value
|
|
112
144
|
} else if (this.socotra_location === 'quote.name'){
|
|
113
145
|
socotra_response.name = value
|
|
@@ -261,11 +293,6 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
261
293
|
|
|
262
294
|
// If data is an array, process each item
|
|
263
295
|
if (Array.isArray(data)) {
|
|
264
|
-
// Initialize fieldGroups if it doesn't exist
|
|
265
|
-
if (!socotra_response.fieldGroups) {
|
|
266
|
-
socotra_response.fieldGroups = [];
|
|
267
|
-
}
|
|
268
|
-
|
|
269
296
|
// Transform each item according to the schemas
|
|
270
297
|
const transformedData = data.map(item => {
|
|
271
298
|
const fieldValues = {};
|
|
@@ -287,8 +314,25 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
287
314
|
};
|
|
288
315
|
});
|
|
289
316
|
|
|
290
|
-
// Add the transformed data to the
|
|
291
|
-
|
|
317
|
+
// Add the transformed data to the appropriate location based on socotra_location
|
|
318
|
+
// Only add if there's actually data to add
|
|
319
|
+
if (transformedData.length > 0) {
|
|
320
|
+
if (this.socotra_location === 'policy.fields.group') {
|
|
321
|
+
// Initialize fieldGroups if it doesn't exist
|
|
322
|
+
if (!socotra_response.fieldGroups) {
|
|
323
|
+
socotra_response.fieldGroups = [];
|
|
324
|
+
}
|
|
325
|
+
// Append to fieldGroups instead of overwriting
|
|
326
|
+
socotra_response.fieldGroups.push(...transformedData);
|
|
327
|
+
} else if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
328
|
+
// Initialize exposures[0].fieldGroups if it doesn't exist
|
|
329
|
+
if (!socotra_response.exposures[0].fieldGroups) {
|
|
330
|
+
socotra_response.exposures[0].fieldGroups = [];
|
|
331
|
+
}
|
|
332
|
+
// Append to fieldGroups instead of overwriting
|
|
333
|
+
socotra_response.exposures[0].fieldGroups.push(...transformedData);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
292
336
|
}
|
|
293
337
|
}
|
|
294
338
|
|
|
@@ -344,11 +388,7 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
344
388
|
}
|
|
345
389
|
}
|
|
346
390
|
}
|
|
347
|
-
return;
|
|
348
391
|
}
|
|
349
|
-
|
|
350
|
-
// Fall back to the parent class implementation for non-group fields
|
|
351
|
-
return super.retool_response(socotra_payload, retool_response);
|
|
352
392
|
}
|
|
353
393
|
|
|
354
394
|
// Helper function to navigate through nested structure
|
|
@@ -391,19 +431,61 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
391
431
|
// Transform the item for add
|
|
392
432
|
const fieldValues = this._createFieldValues(item);
|
|
393
433
|
|
|
394
|
-
//
|
|
395
|
-
|
|
434
|
+
// Create the field group object
|
|
435
|
+
const fieldGroup = {
|
|
396
436
|
fieldName: this.socotra_id,
|
|
397
437
|
fieldValues: fieldValues
|
|
398
|
-
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// Add to the appropriate location based on socotra_location
|
|
441
|
+
if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
442
|
+
// Initialize updateExposures[0].addFieldGroups if it doesn't exist
|
|
443
|
+
if (!socotra_response.updateExposures) {
|
|
444
|
+
socotra_response.updateExposures = [{ addFieldGroups: [] }];
|
|
445
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
446
|
+
socotra_response.updateExposures[0] = { addFieldGroups: [] };
|
|
447
|
+
} else if (!socotra_response.updateExposures[0].addFieldGroups) {
|
|
448
|
+
socotra_response.updateExposures[0].addFieldGroups = [];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Add to updateExposures[0].addFieldGroups
|
|
452
|
+
socotra_response.updateExposures[0].addFieldGroups.push(fieldGroup);
|
|
453
|
+
} else {
|
|
454
|
+
// Initialize addFieldGroups if it doesn't exist
|
|
455
|
+
if (!socotra_response.addFieldGroups) {
|
|
456
|
+
socotra_response.addFieldGroups = [];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Add to addFieldGroups (for policy.fields.group)
|
|
460
|
+
socotra_response.addFieldGroups.push(fieldGroup);
|
|
461
|
+
}
|
|
399
462
|
}
|
|
400
463
|
|
|
401
464
|
// Helper function to process explicit remove operations
|
|
402
465
|
_processRemoveOperations(data, socotra_response) {
|
|
403
466
|
for (const item of data) {
|
|
404
467
|
if (item.remove === true && item.locator) {
|
|
405
|
-
|
|
406
|
-
|
|
468
|
+
if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
469
|
+
// Initialize updateExposures[0].removeFieldGroups if it doesn't exist
|
|
470
|
+
if (!socotra_response.updateExposures) {
|
|
471
|
+
socotra_response.updateExposures = [{ removeFieldGroups: [] }];
|
|
472
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
473
|
+
socotra_response.updateExposures[0] = { removeFieldGroups: [] };
|
|
474
|
+
} else if (!socotra_response.updateExposures[0].removeFieldGroups) {
|
|
475
|
+
socotra_response.updateExposures[0].removeFieldGroups = [];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Add to updateExposures[0].removeFieldGroups
|
|
479
|
+
socotra_response.updateExposures[0].removeFieldGroups.push(item.locator);
|
|
480
|
+
} else {
|
|
481
|
+
// Initialize removeFieldGroups if it doesn't exist
|
|
482
|
+
if (!socotra_response.removeFieldGroups) {
|
|
483
|
+
socotra_response.removeFieldGroups = [];
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Add to removeFieldGroups (for policy.fields.group)
|
|
487
|
+
socotra_response.removeFieldGroups.push(item.locator);
|
|
488
|
+
}
|
|
407
489
|
}
|
|
408
490
|
}
|
|
409
491
|
}
|
|
@@ -461,7 +543,27 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
461
543
|
}
|
|
462
544
|
// If the item only exists in old, remove it
|
|
463
545
|
else if (oldItem.socotra_field_locator) {
|
|
464
|
-
|
|
546
|
+
if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
547
|
+
// Initialize updateExposures[0].removeFieldGroups if it doesn't exist
|
|
548
|
+
if (!socotra_response.updateExposures) {
|
|
549
|
+
socotra_response.updateExposures = [{ removeFieldGroups: [] }];
|
|
550
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
551
|
+
socotra_response.updateExposures[0] = { removeFieldGroups: [] };
|
|
552
|
+
} else if (!socotra_response.updateExposures[0].removeFieldGroups) {
|
|
553
|
+
socotra_response.updateExposures[0].removeFieldGroups = [];
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Add to updateExposures[0].removeFieldGroups
|
|
557
|
+
socotra_response.updateExposures[0].removeFieldGroups.push(oldItem.socotra_field_locator);
|
|
558
|
+
} else {
|
|
559
|
+
// Initialize removeFieldGroups if it doesn't exist
|
|
560
|
+
if (!socotra_response.removeFieldGroups) {
|
|
561
|
+
socotra_response.removeFieldGroups = [];
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Add to removeFieldGroups (for policy.fields.group)
|
|
565
|
+
socotra_response.removeFieldGroups.push(oldItem.socotra_field_locator);
|
|
566
|
+
}
|
|
465
567
|
}
|
|
466
568
|
}
|
|
467
569
|
|
|
@@ -478,12 +580,40 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
478
580
|
}
|
|
479
581
|
|
|
480
582
|
// Remove empty arrays
|
|
481
|
-
if (socotra_response.addFieldGroups.length === 0) {
|
|
583
|
+
if (socotra_response.addFieldGroups && socotra_response.addFieldGroups.length === 0) {
|
|
482
584
|
delete socotra_response.addFieldGroups;
|
|
483
585
|
}
|
|
484
|
-
if (socotra_response.removeFieldGroups.length === 0) {
|
|
586
|
+
if (socotra_response.removeFieldGroups && socotra_response.removeFieldGroups.length === 0) {
|
|
485
587
|
delete socotra_response.removeFieldGroups;
|
|
486
588
|
}
|
|
589
|
+
|
|
590
|
+
// Clean up updateExposures if it exists
|
|
591
|
+
if (socotra_response.updateExposures) {
|
|
592
|
+
// Check if updateExposures[0] exists
|
|
593
|
+
if (socotra_response.updateExposures[0]) {
|
|
594
|
+
// Check if addFieldGroups is empty
|
|
595
|
+
if (socotra_response.updateExposures[0].addFieldGroups &&
|
|
596
|
+
socotra_response.updateExposures[0].addFieldGroups.length === 0) {
|
|
597
|
+
delete socotra_response.updateExposures[0].addFieldGroups;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Check if removeFieldGroups is empty
|
|
601
|
+
if (socotra_response.updateExposures[0].removeFieldGroups &&
|
|
602
|
+
socotra_response.updateExposures[0].removeFieldGroups.length === 0) {
|
|
603
|
+
delete socotra_response.updateExposures[0].removeFieldGroups;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Check if updateExposures[0] is now empty
|
|
607
|
+
if (Object.keys(socotra_response.updateExposures[0]).length === 0) {
|
|
608
|
+
socotra_response.updateExposures.splice(0, 1);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Check if updateExposures is now empty
|
|
613
|
+
if (socotra_response.updateExposures.length === 0) {
|
|
614
|
+
delete socotra_response.updateExposures;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
487
617
|
}
|
|
488
618
|
}
|
|
489
619
|
|
|
@@ -17,7 +17,7 @@ entries_v3 = [
|
|
|
17
17
|
new SocotraEntry("square_feet", "square_feet", "exposure.dwelling.fields", undefined, parseInt),
|
|
18
18
|
new SocotraEntry("stand_protect_discount", "stand_protect_discount", "exposure.dwelling.fields"),
|
|
19
19
|
new SocotraEntry("multi_policy_discount", "multi_policy_discount", "exposure.dwelling.fields"),
|
|
20
|
-
new SocotraEntry(undefined, "has_any_claim_history", "exposure.dwelling.fields", (x) => undefined, x => "No"),
|
|
20
|
+
new SocotraEntry(undefined, "has_any_claim_history", "exposure.dwelling.fields", (x) => undefined, x => x && x.claims_data && x.claims_data.claims && x.claims_data.claims.length > 0 ? "Yes" : "No"),
|
|
21
21
|
new SocotraEntry("roof_rating", "roof_rating", "exposure.dwelling.fields"),
|
|
22
22
|
new SocotraEntry("slab_plumbing", "slab_plumbing", "exposure.dwelling.fields"),
|
|
23
23
|
new SocotraEntry("foundation_type", "foundation_type", "exposure.dwelling.fields"),
|
|
@@ -195,8 +195,6 @@ entries_v3 = [
|
|
|
195
195
|
new SocotraEntry("water_supply_fittings_type", "water_supply_fittings_type", "policy.fields"),
|
|
196
196
|
new SocotraEntry("prior_status_reason", "prev_policy_status", "policy.fields"),
|
|
197
197
|
new SocotraEntry("prior_policy_status", "prev_policy_status", "policy.fields"),
|
|
198
|
-
//TODO figure out how to connect AI Data
|
|
199
|
-
//TODO figure out how to connect claims
|
|
200
198
|
|
|
201
199
|
//Maybe
|
|
202
200
|
// bite history
|
|
@@ -240,6 +238,31 @@ entries_v3.push(
|
|
|
240
238
|
)
|
|
241
239
|
);
|
|
242
240
|
|
|
241
|
+
// Define schemas for Groups
|
|
242
|
+
const claims_retool_schema = {
|
|
243
|
+
date: ":date",
|
|
244
|
+
amount: ":amount",
|
|
245
|
+
type: ":type",
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const claims_socotra_schema = {
|
|
249
|
+
prior_claim_type: ":type",
|
|
250
|
+
accident_date: ":date",
|
|
251
|
+
claim_amount: ":amount",
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// Create the claims SocotraGroupEntry
|
|
255
|
+
const claims_entry = new SocotraGroupEntry(
|
|
256
|
+
"claims_data.claims",
|
|
257
|
+
"claims_history",
|
|
258
|
+
"exposure.dwelling.fields.group",
|
|
259
|
+
claims_socotra_schema,
|
|
260
|
+
claims_retool_schema
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
// Add claims entry to entries_v3
|
|
264
|
+
entries_v3.push(claims_entry);
|
|
265
|
+
|
|
243
266
|
|
|
244
267
|
|
|
245
268
|
|