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" "preinstall": "npx only-allow pnpm"
}, },
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^1.6.1",
"jsep": "^1.3.8" "jsep": "^1.3.8"
}, },
"devDependencies": { "devDependencies": {
@ -69,4 +69,4 @@
"prettier": { "prettier": {
"singleQuote": true "singleQuote": true
} }
} }

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

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

2
packages/nocodb/package.json

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

48
pnpm-lock.yaml

@ -473,8 +473,8 @@ importers:
specifier: ^2.1455.0 specifier: ^2.1455.0
version: 2.1455.0 version: 2.1455.0
axios: axios:
specifier: ^0.21.1 specifier: ^1.6.1
version: 0.21.1(debug@4.3.4) version: 1.6.2(debug@4.3.4)
bcryptjs: bcryptjs:
specifier: ^2.4.3 specifier: ^2.4.3
version: 2.4.3 version: 2.4.3
@ -876,8 +876,8 @@ importers:
packages/nocodb-sdk: packages/nocodb-sdk:
dependencies: dependencies:
axios: axios:
specifier: ^0.21.1 specifier: ^1.6.1
version: 0.21.1 version: 1.6.2
jsep: jsep:
specifier: ^1.3.8 specifier: ^1.3.8
version: 1.3.8 version: 1.3.8
@ -927,6 +927,9 @@ importers:
tests/playwright: tests/playwright:
dependencies: dependencies:
axios:
specifier: ^1.6.1
version: 1.6.2
body-parser: body-parser:
specifier: ^1.20.1 specifier: ^1.20.1
version: 1.20.1 version: 1.20.1
@ -958,9 +961,6 @@ importers:
'@typescript-eslint/parser': '@typescript-eslint/parser':
specifier: ^6.1.0 specifier: ^6.1.0
version: 6.1.0(eslint@8.33.0)(typescript@5.2.2) version: 6.1.0(eslint@8.33.0)(typescript@5.2.2)
axios:
specifier: ^0.24.0
version: 0.24.0
dotenv: dotenv:
specifier: ^16.0.3 specifier: ^16.0.3
version: 16.0.3 version: 16.0.3
@ -10538,14 +10538,6 @@ packages:
is-retry-allowed: 2.2.0 is-retry-allowed: 2.2.0
dev: false 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): /axios@0.21.1(debug@4.3.4):
resolution: {integrity: sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==} resolution: {integrity: sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==}
dependencies: dependencies:
@ -10554,14 +10546,6 @@ packages:
- debug - debug
dev: false 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): /axios@0.24.0(debug@4.3.4):
resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==} resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==}
dependencies: dependencies:
@ -10596,15 +10580,24 @@ packages:
- debug - debug
dev: false dev: false
/axios@1.5.0: /axios@1.6.2:
resolution: {integrity: sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==} resolution: {integrity: sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==}
dependencies: dependencies:
follow-redirects: 1.15.2(debug@3.2.7) follow-redirects: 1.15.2(debug@3.2.7)
form-data: 4.0.0 form-data: 4.0.0
proxy-from-env: 1.1.0 proxy-from-env: 1.1.0
transitivePeerDependencies: transitivePeerDependencies:
- debug - 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: /b4a@1.6.4:
resolution: {integrity: sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==} resolution: {integrity: sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==}
@ -19532,7 +19525,7 @@ packages:
'@yarnpkg/lockfile': 1.1.0 '@yarnpkg/lockfile': 1.1.0
'@yarnpkg/parsers': 3.0.0-rc.46 '@yarnpkg/parsers': 3.0.0-rc.46
'@zkochan/js-yaml': 0.0.6 '@zkochan/js-yaml': 0.0.6
axios: 1.5.0 axios: 1.6.2
chalk: 4.1.2 chalk: 4.1.2
cli-cursor: 3.1.0 cli-cursor: 3.1.0
cli-spinners: 2.6.1 cli-spinners: 2.6.1
@ -20914,7 +20907,6 @@ packages:
/proxy-from-env@1.1.0: /proxy-from-env@1.1.0:
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
dev: true
/prr@1.0.1: /prr@1.0.1:
resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==} 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; 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>; export type QueryParamsType = Record<string | number, any>;
@ -23,7 +24,7 @@ export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "pa
body?: unknown; 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"> { export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void; securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
@ -35,6 +36,7 @@ export enum ContentType {
Json = "application/json", Json = "application/json",
FormData = "multipart/form-data", FormData = "multipart/form-data",
UrlEncoded = "application/x-www-form-urlencoded", UrlEncoded = "application/x-www-form-urlencoded",
Text = "text/plain",
} }
export class HttpClient<SecurityDataType = unknown> { export class HttpClient<SecurityDataType = unknown> {
@ -55,43 +57,44 @@ export class HttpClient<SecurityDataType = unknown> {
this.securityData = data this.securityData = data
} }
private mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig { protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig {
return { const method = params1.method || (params2 && params2.method)
...this.instance.defaults,
...params1, return {
...(params2 || {}), ...this.instance.defaults,
headers: { ...params1,
...(this.instance.defaults.headers || {}), ...(params2 || {}),
...(params1.headers || {}), headers: {
...((params2 && 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 { protected createFormData(input: Record<string, unknown>): FormData {
if (input instanceof FormData) { return Object.keys(input || {}).reduce((formData, key) => {
return input; 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]; return formData;
}, new FormData());
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());
} }
public request = async <T = any, _E = any>({ 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 secureParams = ((typeof secure === 'boolean' ? secure : this.secure) && this.securityWorker && (await this.securityWorker(this.securityData))) || {};
const requestParams = this.mergeRequestParams(params, secureParams); 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") { 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>); 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({ return this.instance.request({
...requestParams, ...requestParams,
headers: { headers: {
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
...(requestParams.headers || {}), ...(requestParams.headers || {}),
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
}, },
params: query, params: query,
responseType: responseFormat, 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" "preinstall": "npx only-allow pnpm"
}, },
"dependencies": { "dependencies": {
"axios": "^1.6.1",
"body-parser": "^1.20.1", "body-parser": "^1.20.1",
"dayjs": "^1.11.9", "dayjs": "^1.11.9",
"express": "^4.18.1", "express": "^4.18.1",
@ -52,7 +53,6 @@
"@playwright/test": "1.38.0", "@playwright/test": "1.38.0",
"@typescript-eslint/eslint-plugin": "^6.1.0", "@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0", "@typescript-eslint/parser": "^6.1.0",
"axios": "^0.24.0",
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"eslint": "^8.22.0", "eslint": "^8.22.0",
"eslint-config-prettier": "^6.15.0", "eslint-config-prettier": "^6.15.0",

Loading…
Cancel
Save