Browse Source

chore: bump axios version

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/6949/head
mertmit 8 months ago
parent
commit
5c4a18499c
  1. 4
      packages/nocodb-sdk/package.json
  2. 76
      packages/nocodb-sdk/src/lib/Api.ts
  3. 2
      packages/nocodb/package.json
  4. 48
      pnpm-lock.yaml
  5. 85
      scripts/sdk/templates/http-clients/axios-http-client.eta
  6. 2
      tests/playwright/package.json

4
packages/nocodb-sdk/package.json

@ -38,7 +38,7 @@
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"axios": "^0.21.1",
"axios": "^1.6.1",
"jsep": "^1.3.8"
},
"devDependencies": {
@ -69,4 +69,4 @@
"prettier": {
"singleQuote": true
}
}
}

76
packages/nocodb-sdk/src/lib/Api.ts

@ -2761,7 +2761,13 @@ export interface NotificationUpdateType {
is_read?: boolean;
}
import axios, { AxiosInstance, AxiosRequestConfig, ResponseType } from 'axios';
import type {
AxiosInstance,
AxiosRequestConfig,
HeadersDefaults,
ResponseType,
} from 'axios';
import axios from 'axios';
export type QueryParamsType = Record<string | number, any>;
@ -2783,7 +2789,10 @@ export interface FullRequestParams
body?: unknown;
}
export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'path'>;
export type RequestParams = Omit<
FullRequestParams,
'body' | 'method' | 'query' | 'path'
>;
export interface ApiConfig<SecurityDataType = unknown>
extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
@ -2798,6 +2807,7 @@ export enum ContentType {
Json = 'application/json',
FormData = 'multipart/form-data',
UrlEncoded = 'application/x-www-form-urlencoded',
Text = 'text/plain',
}
export class HttpClient<SecurityDataType = unknown> {
@ -2826,43 +2836,50 @@ export class HttpClient<SecurityDataType = unknown> {
this.securityData = data;
};
private mergeRequestParams(
protected mergeRequestParams(
params1: AxiosRequestConfig,
params2?: AxiosRequestConfig
): AxiosRequestConfig {
const method = params1.method || (params2 && params2.method);
return {
...this.instance.defaults,
...params1,
...(params2 || {}),
headers: {
...(this.instance.defaults.headers || {}),
...((method &&
this.instance.defaults.headers[
method.toLowerCase() as keyof HeadersDefaults
]) ||
{}),
...(params1.headers || {}),
...((params2 && params2.headers) || {}),
},
};
}
protected createFormData(input: Record<string, unknown>): FormData {
if (input instanceof FormData) {
return input;
protected stringifyFormItem(formItem: unknown) {
if (typeof formItem === 'object' && formItem !== null) {
return JSON.stringify(formItem);
} else {
return `${formItem}`;
}
}
protected createFormData(input: Record<string, unknown>): FormData {
return Object.keys(input || {}).reduce((formData, key) => {
const property = input[key];
if (property instanceof Blob) {
formData.append(key, property);
} else if (typeof property === 'object' && property !== null) {
if (Array.isArray(property)) {
// eslint-disable-next-line functional/no-loop-statement
for (const prop of property) {
formData.append(`${key}[]`, prop);
}
} else {
formData.append(key, JSON.stringify(property));
}
} else {
formData.append(key, `${property}`);
const propertyContent: any[] =
property instanceof Array ? property : [property];
for (const formItem of propertyContent) {
const isFileType = formItem instanceof Blob || formItem instanceof File;
formData.append(
key,
isFileType ? formItem : this.stringifyFormItem(formItem)
);
}
return formData;
}, new FormData());
}
@ -2883,7 +2900,7 @@ export class HttpClient<SecurityDataType = unknown> {
(await this.securityWorker(this.securityData))) ||
{};
const requestParams = this.mergeRequestParams(params, secureParams);
const responseFormat = (format && this.format) || void 0;
const responseFormat = format || this.format || undefined;
if (
type === ContentType.FormData &&
@ -2891,21 +2908,26 @@ export class HttpClient<SecurityDataType = unknown> {
body !== null &&
typeof body === 'object'
) {
requestParams.headers.common = { Accept: '*/*' };
requestParams.headers.post = {};
requestParams.headers.put = {};
body = this.createFormData(body as Record<string, unknown>);
}
if (
type === ContentType.Text &&
body &&
body !== null &&
typeof body !== 'string'
) {
body = JSON.stringify(body);
}
return this.instance
.request({
...requestParams,
headers: {
...(requestParams.headers || {}),
...(type && type !== ContentType.FormData
? { 'Content-Type': type }
: {}),
...(requestParams.headers || {}),
},
params: query,
responseType: responseFormat,

2
packages/nocodb/package.json

@ -76,7 +76,7 @@
"auto-bind": "^4.0.0",
"aws-kcl": "^2.2.2",
"aws-sdk": "^2.1455.0",
"axios": "^0.21.1",
"axios": "^1.6.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.2",
"boxen": "^5.1.2",

48
pnpm-lock.yaml

@ -473,8 +473,8 @@ importers:
specifier: ^2.1455.0
version: 2.1455.0
axios:
specifier: ^0.21.1
version: 0.21.1(debug@4.3.4)
specifier: ^1.6.1
version: 1.6.2(debug@4.3.4)
bcryptjs:
specifier: ^2.4.3
version: 2.4.3
@ -876,8 +876,8 @@ importers:
packages/nocodb-sdk:
dependencies:
axios:
specifier: ^0.21.1
version: 0.21.1
specifier: ^1.6.1
version: 1.6.2
jsep:
specifier: ^1.3.8
version: 1.3.8
@ -927,6 +927,9 @@ importers:
tests/playwright:
dependencies:
axios:
specifier: ^1.6.1
version: 1.6.2
body-parser:
specifier: ^1.20.1
version: 1.20.1
@ -958,9 +961,6 @@ importers:
'@typescript-eslint/parser':
specifier: ^6.1.0
version: 6.1.0(eslint@8.33.0)(typescript@5.2.2)
axios:
specifier: ^0.24.0
version: 0.24.0
dotenv:
specifier: ^16.0.3
version: 16.0.3
@ -10538,14 +10538,6 @@ packages:
is-retry-allowed: 2.2.0
dev: false
/axios@0.21.1:
resolution: {integrity: sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==}
dependencies:
follow-redirects: 1.15.2(debug@3.2.7)
transitivePeerDependencies:
- debug
dev: false
/axios@0.21.1(debug@4.3.4):
resolution: {integrity: sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==}
dependencies:
@ -10554,14 +10546,6 @@ packages:
- debug
dev: false
/axios@0.24.0:
resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==}
dependencies:
follow-redirects: 1.15.2(debug@3.2.7)
transitivePeerDependencies:
- debug
dev: true
/axios@0.24.0(debug@4.3.4):
resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==}
dependencies:
@ -10596,15 +10580,24 @@ packages:
- debug
dev: false
/axios@1.5.0:
resolution: {integrity: sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==}
/axios@1.6.2:
resolution: {integrity: sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==}
dependencies:
follow-redirects: 1.15.2(debug@3.2.7)
form-data: 4.0.0
proxy-from-env: 1.1.0
transitivePeerDependencies:
- debug
dev: true
/axios@1.6.2(debug@4.3.4):
resolution: {integrity: sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==}
dependencies:
follow-redirects: 1.15.2(debug@4.3.4)
form-data: 4.0.0
proxy-from-env: 1.1.0
transitivePeerDependencies:
- debug
dev: false
/b4a@1.6.4:
resolution: {integrity: sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==}
@ -19532,7 +19525,7 @@ packages:
'@yarnpkg/lockfile': 1.1.0
'@yarnpkg/parsers': 3.0.0-rc.46
'@zkochan/js-yaml': 0.0.6
axios: 1.5.0
axios: 1.6.2
chalk: 4.1.2
cli-cursor: 3.1.0
cli-spinners: 2.6.1
@ -20914,7 +20907,6 @@ packages:
/proxy-from-env@1.1.0:
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
dev: true
/prr@1.0.1:
resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==}

85
scripts/sdk/templates/http-clients/axios-http-client.eta

@ -2,7 +2,8 @@
const { apiConfig, generateResponses, config } = it;
%>
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from "axios";
import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults, ResponseType, AxiosResponse } from "axios";
import axios from "axios";
export type QueryParamsType = Record<string | number, any>;
@ -23,7 +24,7 @@ export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "pa
body?: unknown;
}
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "path">;
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
@ -35,6 +36,7 @@ export enum ContentType {
Json = "application/json",
FormData = "multipart/form-data",
UrlEncoded = "application/x-www-form-urlencoded",
Text = "text/plain",
}
export class HttpClient<SecurityDataType = unknown> {
@ -55,43 +57,44 @@ export class HttpClient<SecurityDataType = unknown> {
this.securityData = data
}
private mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig {
return {
...this.instance.defaults,
...params1,
...(params2 || {}),
headers: {
...(this.instance.defaults.headers || {}),
...(params1.headers || {}),
...((params2 && params2.headers) || {}),
},
};
protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig {
const method = params1.method || (params2 && params2.method)
return {
...this.instance.defaults,
...params1,
...(params2 || {}),
headers: {
...((method && this.instance.defaults.headers[method.toLowerCase() as keyof HeadersDefaults]) || {}),
...(params1.headers || {}),
...((params2 && params2.headers) || {}),
},
};
}
protected stringifyFormItem(formItem: unknown) {
if (typeof formItem === "object" && formItem !== null) {
return JSON.stringify(formItem);
} else {
return `${formItem}`;
}
}
protected createFormData(input: Record<string, unknown>): FormData {
if (input instanceof FormData) {
return input;
return Object.keys(input || {}).reduce((formData, key) => {
const property = input[key];
const propertyContent: any[] = (property instanceof Array) ? property : [property]
for (const formItem of propertyContent) {
const isFileType = formItem instanceof Blob || formItem instanceof File;
formData.append(
key,
isFileType ? formItem : this.stringifyFormItem(formItem)
);
}
return Object.keys(input || {}).reduce((formData, key) => {
const property = input[key];
if (property instanceof Blob) {
formData.append(key, property)
} else if (typeof property === 'object' && property !== null) {
if (Array.isArray(property)) {
// eslint-disable-next-line functional/no-loop-statement
for (const prop of property) {
formData.append(`${key}[]`, prop)
}
} else {
formData.append(key, JSON.stringify(property))
}
} else {
formData.append(key, `${property}`)
}
return formData;
}, new FormData());
return formData;
}, new FormData());
}
public request = async <T = any, _E = any>({
@ -110,21 +113,21 @@ export class HttpClient<SecurityDataType = unknown> {
<% } %>
const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {};
const requestParams = this.mergeRequestParams(params, secureParams);
const responseFormat = (format && this.format) || void 0;
const responseFormat = (format || this.format) || undefined;
if (type === ContentType.FormData && body && body !== null && typeof body === "object") {
requestParams.headers.common = { Accept: "*/*" };
requestParams.headers.post = {};
requestParams.headers.put = {};
body = this.createFormData(body as Record<string, unknown>);
}
if (type === ContentType.Text && body && body !== null && typeof body !== "string") {
body = JSON.stringify(body);
}
return this.instance.request({
...requestParams,
headers: {
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
...(requestParams.headers || {}),
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
},
params: query,
responseType: responseFormat,
@ -139,4 +142,4 @@ export class HttpClient<SecurityDataType = unknown> {
});
<% } %>
};
}
}

2
tests/playwright/package.json

@ -40,6 +40,7 @@
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
"axios": "^1.6.1",
"body-parser": "^1.20.1",
"dayjs": "^1.11.9",
"express": "^4.18.1",
@ -52,7 +53,6 @@
"@playwright/test": "1.38.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"axios": "^0.24.0",
"dotenv": "^16.0.3",
"eslint": "^8.22.0",
"eslint-config-prettier": "^6.15.0",

Loading…
Cancel
Save