Skip to content

Commit 784f5ad

Browse files
upgrade axios
1 parent b441ba4 commit 784f5ad

File tree

6 files changed

+42
-28
lines changed

6 files changed

+42
-28
lines changed

client/config/test/jest.setup-after-env.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ window.ResizeObserver = function () {
2121
disconnect: () => {},
2222
};
2323
};
24+
25+
window.ImageData = {}
26+
window.MediaStreamTrack = {}
27+
window.URL.createObjectURL = () => {}
28+
29+
class Worker {
30+
constructor(stringUrl) {
31+
this.url = stringUrl;
32+
this.onmessage = () => {};
33+
}
34+
35+
postMessage(msg) {
36+
this.onmessage(msg);
37+
}
38+
}
39+
window.Worker = Worker;

client/packages/lowcoder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"agora-rtc-sdk-ng": "^4.19.0",
3939
"agora-rtm-sdk": "^1.5.1",
4040
"antd": "^5.12.2",
41-
"axios": "^0.21.1",
41+
"axios": "^1.6.2",
4242
"buffer": "^6.0.3",
4343
"clsx": "^2.0.0",
4444
"cnchar": "^3.2.4",

client/packages/lowcoder/src/api/apiUtils.test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
doValidResponse,
88
validateResponse,
99
} from "./apiUtils";
10-
import { AxiosResponse } from "axios";
10+
import { AxiosHeaders, AxiosResponse } from "axios";
1111
import { ApiResponse } from "./apiResponses";
1212
import {
1313
createMessage,
@@ -23,8 +23,14 @@ beforeAll(() => {
2323
jest.spyOn(log, "error").mockImplementation(() => {});
2424
});
2525

26+
const headers = new AxiosHeaders({
27+
"Content-Type": "application/json",
28+
});
29+
2630
test("apiRequestInterceptor", () => {
27-
expect(apiRequestInterceptor({})).toHaveProperty("timer");
31+
expect(apiRequestInterceptor({
32+
headers,
33+
})).toHaveProperty("timer");
2834
});
2935

3036
test("apiSuccessResponseInterceptor", () => {
@@ -132,17 +138,17 @@ test("validateResponse", () => {
132138
status: 500,
133139
data: { success: false, code: 1, message: "fail", data: "" },
134140
statusText: "",
135-
headers: [],
136-
config: {},
141+
headers,
142+
config: { headers },
137143
})
138144
).toThrowError(Error("fail"));
139145
expect(
140146
validateResponse({
141147
status: 500,
142148
data: { success: true, code: 1, message: "", data: "" },
143149
statusText: "",
144-
headers: [],
145-
config: {},
150+
headers,
151+
config: { headers },
146152
})
147153
).toEqual(true);
148154
});
@@ -171,17 +177,17 @@ test("doValidResponse", () => {
171177
status: 500,
172178
data: { success: false, code: 1, message: "fail", data: "" },
173179
statusText: "",
174-
headers: [],
175-
config: {},
180+
headers,
181+
config: { headers },
176182
})
177183
).toEqual(false);
178184
expect(
179185
doValidResponse({
180186
status: 500,
181187
data: { success: true, code: 1, message: "", data: "" },
182188
statusText: "",
183-
headers: [],
184-
config: {},
189+
headers,
190+
config: { headers },
185191
})
186192
).toEqual(true);
187193
});

client/packages/lowcoder/src/api/apiUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { AUTH_BIND_URL, OAUTH_REDIRECT } from "constants/routesURL";
1111
import log from "loglevel";
1212
import history from "util/history";
13-
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
13+
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from "axios";
1414
import { trans } from "i18n";
1515
import StoreRegistry from "redux/store/storeRegistry";
1616
import { logoutAction } from "redux/reduxActions/userActions";
@@ -20,7 +20,7 @@ const executeActionRegex = /query\/execute/;
2020
const timeoutErrorRegex = /timeout of (\d+)ms exceeded/;
2121
export const axiosConnectionAbortedCode = "ECONNABORTED";
2222

23-
type AxiosRequestConfigWithTimer = AxiosRequestConfig & { timer: number };
23+
type AxiosRequestConfigWithTimer = InternalAxiosRequestConfig & { timer: number };
2424

