Skip to content

Commit b014b84

Browse files
authored
Merge pull request #370 from contentful/fix/types
fix: usage of axios [PHX-2738]
2 parents b746440 + d9a4f4a commit b014b84

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
"fast-copy": "^2.1.7",
4747
"lodash.isplainobject": "^4.0.6",
4848
"lodash.isstring": "^4.0.1",
49-
"p-throttle": "^4.1.1",
50-
"qs": "^6.11.2"
49+
"p-throttle": "^4.1.1"
5150
},
5251
"devDependencies": {
5352
"@babel/cli": "^7.12.8",
@@ -66,7 +65,6 @@
6665
"@types/jest": "^29.2.2",
6766
"@types/lodash.isplainobject": "^4.0.6",
6867
"@types/lodash.isstring": "^4.0.6",
69-
"@types/qs": "^6.9.5",
7068
"@typescript-eslint/eslint-plugin": "^5.11.0",
7169
"@typescript-eslint/parser": "^5.11.0",
7270
"axios": "^1.4.0",

src/create-http-client.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { AxiosRequestHeaders, AxiosStatic } from 'axios'
1+
import { AxiosRequestHeaders } from 'axios'
2+
import type { AxiosStatic } from 'axios'
23
import copy from 'fast-copy'
3-
import qs from 'qs'
44
import asyncToken from './async-token'
55

66
import rateLimitRetry from './rate-limit'
@@ -16,7 +16,7 @@ const HOST_REGEX = /^(?!\w+:\/\/)([^\s:]+\.?[^\s:]+)(?::(\d+))?(?!:)$/
1616
* @private
1717
* @param {AxiosStatic} axios - Axios library
1818
* @param {CreateHttpClientParams} options - Initialization parameters for the HTTP client
19-
* @return {ContentfulAxiosInstance} Initialized axios instance
19+
* @return {AxiosInstance} Initialized axios instance
2020
*/
2121
export default function createHttpClient(
2222
axios: AxiosStatic,
@@ -41,7 +41,6 @@ export default function createHttpClient(
4141
httpsAgent: false as const,
4242
timeout: 30000,
4343
throttle: 0,
44-
proxy: false as const,
4544
basePath: '',
4645
adapter: undefined,
4746
maxContentLength: 1073741824, // 1GB
@@ -90,11 +89,6 @@ export default function createHttpClient(
9089
headers: config.headers,
9190
httpAgent: config.httpAgent,
9291
httpsAgent: config.httpsAgent,
93-
paramsSerializer: {
94-
serialize: (params) => {
95-
return qs.stringify(params, { arrayFormat: 'repeat' })
96-
},
97-
},
9892
proxy: config.proxy,
9993
timeout: config.timeout,
10094
adapter: config.adapter,
@@ -106,6 +100,7 @@ export default function createHttpClient(
106100
requestLogger: config.requestLogger,
107101
retryOnError: config.retryOnError,
108102
}
103+
109104
const instance = axios.create(axiosOptions) as AxiosInstance
110105
instance.httpClientParams = options
111106

@@ -116,8 +111,8 @@ export default function createHttpClient(
116111
* and the version of the library comes from different places depending
117112
* on whether it's a browser build or a node.js build.
118113
* @private
119-
* @param {CreateHttpClientParams} httpClientParams - Initialization parameters for the HTTP client
120-
* @return {ContentfulAxiosInstance} Initialized axios instance
114+
* @param {CreateHttpClientParams} newParams - Initialization parameters for the HTTP client
115+
* @return {AxiosInstance} Initialized axios instance
121116
*/
122117
instance.cloneWithNewParams = function (
123118
newParams: Partial<CreateHttpClientParams>

src/error-handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import isPlainObject from 'lodash.isplainobject'
2-
import type { AxiosError } from 'axios'
32
import type { ContentfulErrorData } from './types'
43

54
/**
@@ -10,7 +9,7 @@ import type { ContentfulErrorData } from './types'
109
* and the expected error codes.
1110
* @private
1211
*/
13-
export default function errorHandler(errorResponse: AxiosError<ContentfulErrorData>): never {
12+
export default function errorHandler(errorResponse: any): never {
1413
const { config, response } = errorResponse
1514
let errorName
1615

src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios'
2+
import { AxiosHeaderValue, AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios'
33

44
import type {
55
AxiosInstance as OriginalAxiosInstance,
@@ -64,7 +64,7 @@ export type CreateHttpClientParams = {
6464
logHandler?: DefaultOptions['logHandler']
6565

6666
/** Optional additional headers */
67-
headers?: AxiosRequestHeaders
67+
headers?: AxiosRequestHeaders | Record<string, AxiosHeaderValue>
6868

6969
defaultHostname?: string
7070

@@ -122,7 +122,7 @@ export type ContentfulErrorData = {
122122
statusText?: string
123123
requestId?: string
124124
message: string
125-
details: Record<string, unknown>
126-
request?: Record<string, unknown>
125+
details: Record<string, any>
126+
request?: Record<string, any>
127127
sys?: { id?: string }
128128
}

0 commit comments

Comments
 (0)