@tolinax/ayoune-cli 2024.2.17 → 2024.2.18
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/lib/api/apiCallHandler.js +42 -42
- package/lib/api/apiClient.js +16 -16
- package/package.json +1 -1
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { api } from "./apiClient.js";
|
|
2
|
-
import { spinner } from "../../index.js";
|
|
3
|
-
import * as process from "process";
|
|
4
|
-
import { login } from "./login.js";
|
|
5
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
-
export const apiCallHandler = async (url, method = "get", data = null, params = {}) => {
|
|
7
|
-
var _a, _b, _c;
|
|
8
|
-
try {
|
|
9
|
-
const response = await api({
|
|
10
|
-
method,
|
|
11
|
-
url,
|
|
12
|
-
data,
|
|
13
|
-
params: { ...params, ref: `ayoune-cli@${process.env.AYOUNE_VERSION}` },
|
|
14
|
-
headers: {
|
|
15
|
-
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
return response.data;
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
const apiError = error.response;
|
|
22
|
-
if (apiError.status === 400) {
|
|
23
|
-
spinner.error({
|
|
24
|
-
text: `Bad Request: ${apiError.data.meta.message}`,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (apiError.status === 401) {
|
|
28
|
-
await login();
|
|
29
|
-
}
|
|
30
|
-
if (apiError.status === 403) {
|
|
31
|
-
spinner.error({
|
|
32
|
-
text: `You are not allowed to access this ressource... Required rights are [${(_c = (_b = (_a = apiError.data) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.requiredRights) === null || _c === void 0 ? void 0 : _c.join(",")}]`,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
spinner.error({
|
|
37
|
-
text: `Status ${apiError.status}: ${apiError.statusText} | ${apiError.data.meta.message}`,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return apiError.data;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
1
|
+
import { api } from "./apiClient.js";
|
|
2
|
+
import { spinner } from "../../index.js";
|
|
3
|
+
import * as process from "process";
|
|
4
|
+
import { login } from "./login.js";
|
|
5
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
6
|
+
export const apiCallHandler = async (url, method = "get", data = null, params = {}) => {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
try {
|
|
9
|
+
const response = await api({
|
|
10
|
+
method,
|
|
11
|
+
url,
|
|
12
|
+
data,
|
|
13
|
+
params: { ...params, ref: `ayoune-cli@${process.env.AYOUNE_VERSION}` },
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
return response.data;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const apiError = error.response;
|
|
22
|
+
if (apiError.status === 400) {
|
|
23
|
+
spinner.error({
|
|
24
|
+
text: `Bad Request: ${apiError.data.meta.message}`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (apiError.status === 401) {
|
|
28
|
+
await login();
|
|
29
|
+
}
|
|
30
|
+
if (apiError.status === 403) {
|
|
31
|
+
spinner.error({
|
|
32
|
+
text: `You are not allowed to access this ressource... Required rights are [${(_c = (_b = (_a = apiError.data) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.requiredRights) === null || _c === void 0 ? void 0 : _c.join(",")}]`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
spinner.error({
|
|
37
|
+
text: `Status ${apiError.status}: ${apiError.statusText} | ${apiError.data.meta.message}`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return apiError.data;
|
|
41
|
+
}
|
|
42
|
+
};
|
package/lib/api/apiClient.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import axiosRetry from "axios-retry";
|
|
3
|
-
const hosts = {
|
|
4
|
-
api: "https://api.ayoune.app",
|
|
5
|
-
api_dev: "http://localhost:3000",
|
|
6
|
-
audit: "https://audit.ayoune.app",
|
|
7
|
-
};
|
|
8
|
-
const api = axios.create({
|
|
9
|
-
baseURL: hosts.
|
|
10
|
-
});
|
|
11
|
-
const audit = axios.create({
|
|
12
|
-
baseURL: hosts.audit,
|
|
13
|
-
});
|
|
14
|
-
axiosRetry(api, { retries: 3 });
|
|
15
|
-
axiosRetry(audit, { retries: 3 });
|
|
16
|
-
export { api, audit };
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import axiosRetry from "axios-retry";
|
|
3
|
+
const hosts = {
|
|
4
|
+
api: "https://api.ayoune.app",
|
|
5
|
+
api_dev: "http://localhost:3000",
|
|
6
|
+
audit: "https://audit.ayoune.app",
|
|
7
|
+
};
|
|
8
|
+
const api = axios.create({
|
|
9
|
+
baseURL: hosts.api,
|
|
10
|
+
});
|
|
11
|
+
const audit = axios.create({
|
|
12
|
+
baseURL: hosts.audit,
|
|
13
|
+
});
|
|
14
|
+
axiosRetry(api, { retries: 3 });
|
|
15
|
+
axiosRetry(audit, { retries: 3 });
|
|
16
|
+
export { api, audit };
|