@moneylion/engine-api 1.2.0 → 1.3.1

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/dist/client.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  type HttpMethod = "GET" | "POST" | "PATCH" | "DELETE";
2
3
  /**
3
4
  * The base HTTP client that the API clients depend on.
@@ -10,12 +11,14 @@ type HttpMethod = "GET" | "POST" | "PATCH" | "DELETE";
10
11
  export declare class Client {
11
12
  private host;
12
13
  private auth_token;
14
+ private fetch_impl;
15
+ private timeout_ms;
13
16
  /**
14
17
  * Construct a new client instance.
15
18
  * @param host - The API host URL. Example: https://www.example.com. Should not include a trailing slash.
16
19
  * @param auth_token - The auth token used for authenticating with the API.
17
20
  */
18
- constructor(host: string | undefined, auth_token: string);
21
+ constructor(host: string | undefined, auth_token: string, timeout_ms?: number, fetch_impl?: typeof fetch);
19
22
  /**
20
23
  * Make a GET request.
21
24
  *
@@ -62,7 +65,7 @@ export declare class Client {
62
65
  export declare class ApiError extends Error {
63
66
  /** The HTTP status code.
64
67
  */
65
- failureStatus: number;
68
+ failureStatus?: number;
66
69
  /** The url that was requested.
67
70
  */
68
71
  url: string;
@@ -72,7 +75,13 @@ export declare class ApiError extends Error {
72
75
  /** The serialized body.
73
76
  */
74
77
  body?: string;
75
- constructor(failureStatus: number, failureReason: string, url: string, method: HttpMethod, body?: string);
78
+ constructor({ failureStatus, failureReason, url, method, body }: {
79
+ failureStatus?: number;
80
+ failureReason: string;
81
+ url: string;
82
+ method: HttpMethod;
83
+ body?: string;
84
+ });
76
85
  }
77
86
  /**
78
87
  * An error that the caller has made in the request.
@@ -88,4 +97,6 @@ export declare class ServerError extends ApiError {
88
97
  */
89
98
  export declare class AuthenticationError extends ApiError {
90
99
  }
100
+ export declare class TimeoutError extends ApiError {
101
+ }
91
102
  export {};
