Skip to content

Commit

Permalink
[dep] Upgrade axios from 0.21.4 to 1.6.0 (#1108)
Browse files Browse the repository at this point in the history
* [dep] Upgrade axios from `0.21.4` to `1.6.0`

* Fix jest config

* Fix axios in standalone binary

* Fix bug when sending FormData

This bug lead to a silent error,
with a `Decoder has partially decoded field` warning
in our backend. Maybe the boundary was incorrect.

This bug gets fixed with
form-data/form-data@v3.0.1...v4.0.0

I also tried with `axios@1.6.1`, but it didn't work.

* Do not return early in `formatBackendErrors`
  • Loading branch information
Drarig29 authored Nov 10, 2023
1 parent 3dd9125 commit 81bf230
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 48 deletions.
11 changes: 7 additions & 4 deletions jest.config-standalone.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module.exports = {
preset: 'ts-jest',
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json',
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
roots: ['standalone-e2e'],
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"pkg": {
"scripts": [
"dist/commands/*/*.js"
],
"assets": [
"node_modules/axios/dist/node/axios.cjs"
]
},
"scripts": {
Expand Down Expand Up @@ -77,14 +80,14 @@
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"async-retry": "1.3.1",
"axios": "0.21.4",
"axios": "1.6.0",
"chalk": "3.0.0",
"clipanion": "^3.2.1",
"datadog-metrics": "0.9.3",
"deep-extend": "0.6.0",
"deep-object-diff": "^1.1.9",
"fast-xml-parser": "^4.2.5",
"form-data": "3.0.0",
"form-data": "4.0.0",
"fuzzy": "^0.1.3",
"glob": "7.1.4",
"google-auth-library": "^8.9.0",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/gate/__tests__/evaluate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AxiosResponse} from 'axios'
import type {AxiosResponse, InternalAxiosRequestConfig} from 'axios'

import {createCommand} from '../../../helpers/__tests__/fixtures'

Expand Down Expand Up @@ -158,7 +158,7 @@ describe('evaluate', () => {
status: 200,
statusText: 'OK',
headers: {},
config: {},
config: {} as InternalAxiosRequestConfig,
data: {
data: {
attributes: {
Expand All @@ -176,7 +176,7 @@ describe('evaluate', () => {
status: 200,
statusText: 'OK',
headers: {},
config: {},
config: {} as InternalAxiosRequestConfig,
data: {
data: {
attributes: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gate/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Writable} from 'stream'

import {AxiosPromise, AxiosRequestConfig} from 'axios'
import type {AxiosPromise, AxiosRequestConfig} from 'axios'

import {getRequestBuilder} from '../../helpers/utils'

Expand Down
2 changes: 1 addition & 1 deletion src/commands/gate/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Writable} from 'stream'

import {AxiosPromise} from 'axios'
import type {AxiosPromise} from 'axios'

import {SpanTags} from '../../helpers/interfaces'

Expand Down
3 changes: 2 additions & 1 deletion src/commands/git-metadata/gitdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {mkdtemp} from 'fs/promises'
import os from 'os'
import path from 'path'

import {AxiosResponse} from 'axios'
import type {AxiosResponse} from 'axios'

import FormData from 'form-data'
import {lte} from 'semver'
import * as simpleGit from 'simple-git'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/junit/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AxiosPromise, AxiosResponse} from 'axios'
import type {AxiosPromise, AxiosResponse} from 'axios'

import {SpanTags} from '../../helpers/interfaces'

Expand Down
2 changes: 1 addition & 1 deletion src/commands/sarif/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Writable} from 'stream'

import {AxiosPromise, AxiosResponse} from 'axios'
import type {AxiosPromise, AxiosResponse} from 'axios'

import {SpanTags} from '../../helpers/interfaces'

Expand Down
2 changes: 1 addition & 1 deletion src/commands/sbom/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios'
import type {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios'

import {CONTENT_TYPE_HEADER, CONTENT_TYPE_VALUE_JSON, CONTENT_TYPE_VALUE_PROTOBUF, METHOD_POST} from '../../constants'
import {getRequestBuilder} from '../../helpers/utils'
Expand Down
3 changes: 2 additions & 1 deletion src/commands/sbom/upload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'fs'
import process from 'process'

import type {AxiosPromise, AxiosResponse} from 'axios'

import Ajv from 'ajv'
import {AxiosPromise, AxiosResponse} from 'axios'
import chalk from 'chalk'
import {Command, Option} from 'clipanion'

Expand Down
4 changes: 3 additions & 1 deletion src/commands/synthetics/__tests__/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {AxiosError, AxiosResponse, default as axios} from 'axios'
import type {AxiosError, AxiosResponse} from 'axios'

import axios from 'axios'

import {ProxyConfiguration} from '../../../helpers/utils'

Expand Down
7 changes: 4 additions & 3 deletions src/commands/synthetics/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as http from 'http'
import * as net from 'net'
import {URL} from 'url'

import {AxiosError, AxiosResponse} from 'axios'
import type {AxiosError, AxiosResponse, InternalAxiosRequestConfig} from 'axios'

import WebSocket, {Server as WebSocketServer} from 'ws'

import {ProxyConfiguration} from '../../../helpers/utils'
Expand Down Expand Up @@ -84,8 +85,8 @@ export const ciConfig: RunTestsCommandConfig = {
}

export const getAxiosHttpError = (status: number, {errors, message}: {errors?: string[]; message?: string}) => {
const serverError = new Error(message) as AxiosError
serverError.config = {baseURL: MOCK_BASE_URL, url: 'example'}
const serverError = new Error(message) as AxiosError<any, any> & {config: InternalAxiosRequestConfig}
serverError.config = {baseURL: MOCK_BASE_URL, url: 'example'} as InternalAxiosRequestConfig
serverError.response = {data: {errors}, status} as AxiosResponse

return serverError
Expand Down
9 changes: 5 additions & 4 deletions src/commands/synthetics/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {stringify} from 'querystring'

import {AxiosError, AxiosPromise, AxiosRequestConfig} from 'axios'
import type {AxiosError, AxiosPromise, AxiosRequestConfig} from 'axios'

import FormData from 'form-data'

import {getRequestBuilder} from '../../helpers/utils'
Expand Down Expand Up @@ -39,7 +40,7 @@ export class EndpointError extends Error {

export const formatBackendErrors = (requestError: AxiosError<BackendError>) => {
if (requestError.response?.data?.errors) {
const serverHead = `query on ${requestError.config.baseURL}${requestError.config.url} returned:`
const serverHead = `query on ${requestError.config?.baseURL}${requestError.config?.url} returned:`
const errors = requestError.response.data.errors
if (errors.length > 1) {
const formattedErrors = errors.map((message: string) => ` - ${message}`)
Expand All @@ -48,11 +49,11 @@ export const formatBackendErrors = (requestError: AxiosError<BackendError>) => {
} else if (errors.length) {
return `${serverHead} "${errors[0]}"`
} else {
return `error querying ${requestError.config.baseURL}${requestError.config.url}`
return `error querying ${requestError.config?.baseURL}${requestError.config?.url}`
}
}

return `could not query ${requestError.config.baseURL}${requestError.config.url}\n${requestError.message}`
return `could not query ${requestError.config?.baseURL}${requestError.config?.url}\n${requestError.message}`
}

const triggerTests = (request: (args: AxiosRequestConfig) => AxiosPromise<Trigger>) => async (data: Payload) => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/trace/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AxiosPromise, AxiosResponse} from 'axios'
import type {AxiosPromise, AxiosResponse} from 'axios'

export const CIRCLECI = 'circleci'
export const JENKINS = 'jenkins'
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/__tests__/retry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AxiosPromise} from 'axios'
import type {AxiosPromise, AxiosResponseHeaders, InternalAxiosRequestConfig} from 'axios'

import {retryRequest} from '../retry'

Expand All @@ -11,9 +11,9 @@ describe('retry', () => {
i = i + 1
if (errors[i] === undefined) {
return Promise.resolve({
config: {},
config: {} as InternalAxiosRequestConfig,
data: {},
headers: undefined,
headers: {} as AxiosResponseHeaders,
status: 200,
statusText: '',
})
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import http from 'http'
import {AddressInfo} from 'net'

import {AxiosPromise, AxiosRequestConfig, default as axios} from 'axios'
import type {AxiosPromise, AxiosRequestConfig} from 'axios'

import axios from 'axios'
import {createProxy} from 'proxy'
import {ProxyAgent} from 'proxy-agent'

Expand Down
3 changes: 1 addition & 2 deletions src/helpers/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {AxiosPromise, AxiosRequestConfig} from 'axios'
import type {Writable} from 'stream'

import {AxiosPromise, AxiosRequestConfig} from 'axios'

import {
CI_ENV_VARS,
CI_JOB_NAME,
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import fs, {existsSync} from 'fs'
import {promisify} from 'util'

import type {SpanTag, SpanTags} from './interfaces'
import type {AxiosRequestConfig} from 'axios'

import {AxiosRequestConfig, default as axios} from 'axios'
import axios from 'axios'
import {BaseContext, CommandClass, Cli} from 'clipanion'
import deepExtend from 'deep-extend'
import {ProxyAgent} from 'proxy-agent'
Expand Down Expand Up @@ -176,7 +177,7 @@ export const getRequestBuilder = (options: RequestOptions) => {
'DD-API-KEY': apiKey,
...(appKey ? {'DD-APPLICATION-KEY': appKey} : {}),
...args.headers,
},
} as NonNullable<typeof args.headers>,
}

if (overrideUrl !== undefined) {
Expand Down
32 changes: 17 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ __metadata:
async-retry: 1.3.1
aws-sdk-client-mock: ^2.1.1
aws-sdk-client-mock-jest: ^2.1.1
axios: 0.21.4
axios: 1.6.0
chalk: 3.0.0
clipanion: ^3.2.1
datadog-metrics: 0.9.3
Expand All @@ -2025,7 +2025,7 @@ __metadata:
eslint-plugin-prefer-arrow: ^1.2.3
eslint-plugin-prettier: 4.0.0
fast-xml-parser: ^4.2.5
form-data: 3.0.0
form-data: 4.0.0
fuzzy: ^0.1.3
glob: 7.1.4
google-auth-library: ^8.9.0
Expand Down Expand Up @@ -4468,12 +4468,14 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:0.21.4":
version: 0.21.4
resolution: "axios@npm:0.21.4"
"axios@npm:1.6.0":
version: 1.6.0
resolution: "axios@npm:1.6.0"
dependencies:
follow-redirects: ^1.14.0
checksum: 44245f24ac971e7458f3120c92f9d66d1fc695e8b97019139de5b0cc65d9b8104647db01e5f46917728edfc0cfd88eb30fc4c55e6053eef4ace76768ce95ff3c
follow-redirects: ^1.15.0
form-data: ^4.0.0
proxy-from-env: ^1.1.0
checksum: c7c9f2ae9e0b9bad7d6f9a4dff030930b12ee667dedf54c3c776714f91681feb743c509ac0796ae5c01e12c4ab4a2bee74905068dd200fbc1ab86f9814578fb0
languageName: node
linkType: hard

Expand Down Expand Up @@ -6257,13 +6259,13 @@ __metadata:
languageName: node
linkType: hard

"follow-redirects@npm:^1.14.0":
version: 1.15.2
resolution: "follow-redirects@npm:1.15.2"
"follow-redirects@npm:^1.15.0":
version: 1.15.3
resolution: "follow-redirects@npm:1.15.3"
peerDependenciesMeta:
debug:
optional: true
checksum: faa66059b66358ba65c234c2f2a37fcec029dc22775f35d9ad6abac56003268baf41e55f9ee645957b32c7d9f62baf1f0b906e68267276f54ec4b4c597c2b190
checksum: 584da22ec5420c837bd096559ebfb8fe69d82512d5585004e36a3b4a6ef6d5905780e0c74508c7b72f907d1fa2b7bd339e613859e9c304d0dc96af2027fd0231
languageName: node
linkType: hard

Expand All @@ -6286,14 +6288,14 @@ __metadata:
languageName: node
linkType: hard

"form-data@npm:3.0.0":
version: 3.0.0
resolution: "form-data@npm:3.0.0"
"form-data@npm:4.0.0, form-data@npm:^4.0.0":
version: 4.0.0
resolution: "form-data@npm:4.0.0"
dependencies:
asynckit: ^0.4.0
combined-stream: ^1.0.8
mime-types: ^2.1.12
checksum: 60ec3fe7e23154949ab6fef31baedf5afbfb8d6441ea8d19b211b43a5d0448be2918c9bba6218cade56a7cbd43f670d6e75f41f626f8d397d56bf8c60f4a829d
checksum: 01135bf8675f9d5c61ff18e2e2932f719ca4de964e3be90ef4c36aacfc7b9cb2fceb5eca0b7e0190e3383fe51c5b37f4cb80b62ca06a99aaabfcfd6ac7c9328c
languageName: node
linkType: hard

Expand Down

0 comments on commit 81bf230

Please sign in to comment.