@moneylion/engine-api 1.0.2 → 1.1.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 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 `createBlocking` which will resolve with a RateTable, but you will potentially spend longer waiting for network requests.
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 *not* resolve with a rate table and will instead resolve the lead UUID back to you when it finishes.
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
 
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
- create(lead: LeadCreateData): Promise<AsyncRateTable>;
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
- createBlocking(lead: LeadCreateData): Promise<RateTable>;
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
- create(lead) {
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
- createBlocking(lead) {
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
  }
@@ -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.createBlocking(testLeadData);
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.create(testLeadData);
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.create(testLeadData);
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneylion/engine-api",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Interface to engine.tech API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",