package/dist/client.js CHANGED
@@ -21,9 +21,11 @@ export class Client {
21
21
  * @param host - The API host URL. Example: https://www.example.com. Should not include a trailing slash.
22
22
  * @param auth_token - The auth token used for authenticating with the API.
23
23
  */
24
- constructor(host = "https://api.evenfinancial.com", auth_token) {
24
+ constructor(host = "https://api.evenfinancial.com", auth_token, timeout_ms = 15 * 1000, fetch_impl = fetch) {
25
25
  this.host = host;
26
26
  this.auth_token = auth_token;
27
+ this.fetch_impl = fetch_impl;
28
+ this.timeout_ms = timeout_ms;
27
29
  }
28
30
  /**
29
31
  * Make a GET request.
@@ -72,24 +74,56 @@ export class Client {
72
74
  */
73
75
  request(endpoint, method, body) {
74
76
  return __awaiter(this, void 0, void 0, function* () {
75
- const url = `${this.host}/${endpoint}`;
76
- const response = yield fetch(url, {
77
- method: method,
78
- headers: {
79
- "Content-Type": "application/json",
80
- "Accept": "application/json",
81
- "Authorization": `Bearer ${this.auth_token}`,
82
- },
83
- body: body,
77
+ const timeout = new Promise((resolve) => {
78
+ setTimeout(() => resolve(undefined), this.timeout_ms);
84
79
  });
80
+ const url = `${this.host}/${endpoint}`;
81
+ const response = yield Promise.race([
82
+ this.fetch_impl(url, {
83
+ method: method,
84
+ headers: {
85
+ "Content-Type": "application/json",
86
+ "Accept": "application/json",
87
+ "Authorization": `Bearer ${this.auth_token}`,
88
+ },
89
+ body: body,
90
+ }),
91
+ timeout
92
+ ]);
93
+ if (response === undefined) {
94
+ throw new TimeoutError({
95
+ failureReason: "Client Timeout",
96
+ url,
97
+ method,
98
+ body
99
+ });
100
+ }
85
101
  if (response.status >= 500) {
86
- throw new ServerError(response.status, response.statusText, url, method, body);
102
+ throw new ServerError({
103
+ failureStatus: response.status,
104
+ failureReason: response.statusText,
105
+ url,
106
+ method,
107
+ body
108
+ });
87
109
  }
88
110
  if (response.status >= 400) {
89
111
  if (response.status === 401 || response.status === 403) {
90
- throw new AuthenticationError(response.status, response.statusText, url, method, body);
112
+ throw new AuthenticationError({
113
+ failureStatus: response.status,
114
+ failureReason: response.statusText,
115
+ url,
116
+ method,
117
+ body
118
+ });
91
119
  }
92
- throw new ClientError(response.status, response.statusText, url, method, body);
120
+ throw new ClientError({
121
+ failureStatus: response.status,
122
+ failureReason: response.statusText,
123
+ url,
124
+ method,
125
+ body
126
+ });
93
127
  }
94
128
  /* node-fetch types json() as Promise<unknown> to ensure the consumer makes a decision about the
95
129
  * type. We are deciding here to treat it as an object so that consumers of this method can introspect
@@ -103,7 +137,7 @@ export class Client {
103
137
  /** The generic error class used to represent error status codes such as 400 Bad Request.
104
138
  */
105
139
  export class ApiError extends Error {
106
- constructor(failureStatus, failureReason, url, method, body) {
140
+ constructor({ failureStatus, failureReason, url, method, body }) {
107
141
  super(failureReason);
108
142
  this.failureStatus = failureStatus;
109
143
  this.url = url;
@@ -125,3 +159,5 @@ export class ServerError extends ApiError {
125
159
  */
126
160
  export class AuthenticationError extends ApiError {
127
161
  }
162
+ export class TimeoutError extends ApiError {
163
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test, beforeAll, afterEach, afterAll, } from "@jest/globals";
2
- import { Client, AuthenticationError, ClientError, ServerError, } from "./client";
2
+ import { Client, AuthenticationError, ClientError, ServerError, TimeoutError, } from "./client";
3
3
  import { setupServer } from "msw/node";
4
4
  import { http, HttpResponse } from "msw";
5
5
  const successBody = { response: "Okay" };
@@ -75,4 +75,12 @@ describe("Client", () => {
75
75
  const response = client.request("network_error", "GET");
76
76
  return expect(response).rejects.toThrow(TypeError);
77
77
  });
78
+ test("Timeout error is raised when a timeout occurs", () => {
79
+ const fetch_impl = () => new Promise((_, reject) => {
80
+ setTimeout(() => reject(new Error("this should be impossible")), 100);
81
+ });
82
+ const client = new Client(testEndpoint, "good_token", 1, fetch_impl);
83
+ const response = client.request("timeout_error", "GET");
84
+ return expect(response).rejects.toThrow(TimeoutError);
85
+ });
78
86
  });
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@moneylion/engine-api",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Interface to engine.tech API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
- "files": ["dist"],
7
+ "files": [
8
+ "dist"
9
+ ],
8
10
  "scripts": {
9
11
  "build": "tsc",
10
12
  "lint": "prettier . --check && eslint src/",
@@ -26,7 +28,8 @@
26
28
  "msw": "^2.2.10",
27
29
  "openapi-typescript": "^6.7.5",
28
30
  "prettier": "3.2.5",
29
- "ts-jest": "^29.1.2"
31
+ "ts-jest": "^29.1.2",
32
+ "typescript": "^5.2.2"
30
33
  },
31
34
  "engines": {
32
35
  "node": ">=18"
@@ -1,206 +0,0 @@
1
- import { components } from "./generated/schema";
2
- export type LeadCreateData = components["schemas"]["LeadCreateData"];
3
- export declare class LeadCreateBuilder {
4
- private leadData;
5
- constructor(startingData?: LeadCreateData);
6
- build(): {
7
- productTypes?: ("credit_card" | "insurance" | "life_insurance" | "loan" | "mortgage" | "savings" | "other")[] | undefined;
8
- uuid?: string | undefined;
9
- sessionUuid?: string | undefined;
10
- loanInformation?: {
11
- purpose?: "other" | "unknown" | "auto" | "auto_purchase" | "auto_refinance" | "baby" | "boat" | "business" | "car_repair" | "cosmetic" | "credit_card_refi" | "debt_consolidation" | "emergency" | "engagement" | "green" | "home_improvement" | "home_purchase" | "home_refi" | "household_expenses" | "large_purchases" | "life_event" | "medical_dental" | "motorcycle" | "moving_relocation" | "rv" | "special_occasion" | "student_loan" | "student_loan_refi" | "taxes" | "vacation" | "wedding" | undefined;
12
- loanAmount?: number | undefined;
13
- } | undefined;
14
- personalInformation?: {
15
- firstName?: string | undefined;
16
- lastName?: string | undefined;
17
- aliasFirstName?: string | undefined;
18
- aliasLastName?: string | undefined;
19
- email?: string | undefined;
20
- city?: string | undefined;
21
- state?: "AK" | "AL" | "AR" | "AZ" | "CA" | "CO" | "CT" | "DC" | "DE" | "FL" | "GA" | "HI" | "IA" | "ID" | "IL" | "IN" | "KS" | "KY" | "LA" | "MA" | "MD" | "ME" | "MI" | "MN" | "MO" | "MS" | "MT" | "NC" | "ND" | "NE" | "NH" | "NJ" | "NM" | "NV" | "NY" | "OH" | "OK" | "OR" | "PA" | "PR" | "RI" | "SC" | "SD" | "TN" | "TX" | "UT" | "VA" | "VI" | "VT" | "WA" | "WI" | "WV" | "WY" | undefined;
22
- workPhone?: string | undefined;
23
- primaryPhone?: string | undefined;
24
- bestTimeToCall?: "morning" | "afternoon" | "evening" | "night" | undefined;
25
- address1?: string | undefined;
26
- address2?: string | undefined;
27
- addressMoveInDate?: string | undefined;
28
- zipcode?: string | undefined;
29
- monthsAtAddress?: number | undefined;
30
- driversLicenseNumber?: string | undefined;
31
- driversLicenseState?: string | undefined;
32
- ipAddress?: string | undefined;
33
- activeMilitary?: boolean | undefined;
34
- militaryVeteran?: boolean | undefined;
35
- dateOfBirth?: string | undefined;
36
- educationLevel?: "other" | "high_school" | "associate" | "bachelors" | "masters" | "doctorate" | "other_grad_degree" | "certificate" | "did_not_graduate" | "still_enrolled" | undefined;
37
- ssn?: string | undefined;
38
- citizenshipStatus?: "other" | "citizen" | "permanent_resident" | undefined;
39
- } | undefined;
40
- personalReferenceInformation?: {
41
- firstName?: string | undefined;
42
- lastName?: string | undefined;
43
- primaryPhone?: string | undefined;
44
- relationType?: "other" | "parent" | "employer" | "spouse" | "guardian" | "sibling" | "relative" | "friend" | undefined;
45
- } | undefined;
46
- mortgageInformation?: {
47
- propertyType?: "rent" | "condo" | "multi_unit" | "single_family" | "townhouse" | undefined;
48
- propertyValue?: number | undefined;
49
- mortgageBalance?: number | undefined;
50
- lenderName?: string | undefined;
51
- hasFHALoan?: boolean | undefined;
52
- currentWithLoan?: boolean | undefined;
53
- propertyStatus?: "own_outright" | "own_with_mortgage" | "rent" | undefined;
54
- mortgageType?: "purchase" | "refinance" | undefined;
55
- mortgageAmount?: number | undefined;
56
- downPaymentAmount?: number | undefined;
57
- propertyState?: string | undefined;
58
- propertyCounty?: string | undefined;
59
- propertyAddress1?: string | undefined;
60
- propertyAddress2?: string | undefined;
61
- propertyZipcode?: string | undefined;
62
- propertyCity?: string | undefined;
63
- refinanceAmount?: number | undefined;
64
- cashOutAmount?: number | undefined;
65
- occupancyType?: "primary" | "secondary" | "investment" | undefined;
66
- refinanceType?: "cash_out" | "rate_term" | undefined;
67
- propertySearchStatus?: "found" | "not_found" | undefined;
68
- numUnits?: number | undefined;
69
- closingDate?: string | undefined;
70
- purchaseStatus?: "no_offer" | "offer_accepted" | "offer_pending" | "under_contract" | undefined;
71
- purchaseDate?: string | undefined;
72
- monthlyHoaFee?: number | undefined;
73
- mortgageCompany?: string | undefined;
74
- mortgageEscrowAmount?: number | undefined;
75
- } | undefined;
76
- creditCardInformation?: {
77
- allowAnnualFee?: boolean | undefined;
78
- cardPurposes?: ("balance_transfer" | "cash_back" | "earning_rewards" | "improve_credit" | "low_interest" | "new_to_credit" | "student" | "travel_incentives")[] | undefined;
79
- } | undefined;
80
- savingsInformation?: {
81
- minDepositAmount?: number | undefined;
82
- maxDepositAmount?: number | undefined;
83
- } | undefined;
84
- creditInformation?: {
85
- providedCreditRating?: "excellent" | "good" | "fair" | "poor" | "limited" | "unknown" | undefined;
86
- providedNumericCreditScore?: number | undefined;
87
- } | undefined;
88
- financialInformation?: {
89
- employmentStatus?: "other" | "employed" | "employed_full_time" | "employed_part_time" | "military" | "not_employed" | "self_employed" | "retired" | undefined;
90
- employmentPayFrequency?: "monthly" | "weekly" | "biweekly" | "twice_monthly" | undefined;
91
- annualIncome?: number | undefined;
92
- monthlyNetIncome?: number | undefined;
93
- bankName?: string | undefined;
94
- bankRoutingNumber?: string | undefined;
95
- bankAccountType?: "savings" | "other" | "checking" | undefined;
96
- creditCardDebt?: number | undefined;
97
- monthsAtBank?: number | undefined;
98
- bankAccountNumber?: string | undefined;
99
- monthlyDebt?: number | undefined;
100
- totalAssets?: number | undefined;
101
- monthlyHousingPayment?: number | undefined;
102
- availableAssets?: number | undefined;
103
- additionalIncome?: number | undefined;
104
- additionalIncomeFrequency?: "monthly" | "weekly" | "biweekly" | "twice_monthly" | undefined;
105
- hasDirectDeposit?: boolean | undefined;
106
- totalUnsecuredDebt?: number | undefined;
107
- } | undefined;
108
- employmentInformation?: {
109
- employerName?: string | undefined;
110
- employerAddress?: string | undefined;
111
- employerAddress2?: string | undefined;
112
- employerCity?: string | undefined;
113
- employerPhone?: string | undefined;
114
- employerState?: string | undefined;
115
- employerZip?: string | undefined;
116
- jobTitle?: string | undefined;
117
- monthsEmployed?: number | undefined;
118
- directDeposit?: boolean | undefined;
119
- payDate1?: string | undefined;
120
- payDate2?: string | undefined;
121
- startDate?: string | undefined;
122
- } | undefined;
123
- legalInformation?: {
124
- consentsToFcra?: boolean | undefined;
125
- consentsToSms?: boolean | undefined;
126
- consentsToTcpa?: boolean | undefined;
127
- fcraLanguage?: string | undefined;
128
- tcpaLanguage?: string | undefined;
129
- } | undefined;
130
- educationInformation?: {
131
- educationLevel?: "other" | "high_school" | "associate" | "bachelors" | "masters" | "doctorate" | "other_grad_degree" | "certificate" | "did_not_graduate" | "still_enrolled" | undefined;
132
- graduateDegreeType?: "other" | "doctor_of_medicine" | "doctor_of_osteopathic_medicine" | "doctor_of_optometry" | "doctor_of_dental_medicine" | "dentariae_medicinae_doctoris" | "doctor_of_dental_surgery" | "doctor_of_veterinary_medicine" | "doctor_of_pharmacy" | "veterinariae_medicinae_doctoris" | "master_of_arts" | "master_of_science" | "master_of_research" | "master_of_research_project" | "master_of_studies" | "master_of_business_administration" | "master_of_library_science" | "master_of_public_administration" | "master_of_public_health" | "master_of_laws" | "master_of_arts_liberal_studies" | "master_of_fine_arts" | "master_of_music" | "master_of_education" | "master_of_engineering" | "master_of_architecture" | "juris_doctor" | undefined;
133
- universityAttended?: string | undefined;
134
- universityOpeId?: string | undefined;
135
- graduationDate?: string | undefined;
136
- graduateGraduationDate?: string | undefined;
137
- graduateLastAttendedDate?: string | undefined;
138
- graduateUniversityAttended?: string | undefined;
139
- graduateUniversityOpeId?: string | undefined;
140
- undergraduateGraduationDate?: string | undefined;
141
- undergraduateLastAttendedDate?: string | undefined;
142
- undergraduateUniversityAttended?: string | undefined;
143
- undergraduateUniversityOpeId?: string | undefined;
144
- } | undefined;
145
- coApplicantInformation?: {
146
- firstName?: string | undefined;
147
- lastName?: string | undefined;
148
- dateOfBirth?: string | undefined;
149
- annualIncome?: number | undefined;
150
- streetAddress1?: string | undefined;
151
- streetAddress2?: string | undefined;
152
- city?: string | undefined;
153
- state?: "AK" | "AL" | "AR" | "AZ" | "CA" | "CO" | "CT" | "DC" | "DE" | "FL" | "GA" | "HI" | "IA" | "ID" | "IL" | "IN" | "KS" | "KY" | "LA" | "MA" | "MD" | "ME" | "MI" | "MN" | "MO" | "MS" | "MT" | "NC" | "ND" | "NE" | "NH" | "NJ" | "NM" | "NV" | "NY" | "OH" | "OK" | "OR" | "PA" | "PR" | "RI" | "SC" | "SD" | "TN" | "TX" | "UT" | "VA" | "VI" | "VT" | "WA" | "WI" | "WV" | "WY" | undefined;
154
- zipcode?: string | undefined;
155
- } | undefined;
156
- healthInformation?: {
157
- gender?: "male" | "female" | undefined;
158
- heightInInches?: number | undefined;
159
- weightInPounds?: number | undefined;
160
- tobaccoSmoker?: boolean | undefined;
161
- } | undefined;
162
- refinanceLoans?: {
163
- accountNumber?: string | undefined;
164
- incomeBasedRepayment?: boolean | undefined;
165
- interestRate?: number | undefined;
166
- loanAmount?: number | undefined;
167
- loanServicer?: string | undefined;
168
- loanType?: "federal_student_loan" | "private_student_loan" | undefined;
169
- nextPaymentAmount?: number | undefined;
170
- nextPaymentDate?: string | undefined;
171
- }[] | undefined;
172
- identificationInformation?: {
173
- idNumber?: string | undefined;
174
- idState?: string | undefined;
175
- idType?: "driver_license" | "state_id" | "passport" | undefined;
176
- } | undefined;
177
- clientTags?: {
178
- [key: string]: string[];
179
- } | undefined;
180
- sessionInformation?: {
181
- ipAddress?: string | undefined;
182
- userAgent?: string | undefined;
183
- } | undefined;
184
- formCompleted?: boolean | undefined;
185
- referralCompanyUuid?: string | undefined;
186
- trackingUuid?: string | undefined;
187
- };
188
- productTypes(types: components["schemas"]["ProductType"][]): this;
189
- loanInformation(loanInfo: components["schemas"]["LeadLoanInformation"]): this;
190
- personalInformation(personalInfo: components["schemas"]["LeadPersonalInformation"]): this;
191
- personalReferenceInformation(pRefInfo: components["schemas"]["PersonalReferenceInformation"]): this;
192
- mortgageInformation(mortgageInfo: components["schemas"]["LeadMortgageInformation"]): this;
193
- creditCardInformation(creditCardInformation: components["schemas"]["LeadCreditCardInformation"]): this;
194
- savingsInformation(savingsInformation: components["schemas"]["LeadSavingsInformation"]): this;
195
- creditInformation(creditInformation: components["schemas"]["LeadCreditInformation"]): this;
196
- financialInformation(financialInformation: components["schemas"]["LeadFinancialInformation"]): this;
197
- employmentInformation(employmentInformation: components["schemas"]["LeadEmploymentInformation"]): this;
198
- legalInformation(legalInformation: components["schemas"]["LeadLegalInformation"]): this;
199
- educationInformation(educationInformation: components["schemas"]["LeadEducationInformation"]): this;
200
- coApplicantInformation(coApplicantInformation: components["schemas"]["LeadCoApplicantInformation"]): this;
201
- healthInformation(healthInformation: components["schemas"]["LeadHealthInformation"]): this;
202
- refinanceLoans(refinanceLoans: components["schemas"]["RefinanceLoanInformation"][]): this;
203
- identificationInformation(identificationInformation: components["schemas"]["LeadIdentificationInformation"]): this;
204
- clientTags(clientTags: components["schemas"]["ClientTags"]): this;
205
- sessionInformation(sessionInformation: components["schemas"]["LeadSessionInformation"]): this;
206
- }
package/dist/builders.js DELETED
@@ -1,80 +0,0 @@
1
- export class LeadCreateBuilder {
2
- constructor(startingData = {}) {
3
- this.leadData = startingData;
4
- }
5
- build() {
6
- return this.leadData;
7
- }
8
- productTypes(types) {
9
- this.leadData.productTypes = types;
10
- return this;
11
- }
12
- loanInformation(loanInfo) {
13
- this.leadData.loanInformation = loanInfo;
14
- return this;
15
- }
16
- personalInformation(personalInfo) {
17
- this.leadData.personalInformation = personalInfo;
18
- return this;
19
- }
20
- personalReferenceInformation(pRefInfo) {
21
- this.leadData.personalReferenceInformation = pRefInfo;
22
- return this;
23
- }
24
- mortgageInformation(mortgageInfo) {
25
- this.leadData.mortgageInformation = mortgageInfo;
26
- return this;
27
- }
28
- creditCardInformation(creditCardInformation) {
29
- this.leadData.creditCardInformation = creditCardInformation;
30
- return this;
31
- }
32
- savingsInformation(savingsInformation) {
33
- this.leadData.savingsInformation = savingsInformation;
34
- return this;
35
- }
36
- creditInformation(creditInformation) {
37
- this.leadData.creditInformation = creditInformation;
38
- return this;
39
- }
40
- financialInformation(financialInformation) {
41
- this.leadData.financialInformation = financialInformation;
42
- return this;
43
- }
44
- employmentInformation(employmentInformation) {
45
- this.leadData.employmentInformation = employmentInformation;
46
- return this;
47
- }
48
- legalInformation(legalInformation) {
49
- this.leadData.legalInformation = legalInformation;
50
- return this;
51
- }
52
- educationInformation(educationInformation) {
53
- this.leadData.educationInformation = educationInformation;
54
- return this;
55
- }
56
- coApplicantInformation(coApplicantInformation) {
57
- this.leadData.coApplicantInformation = coApplicantInformation;
58
- return this;
59
- }
60
- healthInformation(healthInformation) {
61
- this.leadData.healthInformation = healthInformation;
62
- return this;
63
- }
64
- refinanceLoans(refinanceLoans) {
65
- this.leadData.refinanceLoans = refinanceLoans;
66
- return this;
67
- }
68
- identificationInformation(identificationInformation) {
69
- this.leadData.identificationInformation = identificationInformation;
70
- return this;
71
- }
72
- clientTags(clientTags) {
73
- this.leadData.clientTags = clientTags;
74
- return this;
75
- }
76
- sessionInformation(sessionInformation) {
77
- this.leadData.sessionInformation = sessionInformation;
78
- return this;
79
- }
80
- }