@kubb/plugin-fetch 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-fetch",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -61,16 +61,16 @@
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
- "kubb": "^5.0.1",
68
- "typescript": "^6.0.3",
67
+ "@internals/client": "0.0.0",
69
68
  "@internals/shared": "0.0.0",
70
- "@internals/client": "0.0.0"
69
+ "kubb": "^5.0.4",
70
+ "typescript": "^6.0.3"
71
71
  },
72
72
  "peerDependencies": {
73
- "kubb": "^5.0.1"
73
+ "kubb": "^5.0.4"
74
74
  },
75
75
  "engines": {
76
76
  "node": ">=22"
@@ -405,12 +405,12 @@ export async function resolveAuth(params: {
405
405
  if (scheme.in === 'query') {
406
406
  if (query[name] === undefined) query[name] = token
407
407
  } else if (scheme.in === 'cookie') {
408
- headers.Cookie = [headers.Cookie, `${name}=${token}`].filter(Boolean).join('; ')
408
+ headers['Cookie'] = [headers['Cookie'], `${name}=${token}`].filter(Boolean).join('; ')
409
409
  } else if (!hasHeader(headers, name)) {
410
410
  headers[name] = token
411
411
  }
412
412
  } else if (!hasHeader(headers, 'Authorization')) {
413
- headers.Authorization = scheme.scheme === 'basic' ? `Basic ${btoa(token)}` : `Bearer ${token}`
413
+ headers['Authorization'] = scheme.scheme === 'basic' ? `Basic ${btoa(token)}` : `Bearer ${token}`
414
414
  }
415
415
  return
416
416
  }
@@ -491,7 +491,7 @@ async function resolveRequest<TBody, TRequest, TResponse>({
491
491
 
492
492
  if (requestConfig.cookies) {
493
493
  const cookie = serializeCookies(requestConfig.cookies, requestConfig.styles?.cookie)
494
- if (cookie) headers.Cookie = [headers.Cookie, cookie].filter(Boolean).join('; ')
494
+ if (cookie) headers['Cookie'] = [headers['Cookie'], cookie].filter(Boolean).join('; ')
495
495
  }
496
496
 
497
497
  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 {