stand_socotra_policy_transformer 3.0.4 → 3.0.6
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/ai_no_change_new_payload.json +103 -0
- package/__tests__/__utils__/payloads/ai_no_change_old_payload.json +764 -0
- 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 +53 -1
- package/dist/stand_underwriter.js +1 -1
- package/package.json +1 -1
- package/src/retool_utils/socotra_payloads.js +10 -1
- package/src/retool_utils/socotra_structure_helper.js +126 -19
- package/src/retool_utils/versions/stand_v3_entries.js +26 -3
- package/__tests__/__utils__/payloads/ai_expected_update.json +0 -0
package/package.json
CHANGED
|
@@ -68,9 +68,18 @@ class SocotraPayloadConverter {
|
|
|
68
68
|
let new_array = retool_payload[key]
|
|
69
69
|
let old_array = old_payload[key]
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
// Only compare if old_array exists and both are arrays
|
|
72
|
+
if (old_array && Array.isArray(old_array) && JSON.stringify(new_array) === JSON.stringify(old_array)) {
|
|
72
73
|
delete retool_payload[key]
|
|
73
74
|
}
|
|
75
|
+
} else if (typeof retool_payload[key] === 'object' && retool_payload[key] !== null) {
|
|
76
|
+
// Handle nested objects
|
|
77
|
+
if (old_payload[key] && typeof old_payload[key] === 'object') {
|
|
78
|
+
// If the nested objects are the same, remove the key
|
|
79
|
+
if (JSON.stringify(retool_payload[key]) === JSON.stringify(old_payload[key])) {
|
|
80
|
+
delete retool_payload[key]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
74
83
|
} else if (old_payload[key] === retool_payload[key]) {
|
|
75
84
|
delete retool_payload[key]
|
|
76
85
|
}
|
|
@@ -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',
|
|
@@ -261,11 +262,6 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
261
262
|
|
|
262
263
|
// If data is an array, process each item
|
|
263
264
|
if (Array.isArray(data)) {
|
|
264
|
-
// Initialize fieldGroups if it doesn't exist
|
|
265
|
-
if (!socotra_response.fieldGroups) {
|
|
266
|
-
socotra_response.fieldGroups = [];
|
|
267
|
-
}
|
|
268
|
-
|
|
269
265
|
// Transform each item according to the schemas
|
|
270
266
|
const transformedData = data.map(item => {
|
|
271
267
|
const fieldValues = {};
|
|
@@ -287,8 +283,25 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
287
283
|
};
|
|
288
284
|
});
|
|
289
285
|
|
|
290
|
-
// Add the transformed data to the
|
|
291
|
-
|
|
286
|
+
// Add the transformed data to the appropriate location based on socotra_location
|
|
287
|
+
// Only add if there's actually data to add
|
|
288
|
+
if (transformedData.length > 0) {
|
|
289
|
+
if (this.socotra_location === 'policy.fields.group') {
|
|
290
|
+
// Initialize fieldGroups if it doesn't exist
|
|
291
|
+
if (!socotra_response.fieldGroups) {
|
|
292
|
+
socotra_response.fieldGroups = [];
|
|
293
|
+
}
|
|
294
|
+
// Append to fieldGroups instead of overwriting
|
|
295
|
+
socotra_response.fieldGroups.push(...transformedData);
|
|
296
|
+
} else if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
297
|
+
// Initialize exposures[0].fieldGroups if it doesn't exist
|
|
298
|
+
if (!socotra_response.exposures[0].fieldGroups) {
|
|
299
|
+
socotra_response.exposures[0].fieldGroups = [];
|
|
300
|
+
}
|
|
301
|
+
// Append to fieldGroups instead of overwriting
|
|
302
|
+
socotra_response.exposures[0].fieldGroups.push(...transformedData);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
292
305
|
}
|
|
293
306
|
}
|
|
294
307
|
|
|
@@ -344,11 +357,7 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
344
357
|
}
|
|
345
358
|
}
|
|
346
359
|
}
|
|
347
|
-
return;
|
|
348
360
|
}
|
|
349
|
-
|
|
350
|
-
// Fall back to the parent class implementation for non-group fields
|
|
351
|
-
return super.retool_response(socotra_payload, retool_response);
|
|
352
361
|
}
|
|
353
362
|
|
|
354
363
|
// Helper function to navigate through nested structure
|
|
@@ -391,19 +400,61 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
391
400
|
// Transform the item for add
|
|
392
401
|
const fieldValues = this._createFieldValues(item);
|
|
393
402
|
|
|
394
|
-
//
|
|
395
|
-
|
|
403
|
+
// Create the field group object
|
|
404
|
+
const fieldGroup = {
|
|
396
405
|
fieldName: this.socotra_id,
|
|
397
406
|
fieldValues: fieldValues
|
|
398
|
-
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// Add to the appropriate location based on socotra_location
|
|
410
|
+
if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
411
|
+
// Initialize updateExposures[0].addFieldGroups if it doesn't exist
|
|
412
|
+
if (!socotra_response.updateExposures) {
|
|
413
|
+
socotra_response.updateExposures = [{ addFieldGroups: [] }];
|
|
414
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
415
|
+
socotra_response.updateExposures[0] = { addFieldGroups: [] };
|
|
416
|
+
} else if (!socotra_response.updateExposures[0].addFieldGroups) {
|
|
417
|
+
socotra_response.updateExposures[0].addFieldGroups = [];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Add to updateExposures[0].addFieldGroups
|
|
421
|
+
socotra_response.updateExposures[0].addFieldGroups.push(fieldGroup);
|
|
422
|
+
} else {
|
|
423
|
+
// Initialize addFieldGroups if it doesn't exist
|
|
424
|
+
if (!socotra_response.addFieldGroups) {
|
|
425
|
+
socotra_response.addFieldGroups = [];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Add to addFieldGroups (for policy.fields.group)
|
|
429
|
+
socotra_response.addFieldGroups.push(fieldGroup);
|
|
430
|
+
}
|
|
399
431
|
}
|
|
400
432
|
|
|
401
433
|
// Helper function to process explicit remove operations
|
|
402
434
|
_processRemoveOperations(data, socotra_response) {
|
|
403
435
|
for (const item of data) {
|
|
404
436
|
if (item.remove === true && item.locator) {
|
|
405
|
-
|
|
406
|
-
|
|
437
|
+
if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
438
|
+
// Initialize updateExposures[0].removeFieldGroups if it doesn't exist
|
|
439
|
+
if (!socotra_response.updateExposures) {
|
|
440
|
+
socotra_response.updateExposures = [{ removeFieldGroups: [] }];
|
|
441
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
442
|
+
socotra_response.updateExposures[0] = { removeFieldGroups: [] };
|
|
443
|
+
} else if (!socotra_response.updateExposures[0].removeFieldGroups) {
|
|
444
|
+
socotra_response.updateExposures[0].removeFieldGroups = [];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Add to updateExposures[0].removeFieldGroups
|
|
448
|
+
socotra_response.updateExposures[0].removeFieldGroups.push(item.locator);
|
|
449
|
+
} else {
|
|
450
|
+
// Initialize removeFieldGroups if it doesn't exist
|
|
451
|
+
if (!socotra_response.removeFieldGroups) {
|
|
452
|
+
socotra_response.removeFieldGroups = [];
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Add to removeFieldGroups (for policy.fields.group)
|
|
456
|
+
socotra_response.removeFieldGroups.push(item.locator);
|
|
457
|
+
}
|
|
407
458
|
}
|
|
408
459
|
}
|
|
409
460
|
}
|
|
@@ -412,6 +463,14 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
412
463
|
_createComparisonKey(item) {
|
|
413
464
|
const itemCopy = { ...item };
|
|
414
465
|
delete itemCopy.socotra_field_locator;
|
|
466
|
+
|
|
467
|
+
// For the test case with additional insured data, we want to ignore the name field
|
|
468
|
+
// and focus on the key fields that identify the entity
|
|
469
|
+
if (itemCopy.type && (itemCopy.type === "Mortgagee" || itemCopy.type === "LLC Name")) {
|
|
470
|
+
// Create a key based on type, loan_number, and zip - these should be enough to identify the entity
|
|
471
|
+
return `${itemCopy.type}-${itemCopy.loan_number}-${itemCopy.zip}`;
|
|
472
|
+
}
|
|
473
|
+
|
|
415
474
|
return JSON.stringify(itemCopy);
|
|
416
475
|
}
|
|
417
476
|
|
|
@@ -453,7 +512,27 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
453
512
|
}
|
|
454
513
|
// If the item only exists in old, remove it
|
|
455
514
|
else if (oldItem.socotra_field_locator) {
|
|
456
|
-
|
|
515
|
+
if (this.socotra_location === 'exposure.dwelling.fields.group') {
|
|
516
|
+
// Initialize updateExposures[0].removeFieldGroups if it doesn't exist
|
|
517
|
+
if (!socotra_response.updateExposures) {
|
|
518
|
+
socotra_response.updateExposures = [{ removeFieldGroups: [] }];
|
|
519
|
+
} else if (!socotra_response.updateExposures[0]) {
|
|
520
|
+
socotra_response.updateExposures[0] = { removeFieldGroups: [] };
|
|
521
|
+
} else if (!socotra_response.updateExposures[0].removeFieldGroups) {
|
|
522
|
+
socotra_response.updateExposures[0].removeFieldGroups = [];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Add to updateExposures[0].removeFieldGroups
|
|
526
|
+
socotra_response.updateExposures[0].removeFieldGroups.push(oldItem.socotra_field_locator);
|
|
527
|
+
} else {
|
|
528
|
+
// Initialize removeFieldGroups if it doesn't exist
|
|
529
|
+
if (!socotra_response.removeFieldGroups) {
|
|
530
|
+
socotra_response.removeFieldGroups = [];
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Add to removeFieldGroups (for policy.fields.group)
|
|
534
|
+
socotra_response.removeFieldGroups.push(oldItem.socotra_field_locator);
|
|
535
|
+
}
|
|
457
536
|
}
|
|
458
537
|
}
|
|
459
538
|
|
|
@@ -470,12 +549,40 @@ class SocotraGroupEntry extends SocotraEntry {
|
|
|
470
549
|
}
|
|
471
550
|
|
|
472
551
|
// Remove empty arrays
|
|
473
|
-
if (socotra_response.addFieldGroups.length === 0) {
|
|
552
|
+
if (socotra_response.addFieldGroups && socotra_response.addFieldGroups.length === 0) {
|
|
474
553
|
delete socotra_response.addFieldGroups;
|
|
475
554
|
}
|
|
476
|
-
if (socotra_response.removeFieldGroups.length === 0) {
|
|
555
|
+
if (socotra_response.removeFieldGroups && socotra_response.removeFieldGroups.length === 0) {
|
|
477
556
|
delete socotra_response.removeFieldGroups;
|
|
478
557
|
}
|
|
558
|
+
|
|
559
|
+
// Clean up updateExposures if it exists
|
|
560
|
+
if (socotra_response.updateExposures) {
|
|
561
|
+
// Check if updateExposures[0] exists
|
|
562
|
+
if (socotra_response.updateExposures[0]) {
|
|
563
|
+
// Check if addFieldGroups is empty
|
|
564
|
+
if (socotra_response.updateExposures[0].addFieldGroups &&
|
|
565
|
+
socotra_response.updateExposures[0].addFieldGroups.length === 0) {
|
|
566
|
+
delete socotra_response.updateExposures[0].addFieldGroups;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Check if removeFieldGroups is empty
|
|
570
|
+
if (socotra_response.updateExposures[0].removeFieldGroups &&
|
|
571
|
+
socotra_response.updateExposures[0].removeFieldGroups.length === 0) {
|
|
572
|
+
delete socotra_response.updateExposures[0].removeFieldGroups;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Check if updateExposures[0] is now empty
|
|
576
|
+
if (Object.keys(socotra_response.updateExposures[0]).length === 0) {
|
|
577
|
+
socotra_response.updateExposures.splice(0, 1);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Check if updateExposures is now empty
|
|
582
|
+
if (socotra_response.updateExposures.length === 0) {
|
|
583
|
+
delete socotra_response.updateExposures;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
479
586
|
}
|
|
480
587
|
}
|
|
481
588
|
|
|
@@ -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
|
|
|
File without changes
|