api-def 0.10.2 → 0.11.0-alpha.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/cjs/ApiTypes.d.ts CHANGED
@@ -4,7 +4,7 @@ import type RequestContext from "./RequestContext";
4
4
  import type { Validation } from "./Validation";
5
5
  import type RequestBackend from "./backend/RequestBackend";
6
6
  export type AcceptableStatus = number | [min: number, max: number];
7
- export type Headers = Record<string, string | number | boolean | null | undefined>;
7
+ export type RawHeaders = Record<string, string | number | boolean | null | undefined>;
8
8
  export type Params = string;
9
9
  export type Query = string | undefined | Record<string, any>;
10
10
  export type Body = string | number | Record<string, any>;
@@ -14,7 +14,7 @@ export interface ApiResponse<T = any> {
14
14
  readonly url: string;
15
15
  readonly status: number;
16
16
  readonly data: T;
17
- readonly headers: Record<string, string>;
17
+ readonly headers: Headers;
18
18
  readonly state: State;
19
19
  }
20
20
  export type RequestLock = string | false;
@@ -35,7 +35,7 @@ export interface BaseRequestConfig {
35
35
  lock?: RequestLock;
36
36
  credentials?: "omit" | "same-origin" | "include";
37
37
  retry?: number | false | RetryOptions;
38
- headers?: Readonly<Headers>;
38
+ headers?: Readonly<RawHeaders>;
39
39
  acceptableStatus?: AcceptableStatus[];
40
40
  /**
41
41
  * @deprecated use `queryHandling.stringify` instead
@@ -1,4 +1,4 @@
1
- import type { ApiResponse, Body, Headers, Params, Query, State } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Params, Query, RawHeaders, State } from "./ApiTypes";
2
2
  export interface ApiMockingConfig {
3
3
  enabled: boolean | (() => boolean);
4
4
  }
@@ -6,14 +6,14 @@ export interface MockRequest<TResponse = any, TParams extends Params | undefined
6
6
  params: TParams extends Params ? Record<TParams, string> : {};
7
7
  body: TBody;
8
8
  query: TQuery;
9
- headers: Readonly<Headers>;
9
+ headers: Readonly<RawHeaders>;
10
10
  url: string;
11
11
  state: TState;
12
12
  }
13
13
  export interface MockResponse<TResponse = any, TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State> {
14
14
  statusCode: number;
15
15
  response: TResponse | undefined;
16
- headers: Headers;
16
+ headers: RawHeaders;
17
17
  status(statusCode: number): this;
18
18
  send(response: TResponse): this;
19
19
  }
@@ -1,2 +1,2 @@
1
- import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Query, type RequestConfig, type State } from "./ApiTypes";
2
- export declare const computeRequestConfig: <TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
1
+ import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Params, type Query, type RequestConfig, type State } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
@@ -1,6 +1,6 @@
1
1
  import type { Api } from "./Api";
2
2
  import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
- import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost, State } from "./ApiTypes";
3
+ import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost, State } from "./ApiTypes";
4
4
  import type { EndpointMockingConfig } from "./MockingTypes";
5
5
  import type { RequestError } from "./RequestError";
6
6
  import type { Validation } from "./Validation";
@@ -36,7 +36,7 @@ export default class RequestContext<TResponse = any, TParams extends Params | un
36
36
  get responseType(): ResponseType | undefined;
37
37
  private initMiddleware;
38
38
  private generateKey;
39
- updateHeaders(newHeaders: Headers): this;
39
+ updateHeaders(newHeaders: RawHeaders): this;
40
40
  private parseRequestBody;
41
41
  getParsedBody(): any;
42
42
  updateQuery(newQuery: Partial<TQuery>): this;
@@ -1,3 +1,3 @@
1
- import type { ApiResponse, Body, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Params, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
2
2
  import type { EndpointMockingConfig } from "./MockingTypes";
3
- export declare const submit: <TResponse, TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
3
+ export declare const submit: <TResponse, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
package/cjs/Requester.js CHANGED
@@ -242,7 +242,7 @@ var makeRequest = function (context) { return __awaiter(void 0, void 0, void 0,
242
242
  });
243
243
  }); };
244
244
  var parseResponse = function (context, response, error) { return __awaiter(void 0, void 0, void 0, function () {
245
- var parsedResponse_1, contentType, inferredResponseType, data, decodedData;
245
+ var parsedResponse, contentType, inferredResponseType, data, decodedData;
246
246
  var _a;
247
247
  return __generator(this, function (_b) {
248
248
  switch (_b.label) {
@@ -250,15 +250,8 @@ var parseResponse = function (context, response, error) { return __awaiter(void
250
250
  if (!response) return [3 /*break*/, 2];
