@brostark/solutions-client 1.1.14 → 1.1.16
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/helper.d.ts +6 -0
- package/dist/helper.d.ts.map +1 -1
- package/dist/helper.js +16 -1
- package/dist/lib/httpRequest.js +2 -2
- package/package.json +1 -1
- package/src/helper.ts +19 -1
- package/src/lib/httpRequest.ts +3 -3
package/dist/helper.d.ts
CHANGED
|
@@ -13,4 +13,10 @@ export declare const setLimit: (limit: number, min: number, max: number) => numb
|
|
|
13
13
|
* @returns The URL with the query string
|
|
14
14
|
*/
|
|
15
15
|
export declare const buildUrlWithParams: (baseUrl: string, params?: Record<string, unknown>) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Remove undefined values of an objet
|
|
18
|
+
* @param record - The record
|
|
19
|
+
* @returns The record filtered
|
|
20
|
+
*/
|
|
21
|
+
export declare const removeUndefinedValues: <T extends object>(record: T) => T;
|
|
16
22
|
//# sourceMappingURL=helper.d.ts.map
|
package/dist/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,WAE/D,CAAA;AAGD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAiBtF,CAAA"}
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,WAE/D,CAAA;AAGD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAiBtF,CAAA;AAGD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,KAAG,CAUnE,CAAA"}
|
package/dist/helper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildUrlWithParams = exports.setLimit = void 0;
|
|
3
|
+
exports.removeUndefinedValues = exports.buildUrlWithParams = exports.setLimit = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Sets a limit between a minimum and maximum value
|
|
6
6
|
* @param limit - The desired limit
|
|
@@ -33,3 +33,18 @@ const buildUrlWithParams = (baseUrl, params) => {
|
|
|
33
33
|
return `${baseUrl}${separator}${search}`;
|
|
34
34
|
};
|
|
35
35
|
exports.buildUrlWithParams = buildUrlWithParams;
|
|
36
|
+
/**
|
|
37
|
+
* Remove undefined values of an objet
|
|
38
|
+
* @param record - The record
|
|
39
|
+
* @returns The record filtered
|
|
40
|
+
*/
|
|
41
|
+
const removeUndefinedValues = (record) => {
|
|
42
|
+
Object.keys(record).forEach((key) => {
|
|
43
|
+
const value = record[key];
|
|
44
|
+
if (typeof value === "undefined") {
|
|
45
|
+
delete record[key];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return record;
|
|
49
|
+
};
|
|
50
|
+
exports.removeUndefinedValues = removeUndefinedValues;
|
package/dist/lib/httpRequest.js
CHANGED
|
@@ -13,11 +13,11 @@ const constant_1 = require("../constant");
|
|
|
13
13
|
const httpRequest = async (apiUrl, apiKey, options) => {
|
|
14
14
|
const { headers, params, data, ...rest } = options;
|
|
15
15
|
const url = (0, helper_1.buildUrlWithParams)(apiUrl, params);
|
|
16
|
-
const config = {
|
|
16
|
+
const config = (0, helper_1.removeUndefinedValues)({
|
|
17
17
|
mode: "cors",
|
|
18
18
|
method: "GET",
|
|
19
19
|
...rest,
|
|
20
|
-
};
|
|
20
|
+
});
|
|
21
21
|
const finalHeaders = {
|
|
22
22
|
"x-api-key": apiKey,
|
|
23
23
|
...headers,
|
package/package.json
CHANGED
package/src/helper.ts
CHANGED
|
@@ -33,4 +33,22 @@ export const buildUrlWithParams = (baseUrl: string, params?: Record<string, unkn
|
|
|
33
33
|
const separator = baseUrl.includes("?") ? "&" : "?";
|
|
34
34
|
|
|
35
35
|
return `${baseUrl}${separator}${search}`;
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Remove undefined values of an objet
|
|
41
|
+
* @param record - The record
|
|
42
|
+
* @returns The record filtered
|
|
43
|
+
*/
|
|
44
|
+
export const removeUndefinedValues = <T extends object>(record: T): T => {
|
|
45
|
+
Object.keys(record).forEach((key) => {
|
|
46
|
+
const value = record[key as keyof typeof record];
|
|
47
|
+
|
|
48
|
+
if (typeof value === "undefined") {
|
|
49
|
+
delete record[key as keyof typeof record];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return record as T;
|
|
54
|
+
}
|
package/src/lib/httpRequest.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ListOptions } from "./types";
|
|
2
|
-
import { buildUrlWithParams, setLimit } from "../helper";
|
|
2
|
+
import { buildUrlWithParams, removeUndefinedValues, setLimit } from "../helper";
|
|
3
3
|
import { MAX_LIMIT } from "../constant";
|
|
4
4
|
|
|
5
5
|
type RequestOptions = Omit<RequestInit, "body"> & {
|
|
@@ -20,11 +20,11 @@ export const httpRequest = async (apiUrl: string, apiKey: string, options: Reque
|
|
|
20
20
|
|
|
21
21
|
const url = buildUrlWithParams(apiUrl, params);
|
|
22
22
|
|
|
23
|
-
const config: RequestInit = {
|
|
23
|
+
const config: RequestInit = removeUndefinedValues({
|
|
24
24
|
mode: "cors",
|
|
25
25
|
method: "GET",
|
|
26
26
|
...rest,
|
|
27
|
-
};
|
|
27
|
+
});
|
|
28
28
|
|
|
29
29
|
const finalHeaders: Record<string, string> = {
|
|
30
30
|
"x-api-key": apiKey,
|