@lendi/act-credit-decisions-transform 1.9.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 +8 -0
  43. package/lib/transform-events/transform-employment.js +106 -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 +78 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * A set of tools for manipulating addresses in LIXI applications.
3
+ */
4
+ import { AddressType, CurrentAddress, PreviousAddress } from '@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request';
5
+ import { Address, CommonAddressProperties, Countries, PreviousAddress as InternalPreviousAddress } from '../types/events/public-applicant';
6
+ /**
7
+ * Type definition for functions used to transform types while mapping from event values to LIXI values.
8
+ */
9
+ export type MappingTransformFunction<I = any, O = any> = (input: I) => O;
10
+ /**
11
+ * Specifies the destination path of the object in dot notation along with an optional data transform function.
12
+ */
13
+ export interface MappedTransform {
14
+ /**
15
+ * A path in dot notation.
16
+ */
17
+ path: string;
18
+ /**
19
+ * An optional transform function for the value to be stored at the path.
20
+ */
21
+ transform?: MappingTransformFunction;
22
+ }
23
+ /**
24
+ * A type defining a record set of path mapped transforms
25
+ */
26
+ export type PathMappedTransform = Record<string, MappedTransform>;
27
+ export declare const lixiContactAddressMapping: PathMappedTransform;
28
+ export declare const australianStates: string[];
29
+ /**
30
+ * The transform map used for the LIXI address
31
+ */
32
+ export declare const lixiAddressMapping: PathMappedTransform;
33
+ /**
34
+ * Transforms a source object by applying a PathMappedTransform.
35
+ *
36
+ * @param source A source object to be mapped and transformed
37
+ * @param pathMappedTransform A PathMappedTransform to be applied to the source
38
+ */
39
+ export declare function mapTransform<T>(source: any, pathMappedTransform: PathMappedTransform): T;
40
+ type EventAddressType = InternalPreviousAddress | CommonAddressProperties;
41
+ export type LixiContactAddressType = CurrentAddress | PreviousAddress;
42
+ export interface AddressTransformedType {
43
+ lixiAddress: AddressType;
44
+ lixiContactAddress: LixiContactAddressType;
45
+ }
46
+ /**
47
+ * Converts an address object from an event model to a LIXI address and corresponding LIXI contact address object.
48
+ *
49
+ * @param eventAddress
50
+ * @param addressId
51
+ */
52
+ export declare function rebuildAddress(eventAddress: EventAddressType, addressId: string): AddressTransformedType;
53
+ /**
54
+ * Converts a previous address object from an event model to a LIXI address and corresponding LIXI current address object.
55
+ *
56
+ * @param eventPreviousAddresses
57
+ * @param addressId
58
+ */
59
+ export declare function rebuildPreviousAddress(eventPreviousAddresses: InternalPreviousAddress[], addressId: string): AddressTransformedType;
60
+ /**
61
+ * Checks if an event is missing country.
62
+ *
63
+ * @param addressEvent
64
+ */
65
+ export declare function isMissingCountry(addressEvent: EventAddressType): boolean;
66
+ /**
67
+ * Sets the country from the last item on the formatted address.
68
+ *
69
+ * @param address
70
+ */
71
+ export declare function setCountry(address: EventAddressType): EventAddressType;
72
+ /**
73
+ * @description Extract a country from a formatted address.
74
+ * @param {string} formatted - A formatted Address.
75
+ * @returns {Countries} The country extracted from the Address.
76
+ */
77
+ export declare function extractCountryFromFormatted(formatted?: string): Countries;
78
+ /**
79
+ * @description If the address has an overseas country or state, it returns true, defaults to false if no country and state found.
80
+ * @param {Address} address - Asset Address
81
+ * @returns {boolean} - Returns true if overseas address.
82
+ */
83
+ export declare function isOverseasAddress({ country, formatted, state }?: Address): boolean;
84
+ export {};
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /**
3
+ * A set of tools for manipulating addresses in LIXI applications.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isOverseasAddress = exports.extractCountryFromFormatted = exports.setCountry = exports.isMissingCountry = exports.rebuildPreviousAddress = exports.rebuildAddress = exports.mapTransform = exports.lixiAddressMapping = exports.australianStates = exports.lixiContactAddressMapping = void 0;
7
+ const lixi_internal_request_1 = require("@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request");
8
+ const lodash_1 = require("lodash");
9
+ const country_code_1 = require("../types/enum-mappings/country-code");
10
+ const housing_status_1 = require("../types/enum-mappings/housing-status");
11
+ const public_applicant_1 = require("../types/events/public-applicant");
12
+ const generate_address_1 = require("./generate-address");
13
+ exports.lixiContactAddressMapping = {
14
+ externalId: {
15
+ path: '@x_ResidentialAddress',
16
+ },
17
+ housingStatus: {
18
+ path: '@HousingStatus',
19
+ transform: (value) => housing_status_1.housingStatusMapping[value],
20
+ },
21
+ startDate: {
22
+ path: '@StartDate',
23
+ },
24
+ endDate: {
25
+ path: '@EndDate',
26
+ },
27
+ };
28
+ exports.australianStates = Object.values(lixi_internal_request_1.AuStateList);
29
+ /**
30
+ * The transform map used for the LIXI address
31
+ */
32
+ exports.lixiAddressMapping = {
33
+ externalId: {
34
+ path: '@UniqueID',
35
+ },
36
+ 'residentialAddress.city': {
37
+ path: '@Suburb',
38
+ },
39
+ 'residentialAddress.country': {
40
+ path: '@Country',
41
+ transform: (value) => country_code_1.countryCodeMapping[value],
42
+ },
43
+ 'residentialAddress.postcode': {
44
+ path: '@AustralianPostCode',
45
+ },
46
+ 'residentialAddress.state': {
47
+ path: '@AustralianState',
48
+ },
49
+ 'residentialAddress.standard.level': {
50
+ path: 'Standard.@Level',
51
+ },
52
+ 'residentialAddress.standard.streetName': {
53
+ path: 'Standard.@StreetName',
54
+ },
55
+ 'residentialAddress.standard.streetNumber': {
56
+ path: 'Standard.@StreetNumber',
57
+ transform: (value) => value.substring(0, generate_address_1.StreetNumberMaxLength),
58
+ },
59
+ 'residentialAddress.standard.streetType': {
60
+ path: 'Standard.@StreetType',
61
+ },
62
+ 'residentialAddress.standard.unit': {
63
+ path: 'Standard.@Unit',
64
+ },
65
+ };
66
+ /**
67
+ * Transforms a source object by applying a PathMappedTransform.
68
+ *
69
+ * @param source A source object to be mapped and transformed
70
+ * @param pathMappedTransform A PathMappedTransform to be applied to the source
71
+ */
72
+ function mapTransform(source, pathMappedTransform) {
73
+ const finalTransform = {};
74
+ Object.entries(pathMappedTransform).forEach(([key, { transform, path }]) => {
75
+ const sourceValue = (0, lodash_1.get)(source, key);
76
+ if (sourceValue) {
77
+ (0, lodash_1.set)(finalTransform, path, (transform === null || transform === void 0 ? void 0 : transform(sourceValue)) || sourceValue);
78
+ }
79
+ });
80
+ return finalTransform;
81
+ }
82
+ exports.mapTransform = mapTransform;
83
+ const postcodePathString = 'residentialAddress.postcode';
84
+ const statePathString = 'residentialAddress.state';
85
+ /**
86
+ * Converts an address object from an event model to a LIXI address and corresponding LIXI contact address object.
87
+ *
88
+ * @param eventAddress
89
+ * @param addressId
90
+ */
91
+ function rebuildAddress(eventAddress, addressId) {
92
+ if (isMissingCountry(eventAddress)) {
93
+ setCountry(eventAddress);
94
+ }
95
+ if ((0, lodash_1.get)(eventAddress, 'residentialAddress.country') !== public_applicant_1.Countries.Australia) {
96
+ exports.lixiAddressMapping[postcodePathString] = { path: '@OverseasPostCode' };
97
+ exports.lixiAddressMapping[statePathString] = { path: '@OverseasState' };
98
+ }
99
+ else {
100
+ exports.lixiAddressMapping[postcodePathString] = { path: '@AustralianPostCode' };
101
+ exports.lixiAddressMapping[statePathString] = { path: '@AustralianState' };
102
+ }
103
+ const lixiAddress = mapTransform(eventAddress, exports.lixiAddressMapping);
104
+ const lixiContactAddress = mapTransform(eventAddress, exports.lixiContactAddressMapping);
105
+ lixiAddress['@UniqueID'] = addressId;
106
+ lixiContactAddress['@x_ResidentialAddress'] = addressId;
107
+ return { lixiAddress, lixiContactAddress };
108
+ }
109
+ exports.rebuildAddress = rebuildAddress;
110
+ /**
111
+ * Converts a previous address object from an event model to a LIXI address and corresponding LIXI current address object.
112
+ *
113
+ * @param eventPreviousAddresses
114
+ * @param addressId
115
+ */
116
+ function rebuildPreviousAddress(eventPreviousAddresses = [], addressId) {
117
+ if (eventPreviousAddresses.length === 0)
118
+ return null;
119
+ const previousAddress = eventPreviousAddresses.sort((lhs, rhs) => lhs.endDate.localeCompare(rhs.endDate)).pop();
120
+ return rebuildAddress(previousAddress, addressId);
121
+ }
122
+ exports.rebuildPreviousAddress = rebuildPreviousAddress;
123
+ /**
124
+ * Checks if an event is missing country.
125
+ *
126
+ * @param addressEvent
127
+ */
128
+ function isMissingCountry(addressEvent) {
129
+ if (addressEvent.residentialAddress && addressEvent.residentialAddress.formatted) {
130
+ return !(0, lodash_1.get)(addressEvent, 'residentialAddress.country');
131
+ }
132
+ return false;
133
+ }
134
+ exports.isMissingCountry = isMissingCountry;
135
+ /**
136
+ * Sets the country from the last item on the formatted address.
137
+ *
138
+ * @param address
139
+ */
140
+ function setCountry(address) {
141
+ const formatted = (0, lodash_1.get)(address, 'residentialAddress.formatted');
142
+ if (formatted && !address.residentialAddress.country) {
143
+ address.residentialAddress.country = extractCountryFromFormatted(formatted);
144
+ }
145
+ return address;
146
+ }
147
+ exports.setCountry = setCountry;
148
+ /**
149
+ * @description Extract a country from a formatted address.
150
+ * @param {string} formatted - A formatted Address.
151
+ * @returns {Countries} The country extracted from the Address.
152
+ */
153
+ function extractCountryFromFormatted(formatted = '') {
154
+ var _a;
155
+ return (_a = formatted === null || formatted === void 0 ? void 0 : formatted.split(',').pop()) === null || _a === void 0 ? void 0 : _a.trim();
156
+ }
157
+ exports.extractCountryFromFormatted = extractCountryFromFormatted;
158
+ /**
159
+ * @description If the address has an overseas country or state, it returns true, defaults to false if no country and state found.
160
+ * @param {Address} address - Asset Address
161
+ * @returns {boolean} - Returns true if overseas address.
162
+ */
163
+ function isOverseasAddress({ country, formatted, state } = {}) {
164
+ if (country) {
165
+ return country !== public_applicant_1.Countries.Australia;
166
+ }
167
+ if (formatted) {
168
+ const lastPast = extractCountryFromFormatted(formatted);
169
+ return lastPast !== public_applicant_1.Countries.Australia;
170
+ }
171
+ if (state) {
172
+ return !exports.australianStates.includes(state);
173
+ }
174
+ return false;
175
+ }
176
+ exports.isOverseasAddress = isOverseasAddress;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Recursively removes nulls from nested objects and arrays
3
+ *
4
+ * @param payload any
5
+ * @returns result of sanitised object.
6
+ */
7
+ export declare function cleanUp<T>(payload: T): Partial<T>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanUp = void 0;
4
+ /* istanbul ignore file */
5
+ const clean_deep_1 = require("clean-deep");
6
+ /**
7
+ * Recursively removes nulls from nested objects and arrays
8
+ *
9
+ * @param payload any
10
+ * @returns result of sanitised object.
11
+ */
12
+ function cleanUp(payload) {
13
+ // cleanDeep configurations.
14
+ const params = {
15
+ cleanValues: [],
16
+ emptyArrays: true,
17
+ emptyObjects: true,
18
+ emptyStrings: false,
19
+ nullValues: true,
20
+ undefinedValues: true,
21
+ };
22
+ return (0, clean_deep_1.default)(payload, params);
23
+ }
24
+ exports.cleanUp = cleanUp;
@@ -0,0 +1,28 @@
1
+ export declare enum ErrorType {
2
+ ApplicationNotFound = "ApplicationNotFound",
3
+ BaseError = "BaseError",
4
+ DatabaseConditionalWriteError = "DatabaseConditionalWriteError",
5
+ DatabaseError = "DatabaseError",
6
+ Errors = "Errors",
7
+ InternalError = "InternalError",
8
+ InvalidApplication = "InvalidApplication",
9
+ InvalidEvent = "InvalidEvent",
10
+ InvalidEventNoApplicationId = "InvalidEventNoApplicationId",
11
+ InvalidEventNotCritical = "InvalidEventNotCritical",
12
+ OwnershipOutOfBounds = "OwnershipOutOfBounds",
13
+ ResourceNotFound = "ResourceNotFound"
14
+ }
15
+ export declare class BaseError extends Error {
16
+ origin: string;
17
+ path: string[];
18
+ type: ErrorType;
19
+ context: object;
20
+ constructor(message: string, path: string[], origin: string, context?: object);
21
+ }
22
+ /**
23
+ * InvalidEvent occurs when an incorrect/damaged event has been consumed and
24
+ * found to be invalid against its related schema.
25
+ */
26
+ export declare class InvalidEvent extends BaseError {
27
+ constructor(message: string, path?: string[], origin?: string, context?: object);
28
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidEvent = exports.BaseError = exports.ErrorType = void 0;
4
+ var ErrorType;
5
+ (function (ErrorType) {
6
+ ErrorType["ApplicationNotFound"] = "ApplicationNotFound";
7
+ ErrorType["BaseError"] = "BaseError";
8
+ ErrorType["DatabaseConditionalWriteError"] = "DatabaseConditionalWriteError";
9
+ ErrorType["DatabaseError"] = "DatabaseError";
10
+ ErrorType["Errors"] = "Errors";
11
+ ErrorType["InternalError"] = "InternalError";
12
+ ErrorType["InvalidApplication"] = "InvalidApplication";
13
+ ErrorType["InvalidEvent"] = "InvalidEvent";
14
+ ErrorType["InvalidEventNoApplicationId"] = "InvalidEventNoApplicationId";
15
+ ErrorType["InvalidEventNotCritical"] = "InvalidEventNotCritical";
16
+ ErrorType["OwnershipOutOfBounds"] = "OwnershipOutOfBounds";
17
+ ErrorType["ResourceNotFound"] = "ResourceNotFound";
18
+ })(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
19
+ class BaseError extends Error {
20
+ /* istanbul ignore next */
21
+ constructor(message, path = [], origin, context = {}) {
22
+ super(message);
23
+ Object.setPrototypeOf(this, BaseError.prototype);
24
+ this.type = ErrorType.BaseError;
25
+ this.path = path;
26
+ this.origin = origin;
27
+ this.context = context;
28
+ }
29
+ }
30
+ exports.BaseError = BaseError;
31
+ /**
32
+ * InvalidEvent occurs when an incorrect/damaged event has been consumed and
33
+ * found to be invalid against its related schema.
34
+ */
35
+ class InvalidEvent extends BaseError {
36
+ /* istanbul ignore next */
37
+ constructor(message, path, origin, context) {
38
+ super(message, path, origin, context);
39
+ Object.setPrototypeOf(this, InvalidEvent.prototype);
40
+ this.type = ErrorType.InvalidEvent;
41
+ }
42
+ }
43
+ exports.InvalidEvent = InvalidEvent;
@@ -0,0 +1,8 @@
1
+ import { YesNoList } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
2
+ /**
3
+ * Formats a value as Yes or No
4
+ *
5
+ * @param isTruthy Some value to be formatted as Yes/No
6
+ * @returns Yes/No
7
+ */
8
+ export declare const formatYesNo: (isTruthy: any) => YesNoList;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatYesNo = void 0;
4
+ const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
5
+ /**
6
+ * Formats a value as Yes or No
7
+ *
8
+ * @param isTruthy Some value to be formatted as Yes/No
9
+ * @returns Yes/No
10
+ */
11
+ const formatYesNo = (isTruthy) => (isTruthy ? lixi_internal_request_1.YesNoList.Yes : lixi_internal_request_1.YesNoList.No);
12
+ exports.formatYesNo = formatYesNo;
@@ -0,0 +1,19 @@
1
+ import { AddressType, Standard, StreetTypeList } from '@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request';
2
+ import { Address, AddressStandard } from '../types/events/public-asset';
3
+ export declare const StreetNumberMaxLength = 16;
4
+ export declare const StreetTypeArray: StreetTypeList[];
5
+ /**
6
+ * Generates an address for an asset.
7
+ *
8
+ * @param {Address} address - An address object.
9
+ * @param {string} id - Id of asset object.
10
+ * @returns {Partial<AddressType>} A transformed address object.
11
+ */
12
+ export declare function generateAddress(address: Address, id: string): Partial<AddressType>;
13
+ /**
14
+ * Generates an address standard.
15
+ *
16
+ * @param addressStandard An address standard object.
17
+ * @returns A transformed standard object.
18
+ */
19
+ export declare function generateStandard(addressStandard: AddressStandard): Standard;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStandard = exports.generateAddress = exports.StreetTypeArray = exports.StreetNumberMaxLength = void 0;
4
+ const lixi_internal_request_1 = require("@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request");
5
+ const lodash_1 = require("lodash");
6
+ const country_code_1 = require("..//types/enum-mappings/country-code");
7
+ const postcode_1 = require("../types/enum-mappings/postcode");
8
+ const public_asset_1 = require("../types/events/public-asset");
9
+ const address_tools_1 = require("./address-tools");
10
+ exports.StreetNumberMaxLength = 16;
11
+ exports.StreetTypeArray = Object.values(lixi_internal_request_1.StreetTypeList);
12
+ const addressMapping = {
13
+ country: '@Country',
14
+ city: '@Suburb',
15
+ postcode: '@AustralianPostCode',
16
+ state: '@AustralianState',
17
+ standard: 'Standard',
18
+ };
19
+ const standardMapping = {
20
+ streetName: '@StreetName',
21
+ streetType: '@StreetType',
22
+ streetNumber: '@StreetNumber',
23
+ level: '@Level',
24
+ unit: '@Unit',
25
+ };
26
+ /**
27
+ * Generates an address for an asset.
28
+ *
29
+ * @param {Address} address - An address object.
30
+ * @param {string} id - Id of asset object.
31
+ * @returns {Partial<AddressType>} A transformed address object.
32
+ */
33
+ function generateAddress(address, id) {
34
+ const transformedAddress = {
35
+ '@Country': lixi_internal_request_1.CountryCodeList.Au,
36
+ '@UniqueID': id,
37
+ };
38
+ const country = (0, address_tools_1.extractCountryFromFormatted)(address.formatted);
39
+ if (!address.country && country.length > 0) {
40
+ address.country = country;
41
+ }
42
+ if (address.country && address.country !== public_asset_1.Countries.Australia) {
43
+ addressMapping.postcode = '@OverseasPostCode';
44
+ addressMapping.state = '@OverseasState';
45
+ }
46
+ else {
47
+ addressMapping.postcode = '@AustralianPostCode';
48
+ addressMapping.state = '@AustralianState';
49
+ if (!address.postcode && address.state) {
50
+ transformedAddress['@AustralianPostCode'] = postcode_1.postcodeMapping[address.state];
51
+ }
52
+ }
53
+ for (const [key, value] of Object.entries(address)) {
54
+ if (addressMapping[key]) {
55
+ switch (key) {
56
+ case 'standard':
57
+ (0, lodash_1.set)(transformedAddress, addressMapping[key], generateStandard(value));
58
+ break;
59
+ case 'country':
60
+ (0, lodash_1.set)(transformedAddress, addressMapping[key], country_code_1.countryCodeMapping[value]);
61
+ break;
62
+ default:
63
+ (0, lodash_1.set)(transformedAddress, addressMapping[key], value);
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ return transformedAddress;
69
+ }
70
+ exports.generateAddress = generateAddress;
71
+ /**
72
+ * Generates an address standard.
73
+ *
74
+ * @param addressStandard An address standard object.
75
+ * @returns A transformed standard object.
76
+ */
77
+ function generateStandard(addressStandard) {
78
+ const transformedStandard = {};
79
+ for (const [key, value] of Object.entries(addressStandard)) {
80
+ if (standardMapping[key]) {
81
+ switch (key) {
82
+ case 'streetNumber':
83
+ (0, lodash_1.set)(transformedStandard, standardMapping[key], value.substring(0, exports.StreetNumberMaxLength));
84
+ break;
85
+ case 'streetType':
86
+ const streetType = exports.StreetTypeArray.find((type) => type.toLowerCase() === value.toLowerCase());
87
+ (0, lodash_1.set)(transformedStandard, standardMapping[key], streetType || lixi_internal_request_1.StreetTypeList.Street);
88
+ break;
89
+ default:
90
+ (0, lodash_1.set)(transformedStandard, standardMapping[key], value);
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ return transformedStandard;
96
+ }
97
+ exports.generateStandard = generateStandard;
@@ -0,0 +1,8 @@
1
+ import { FinancialInstitutionList } from '@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request';
2
+ /**
3
+ * Returns the financialInstitution value form the Enum based on the index where it was found.
4
+ *
5
+ * @param institution: Institution value from event.
6
+ * @param institution
7
+ */
8
+ export declare function getFinancialInstitution(institution: string): FinancialInstitutionList;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFinancialInstitution = void 0;
4
+ const lixi_internal_request_1 = require("@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request");
5
+ const financialInstitutions = Object.values(lixi_internal_request_1.FinancialInstitutionList);
6
+ /**
7
+ * Returns the financialInstitution value form the Enum based on the index where it was found.
8
+ *
9
+ * @param institution: Institution value from event.
10
+ * @param institution
11
+ */
12
+ function getFinancialInstitution(institution) {
13
+ const institutionUpperCased = institution.toUpperCase();
14
+ const financialInstitution = financialInstitutions.find((item) => item.toUpperCase() === institutionUpperCased);
15
+ return financialInstitution || lixi_internal_request_1.FinancialInstitutionList.Other;
16
+ }
17
+ exports.getFinancialInstitution = getFinancialInstitution;
@@ -0,0 +1,25 @@
1
+ import { Asset } from '../types/events/public-asset';
2
+ /**
3
+ * @description Checks if the asset is of financial type.
4
+ * @param {Asset} asset asset payload.
5
+ * @returns {boolean} returns true if asset is a financial asset.
6
+ */
7
+ export declare function isFinancialAsset(asset: Asset): boolean;
8
+ /**
9
+ * @description Is Asset a Real Estate Asset.
10
+ * @param {Asset} asset An Asset.
11
+ * @returns {boolean} returns true if Asset is a Real Estate Asset.
12
+ */
13
+ export declare function isRealEstateAsset(asset: Asset): boolean;
14
+ /**
15
+ * @description Is Asset a Motor Vehicle.
16
+ * @param {Asset} asset An Asset.
17
+ * @returns {boolean} returns true if an Asset is a vehicle.
18
+ */
19
+ export declare function isMotorVehicle(asset: Asset): boolean;
20
+ /**
21
+ * @description Is Asset of LIXI type `OtherAsset`.
22
+ * @param {Asset} asset An Asset.
23
+ * @returns {boolean} returns true if asset is `OtherAsset`.
24
+ */
25
+ export declare function isOtherAsset(asset: Asset): boolean;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOtherAsset = exports.isMotorVehicle = exports.isRealEstateAsset = exports.isFinancialAsset = void 0;
4
+ const public_asset_1 = require("../types/events/public-asset");
5
+ /**
6
+ * @description Checks if the asset is of financial type.
7
+ * @param {Asset} asset asset payload.
8
+ * @returns {boolean} returns true if asset is a financial asset.
9
+ */
10
+ function isFinancialAsset(asset) {
11
+ return [
12
+ public_asset_1.AssetType.Shares,
13
+ public_asset_1.AssetType.Superannuation,
14
+ public_asset_1.AssetType.TermDeposit,
15
+ public_asset_1.AssetType.SavingCheckAccount,
16
+ public_asset_1.AssetType.ManagedFunds,
17
+ ].includes(asset.type);
18
+ }
19
+ exports.isFinancialAsset = isFinancialAsset;
20
+ /**
21
+ * @description Is Asset a Real Estate Asset.
22
+ * @param {Asset} asset An Asset.
23
+ * @returns {boolean} returns true if Asset is a Real Estate Asset.
24
+ */
25
+ function isRealEstateAsset(asset) {
26
+ return asset.type === public_asset_1.AssetType.Property;
27
+ }
28
+ exports.isRealEstateAsset = isRealEstateAsset;
29
+ /**
30
+ * @description Is Asset a Motor Vehicle.
31
+ * @param {Asset} asset An Asset.
32
+ * @returns {boolean} returns true if an Asset is a vehicle.
33
+ */
34
+ function isMotorVehicle(asset) {
35
+ return asset.type === public_asset_1.AssetType.Vehicle;
36
+ }
37
+ exports.isMotorVehicle = isMotorVehicle;
38
+ /**
39
+ * @description Is Asset of LIXI type `OtherAsset`.
40
+ * @param {Asset} asset An Asset.
41
+ * @returns {boolean} returns true if asset is `OtherAsset`.
42
+ */
43
+ function isOtherAsset(asset) {
44
+ return [public_asset_1.AssetType.HomeContents, public_asset_1.AssetType.Gifts, public_asset_1.AssetType.OtherAsset].includes(asset.type);
45
+ }
46
+ exports.isOtherAsset = isOtherAsset;