@lendi/integrations-transform 1.6.3 → 1.6.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/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/transform-events/transform-asset.d.ts +1 -1
- package/lib/transform-events/transform-asset.js +8 -5
- package/lib/transform-events/transform-required-document.d.ts +67 -0
- package/lib/transform-events/transform-required-document.js +148 -0
- package/lib/types/enum-mappings/verification.d.ts +1 -5
- package/lib/update-application/merge-application.d.ts +8 -2
- package/lib/update-application/merge-application.js +15 -9
- package/lib/update-application/remove-ids-not-required.d.ts +21 -0
- package/lib/update-application/remove-ids-not-required.js +54 -0
- package/package.json +2 -2
- package/lib/transform-events/generate-required-document.d.ts +0 -44
- package/lib/transform-events/generate-required-document.js +0 -106
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export * from './transform-events/transform-income';
|
|
|
5
5
|
export * from './transform-events/transform-asset';
|
|
6
6
|
export * from './transform-events/transform-expenses';
|
|
7
7
|
export * from './transform-events/transform-liability';
|
|
8
|
-
export * from './transform-events/
|
|
8
|
+
export * from './transform-events/transform-required-document';
|
|
9
9
|
export * from './transform-events/transform-funding-position';
|
|
10
10
|
export * from './update-application/merge-application';
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,6 @@ __exportStar(require("./transform-events/transform-income"), exports);
|
|
|
22
22
|
__exportStar(require("./transform-events/transform-asset"), exports);
|
|
23
23
|
__exportStar(require("./transform-events/transform-expenses"), exports);
|
|
24
24
|
__exportStar(require("./transform-events/transform-liability"), exports);
|
|
25
|
-
__exportStar(require("./transform-events/
|
|
25
|
+
__exportStar(require("./transform-events/transform-required-document"), exports);
|
|
26
26
|
__exportStar(require("./transform-events/transform-funding-position"), exports);
|
|
27
27
|
__exportStar(require("./update-application/merge-application"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LivingExpense, PropertyExpense as LIXIPropertyExpense
|
|
1
|
+
import { LivingExpense, OccupancyList, PropertyExpense as LIXIPropertyExpense } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
2
2
|
import { PropertyType as LixiPropertyType, Residential } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
|
|
3
3
|
import { Asset, Payload, PercentOwned, PropertyExpense, PropertyType } from '../types/events/public-asset';
|
|
4
4
|
import { PartialApplication } from '../types/partial-application';
|
|
@@ -4,10 +4,13 @@ exports.normalizeAmounts = exports.determineOccupancy = exports.generateProperty
|
|
|
4
4
|
const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
|
|
5
5
|
const application_paths_1 = require("@lendi/integrations-credit-protocol/utils/application-paths");
|
|
6
6
|
const lixi_internal_request_2 = require("@lendi/integrations-protocol/lib/types/lixi-internal-request");
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
7
|
const lodash_1 = require("lodash");
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const __1 = require("..");
|
|
9
10
|
const logger_1 = require("../logger");
|
|
10
11
|
const enum_mappings_1 = require("../types/enum-mappings");
|
|
12
|
+
const builder_type_1 = require("../types/enum-mappings/builder-type");
|
|
13
|
+
const construction_type_1 = require("../types/enum-mappings/construction-type");
|
|
11
14
|
const public_asset_1 = require("../types/events/public-asset");
|
|
12
15
|
const public_expense_1 = require("../types/events/public-expense");
|
|
13
16
|
const get_financial_institution_1 = require("../utils/get-financial-institution");
|
|
@@ -15,9 +18,6 @@ const is_asset_type_1 = require("../utils/is-asset-type");
|
|
|
15
18
|
const round_decimal_1 = require("../utils/round-decimal");
|
|
16
19
|
const transform_asset_address_1 = require("./transform-asset-address");
|
|
17
20
|
const transform_percent_owned_1 = require("./transform-percent-owned");
|
|
18
|
-
const builder_type_1 = require("../types/enum-mappings/builder-type");
|
|
19
|
-
const construction_type_1 = require("../types/enum-mappings/construction-type");
|
|
20
|
-
const __1 = require("..");
|
|
21
21
|
exports.propertyTypeNameList = Object.values(lixi_internal_request_2.Custom2PropertyTypeNameList);
|
|
22
22
|
exports.residentialTypeList = Object.values(lixi_internal_request_1.ResidentialTypeList);
|
|
23
23
|
// will add this path to protocol
|
|
@@ -80,9 +80,11 @@ function transformAsset({ asset, applicationId, id }) {
|
|
|
80
80
|
if (assetMapping[key]) {
|
|
81
81
|
switch (key) {
|
|
82
82
|
case 'contractDetails':
|
|
83
|
-
const { contractDate } = value;
|
|
83
|
+
const { contractDate, estimatedSettlementDate } = value;
|
|
84
84
|
if (contractDate)
|
|
85
85
|
(0, lodash_1.set)(partialApplication, assetMapping.contractDate, contractDate);
|
|
86
|
+
if (estimatedSettlementDate)
|
|
87
|
+
(0, lodash_1.set)(partialApplication, assetMapping.estimatedSettlementDate, estimatedSettlementDate);
|
|
86
88
|
break;
|
|
87
89
|
case 'primaryPurpose':
|
|
88
90
|
(0, lodash_1.set)(partialApplication, assetMapping[key], enum_mappings_1.primaryPurposeMapping[value]);
|
|
@@ -224,6 +226,7 @@ function getAssetMapping(asset) {
|
|
|
224
226
|
address: application_paths_1.paths.Address,
|
|
225
227
|
contractDetails: 'contractDetails',
|
|
226
228
|
contractDate: `${application_paths_1.paths.RealEstateAsset}.ContractDetails.@ContractDate`,
|
|
229
|
+
estimatedSettlementDate: `${application_paths_1.paths.RealEstateAsset}.ContractDetails.@EstimatedSettlementDate`,
|
|
227
230
|
estimatedValue,
|
|
228
231
|
percentOwned,
|
|
229
232
|
primaryPurpose: `${application_paths_1.paths.RealEstateAsset}.@PrimaryPurpose`,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { PersonApplicantPrivacy, ProofOfIdentity } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
2
|
+
import { EConsent, Identification, Payload as RequiredDocumentPayload, Status } from '../types/events/public-required-document';
|
|
3
|
+
import { PartialApplication } from '../types/partial-application';
|
|
4
|
+
interface TransformRequiredDocumentOptions {
|
|
5
|
+
readonly secondIDEnabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Gets the applicant gender from the identification data
|
|
9
|
+
*
|
|
10
|
+
* @param {Identification} identification Identification data
|
|
11
|
+
*
|
|
12
|
+
* @returns The gender of the applicant
|
|
13
|
+
*/
|
|
14
|
+
export declare const getApplicantGenderFromIdentification: (identification: Identification) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Gets full name on document from the identification data
|
|
17
|
+
*
|
|
18
|
+
* @param {Identification} identification Identification data
|
|
19
|
+
*
|
|
20
|
+
* @returns {string} The full name on document
|
|
21
|
+
*/
|
|
22
|
+
export declare const getNameOnDocument: (identification: Identification) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Transforms issued location data of an ID document
|
|
25
|
+
*
|
|
26
|
+
* @param {Identification} identification Identification data
|
|
27
|
+
* @param {boolean} secondIDEnabled Whether or not second Id functionality is enabled
|
|
28
|
+
*
|
|
29
|
+
* @returns {Partial<ProofOfIdentity>} Partial proof of identity object
|
|
30
|
+
*/
|
|
31
|
+
export declare const transformIDIssuedLocation: (identification: Identification, secondIDEnabled?: boolean) => Partial<ProofOfIdentity>;
|
|
32
|
+
/**
|
|
33
|
+
* Transforms the verification status data of the ID document
|
|
34
|
+
*
|
|
35
|
+
* @param {Status} status Verification status of the ID document
|
|
36
|
+
* @param {boolean} secondIDEnabled Whether or not secondID mapping is enabled
|
|
37
|
+
*
|
|
38
|
+
* @returns {Partial<ProofOfIdentity>} Partial proof of identity
|
|
39
|
+
*/
|
|
40
|
+
export declare const transformVerificationStatus: (status: Status | undefined, secondIDEnabled?: boolean) => Partial<ProofOfIdentity>;
|
|
41
|
+
/**
|
|
42
|
+
* Generates a partial proof of identity object
|
|
43
|
+
*
|
|
44
|
+
* @param {RequiredDocumentPayload} requiredDocumentEventPayload RequiredDocumentCreated/RequiredDocumentUpdated event payload
|
|
45
|
+
* @param {TransformRequiredDocumentOptions} options - Options from generating partial proof of identity
|
|
46
|
+
*
|
|
47
|
+
* @returns {Partial<ProofOfIdentity>} Partial proof of identity document object
|
|
48
|
+
*/
|
|
49
|
+
export declare const generateProofOfIdentity: (requiredDocumentEventPayload: RequiredDocumentPayload, options?: TransformRequiredDocumentOptions) => Partial<ProofOfIdentity>;
|
|
50
|
+
/**
|
|
51
|
+
* Generates an applicants disclosure details mapping for the partial application
|
|
52
|
+
*
|
|
53
|
+
* @param {EConsent} eConsent E-Consent detials from the RequiredDocumentCreated/RequqiredDocumentUpdated event payload
|
|
54
|
+
*
|
|
55
|
+
* @returns {PersonApplicantPrivacy} Applicant disclosure details for partial application
|
|
56
|
+
*/
|
|
57
|
+
export declare const generatePersonApplicantPrivacy: (eConsent: EConsent) => PersonApplicantPrivacy;
|
|
58
|
+
/**
|
|
59
|
+
* Transforms a RequiredDocumentCreated/RequiredDocumentUpdated event payload into a partial application
|
|
60
|
+
*
|
|
61
|
+
* @param {RequiredDocumentPayload} requiredDocEventPayload A RequiredDocumentCreated/RequiredDocumentUpdated event payload
|
|
62
|
+
* @param {TransformRequiredDocumentOptions} options Required document event transformation options
|
|
63
|
+
*
|
|
64
|
+
* @returns {PartialApplication} A partial application
|
|
65
|
+
*/
|
|
66
|
+
export declare const transformRequiredDocument: (requiredDocEventPayload: RequiredDocumentPayload, options?: TransformRequiredDocumentOptions) => PartialApplication;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformRequiredDocument = exports.generatePersonApplicantPrivacy = exports.generateProofOfIdentity = exports.transformVerificationStatus = exports.transformIDIssuedLocation = exports.getNameOnDocument = exports.getApplicantGenderFromIdentification = void 0;
|
|
4
|
+
const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
|
|
5
|
+
const application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const enum_mappings_1 = require("../types/enum-mappings");
|
|
8
|
+
const enum_mappings_2 = require("../types/enum-mappings");
|
|
9
|
+
const enum_mappings_3 = require("../types/enum-mappings");
|
|
10
|
+
const verification_1 = require("../types/enum-mappings/verification");
|
|
11
|
+
const public_required_document_1 = require("../types/events/public-required-document");
|
|
12
|
+
const formatYesNo_1 = require("../utils/formatYesNo");
|
|
13
|
+
const iso_date_1 = require("../utils/iso-date");
|
|
14
|
+
/**
|
|
15
|
+
* Gets the applicant gender from the identification data
|
|
16
|
+
*
|
|
17
|
+
* @param {Identification} identification Identification data
|
|
18
|
+
*
|
|
19
|
+
* @returns The gender of the applicant
|
|
20
|
+
*/
|
|
21
|
+
const getApplicantGenderFromIdentification = (identification) => {
|
|
22
|
+
const { gender, idTitle } = identification;
|
|
23
|
+
return gender ? (0, lodash_1.capitalize)(gender) : enum_mappings_3.titleGenderMapping[idTitle || public_required_document_1.IDTitle.Unknown];
|
|
24
|
+
};
|
|
25
|
+
exports.getApplicantGenderFromIdentification = getApplicantGenderFromIdentification;
|
|
26
|
+
/**
|
|
27
|
+
* Gets full name on document from the identification data
|
|
28
|
+
*
|
|
29
|
+
* @param {Identification} identification Identification data
|
|
30
|
+
*
|
|
31
|
+
* @returns {string} The full name on document
|
|
32
|
+
*/
|
|
33
|
+
const getNameOnDocument = (identification) => {
|
|
34
|
+
const { idFirstName, idMiddleName, idLastName } = identification;
|
|
35
|
+
return [idFirstName, idMiddleName, idLastName].reduce((fullName, nameComponent) => {
|
|
36
|
+
let newFullName = fullName;
|
|
37
|
+
const nameSubstring = nameComponent === null || nameComponent === void 0 ? void 0 : nameComponent.trim();
|
|
38
|
+
if (nameSubstring) {
|
|
39
|
+
newFullName += `${fullName ? ' ' : ''}${nameSubstring}`;
|
|
40
|
+
}
|
|
41
|
+
return newFullName;
|
|
42
|
+
}, '');
|
|
43
|
+
};
|
|
44
|
+
exports.getNameOnDocument = getNameOnDocument;
|
|
45
|
+
/**
|
|
46
|
+
* Transforms issued location data of an ID document
|
|
47
|
+
*
|
|
48
|
+
* @param {Identification} identification Identification data
|
|
49
|
+
* @param {boolean} secondIDEnabled Whether or not second Id functionality is enabled
|
|
50
|
+
*
|
|
51
|
+
* @returns {Partial<ProofOfIdentity>} Partial proof of identity object
|
|
52
|
+
*/
|
|
53
|
+
const transformIDIssuedLocation = (identification, secondIDEnabled = false) => {
|
|
54
|
+
const { australianState, idType, issuingCountry = public_required_document_1.IssuingCountry.Australia } = identification;
|
|
55
|
+
let transformedIssuedLocation = {};
|
|
56
|
+
if (idType === public_required_document_1.IDType.Passport && issuingCountry !== public_required_document_1.IssuingCountry.Australia) {
|
|
57
|
+
const foreignCountryOfIssue = enum_mappings_1.countryCodeMapping[issuingCountry];
|
|
58
|
+
transformedIssuedLocation = Object.assign({ '@DocumentType': lixi_internal_request_1.DocumentTypeList.InternationalPassport, '@CountryOfIssue': foreignCountryOfIssue, '@PlaceOfIssue': foreignCountryOfIssue }, (secondIDEnabled && { '@ResidentialAddressVerified': lixi_internal_request_1.YesNoList.No }));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
transformedIssuedLocation = {
|
|
62
|
+
'@CountryOfIssue': lixi_internal_request_1.CountryCodeList.Au,
|
|
63
|
+
'@PlaceOfIssue': australianState || lixi_internal_request_1.CountryCodeList.Au,
|
|
64
|
+
'@DocumentType': enum_mappings_2.proofOfIdentityMapping[idType],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return transformedIssuedLocation;
|
|
68
|
+
};
|
|
69
|
+
exports.transformIDIssuedLocation = transformIDIssuedLocation;
|
|
70
|
+
/**
|
|
71
|
+
* Transforms the verification status data of the ID document
|
|
72
|
+
*
|
|
73
|
+
* @param {Status} status Verification status of the ID document
|
|
74
|
+
* @param {boolean} secondIDEnabled Whether or not secondID mapping is enabled
|
|
75
|
+
*
|
|
76
|
+
* @returns {Partial<ProofOfIdentity>} Partial proof of identity
|
|
77
|
+
*/
|
|
78
|
+
const transformVerificationStatus = (status, secondIDEnabled = false) => {
|
|
79
|
+
let transformedVerification = {};
|
|
80
|
+
if (status) {
|
|
81
|
+
const verificationStatus = verification_1.verificationMapping[status];
|
|
82
|
+
transformedVerification = Object.assign({ '@PhotographVerified': verificationStatus }, (secondIDEnabled && {
|
|
83
|
+
'@DOBVerified': verificationStatus,
|
|
84
|
+
'@NameVerified': verificationStatus,
|
|
85
|
+
'@SignatureVerified': verificationStatus,
|
|
86
|
+
'@ResidentialAddressVerified': verificationStatus,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
return transformedVerification;
|
|
90
|
+
};
|
|
91
|
+
exports.transformVerificationStatus = transformVerificationStatus;
|
|
92
|
+
/**
|
|
93
|
+
* Generates a partial proof of identity object
|
|
94
|
+
*
|
|
95
|
+
* @param {RequiredDocumentPayload} requiredDocumentEventPayload RequiredDocumentCreated/RequiredDocumentUpdated event payload
|
|
96
|
+
* @param {TransformRequiredDocumentOptions} options - Options from generating partial proof of identity
|
|
97
|
+
*
|
|
98
|
+
* @returns {Partial<ProofOfIdentity>} Partial proof of identity document object
|
|
99
|
+
*/
|
|
100
|
+
const generateProofOfIdentity = (requiredDocumentEventPayload, options = {}) => {
|
|
101
|
+
const { secondIDEnabled = false } = options;
|
|
102
|
+
const { id, status, expiryDate, identification } = requiredDocumentEventPayload;
|
|
103
|
+
const nameOnDocument = (0, exports.getNameOnDocument)(identification);
|
|
104
|
+
const { idNumber } = identification;
|
|
105
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ '@UniqueID': id }, (expiryDate && { '@ExpiryDate': (0, iso_date_1.isoDate)(expiryDate) })), (0, exports.transformVerificationStatus)(status, secondIDEnabled)), (nameOnDocument && { '@NameOnDocument': nameOnDocument })), (idNumber && { '@DocumentNumber': idNumber })), (0, exports.transformIDIssuedLocation)(identification, secondIDEnabled)), (secondIDEnabled && {
|
|
106
|
+
'@DocumentCategory': lixi_internal_request_1.DocumentCategoryList.Photographic,
|
|
107
|
+
'@Original': lixi_internal_request_1.YesNoList.Yes,
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
exports.generateProofOfIdentity = generateProofOfIdentity;
|
|
111
|
+
/**
|
|
112
|
+
* Generates an applicants disclosure details mapping for the partial application
|
|
113
|
+
*
|
|
114
|
+
* @param {EConsent} eConsent E-Consent detials from the RequiredDocumentCreated/RequqiredDocumentUpdated event payload
|
|
115
|
+
*
|
|
116
|
+
* @returns {PersonApplicantPrivacy} Applicant disclosure details for partial application
|
|
117
|
+
*/
|
|
118
|
+
const generatePersonApplicantPrivacy = (eConsent) => {
|
|
119
|
+
const { hasConsented, consentedAt = new Date() } = eConsent;
|
|
120
|
+
return {
|
|
121
|
+
'@CreditAuthoritySigned': (0, formatYesNo_1.formatYesNo)(hasConsented),
|
|
122
|
+
'@DateSigned': (0, iso_date_1.isoDate)(consentedAt),
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
exports.generatePersonApplicantPrivacy = generatePersonApplicantPrivacy;
|
|
126
|
+
/**
|
|
127
|
+
* Transforms a RequiredDocumentCreated/RequiredDocumentUpdated event payload into a partial application
|
|
128
|
+
*
|
|
129
|
+
* @param {RequiredDocumentPayload} requiredDocEventPayload A RequiredDocumentCreated/RequiredDocumentUpdated event payload
|
|
130
|
+
* @param {TransformRequiredDocumentOptions} options Required document event transformation options
|
|
131
|
+
*
|
|
132
|
+
* @returns {PartialApplication} A partial application
|
|
133
|
+
*/
|
|
134
|
+
const transformRequiredDocument = (requiredDocEventPayload, options) => {
|
|
135
|
+
const partialApplication = {};
|
|
136
|
+
const { applicantId, applicationId, identification, eConsent } = requiredDocEventPayload;
|
|
137
|
+
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@UniqueID`, applicantId);
|
|
138
|
+
(0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, applicationId);
|
|
139
|
+
if (identification) {
|
|
140
|
+
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@Gender`, (0, exports.getApplicantGenderFromIdentification)(identification));
|
|
141
|
+
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.ProofOfIdentity}`, (0, exports.generateProofOfIdentity)(requiredDocEventPayload, options));
|
|
142
|
+
}
|
|
143
|
+
if (eConsent) {
|
|
144
|
+
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Privacy}`, (0, exports.generatePersonApplicantPrivacy)(eConsent));
|
|
145
|
+
}
|
|
146
|
+
return partialApplication;
|
|
147
|
+
};
|
|
148
|
+
exports.transformRequiredDocument = transformRequiredDocument;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { Status } from '../events/public-required-document';
|
|
2
2
|
import { YesNoList } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
3
|
-
declare
|
|
4
|
-
[key in Status]: YesNoList;
|
|
5
|
-
};
|
|
6
|
-
export declare const verificationMapping: VerificationMapping;
|
|
7
|
-
export {};
|
|
3
|
+
export declare const verificationMapping: Record<Status, YesNoList>;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
interface DeepMergeOptions {
|
|
2
|
+
readonly secondIDEnabled?: boolean;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Deep merges the application and custom handles specific arrays
|
|
3
6
|
*
|
|
4
|
-
* @param newApplication new application coming from events.
|
|
5
7
|
* @param existingApplication a saved dynamo application.
|
|
8
|
+
* @param newApplication new application coming from events.
|
|
9
|
+
* @param {DeepMergeOptions} options Deep merge options
|
|
10
|
+
*
|
|
6
11
|
* @returns merged application.
|
|
7
12
|
*/
|
|
8
|
-
export declare function deepMergeApplication(existingApplication: object | undefined, newApplication: object): any;
|
|
13
|
+
export declare function deepMergeApplication(existingApplication: object | undefined, newApplication: object, options?: DeepMergeOptions): any;
|
|
14
|
+
export {};
|
|
@@ -6,11 +6,17 @@ const cleanDeep = require('clean-deep');
|
|
|
6
6
|
/**
|
|
7
7
|
* Deep merges the application and custom handles specific arrays
|
|
8
8
|
*
|
|
9
|
-
* @param newApplication new application coming from events.
|
|
10
9
|
* @param existingApplication a saved dynamo application.
|
|
10
|
+
* @param newApplication new application coming from events.
|
|
11
|
+
* @param {DeepMergeOptions} options Deep merge options
|
|
12
|
+
*
|
|
11
13
|
* @returns merged application.
|
|
12
14
|
*/
|
|
13
|
-
function deepMergeApplication(existingApplication, newApplication) {
|
|
15
|
+
function deepMergeApplication(existingApplication, newApplication, options = {}) {
|
|
16
|
+
if (!existingApplication) {
|
|
17
|
+
return newApplication;
|
|
18
|
+
}
|
|
19
|
+
const { secondIDEnabled = false } = options;
|
|
14
20
|
// Array fields with @UniqueIDs
|
|
15
21
|
const listsWithUniqueIds = [
|
|
16
22
|
'Attachment',
|
|
@@ -28,6 +34,9 @@ function deepMergeApplication(existingApplication, newApplication) {
|
|
|
28
34
|
'RelatedCompany',
|
|
29
35
|
'RelatedPerson',
|
|
30
36
|
];
|
|
37
|
+
if (secondIDEnabled) {
|
|
38
|
+
listsWithUniqueIds.push('ProofOfIdentity');
|
|
39
|
+
}
|
|
31
40
|
// Array fields with @x_Party
|
|
32
41
|
const listsWithXParty = ['Report'];
|
|
33
42
|
// Array fields with @x_Owner
|
|
@@ -40,19 +49,16 @@ function deepMergeApplication(existingApplication, newApplication) {
|
|
|
40
49
|
const listsWithXGuarantor = ['Guarantor'];
|
|
41
50
|
// Curried function which takes a uniqueKey and returns a function which will either replace
|
|
42
51
|
// or merge the item in the array based on the uniqueKey
|
|
43
|
-
if (!existingApplication) {
|
|
44
|
-
return newApplication;
|
|
45
|
-
}
|
|
46
52
|
const mergeItems = (uniqueKey) => {
|
|
47
53
|
return (existingItem, newItem) => {
|
|
48
54
|
// if not array continue with merge
|
|
49
55
|
if (!Array.isArray(newItem)) {
|
|
50
|
-
return merge(existingItem, newItem,
|
|
56
|
+
return merge(existingItem, newItem, mergeOptions);
|
|
51
57
|
}
|
|
52
|
-
return findArrayItemAndMerge(existingItem, newItem, uniqueKey,
|
|
58
|
+
return findArrayItemAndMerge(existingItem, newItem, uniqueKey, mergeOptions);
|
|
53
59
|
};
|
|
54
60
|
};
|
|
55
|
-
const
|
|
61
|
+
const mergeOptions = {
|
|
56
62
|
customMerge: (key) => {
|
|
57
63
|
if (listsWithUniqueIds.find((item) => item === key)) {
|
|
58
64
|
return mergeItems('@UniqueID');
|
|
@@ -75,7 +81,7 @@ function deepMergeApplication(existingApplication, newApplication) {
|
|
|
75
81
|
return mergeItems(key);
|
|
76
82
|
},
|
|
77
83
|
};
|
|
78
|
-
const mergedApplication = merge(existingApplication, newApplication,
|
|
84
|
+
const mergedApplication = merge(existingApplication, newApplication, mergeOptions);
|
|
79
85
|
// Default configurations of cleanDeep for reference.
|
|
80
86
|
const params = {
|
|
81
87
|
cleanValues: [],
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InternalRequest, PersonApplicant } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
2
|
+
import { Payload as RequiredDocEventPayload } from '../types/events/public-required-document';
|
|
3
|
+
import { RecursivePartial } from '../types/recursive-partial';
|
|
4
|
+
/**
|
|
5
|
+
* Remove proof of identity document from a person applicant
|
|
6
|
+
*
|
|
7
|
+
* @param {PersonApplicant} personApplicant Person applicant to remove the id document from
|
|
8
|
+
* @param {string} id Proof of identity document
|
|
9
|
+
*
|
|
10
|
+
* @returns {PersonApplicant} Updated person applicant
|
|
11
|
+
*/
|
|
12
|
+
export declare const removeIDDocumentFromApplicant: (personApplicant: PersonApplicant, id: string) => PersonApplicant;
|
|
13
|
+
/**
|
|
14
|
+
* Removes ProofOfIdentity ID document that is in status Not Required
|
|
15
|
+
*
|
|
16
|
+
* @param {RecursivePartial<InternalRequest>} application - Partial LIXI CAL application
|
|
17
|
+
* @param {RequiredDocEventPayload} eventPayload - Required Document event payload
|
|
18
|
+
*
|
|
19
|
+
* @returns {RecursivePartial<InternalRequest>} Updated application
|
|
20
|
+
*/
|
|
21
|
+
export declare const removeIdsNotRequired: (application: RecursivePartial<InternalRequest>, eventPayload: RequiredDocEventPayload) => RecursivePartial<InternalRequest>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.removeIdsNotRequired = exports.removeIDDocumentFromApplicant = void 0;
|
|
15
|
+
const application_paths_1 = require("@lendi/integrations-credit-protocol/utils/application-paths");
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
17
|
+
const public_required_document_1 = require("../types/events/public-required-document");
|
|
18
|
+
/**
|
|
19
|
+
* Remove proof of identity document from a person applicant
|
|
20
|
+
*
|
|
21
|
+
* @param {PersonApplicant} personApplicant Person applicant to remove the id document from
|
|
22
|
+
* @param {string} id Proof of identity document
|
|
23
|
+
*
|
|
24
|
+
* @returns {PersonApplicant} Updated person applicant
|
|
25
|
+
*/
|
|
26
|
+
const removeIDDocumentFromApplicant = (personApplicant, id) => {
|
|
27
|
+
const { ProofOfIdentity = [] } = personApplicant, rest = __rest(personApplicant, ["ProofOfIdentity"]);
|
|
28
|
+
const updatedProofOfIdentity = ProofOfIdentity.filter((proofOfId) => proofOfId['@UniqueID'] !== id);
|
|
29
|
+
// If the updateProofOfIdentity is an empty array then we remove the ProofOfIdentity attribute from the person applicant
|
|
30
|
+
return Object.assign(Object.assign({}, rest), (updatedProofOfIdentity.length && { ProofOfIdentity: updatedProofOfIdentity }));
|
|
31
|
+
};
|
|
32
|
+
exports.removeIDDocumentFromApplicant = removeIDDocumentFromApplicant;
|
|
33
|
+
/**
|
|
34
|
+
* Removes ProofOfIdentity ID document that is in status Not Required
|
|
35
|
+
*
|
|
36
|
+
* @param {RecursivePartial<InternalRequest>} application - Partial LIXI CAL application
|
|
37
|
+
* @param {RequiredDocEventPayload} eventPayload - Required Document event payload
|
|
38
|
+
*
|
|
39
|
+
* @returns {RecursivePartial<InternalRequest>} Updated application
|
|
40
|
+
*/
|
|
41
|
+
const removeIdsNotRequired = (application, eventPayload) => {
|
|
42
|
+
const { status: verificationStatus, id, applicantId } = eventPayload;
|
|
43
|
+
const personApplicants = (0, lodash_1.get)(application, application_paths_1.paths.PersonApplicants, []);
|
|
44
|
+
const updatedApplication = application;
|
|
45
|
+
if (verificationStatus === public_required_document_1.Status.NotRequired && personApplicants.length) {
|
|
46
|
+
const personApplicantIndex = personApplicants.findIndex((personApplicant) => personApplicant['@UniqueID'] === applicantId);
|
|
47
|
+
if (personApplicantIndex !== -1) {
|
|
48
|
+
const updatedPersonApplicant = (0, exports.removeIDDocumentFromApplicant)(personApplicants[personApplicantIndex], id);
|
|
49
|
+
(0, lodash_1.set)(updatedApplication, `${application_paths_1.paths.PersonApplicants}.[${personApplicantIndex}]`, updatedPersonApplicant);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return updatedApplication;
|
|
53
|
+
};
|
|
54
|
+
exports.removeIdsNotRequired = removeIdsNotRequired;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lendi/integrations-transform",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"description": "Library for kafka event data transforming",
|
|
5
5
|
"author": "Integrations <integrations@lendi.com.au>",
|
|
6
6
|
"homepage": "https://bitbucket.org/lendi-dev/integrations-shared-packages#readme",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "git+ssh://git@bitbucket.org/lendi-dev/integrations-shared-packages.git"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@lendi/integrations-credit-protocol": "^1.17.
|
|
24
|
+
"@lendi/integrations-credit-protocol": "^1.17.5",
|
|
25
25
|
"@lendi/integrations-protocol": "^2.6.4",
|
|
26
26
|
"@lendi/logging": "^1.0.0",
|
|
27
27
|
"clean-deep": "^3.4.0",
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { PersonApplicantPrivacy, ProofOfIdentity } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
|
|
2
|
-
import { EConsent, Identification, Payload as RequiredDocumentPayload } from '../types/events/public-required-document';
|
|
3
|
-
/**
|
|
4
|
-
* Gets the applicant gender from the identification data
|
|
5
|
-
*
|
|
6
|
-
* @param identification Identification data
|
|
7
|
-
* @returns The gender of the applicant
|
|
8
|
-
*/
|
|
9
|
-
export declare const getApplicantGenderFromIdentification: (identification: Identification) => string;
|
|
10
|
-
/**
|
|
11
|
-
* Gets full name on document from the identification data
|
|
12
|
-
*
|
|
13
|
-
* @param identification Identification data
|
|
14
|
-
* @returns The full name on document
|
|
15
|
-
*/
|
|
16
|
-
export declare const getNameOnDocument: (identification: Identification) => string;
|
|
17
|
-
/**
|
|
18
|
-
* Transforms identification data into a partial proof of identity document
|
|
19
|
-
*
|
|
20
|
-
* @param identification Identification data
|
|
21
|
-
* @returns Partial proof of identity object
|
|
22
|
-
*/
|
|
23
|
-
export declare const transformIdentification: (identification: Identification) => Partial<ProofOfIdentity>;
|
|
24
|
-
/**
|
|
25
|
-
* Generates partial details for document used to verify identity
|
|
26
|
-
*
|
|
27
|
-
* @param requiredDocument RequiredDocumentCreated/RequiredDocumentUpdated event payload
|
|
28
|
-
* @returns Partial proof of identity document object
|
|
29
|
-
*/
|
|
30
|
-
export declare const generateProofOfIdentity: (requiredDocument: RequiredDocumentPayload) => Partial<ProofOfIdentity>;
|
|
31
|
-
/**
|
|
32
|
-
* Generates an applicants disclosure details mapping for the partial application
|
|
33
|
-
*
|
|
34
|
-
* @param eConsent E-Consent detials from the RequiredDocumentCreated/RequqiredDocumentUpdated event payload
|
|
35
|
-
* @returns Applicant disclosure details for partial application
|
|
36
|
-
*/
|
|
37
|
-
export declare const generatePersonApplicantPrivacy: (eConsent: EConsent) => PersonApplicantPrivacy;
|
|
38
|
-
/**
|
|
39
|
-
* Transforms a RequiredDocumentCreated or RequiredDocumentUpdated event payload into a partial application
|
|
40
|
-
*
|
|
41
|
-
* @param requiredDocument A RequiredDocumentCreated or RequiredDocumentUpdated event payload
|
|
42
|
-
* @returns A partial application
|
|
43
|
-
*/
|
|
44
|
-
export declare function transformRequiredDocument(requiredDocument: RequiredDocumentPayload): {};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformRequiredDocument = exports.generatePersonApplicantPrivacy = exports.generateProofOfIdentity = exports.transformIdentification = exports.getNameOnDocument = exports.getApplicantGenderFromIdentification = void 0;
|
|
4
|
-
const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
|
|
5
|
-
const application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
|
-
const enum_mappings_1 = require("../types/enum-mappings");
|
|
8
|
-
const enum_mappings_2 = require("../types/enum-mappings");
|
|
9
|
-
const enum_mappings_3 = require("../types/enum-mappings");
|
|
10
|
-
const verification_1 = require("../types/enum-mappings/verification");
|
|
11
|
-
const public_required_document_1 = require("../types/events/public-required-document");
|
|
12
|
-
const formatYesNo_1 = require("../utils/formatYesNo");
|
|
13
|
-
const iso_date_1 = require("../utils/iso-date");
|
|
14
|
-
/**
|
|
15
|
-
* Gets the applicant gender from the identification data
|
|
16
|
-
*
|
|
17
|
-
* @param identification Identification data
|
|
18
|
-
* @returns The gender of the applicant
|
|
19
|
-
*/
|
|
20
|
-
const getApplicantGenderFromIdentification = (identification) => {
|
|
21
|
-
const { gender, idTitle } = identification;
|
|
22
|
-
return gender ? (0, lodash_1.capitalize)(gender) : enum_mappings_3.titleGenderMapping[idTitle || public_required_document_1.IDTitle.Unknown];
|
|
23
|
-
};
|
|
24
|
-
exports.getApplicantGenderFromIdentification = getApplicantGenderFromIdentification;
|
|
25
|
-
/**
|
|
26
|
-
* Gets full name on document from the identification data
|
|
27
|
-
*
|
|
28
|
-
* @param identification Identification data
|
|
29
|
-
* @returns The full name on document
|
|
30
|
-
*/
|
|
31
|
-
const getNameOnDocument = (identification) => {
|
|
32
|
-
const { idFirstName, idMiddleName, idLastName } = identification;
|
|
33
|
-
return [idFirstName, idMiddleName, idLastName].reduce((fullName, nameComponent) => {
|
|
34
|
-
let newFullName = fullName;
|
|
35
|
-
const nameSubstring = nameComponent === null || nameComponent === void 0 ? void 0 : nameComponent.trim();
|
|
36
|
-
if (nameSubstring) {
|
|
37
|
-
newFullName += `${fullName ? ' ' : ''}${nameSubstring}`;
|
|
38
|
-
}
|
|
39
|
-
return newFullName;
|
|
40
|
-
}, '');
|
|
41
|
-
};
|
|
42
|
-
exports.getNameOnDocument = getNameOnDocument;
|
|
43
|
-
/**
|
|
44
|
-
* Transforms identification data into a partial proof of identity document
|
|
45
|
-
*
|
|
46
|
-
* @param identification Identification data
|
|
47
|
-
* @returns Partial proof of identity object
|
|
48
|
-
*/
|
|
49
|
-
const transformIdentification = (identification) => {
|
|
50
|
-
const { australianState, idNumber, idType, issuingCountry = public_required_document_1.IssuingCountry.Australia } = identification;
|
|
51
|
-
const nameOnDocument = (0, exports.getNameOnDocument)(identification);
|
|
52
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, (nameOnDocument && { '@NameOnDocument': nameOnDocument })), (idNumber && { '@DocumentNumber': idNumber })), (australianState && { '@PlaceOfIssue': australianState })), (idType === public_required_document_1.IDType.Passport && issuingCountry !== public_required_document_1.IssuingCountry.Australia
|
|
53
|
-
? {
|
|
54
|
-
'@DocumentType': lixi_internal_request_1.DocumentTypeList.InternationalPassport,
|
|
55
|
-
'@CountryOfIssue': enum_mappings_1.countryCodeMapping[issuingCountry],
|
|
56
|
-
'@PlaceOfIssue': enum_mappings_1.countryCodeMapping[issuingCountry],
|
|
57
|
-
}
|
|
58
|
-
: { '@DocumentType': enum_mappings_2.proofOfIdentityMapping[idType] }));
|
|
59
|
-
};
|
|
60
|
-
exports.transformIdentification = transformIdentification;
|
|
61
|
-
/**
|
|
62
|
-
* Generates partial details for document used to verify identity
|
|
63
|
-
*
|
|
64
|
-
* @param requiredDocument RequiredDocumentCreated/RequiredDocumentUpdated event payload
|
|
65
|
-
* @returns Partial proof of identity document object
|
|
66
|
-
*/
|
|
67
|
-
const generateProofOfIdentity = (requiredDocument) => {
|
|
68
|
-
const { id, status, expiryDate, identification } = requiredDocument;
|
|
69
|
-
return Object.assign(Object.assign(Object.assign({ '@UniqueID': id, '@CountryOfIssue': lixi_internal_request_1.CountryCodeList.Au, '@PlaceOfIssue': lixi_internal_request_1.CountryCodeList.Au }, (expiryDate && { '@ExpiryDate': (0, iso_date_1.isoDate)(expiryDate) })), (status && { '@PhotographVerified': verification_1.verificationMapping[status] })), (identification && (0, exports.transformIdentification)(identification)));
|
|
70
|
-
};
|
|
71
|
-
exports.generateProofOfIdentity = generateProofOfIdentity;
|
|
72
|
-
/**
|
|
73
|
-
* Generates an applicants disclosure details mapping for the partial application
|
|
74
|
-
*
|
|
75
|
-
* @param eConsent E-Consent detials from the RequiredDocumentCreated/RequqiredDocumentUpdated event payload
|
|
76
|
-
* @returns Applicant disclosure details for partial application
|
|
77
|
-
*/
|
|
78
|
-
const generatePersonApplicantPrivacy = (eConsent) => {
|
|
79
|
-
const { hasConsented, consentedAt = new Date() } = eConsent;
|
|
80
|
-
return {
|
|
81
|
-
'@CreditAuthoritySigned': (0, formatYesNo_1.formatYesNo)(hasConsented),
|
|
82
|
-
'@DateSigned': (0, iso_date_1.isoDate)(consentedAt),
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
exports.generatePersonApplicantPrivacy = generatePersonApplicantPrivacy;
|
|
86
|
-
/**
|
|
87
|
-
* Transforms a RequiredDocumentCreated or RequiredDocumentUpdated event payload into a partial application
|
|
88
|
-
*
|
|
89
|
-
* @param requiredDocument A RequiredDocumentCreated or RequiredDocumentUpdated event payload
|
|
90
|
-
* @returns A partial application
|
|
91
|
-
*/
|
|
92
|
-
function transformRequiredDocument(requiredDocument) {
|
|
93
|
-
const partialApplication = {};
|
|
94
|
-
const { applicantId, applicationId, identification, eConsent } = requiredDocument;
|
|
95
|
-
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@UniqueID`, applicantId);
|
|
96
|
-
(0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, applicationId);
|
|
97
|
-
if (identification) {
|
|
98
|
-
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@Gender`, (0, exports.getApplicantGenderFromIdentification)(identification));
|
|
99
|
-
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.ProofOfIdentity}`, (0, exports.generateProofOfIdentity)(requiredDocument));
|
|
100
|
-
}
|
|
101
|
-
if (eConsent) {
|
|
102
|
-
(0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Privacy}`, (0, exports.generatePersonApplicantPrivacy)(eConsent));
|
|
103
|
-
}
|
|
104
|
-
return partialApplication;
|
|
105
|
-
}
|
|
106
|
-
exports.transformRequiredDocument = transformRequiredDocument;
|