2525
export type AxiosResponseWithTimer = AxiosResponse<ApiResponse> & {
2626
config: AxiosRequestConfigWithTimer;
@@ -37,7 +37,7 @@ export type AxiosErrorWithTimer = AxiosError<ApiResponse> & {
3737
};
3838

3939
function isAxiosErrorWithTimer(error: any): error is AxiosErrorWithTimer {
40-
return axios.isAxiosError(error) && error?.config && "timer" in error.config;
40+
return Boolean(axios.isAxiosError(error) && error?.config && "timer" in error.config);
4141
}
4242

4343
const makeExecuteActionResponse = (response: any) => {
@@ -68,7 +68,7 @@ const notNeedBindPath = () => {
6868
return pathName === AUTH_BIND_URL || pathName === OAUTH_REDIRECT;
6969
};
7070

71-
export const apiRequestInterceptor = (config: AxiosRequestConfig): AxiosRequestConfigWithTimer => ({
71+
export const apiRequestInterceptor = (config: InternalAxiosRequestConfig): AxiosRequestConfigWithTimer => ({
7272
...config,
7373
timer: performance.now(),
7474
});

client/packages/lowcoder/src/constants/apiConstants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RawAxiosRequestHeaders } from "axios";
12
import { trans } from "i18n";
23

34
export const DEFAULT_VERIFY_CODE_INTERVAL_SECONDS = 10;
@@ -47,7 +48,7 @@ export type PaginationParam = {
4748
size: number;
4849
};
4950

50-
export const API_REQUEST_HEADERS: APIHeaders = {
51+
export const API_REQUEST_HEADERS: RawAxiosRequestHeaders = {
5152
"Content-Type": "application/json",
5253
};
5354
export const SERVER_HOST = `${REACT_APP_API_HOST ?? ""}`;

client/yarn.lock

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5232,7 +5232,7 @@ __metadata:
52325232
languageName: node
52335233
linkType: hard
52345234

5235-
"axios@npm:*, axios@npm:^1.1.3":
5235+
"axios@npm:*, axios@npm:^1.1.3, axios@npm:^1.6.2":
52365236
version: 1.6.2
52375237
resolution: "axios@npm:1.6.2"
52385238
dependencies:
@@ -5243,15 +5243,6 @@ __metadata:
52435243
languageName: node
52445244
linkType: hard
52455245

5246-
"axios@npm:^0.21.1":
5247-
version: 0.21.4
5248-
resolution: "axios@npm:0.21.4"
5249-
dependencies:
5250-
follow-redirects: ^1.14.0
5251-
checksum: 44245f24ac971e7458f3120c92f9d66d1fc695e8b97019139de5b0cc65d9b8104647db01e5f46917728edfc0cfd88eb30fc4c55e6053eef4ace76768ce95ff3c
5252-
languageName: node
5253-
linkType: hard
5254-
52555246
"axios@npm:^0.27.2":
52565247
version: 0.27.2
52575248
resolution: "axios@npm:0.27.2"
@@ -8616,7 +8607,7 @@ __metadata:
86168607
languageName: node
86178608
linkType: hard
86188609

8619-
"follow-redirects@npm:^1.0.0, follow-redirects@npm:^1.14.0, follow-redirects@npm:^1.14.9, follow-redirects@npm:^1.15.0":
8610+
"follow-redirects@npm:^1.0.0, follow-redirects@npm:^1.14.9, follow-redirects@npm:^1.15.0":
86208611
version: 1.15.3
86218612
resolution: "follow-redirects@npm:1.15.3"
86228613
peerDependenciesMeta:
@@ -11652,7 +11643,7 @@ __metadata:
1165211643
agora-rtc-sdk-ng: ^4.19.0
1165311644
agora-rtm-sdk: ^1.5.1
1165411645
antd: ^5.12.2
11655-
axios: ^0.21.1
11646+
axios: ^1.6.2
1165611647
buffer: ^6.0.3
1165711648
clsx: ^2.0.0
1165811649
cnchar: ^3.2.4

0 commit comments

Comments
 (0)