@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,138 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Opportunity",
4
+ "description": "The Opportunity object in Salesforce",
5
+ "type": "object",
6
+ "properties": {
7
+ "version": {
8
+ "type": "string",
9
+ "description": "schema version"
10
+ },
11
+ "type": {
12
+ "type": "string",
13
+ "enum": ["OpportunityCreated", "OpportunityUpdated", "OpportunityMigrated"]
14
+ },
15
+ "payload": {
16
+ "$ref": "#/definitions/opportunity"
17
+ }
18
+ },
19
+ "required": ["version", "type", "payload"],
20
+ "additionalProperties": false,
21
+ "definitions": {
22
+ "opportunity": {
23
+ "type": "object",
24
+ "additionalProperties": true,
25
+ "properties": {
26
+ "areYouAFirstHomeBuyer": {
27
+ "type": ["string", "null"],
28
+ "maxLength": 255
29
+ },
30
+ "brand": {
31
+ "enum": ["domain", "domain variation", "lendi", "lendi variation"],
32
+ "description": "Brand of an Opportunity, taken from Record Type in Salesforce"
33
+ },
34
+ "cashoutAmount": {
35
+ "type": ["number", "null"],
36
+ "description": "From Funnel"
37
+ },
38
+ "customerId": {
39
+ "type": ["string", "null"],
40
+ "maxLength": 255
41
+ },
42
+ "deposit": {
43
+ "type": ["number", "null"],
44
+ "description": "From Funnel"
45
+ },
46
+ "expectedSettlementDate": {
47
+ "type": ["string", "null"],
48
+ "format": "date",
49
+ "description": "From funnel, ISO 8601 string date format"
50
+ },
51
+ "factorsInChoosingALender": {
52
+ "type": ["string", "null"],
53
+ "maxLength": 255,
54
+ "description": "From Funnel"
55
+ },
56
+ "id": {
57
+ "type": ["string"],
58
+ "maxLength": 255,
59
+ "description": "The unique identifier of the Opportunity"
60
+ },
61
+ "isHidden": {
62
+ "type": "boolean",
63
+ "description": "When checked the Application is hidden from view"
64
+ },
65
+ "loanAmount": {
66
+ "type": ["number", "null"]
67
+ },
68
+ "name": {
69
+ "type": ["string", "null"],
70
+ "maxLength": 120
71
+ },
72
+ "preferredRepaymentMethod": {
73
+ "type": ["string", "null"],
74
+ "maxLength": 255
75
+ },
76
+ "stage": {
77
+ "type": "string",
78
+ "maxLength": 255,
79
+ "description": "Opportunity Stage Name",
80
+ "enum": [
81
+ "Application Taken",
82
+ "Appointed",
83
+ "Approval",
84
+ "Approved",
85
+ "At Risk",
86
+ "CL Future Contact Date",
87
+ "Closed Lost",
88
+ "Closed Won - Policy Active",
89
+ "Closed Won - Signed",
90
+ "Closed Won",
91
+ "Confirmed Appointment",
92
+ "In Application",
93
+ "In Assessment",
94
+ "Loan Document",
95
+ "Post-Contact",
96
+ "Post-Settlement",
97
+ "Pre-Contact",
98
+ "Qualification",
99
+ "Quote",
100
+ "Settled",
101
+ "Settlement",
102
+ "Submitted"
103
+ ]
104
+ },
105
+ "status": {
106
+ "type": ["string", "null"],
107
+ "maxLength": 255,
108
+ "description": "Opportunity status. Can be null when this field is empty/not set on new and closed opportunities"
109
+ },
110
+ "transactionType": {
111
+ "type": ["string"],
112
+ "maxLength": 255
113
+ },
114
+ "userId": {
115
+ "type": ["string", "null"],
116
+ "maxLength": 255
117
+ },
118
+ "whyAreYouRefinancing": {
119
+ "type": ["string", "null"],
120
+ "maxLength": 255,
121
+ "description": "From Funnel"
122
+ }
123
+ },
124
+ "required": ["id", "stage", "userId"]
125
+ },
126
+ "opportunityDeleted": {
127
+ "type": "object",
128
+ "additionalProperties": false,
129
+ "properties": {
130
+ "id": {
131
+ "type": ["string"],
132
+ "maxLength": 255,
133
+ "description": "The unique identifier of the Opportunity"
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
@@ -0,0 +1,10 @@
1
+ import { AssetAndLiabilityRelation } from '../types/events/public-asset-liability-relation';
2
+ /**
3
+ * Generates a partial application from the partial asset and liability event.
4
+ *
5
+ * @param assetLiabilityLink: A partial asset and liability event.
6
+ * @param assetLiabilityLink:.applicationId
7
+ * @param assetLiabilityLink:.relation
8
+ * @returns partialApplication: A partial internal request.
9
+ */
10
+ export declare function generateAssetLiabilityLink({ applicationId, relation }: AssetAndLiabilityRelation): {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateAssetLiabilityLink = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const application_paths_1 = require("@lendi/act-eac-integrations-protocol/lib/utils/application-paths");
6
+ /**
7
+ * Generates a partial application from the partial asset and liability event.
8
+ *
9
+ * @param assetLiabilityLink: A partial asset and liability event.
10
+ * @param assetLiabilityLink:.applicationId
11
+ * @param assetLiabilityLink:.relation
12
+ * @returns partialApplication: A partial internal request.
13
+ */
14
+ function generateAssetLiabilityLink({ applicationId, relation }) {
15
+ const partialApplication = {};
16
+ const assetLiabilityMapping = {
17
+ applicationId: application_paths_1.paths.ApplicationId,
18
+ liabilityId: `${application_paths_1.paths.Liability}.@UniqueID`,
19
+ assetId: `${application_paths_1.paths.Liability}.Security[0].@x_Security`,
20
+ };
21
+ (0, lodash_1.set)(partialApplication, assetLiabilityMapping.applicationId, applicationId);
22
+ for (const [key, value] of Object.entries(relation)) {
23
+ if (assetLiabilityMapping[key]) {
24
+ (0, lodash_1.set)(partialApplication, assetLiabilityMapping[key], value);
25
+ }
26
+ }
27
+ return partialApplication;
28
+ }
29
+ exports.generateAssetLiabilityLink = generateAssetLiabilityLink;
@@ -0,0 +1,8 @@
1
+ import { PayloadObject as CreditReportPayload } from '../types/events/credit-report-retrieved';
2
+ /**
3
+ * Generates LIXI compliant `Attachment` and `CreditAssessment` objects which
4
+ * use credit report data fetched from Equifax.
5
+ *
6
+ * @param {CreditReportPayload} creditReport - Credit report rebuilt event.
7
+ */
8
+ export declare function generateCreditReportRebuilt(creditReport: CreditReportPayload): {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCreditReportRebuilt = 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 application_paths_1 = require("@lendi/act-eac-integrations-protocol/lib/utils/application-paths");
7
+ /**
8
+ * Generates LIXI compliant `Attachment` and `CreditAssessment` objects which
9
+ * use credit report data fetched from Equifax.
10
+ *
11
+ * @param {CreditReportPayload} creditReport - Credit report rebuilt event.
12
+ */
13
+ function generateCreditReportRebuilt(creditReport) {
14
+ const { applicantId, raw, source } = creditReport;
15
+ const id = `${applicantId}-creditReport`;
16
+ const attachment = {
17
+ '@Filename': 'Credit Report',
18
+ '@UniqueID': id,
19
+ InlineAttachment: {
20
+ $: raw,
21
+ },
22
+ };
23
+ const report = {
24
+ '@RequestDateTime': new Date().toISOString(),
25
+ '@Source': source,
26
+ '@x_Party': applicantId,
27
+ Content: [
28
+ {
29
+ '@Type': lixi_internal_request_1.ReportContentTypeList.XML,
30
+ '@x_Attachment': id,
31
+ },
32
+ ],
33
+ };
34
+ const partialApplication = {};
35
+ // Set application id, attachment and credit assessment report.
36
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, creditReport.applicationId);
37
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.Attachment, [attachment]);
38
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.Report, [report]);
39
+ return partialApplication;
40
+ }
41
+ exports.generateCreditReportRebuilt = generateCreditReportRebuilt;
@@ -0,0 +1,8 @@
1
+ import { YesNoList } from '@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request';
2
+ import { Payload as ApplicantPayload } from '../types/events/public-applicant';
3
+ export declare const booleanMapping: (input?: boolean) => YesNoList;
4
+ /**
5
+ *
6
+ * @param applicant
7
+ */
8
+ export declare function transformApplicant(applicant: ApplicantPayload): import("../types/recursive-partial").RecursivePartial<import("@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request").InternalRequest>;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformApplicant = exports.booleanMapping = void 0;
4
+ const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
5
+ const lixi_internal_request_2 = require("@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request");
6
+ const application_paths_1 = require("@lendi/act-eac-integrations-protocol/lib/utils/application-paths");
7
+ const application_paths_2 = require("@lendi/integrations-credit-protocol/utils/application-paths");
8
+ const lodash_1 = require("lodash");
9
+ const enum_mappings_1 = require("../types/enum-mappings");
10
+ const applicant_gender_1 = require("../types/enum-mappings/applicant-gender");
11
+ const applicant_type_1 = require("../types/enum-mappings/applicant-type");
12
+ const guarantor_relationship_type_1 = require("../types/enum-mappings/guarantor-relationship-type");
13
+ const trust_1 = require("../types/enum-mappings/trust");
14
+ const public_applicant_1 = require("../types/events/public-applicant");
15
+ const errors_1 = require("../utils/errors");
16
+ const normalise_date_1 = require("../utils/normalise-date");
17
+ const company_type_1 = require("../types/enum-mappings/company-type");
18
+ const company_structure_1 = require("../types/enum-mappings/company-structure");
19
+ const booleanMapping = (input = false) => (input === true ? lixi_internal_request_2.YesNoList.Yes : lixi_internal_request_2.YesNoList.No);
20
+ exports.booleanMapping = booleanMapping;
21
+ /**
22
+ *
23
+ * @param applicant
24
+ */
25
+ function transformApplicant(applicant) {
26
+ const partialApplication = {};
27
+ const applicantId = applicant.id; // This is how SF events cross reference applicant with its entities.
28
+ let applicantMapping = {
29
+ applicantType: `${application_paths_1.paths.PersonApplicant}.@ApplicantType`,
30
+ applicationId: application_paths_1.paths.ApplicationId,
31
+ citizenship: `${application_paths_1.paths.PersonApplicant}.@Citizenship`,
32
+ cityOfBirth: `${application_paths_1.paths.PersonApplicant}.@PlaceOfBirth`,
33
+ contact: 'contact',
34
+ countryOfBirth: `${application_paths_1.paths.PersonApplicant}.@CountryOfBirth`,
35
+ dateOfBirth: `${application_paths_1.paths.PersonApplicant}.@DateOfBirth`,
36
+ dependants: 'dependants',
37
+ email: `${application_paths_1.paths.PersonApplicant}.Contact.EmailAddress[0].@Email`,
38
+ firstName: `${application_paths_1.paths.PersonApplicant}.PersonName.@FirstName`,
39
+ id: `${application_paths_1.paths.PersonApplicant}.@UniqueID`,
40
+ lastName: `${application_paths_1.paths.PersonApplicant}.PersonName.@Surname`,
41
+ maritalDetails: `${application_paths_1.paths.PersonApplicant}.MaritalStatusDetails.@x_Spouse`,
42
+ maritalStatus: `${application_paths_1.paths.PersonApplicant}.@MaritalStatus`,
43
+ middleName: `${application_paths_1.paths.PersonApplicant}.PersonName.@MiddleNames`,
44
+ mothersMaidenName: `${application_paths_1.paths.PersonApplicant}.@MothersMaidenName`,
45
+ phone: `${application_paths_1.paths.PersonApplicant}.Contact.Mobile.@Number`,
46
+ residencyStatus: `${application_paths_1.paths.PersonApplicant}.@ResidencyStatus`,
47
+ title: `${application_paths_1.paths.PersonName}.@NameTitle`,
48
+ };
49
+ if (applicant.entity === public_applicant_1.Entity.Trust) {
50
+ applicantMapping = {
51
+ applicantType: `${application_paths_2.paths.TrustApplicant}.@ApplicantType`,
52
+ applicationId: application_paths_1.paths.ApplicationId,
53
+ id: `${application_paths_2.paths.TrustApplicant}.@UniqueID`,
54
+ industryCode: `${application_paths_2.paths.TrustApplicant}.Business.@IndustryCode`,
55
+ registeredAddress: `${application_paths_2.paths.TrustApplicant}.Contact.@x_RegisteredAddress`,
56
+ registeredCountry: `${application_paths_2.paths.TrustApplicant}.@CountryEstablished`,
57
+ registeredDate: `${application_paths_2.paths.TrustApplicant}.@EstablishmentDate`,
58
+ trustName: `${application_paths_2.paths.TrustApplicant}.@TrustName`,
59
+ trustType: `${application_paths_2.paths.TrustApplicant}.@TrustStructure`,
60
+ };
61
+ }
62
+ if (applicant.entity === public_applicant_1.Entity.Company) {
63
+ applicantMapping = {
64
+ id: `${application_paths_2.paths.CompanyApplicant}.@UniqueID`,
65
+ applicationId: application_paths_1.paths.ApplicationId,
66
+ applicantType: `${application_paths_2.paths.CompanyApplicant}.@ApplicantType`,
67
+ companyName: `${application_paths_2.paths.CompanyApplicant}.@CompanyName`,
68
+ companyType: `${application_paths_2.paths.CompanyApplicant}.@TypeOfIncorporation`,
69
+ companyStructure: `${application_paths_2.paths.CompanyApplicant}.@BusinessStructure`,
70
+ abn: `${application_paths_2.paths.CompanyApplicant}.@ABN`,
71
+ acn: `${application_paths_2.paths.CompanyApplicant}.@ACN`,
72
+ industryCode: `${application_paths_2.paths.CompanyApplicant}.Business.@IndustryCode`,
73
+ registeredState: `${application_paths_2.paths.CompanyApplicant}.@RegisteredInState`,
74
+ registeredDate: `${application_paths_2.paths.CompanyApplicant}.@DateRegistered`,
75
+ };
76
+ }
77
+ // Any applicant event need to have at least dateOfBirth, firstName and lastName.
78
+ if (applicant.entity === public_applicant_1.Entity.Person && !(applicant.dateOfBirth && applicant.firstName && applicant.lastName)) {
79
+ throw new errors_1.InvalidEvent('Applicant needs to have dateOfBirth, firstName and lastName');
80
+ }
81
+ // If applicant event comes without an applicantType then default it to ApplicantType.Borrower
82
+ if (!applicant.applicantType) {
83
+ applicant.applicantType = public_applicant_1.ApplicantType.Borrower;
84
+ }
85
+ if (applicant.entity === public_applicant_1.Entity.Person) {
86
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonName}.@NameTitle`, lixi_internal_request_1.NameTitleList.Other);
87
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@PrimaryApplicant`, (0, exports.booleanMapping)(applicant.isPrimaryApplicant));
88
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@FirstHomeBuyer`, (0, exports.booleanMapping)(applicant.isFirstHomeBuyer));
89
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@Gender`, applicant_gender_1.applicantGenderMapping[applicant.gender]);
90
+ }
91
+ if (applicant.entity === public_applicant_1.Entity.Person && applicant.applicantType === public_applicant_1.ApplicantType.Guarantor) {
92
+ const mappedGuarantorRelationship = applicant.guarantorRelationshipToBorrower
93
+ ? guarantor_relationship_type_1.guarantorRelationshipTypeMappings[applicant.guarantorRelationshipToBorrower.type]
94
+ : lixi_internal_request_1.KinRelationshipList.OtherRelative;
95
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@RelationshipToPrimaryApplicant`, mappedGuarantorRelationship);
96
+ }
97
+ for (const [key, value] of Object.entries(applicant)) {
98
+ if (applicantMapping[key]) {
99
+ switch (key) {
100
+ case 'applicantType':
101
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], applicant_type_1.applicantTypeMapping[value]);
102
+ break;
103
+ case 'dateOfBirth':
104
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], (0, normalise_date_1.normaliseDate)(value));
105
+ break;
106
+ case 'maritalStatus':
107
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], enum_mappings_1.maritalStatusMapping[value]);
108
+ break;
109
+ case 'residencyStatus':
110
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], enum_mappings_1.residencyStatusMapping[value]);
111
+ // Certain bank integrations require the ability to differentiate between permanentResident and Citizen
112
+ // As lixi does not have a citizen enum for residencyStatus citizen is mapped to permanentResident
113
+ // Adding a @Citizenship attribute to person applicant gives us the ability to determine citizenship status
114
+ // If citizen this field will be always added and value will be AU.
115
+ // @tsilva 21/11/19
116
+ if (value === public_applicant_1.ResidencyStatus.AustralianCitizen) {
117
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@Citizenship`, lixi_internal_request_2.CountryCodeList.Au);
118
+ }
119
+ break;
120
+ case 'countryOfBirth':
121
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@CountryOfBirth`, enum_mappings_1.countryCodeMapping[value]);
122
+ break;
123
+ case 'citizenship':
124
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@Citizenship`, enum_mappings_1.countryCodeMapping[value]);
125
+ break;
126
+ case 'title':
127
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], enum_mappings_1.titleMapping[value]);
128
+ break;
129
+ case 'trustType':
130
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], trust_1.trustTypeMapping[value]);
131
+ break;
132
+ case 'registeredCountry':
133
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], enum_mappings_1.countryCodeMapping[value]);
134
+ break;
135
+ case 'registeredAddress':
136
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], `${applicant.id}-address`);
137
+ break;
138
+ case 'maritalDetails':
139
+ const id = (0, lodash_1.get)(value, 'applicantId');
140
+ if (id)
141
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], id);
142
+ break;
143
+ case 'contact':
144
+ const emailAddress = (0, lodash_1.get)(value, 'emailAddress');
145
+ const mobileNumber = (0, lodash_1.get)(value, 'mobileNumber');
146
+ if (emailAddress) {
147
+ (0, lodash_1.set)(partialApplication, applicantMapping.email, emailAddress);
148
+ }
149
+ if (mobileNumber) {
150
+ (0, lodash_1.set)(partialApplication, applicantMapping.phone, mobileNumber.replace('+61', '0'));
151
+ }
152
+ break;
153
+ case 'dependants':
154
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Household}.@UniqueID`, `${applicant.applicationId}-household`);
155
+ const dependants = value.map((dependant) => ({
156
+ '@Age': dependant.age,
157
+ '@UniqueID': dependant.id,
158
+ FinancialProvider: [
159
+ {
160
+ '@x_Party': applicantId,
161
+ },
162
+ ],
163
+ }));
164
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Household}.Dependant`, dependants);
165
+ break;
166
+ case 'companyType':
167
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], company_type_1.companyTypeMapping[value]);
168
+ break;
169
+ case 'companyStructure':
170
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], company_structure_1.companyStructureMapping[value]);
171
+ break;
172
+ default:
173
+ (0, lodash_1.set)(partialApplication, applicantMapping[key], value);
174
+ break;
175
+ }
176
+ }
177
+ }
178
+ return partialApplication;
179
+ }
180
+ exports.transformApplicant = transformApplicant;
@@ -0,0 +1,8 @@
1
+ import { PayloadClass as ApplicationWorkflowEventPayload } from '../types/events/application-workflow';
2
+ /**
3
+ * Generates a partial application from an ApplicationWorkflow event
4
+ *
5
+ * @param applicationWorkflowEventPayload ApplicationWorkflow event payload
6
+ * @returns A partial application
7
+ */
8
+ export declare function transformApplicationWorkflow(applicationWorkflowEventPayload: ApplicationWorkflowEventPayload): {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformApplicationWorkflow = void 0;
4
+ const application_paths_1 = require("@lendi/act-eac-integrations-protocol/lib/utils/application-paths");
5
+ const lodash_1 = require("lodash");
6
+ const application_workflow_1 = require("../types/events/application-workflow");
7
+ /**
8
+ * Generates a partial application from an ApplicationWorkflow event
9
+ *
10
+ * @param applicationWorkflowEventPayload ApplicationWorkflow event payload
11
+ * @returns A partial application
12
+ */
13
+ function transformApplicationWorkflow(applicationWorkflowEventPayload) {
14
+ const { stage, applicationStage, applicationId, applicationStatus, status } = applicationWorkflowEventPayload;
15
+ const partialApplication = {};
16
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, applicationId);
17
+ // The stage being defaulted to Unknown caters for LGSF application workflow events having stage as an optional attribute in the future
18
+ const stageInstructionDetails = {
19
+ '@UniqueID': `${applicationId}-stage`,
20
+ '@Details': applicationStage || stage || 'Unknown',
21
+ };
22
+ const statusInstructionDetails = {
23
+ '@UniqueID': `${applicationId}-status`,
24
+ '@Details': applicationStatus || status || application_workflow_1.Status.Unknown,
25
+ };
26
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.Instructions, stageInstructionDetails);
27
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.InstructionsStatus, statusInstructionDetails);
28
+ return partialApplication;
29
+ }
30
+ exports.transformApplicationWorkflow = transformApplicationWorkflow;
@@ -0,0 +1,20 @@
1
+ import { Payload as ApplicationPayload } from '../types/events/public-application';
2
+ export interface TransformApplicationOptions {
3
+ uniqueIdSuffix?: string;
4
+ /**
5
+ * Enables/disables the rate lock mapping (Used to enable the mapping in AW and disable in DW simulatenously due to having to notify integrated approval confidence lenders of schema changes if the attribute is added to schema)
6
+ */
7
+ enableRateLock?: boolean;
8
+ /**
9
+ * Enables/disables the fast refi mapping (Used to enable the mapping in AW and disable in DW simulatenously due to having to notify integrated approval confidence lenders of schema changes if the attribute is added to schema)
10
+ */
11
+ enableFastRefi?: boolean;
12
+ }
13
+ /**
14
+ * Transforms a partial opportunity event to a partial internal request.
15
+ *
16
+ * @param {ApplicationPayload} opportunity Public application event payload
17
+ * @param {TransformApplicationOptions} options Options for transforming the public application event
18
+ * @returns Partial application
19
+ */
20
+ export declare function transformApplication(opportunity: ApplicationPayload, options?: TransformApplicationOptions): {};
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformApplication = 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-credit-protocol/utils/application-paths");
6
+ const application_paths_2 = require("@lendi/act-eac-integrations-protocol/lib/utils/application-paths");
7
+ const lodash_1 = require("lodash");
8
+ const enum_mappings_1 = require("../types/enum-mappings/");
9
+ const transform_applicant_1 = require("./transform-applicant");
10
+ /**
11
+ * Transforms a partial opportunity event to a partial internal request.
12
+ *
13
+ * @param {ApplicationPayload} opportunity Public application event payload
14
+ * @param {TransformApplicationOptions} options Options for transforming the public application event
15
+ * @returns Partial application
16
+ */
17
+ function transformApplication(opportunity, options = {}) {
18
+ const { uniqueIdSuffix = 'loanDetails', enableRateLock = false, enableFastRefi = false } = options;
19
+ const partialApplication = {};
20
+ const opportunityMapping = {
21
+ brand: application_paths_2.paths.BusinessName,
22
+ id: application_paths_2.paths.ApplicationId,
23
+ paymentType: `${application_paths_2.paths.LoanTerm}.@PaymentType`,
24
+ preliminary: 'preliminary',
25
+ primaryPurpose: application_paths_2.paths.PurposeOfApplication,
26
+ brokerPrimaryPurpose: 'Package.Content.NeedsAnalysis.PurposeOfApplication[0].@Description',
27
+ };
28
+ (0, lodash_1.set)(partialApplication, `${application_paths_2.paths.LoanDetail}.@UniqueID`, `${opportunity.id}-${uniqueIdSuffix}`);
29
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Instructions}.@UniqueID`, `${opportunity.id}-stage`);
30
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Instructions}.@Name`, lixi_internal_request_1.EventNameApplicationInstructionsList.ApplicationReceived);
31
+ const { hasOptedInRateLock = false, isFastRefi = false } = opportunity;
32
+ if (enableRateLock) {
33
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.FeaturesSelected}.@RateLock`, (0, transform_applicant_1.booleanMapping)(hasOptedInRateLock));
34
+ }
35
+ /**
36
+ * Please note that fast refinance is only applicable to applications where the primary purpose of the application is Refinance
37
+ * Hence there is logic in the fixApplicationInconsistencies method used by the updateApplication middleware in AW that removes or defaults the value of the FastRefinance attribute
38
+ * based on the primary purpose of the application. This logic was placed in the fixApplicationInconsistencies method in the updateApplication middleware as this is where we know the correct primary purpose of the
39
+ * application.
40
+ */
41
+ if (enableFastRefi) {
42
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Overview}.@FastRefinance`, (0, transform_applicant_1.booleanMapping)(isFastRefi));
43
+ }
44
+ for (const [opportunityKey, opportunityValue] of Object.entries(opportunity)) {
45
+ if (opportunityMapping[opportunityKey]) {
46
+ if (opportunityKey === 'preliminary') {
47
+ for (const [key, value] of Object.entries(opportunityValue)) {
48
+ if (opportunityMapping[key]) {
49
+ switch (key) {
50
+ case 'paymentType':
51
+ (0, lodash_1.set)(partialApplication, opportunityMapping[key], enum_mappings_1.preferredRepaymentMapping[value]);
52
+ break;
53
+ case 'primaryPurpose':
54
+ (0, lodash_1.set)(partialApplication, opportunityMapping[key], enum_mappings_1.transactionTypeMapping[value]);
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ else {
61
+ (0, lodash_1.set)(partialApplication, opportunityMapping[opportunityKey], opportunityValue);
62
+ }
63
+ }
64
+ }
65
+ return partialApplication;
66
+ }
67
+ exports.transformApplication = transformApplication;
@@ -0,0 +1,25 @@
1
+ import { AddressType, Standard } from '@lendi/act-eac-integrations-protocol/lib/types/lixi-internal-request';
2
+ import { Address, AddressStandard } from '../types/events/public-asset';
3
+ /**
4
+ *
5
+ * @param address
6
+ */
7
+ export declare function getAddressMapping(address: Address): Record<string, string>;
8
+ export declare const standardMapping: Record<string, string>;
9
+ /**
10
+ * Generates an address for an asset.
11
+ *
12
+ * @param address: An address object.
13
+ * @param id: address event id.
14
+ * @param toBeUsedAsSecurity
15
+ * @param address
16
+ * @param id
17
+ * @returns A transformed address object.
18
+ */
19
+ export declare function transformAddress(address: Address, id: string): Partial<AddressType>;
20
+ /**
21
+ * @description Generates an address standard.
22
+ * @param {AddressStandard} addressStandard An address standard object.
23
+ * @returns {Partial<Standard>} A transformed standard object.
24
+ */
25
+ export declare function transformStandard(addressStandard: AddressStandard): Partial<Standard>;