@moneylion/engine-api 1.0.2 → 1.2.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.
- package/README.md +22 -2
- package/dist/decoders.d.ts +8 -2
- package/dist/decoders.js +2 -2
- package/dist/leads.d.ts +41 -3
- package/dist/leads.js +63 -3
- package/dist/leads.test.js +38 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,9 +40,21 @@ import { Lead } from "@moneylion/engine-api";
|
|
|
40
40
|
new Lead(endpoint, authentication_token).create(lead);
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
This will return a promise that resolves with the UUID of the lead that was just created.
|
|
44
|
+
It will not create a rate table yet.
|
|
45
|
+
In order to create a rate table you can do the following:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
import { Lead } from "@moneylion/engine-api";
|
|
49
|
+
|
|
50
|
+
new Lead(endpoint, authentication_token).getRateTable(lead);
|
|
51
|
+
```
|
|
52
|
+
|
|
43
53
|
This will return a promise that resolves with an AsyncRateTable.
|
|
44
54
|
You can use the `AsyncRateTable.resolve()` method to turn it into a real RateTable.
|
|
45
|
-
You can also use `
|
|
55
|
+
You can also use `getRateTableBlocking` which will resolve with a RateTable, but you will potentially spend longer waiting for network requests.
|
|
56
|
+
|
|
57
|
+
You can do the lead creation and rate table fetch in one step using the `createAndGetRateTable` and `createAndGetRateTableBlocking` methods.
|
|
46
58
|
|
|
47
59
|
### Updating a Lead
|
|
48
60
|
|
|
@@ -54,7 +66,7 @@ import { Lead } from "@moneylion/engine-api";
|
|
|
54
66
|
new Lead(endpoint, authentication_token).update(leadUuid, updatedLead);
|
|
55
67
|
```
|
|
56
68
|
|
|
57
|
-
This returns a promise but will
|
|
69
|
+
This returns a promise but will _not_ resolve with a rate table and will instead resolve the lead UUID back to you when it finishes.
|
|
58
70
|
|
|
59
71
|
### Rate Tables
|
|
60
72
|
|
|
@@ -80,3 +92,11 @@ This is a relatively normal NPM and Typescript project.
|
|
|
80
92
|
1. `npm install` to install dependencies
|
|
81
93
|
2. `npm run build` to build the project
|
|
82
94
|
3. `npm test` to run the tests
|
|
95
|
+
|
|
96
|
+
# Publishing to NPM
|
|
97
|
+
|
|
98
|
+
Run the following steps to publish the library to NPM.
|
|
99
|
+
|
|
100
|
+
0. Update the version number in `package.json`. Commit this change.
|
|
101
|
+
1. `npm run build` - This will run Typescript to compile the Javascript.
|
|
102
|
+
2. `npm publish --access=public`. This will publish the library.
|
package/dist/decoders.d.ts
CHANGED
|
@@ -21,7 +21,10 @@ export declare const originatorImageDecoder: Decoder<components["schemas"]["Orig
|
|
|
21
21
|
export declare const originatorDecoder: Decoder<FixNull<components["schemas"]["Originator"]>>;
|
|
22
22
|
export declare const aprTypeDecoder: Decoder<components["schemas"]["AprType"]>;
|
|
23
23
|
type OldLoanOffer = components["schemas"]["LoanOffer"];
|
|
24
|
-
type
|
|
24
|
+
type TempLoanOfferWithNulledFields = {
|
|
25
|
+
[P in keyof OldLoanOffer]: P extends "termLength" | "termUnit" ? OldLoanOffer[P] | null | undefined : OldLoanOffer[P];
|
|
26
|
+
};
|
|
27
|
+
type LoanOffer = FixNull<TempLoanOfferWithNulledFields>;
|
|
25
28
|
export declare const loanOfferDecoder: Decoder<LoanOffer>;
|
|
26
29
|
export declare const mortgageLoanTypeDecoder: Decoder<components["schemas"]["MortgageLoanType"]>;
|
|
27
30
|
export declare const mortgageAdjustmentTypeDecoder: Decoder<components["schemas"]["MortgageAdjustmentType"]>;
|
|
@@ -34,7 +37,10 @@ export declare const savingsOfferDecoder: Decoder<FixNull<components["schemas"][
|
|
|
34
37
|
export declare const specialOfferDecoder: Decoder<FixNull<components["schemas"]["SpecialOffer"]>>;
|
|
35
38
|
export declare const pendingResponseDecoder: Decoder<FixNull<components["schemas"]["PendingResponse"]>>;
|
|
36
39
|
type OldRateTable = components["schemas"]["RateTable"];
|
|
37
|
-
|
|
40
|
+
type TempRateTableWithNulledFields = {
|
|
41
|
+
[P in keyof OldRateTable]: P extends "loanOffers" ? Array<LoanOffer> : OldRateTable[P];
|
|
42
|
+
};
|
|
43
|
+
export type FixedRateTable = FixNull<TempRateTableWithNulledFields>;
|
|
38
44
|
export declare const rateTableDecoder: Decoder<FixedRateTable>;
|
|
39
45
|
export declare const leadUuidDecoder: Decoder<components["schemas"]["LeadUuid"]>;
|
|
40
46
|
export {};
|
package/dist/decoders.js
CHANGED
|
@@ -119,8 +119,8 @@ export const loanOfferDecoder = object({
|
|
|
119
119
|
sponsored: boolean(),
|
|
120
120
|
maxAmount: number(),
|
|
121
121
|
minAmount: optional(number()),
|
|
122
|
-
termLength: number(),
|
|
123
|
-
termUnit: termUnitDecoder,
|
|
122
|
+
termLength: optional(number()),
|
|
123
|
+
termUnit: optional(termUnitDecoder),
|
|
124
124
|
displayTermUnit: optional(string()),
|
|
125
125
|
termDescription: optional(string()),
|
|
126
126
|
maxApr: optional(number()),
|
package/dist/leads.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class Leads {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor(host: string, auth_token: string);
|
|
17
17
|
/**
|
|
18
|
-
* Create a new lead.
|
|
18
|
+
* Create a new lead and retrieve its rate table.
|
|
19
19
|
*
|
|
20
20
|
* @param lead - An object representing the required information to create a Lead.
|
|
21
21
|
*
|
|
@@ -25,7 +25,7 @@ export declare class Leads {
|
|
|
25
25
|
* This method returns an AsyncRateTable.
|
|
26
26
|
* Use the resolve method on the returned object to retrieve the final Rate Table.
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
createAndGetRateTable(lead: LeadCreateData): Promise<AsyncRateTable>;
|
|
29
29
|
/**
|
|
30
30
|
* Create a new lead, immediately resolving the final Rate Table.
|
|
31
31
|
*
|
|
@@ -38,7 +38,18 @@ export declare class Leads {
|
|
|
38
38
|
* This may mean waiting a significant amount of time before it is finalized.
|
|
39
39
|
* Only use this if you can handle waiting for that amount of time.
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
createAndGetRateTableBlocking(lead: LeadCreateData): Promise<RateTable>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new lead.
|
|
44
|
+
*
|
|
45
|
+
* @param lead - New lead data to merge into the lead.
|
|
46
|
+
*
|
|
47
|
+
* @returns lead uuid
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* This method returns the UUID of the lead that was created.
|
|
51
|
+
*/
|
|
52
|
+
create(lead: LeadCreateData): Promise<string>;
|
|
42
53
|
/**
|
|
43
54
|
* Update an existing lead, merging the given data with the already existing data.
|
|
44
55
|
*
|
|
@@ -51,4 +62,31 @@ export declare class Leads {
|
|
|
51
62
|
* This method returns the UUID of the lead that was updated.
|
|
52
63
|
*/
|
|
53
64
|
update(leadUuid: string, lead: LeadCreateData): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Retrieve the rate table for a lead.
|
|
67
|
+
*
|
|
68
|
+
* @param leadUuid - The UUID of the lead whose rate table you wish to retrieve.
|
|
69
|
+
* @param lead - An object representing the any information the lead should be updated with.
|
|
70
|
+
*
|
|
71
|
+
* @returns AsyncRateTable
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* This method returns an AsyncRateTable.
|
|
75
|
+
* Use the resolve method on the returned object to retrieve the final Rate Table.
|
|
76
|
+
*/
|
|
77
|
+
getRateTable(leadUuid: string, lead: LeadCreateData): Promise<AsyncRateTable>;
|
|
78
|
+
/**
|
|
79
|
+
* Retrieve the rate table for a lead, immediately resolving it.
|
|
80
|
+
*
|
|
81
|
+
* @param leadUuid - The UUID of the lead whose rate table you wish to retrieve.
|
|
82
|
+
* @param lead - An object representing the any information the lead should be updated with.
|
|
83
|
+
*
|
|
84
|
+
* @returns RateTable
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* This method will immediately resolve the final Rate Table.
|
|
88
|
+
* This may mean waiting a significant amount of time before it is finalized.
|
|
89
|
+
* Only use this if you can handle waiting for that amount of time.
|
|
90
|
+
*/
|
|
91
|
+
getRateTableBlocking(leadUuid: string, lead: LeadCreateData): Promise<RateTable>;
|
|
54
92
|
}
|
package/dist/leads.js
CHANGED
|
@@ -25,7 +25,7 @@ export class Leads {
|
|
|
25
25
|
this.client = new Client(host, auth_token);
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Create a new lead.
|
|
28
|
+
* Create a new lead and retrieve its rate table.
|
|
29
29
|
*
|
|
30
30
|
* @param lead - An object representing the required information to create a Lead.
|
|
31
31
|
*
|
|
@@ -35,7 +35,7 @@ export class Leads {
|
|
|
35
35
|
* This method returns an AsyncRateTable.
|
|
36
36
|
* Use the resolve method on the returned object to retrieve the final Rate Table.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
createAndGetRateTable(lead) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
const resp = yield this.client.post("leads/rateTables", lead);
|
|
41
41
|
const rateTable = rateTableDecoder.runWithException(resp);
|
|
@@ -58,13 +58,30 @@ export class Leads {
|
|
|
58
58
|
* This may mean waiting a significant amount of time before it is finalized.
|
|
59
59
|
* Only use this if you can handle waiting for that amount of time.
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
createAndGetRateTableBlocking(lead) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
const resp = yield this.client.post("blocking/leads/rateTables", lead);
|
|
64
64
|
const rateTable = rateTableDecoder.runWithException(resp);
|
|
65
65
|
return rateTable;
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a new lead.
|
|
70
|
+
*
|
|
71
|
+
* @param lead - New lead data to merge into the lead.
|
|
72
|
+
*
|
|
73
|
+
* @returns lead uuid
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This method returns the UUID of the lead that was created.
|
|
77
|
+
*/
|
|
78
|
+
create(lead) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const resp = yield this.client.post("leads", lead);
|
|
81
|
+
const leadUuidResponse = leadUuidDecoder.runWithException(resp);
|
|
82
|
+
return leadUuidResponse.uuid;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
68
85
|
/**
|
|
69
86
|
* Update an existing lead, merging the given data with the already existing data.
|
|
70
87
|
*
|
|
@@ -83,4 +100,47 @@ export class Leads {
|
|
|
83
100
|
return leadUuidResponse.uuid;
|
|
84
101
|
});
|
|
85
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Retrieve the rate table for a lead.
|
|
105
|
+
*
|
|
106
|
+
* @param leadUuid - The UUID of the lead whose rate table you wish to retrieve.
|
|
107
|
+
* @param lead - An object representing the any information the lead should be updated with.
|
|
108
|
+
*
|
|
109
|
+
* @returns AsyncRateTable
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* This method returns an AsyncRateTable.
|
|
113
|
+
* Use the resolve method on the returned object to retrieve the final Rate Table.
|
|
114
|
+
*/
|
|
115
|
+
getRateTable(leadUuid, lead) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const resp = yield this.client.post(`leads/${leadUuid}/rateTables`, lead);
|
|
118
|
+
const rateTable = rateTableDecoder.runWithException(resp);
|
|
119
|
+
const asyncRateTable = new AsyncRateTable({
|
|
120
|
+
rateTable,
|
|
121
|
+
client: this.client,
|
|
122
|
+
});
|
|
123
|
+
return asyncRateTable;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve the rate table for a lead, immediately resolving it.
|
|
128
|
+
*
|
|
129
|
+
* @param leadUuid - The UUID of the lead whose rate table you wish to retrieve.
|
|
130
|
+
* @param lead - An object representing the any information the lead should be updated with.
|
|
131
|
+
*
|
|
132
|
+
* @returns RateTable
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* This method will immediately resolve the final Rate Table.
|
|
136
|
+
* This may mean waiting a significant amount of time before it is finalized.
|
|
137
|
+
* Only use this if you can handle waiting for that amount of time.
|
|
138
|
+
*/
|
|
139
|
+
getRateTableBlocking(leadUuid, lead) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const resp = yield this.client.post(`blocking/leads/${leadUuid}/rateTables`, lead);
|
|
142
|
+
const rateTable = rateTableDecoder.runWithException(resp);
|
|
143
|
+
return rateTable;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
86
146
|
}
|
package/dist/leads.test.js
CHANGED
|
@@ -175,6 +175,9 @@ const testHost = "https://engine.com";
|
|
|
175
175
|
const token = "good_auth_token";
|
|
176
176
|
const patchLeadUuid = "patch-lead-uuid";
|
|
177
177
|
const patchLeadUuidResponse = "patch-lead-uuid-response";
|
|
178
|
+
const createLeadUuidResponse = "create-lead-uuid-response";
|
|
179
|
+
const getRateTableLeadUuid = "get-rate-table-lead-uuid";
|
|
180
|
+
const getRateTableLeadUuidBlocking = "get-rate-table-lead-uuid-blocking";
|
|
178
181
|
const handlers = [
|
|
179
182
|
http.post(`${testHost}/blocking/leads/rateTables`, () => {
|
|
180
183
|
return new HttpResponse(JSON.stringify(fullRateTable), { status: 200 });
|
|
@@ -194,11 +197,26 @@ const handlers = [
|
|
|
194
197
|
status: 200,
|
|
195
198
|
});
|
|
196
199
|
}),
|
|
200
|
+
http.post(`${testHost}/leads`, () => {
|
|
201
|
+
return new HttpResponse(JSON.stringify({
|
|
202
|
+
uuid: createLeadUuidResponse,
|
|
203
|
+
}));
|
|
204
|
+
}),
|
|
197
205
|
http.patch(`${testHost}/leads/${patchLeadUuid}`, () => {
|
|
198
206
|
return new HttpResponse(JSON.stringify({
|
|
199
207
|
uuid: patchLeadUuidResponse,
|
|
200
208
|
}));
|
|
201
209
|
}),
|
|
210
|
+
http.post(`${testHost}/leads/${getRateTableLeadUuid}/rateTables`, () => {
|
|
211
|
+
return new HttpResponse(JSON.stringify(pendingRateTable), {
|
|
212
|
+
status: 200,
|
|
213
|
+
});
|
|
214
|
+
}),
|
|
215
|
+
http.post(`${testHost}/blocking/leads/${getRateTableLeadUuidBlocking}/rateTables`, () => {
|
|
216
|
+
return new HttpResponse(JSON.stringify(fullRateTable), {
|
|
217
|
+
status: 200,
|
|
218
|
+
});
|
|
219
|
+
}),
|
|
202
220
|
];
|
|
203
221
|
const server = setupServer(...handlers);
|
|
204
222
|
describe("Leads", () => {
|
|
@@ -209,23 +227,40 @@ describe("Leads", () => {
|
|
|
209
227
|
afterAll(() => server.close());
|
|
210
228
|
test("Blocking leads endpoint returns a resolved rate table", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
229
|
const leads = new Leads(testHost, token);
|
|
212
|
-
const resp = yield leads.
|
|
230
|
+
const resp = yield leads.createAndGetRateTableBlocking(testLeadData);
|
|
213
231
|
expect(resp).toEqual(fullRateTable);
|
|
214
232
|
}));
|
|
215
233
|
test("Async leads endpoint returns an async rate table", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
234
|
const leads = new Leads(testHost, token);
|
|
217
|
-
const resp = yield leads.
|
|
235
|
+
const resp = yield leads.createAndGetRateTable(testLeadData);
|
|
218
236
|
expect(resp).toBeInstanceOf(AsyncRateTable);
|
|
219
237
|
}));
|
|
220
238
|
test("Async leads endpoint can be further resolved to a final rate table", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
239
|
const leads = new Leads(testHost, token);
|
|
222
|
-
const resp = yield leads.
|
|
240
|
+
const resp = yield leads.createAndGetRateTable(testLeadData);
|
|
223
241
|
const rateTable = yield resp.resolve();
|
|
224
242
|
expect(rateTable).toEqual(fullRateTable);
|
|
225
243
|
}));
|
|
244
|
+
test("Create lead endpoint returns the uuid of the created lead", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
const leads = new Leads(testHost, token);
|
|
246
|
+
const resp = yield leads.create(testLeadData);
|
|
247
|
+
expect(resp).toEqual(createLeadUuidResponse);
|
|
248
|
+
}));
|
|
226
249
|
test("Patch leads endpoint returns the uuid of the lead", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
227
250
|
const leads = new Leads(testHost, token);
|
|
228
251
|
const resp = yield leads.update(patchLeadUuid, testLeadData);
|
|
229
252
|
expect(resp).toEqual(patchLeadUuidResponse);
|
|
230
253
|
}));
|
|
254
|
+
test("Get lead rate table endpoint returns an async rate table", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
255
|
+
const leads = new Leads(testHost, token);
|
|
256
|
+
const resp = yield leads.getRateTable(getRateTableLeadUuid, testLeadData);
|
|
257
|
+
expect(resp).toBeInstanceOf(AsyncRateTable);
|
|
258
|
+
const rateTable = yield resp.resolve();
|
|
259
|
+
expect(rateTable).toEqual(fullRateTable);
|
|
260
|
+
}));
|
|
261
|
+
test("Get lead rate table blocking endpoint returns a resolved rate table", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
const leads = new Leads(testHost, token);
|
|
263
|
+
const resp = yield leads.getRateTableBlocking(getRateTableLeadUuidBlocking, testLeadData);
|
|
264
|
+
expect(resp).toEqual(fullRateTable);
|
|
265
|
+
}));
|
|
231
266
|
});
|