@lendi/act-credit-decisions-transform 2.0.0

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.
Files changed (204) hide show
  1. package/README.md +31 -0
  2. package/lib/index.d.ts +11 -0
  3. package/lib/index.js +28 -0
  4. package/lib/logger.d.ts +1 -0
  5. package/lib/logger.js +5 -0
  6. package/lib/schemas/application-workflow-event.json +240 -0
  7. package/lib/schemas/credit-report-retrieved-event.json +57 -0
  8. package/lib/schemas/public-applicant-event.json +910 -0
  9. package/lib/schemas/public-application-event.json +250 -0
  10. package/lib/schemas/public-asset-event.json +679 -0
  11. package/lib/schemas/public-asset-liability-relation-delete-event.json +74 -0
  12. package/lib/schemas/public-asset-liability-relation-event.json +73 -0
  13. package/lib/schemas/public-create-applicant-event.json +609 -0
  14. package/lib/schemas/public-delete-applicant-event.json +66 -0
  15. package/lib/schemas/public-delete-asset-event.json +53 -0
  16. package/lib/schemas/public-delete-income-event.json +55 -0
  17. package/lib/schemas/public-employment-delete-event.json +31 -0
  18. package/lib/schemas/public-employment-event.json +278 -0
  19. package/lib/schemas/public-expense-delete-event.json +41 -0
  20. package/lib/schemas/public-expense-event.json +133 -0
  21. package/lib/schemas/public-funding-position-event.json +419 -0
  22. package/lib/schemas/public-income-event.json +242 -0
  23. package/lib/schemas/public-liability-delete-event.json +37 -0
  24. package/lib/schemas/public-liability-event.json +262 -0
  25. package/lib/schemas/public-required-document-event.json +366 -0
  26. package/lib/schemas/public-update-applicant-event.json +606 -0
  27. package/lib/schemas/sf-opportunity-event-out.json +138 -0
  28. package/lib/transform-events/generate-asset-liability-link.d.ts +10 -0
  29. package/lib/transform-events/generate-asset-liability-link.js +29 -0
  30. package/lib/transform-events/generate-credit-report-rebuilt.d.ts +8 -0
  31. package/lib/transform-events/generate-credit-report-rebuilt.js +41 -0
  32. package/lib/transform-events/transform-applicant.d.ts +8 -0
  33. package/lib/transform-events/transform-applicant.js +180 -0
  34. package/lib/transform-events/transform-application-workflow.d.ts +8 -0
  35. package/lib/transform-events/transform-application-workflow.js +30 -0
  36. package/lib/transform-events/transform-application.d.ts +20 -0
  37. package/lib/transform-events/transform-application.js +67 -0
  38. package/lib/transform-events/transform-asset-address.d.ts +25 -0
  39. package/lib/transform-events/transform-asset-address.js +87 -0
  40. package/lib/transform-events/transform-asset.d.ts +58 -0
  41. package/lib/transform-events/transform-asset.js +337 -0
  42. package/lib/transform-events/transform-employment.d.ts +9 -0
  43. package/lib/transform-events/transform-employment.js +107 -0
  44. package/lib/transform-events/transform-expenses.d.ts +41 -0
  45. package/lib/transform-events/transform-expenses.js +121 -0
  46. package/lib/transform-events/transform-funding-position.d.ts +21 -0
  47. package/lib/transform-events/transform-funding-position.js +107 -0
  48. package/lib/transform-events/transform-income.d.ts +48 -0
  49. package/lib/transform-events/transform-income.js +260 -0
  50. package/lib/transform-events/transform-liability.d.ts +12 -0
  51. package/lib/transform-events/transform-liability.js +117 -0
  52. package/lib/transform-events/transform-percent-owned.d.ts +10 -0
  53. package/lib/transform-events/transform-percent-owned.js +22 -0
  54. package/lib/transform-events/transform-required-document.d.ts +67 -0
  55. package/lib/transform-events/transform-required-document.js +148 -0
  56. package/lib/types/enum-mappings/alieo-frequency.d.ts +15 -0
  57. package/lib/types/enum-mappings/alieo-frequency.js +25 -0
  58. package/lib/types/enum-mappings/applicant-gender.d.ts +6 -0
  59. package/lib/types/enum-mappings/applicant-gender.js +11 -0
  60. package/lib/types/enum-mappings/applicant-type.d.ts +6 -0
  61. package/lib/types/enum-mappings/applicant-type.js +10 -0
  62. package/lib/types/enum-mappings/asset-type.d.ts +3 -0
  63. package/lib/types/enum-mappings/asset-type.js +17 -0
  64. package/lib/types/enum-mappings/builder-type.d.ts +7 -0
  65. package/lib/types/enum-mappings/builder-type.js +9 -0
  66. package/lib/types/enum-mappings/company-structure.d.ts +7 -0
  67. package/lib/types/enum-mappings/company-structure.js +10 -0
  68. package/lib/types/enum-mappings/company-type.d.ts +7 -0
  69. package/lib/types/enum-mappings/company-type.js +11 -0
  70. package/lib/types/enum-mappings/construction-type.d.ts +7 -0
  71. package/lib/types/enum-mappings/construction-type.js +10 -0
  72. package/lib/types/enum-mappings/country-code.d.ts +7 -0
  73. package/lib/types/enum-mappings/country-code.js +246 -0
  74. package/lib/types/enum-mappings/employment-basis.d.ts +7 -0
  75. package/lib/types/enum-mappings/employment-basis.js +12 -0
  76. package/lib/types/enum-mappings/expense-frequency.d.ts +7 -0
  77. package/lib/types/enum-mappings/expense-frequency.js +11 -0
  78. package/lib/types/enum-mappings/funding-position.d.ts +18 -0
  79. package/lib/types/enum-mappings/funding-position.js +36 -0
  80. package/lib/types/enum-mappings/government-benefits.d.ts +7 -0
  81. package/lib/types/enum-mappings/government-benefits.js +10 -0
  82. package/lib/types/enum-mappings/guarantor-relationship-type.d.ts +3 -0
  83. package/lib/types/enum-mappings/guarantor-relationship-type.js +16 -0
  84. package/lib/types/enum-mappings/housing-status.d.ts +7 -0
  85. package/lib/types/enum-mappings/housing-status.js +15 -0
  86. package/lib/types/enum-mappings/income-type.d.ts +7 -0
  87. package/lib/types/enum-mappings/income-type.js +16 -0
  88. package/lib/types/enum-mappings/index.d.ts +27 -0
  89. package/lib/types/enum-mappings/index.js +43 -0
  90. package/lib/types/enum-mappings/liability-payment-type.d.ts +7 -0
  91. package/lib/types/enum-mappings/liability-payment-type.js +9 -0
  92. package/lib/types/enum-mappings/liability-type.d.ts +7 -0
  93. package/lib/types/enum-mappings/liability-type.js +21 -0
  94. package/lib/types/enum-mappings/living-expense.d.ts +7 -0
  95. package/lib/types/enum-mappings/living-expense.js +31 -0
  96. package/lib/types/enum-mappings/marital-status.d.ts +7 -0
  97. package/lib/types/enum-mappings/marital-status.js +12 -0
  98. package/lib/types/enum-mappings/postcode.d.ts +6 -0
  99. package/lib/types/enum-mappings/postcode.js +15 -0
  100. package/lib/types/enum-mappings/preferred-repayment.d.ts +7 -0
  101. package/lib/types/enum-mappings/preferred-repayment.js +10 -0
  102. package/lib/types/enum-mappings/proof-of-identity.d.ts +7 -0
  103. package/lib/types/enum-mappings/proof-of-identity.js +10 -0
  104. package/lib/types/enum-mappings/property-expense-category.d.ts +7 -0
  105. package/lib/types/enum-mappings/property-expense-category.js +11 -0
  106. package/lib/types/enum-mappings/public-financial-asset.d.ts +7 -0
  107. package/lib/types/enum-mappings/public-financial-asset.js +12 -0
  108. package/lib/types/enum-mappings/public-primary-purpose.d.ts +7 -0
  109. package/lib/types/enum-mappings/public-primary-purpose.js +9 -0
  110. package/lib/types/enum-mappings/public-property-status.d.ts +7 -0
  111. package/lib/types/enum-mappings/public-property-status.js +11 -0
  112. package/lib/types/enum-mappings/public-property-type.d.ts +7 -0
  113. package/lib/types/enum-mappings/public-property-type.js +23 -0
  114. package/lib/types/enum-mappings/residency-status.d.ts +7 -0
  115. package/lib/types/enum-mappings/residency-status.js +11 -0
  116. package/lib/types/enum-mappings/title-gender.d.ts +7 -0
  117. package/lib/types/enum-mappings/title-gender.js +13 -0
  118. package/lib/types/enum-mappings/title.d.ts +7 -0
  119. package/lib/types/enum-mappings/title.js +13 -0
  120. package/lib/types/enum-mappings/to-be-purchased.d.ts +5 -0
  121. package/lib/types/enum-mappings/to-be-purchased.js +8 -0
  122. package/lib/types/enum-mappings/to-be-used-as-security.d.ts +5 -0
  123. package/lib/types/enum-mappings/to-be-used-as-security.js +8 -0
  124. package/lib/types/enum-mappings/transaction-type.d.ts +7 -0
  125. package/lib/types/enum-mappings/transaction-type.js +9 -0
  126. package/lib/types/enum-mappings/trust.d.ts +7 -0
  127. package/lib/types/enum-mappings/trust.js +14 -0
  128. package/lib/types/enum-mappings/verification.d.ts +3 -0
  129. package/lib/types/enum-mappings/verification.js +13 -0
  130. package/lib/types/events/applicant-delete.d.ts +42 -0
  131. package/lib/types/events/applicant-delete.js +15 -0
  132. package/lib/types/events/application-workflow.d.ts +233 -0
  133. package/lib/types/events/application-workflow.js +172 -0
  134. package/lib/types/events/asset-delete.d.ts +33 -0
  135. package/lib/types/events/asset-delete.js +15 -0
  136. package/lib/types/events/asset-liability-relation-delete.d.ts +52 -0
  137. package/lib/types/events/asset-liability-relation-delete.js +15 -0
  138. package/lib/types/events/credit-report-retrieved.d.ts +36 -0
  139. package/lib/types/events/credit-report-retrieved.js +15 -0
  140. package/lib/types/events/employment-delete.d.ts +19 -0
  141. package/lib/types/events/employment-delete.js +7 -0
  142. package/lib/types/events/expense-delete.d.ts +21 -0
  143. package/lib/types/events/expense-delete.js +7 -0
  144. package/lib/types/events/funding-position.d.ts +116 -0
  145. package/lib/types/events/funding-position.js +34 -0
  146. package/lib/types/events/income-delete.d.ts +33 -0
  147. package/lib/types/events/income-delete.js +15 -0
  148. package/lib/types/events/liability-delete.d.ts +17 -0
  149. package/lib/types/events/liability-delete.js +7 -0
  150. package/lib/types/events/opportunity.d.ts +102 -0
  151. package/lib/types/events/opportunity.js +47 -0
  152. package/lib/types/events/public-applicant.d.ts +628 -0
  153. package/lib/types/events/public-applicant.js +411 -0
  154. package/lib/types/events/public-application.d.ts +151 -0
  155. package/lib/types/events/public-application.js +103 -0
  156. package/lib/types/events/public-asset-liability-relation.d.ts +52 -0
  157. package/lib/types/events/public-asset-liability-relation.js +15 -0
  158. package/lib/types/events/public-asset.d.ts +502 -0
  159. package/lib/types/events/public-asset.js +348 -0
  160. package/lib/types/events/public-employment.d.ts +121 -0
  161. package/lib/types/events/public-employment.js +46 -0
  162. package/lib/types/events/public-expense.d.ts +84 -0
  163. package/lib/types/events/public-expense.js +51 -0
  164. package/lib/types/events/public-funding-position.d.ts +341 -0
  165. package/lib/types/events/public-funding-position.js +20 -0
  166. package/lib/types/events/public-income.d.ts +144 -0
  167. package/lib/types/events/public-income.js +65 -0
  168. package/lib/types/events/public-liability.d.ts +140 -0
  169. package/lib/types/events/public-liability.js +68 -0
  170. package/lib/types/events/public-required-document.d.ts +374 -0
  171. package/lib/types/events/public-required-document.js +297 -0
  172. package/lib/types/partial-application.d.ts +3 -0
  173. package/lib/types/partial-application.js +2 -0
  174. package/lib/types/recursive-partial.d.ts +3 -0
  175. package/lib/types/recursive-partial.js +2 -0
  176. package/lib/update-application/merge-application.d.ts +14 -0
  177. package/lib/update-application/merge-application.js +175 -0
  178. package/lib/update-application/remove-ids-not-required.d.ts +11 -0
  179. package/lib/update-application/remove-ids-not-required.js +63 -0
  180. package/lib/update-application/update-primary-applicant.d.ts +27 -0
  181. package/lib/update-application/update-primary-applicant.js +46 -0
  182. package/lib/utils/address-tools.d.ts +84 -0
  183. package/lib/utils/address-tools.js +176 -0
  184. package/lib/utils/clean-up.d.ts +7 -0
  185. package/lib/utils/clean-up.js +24 -0
  186. package/lib/utils/errors.d.ts +28 -0
  187. package/lib/utils/errors.js +43 -0
  188. package/lib/utils/formatYesNo.d.ts +8 -0
  189. package/lib/utils/formatYesNo.js +12 -0
  190. package/lib/utils/generate-address.d.ts +19 -0
  191. package/lib/utils/generate-address.js +97 -0
  192. package/lib/utils/get-financial-institution.d.ts +8 -0
  193. package/lib/utils/get-financial-institution.js +17 -0
  194. package/lib/utils/is-asset-type.d.ts +25 -0
  195. package/lib/utils/is-asset-type.js +46 -0
  196. package/lib/utils/is-income-type.d.ts +73 -0
  197. package/lib/utils/is-income-type.js +134 -0
  198. package/lib/utils/iso-date.d.ts +7 -0
  199. package/lib/utils/iso-date.js +12 -0
  200. package/lib/utils/normalise-date.d.ts +8 -0
  201. package/lib/utils/normalise-date.js +17 -0
  202. package/lib/utils/round-decimal.d.ts +6 -0
  203. package/lib/utils/round-decimal.js +12 -0
  204. package/package.json +79 -0
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Type = exports.Status = exports.IssuingCountry = exports.IDType = exports.IDTitle = exports.Gender = exports.AustralianState = void 0;
4
+ var AustralianState;
5
+ (function (AustralianState) {
6
+ AustralianState["Act"] = "ACT";
7
+ AustralianState["NT"] = "NT";
8
+ AustralianState["Nsw"] = "NSW";
9
+ AustralianState["Qld"] = "QLD";
10
+ AustralianState["Sa"] = "SA";
11
+ AustralianState["Tas"] = "TAS";
12
+ AustralianState["Vic"] = "VIC";
13
+ AustralianState["Wa"] = "WA";
14
+ })(AustralianState = exports.AustralianState || (exports.AustralianState = {}));
15
+ var Gender;
16
+ (function (Gender) {
17
+ Gender["Female"] = "FEMALE";
18
+ Gender["Male"] = "MALE";
19
+ })(Gender = exports.Gender || (exports.Gender = {}));
20
+ var IDTitle;
21
+ (function (IDTitle) {
22
+ IDTitle["DR"] = "DR";
23
+ IDTitle["MS"] = "MS";
24
+ IDTitle["Miss"] = "MISS";
25
+ IDTitle["Mr"] = "MR";
26
+ IDTitle["Mrs"] = "MRS";
27
+ IDTitle["Other"] = "OTHER";
28
+ IDTitle["Unknown"] = "UNKNOWN";
29
+ })(IDTitle = exports.IDTitle || (exports.IDTitle = {}));
30
+ /**
31
+ * ID Type
32
+ */
33
+ var IDType;
34
+ (function (IDType) {
35
+ IDType["AustralianDriverLicense"] = "australian_driver_license";
36
+ IDType["NationalIDCard"] = "national_id_card";
37
+ IDType["Passport"] = "passport";
38
+ })(IDType = exports.IDType || (exports.IDType = {}));
39
+ var IssuingCountry;
40
+ (function (IssuingCountry) {
41
+ IssuingCountry["Afghanistan"] = "Afghanistan";
42
+ IssuingCountry["Albania"] = "Albania";
43
+ IssuingCountry["Algeria"] = "Algeria";
44
+ IssuingCountry["AmericanSamoa"] = "American Samoa";
45
+ IssuingCountry["Andorra"] = "Andorra";
46
+ IssuingCountry["Angola"] = "Angola";
47
+ IssuingCountry["Anguilla"] = "Anguilla";
48
+ IssuingCountry["Antarctica"] = "Antarctica";
49
+ IssuingCountry["AntiguaAndBarbuda"] = "Antigua And Barbuda";
50
+ IssuingCountry["Argentina"] = "Argentina";
51
+ IssuingCountry["Armenia"] = "Armenia";
52
+ IssuingCountry["Aruba"] = "Aruba";
53
+ IssuingCountry["Australia"] = "Australia";
54
+ IssuingCountry["Austria"] = "Austria";
55
+ IssuingCountry["Azerbaijan"] = "Azerbaijan";
56
+ IssuingCountry["Bahamas"] = "Bahamas";
57
+ IssuingCountry["Bahrain"] = "Bahrain";
58
+ IssuingCountry["Bangladesh"] = "Bangladesh";
59
+ IssuingCountry["Barbados"] = "Barbados";
60
+ IssuingCountry["Belarus"] = "Belarus";
61
+ IssuingCountry["Belgium"] = "Belgium";
62
+ IssuingCountry["Belize"] = "Belize";
63
+ IssuingCountry["Benin"] = "Benin";
64
+ IssuingCountry["Bermuda"] = "Bermuda";
65
+ IssuingCountry["Bhutan"] = "Bhutan";
66
+ IssuingCountry["Bolivia"] = "Bolivia";
67
+ IssuingCountry["BosniaAndHerzegovina"] = "Bosnia And Herzegovina";
68
+ IssuingCountry["Botswana"] = "Botswana";
69
+ IssuingCountry["BouvetIsland"] = "Bouvet Island";
70
+ IssuingCountry["Brazil"] = "Brazil";
71
+ IssuingCountry["BritishIndianOceanTerritory"] = "British Indian Ocean Territory";
72
+ IssuingCountry["BritishVirginIslands"] = "British Virgin Islands";
73
+ IssuingCountry["BruneiDarussalam"] = "Brunei Darussalam";
74
+ IssuingCountry["Bulgaria"] = "Bulgaria";
75
+ IssuingCountry["BurkinaFaso"] = "Burkina Faso";
76
+ IssuingCountry["Burundi"] = "Burundi";
77
+ IssuingCountry["Cambodia"] = "Cambodia";
78
+ IssuingCountry["Cameroon"] = "Cameroon";
79
+ IssuingCountry["Canada"] = "Canada";
80
+ IssuingCountry["CapeVerde"] = "Cape Verde";
81
+ IssuingCountry["CaymanIslands"] = "Cayman Islands";
82
+ IssuingCountry["CentralAfricanRepublic"] = "Central African Republic";
83
+ IssuingCountry["Chad"] = "Chad";
84
+ IssuingCountry["Chile"] = "Chile";
85
+ IssuingCountry["China"] = "China";
86
+ IssuingCountry["ChristmasIsland"] = "Christmas Island";
87
+ IssuingCountry["CocosKeelingIslands"] = "Cocos (Keeling) Islands";
88
+ IssuingCountry["Colombia"] = "Colombia";
89
+ IssuingCountry["Comoros"] = "Comoros";
90
+ IssuingCountry["CookIslands"] = "Cook Islands";
91
+ IssuingCountry["CostaRica"] = "Costa Rica";
92
+ IssuingCountry["CoteDIvoire"] = "Cote D'ivoire";
93
+ IssuingCountry["Croatia"] = "Croatia";
94
+ IssuingCountry["Cuba"] = "Cuba";
95
+ IssuingCountry["Cyprus"] = "Cyprus";
96
+ IssuingCountry["CzechRepublic"] = "Czech Republic";
97
+ IssuingCountry["DemocraticPeopleSRepublicOfKorea"] = "Democratic People's Republic of Korea";
98
+ IssuingCountry["DemocraticRepublicOfTheCongo"] = "Democratic Republic Of The Congo";
99
+ IssuingCountry["Denmark"] = "Denmark";
100
+ IssuingCountry["Djibouti"] = "Djibouti";
101
+ IssuingCountry["Dominica"] = "Dominica";
102
+ IssuingCountry["DominicanRepublic"] = "Dominican Republic";
103
+ IssuingCountry["EastTimor"] = "East Timor";
104
+ IssuingCountry["Ecuador"] = "Ecuador";
105
+ IssuingCountry["Egypt"] = "Egypt";
106
+ IssuingCountry["ElSalvador"] = "El Salvador";
107
+ IssuingCountry["EquatorialGuinea"] = "Equatorial Guinea";
108
+ IssuingCountry["Eritrea"] = "Eritrea";
109
+ IssuingCountry["Estonia"] = "Estonia";
110
+ IssuingCountry["Ethiopia"] = "Ethiopia";
111
+ IssuingCountry["FalklandIslands"] = "Falkland Islands";
112
+ IssuingCountry["FaroeIslands"] = "Faroe Islands";
113
+ IssuingCountry["FederatedStatesOfMicronesia"] = "Federated States Of Micronesia";
114
+ IssuingCountry["Fiji"] = "Fiji";
115
+ IssuingCountry["Finland"] = "Finland";
116
+ IssuingCountry["France"] = "France";
117
+ IssuingCountry["FrenchGuiana"] = "French Guiana";
118
+ IssuingCountry["FrenchPolynesia"] = "French Polynesia";
119
+ IssuingCountry["FrenchSouthernTerritories"] = "French Southern Territories";
120
+ IssuingCountry["Gabon"] = "Gabon";
121
+ IssuingCountry["Gambia"] = "Gambia";
122
+ IssuingCountry["Georgia"] = "Georgia";
123
+ IssuingCountry["Germany"] = "Germany";
124
+ IssuingCountry["Ghana"] = "Ghana";
125
+ IssuingCountry["Gibraltar"] = "Gibraltar";
126
+ IssuingCountry["Greece"] = "Greece";
127
+ IssuingCountry["Greenland"] = "Greenland";
128
+ IssuingCountry["Grenada"] = "Grenada";
129
+ IssuingCountry["Guadeloupe"] = "Guadeloupe";
130
+ IssuingCountry["Guam"] = "Guam";
131
+ IssuingCountry["Guatemala"] = "Guatemala";
132
+ IssuingCountry["Guinea"] = "Guinea";
133
+ IssuingCountry["GuineaBissau"] = "Guinea-bissau";
134
+ IssuingCountry["Guyana"] = "Guyana";
135
+ IssuingCountry["Haiti"] = "Haiti";
136
+ IssuingCountry["HeardIslandAndMcdonaldIslands"] = "Heard Island And Mcdonald Islands";
137
+ IssuingCountry["HolySeeVaticanCityState"] = "Holy See (Vatican City State)";
138
+ IssuingCountry["Honduras"] = "Honduras";
139
+ IssuingCountry["HongKong"] = "Hong Kong";
140
+ IssuingCountry["Hungary"] = "Hungary";
141
+ IssuingCountry["Iceland"] = "Iceland";
142
+ IssuingCountry["India"] = "India";
143
+ IssuingCountry["Indonesia"] = "Indonesia";
144
+ IssuingCountry["Iran"] = "Iran";
145
+ IssuingCountry["Iraq"] = "Iraq";
146
+ IssuingCountry["Ireland"] = "Ireland";
147
+ IssuingCountry["Israel"] = "Israel";
148
+ IssuingCountry["Italy"] = "Italy";
149
+ IssuingCountry["Jamaica"] = "Jamaica";
150
+ IssuingCountry["Japan"] = "Japan";
151
+ IssuingCountry["Jordan"] = "Jordan";
152
+ IssuingCountry["Kazakstan"] = "Kazakstan";
153
+ IssuingCountry["Kenya"] = "Kenya";
154
+ IssuingCountry["Kiribati"] = "Kiribati";
155
+ IssuingCountry["Kosovo"] = "Kosovo";
156
+ IssuingCountry["Kuwait"] = "Kuwait";
157
+ IssuingCountry["Kyrgyzstan"] = "Kyrgyzstan";
158
+ IssuingCountry["Laos"] = "Laos";
159
+ IssuingCountry["Latvia"] = "Latvia";
160
+ IssuingCountry["Lebanon"] = "Lebanon";
161
+ IssuingCountry["Lesotho"] = "Lesotho";
162
+ IssuingCountry["Liberia"] = "Liberia";
163
+ IssuingCountry["LibyanArabJamahiriya"] = "Libyan Arab Jamahiriya";
164
+ IssuingCountry["Liechtenstein"] = "Liechtenstein";
165
+ IssuingCountry["Lithuania"] = "Lithuania";
166
+ IssuingCountry["Luxembourg"] = "Luxembourg";
167
+ IssuingCountry["Macau"] = "Macau";
168
+ IssuingCountry["Macedonia"] = "Macedonia";
169
+ IssuingCountry["Madagascar"] = "Madagascar";
170
+ IssuingCountry["Malawi"] = "Malawi";
171
+ IssuingCountry["Malaysia"] = "Malaysia";
172
+ IssuingCountry["Maldives"] = "Maldives";
173
+ IssuingCountry["Mali"] = "Mali";
174
+ IssuingCountry["Malta"] = "Malta";
175
+ IssuingCountry["MarshallIslands"] = "Marshall Islands";
176
+ IssuingCountry["Martinique"] = "Martinique";
177
+ IssuingCountry["Mauritania"] = "Mauritania";
178
+ IssuingCountry["Mauritius"] = "Mauritius";
179
+ IssuingCountry["Mayotte"] = "Mayotte";
180
+ IssuingCountry["Mexico"] = "Mexico";
181
+ IssuingCountry["Monaco"] = "Monaco";
182
+ IssuingCountry["Mongolia"] = "Mongolia";
183
+ IssuingCountry["Montenegro"] = "Montenegro";
184
+ IssuingCountry["Montserrat"] = "Montserrat";
185
+ IssuingCountry["Morocco"] = "Morocco";
186
+ IssuingCountry["Mozambique"] = "Mozambique";
187
+ IssuingCountry["Myanmar"] = "Myanmar";
188
+ IssuingCountry["Namibia"] = "Namibia";
189
+ IssuingCountry["Nauru"] = "Nauru";
190
+ IssuingCountry["Nepal"] = "Nepal";
191
+ IssuingCountry["Netherlands"] = "Netherlands";
192
+ IssuingCountry["NetherlandsAntilles"] = "Netherlands Antilles";
193
+ IssuingCountry["NewCaledonia"] = "New Caledonia";
194
+ IssuingCountry["NewZealand"] = "New Zealand";
195
+ IssuingCountry["Nicaragua"] = "Nicaragua";
196
+ IssuingCountry["Niger"] = "Niger";
197
+ IssuingCountry["Nigeria"] = "Nigeria";
198
+ IssuingCountry["Niue"] = "Niue";
199
+ IssuingCountry["NorfolkIsland"] = "Norfolk Island";
200
+ IssuingCountry["NorthernMarianaIslands"] = "Northern Mariana Islands";
201
+ IssuingCountry["Norway"] = "Norway";
202
+ IssuingCountry["Oman"] = "Oman";
203
+ IssuingCountry["Pakistan"] = "Pakistan";
204
+ IssuingCountry["Palau"] = "Palau";
205
+ IssuingCountry["PalestinianTerritory"] = "Palestinian Territory";
206
+ IssuingCountry["Panama"] = "Panama";
207
+ IssuingCountry["PapuaNewGuinea"] = "Papua New Guinea";
208
+ IssuingCountry["Paraguay"] = "Paraguay";
209
+ IssuingCountry["Peru"] = "Peru";
210
+ IssuingCountry["Philippines"] = "Philippines";
211
+ IssuingCountry["Pitcairn"] = "Pitcairn";
212
+ IssuingCountry["Poland"] = "Poland";
213
+ IssuingCountry["Portugal"] = "Portugal";
214
+ IssuingCountry["PuertoRico"] = "Puerto Rico";
215
+ IssuingCountry["Qatar"] = "Qatar";
216
+ IssuingCountry["RepublicOfMoldova"] = "Republic Of Moldova";
217
+ IssuingCountry["Romania"] = "Romania";
218
+ IssuingCountry["RussianFederation"] = "Russian Federation";
219
+ IssuingCountry["Rwanda"] = "Rwanda";
220
+ IssuingCountry["SANMarino"] = "San Marino";
221
+ IssuingCountry["SaintHelena"] = "Saint Helena";
222
+ IssuingCountry["SaintKittsAndNevis"] = "Saint Kitts And Nevis";
223
+ IssuingCountry["SaintLucia"] = "Saint Lucia";
224
+ IssuingCountry["SaintPierreAndMiquelon"] = "Saint Pierre And Miquelon";
225
+ IssuingCountry["SaintVincentAndTheGrenadines"] = "Saint Vincent And The Grenadines";
226
+ IssuingCountry["Samoa"] = "Samoa";
227
+ IssuingCountry["SaoTomeAndPrincipe"] = "Sao Tome And Principe";
228
+ IssuingCountry["SaudiArabia"] = "Saudi Arabia";
229
+ IssuingCountry["Senegal"] = "Senegal";
230
+ IssuingCountry["Serbia"] = "Serbia";
231
+ IssuingCountry["Seychelles"] = "Seychelles";
232
+ IssuingCountry["SierraLeone"] = "Sierra Leone";
233
+ IssuingCountry["Singapore"] = "Singapore";
234
+ IssuingCountry["Slovakia"] = "Slovakia";
235
+ IssuingCountry["Slovenia"] = "Slovenia";
236
+ IssuingCountry["SolomonIslands"] = "Solomon Islands";
237
+ IssuingCountry["Somalia"] = "Somalia";
238
+ IssuingCountry["SouthAfrica"] = "South Africa";
239
+ IssuingCountry["SouthGeorgiaAndTheSouthSandwichIslands"] = "South Georgia And The South Sandwich Islands";
240
+ IssuingCountry["Spain"] = "Spain";
241
+ IssuingCountry["SriLanka"] = "Sri Lanka";
242
+ IssuingCountry["Sudan"] = "Sudan";
243
+ IssuingCountry["Suriname"] = "Suriname";
244
+ IssuingCountry["SvalbardAndJanMayen"] = "Svalbard And Jan Mayen";
245
+ IssuingCountry["Swaziland"] = "Swaziland";
246
+ IssuingCountry["Sweden"] = "Sweden";
247
+ IssuingCountry["Switzerland"] = "Switzerland";
248
+ IssuingCountry["SyrianArabRepublic"] = "Syrian Arab Republic";
249
+ IssuingCountry["Taiwan"] = "Taiwan";
250
+ IssuingCountry["Tajikistan"] = "Tajikistan";
251
+ IssuingCountry["Tanzania"] = "Tanzania";
252
+ IssuingCountry["Thailand"] = "Thailand";
253
+ IssuingCountry["TheRepublicOfSouthKorea"] = "The Republic of South Korea";
254
+ IssuingCountry["Togo"] = "Togo";
255
+ IssuingCountry["Tokelau"] = "Tokelau";
256
+ IssuingCountry["Tonga"] = "Tonga";
257
+ IssuingCountry["TrinidadAndTobago"] = "Trinidad And Tobago";
258
+ IssuingCountry["Tunisia"] = "Tunisia";
259
+ IssuingCountry["Turkey"] = "Turkey";
260
+ IssuingCountry["Turkmenistan"] = "Turkmenistan";
261
+ IssuingCountry["TurksAndCaicosIslands"] = "Turks And Caicos Islands";
262
+ IssuingCountry["Tuvalu"] = "Tuvalu";
263
+ IssuingCountry["USVirginIslands"] = "US Virgin Islands";
264
+ IssuingCountry["Uganda"] = "Uganda";
265
+ IssuingCountry["Ukraine"] = "Ukraine";
266
+ IssuingCountry["UnitedArabEmirates"] = "United Arab Emirates";
267
+ IssuingCountry["UnitedKingdom"] = "United Kingdom";
268
+ IssuingCountry["UnitedStatesMinorOutlyingIslands"] = "United States Minor Outlying Islands";
269
+ IssuingCountry["UnitedStatesOfAmerica"] = "United States of America";
270
+ IssuingCountry["Uruguay"] = "Uruguay";
271
+ IssuingCountry["Uzbekistan"] = "Uzbekistan";
272
+ IssuingCountry["Vanuatu"] = "Vanuatu";
273
+ IssuingCountry["Venezuela"] = "Venezuela";
274
+ IssuingCountry["Vietnam"] = "Vietnam";
275
+ IssuingCountry["WallisAndFutuna"] = "Wallis And Futuna";
276
+ IssuingCountry["WesternSahara"] = "Western Sahara";
277
+ IssuingCountry["Yemen"] = "Yemen";
278
+ IssuingCountry["Zambia"] = "Zambia";
279
+ IssuingCountry["Zimbabwe"] = "Zimbabwe";
280
+ })(IssuingCountry = exports.IssuingCountry || (exports.IssuingCountry = {}));
281
+ /**
282
+ * Status
283
+ */
284
+ var Status;
285
+ (function (Status) {
286
+ Status["Expired"] = "expired";
287
+ Status["FailedVerification"] = "failed_verification";
288
+ Status["NotRequired"] = "not_required";
289
+ Status["PendingUpload"] = "pending_upload";
290
+ Status["PendingVerification"] = "pending_verification";
291
+ Status["Verified"] = "verified";
292
+ })(Status = exports.Status || (exports.Status = {}));
293
+ var Type;
294
+ (function (Type) {
295
+ Type["RequiredDocumentCreated"] = "RequiredDocumentCreated";
296
+ Type["RequiredDocumentUpdated"] = "RequiredDocumentUpdated";
297
+ })(Type = exports.Type || (exports.Type = {}));
@@ -0,0 +1,3 @@
1
+ import { InternalRequest } from '@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request';
2
+ import { RecursivePartial } from './recursive-partial';
3
+ export type PartialApplication = RecursivePartial<InternalRequest>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export type RecursivePartial<T> = {
2
+ [P in keyof T]?: RecursivePartial<T[P]>;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ interface DeepMergeOptions {
2
+ readonly secondIDEnabled?: boolean;
3
+ }
4
+ /**
5
+ * Deep merges the application and custom handles specific arrays
6
+ *
7
+ * @param existingApplication a saved dynamo application.
8
+ * @param newApplication new application coming from events.
9
+ * @param {DeepMergeOptions} options Deep merge options
10
+ *
11
+ * @returns merged application.
12
+ */
13
+ export declare function deepMergeApplication(existingApplication: object | undefined, newApplication: object, options?: DeepMergeOptions): any;
14
+ export {};
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deepMergeApplication = void 0;
4
+ const merge = require("deepmerge");
5
+ const cleanDeep = require('clean-deep');
6
+ /**
7
+ * Deep merges the application and custom handles specific arrays
8
+ *
9
+ * @param existingApplication a saved dynamo application.
10
+ * @param newApplication new application coming from events.
11
+ * @param {DeepMergeOptions} options Deep merge options
12
+ *
13
+ * @returns merged application.
14
+ */
15
+ function deepMergeApplication(existingApplication, newApplication, options = {}) {
16
+ if (!existingApplication) {
17
+ return newApplication;
18
+ }
19
+ const { secondIDEnabled = false } = options;
20
+ // Array fields with @UniqueIDs
21
+ const listsWithUniqueIds = [
22
+ 'Attachment',
23
+ 'Address',
24
+ 'CompanyApplicant',
25
+ 'Dependant',
26
+ 'Liability',
27
+ 'LivingExpense',
28
+ 'LoanDetails',
29
+ 'NonRealEstateAsset',
30
+ 'OtherCommitment',
31
+ 'OtherIncome',
32
+ 'PersonApplicant',
33
+ 'RealEstateAsset',
34
+ 'RelatedCompany',
35
+ 'RelatedPerson',
36
+ 'TrustApplicant',
37
+ ];
38
+ if (secondIDEnabled) {
39
+ listsWithUniqueIds.push('ProofOfIdentity');
40
+ }
41
+ // Array fields with @x_Party
42
+ const listsWithXParty = ['Report'];
43
+ // Array fields with @x_Owner
44
+ const listsWithXOwner = ['RentalIncome'];
45
+ // Array fields with @x_Applicant
46
+ const listsWithXApplicant = ['Applicant'];
47
+ // Array fields with @x_ResidentialAddress
48
+ const listsWithXResidentialAddress = ['PriorAddress'];
49
+ // Array fields with @x_Guarantor
50
+ const listsWithXGuarantor = ['Guarantor'];
51
+ // Array fields with @x_Trustee
52
+ const listsWithXTrustee = ['Trustee'];
53
+ // Array fields with @x_Beneficiary
54
+ const listsWithXBeneficiary = ['Beneficiary'];
55
+ // Array fields with @x_BeneficialOwner
56
+ const listsWithXBeneficialOwner = ['BeneficialOwner'];
57
+ // Array fields with @x_Director
58
+ const listsWithXDirector = ['Director'];
59
+ // Curried function which takes a uniqueKey and returns a function which will either replace
60
+ // or merge the item in the array based on the uniqueKey
61
+ const mergeItems = (uniqueKey) => {
62
+ return (existingItem, newItem) => {
63
+ // if not array continue with merge
64
+ if (!Array.isArray(newItem)) {
65
+ return merge(existingItem, newItem, mergeOptions);
66
+ }
67
+ return findArrayItemAndMerge(existingItem, newItem, uniqueKey, mergeOptions);
68
+ };
69
+ };
70
+ const mergeOptions = {
71
+ customMerge: (key) => {
72
+ if (listsWithUniqueIds.find((item) => item === key)) {
73
+ return mergeItems('@UniqueID');
74
+ }
75
+ if (listsWithXParty.find((item) => item === key)) {
76
+ return mergeItems('@x_Party');
77
+ }
78
+ if (listsWithXOwner.find((item) => item === key)) {
79
+ return mergeItems('@x_Owner');
80
+ }
81
+ if (listsWithXResidentialAddress.find((item) => item === key)) {
82
+ return mergeItems('@x_ResidentialAddress');
83
+ }
84
+ if (listsWithXApplicant.find((item) => item === key)) {
85
+ return mergeItems('@x_Applicant');
86
+ }
87
+ if (listsWithXGuarantor.find((item) => item === key)) {
88
+ return mergeItems('@x_Guarantor');
89
+ }
90
+ if (listsWithXTrustee.find((item) => item === key)) {
91
+ return mergeItems('@x_Trustee');
92
+ }
93
+ if (listsWithXBeneficiary.find((item) => item === key)) {
94
+ return mergeItems('@x_Beneficiary');
95
+ }
96
+ if (listsWithXBeneficialOwner.find((item) => item === key)) {
97
+ return mergeItems('@x_BeneficialOwner');
98
+ }
99
+ if (listsWithXDirector.find((item) => item === key)) {
100
+ return mergeItems('@x_Director');
101
+ }
102
+ return mergeItems(key);
103
+ },
104
+ };
105
+ const mergedApplication = merge(existingApplication, newApplication, mergeOptions);
106
+ // Default configurations of cleanDeep for reference.
107
+ const params = {
108
+ cleanValues: [],
109
+ emptyArrays: true,
110
+ emptyObjects: true,
111
+ emptyStrings: true,
112
+ NaNValues: true,
113
+ nullValues: true,
114
+ undefinedValues: true,
115
+ };
116
+ return cleanDeep(mergedApplication, params);
117
+ }
118
+ exports.deepMergeApplication = deepMergeApplication;
119
+ const arrayItemToReplaceKeys = ['Owner', 'Attendee', 'Shareholder', 'Fee', 'ContributionFunds', 'RentalIncome'];
120
+ /**
121
+ *
122
+ * @param existingItem
123
+ * @param newItem
124
+ * @param uniqueKey
125
+ * @param options
126
+ */
127
+ function findArrayItemAndMerge(existingItem, newItem, uniqueKey, options) {
128
+ // For some Key, overwritten the old value with the new data so no merge is happening.
129
+ if (arrayItemToReplaceKeys.includes(uniqueKey))
130
+ return newItem;
131
+ if (uniqueKey === 'Income' && existingItem && existingItem.some((item) => item['@StartDate'])) {
132
+ // Income array in CompanyApplicant
133
+ return newItem;
134
+ }
135
+ if (uniqueKey === 'Income' && existingItem && existingItem.some((item) => item.BusinessActivityStatement)) {
136
+ // Income array in CompanyApplicant for Low Doc applications
137
+ return newItem;
138
+ }
139
+ // Copying existing array
140
+ const mergedArray = existingItem.slice();
141
+ // Searching whether item in the new array exists in existing array
142
+ newItem.forEach((item) => {
143
+ const indexOfItem = mergedArray.findIndex((existingItem) => {
144
+ // TODO [CORE-2160] how to identify employment without go a level down.
145
+ // Employment needs to go one level deeper to check if the @UniqueID already exist.
146
+ if (uniqueKey === 'Employment') {
147
+ const currentEmploymentKeys = Object.keys(item);
148
+ const existingEmploymentKeys = Object.keys(existingItem);
149
+ if (currentEmploymentKeys.length && existingEmploymentKeys.length) {
150
+ // Get the unique id from the field with proper value for current employment. The types with undefined value
151
+ // are present in order to remove the related types from existing application. These undefined types will be
152
+ // removed from payload immediately after deep merging.
153
+ // @pliu 19/11/19
154
+ const currentEmployment = currentEmploymentKeys.find((key) => item[key]);
155
+ // Each employment can only have one of three types.
156
+ // @pliu 19/11/19
157
+ const existingEmployment = existingEmploymentKeys[0];
158
+ if (currentEmployment && existingEmployment) {
159
+ return existingItem[existingEmployment]['@UniqueID'] === item[currentEmployment]['@UniqueID'];
160
+ }
161
+ }
162
+ return -1;
163
+ }
164
+ return existingItem[uniqueKey] === item[uniqueKey];
165
+ });
166
+ // Checks if item should be added or merged
167
+ if (indexOfItem === -1) {
168
+ mergedArray.push(item);
169
+ }
170
+ else {
171
+ mergedArray[indexOfItem] = merge(mergedArray[indexOfItem], item, options);
172
+ }
173
+ });
174
+ return mergedArray;
175
+ }
@@ -0,0 +1,11 @@
1
+ import { InternalRequest } 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
+ * Removes ProofOfIdentity ID document that is in status Not Required
6
+ *
7
+ * @param {RecursivePartial<InternalRequest>} application - Partial LIXI CAL application
8
+ * @param {RequiredDocEventPayload} eventPayload - Required Document event payload
9
+ * @returns {RecursivePartial<InternalRequest>} Updated application
10
+ */
11
+ export declare const removeIdsNotRequired: (application: RecursivePartial<InternalRequest>, eventPayload: RequiredDocEventPayload) => RecursivePartial<InternalRequest>;
@@ -0,0 +1,63 @@
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 = 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
+ * @param {identification} identification Identification data in RequiredDocument event
24
+ * @returns {PersonApplicant} Updated person applicant
25
+ */
26
+ const removeIDDocumentFromApplicant = (personApplicant, id, identification) => {
27
+ const { ProofOfIdentity = [] } = personApplicant, rest = __rest(personApplicant, ["ProofOfIdentity"]);
28
+ const updatedProofOfIdentity = ProofOfIdentity.filter((proofOfId) => {
29
+ let shouldKeepProofOfId = true;
30
+ if (proofOfId['@UniqueID']) {
31
+ shouldKeepProofOfId = proofOfId['@UniqueID'] !== id;
32
+ }
33
+ else {
34
+ if (identification === null || identification === void 0 ? void 0 : identification.idNumber) {
35
+ shouldKeepProofOfId = proofOfId['@DocumentNumber'] !== identification.idNumber;
36
+ }
37
+ }
38
+ return shouldKeepProofOfId;
39
+ });
40
+ // If the updateProofOfIdentity is an empty array then we remove the ProofOfIdentity attribute from the person applicant
41
+ return Object.assign(Object.assign({}, rest), (updatedProofOfIdentity.length && { ProofOfIdentity: updatedProofOfIdentity }));
42
+ };
43
+ /**
44
+ * Removes ProofOfIdentity ID document that is in status Not Required
45
+ *
46
+ * @param {RecursivePartial<InternalRequest>} application - Partial LIXI CAL application
47
+ * @param {RequiredDocEventPayload} eventPayload - Required Document event payload
48
+ * @returns {RecursivePartial<InternalRequest>} Updated application
49
+ */
50
+ const removeIdsNotRequired = (application, eventPayload) => {
51
+ const { status: verificationStatus, identification, applicantId, id } = eventPayload;
52
+ const personApplicants = (0, lodash_1.get)(application, application_paths_1.paths.PersonApplicants, []);
53
+ const updatedApplication = (0, lodash_1.cloneDeep)(application);
54
+ if (verificationStatus === public_required_document_1.Status.NotRequired && personApplicants.length) {
55
+ const personApplicantIndex = personApplicants.findIndex((personApplicant) => personApplicant['@UniqueID'] === applicantId);
56
+ if (personApplicantIndex !== -1) {
57
+ const updatedPersonApplicant = removeIDDocumentFromApplicant(personApplicants[personApplicantIndex], id, identification);
58
+ (0, lodash_1.set)(updatedApplication, `${application_paths_1.paths.PersonApplicants}.[${personApplicantIndex}]`, updatedPersonApplicant);
59
+ }
60
+ }
61
+ return updatedApplication;
62
+ };
63
+ exports.removeIdsNotRequired = removeIdsNotRequired;
@@ -0,0 +1,27 @@
1
+ import { PersonApplicant } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
2
+ import { PartialApplication } from '../types/partial-application';
3
+ import { Payload } from '../types/events/public-applicant';
4
+ /**
5
+ * Checks if there are more than one person applicants with applicant type borrower
6
+ *
7
+ * @param {PersonApplicants[]} personApplicants - Person applicants on the deep merged application
8
+ * @returns {boolean} - Whether or not there are more than one applicant with applicant type borrower
9
+ */
10
+ export declare const isMultiplePersonApplicantBorrowers: (personApplicants: PersonApplicant[]) => boolean;
11
+ /**
12
+ * Updates the primary applicant of the application based on the new primary applicant id
13
+ *
14
+ * @param {string} newPrimaryApplicantId - New primary applicant id
15
+ * @param {PersonApplicant[]} personApplicants - Person applicants from the updated application after deep merge
16
+ * @returns {PersonApplicant[]} - Updated person applicants
17
+ */
18
+ export declare const updatePrimaryApplicant: (newPrimaryApplicantId: string, personApplicants: PersonApplicant[]) => PersonApplicant[];
19
+ /**
20
+ * Updates the primary applicant on the application based on the data in the guarantor applicant event
21
+ *
22
+ * @param {PartialApplication} application - Application after deep merge
23
+ * @param {Payload} applicantPayload - Public applicant event payload
24
+ * @returns {PartialApplication} - Updated application
25
+ */
26
+ declare const updatePrimaryApplicantUsingGuarantor: (application: PartialApplication, applicantPayload: Payload) => PartialApplication;
27
+ export default updatePrimaryApplicantUsingGuarantor;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updatePrimaryApplicant = exports.isMultiplePersonApplicantBorrowers = void 0;
4
+ const application_paths_1 = require("@lendi/act-eac-integrations-protocol/lib/utils/application-paths");
5
+ const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
6
+ const lodash_1 = require("lodash");
7
+ const public_applicant_1 = require("../types/events/public-applicant");
8
+ /**
9
+ * Checks if there are more than one person applicants with applicant type borrower
10
+ *
11
+ * @param {PersonApplicants[]} personApplicants - Person applicants on the deep merged application
12
+ * @returns {boolean} - Whether or not there are more than one applicant with applicant type borrower
13
+ */
14
+ const isMultiplePersonApplicantBorrowers = (personApplicants) => {
15
+ const totalBorrowerApplicants = personApplicants.filter((applicant) => applicant['@ApplicantType'] === lixi_internal_request_1.ApplicantTypeList.Borrower).length;
16
+ return totalBorrowerApplicants > 1;
17
+ };
18
+ exports.isMultiplePersonApplicantBorrowers = isMultiplePersonApplicantBorrowers;
19
+ /**
20
+ * Updates the primary applicant of the application based on the new primary applicant id
21
+ *
22
+ * @param {string} newPrimaryApplicantId - New primary applicant id
23
+ * @param {PersonApplicant[]} personApplicants - Person applicants from the updated application after deep merge
24
+ * @returns {PersonApplicant[]} - Updated person applicants
25
+ */
26
+ const updatePrimaryApplicant = (newPrimaryApplicantId, personApplicants) => personApplicants.map((applicant) => (Object.assign(Object.assign({}, applicant), { ['@PrimaryApplicant']: applicant['@UniqueID'] === newPrimaryApplicantId ? lixi_internal_request_1.YesNoList.Yes : lixi_internal_request_1.YesNoList.No })));
27
+ exports.updatePrimaryApplicant = updatePrimaryApplicant;
28
+ /**
29
+ * Updates the primary applicant on the application based on the data in the guarantor applicant event
30
+ *
31
+ * @param {PartialApplication} application - Application after deep merge
32
+ * @param {Payload} applicantPayload - Public applicant event payload
33
+ * @returns {PartialApplication} - Updated application
34
+ */
35
+ const updatePrimaryApplicantUsingGuarantor = (application, applicantPayload) => {
36
+ var _a;
37
+ const updatedApplication = application, personApplicants = (0, lodash_1.get)(application, application_paths_1.paths.PersonApplicants, []);
38
+ // Checks if there are more than one borrower in the application and that the applicant type of the applicant event being processed is GUARANTOR
39
+ if ((0, exports.isMultiplePersonApplicantBorrowers)(personApplicants) &&
40
+ applicantPayload.applicantType === public_applicant_1.ApplicantType.Guarantor &&
41
+ ((_a = applicantPayload.guarantorRelationshipToBorrower) === null || _a === void 0 ? void 0 : _a.applicantId)) {
42
+ (0, lodash_1.set)(updatedApplication, application_paths_1.paths.PersonApplicants, (0, exports.updatePrimaryApplicant)(applicantPayload.guarantorRelationshipToBorrower.applicantId, personApplicants));
43
+ }
44
+ return updatedApplication;
45
+ };
46
+ exports.default = updatePrimaryApplicantUsingGuarantor;