251
251
  return [4 /*yield*/, context.backend.convertResponse(context, response)];
252
252
  case 1:
253
- parsedResponse_1 = _b.sent();
254
- // lowercase all header names
255
- parsedResponse_1.headers =
256
- parsedResponse_1.__lowercaseHeaders ||
257
- Object.keys(parsedResponse_1.headers).reduce(function (headers, header) {
258
- headers[header.toLowerCase()] = parsedResponse_1.headers[header];
259
- return headers;
260
- }, {});
261
- contentType = parsedResponse_1.headers["content-type"];
253
+ parsedResponse = _b.sent();
254
+ contentType = parsedResponse.headers.get("content-type");
262
255
  inferredResponseType = (0, ApiUtils_1.inferResponseType)(contentType);
263
256
  if (!error) {
264
257
  // expand to array buffer once we support that in inferResponseType
@@ -266,13 +259,13 @@ var parseResponse = function (context, response, error) { return __awaiter(void
266
259
  throw (0, RequestError_1.convertToRequestError)({
267
260
  error: new Error("[api-def] Expected '".concat(context.responseType, "' response, got '").concat(inferredResponseType, "' (from 'Content-Type' of '").concat(contentType, "')")),
268
261
  code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
269
- response: parsedResponse_1,
262
+ response: parsedResponse,
270
263
  context: context,
271
264
  });
272
265
  }
273
266
  // transform arrayBuffer to json
274
267
  if (inferredResponseType === "arraybuffer" && context.responseType === "json") {
275
- if (parsedResponse_1.data && typeof parsedResponse_1.data === "object") {
268
+ if (parsedResponse.data && typeof parsedResponse.data === "object") {
276
269
  data = response.data;
277
270
  if (((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ArrayBuffer") {
278
271
  try {
@@ -283,7 +276,7 @@ var parseResponse = function (context, response, error) { return __awaiter(void
283
276
  throw (0, RequestError_1.convertToRequestError)({
284
277
  error: new Error("[api-def] Expected '".concat(context.responseType, "' response, got '").concat(inferredResponseType, "' (from 'Content-Type' of '").concat(contentType, "')")),
285
278
  code: RequestError_1.RequestErrorCode.REQUEST_MISMATCH_RESPONSE_TYPE,
286
- response: parsedResponse_1,
279
+ response: parsedResponse,
287
280
  context: context,
288
281
  });
289
282
  }
@@ -291,7 +284,7 @@ var parseResponse = function (context, response, error) { return __awaiter(void
291
284
  }
292
285
  }
293
286
  }
294
- return [2 /*return*/, parsedResponse_1];
287
+ return [2 /*return*/, parsedResponse];
295
288
  case 2: return [2 /*return*/, response];
296
289
  }
297
290
  });
package/cjs/Utils.d.ts CHANGED
@@ -13,3 +13,4 @@ export declare const noop: () => void;
13
13
  */
14
14
  export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
15
15
  export declare const randInt: (min: number, max: number) => number;
16
+ export declare const isFormData: (value: any) => value is FormData;
package/cjs/Utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randInt = exports.delayThenReturn = exports.noop = exports.getGlobalFetch = exports.getGlobal = exports.padNumber = exports.assign = void 0;
3
+ exports.isFormData = exports.randInt = exports.delayThenReturn = exports.noop = exports.getGlobalFetch = exports.getGlobal = exports.padNumber = exports.assign = void 0;
4
4
  // polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
5
5
  exports.assign = Object.assign ||
6
6
  (function (target) {
@@ -75,3 +75,7 @@ var randInt = function (min, max) {
75
75
  return Math.floor(Math.random() * (maxI - minI + 1)) + minI;
76
76
  };
77
77
  exports.randInt = randInt;
78
+ var isFormData = function (value) {
79
+ return value instanceof FormData;
80
+ };
81
+ exports.isFormData = isFormData;
@@ -3,7 +3,7 @@ import type { ApiResponse } from "../ApiTypes";
3
3
  import type RequestContext from "../RequestContext";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
- export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
6
+ export declare const isAxiosError: (error: Error) => error is AxiosError;
7
7
  export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
8
8
  readonly id = "axios";
9
9
  constructor(axiosLibrary: any);
@@ -4,7 +4,7 @@ import { type Fetch } from "../Utils";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
6
  export default class FetchRequestBackend implements RequestBackend<Response> {
7
- fetch: (((input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | undefined;
7
+ fetch: (((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) & typeof fetch) | undefined;
8
8
  readonly id = "fetch";
9
9
  constructor(fetchLibrary?: Fetch);
10
10
  extractResponseFromError(error: Error): Promise<Response | null | undefined>;
@@ -88,23 +88,18 @@ var FetchRequestBackend = /** @class */ (function () {
88
88
  };
89
89
  FetchRequestBackend.prototype.convertResponse = function (context, response) {
90
90
  return __awaiter(this, void 0, void 0, function () {
91
- var status, headers, processedHeaders, convertedResponse, responseType, text, data, error_1;
91
+ var status, headers, convertedResponse, responseType, text, data, error_1;
92
92
  var _a;
93
93
  return __generator(this, function (_b) {
94
94
  switch (_b.label) {
95
95
  case 0:
96
96
  status = response.status, headers = response.headers;
97
- processedHeaders = {};
98
- headers.forEach(function (value, key) {
99
- processedHeaders[key] = value;
100
- });
101
97
  convertedResponse = {
102
- __lowercaseHeaders: processedHeaders,
103
98
  method: context.method,
104
99
  url: response.url,
105
100
  data: undefined,
106
101
  status: status,
107
- headers: processedHeaders,
102
+ headers: headers,
108
103
  state: context.requestConfig.state,
109
104
  };
110
105
  responseType = (_a = context.responseType) !== null && _a !== void 0 ? _a : (0, ApiUtils_1.inferResponseType)(response.headers.get("Content-Type"));
@@ -149,18 +144,18 @@ var FetchRequestBackend = /** @class */ (function () {
149
144
  if (!this.fetch) {
150
145
  throw new Error("[api-def] No fetch impl was provided to FetchRequestBackend");
151
146
  }
152
- var computedConfig = context.computedConfig;
147
+ var requestConfig = context.requestConfig;
153
148
  // abort controller is a newer feature than fetch
154
149
  var abortController = AbortController && new AbortController();
155
150
  var abortSignal = abortController ? abortController.signal : undefined;
156
151
  var softAbort = false;
157
152
  var responded = false;
158
153
  var body = context.getParsedBody();
159
- var bodyJsonify = body !== null && typeof body === "object";
154
+ var bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormData(body);
160
155
  var headers = Utils.assign({
161
156
  // logic from axios
162
157
  "Content-Type": bodyJsonify ? "application/json;charset=utf-8" : "application/x-www-form-urlencoded",
163
- }, computedConfig.headers);
158
+ }, requestConfig.headers);
164
159
  var parsedHeaders = Object.keys(headers).reduce(function (parsedHeaders, key) {
165
160
  var value = headers[key];
166
161
  if (value !== undefined) {
@@ -137,9 +137,9 @@ var MockRequestBackend = /** @class */ (function () {
137
137
  });
138
138
  }
139
139
  parsedHeaders = Object.keys(res.headers).reduce(function (parsedHeaders, key) {
140
- parsedHeaders[key] = res.headers[key].toString();
140
+ parsedHeaders.set(key, res.headers[key].toString());
141
141
  return parsedHeaders;
142
- }, {});
142
+ }, new Headers());
143
143
  return [2 /*return*/, {
144
144
  url: context.requestUrl.href,
145
145
  method: context.method,
package/esm/ApiTypes.d.ts CHANGED
@@ -4,7 +4,7 @@ import type RequestContext from "./RequestContext";
4
4
  import type { Validation } from "./Validation";
5
5
  import type RequestBackend from "./backend/RequestBackend";
6
6
  export type AcceptableStatus = number | [min: number, max: number];
7
- export type Headers = Record<string, string | number | boolean | null | undefined>;
7
+ export type RawHeaders = Record<string, string | number | boolean | null | undefined>;
8
8
  export type Params = string;
9
9
  export type Query = string | undefined | Record<string, any>;
10
10
  export type Body = string | number | Record<string, any>;
@@ -14,7 +14,7 @@ export interface ApiResponse<T = any> {
14
14
  readonly url: string;
15
15
  readonly status: number;
16
16
  readonly data: T;
17
- readonly headers: Record<string, string>;
17
+ readonly headers: Headers;
18
18
  readonly state: State;
19
19
  }
20
20
  export type RequestLock = string | false;
@@ -35,7 +35,7 @@ export interface BaseRequestConfig {
35
35
  lock?: RequestLock;
36
36
  credentials?: "omit" | "same-origin" | "include";
37
37
  retry?: number | false | RetryOptions;
38
- headers?: Readonly<Headers>;
38
+ headers?: Readonly<RawHeaders>;
39
39
  acceptableStatus?: AcceptableStatus[];
40
40
  /**
41
41
  * @deprecated use `queryHandling.stringify` instead
@@ -1,4 +1,4 @@
1
- import type { ApiResponse, Body, Headers, Params, Query, State } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Params, Query, RawHeaders, State } from "./ApiTypes";
2
2
  export interface ApiMockingConfig {
3
3
  enabled: boolean | (() => boolean);
4
4
  }
@@ -6,14 +6,14 @@ export interface MockRequest<TResponse = any, TParams extends Params | undefined
6
6
  params: TParams extends Params ? Record<TParams, string> : {};
7
7
  body: TBody;
8
8
  query: TQuery;
9
- headers: Readonly<Headers>;
9
+ headers: Readonly<RawHeaders>;
10
10
  url: string;
11
11
  state: TState;
12
12
  }
13
13
  export interface MockResponse<TResponse = any, TParams extends Params | undefined = Params | undefined, TQuery extends Query | undefined = Query | undefined, TBody extends Body | undefined = Body | undefined, TState extends State = State> {
14
14
  statusCode: number;
15
15
  response: TResponse | undefined;
16
- headers: Headers;
16
+ headers: RawHeaders;
17
17
  status(statusCode: number): this;
18
18
  send(response: TResponse): this;
19
19
  }
@@ -1,2 +1,2 @@
1
- import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Query, type RequestConfig, type State } from "./ApiTypes";
2
- export declare const computeRequestConfig: <TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
1
+ import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Params, type Query, type RequestConfig, type State } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(configs: (RequestConfig<TParams, TQuery, TBody, TState> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<TParams, TQuery, TBody, TState>;
@@ -1,6 +1,6 @@
1
1
  import type { Api } from "./Api";
2
2
  import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
- import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost, State } from "./ApiTypes";
3
+ import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Params, Query, RawHeaders, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost, State } from "./ApiTypes";
4
4
  import type { EndpointMockingConfig } from "./MockingTypes";
5
5
  import type { RequestError } from "./RequestError";
6
6
  import type { Validation } from "./Validation";
@@ -36,7 +36,7 @@ export default class RequestContext<TResponse = any, TParams extends Params | un
36
36
  get responseType(): ResponseType | undefined;
37
37
  private initMiddleware;
38
38
  private generateKey;
39
- updateHeaders(newHeaders: Headers): this;
39
+ updateHeaders(newHeaders: RawHeaders): this;
40
40
  private parseRequestBody;
41
41
  getParsedBody(): any;
42
42
  updateQuery(newQuery: Partial<TQuery>): this;
@@ -1,3 +1,3 @@
1
- import type { ApiResponse, Body, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Params, Query, RequestConfig, RequestHost, State } from "./ApiTypes";
2
2
  import type { EndpointMockingConfig } from "./MockingTypes";
3
- export declare const submit: <TResponse, TParams extends string | undefined, TQuery extends Query, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
3
+ export declare const submit: <TResponse, TParams extends Params | undefined, TQuery extends Query | undefined, TBody extends Body | undefined, TState extends State>(host: RequestHost, config: RequestConfig<TParams, TQuery, TBody, TState>, mocking: EndpointMockingConfig<TResponse, TParams, TQuery, TBody, TState> | null | undefined) => Promise<ApiResponse<TResponse>>;
package/esm/Requester.js CHANGED
@@ -175,17 +175,10 @@ const makeRequest = (context) => __awaiter(void 0, void 0, void 0, function* ()
175
175
  return response;
176
176
  });
177
177
  const parseResponse = (context, response, error) => __awaiter(void 0, void 0, void 0, function* () {
178
- var _d;
178
+ var _a;
179
179
  if (response) {
180
180
  const parsedResponse = yield context.backend.convertResponse(context, response);
181
- // lowercase all header names
182
- parsedResponse.headers =
183
- parsedResponse.__lowercaseHeaders ||
184
- Object.keys(parsedResponse.headers).reduce((headers, header) => {
185
- headers[header.toLowerCase()] = parsedResponse.headers[header];
186
- return headers;
187
- }, {});
188
- const contentType = parsedResponse.headers["content-type"];
181
+ const contentType = parsedResponse.headers.get("content-type");
189
182
  const inferredResponseType = inferResponseType(contentType);
190
183
  if (!error) {
191
184
  // expand to array buffer once we support that in inferResponseType
@@ -201,7 +194,7 @@ const parseResponse = (context, response, error) => __awaiter(void 0, void 0, vo
201
194
  if (inferredResponseType === "arraybuffer" && context.responseType === "json") {
202
195
  if (parsedResponse.data && typeof parsedResponse.data === "object") {
203
196
  const data = response.data;
204
- if (((_d = data.constructor) === null || _d === void 0 ? void 0 : _d.name) === "ArrayBuffer") {
197
+ if (((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "ArrayBuffer") {
205
198
  try {
206
199
  const decodedData = (response.data = textDecode(data));
207
200
  response.data = JSON.parse(decodedData);
@@ -223,7 +216,7 @@ const parseResponse = (context, response, error) => __awaiter(void 0, void 0, vo
223
216
  return response;
224
217
  });
225
218
  const parseError = (context, rawError) => __awaiter(void 0, void 0, void 0, function* () {
226
- var _e;
219
+ var _a;
227
220
  let error;
228
221
  if (isRequestError(rawError)) {
229
222
  error = rawError;
@@ -243,7 +236,7 @@ const parseError = (context, rawError) => __awaiter(void 0, void 0, void 0, func
243
236
  }
244
237
  }
245
238
  else {
246
- if (rawError.code === "ENOTFOUND" || ((_e = rawError.cause) === null || _e === void 0 ? void 0 : _e.code) === "ENOTFOUND") {
239
+ if (rawError.code === "ENOTFOUND" || ((_a = rawError.cause) === null || _a === void 0 ? void 0 : _a.code) === "ENOTFOUND") {
247
240
  code = RequestErrorCode.REQUEST_HOST_NAME_NOT_FOUND;
248
241
  }
249
242
  }
package/esm/Utils.d.ts CHANGED
@@ -13,3 +13,4 @@ export declare const noop: () => void;
13
13
  */
14
14
  export declare const delayThenReturn: <T>(value: T, delayMs: number) => Promise<T>;
15
15
  export declare const randInt: (min: number, max: number) => number;
16
+ export declare const isFormData: (value: any) => value is FormData;
package/esm/Utils.js CHANGED
@@ -62,3 +62,6 @@ export const randInt = (min, max) => {
62
62
  const maxI = Math.floor(max);
63
63
  return Math.floor(Math.random() * (maxI - minI + 1)) + minI;
64
64
  };
65
+ export const isFormData = (value) => {
66
+ return value instanceof FormData;
67
+ };
@@ -3,7 +3,7 @@ import type { ApiResponse } from "../ApiTypes";
3
3
  import type RequestContext from "../RequestContext";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
- export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
6
+ export declare const isAxiosError: (error: Error) => error is AxiosError;
7
7
  export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
8
8
  readonly id = "axios";
9
9
  constructor(axiosLibrary: any);
@@ -4,7 +4,7 @@ import { type Fetch } from "../Utils";
4
4
  import type RequestBackend from "./RequestBackend";
5
5
  import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
6
6
  export default class FetchRequestBackend implements RequestBackend<Response> {
7
- fetch: (((input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | undefined;
7
+ fetch: (((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) & typeof fetch) | undefined;
8
8
  readonly id = "fetch";
9
9
  constructor(fetchLibrary?: Fetch);
10
10
  extractResponseFromError(error: Error): Promise<Response | null | undefined>;
@@ -38,17 +38,12 @@ export default class FetchRequestBackend {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
39
  var _a;
40
40
  const { status, headers } = response;
41
- const processedHeaders = {};
42
- headers.forEach((value, key) => {
43
- processedHeaders[key] = value;
44
- });
45
41
  const convertedResponse = {
46
- __lowercaseHeaders: processedHeaders,
47
42
  method: context.method,
48
43
  url: response.url,
49
44
  data: undefined,
50
45
  status: status,
51
- headers: processedHeaders,
46
+ headers: headers,
52
47
  state: context.requestConfig.state,
53
48
  };
54
49
  const responseType = (_a = context.responseType) !== null && _a !== void 0 ? _a : inferResponseType(response.headers.get("Content-Type"));
@@ -84,18 +79,18 @@ export default class FetchRequestBackend {
84
79
  if (!this.fetch) {
85
80
  throw new Error("[api-def] No fetch impl was provided to FetchRequestBackend");
86
81
  }
87
- const { computedConfig } = context;
82
+ const { requestConfig } = context;
88
83
  // abort controller is a newer feature than fetch
89
84
  const abortController = AbortController && new AbortController();
90
85
  const abortSignal = abortController ? abortController.signal : undefined;
91
86
  let softAbort = false;
92
87
  let responded = false;
93
88
  const body = context.getParsedBody();
94
- const bodyJsonify = body !== null && typeof body === "object";
89
+ const bodyJsonify = body !== null && typeof body === "object" && !Utils.isFormData(body);
95
90
  const headers = Utils.assign({
96
91
  // logic from axios
97
92
  "Content-Type": bodyJsonify ? "application/json;charset=utf-8" : "application/x-www-form-urlencoded",
98
- }, computedConfig.headers);
93
+ }, requestConfig.headers);
99
94
  const parsedHeaders = Object.keys(headers).reduce((parsedHeaders, key) => {
100
95
  const value = headers[key];
101
96
  if (value !== undefined) {
@@ -93,9 +93,9 @@ export default class MockRequestBackend {
93
93
  });
94
94
  }
95
95
  const parsedHeaders = Object.keys(res.headers).reduce((parsedHeaders, key) => {
96
- parsedHeaders[key] = res.headers[key].toString();
96
+ parsedHeaders.set(key, res.headers[key].toString());
97
97
  return parsedHeaders;
98
- }, {});
98
+ }, new Headers());
99
99
  return {
100
100
  url: context.requestUrl.href,
101
101
  method: context.method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.10.2",
3
+ "version": "0.11.0-alpha.2",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "prepublishOnly": "npm run check:fix && npm run test && npm run build",
11
11
  "test": "jest",
12
12
  "example:start": "cd example && npm run start",
13
- "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --apply .",
14
- "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check .",
13
+ "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --write",
14
+ "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check",
15
15
  "cleanup": "rimraf esm && rimraf cjs",
16
16
  "build": "npm run cleanup && npm run build:esm && npm run build:cjs",
17
17
  "build:esm": "tsc --module es2015 --target es2016 --outDir esm --preserveWatchOutput",
@@ -30,20 +30,20 @@
30
30
  },
31
31
  "repository": "https://github.com/Censkh/api-def",
32
32
  "devDependencies": {
33
- "@biomejs/biome": "1.8.1",
33
+ "@biomejs/biome": "1.8.3",
34
34
  "@swc/core": "latest",
35
35
  "@swc/jest": "latest",
36
36
  "@types/axios": "0.14.0",
37
37
  "@types/jest": "^29.5.12",
38
- "@types/node": "20.14.2",
38
+ "@types/node": "22.4.0",
39
39
  "@types/qs": "6.9.15",
40
- "axios": "1.7.2",
40
+ "axios": "1.7.4",
41
41
  "cross-env": "7.0.3",
42
42
  "jest": "latest",
43
43
  "npm-run-all": "4.1.5",
44
- "qs": "6.12.1",
45
- "rimraf": "5.0.7",
46
- "typescript": "5.4.5",
44
+ "qs": "6.13.0",
45
+ "rimraf": "6.0.1",
46
+ "typescript": "5.5.4",
47
47
  "zod": "3.23.8"
48
48
  }
49
49
  }