@kubb/plugin-axios 5.1.0 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-axios",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -61,18 +61,18 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@kubb/plugin-ts": "^5.0.0",
64
- "@kubb/plugin-zod": "^5.1.0"
64
+ "@kubb/plugin-zod": "^5.1.2"
65
65
  },
66
66
  "devDependencies": {
67
- "axios": "^1.19.0",
68
- "kubb": "^5.0.1",
69
- "typescript": "^6.0.3",
70
67
  "@internals/client": "0.0.0",
71
- "@internals/shared": "0.0.0"
68
+ "@internals/shared": "0.0.0",
69
+ "axios": "^1.20.0",
70
+ "kubb": "^5.0.4",
71
+ "typescript": "^6.0.3"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "axios": "^1.19.0",
75
- "kubb": "^5.0.1"
75
+ "kubb": "^5.0.4"
76
76
  },
77
77
  "peerDependenciesMeta": {
78
78
  "axios": {
@@ -370,12 +370,12 @@ export async function resolveAuth(params: {
370
370
  if (scheme.in === 'query') {
371
371
  if (query[name] === undefined) query[name] = token
372
372
  } else if (scheme.in === 'cookie') {
373
- headers.Cookie = [headers.Cookie, `${name}=${token}`].filter(Boolean).join('; ')
373
+ headers['Cookie'] = [headers['Cookie'], `${name}=${token}`].filter(Boolean).join('; ')
374
374
  } else if (!hasHeader(headers, name)) {
375
375
  headers[name] = token
376
376
  }
377
377
  } else if (!hasHeader(headers, 'Authorization')) {
378
- headers.Authorization = scheme.scheme === 'basic' ? `Basic ${btoa(token)}` : `Bearer ${token}`
378
+ headers['Authorization'] = scheme.scheme === 'basic' ? `Basic ${btoa(token)}` : `Bearer ${token}`
379
379
  }
380
380
  return
381
381
  }
@@ -456,7 +456,7 @@ async function resolveRequest<TBody, TRequest, TResponse>({
456
456
 
457
457
  if (requestConfig.cookies) {
458
458
  const cookie = serializeCookies(requestConfig.cookies, requestConfig.styles?.cookie)
459
- if (cookie) headers.Cookie = [headers.Cookie, cookie].filter(Boolean).join('; ')
459
+ if (cookie) headers['Cookie'] = [headers['Cookie'], cookie].filter(Boolean).join('; ')
460
460
  }
461
461
 
462
462
  const validatedBody = await runValidator(requestConfig.validator?.request, requestConfig.body)
@@ -126,11 +126,22 @@ export function isDefaultJsonBody(body: unknown): boolean {
126
126
  return body !== undefined && body !== null && !isFormBody(body)
127
127
  }
128
128
 
129
+ /**
130
+ * Emits a `bigint` (`format: int64`) as a JSON number, which `JSON.stringify` refuses to do itself.
131
+ * Past the safe-integer range it throws, so an id never goes out silently truncated.
132
+ */
133
+ function jsonReplacer(_key: string, value: unknown): unknown {
134
+ if (typeof value !== 'bigint') return value
135
+ if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)
136
+ throw new TypeError(`Cannot serialize ${value}n as JSON without losing precision, register a serializer.body to send it another way.`)
137
+ return Number(value)
138
+ }
139
+
129
140
  function appendFormDataValue({ formData, key, value, contentType }: { formData: FormData; key: string; value: unknown; contentType?: string }): void {
130
141
  if (value === undefined || value === null) return
131
142
  if (value instanceof Blob) formData.append(key, value)
132
143
  else if (typeof value === 'object' && !(value instanceof Date)) {
133
- const json = JSON.stringify(value)
144
+ const json = JSON.stringify(value, jsonReplacer)
134
145
  // A part's media type can only be set by wrapping the value in a typed Blob.
135
146
  formData.append(key, contentType ? new Blob([json], { type: contentType }) : json)
136
147
  } else formData.append(key, toValue(value))
@@ -166,7 +177,7 @@ export const defaultBodySerializer: BodySerializer = ({ body, contentType, encod
166
177
  if (encoding) return serializeUrlencodedBody(body as Record<string, unknown>, encoding)
167
178
  return new URLSearchParams(body as Record<string, string>)
168
179
  }
169
- return JSON.stringify(body)
180
+ return JSON.stringify(body, jsonReplacer)
170
181
  }
171
182
 
172
183
  function serializeUrlencodedBody(body: Record<string, unknown>, encoding: Record<string, BodyEncoding>): string {