@8ms/helpers 1.1.104 → 1.1.105
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/axios/get.d.ts +3 -1
- package/axios/get.js +7 -2
- package/axios/post.d.ts +3 -1
- package/axios/post.js +7 -2
- package/package.json +1 -1
package/axios/get.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import ApiResponse from '../api/ApiResponse';
|
|
1
2
|
export declare type Get = {
|
|
2
3
|
config?: object;
|
|
3
4
|
onError?: Function;
|
|
4
5
|
onSuccess?: Function;
|
|
6
|
+
returnApiResponse?: boolean;
|
|
5
7
|
url: string;
|
|
6
8
|
};
|
|
7
|
-
declare const get: ({ config, onError, onSuccess, url }: Get) => Promise<any>;
|
|
9
|
+
declare const get: ({ config, onError, onSuccess, returnApiResponse, url }: Get) => Promise<any | ApiResponse>;
|
|
8
10
|
export default get;
|
package/axios/get.js
CHANGED
|
@@ -4,9 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const ApiResponse_1 = __importDefault(require("../api/ApiResponse"));
|
|
7
8
|
const states_1 = __importDefault(require("../api/states"));
|
|
8
|
-
const get = async ({ config = {}, onError, onSuccess, url }) => {
|
|
9
|
-
|
|
9
|
+
const get = async ({ config = {}, onError, onSuccess, returnApiResponse, url }) => {
|
|
10
|
+
let response = await axios_1.default.get(url, config)
|
|
10
11
|
.then(async (response) => {
|
|
11
12
|
if (200 === response.status) {
|
|
12
13
|
// Is an API request
|
|
@@ -39,6 +40,10 @@ const get = async ({ config = {}, onError, onSuccess, url }) => {
|
|
|
39
40
|
throw Error;
|
|
40
41
|
}
|
|
41
42
|
});
|
|
43
|
+
// Convert the response into an ApiResponse instance
|
|
44
|
+
if (returnApiResponse) {
|
|
45
|
+
response = new ApiResponse_1.default(response);
|
|
46
|
+
}
|
|
42
47
|
return response;
|
|
43
48
|
};
|
|
44
49
|
exports.default = get;
|
package/axios/post.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import ApiResponse from '../api/ApiResponse';
|
|
1
2
|
export declare type Post = {
|
|
2
3
|
config?: object;
|
|
3
4
|
data?: object;
|
|
4
5
|
onError?: Function;
|
|
5
6
|
onSuccess?: Function;
|
|
7
|
+
returnApiResponse?: boolean;
|
|
6
8
|
url: string;
|
|
7
9
|
};
|
|
8
10
|
/**
|
|
9
11
|
* Make a POST request.
|
|
10
12
|
*/
|
|
11
|
-
declare const post: ({ config, data, onError, onSuccess, url }: Post) => Promise<any>;
|
|
13
|
+
declare const post: ({ config, data, onError, onSuccess, returnApiResponse, url }: Post) => Promise<any | ApiResponse>;
|
|
12
14
|
export default post;
|
package/axios/post.js
CHANGED
|
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const ApiResponse_1 = __importDefault(require("../api/ApiResponse"));
|
|
7
8
|
const states_1 = __importDefault(require("../api/states"));
|
|
8
9
|
/**
|
|
9
10
|
* Make a POST request.
|
|
10
11
|
*/
|
|
11
|
-
const post = async ({ config = {}, data = {}, onError, onSuccess, url }) => {
|
|
12
|
-
|
|
12
|
+
const post = async ({ config = {}, data = {}, onError, onSuccess, returnApiResponse, url }) => {
|
|
13
|
+
let response = await axios_1.default.post(url, data, config)
|
|
13
14
|
.then(async (response) => {
|
|
14
15
|
if (200 === response.status) {
|
|
15
16
|
// Is an API request
|
|
@@ -42,6 +43,10 @@ const post = async ({ config = {}, data = {}, onError, onSuccess, url }) => {
|
|
|
42
43
|
throw Error;
|
|
43
44
|
}
|
|
44
45
|
});
|
|
46
|
+
// Convert the response into an ApiResponse instance
|
|
47
|
+
if (returnApiResponse) {
|
|
48
|
+
response = new ApiResponse_1.default(response);
|
|
49
|
+
}
|
|
45
50
|
return response;
|
|
46
51
|
};
|
|
47
52
|
exports.default = post;
|