@matech/thebigpos-sdk 2.10.0-rc3 → 2.11.0-rc1

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/index.js CHANGED
@@ -28,7 +28,6 @@ var __rest = (this && this.__rest) || function (s, e) {
28
28
  }
29
29
  return t;
30
30
  };
31
- import axios from "axios";
32
31
  export var ContentType;
33
32
  (function (ContentType) {
34
33
  ContentType["Json"] = "application/json";
@@ -37,63 +36,122 @@ export var ContentType;
37
36
  ContentType["Text"] = "text/plain";
38
37
  })(ContentType || (ContentType = {}));
39
38
  export class HttpClient {
40
- constructor(_a = {}) {
41
- var { securityWorker, secure, format } = _a, axiosConfig = __rest(_a, ["securityWorker", "secure", "format"]);
39
+ constructor(apiConfig = {}) {
40
+ this.baseUrl = "";
42
41
  this.securityData = null;
42
+ this.abortControllers = new Map();
43
+ this.customFetch = (...fetchParams) => fetch(...fetchParams);
44
+ this.baseApiParams = {
45
+ credentials: "same-origin",
46
+ headers: {},
47
+ redirect: "follow",
48
+ referrerPolicy: "no-referrer",
49
+ };
43
50
  this.setSecurityData = (data) => {
44
51
  this.securityData = data;
45
52
  };
53
+ this.contentFormatters = {
54
+ [ContentType.Json]: (input) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
55
+ [ContentType.Text]: (input) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
56
+ [ContentType.FormData]: (input) => Object.keys(input || {}).reduce((formData, key) => {
57
+ const property = input[key];
58
+ formData.append(key, property instanceof Blob
59
+ ? property
60
+ : typeof property === "object" && property !== null
61
+ ? JSON.stringify(property)
62
+ : `${property}`);
63
+ return formData;
64
+ }, new FormData()),
65
+ [ContentType.UrlEncoded]: (input) => this.toQueryString(input),
66
+ };
67
+ this.createAbortSignal = (cancelToken) => {
68
+ if (this.abortControllers.has(cancelToken)) {
69
+ const abortController = this.abortControllers.get(cancelToken);
70
+ if (abortController) {
71
+ return abortController.signal;
72
+ }
73
+ return void 0;
74
+ }
75
+ const abortController = new AbortController();
76
+ this.abortControllers.set(cancelToken, abortController);
77
+ return abortController.signal;
78
+ };
79
+ this.abortRequest = (cancelToken) => {
80
+ const abortController = this.abortControllers.get(cancelToken);
81
+ if (abortController) {
82
+ abortController.abort();
83
+ this.abortControllers.delete(cancelToken);
84
+ }
85
+ };
46
86
  this.request = (_a) => __awaiter(this, void 0, void 0, function* () {
47
- var { secure, path, type, query, format, body } = _a, params = __rest(_a, ["secure", "path", "type", "query", "format", "body"]);
48
- const secureParams = ((typeof secure === "boolean" ? secure : this.secure) &&
87
+ var { body, secure, path, type, query, format, baseUrl, cancelToken } = _a, params = __rest(_a, ["body", "secure", "path", "type", "query", "format", "baseUrl", "cancelToken"]);
88
+ const secureParams = ((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
49
89
  this.securityWorker &&
50
90
  (yield this.securityWorker(this.securityData))) ||
51
91
  {};
52
92
  const requestParams = this.mergeRequestParams(params, secureParams);
53
- const responseFormat = format || this.format || undefined;
54
- if (type === ContentType.FormData && body && body !== null && typeof body === "object") {
55
- body = this.createFormData(body);
56
- }
57
- if (type === ContentType.Text && body && body !== null && typeof body !== "string") {
58
- body = JSON.stringify(body);
59
- }
60
- return this.instance.request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type ? { "Content-Type": type } : {})), params: query, responseType: responseFormat, data: body, url: path }));
93
+ const queryString = query && this.toQueryString(query);
94
+ const payloadFormatter = this.contentFormatters[type || ContentType.Json];
95
+ const responseFormat = format || requestParams.format;
96
+ return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type && type !== ContentType.FormData ? { "Content-Type": type } : {})), signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null, body: typeof body === "undefined" || body === null ? null : payloadFormatter(body) })).then((response) => __awaiter(this, void 0, void 0, function* () {
97
+ const r = response.clone();
98
+ r.data = null;
99
+ r.error = null;
100
+ const data = !responseFormat
101
+ ? r
102
+ : yield response[responseFormat]()
103
+ .then((data) => {
104
+ if (r.ok) {
105
+ r.data = data;
106
+ }
107
+ else {
108
+ r.error = data;
109
+ }
110
+ return r;
111
+ })
112
+ .catch((e) => {
113
+ r.error = e;
114
+ return r;
115
+ });
116
+ if (cancelToken) {
117
+ this.abortControllers.delete(cancelToken);
118
+ }
119
+ if (!response.ok)
120
+ throw data;
121
+ return data;
122
+ }));
61
123
  });
