Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
upgrade axios
  • Loading branch information
raheeliftikhar5 committed Dec 21, 2023
commit df577d10ff95a176f904995548dd8caccb7735c5
16 changes: 16 additions & 0 deletions client/config/test/jest.setup-after-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ window.ResizeObserver = function () {
disconnect: () => {},
};
};

window.ImageData = {}
window.MediaStreamTrack = {}
window.URL.createObjectURL = () => {}

class Worker {
constructor(stringUrl) {
this.url = stringUrl;
this.onmessage = () => {};
}

postMessage(msg) {
this.onmessage(msg);
}
}
window.Worker = Worker;
2 changes: 1 addition & 1 deletion client/packages/lowcoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"agora-rtc-sdk-ng": "^4.19.0",
"agora-rtm-sdk": "^1.5.1",
"antd": "^5.12.2",
"axios": "^0.21.1",
"axios": "^1.6.2",
"buffer": "^6.0.3",
"clsx": "^2.0.0",
"cnchar": "^3.2.4",
Expand Down
26 changes: 16 additions & 10 deletions client/packages/lowcoder/src/api/apiUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
doValidResponse,
validateResponse,
} from "./apiUtils";
import { AxiosResponse } from "axios";
import { AxiosHeaders, AxiosResponse } from "axios";
import { ApiResponse } from "./apiResponses";
import {
createMessage,
Expand All @@ -23,8 +23,14 @@ beforeAll(() => {
jest.spyOn(log, "error").mockImplementation(() => {});
});

const headers = new AxiosHeaders({
"Content-Type": "application/json",
});

test("apiRequestInterceptor", () => {
expect(apiRequestInterceptor({})).toHaveProperty("timer");
expect(apiRequestInterceptor({
headers,
})).toHaveProperty("timer");
});

test("apiSuccessResponseInterceptor", () => {
Expand Down Expand Up @@ -132,17 +138,17 @@ test("validateResponse", () => {
status: 500,
data: { success: false, code: 1, message: "fail", data: "" },
statusText: "",
headers: [],
config: {},
headers,
config: { headers },
})
).toThrowError(Error("fail"));
expect(
validateResponse({
status: 500,
data: { success: true, code: 1, message: "", data: "" },
statusText: "",
headers: [],
config: {},
headers,
config: { headers },
})
).toEqual(true);
});
Expand Down Expand Up @@ -171,17 +177,17 @@ test("doValidResponse", () => {
status: 500,
data: { success: false, code: 1, message: "fail", data: "" },
statusText: "",
headers: [],
config: {},
headers,
config: { headers },
})
).toEqual(false);
expect(
doValidResponse({
status: 500,
data: { success: true, code: 1, message: "", data: "" },
statusText: "",
headers: [],
config: {},
headers,
config: { headers },
})
).toEqual(true);
});
8 changes: 4 additions & 4 deletions client/packages/lowcoder/src/api/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { AUTH_BIND_URL, OAUTH_REDIRECT } from "constants/routesURL";
import log from "loglevel";
import history from "util/history";
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from "axios";
import { trans } from "i18n";
import StoreRegistry from "redux/store/storeRegistry";
import { logoutAction } from "redux/reduxActions/userActions";
Expand All @@ -20,7 +20,7 @@ const executeActionRegex = /query\/execute/;
const timeoutErrorRegex = /timeout of (\d+)ms exceeded/;
export const axiosConnectionAbortedCode = "ECONNABORTED";

type AxiosRequestConfigWithTimer = AxiosRequestConfig & { timer: number };
type AxiosRequestConfigWithTimer = InternalAxiosRequestConfig & { timer: number };

export type AxiosResponseWithTimer = AxiosResponse<ApiResponse> & {
config: AxiosRequestConfigWithTimer;
Expand All @@ -37,7 +37,7 @@ export type AxiosErrorWithTimer = AxiosError<ApiResponse> & {
};

function isAxiosErrorWithTimer(error: any): error is AxiosErrorWithTimer {
return axios.isAxiosError(error) && error?.config && "timer" in error.config;
return Boolean(axios.isAxiosError(error) && error?.config && "timer" in error.config);
}

const makeExecuteActionResponse = (response: any) => {
Expand Down Expand Up @@ -68,7 +68,7 @@ const notNeedBindPath = () => {
return pathName === AUTH_BIND_URL || pathName === OAUTH_REDIRECT;
};

export const apiRequestInterceptor = (config: AxiosRequestConfig): AxiosRequestConfigWithTimer => ({
export const apiRequestInterceptor = (config: InternalAxiosRequestConfig): AxiosRequestConfigWithTimer => ({
...config,
timer: performance.now(),
});
Expand Down
3 changes: 2 additions & 1 deletion client/packages/lowcoder/src/constants/apiConstants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RawAxiosRequestHeaders } from "axios";
import { trans } from "i18n";

export const DEFAULT_VERIFY_CODE_INTERVAL_SECONDS = 10;
Expand Down Expand Up @@ -47,7 +48,7 @@ export type PaginationParam = {
size: number;
};

export const API_REQUEST_HEADERS: APIHeaders = {
export const API_REQUEST_HEADERS: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
};
export const SERVER_HOST = `${REACT_APP_API_HOST ?? ""}`;
Expand Down
15 changes: 3 additions & 12 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5232,7 +5232,7 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:*, axios@npm:^1.1.3":
"axios@npm:*, axios@npm:^1.1.3, axios@npm:^1.6.2":
version: 1.6.2
resolution: "axios@npm:1.6.2"
dependencies:
Expand All @@ -5243,15 +5243,6 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^0.21.1":
version: 0.21.4
resolution: "axios@npm:0.21.4"
dependencies:
follow-redirects: ^1.14.0
checksum: 44245f24ac971e7458f3120c92f9d66d1fc695e8b97019139de5b0cc65d9b8104647db01e5f46917728edfc0cfd88eb30fc4c55e6053eef4ace76768ce95ff3c
languageName: node
linkType: hard

"axios@npm:^0.27.2":
version: 0.27.2
resolution: "axios@npm:0.27.2"
Expand Down Expand Up @@ -8616,7 +8607,7 @@ __metadata:
languageName: node
linkType: hard

"follow-redirects@npm:^1.0.0, follow-redirects@npm:^1.14.0, follow-redirects@npm:^1.14.9, follow-redirects@npm:^1.15.0":
"follow-redirects@npm:^1.0.0, follow-redirects@npm:^1.14.9, follow-redirects@npm:^1.15.0":
version: 1.15.3
resolution: "follow-redirects@npm:1.15.3"
peerDependenciesMeta:
Expand Down Expand Up @@ -11652,7 +11643,7 @@ __metadata:
agora-rtc-sdk-ng: ^4.19.0
agora-rtm-sdk: ^1.5.1
antd: ^5.12.2
axios: ^0.21.1
axios: ^1.6.2
buffer: ^6.0.3
clsx: ^2.0.0
cnchar: ^3.2.4
Expand Down