@lendi/integrations-transform 1.5.8 → 1.5.9
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/lib/index.js +10 -26
- package/lib/logger.d.ts +1 -2
- package/lib/logger.js +2 -5
- package/lib/transform-events/generate-asset-liability-link.d.ts +3 -1
- package/lib/transform-events/generate-asset-liability-link.js +14 -18
- package/lib/transform-events/generate-credit-report-rebuilt.js +17 -21
- package/lib/transform-events/generate-employment.d.ts +1 -1
- package/lib/transform-events/generate-employment.js +51 -56
- package/lib/transform-events/generate-required-document.d.ts +1 -7
- package/lib/transform-events/generate-required-document.js +43 -69
- package/lib/transform-events/transform-applicant.d.ts +2 -1
- package/lib/transform-events/transform-applicant.js +78 -91
- package/lib/transform-events/transform-application-workflow.d.ts +0 -1
- package/lib/transform-events/transform-application-workflow.js +9 -14
- package/lib/transform-events/transform-application.d.ts +3 -1
- package/lib/transform-events/transform-application.js +28 -33
- package/lib/transform-events/transform-asset-address.d.ts +8 -2
- package/lib/transform-events/transform-asset-address.js +35 -37
- package/lib/transform-events/transform-asset.d.ts +7 -1
- package/lib/transform-events/transform-asset.js +164 -184
- package/lib/transform-events/transform-expenses.d.ts +4 -0
- package/lib/transform-events/transform-expenses.js +52 -58
- package/lib/transform-events/transform-funding-position.d.ts +2 -2
- package/lib/transform-events/transform-funding-position.js +38 -46
- package/lib/transform-events/transform-income.d.ts +8 -1
- package/lib/transform-events/transform-income.js +121 -139
- package/lib/transform-events/transform-liability.d.ts +4 -1
- package/lib/transform-events/transform-liability.js +62 -65
- package/lib/transform-events/transform-percent-owned.d.ts +1 -0
- package/lib/transform-events/transform-percent-owned.js +7 -14
- package/lib/types/enum-mappings/alieo-frequency.js +22 -26
- package/lib/types/enum-mappings/asset-type.js +14 -18
- package/lib/types/enum-mappings/builder-type.js +6 -10
- package/lib/types/enum-mappings/construction-type.js +7 -11
- package/lib/types/enum-mappings/country-code.js +243 -247
- package/lib/types/enum-mappings/employment-basis.js +9 -13
- package/lib/types/enum-mappings/expense-frequency.js +8 -12
- package/lib/types/enum-mappings/funding-position.js +29 -32
- package/lib/types/enum-mappings/government-benefits.js +7 -11
- package/lib/types/enum-mappings/housing-status.js +12 -16
- package/lib/types/enum-mappings/income-type.js +13 -17
- package/lib/types/enum-mappings/index.js +27 -43
- package/lib/types/enum-mappings/liability-payment-type.js +6 -10
- package/lib/types/enum-mappings/liability-type.js +18 -22
- package/lib/types/enum-mappings/living-expense.js +27 -31
- package/lib/types/enum-mappings/marital-status.js +9 -13
- package/lib/types/enum-mappings/postcode.js +11 -15
- package/lib/types/enum-mappings/preferred-repayment.js +7 -11
- package/lib/types/enum-mappings/proof-of-identity.js +7 -11
- package/lib/types/enum-mappings/property-expense-category.js +8 -12
- package/lib/types/enum-mappings/public-financial-asset.js +9 -13
- package/lib/types/enum-mappings/public-primary-purpose.js +6 -10
- package/lib/types/enum-mappings/public-property-status.js +8 -12
- package/lib/types/enum-mappings/public-property-type.js +20 -24
- package/lib/types/enum-mappings/residency-status.js +8 -12
- package/lib/types/enum-mappings/title-gender.js +10 -14
- package/lib/types/enum-mappings/title.js +10 -14
- package/lib/types/enum-mappings/to-be-purchased.js +4 -7
- package/lib/types/enum-mappings/to-be-used-as-security.js +4 -7
- package/lib/types/enum-mappings/transaction-type.js +6 -10
- package/lib/types/enum-mappings/verification.js +10 -14
- package/lib/types/events/applicant-delete.js +4 -7
- package/lib/types/events/application-workflow.js +10 -13
- package/lib/types/events/asset-delete.js +4 -7
- package/lib/types/events/asset-liability-relation-delete.js +4 -7
- package/lib/types/events/credit-report-retrieved.js +4 -7
- package/lib/types/events/employment-delete.js +2 -5
- package/lib/types/events/expense-delete.js +2 -5
- package/lib/types/events/funding-position.js +6 -9
- package/lib/types/events/income-delete.js +4 -7
- package/lib/types/events/liability-delete.js +2 -5
- package/lib/types/events/opportunity.js +6 -9
- package/lib/types/events/public-applicant.js +28 -31
- package/lib/types/events/public-application.js +26 -29
- package/lib/types/events/public-asset-liability-relation.js +4 -7
- package/lib/types/events/public-asset.js +26 -29
- package/lib/types/events/public-employment.js +18 -21
- package/lib/types/events/public-expense.js +8 -11
- package/lib/types/events/public-funding-position.js +2 -5
- package/lib/types/events/public-income.js +12 -15
- package/lib/types/events/public-liability.js +16 -19
- package/lib/types/events/public-required-document.js +14 -17
- package/lib/types/partial-application.js +1 -2
- package/lib/types/recursive-partial.js +1 -2
- package/lib/update-application/merge-application.d.ts +1 -1
- package/lib/update-application/merge-application.js +41 -38
- package/lib/update-application/update-primary-applicant.d.ts +1 -4
- package/lib/update-application/update-primary-applicant.js +14 -38
- package/lib/utils/address-tools.d.ts +3 -1
- package/lib/utils/address-tools.js +56 -68
- package/lib/utils/clean-up.d.ts +1 -1
- package/lib/utils/clean-up.js +6 -10
- package/lib/utils/formatYesNo.d.ts +0 -1
- package/lib/utils/formatYesNo.js +2 -7
- package/lib/utils/generate-address.d.ts +3 -2
- package/lib/utils/generate-address.js +33 -42
- package/lib/utils/get-financial-institution.d.ts +1 -0
- package/lib/utils/get-financial-institution.js +7 -10
- package/lib/utils/is-asset-type.js +13 -20
- package/lib/utils/is-income-type.d.ts +2 -0
- package/lib/utils/is-income-type.js +50 -69
- package/lib/utils/iso-date.d.ts +0 -1
- package/lib/utils/iso-date.js +2 -7
- package/lib/utils/normalise-date.js +6 -10
- package/lib/utils/round-decimal.js +1 -5
- package/package.json +14 -17
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.deepMergeApplication = void 0;
|
|
4
|
-
var merge = require("deepmerge");
|
|
5
|
-
var cleanDeep = require('clean-deep');
|
|
1
|
+
import * as merge from 'deepmerge';
|
|
2
|
+
const cleanDeep = require('clean-deep');
|
|
6
3
|
/**
|
|
7
4
|
* Deep merges the application and custom handles specific arrays
|
|
8
5
|
*
|
|
9
6
|
* @param newApplication new application coming from events.
|
|
10
7
|
* @param existingApplication a saved dynamo application.
|
|
11
|
-
* @
|
|
8
|
+
* @returns merged application.
|
|
12
9
|
*/
|
|
13
|
-
function deepMergeApplication(existingApplication, newApplication) {
|
|
10
|
+
export function deepMergeApplication(existingApplication, newApplication) {
|
|
14
11
|
// Array fields with @UniqueIDs
|
|
15
|
-
|
|
12
|
+
const listsWithUniqueIds = [
|
|
16
13
|
'Attachment',
|
|
17
14
|
'Address',
|
|
18
15
|
'CompanyApplicant',
|
|
@@ -29,22 +26,22 @@ function deepMergeApplication(existingApplication, newApplication) {
|
|
|
29
26
|
'RelatedPerson',
|
|
30
27
|
];
|
|
31
28
|
// Array fields with @x_Party
|
|
32
|
-
|
|
29
|
+
const listsWithXParty = ['Report'];
|
|
33
30
|
// Array fields with @x_Owner
|
|
34
|
-
|
|
31
|
+
const listsWithXOwner = ['RentalIncome'];
|
|
35
32
|
// Array fields with @x_Applicant
|
|
36
|
-
|
|
33
|
+
const listsWithXApplicant = ['Applicant'];
|
|
37
34
|
// Array fields with @x_ResidentialAddress
|
|
38
|
-
|
|
35
|
+
const listsWithXResidentialAddress = ['PriorAddress'];
|
|
39
36
|
// Array fields with @x_Guarantor
|
|
40
|
-
|
|
37
|
+
const listsWithXGuarantor = ['Guarantor'];
|
|
41
38
|
// Curried function which takes a uniqueKey and returns a function which will either replace
|
|
42
39
|
// or merge the item in the array based on the uniqueKey
|
|
43
40
|
if (!existingApplication) {
|
|
44
41
|
return newApplication;
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
return
|
|
43
|
+
const mergeItems = (uniqueKey) => {
|
|
44
|
+
return (existingItem, newItem) => {
|
|
48
45
|
// if not array continue with merge
|
|
49
46
|
if (!Array.isArray(newItem)) {
|
|
50
47
|
return merge(existingItem, newItem, options);
|
|
@@ -52,75 +49,81 @@ function deepMergeApplication(existingApplication, newApplication) {
|
|
|
52
49
|
return findArrayItemAndMerge(existingItem, newItem, uniqueKey, options);
|
|
53
50
|
};
|
|
54
51
|
};
|
|
55
|
-
|
|
56
|
-
customMerge:
|
|
57
|
-
if (listsWithUniqueIds.find(
|
|
52
|
+
const options = {
|
|
53
|
+
customMerge: (key) => {
|
|
54
|
+
if (listsWithUniqueIds.find((item) => item === key)) {
|
|
58
55
|
return mergeItems('@UniqueID');
|
|
59
56
|
}
|
|
60
|
-
if (listsWithXParty.find(
|
|
57
|
+
if (listsWithXParty.find((item) => item === key)) {
|
|
61
58
|
return mergeItems('@x_Party');
|
|
62
59
|
}
|
|
63
|
-
if (listsWithXOwner.find(
|
|
60
|
+
if (listsWithXOwner.find((item) => item === key)) {
|
|
64
61
|
return mergeItems('@x_Owner');
|
|
65
62
|
}
|
|
66
|
-
if (listsWithXResidentialAddress.find(
|
|
63
|
+
if (listsWithXResidentialAddress.find((item) => item === key)) {
|
|
67
64
|
return mergeItems('@x_ResidentialAddress');
|
|
68
65
|
}
|
|
69
|
-
if (listsWithXApplicant.find(
|
|
66
|
+
if (listsWithXApplicant.find((item) => item === key)) {
|
|
70
67
|
return mergeItems('@x_Applicant');
|
|
71
68
|
}
|
|
72
|
-
if (listsWithXGuarantor.find(
|
|
69
|
+
if (listsWithXGuarantor.find((item) => item === key)) {
|
|
73
70
|
return mergeItems('@x_Guarantor');
|
|
74
71
|
}
|
|
75
72
|
return mergeItems(key);
|
|
76
|
-
}
|
|
73
|
+
},
|
|
77
74
|
};
|
|
78
|
-
|
|
75
|
+
const mergedApplication = merge(existingApplication, newApplication, options);
|
|
79
76
|
// Default configurations of cleanDeep for reference.
|
|
80
|
-
|
|
77
|
+
const params = {
|
|
81
78
|
cleanValues: [],
|
|
82
79
|
emptyArrays: true,
|
|
83
80
|
emptyObjects: true,
|
|
84
81
|
emptyStrings: true,
|
|
85
82
|
NaNValues: true,
|
|
86
83
|
nullValues: true,
|
|
87
|
-
undefinedValues: true
|
|
84
|
+
undefinedValues: true,
|
|
88
85
|
};
|
|
89
86
|
return cleanDeep(mergedApplication, params);
|
|
90
87
|
}
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
const arrayItemToReplaceKeys = ['Owner', 'Attendee', 'Shareholder', 'Fee', 'ContributionFunds', 'RentalIncome'];
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param existingItem
|
|
92
|
+
* @param newItem
|
|
93
|
+
* @param uniqueKey
|
|
94
|
+
* @param options
|
|
95
|
+
*/
|
|
93
96
|
function findArrayItemAndMerge(existingItem, newItem, uniqueKey, options) {
|
|
94
97
|
// For some Key, overwritten the old value with the new data so no merge is happening.
|
|
95
98
|
if (arrayItemToReplaceKeys.includes(uniqueKey))
|
|
96
99
|
return newItem;
|
|
97
|
-
if (uniqueKey === 'Income' && existingItem && existingItem.some(
|
|
100
|
+
if (uniqueKey === 'Income' && existingItem && existingItem.some((item) => item['@StartDate'])) {
|
|
98
101
|
// Income array in CompanyApplicant
|
|
99
102
|
return newItem;
|
|
100
103
|
}
|
|
101
|
-
if (uniqueKey === 'Income' && existingItem && existingItem.some(
|
|
104
|
+
if (uniqueKey === 'Income' && existingItem && existingItem.some((item) => item.BusinessActivityStatement)) {
|
|
102
105
|
// Income array in CompanyApplicant for Low Doc applications
|
|
103
106
|
return newItem;
|
|
104
107
|
}
|
|
105
108
|
// Copying existing array
|
|
106
|
-
|
|
109
|
+
const mergedArray = existingItem.slice();
|
|
107
110
|
// Searching whether item in the new array exists in existing array
|
|
108
|
-
newItem.forEach(
|
|
109
|
-
|
|
111
|
+
newItem.forEach((item) => {
|
|
112
|
+
const indexOfItem = mergedArray.findIndex((existingItem) => {
|
|
110
113
|
// TODO [CORE-2160] how to identify employment without go a level down.
|
|
111
114
|
// Employment needs to go one level deeper to check if the @UniqueID already exist.
|
|
112
115
|
if (uniqueKey === 'Employment') {
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
const currentEmploymentKeys = Object.keys(item);
|
|
117
|
+
const existingEmploymentKeys = Object.keys(existingItem);
|
|
115
118
|
if (currentEmploymentKeys.length && existingEmploymentKeys.length) {
|
|
116
119
|
// Get the unique id from the field with proper value for current employment. The types with undefined value
|
|
117
120
|
// are present in order to remove the related types from existing application. These undefined types will be
|
|
118
121
|
// removed from payload immediately after deep merging.
|
|
119
122
|
// @pliu 19/11/19
|
|
120
|
-
|
|
123
|
+
const currentEmployment = currentEmploymentKeys.find((key) => item[key]);
|
|
121
124
|
// Each employment can only have one of three types.
|
|
122
125
|
// @pliu 19/11/19
|
|
123
|
-
|
|
126
|
+
const existingEmployment = existingEmploymentKeys[0];
|
|
124
127
|
if (currentEmployment && existingEmployment) {
|
|
125
128
|
return existingItem[existingEmployment]['@UniqueID'] === item[currentEmployment]['@UniqueID'];
|
|
126
129
|
}
|
|
@@ -5,16 +5,14 @@ import { Payload } from '../types/events/public-applicant';
|
|
|
5
5
|
* Checks if there are more than one person applicants with applicant type borrower
|
|
6
6
|
*
|
|
7
7
|
* @param {PersonApplicants[]} personApplicants - Person applicants on the deep merged application
|
|
8
|
-
*
|
|
9
8
|
* @returns {boolean} - Whether or not there are more than one applicant with applicant type borrower
|
|
10
9
|
*/
|
|
11
10
|
export declare const isMultiplePersonApplicantBorrowers: (personApplicants: PersonApplicant[]) => boolean;
|
|
12
11
|
/**
|
|
13
12
|
* Updates the primary applicant of the application based on the new primary applicant id
|
|
14
13
|
*
|
|
15
|
-
* @param {
|
|
14
|
+
* @param {string} newPrimaryApplicantId - New primary applicant id
|
|
16
15
|
* @param {PersonApplicant[]} personApplicants - Person applicants from the updated application after deep merge
|
|
17
|
-
*
|
|
18
16
|
* @returns {PersonApplicant[]} - Updated person applicants
|
|
19
17
|
*/
|
|
20
18
|
export declare const updatePrimaryApplicant: (newPrimaryApplicantId: string, personApplicants: PersonApplicant[]) => PersonApplicant[];
|
|
@@ -23,7 +21,6 @@ export declare const updatePrimaryApplicant: (newPrimaryApplicantId: string, per
|
|
|
23
21
|
*
|
|
24
22
|
* @param {PartialApplication} application - Application after deep merge
|
|
25
23
|
* @param {Payload} applicantPayload - Public applicant event payload
|
|
26
|
-
*
|
|
27
24
|
* @returns {PartialApplication} - Updated application
|
|
28
25
|
*/
|
|
29
26
|
declare const updatePrimaryApplicantUsingGuarantor: (application: PartialApplication, applicantPayload: Payload) => PartialApplication;
|
|
@@ -1,65 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
exports.__esModule = true;
|
|
14
|
-
exports.updatePrimaryApplicant = exports.isMultiplePersonApplicantBorrowers = void 0;
|
|
15
|
-
var application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
|
|
16
|
-
var lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
|
|
17
|
-
var lodash_1 = require("lodash");
|
|
18
|
-
var public_applicant_1 = require("../types/events/public-applicant");
|
|
1
|
+
import { paths } from '@lendi/integrations-protocol/lib/utils/application-paths';
|
|
2
|
+
import { ApplicantTypeList, YesNoList, } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
3
|
+
import { get, set } from 'lodash';
|
|
4
|
+
import { ApplicantType } from '../types/events/public-applicant';
|
|
19
5
|
/**
|
|
20
6
|
* Checks if there are more than one person applicants with applicant type borrower
|
|
21
7
|
*
|
|
22
8
|
* @param {PersonApplicants[]} personApplicants - Person applicants on the deep merged application
|
|
23
|
-
*
|
|
24
9
|
* @returns {boolean} - Whether or not there are more than one applicant with applicant type borrower
|
|
25
10
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
export const isMultiplePersonApplicantBorrowers = (personApplicants) => {
|
|
12
|
+
const totalBorrowerApplicants = personApplicants.filter((applicant) => applicant['@ApplicantType'] === ApplicantTypeList.Borrower).length;
|
|
28
13
|
return totalBorrowerApplicants > 1;
|
|
29
14
|
};
|
|
30
|
-
exports.isMultiplePersonApplicantBorrowers = isMultiplePersonApplicantBorrowers;
|
|
31
15
|
/**
|
|
32
16
|
* Updates the primary applicant of the application based on the new primary applicant id
|
|
33
17
|
*
|
|
34
|
-
* @param {
|
|
18
|
+
* @param {string} newPrimaryApplicantId - New primary applicant id
|
|
35
19
|
* @param {PersonApplicant[]} personApplicants - Person applicants from the updated application after deep merge
|
|
36
|
-
*
|
|
37
20
|
* @returns {PersonApplicant[]} - Updated person applicants
|
|
38
21
|
*/
|
|
39
|
-
|
|
40
|
-
return personApplicants.map(function (applicant) {
|
|
41
|
-
var _a;
|
|
42
|
-
return (__assign(__assign({}, applicant), (_a = {}, _a['@PrimaryApplicant'] = applicant['@UniqueID'] === newPrimaryApplicantId ? lixi_internal_request_1.YesNoList.Yes : lixi_internal_request_1.YesNoList.No, _a)));
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
exports.updatePrimaryApplicant = updatePrimaryApplicant;
|
|
22
|
+
export const updatePrimaryApplicant = (newPrimaryApplicantId, personApplicants) => personApplicants.map((applicant) => (Object.assign(Object.assign({}, applicant), { ['@PrimaryApplicant']: applicant['@UniqueID'] === newPrimaryApplicantId ? YesNoList.Yes : YesNoList.No })));
|
|
46
23
|
/**
|
|
47
24
|
* Updates the primary applicant on the application based on the data in the guarantor applicant event
|
|
48
25
|
*
|
|
49
26
|
* @param {PartialApplication} application - Application after deep merge
|
|
50
27
|
* @param {Payload} applicantPayload - Public applicant event payload
|
|
51
|
-
*
|
|
52
28
|
* @returns {PartialApplication} - Updated application
|
|
53
29
|
*/
|
|
54
|
-
|
|
30
|
+
const updatePrimaryApplicantUsingGuarantor = (application, applicantPayload) => {
|
|
55
31
|
var _a;
|
|
56
|
-
|
|
32
|
+
const updatedApplication = application, personApplicants = get(application, paths.PersonApplicants, []);
|
|
57
33
|
// Checks if there are more than one borrower in the application and that the applicant type of the applicant event being processed is GUARANTOR
|
|
58
|
-
if (
|
|
59
|
-
applicantPayload.applicantType ===
|
|
34
|
+
if (isMultiplePersonApplicantBorrowers(personApplicants) &&
|
|
35
|
+
applicantPayload.applicantType === ApplicantType.Guarantor &&
|
|
60
36
|
((_a = applicantPayload.guarantorRelationshipToBorrower) === null || _a === void 0 ? void 0 : _a.applicantId)) {
|
|
61
|
-
|
|
37
|
+
set(updatedApplication, paths.PersonApplicants, updatePrimaryApplicant(applicantPayload.guarantorRelationshipToBorrower.applicantId, personApplicants));
|
|
62
38
|
}
|
|
63
39
|
return updatedApplication;
|
|
64
40
|
};
|
|
65
|
-
|
|
41
|
+
export default updatePrimaryApplicantUsingGuarantor;
|
|
@@ -51,13 +51,15 @@ export interface AddressTransformedType {
|
|
|
51
51
|
*/
|
|
52
52
|
export declare function rebuildAddress(eventAddress: EventAddressType, addressId: string): AddressTransformedType;
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Converts a previous address object from an event model to a LIXI address and corresponding LIXI current address object.
|
|
55
|
+
*
|
|
55
56
|
* @param eventPreviousAddresses
|
|
56
57
|
* @param addressId
|
|
57
58
|
*/
|
|
58
59
|
export declare function rebuildPreviousAddress(eventPreviousAddresses: InternalPreviousAddress[], addressId: string): AddressTransformedType;
|
|
59
60
|
/**
|
|
60
61
|
* Checks if an event is missing country.
|
|
62
|
+
*
|
|
61
63
|
* @param addressEvent
|
|
62
64
|
*/
|
|
63
65
|
export declare function isMissingCountry(addressEvent: EventAddressType): boolean;
|
|
@@ -1,67 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* A set of tools for manipulating addresses in LIXI applications.
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var generate_address_1 = require("./generate-address");
|
|
13
|
-
exports.lixiContactAddressMapping = {
|
|
4
|
+
import { AuStateList, } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
|
|
5
|
+
import { get, set } from 'lodash';
|
|
6
|
+
import { countryCodeMapping } from '../types/enum-mappings/country-code';
|
|
7
|
+
import { housingStatusMapping } from '../types/enum-mappings/housing-status';
|
|
8
|
+
import { Countries, } from '../types/events/public-applicant';
|
|
9
|
+
import { StreetNumberMaxLength } from './generate-address';
|
|
10
|
+
export const lixiContactAddressMapping = {
|
|
14
11
|
externalId: {
|
|
15
|
-
path: '@x_ResidentialAddress'
|
|
12
|
+
path: '@x_ResidentialAddress',
|
|
16
13
|
},
|
|
17
14
|
housingStatus: {
|
|
18
15
|
path: '@HousingStatus',
|
|
19
|
-
transform:
|
|
16
|
+
transform: (value) => housingStatusMapping[value],
|
|
20
17
|
},
|
|
21
18
|
startDate: {
|
|
22
|
-
path: '@StartDate'
|
|
19
|
+
path: '@StartDate',
|
|
23
20
|
},
|
|
24
21
|
endDate: {
|
|
25
|
-
path: '@EndDate'
|
|
26
|
-
}
|
|
22
|
+
path: '@EndDate',
|
|
23
|
+
},
|
|
27
24
|
};
|
|
28
|
-
|
|
25
|
+
export const australianStates = Object.values(AuStateList);
|
|
29
26
|
/**
|
|
30
27
|
* The transform map used for the LIXI address
|
|
31
28
|
*/
|
|
32
|
-
|
|
29
|
+
export const lixiAddressMapping = {
|
|
33
30
|
externalId: {
|
|
34
|
-
path: '@UniqueID'
|
|
31
|
+
path: '@UniqueID',
|
|
35
32
|
},
|
|
36
33
|
'residentialAddress.city': {
|
|
37
|
-
path: '@Suburb'
|
|
34
|
+
path: '@Suburb',
|
|
38
35
|
},
|
|
39
36
|
'residentialAddress.country': {
|
|
40
37
|
path: '@Country',
|
|
41
|
-
transform:
|
|
38
|
+
transform: (value) => countryCodeMapping[value],
|
|
42
39
|
},
|
|
43
40
|
'residentialAddress.postcode': {
|
|
44
|
-
path: '@AustralianPostCode'
|
|
41
|
+
path: '@AustralianPostCode',
|
|
45
42
|
},
|
|
46
43
|
'residentialAddress.state': {
|
|
47
|
-
path: '@AustralianState'
|
|
44
|
+
path: '@AustralianState',
|
|
48
45
|
},
|
|
49
46
|
'residentialAddress.standard.level': {
|
|
50
|
-
path: 'Standard.@Level'
|
|
47
|
+
path: 'Standard.@Level',
|
|
51
48
|
},
|
|
52
49
|
'residentialAddress.standard.streetName': {
|
|
53
|
-
path: 'Standard.@StreetName'
|
|
50
|
+
path: 'Standard.@StreetName',
|
|
54
51
|
},
|
|
55
52
|
'residentialAddress.standard.streetNumber': {
|
|
56
53
|
path: 'Standard.@StreetNumber',
|
|
57
|
-
transform:
|
|
54
|
+
transform: (value) => value.substring(0, StreetNumberMaxLength),
|
|
58
55
|
},
|
|
59
56
|
'residentialAddress.standard.streetType': {
|
|
60
|
-
path: 'Standard.@StreetType'
|
|
57
|
+
path: 'Standard.@StreetType',
|
|
61
58
|
},
|
|
62
59
|
'residentialAddress.standard.unit': {
|
|
63
|
-
path: 'Standard.@Unit'
|
|
64
|
-
}
|
|
60
|
+
path: 'Standard.@Unit',
|
|
61
|
+
},
|
|
65
62
|
};
|
|
66
63
|
/**
|
|
67
64
|
* Transforms a source object by applying a PathMappedTransform.
|
|
@@ -69,110 +66,101 @@ exports.lixiAddressMapping = {
|
|
|
69
66
|
* @param source A source object to be mapped and transformed
|
|
70
67
|
* @param pathMappedTransform A PathMappedTransform to be applied to the source
|
|
71
68
|
*/
|
|
72
|
-
function mapTransform(source, pathMappedTransform) {
|
|
73
|
-
|
|
74
|
-
Object.entries(pathMappedTransform).forEach(
|
|
75
|
-
|
|
76
|
-
var sourceValue = (0, lodash_1.get)(source, key);
|
|
69
|
+
export function mapTransform(source, pathMappedTransform) {
|
|
70
|
+
const finalTransform = {};
|
|
71
|
+
Object.entries(pathMappedTransform).forEach(([key, { transform, path }]) => {
|
|
72
|
+
const sourceValue = get(source, key);
|
|
77
73
|
if (sourceValue) {
|
|
78
|
-
|
|
74
|
+
set(finalTransform, path, (transform === null || transform === void 0 ? void 0 : transform(sourceValue)) || sourceValue);
|
|
79
75
|
}
|
|
80
76
|
});
|
|
81
77
|
return finalTransform;
|
|
82
78
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var statePathString = 'residentialAddress.state';
|
|
79
|
+
const postcodePathString = 'residentialAddress.postcode';
|
|
80
|
+
const statePathString = 'residentialAddress.state';
|
|
86
81
|
/**
|
|
87
82
|
* Converts an address object from an event model to a LIXI address and corresponding LIXI contact address object.
|
|
88
83
|
*
|
|
89
84
|
* @param eventAddress
|
|
90
85
|
* @param addressId
|
|
91
86
|
*/
|
|
92
|
-
function rebuildAddress(eventAddress, addressId) {
|
|
87
|
+
export function rebuildAddress(eventAddress, addressId) {
|
|
93
88
|
if (isMissingCountry(eventAddress)) {
|
|
94
89
|
setCountry(eventAddress);
|
|
95
90
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
if (get(eventAddress, 'residentialAddress.country') !== Countries.Australia) {
|
|
92
|
+
lixiAddressMapping[postcodePathString] = { path: '@OverseasPostCode' };
|
|
93
|
+
lixiAddressMapping[statePathString] = { path: '@OverseasState' };
|
|
99
94
|
}
|
|
100
95
|
else {
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
lixiAddressMapping[postcodePathString] = { path: '@AustralianPostCode' };
|
|
97
|
+
lixiAddressMapping[statePathString] = { path: '@AustralianState' };
|
|
103
98
|
}
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
const lixiAddress = mapTransform(eventAddress, lixiAddressMapping);
|
|
100
|
+
const lixiContactAddress = mapTransform(eventAddress, lixiContactAddressMapping);
|
|
106
101
|
lixiAddress['@UniqueID'] = addressId;
|
|
107
102
|
lixiContactAddress['@x_ResidentialAddress'] = addressId;
|
|
108
|
-
return { lixiAddress
|
|
103
|
+
return { lixiAddress, lixiContactAddress };
|
|
109
104
|
}
|
|
110
|
-
exports.rebuildAddress = rebuildAddress;
|
|
111
105
|
/**
|
|
112
|
-
*
|
|
106
|
+
* Converts a previous address object from an event model to a LIXI address and corresponding LIXI current address object.
|
|
107
|
+
*
|
|
113
108
|
* @param eventPreviousAddresses
|
|
114
109
|
* @param addressId
|
|
115
110
|
*/
|
|
116
|
-
function rebuildPreviousAddress(eventPreviousAddresses, addressId) {
|
|
117
|
-
if (eventPreviousAddresses === void 0) { eventPreviousAddresses = []; }
|
|
111
|
+
export function rebuildPreviousAddress(eventPreviousAddresses = [], addressId) {
|
|
118
112
|
if (eventPreviousAddresses.length === 0)
|
|
119
113
|
return null;
|
|
120
|
-
|
|
114
|
+
const previousAddress = eventPreviousAddresses.sort((lhs, rhs) => lhs.endDate.localeCompare(rhs.endDate)).pop();
|
|
121
115
|
return rebuildAddress(previousAddress, addressId);
|
|
122
116
|
}
|
|
123
|
-
exports.rebuildPreviousAddress = rebuildPreviousAddress;
|
|
124
117
|
/**
|
|
125
118
|
* Checks if an event is missing country.
|
|
119
|
+
*
|
|
126
120
|
* @param addressEvent
|
|
127
121
|
*/
|
|
128
|
-
function isMissingCountry(addressEvent) {
|
|
122
|
+
export function isMissingCountry(addressEvent) {
|
|
129
123
|
if (addressEvent.residentialAddress && addressEvent.residentialAddress.formatted) {
|
|
130
|
-
return !
|
|
124
|
+
return !get(addressEvent, 'residentialAddress.country');
|
|
131
125
|
}
|
|
132
126
|
return false;
|
|
133
127
|
}
|
|
134
|
-
exports.isMissingCountry = isMissingCountry;
|
|
135
128
|
/**
|
|
136
129
|
* Sets the country from the last item on the formatted address.
|
|
137
130
|
*
|
|
138
131
|
* @param address
|
|
139
132
|
*/
|
|
140
|
-
function setCountry(address) {
|
|
141
|
-
|
|
133
|
+
export function setCountry(address) {
|
|
134
|
+
const formatted = get(address, 'residentialAddress.formatted');
|
|
142
135
|
if (formatted && !address.residentialAddress.country) {
|
|
143
136
|
address.residentialAddress.country = extractCountryFromFormatted(formatted);
|
|
144
137
|
}
|
|
145
138
|
return address;
|
|
146
139
|
}
|
|
147
|
-
exports.setCountry = setCountry;
|
|
148
140
|
/**
|
|
149
141
|
* @description Extract a country from a formatted address.
|
|
150
142
|
* @param {string} formatted - A formatted Address.
|
|
151
143
|
* @returns {Countries} The country extracted from the Address.
|
|
152
144
|
*/
|
|
153
|
-
function extractCountryFromFormatted(formatted) {
|
|
145
|
+
export function extractCountryFromFormatted(formatted = '') {
|
|
154
146
|
var _a;
|
|
155
|
-
if (formatted === void 0) { formatted = ''; }
|
|
156
147
|
return (_a = formatted === null || formatted === void 0 ? void 0 : formatted.split(',').pop()) === null || _a === void 0 ? void 0 : _a.trim();
|
|
157
148
|
}
|
|
158
|
-
exports.extractCountryFromFormatted = extractCountryFromFormatted;
|
|
159
149
|
/**
|
|
160
150
|
* @description If the address has an overseas country or state, it returns true, defaults to false if no country and state found.
|
|
161
151
|
* @param {Address} address - Asset Address
|
|
162
152
|
* @returns {boolean} - Returns true if overseas address.
|
|
163
153
|
*/
|
|
164
|
-
function isOverseasAddress(
|
|
165
|
-
var _b = _a === void 0 ? {} : _a, country = _b.country, formatted = _b.formatted, state = _b.state;
|
|
154
|
+
export function isOverseasAddress({ country, formatted, state } = {}) {
|
|
166
155
|
if (country) {
|
|
167
|
-
return country !==
|
|
156
|
+
return country !== Countries.Australia;
|
|
168
157
|
}
|
|
169
158
|
if (formatted) {
|
|
170
|
-
|
|
171
|
-
return lastPast !==
|
|
159
|
+
const lastPast = extractCountryFromFormatted(formatted);
|
|
160
|
+
return lastPast !== Countries.Australia;
|
|
172
161
|
}
|
|
173
162
|
if (state) {
|
|
174
|
-
return !
|
|
163
|
+
return !australianStates.includes(state);
|
|
175
164
|
}
|
|
176
165
|
return false;
|
|
177
166
|
}
|
|
178
|
-
exports.isOverseasAddress = isOverseasAddress;
|
package/lib/utils/clean-up.d.ts
CHANGED
package/lib/utils/clean-up.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
exports.cleanUp = void 0;
|
|
4
1
|
/* istanbul ignore file */
|
|
5
|
-
|
|
2
|
+
import cleanDeep from 'clean-deep';
|
|
6
3
|
/**
|
|
7
4
|
* Recursively removes nulls from nested objects and arrays
|
|
8
5
|
*
|
|
9
6
|
* @param payload any
|
|
10
|
-
* @
|
|
7
|
+
* @returns result of sanitised object.
|
|
11
8
|
*/
|
|
12
|
-
function cleanUp(payload) {
|
|
9
|
+
export function cleanUp(payload) {
|
|
13
10
|
// cleanDeep configurations.
|
|
14
|
-
|
|
11
|
+
const params = {
|
|
15
12
|
cleanValues: [],
|
|
16
13
|
emptyArrays: true,
|
|
17
14
|
emptyObjects: true,
|
|
18
15
|
emptyStrings: false,
|
|
19
16
|
nullValues: true,
|
|
20
|
-
undefinedValues: true
|
|
17
|
+
undefinedValues: true,
|
|
21
18
|
};
|
|
22
|
-
return (
|
|
19
|
+
return cleanDeep(payload, params);
|
|
23
20
|
}
|
|
24
|
-
exports.cleanUp = cleanUp;
|
package/lib/utils/formatYesNo.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
exports.formatYesNo = void 0;
|
|
4
|
-
var lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
|
|
1
|
+
import { YesNoList } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
5
2
|
/**
|
|
6
3
|
* Formats a value as Yes or No
|
|
7
4
|
*
|
|
8
5
|
* @param isTruthy Some value to be formatted as Yes/No
|
|
9
|
-
*
|
|
10
6
|
* @returns Yes/No
|
|
11
7
|
*/
|
|
12
|
-
|
|
13
|
-
exports.formatYesNo = formatYesNo;
|
|
8
|
+
export const formatYesNo = (isTruthy) => (isTruthy ? YesNoList.Yes : YesNoList.No);
|
|
@@ -4,15 +4,16 @@ export declare const StreetNumberMaxLength = 16;
|
|
|
4
4
|
export declare const StreetTypeArray: StreetTypeList[];
|
|
5
5
|
/**
|
|
6
6
|
* Generates an address for an asset.
|
|
7
|
+
*
|
|
7
8
|
* @param {Address} address - An address object.
|
|
8
9
|
* @param {string} id - Id of asset object.
|
|
9
|
-
* @
|
|
10
|
+
* @returns {Partial<AddressType>} A transformed address object.
|
|
10
11
|
*/
|
|
11
12
|
export declare function generateAddress(address: Address, id: string): Partial<AddressType>;
|
|
12
13
|
/**
|
|
13
14
|
* Generates an address standard.
|
|
14
15
|
*
|
|
15
16
|
* @param addressStandard An address standard object.
|
|
16
|
-
* @
|
|
17
|
+
* @returns A transformed standard object.
|
|
17
18
|
*/
|
|
18
19
|
export declare function generateStandard(addressStandard: AddressStandard): Standard;
|