62
- this.instance = axios.create(Object.assign(Object.assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || "" }));
63
- this.secure = secure;
64
- this.format = format;
65
- this.securityWorker = securityWorker;
124
+ Object.assign(this, apiConfig);
66
125
  }
67
- mergeRequestParams(params1, params2) {
68
- const method = params1.method || (params2 && params2.method);
69
- return Object.assign(Object.assign(Object.assign(Object.assign({}, this.instance.defaults), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, ((method && this.instance.defaults.headers[method.toLowerCase()]) || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
126
+ encodeQueryParam(key, value) {
127
+ const encodedKey = encodeURIComponent(key);
128
+ return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
70
129
  }
71
- stringifyFormItem(formItem) {
72
- if (typeof formItem === "object" && formItem !== null) {
73
- return JSON.stringify(formItem);
74
- }
75
- else {
76
- return `${formItem}`;
77
- }
130
+ addQueryParam(query, key) {
131
+ return this.encodeQueryParam(key, query[key]);
78
132
  }
79
- createFormData(input) {
80
- if (input instanceof FormData) {
81
- return input;
82
- }
83
- return Object.keys(input || {}).reduce((formData, key) => {
84
- const property = input[key];
85
- const propertyContent = property instanceof Array ? property : [property];
86
- for (const formItem of propertyContent) {
87
- const isFileType = formItem instanceof Blob || formItem instanceof File;
88
- formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
89
- }
90
- return formData;
91
- }, new FormData());
133
+ addArrayQueryParam(query, key) {
134
+ const value = query[key];
135
+ return value.map((v) => this.encodeQueryParam(key, v)).join("&");
136
+ }
137
+ toQueryString(rawQuery) {
138
+ const query = rawQuery || {};
139
+ const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
140
+ return keys
141
+ .map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
142
+ .join("&");
143
+ }
144
+ addQueryParams(rawQuery) {
145
+ const queryString = this.toQueryString(rawQuery);
146
+ return queryString ? `?${queryString}` : "";
147
+ }
148
+ mergeRequestParams(params1, params2) {
149
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, this.baseApiParams), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, (this.baseApiParams.headers || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
92
150
  }
93
151
  }
94
152
  /**
95
153
  * @title The Big POS API
96
- * @version v2.10.0
154
+ * @version v2.11.0
97
155
  * @termsOfService https://www.thebigpos.com/terms-of-use/
98
156
  * @contact Mortgage Automation Technologies <support@thebigpos.com> (https://www.thebigpos.com/terms-of-use/)
99
157
  */
@@ -160,6 +218,86 @@ export class Api extends HttpClient {
160
218
  * @secure
161
219
  */
162
220
  updateSiteConfigurationForAccount: (data, params = {}) => this.request(Object.assign({ path: `/api/account/site-configurations`, method: "PUT", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
221
+ /**
222
+ * No description
223
+ *
224
+ * @tags Accounts
225
+ * @name GetAccounts
226
+ * @summary Get All
227
+ * @request GET:/api/accounts
228
+ * @secure
229
+ */
230
+ getAccounts: (params = {}) => this.request(Object.assign({ path: `/api/accounts`, method: "GET", secure: true, format: "json" }, params)),
231
+ /**
232
+ * No description
233
+ *
234
+ * @tags Accounts
235
+ * @name UpdateLoansByAccount
236
+ * @summary Update Loans
237
+ * @request PUT:/api/accounts/{id}/loan
238
+ * @secure
239
+ */
240
+ updateLoansByAccount: (id, data, params = {}) => this.request(Object.assign({ path: `/api/accounts/${id}/loan`, method: "PUT", body: data, secure: true, type: ContentType.Json }, params)),
241
+ /**
242
+ * No description
243
+ *
244
+ * @tags Accounts
245
+ * @name GetLoansByAccount
246
+ * @summary Get Loans
247
+ * @request GET:/api/accounts/{id}/loan
248
+ * @secure
249
+ */
250
+ getLoansByAccount: (id, params = {}) => this.request(Object.assign({ path: `/api/accounts/${id}/loan`, method: "GET", secure: true, format: "json" }, params)),
251
+ /**
252
+ * No description
253
+ *
254
+ * @tags Authentication
255
+ * @name GetTokenFromRefreshToken
256
+ * @summary Generate Token From Refresh Token
257
+ * @request POST:/api/refresh-token
258
+ * @secure
259
+ */
260
+ getTokenFromRefreshToken: (data, params = {}) => this.request(Object.assign({ path: `/api/refresh-token`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
261
+ /**
262
+ * No description
263
+ *
264
+ * @tags Authentication
265
+ * @name GetToken
266
+ * @summary Get Token
267
+ * @request POST:/api/token
268
+ * @secure
269
+ */
270
+ getToken: (data, params = {}) => this.request(Object.assign({ path: `/api/token`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
271
+ /**
272
+ * No description
273
+ *
274
+ * @tags Authentication
275
+ * @name GetTokenFromChallengeCode
276
+ * @summary Get Token From Challenge Code
277
+ * @request POST:/api/token/code
278
+ * @secure
279
+ */
280
+ getTokenFromChallengeCode: (data, params = {}) => this.request(Object.assign({ path: `/api/token/code`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
281
+ /**
282
+ * No description
283
+ *
284
+ * @tags Authentication
285
+ * @name GetSystemToken
286
+ * @summary Get System Token
287
+ * @request POST:/api/oauth2/token
288
+ * @secure
289
+ */
290
+ getSystemToken: (data, params = {}) => this.request(Object.assign({ path: `/api/oauth2/token`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
291
+ /**
292
+ * No description
293
+ *
294
+ * @tags Authentication
295
+ * @name GetSsoToken
296
+ * @summary Get SSO Guid Token
297
+ * @request POST:/api/token/sso
298
+ * @secure
299
+ */
300
+ getSsoToken: (data, params = {}) => this.request(Object.assign({ path: `/api/token/sso`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
163
301
  /**
164
302
  * No description
165
303
  *
@@ -950,16 +1088,6 @@ export class Api extends HttpClient {
950
1088
  * @secure
951
1089
  */
952
1090
  createLoan: (data, params = {}) => this.request(Object.assign({ path: `/api/los/loan/application`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
953
- /**
954
- * No description
955
- *
956
- * @tags LegacyLoan
957
- * @name UploadDocuments
958
- * @summary Upload Documents
959
- * @request POST:/api/los/loan/tasks/documents
960
- * @secure
961
- */
962
- uploadDocuments: (data, params = {}) => this.request(Object.assign({ path: `/api/los/loan/tasks/documents`, method: "POST", body: data, secure: true, type: ContentType.Json }, params)),
963
1091
  /**
964
1092
  * No description
965
1093
  *
@@ -1456,7 +1584,7 @@ export class Api extends HttpClient {
1456
1584
  *
1457
1585
  * @tags Loans
1458
1586
  * @name GetLoan
1459
- * @summary Gey By ID
1587
+ * @summary Get By ID
1460
1588
  * @request GET:/api/loans/{loanID}
1461
1589
  * @secure
1462
1590
  */
@@ -1476,7 +1604,7 @@ export class Api extends HttpClient {
1476
1604
  *
1477
1605
  * @tags Loans
1478
1606
  * @name ImportLoanFromLos
1479
- * @summary importFromLOS
1607
+ * @summary Import from LOS
1480
1608
  * @request POST:/api/loans/import-from-los/{loanId}
1481
1609
  * @secure
1482
1610
  */
@@ -2464,94 +2592,6 @@ export class Api extends HttpClient {
2464
2592
  */
2465
2593
  getWorkflow: (data, params = {}) => this.request(Object.assign({ path: `/api/workflow`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
2466
2594
  };
2467
- this.accounts = {
2468
- /**
2469
- * No description
2470
- *
2471
- * @tags Accounts
2472
- * @name GetAccounts
2473
- * @summary Get All
2474
- * @request GET:/accounts
2475
- * @secure
2476
- */
2477
- getAccounts: (params = {}) => this.request(Object.assign({ path: `/accounts`, method: "GET", secure: true, format: "json" }, params)),
2478
- /**
2479
- * No description
2480
- *
2481
- * @tags Accounts
2482
- * @name UpdateLoansByAccount
2483
- * @summary Update Loans
2484
- * @request PUT:/accounts/{id}/loan
2485
- * @secure
2486
- */
2487
- updateLoansByAccount: (id, data, params = {}) => this.request(Object.assign({ path: `/accounts/${id}/loan`, method: "PUT", body: data, secure: true, type: ContentType.Json }, params)),
2488
- /**
2489
- * No description
2490
- *
2491
- * @tags Accounts
2492
- * @name GetLoansByAccount
2493
- * @summary Get Loans
2494
- * @request GET:/accounts/{id}/loan
2495
- * @secure
2496
- */
2497
- getLoansByAccount: (id, params = {}) => this.request(Object.assign({ path: `/accounts/${id}/loan`, method: "GET", secure: true, format: "json" }, params)),
2498
- };
2499
- this.refreshToken = {
2500
- /**
2501
- * No description
2502
- *
2503
- * @tags Authentication
2504
- * @name GetTokenFromRefreshToken
2505
- * @summary Generate Token From Refresh Token
2506
- * @request POST:/refresh-token
2507
- * @secure
2508
- */
2509
- getTokenFromRefreshToken: (data, params = {}) => this.request(Object.assign({ path: `/refresh-token`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
2510
- };
2511
- this.token = {
2512
- /**
2513
- * No description
2514
- *
2515
- * @tags Authentication
2516
- * @name GetToken
2517
- * @summary Get Token
2518
- * @request POST:/token
2519
- * @secure
2520
- */
2521
- getToken: (data, params = {}) => this.request(Object.assign({ path: `/token`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
2522
- /**
2523
- * No description
2524
- *
2525
- * @tags Authentication
2526
- * @name GetTokenFromChallengeCode
2527
- * @summary Get Token From Challenge Code
2528
- * @request POST:/token/code
2529
- * @secure
2530
- */
2531
- getTokenFromChallengeCode: (data, params = {}) => this.request(Object.assign({ path: `/token/code`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
2532
- /**
2533
- * No description
2534
- *
2535
- * @tags Authentication
2536
- * @name GetSsoToken
2537
- * @summary Get SSO Guid Token
2538
- * @request POST:/token/sso
2539
- * @secure
2540
- */
2541
- getSsoToken: (data, params = {}) => this.request(Object.assign({ path: `/token/sso`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
2542
- };
2543
- this.oauth2 = {
2544
- /**
2545
- * No description
2546
- *
2547
- * @tags Authentication
2548
- * @name GetSystemToken
2549
- * @summary Get System Token
2550
- * @request POST:/oauth2/token
2551
- * @secure
2552
- */
2553
- getSystemToken: (data, params = {}) => this.request(Object.assign({ path: `/oauth2/token`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
2554
- };
2555
2595
  }
2556
2596
  }
2557
2597
  //# sourceMappingURL=index.js.map