api-def 0.9.3 → 0.9.4-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.
Files changed (74) hide show
  1. package/cjs/Api.d.ts +4 -4
  2. package/cjs/ApiConstants.d.ts +1 -1
  3. package/cjs/ApiTypes.d.ts +6 -5
  4. package/cjs/ApiUtils.d.ts +2 -2
  5. package/cjs/ApiUtils.js +3 -1
  6. package/cjs/Endpoint.d.ts +6 -6
  7. package/cjs/Endpoint.js +1 -1
  8. package/cjs/EndpointBuilder.d.ts +4 -4
  9. package/cjs/MockingTypes.d.ts +1 -1
  10. package/cjs/QueryHandling.d.ts +1 -1
  11. package/cjs/RequestConfig.d.ts +2 -2
  12. package/cjs/RequestContext.d.ts +7 -7
  13. package/cjs/RequestError.d.ts +3 -3
  14. package/cjs/RequestError.js +3 -1
  15. package/cjs/Requester.d.ts +2 -2
  16. package/cjs/Requester.js +3 -1
  17. package/cjs/TextDecoding.js +3 -1
  18. package/cjs/UtilTypes.d.ts +1 -1
  19. package/cjs/Validation.d.ts +2 -2
  20. package/cjs/backend/AxiosRequestBackend.d.ts +4 -3
  21. package/cjs/backend/AxiosRequestBackend.js +1 -0
  22. package/cjs/backend/FetchRequestBackend.d.ts +5 -4
  23. package/cjs/backend/FetchRequestBackend.js +9 -4
  24. package/cjs/backend/MockRequestBackend.d.ts +4 -3
  25. package/cjs/backend/MockRequestBackend.js +8 -8
  26. package/cjs/backend/RequestBackend.d.ts +2 -2
  27. package/cjs/cache/Caching.d.ts +1 -1
  28. package/cjs/cache/LocalForageCacheBackend.d.ts +1 -1
  29. package/cjs/cache/LocalStorageCacheBackend.d.ts +1 -1
  30. package/cjs/middleware/CacheMiddleware.d.ts +1 -1
  31. package/cjs/middleware/LoggingMiddleware.d.ts +1 -1
  32. package/cjs/middleware/LoggingMiddleware.js +7 -1
  33. package/cjs/util/retry/index.d.ts +1 -1
  34. package/cjs/util/retry/lib/retry.d.ts +1 -1
  35. package/cjs/util/retry/lib/retry.js +2 -2
  36. package/cjs/util/retry/lib/retryOperation.js +1 -1
  37. package/esm/Api.d.ts +4 -4
  38. package/esm/ApiConstants.d.ts +1 -1
  39. package/esm/ApiTypes.d.ts +6 -5
  40. package/esm/ApiUtils.d.ts +2 -2
  41. package/esm/ApiUtils.js +3 -1
  42. package/esm/Endpoint.d.ts +6 -6
  43. package/esm/Endpoint.js +1 -1
  44. package/esm/EndpointBuilder.d.ts +4 -4
  45. package/esm/MockingTypes.d.ts +1 -1
  46. package/esm/QueryHandling.d.ts +1 -1
  47. package/esm/RequestConfig.d.ts +2 -2
  48. package/esm/RequestConfig.js +1 -1
  49. package/esm/RequestContext.d.ts +7 -7
  50. package/esm/RequestError.d.ts +3 -3
  51. package/esm/RequestError.js +3 -1
  52. package/esm/Requester.d.ts +2 -2
  53. package/esm/Requester.js +3 -1
  54. package/esm/TextDecoding.js +3 -1
  55. package/esm/UtilTypes.d.ts +1 -1
  56. package/esm/Validation.d.ts +2 -2
  57. package/esm/backend/AxiosRequestBackend.d.ts +4 -3
  58. package/esm/backend/AxiosRequestBackend.js +1 -0
  59. package/esm/backend/FetchRequestBackend.d.ts +5 -4
  60. package/esm/backend/FetchRequestBackend.js +9 -4
  61. package/esm/backend/MockRequestBackend.d.ts +4 -3
  62. package/esm/backend/MockRequestBackend.js +1 -1
  63. package/esm/backend/RequestBackend.d.ts +2 -2
  64. package/esm/cache/Caching.d.ts +1 -1
  65. package/esm/cache/LocalForageCacheBackend.d.ts +1 -1
  66. package/esm/cache/LocalStorageCacheBackend.d.ts +1 -1
  67. package/esm/middleware/CacheMiddleware.d.ts +1 -1
  68. package/esm/middleware/LoggingMiddleware.d.ts +1 -1
  69. package/esm/middleware/LoggingMiddleware.js +7 -1
  70. package/esm/util/retry/index.d.ts +1 -1
  71. package/esm/util/retry/lib/retry.d.ts +1 -1
  72. package/esm/util/retry/lib/retry.js +2 -2
  73. package/esm/util/retry/lib/retryOperation.js +1 -1
  74. package/package.json +16 -31
package/cjs/Api.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ApiResponse, BaseRequestConfig, RequestConfig, RequestMiddleware } from "./ApiTypes";
2
- import Endpoint from "./Endpoint";
1
+ import type { ApiResponse, BaseRequestConfig, RequestConfig, RequestMiddleware } from "./ApiTypes";
2
+ import type Endpoint from "./Endpoint";
3
3
  import EndpointBuilder from "./EndpointBuilder";
4
- import { ApiMockingConfig } from "./MockingTypes";
5
- import RequestBackend from "./backend/RequestBackend";
4
+ import type { ApiMockingConfig } from "./MockingTypes";
5
+ import type RequestBackend from "./backend/RequestBackend";
6
6
  export declare const getRequestBackend: () => RequestBackend | null;
7
7
  export declare const isRequestBackendDefault: () => boolean;
8
8
  export declare const setRequestBackend: (backend: RequestBackend) => void;
@@ -1,4 +1,4 @@
1
- import { EnumOf } from "./Utils";
1
+ import type { EnumOf } from "./Utils";
2
2
  export declare const RequestMethod: {
3
3
  /** @deprecated use 'POST' */
4
4
  readonly Post: "post";
package/cjs/ApiTypes.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Api } from "./Api";
2
- import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
- import RequestContext from "./RequestContext";
4
- import { Validation } from "./Validation";
5
- import RequestBackend from "./backend/RequestBackend";
1
+ import type { Api } from "./Api";
2
+ import type { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type RequestContext from "./RequestContext";
4
+ import type { Validation } from "./Validation";
5
+ import type RequestBackend from "./backend/RequestBackend";
6
6
  export type AcceptableStatus = number | [min: number, max: number];
7
7
  export type Headers = Record<string, string | number | boolean | null | undefined>;
8
8
  export type Params = string;
@@ -31,6 +31,7 @@ export interface RetryOptions {
31
31
  export interface BaseRequestConfig {
32
32
  cache?: number | boolean;
33
33
  lock?: RequestLock;
34
+ includeCredentials?: boolean;
34
35
  retry?: number | false | RetryOptions;
35
36
  headers?: Readonly<Headers>;
36
37
  acceptableStatus?: AcceptableStatus[];
package/cjs/ApiUtils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ResponseType } from "./ApiConstants";
2
- import { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
1
+ import type { ResponseType } from "./ApiConstants";
2
+ import type { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
3
3
  export declare const isCancelledError: (error: Error) => error is CancelledRequestError;
4
4
  export declare const isNetworkError: (error: Error) => boolean;
5
5
  export declare const isAcceptableStatus: (status: number, acceptableStatus?: AcceptableStatus[]) => boolean;
package/cjs/ApiUtils.js CHANGED
@@ -7,7 +7,9 @@ var isCancelledError = function (error) {
7
7
  exports.isCancelledError = isCancelledError;
8
8
  var isNetworkError = function (error) {
9
9
  var _a;
10
- return error.name === "NetworkError" || error.message === "Network Error" || ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError";
10
+ return (error.name === "NetworkError" ||
11
+ error.message === "Network Error" ||
12
+ ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError");
11
13
  };
12
14
  exports.isNetworkError = isNetworkError;
13
15
  var DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
package/cjs/Endpoint.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Api } from "./Api";
2
- import { RequestMethod, ResponseType } from "./ApiConstants";
3
- import { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
4
- import * as Mocking from "./MockingTypes";
5
- import { Validation } from "./Validation";
6
- import RequestBackend from "./backend/RequestBackend";
1
+ import type { Api } from "./Api";
2
+ import type { RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
4
+ import type * as Mocking from "./MockingTypes";
5
+ import type { Validation } from "./Validation";
6
+ import type RequestBackend from "./backend/RequestBackend";
7
7
  export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined, Path extends string = string> {
8
8
  readonly id: string;
9
9
  readonly method: RequestMethod;
package/cjs/Endpoint.js CHANGED
@@ -52,9 +52,9 @@ var Endpoint = /** @class */ (function () {
52
52
  this.validation = info.validation || {};
53
53
  }
54
54
  Endpoint.prototype.submit = function (config) {
55
- var _a, _b;
56
55
  return __awaiter(this, void 0, void 0, function () {
57
56
  var mock, apiMocking, mockingEnabled;
57
+ var _a, _b;
58
58
  return __generator(this, function (_c) {
59
59
  mock = false;
60
60
  apiMocking = this.api.mocking;
@@ -1,7 +1,7 @@
1
- import * as zod from "zod";
2
- import { Api } from "./Api";
3
- import { Body, Params, Query } from "./ApiTypes";
4
- import Endpoint, { EndpointConfig } from "./Endpoint";
1
+ import type * as zod from "zod";
2
+ import type { Api } from "./Api";
3
+ import type { Body, Params, Query } from "./ApiTypes";
4
+ import Endpoint, { type EndpointConfig } from "./Endpoint";
5
5
  export default class EndpointBuilder<R = any, P extends Params | undefined = undefined, Q extends Query | undefined = undefined, B extends Body | undefined = undefined> {
6
6
  private api;
7
7
  private readonly validation;
@@ -1,4 +1,4 @@
1
- import { ApiResponse, Body, Headers, Params, Query } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Headers, Params, Query } from "./ApiTypes";
2
2
  export interface ApiMockingConfig {
3
3
  enabled: boolean | (() => boolean);
4
4
  }
@@ -1,3 +1,3 @@
1
- import { QueryStringify } from "./ApiTypes";
1
+ import type { QueryStringify } from "./ApiTypes";
2
2
  export declare const DEFAULT_QUERY_STRINGIFY: QueryStringify;
3
3
  export declare const DEFAULT_QUERY_PARSE: (queryString: string) => Record<string, any>;
@@ -1,2 +1,2 @@
1
- import { BaseRequestConfig, Body, ComputedRequestConfig, Query, RequestConfig } from "./ApiTypes";
2
- export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (BaseRequestConfig | RequestConfig<P, Q, B> | undefined)[]) => ComputedRequestConfig<P, Q, B>;
1
+ import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Query, type RequestConfig } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (RequestConfig<P, Q, B> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<P, Q, B>;
@@ -1,10 +1,10 @@
1
- import { Api } from "./Api";
2
- import { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
- import { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost } from "./ApiTypes";
4
- import { EndpointMockingConfig } from "./MockingTypes";
5
- import { RequestError } from "./RequestError";
6
- import { Validation } from "./Validation";
7
- import RequestBackend from "./backend/RequestBackend";
1
+ import type { Api } from "./Api";
2
+ import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost } from "./ApiTypes";
4
+ import type { EndpointMockingConfig } from "./MockingTypes";
5
+ import type { RequestError } from "./RequestError";
6
+ import type { Validation } from "./Validation";
7
+ import type RequestBackend from "./backend/RequestBackend";
8
8
  export default class RequestContext<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
9
9
  readonly id: number;
10
10
  readonly key: string;
@@ -1,6 +1,6 @@
1
- import { ApiResponse } from "./ApiTypes";
2
- import RequestContext from "./RequestContext";
3
- import { EnumOf } from "./Utils";
1
+ import type { ApiResponse } from "./ApiTypes";
2
+ import type RequestContext from "./RequestContext";
3
+ import type { EnumOf } from "./Utils";
4
4
  export declare const RequestErrorCode: {
5
5
  readonly MISC_UNKNOWN_ERROR: "misc/unknown-error";
6
6
  readonly REQUEST_NETWORK_ERROR: "request/network-error";
@@ -34,7 +34,9 @@ var convertToRequestError = function (config) {
34
34
  },
35
35
  });
36
36
  try {
37
- Object.defineProperty(resultError, "message", { value: "Request failed".concat((response === null || response === void 0 ? void 0 : response.status) ? " with status code ".concat(response.status) : "", " [").concat(code, "]: ").concat(resultError.message) });
37
+ Object.defineProperty(resultError, "message", {
38
+ value: "Request failed".concat((response === null || response === void 0 ? void 0 : response.status) ? " with status code ".concat(response.status) : "", " [").concat(code, "]: ").concat(resultError.message),
39
+ });
38
40
  }
39
41
  catch (e) {
40
42
  // ignore
@@ -1,3 +1,3 @@
1
- import { ApiResponse, Body, Query, RequestConfig, RequestHost } from "./ApiTypes";
2
- import { EndpointMockingConfig } from "./MockingTypes";
1
+ import type { ApiResponse, Body, Query, RequestConfig, RequestHost } from "./ApiTypes";
2
+ import type { EndpointMockingConfig } from "./MockingTypes";
3
3
  export declare const submit: <R, P extends string | undefined, Q extends Query, B extends Body | undefined>(host: RequestHost, config: RequestConfig<P, Q, B>, mocking: EndpointMockingConfig<R, P, Q, B> | null | undefined) => Promise<ApiResponse<R>>;
package/cjs/Requester.js CHANGED
@@ -315,7 +315,9 @@ var parseError = function (context, rawError) { return __awaiter(void 0, void 0,
315
315
  errorResponse = _b.sent();
316
316
  _b.label = 4;
317
317
  case 4:
318
- code = (0, ApiUtils_1.isNetworkError)(rawError) ? RequestError_1.RequestErrorCode.REQUEST_NETWORK_ERROR : RequestError_1.RequestErrorCode.MISC_UNKNOWN_ERROR;
318
+ code = (0, ApiUtils_1.isNetworkError)(rawError)
319
+ ? RequestError_1.RequestErrorCode.REQUEST_NETWORK_ERROR
320
+ : RequestError_1.RequestErrorCode.MISC_UNKNOWN_ERROR;
319
321
  if (errorResponse) {
320
322
  if (!(0, ApiUtils_1.isAcceptableStatus)(errorResponse.status, context.computedConfig.acceptableStatus)) {
321
323
  code = RequestError_1.RequestErrorCode.REQUEST_INVALID_STATUS;
@@ -22,7 +22,9 @@ var textDecode = function (inputArrayOrBuffer, options) {
22
22
  var asObjectString;
23
23
  if (!arrayBuffer_isView(inputAs8)) {
24
24
  asObjectString = Object_prototype_toString.call(inputAs8);
25
- if (asObjectString !== arrayBufferString && asObjectString !== sharedArrayBufferString && asObjectString !== undefinedObjectString)
25
+ if (asObjectString !== arrayBufferString &&
26
+ asObjectString !== sharedArrayBufferString &&
27
+ asObjectString !== undefinedObjectString)
26
28
  throw TypeError("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
27
29
  inputAs8 = NativeUint8Array ? new patchedU8Array(inputAs8) : inputAs8 || [];
28
30
  }
@@ -1,4 +1,4 @@
1
- import Endpoint from "./Endpoint";
1
+ import type Endpoint from "./Endpoint";
2
2
  export type ResponseOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<infer R, any, any, any> ? R : never;
3
3
  export type ParamsOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, infer P, any, any> ? P : never;
4
4
  export type QueryOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, infer Q, any> ? Q : never;
@@ -1,5 +1,5 @@
1
- import * as zod from "zod";
2
- import { Body, Params, Query } from "./ApiTypes";
1
+ import type * as zod from "zod";
2
+ import type { Body, Params, Query } from "./ApiTypes";
3
3
  export interface Validation<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
4
4
  query?: zod.Schema<Q>;
5
5
  params?: zod.Schema<P>;
@@ -1,7 +1,8 @@
1
1
  import type { AxiosError, AxiosResponse } from "axios";
2
- import { ApiResponse } from "../ApiTypes";
3
- import RequestContext from "../RequestContext";
4
- import RequestBackend, { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
2
+ import type { ApiResponse } from "../ApiTypes";
3
+ import type RequestContext from "../RequestContext";
4
+ import type RequestBackend from "./RequestBackend";
5
+ import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
5
6
  export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
6
7
  export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
7
8
  readonly id = "axios";
@@ -82,6 +82,7 @@ var AxiosRequestBackend = /** @class */ (function () {
82
82
  data: context.getParsedBody(),
83
83
  headers: computedConfig.headers || {},
84
84
  responseType: context.responseType,
85
+ withCredentials: computedConfig.includeCredentials,
85
86
  cancelToken: new axios.CancelToken(function (cancellerFunc) {
86
87
  canceler = cancellerFunc;
87
88
  }),
@@ -1,7 +1,8 @@
1
- import { ApiResponse } from "../ApiTypes";
2
- import RequestContext from "../RequestContext";
3
- import { Fetch } from "../Utils";
4
- import RequestBackend, { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
1
+ import type { ApiResponse } from "../ApiTypes";
2
+ import type RequestContext from "../RequestContext";
3
+ import { type Fetch } from "../Utils";
4
+ import type RequestBackend from "./RequestBackend";
5
+ import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
5
6
  export default class FetchRequestBackend implements RequestBackend<Response> {
6
7
  fetch: (((input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | undefined;
7
8
  readonly id = "fetch";
@@ -87,9 +87,9 @@ var FetchRequestBackend = /** @class */ (function () {
87
87
  });
88
88
  };
89
89
  FetchRequestBackend.prototype.convertResponse = function (context, response) {
90
- var _a;
91
90
  return __awaiter(this, void 0, void 0, function () {
92
91
  var status, headers, processedHeaders, convertedResponse, responseType, text, data, error_1;
92
+ var _a;
93
93
  return __generator(this, function (_b) {
94
94
  switch (_b.label) {
95
95
  case 0:
@@ -168,13 +168,18 @@ var FetchRequestBackend = /** @class */ (function () {
168
168
  return parsedHeaders;
169
169
  }, {});
170
170
  var url = context.requestUrl;
171
- var promise = this.fetch(url.href, {
171
+ var fetchOptions = {
172
172
  method: context.method.toUpperCase(),
173
173
  body: bodyJsonify ? JSON.stringify(body) : body,
174
174
  headers: parsedHeaders,
175
- mode: "cors",
175
+ credentials: context.computedConfig.includeCredentials ? "include" : undefined,
176
176
  signal: abortSignal,
177
- }).then(function (response) {
177
+ };
178
+ // edge doesn't support mode
179
+ if ("mode" in Request.prototype) {
180
+ fetchOptions.mode = "cors";
181
+ }
182
+ var promise = this.fetch(url.href, fetchOptions).then(function (response) {
178
183
  responded = true;
179
184
  if (!response.ok) {
180
185
  var error = new FetchError("Fetch failed");
@@ -1,6 +1,7 @@
1
- import { ApiResponse } from "../ApiTypes";
2
- import RequestContext from "../RequestContext";
3
- import RequestBackend, { RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
1
+ import type { ApiResponse } from "../ApiTypes";
2
+ import type RequestContext from "../RequestContext";
3
+ import type RequestBackend from "./RequestBackend";
4
+ import type { RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
4
5
  export default class MockRequestBackend implements RequestBackend<ApiResponse> {
5
6
  readonly id = "mock";
6
7
  convertResponse<T>(context: RequestContext, response: ApiResponse, error?: boolean): Promise<ApiResponse<T>>;
@@ -63,13 +63,13 @@ var MockRequestBackend = /** @class */ (function () {
63
63
  });
64
64
  };
65
65
  MockRequestBackend.prototype.runRequest = function (context) {
66
- var _a, _b, _c, _d;
67
66
  return __awaiter(this, void 0, void 0, function () {
68
- var mockingFunc, req, res, delay, delayMs, min, max, _e, parsedHeaders;
67
+ var mockingFunc, req, res, delay, delayMs, min, max, _a, parsedHeaders;
68
+ var _b, _c, _d, _e;
69
69
  return __generator(this, function (_f) {
70
70
  switch (_f.label) {
71
71
  case 0:
72
- mockingFunc = (_a = context.mocking) === null || _a === void 0 ? void 0 : _a.handler;
72
+ mockingFunc = (_b = context.mocking) === null || _b === void 0 ? void 0 : _b.handler;
73
73
  if (!mockingFunc) {
74
74
  throw (0, RequestError_1.convertToRequestError)({
75
75
  error: new Error("[api-def] Attempted to run mocked request without mocking function"),
@@ -79,9 +79,9 @@ var MockRequestBackend = /** @class */ (function () {
79
79
  }
80
80
  req = {
81
81
  body: context.getParsedBody(),
82
- params: (_b = context.computedConfig.params) !== null && _b !== void 0 ? _b : {},
82
+ params: (_c = context.computedConfig.params) !== null && _c !== void 0 ? _c : {},
83
83
  query: context.computedConfig.queryObject,
84
- headers: (_c = context.computedConfig.headers) !== null && _c !== void 0 ? _c : {},
84
+ headers: (_d = context.computedConfig.headers) !== null && _d !== void 0 ? _d : {},
85
85
  url: context.requestUrl.toString(),
86
86
  };
87
87
  res = {
@@ -100,7 +100,7 @@ var MockRequestBackend = /** @class */ (function () {
100
100
  return res;
101
101
  },
102
102
  };
103
- if (!((_d = context.mocking) === null || _d === void 0 ? void 0 : _d.delay)) return [3 /*break*/, 3];
103
+ if (!((_e = context.mocking) === null || _e === void 0 ? void 0 : _e.delay)) return [3 /*break*/, 3];
104
104
  delay = context.mocking.delay;
105
105
  delayMs = void 0;
106
106
  if (typeof delay === "number") {
@@ -117,9 +117,9 @@ var MockRequestBackend = /** @class */ (function () {
117
117
  }
118
118
  delayMs = (0, Utils_1.randInt)(min, max);
119
119
  }
120
- _e = Utils_1.delayThenReturn;
120
+ _a = Utils_1.delayThenReturn;
121
121
  return [4 /*yield*/, mockingFunc(req, res)];
122
- case 1: return [4 /*yield*/, _e.apply(void 0, [_f.sent(), delayMs])];
122
+ case 1: return [4 /*yield*/, _a.apply(void 0, [_f.sent(), delayMs])];
123
123
  case 2:
124
124
  _f.sent();
125
125
  return [3 /*break*/, 5];
@@ -1,5 +1,5 @@
1
- import { ApiResponse } from "../ApiTypes";
2
- import RequestContext from "../RequestContext";
1
+ import type { ApiResponse } from "../ApiTypes";
2
+ import type RequestContext from "../RequestContext";
3
3
  export interface RequestOperation<R> {
4
4
  promise: Promise<R>;
5
5
  canceler: () => void;
@@ -1,4 +1,4 @@
1
- import { CacheBackend } from "./CacheBackend";
1
+ import type { CacheBackend } from "./CacheBackend";
2
2
  export declare const setCacheBackend: (backend: CacheBackend) => void;
3
3
  export declare const DEFAULT_CACHE_EXPIRY: number;
4
4
  export declare const clearCache: () => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { CacheBackend } from "./CacheBackend";
1
+ import type { CacheBackend } from "./CacheBackend";
2
2
  export default class LocalForageCacheBackend implements CacheBackend {
3
3
  private readonly store;
4
4
  constructor(localforage: any);
@@ -1,4 +1,4 @@
1
- import { CacheBackend } from "./CacheBackend";
1
+ import type { CacheBackend } from "./CacheBackend";
2
2
  export default class LocalStorageCacheBackend implements CacheBackend {
3
3
  clear(): Promise<void>;
4
4
  getItem<T>(key: string): Promise<T | null>;
@@ -1,4 +1,4 @@
1
- import { RequestMiddleware } from "../ApiTypes";
1
+ import type { RequestMiddleware } from "../ApiTypes";
2
2
  export interface CacheMiddlewareOptions {
3
3
  defaultExpiry?: number;
4
4
  predicate?: () => boolean;
@@ -1,4 +1,4 @@
1
- import { RequestMiddleware } from "../ApiTypes";
1
+ import type { RequestMiddleware } from "../ApiTypes";
2
2
  export interface LoggingMiddlewareOptions {
3
3
  predicate?: () => boolean;
4
4
  }
@@ -43,7 +43,13 @@ var log = function (context, type, message, config, objects) {
43
43
  }
44
44
  var color = COLOR_MAP[type];
45
45
  var timestamp = formatTime(new Date());
46
- var args = ["%cnetwork %c[".concat(context.api.name, "] ").concat(context.method.toUpperCase(), " ").concat(context.path, " %c").concat(message, " %c@ ").concat(timestamp), "color:gray", "color:auto", "color:".concat(color), "color:gray"];
46
+ var args = [
47
+ "%cnetwork %c[".concat(context.api.name, "] ").concat(context.method.toUpperCase(), " ").concat(context.path, " %c").concat(message, " %c@ ").concat(timestamp),
48
+ "color:gray",
49
+ "color:auto",
50
+ "color:".concat(color),
51
+ "color:gray",
52
+ ];
47
53
  /* eslint-disable-next-line no-console */
48
54
  console.groupCollapsed.apply(console, args);
49
55
  /* eslint-disable-next-line no-console */
@@ -1,3 +1,3 @@
1
- import { RetryFunction, RetryOptions } from "./interfaces";
1
+ import type { RetryFunction, RetryOptions } from "./interfaces";
2
2
  declare const retry: <A>(fn: RetryFunction<A>, opts: RetryOptions) => Promise<A>;
3
3
  export default retry;
@@ -1,3 +1,3 @@
1
- import { RetryOptions } from "../interfaces";
1
+ import type { RetryOptions } from "../interfaces";
2
2
  import RetryOperation from "./retryOperation";
3
3
  export declare const operation: (options: RetryOptions) => RetryOperation;
@@ -16,7 +16,7 @@ var retryOperation_1 = require("./retryOperation");
16
16
  var operation = function (options) {
17
17
  var timeouts = _timeouts(options);
18
18
  return new retryOperation_1.default(timeouts, {
19
- forever: options && (options.forever || options.retries === Infinity),
19
+ forever: options && (options.forever || options.retries === Number.POSITIVE_INFINITY),
20
20
  unref: options === null || options === void 0 ? void 0 : options.unref,
21
21
  maxRetryTime: options === null || options === void 0 ? void 0 : options.maxRetryTime,
22
22
  });
@@ -31,7 +31,7 @@ var _timeouts = function (options) {
31
31
  return timeout;
32
32
  };
33
33
  var defaultRetries = 10;
34
- var opts = __assign({ retries: defaultRetries, factor: 2, minTimeout: 1 * 1000, maxTimeout: Infinity, randomize: false }, options);
34
+ var opts = __assign({ retries: defaultRetries, factor: 2, minTimeout: 1 * 1000, maxTimeout: Number.POSITIVE_INFINITY, randomize: false }, options);
35
35
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36
36
  if (opts.minTimeout > opts.maxTimeout) {
37
37
  throw new Error("minTimeout is greater than maxTimeout");
@@ -4,7 +4,7 @@ function RetryOperation(timeouts, options) {
4
4
  this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
5
5
  this._timeouts = timeouts;
6
6
  this._options = options || {};
7
- this._maxRetryTime = (options === null || options === void 0 ? void 0 : options.maxRetryTime) || Infinity;
7
+ this._maxRetryTime = (options === null || options === void 0 ? void 0 : options.maxRetryTime) || Number.POSITIVE_INFINITY;
8
8
  this._fn = null;
9
9
  this._errors = [];
10
10
  this._attempts = 1;
package/esm/Api.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ApiResponse, BaseRequestConfig, RequestConfig, RequestMiddleware } from "./ApiTypes";
2
- import Endpoint from "./Endpoint";
1
+ import type { ApiResponse, BaseRequestConfig, RequestConfig, RequestMiddleware } from "./ApiTypes";
2
+ import type Endpoint from "./Endpoint";
3
3
  import EndpointBuilder from "./EndpointBuilder";
4
- import { ApiMockingConfig } from "./MockingTypes";
5
- import RequestBackend from "./backend/RequestBackend";
4
+ import type { ApiMockingConfig } from "./MockingTypes";
5
+ import type RequestBackend from "./backend/RequestBackend";
6
6
  export declare const getRequestBackend: () => RequestBackend | null;
7
7
  export declare const isRequestBackendDefault: () => boolean;
8
8
  export declare const setRequestBackend: (backend: RequestBackend) => void;
@@ -1,4 +1,4 @@
1
- import { EnumOf } from "./Utils";
1
+ import type { EnumOf } from "./Utils";
2
2
  export declare const RequestMethod: {
3
3
  /** @deprecated use 'POST' */
4
4
  readonly Post: "post";
package/esm/ApiTypes.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Api } from "./Api";
2
- import { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
- import RequestContext from "./RequestContext";
4
- import { Validation } from "./Validation";
5
- import RequestBackend from "./backend/RequestBackend";
1
+ import type { Api } from "./Api";
2
+ import type { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type RequestContext from "./RequestContext";
4
+ import type { Validation } from "./Validation";
5
+ import type RequestBackend from "./backend/RequestBackend";
6
6
  export type AcceptableStatus = number | [min: number, max: number];
7
7
  export type Headers = Record<string, string | number | boolean | null | undefined>;
8
8
  export type Params = string;
@@ -31,6 +31,7 @@ export interface RetryOptions {
31
31
  export interface BaseRequestConfig {
32
32
  cache?: number | boolean;
33
33
  lock?: RequestLock;
34
+ includeCredentials?: boolean;
34
35
  retry?: number | false | RetryOptions;
35
36
  headers?: Readonly<Headers>;
36
37
  acceptableStatus?: AcceptableStatus[];
package/esm/ApiUtils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ResponseType } from "./ApiConstants";
2
- import { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
1
+ import type { ResponseType } from "./ApiConstants";
2
+ import type { AcceptableStatus, CancelledRequestError } from "./ApiTypes";
3
3
  export declare const isCancelledError: (error: Error) => error is CancelledRequestError;
4
4
  export declare const isNetworkError: (error: Error) => boolean;
5
5
  export declare const isAcceptableStatus: (status: number, acceptableStatus?: AcceptableStatus[]) => boolean;
package/esm/ApiUtils.js CHANGED
@@ -3,7 +3,9 @@ export const isCancelledError = (error) => {
3
3
  };
4
4
  export const isNetworkError = (error) => {
5
5
  var _a;
6
- return error.name === "NetworkError" || error.message === "Network Error" || ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError";
6
+ return (error.name === "NetworkError" ||
7
+ error.message === "Network Error" ||
8
+ ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError");
7
9
  };
8
10
  const DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
9
11
  export const isAcceptableStatus = (status, acceptableStatus) => {
package/esm/Endpoint.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Api } from "./Api";
2
- import { RequestMethod, ResponseType } from "./ApiConstants";
3
- import { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
4
- import * as Mocking from "./MockingTypes";
5
- import { Validation } from "./Validation";
6
- import RequestBackend from "./backend/RequestBackend";
1
+ import type { Api } from "./Api";
2
+ import type { RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RequestConfig, RequestHost } from "./ApiTypes";
4
+ import type * as Mocking from "./MockingTypes";
5
+ import type { Validation } from "./Validation";
6
+ import type RequestBackend from "./backend/RequestBackend";
7
7
  export interface EndpointConfig<R, P extends Params | undefined, Q extends Query | undefined, B extends Body | undefined, Path extends string = string> {
8
8
  readonly id: string;
9
9
  readonly method: RequestMethod;
package/esm/Endpoint.js CHANGED
@@ -23,8 +23,8 @@ export default class Endpoint {
23
23
  this.validation = info.validation || {};
24
24
  }
25
25
  submit(config) {
26
- var _a, _b;
27
26
  return __awaiter(this, void 0, void 0, function* () {
27
+ var _a, _b;
28
28
  let mock = false;
29
29
  const apiMocking = this.api.mocking;
30
30
  if (apiMocking) {
@@ -1,7 +1,7 @@
1
- import * as zod from "zod";
2
- import { Api } from "./Api";
3
- import { Body, Params, Query } from "./ApiTypes";
4
- import Endpoint, { EndpointConfig } from "./Endpoint";
1
+ import type * as zod from "zod";
2
+ import type { Api } from "./Api";
3
+ import type { Body, Params, Query } from "./ApiTypes";
4
+ import Endpoint, { type EndpointConfig } from "./Endpoint";
5
5
  export default class EndpointBuilder<R = any, P extends Params | undefined = undefined, Q extends Query | undefined = undefined, B extends Body | undefined = undefined> {
6
6
  private api;
7
7
  private readonly validation;
@@ -1,4 +1,4 @@
1
- import { ApiResponse, Body, Headers, Params, Query } from "./ApiTypes";
1
+ import type { ApiResponse, Body, Headers, Params, Query } from "./ApiTypes";
2
2
  export interface ApiMockingConfig {
3
3
  enabled: boolean | (() => boolean);
4
4
  }
@@ -1,3 +1,3 @@
1
- import { QueryStringify } from "./ApiTypes";
1
+ import type { QueryStringify } from "./ApiTypes";
2
2
  export declare const DEFAULT_QUERY_STRINGIFY: QueryStringify;
3
3
  export declare const DEFAULT_QUERY_PARSE: (queryString: string) => Record<string, any>;
@@ -1,2 +1,2 @@
1
- import { BaseRequestConfig, Body, ComputedRequestConfig, Query, RequestConfig } from "./ApiTypes";
2
- export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (BaseRequestConfig | RequestConfig<P, Q, B> | undefined)[]) => ComputedRequestConfig<P, Q, B>;
1
+ import { type BaseRequestConfig, type Body, type ComputedRequestConfig, type Query, type RequestConfig } from "./ApiTypes";
2
+ export declare const computeRequestConfig: <P extends string | undefined, Q extends Query, B extends Body | undefined>(configs: (RequestConfig<P, Q, B> | BaseRequestConfig | undefined)[]) => ComputedRequestConfig<P, Q, B>;
@@ -1,4 +1,4 @@
1
- import { COMPUTED_CONFIG_SYMBOL } from "./ApiTypes";
1
+ import { COMPUTED_CONFIG_SYMBOL, } from "./ApiTypes";
2
2
  import { DEFAULT_QUERY_PARSE, DEFAULT_QUERY_STRINGIFY } from "./QueryHandling";
3
3
  import * as Utils from "./Utils";
4
4
  const MERGED_CONFIG_KEYS = ["headers"];
@@ -1,10 +1,10 @@
1
- import { Api } from "./Api";
2
- import { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
- import { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost } from "./ApiTypes";
4
- import { EndpointMockingConfig } from "./MockingTypes";
5
- import { RequestError } from "./RequestError";
6
- import { Validation } from "./Validation";
7
- import RequestBackend from "./backend/RequestBackend";
1
+ import type { Api } from "./Api";
2
+ import type { RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type { ApiResponse, Body, ComputedRequestConfig, EventResult, Headers, Params, Query, RequestCacheInfo, RequestContextStats, RequestEventHandlers, RequestHost } from "./ApiTypes";
4
+ import type { EndpointMockingConfig } from "./MockingTypes";
5
+ import type { RequestError } from "./RequestError";
6
+ import type { Validation } from "./Validation";
7
+ import type RequestBackend from "./backend/RequestBackend";
8
8
  export default class RequestContext<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
9
9
  readonly id: number;
10
10
  readonly key: string;
@@ -1,6 +1,6 @@
1
- import { ApiResponse } from "./ApiTypes";
2
- import RequestContext from "./RequestContext";
3
- import { EnumOf } from "./Utils";
1
+ import type { ApiResponse } from "./ApiTypes";
2
+ import type RequestContext from "./RequestContext";
3
+ import type { EnumOf } from "./Utils";
4
4
  export declare const RequestErrorCode: {
5
5
  readonly MISC_UNKNOWN_ERROR: "misc/unknown-error";
6
6
  readonly REQUEST_NETWORK_ERROR: "request/network-error";
@@ -30,7 +30,9 @@ export const convertToRequestError = (config) => {
30
30
  },
31
31
  });
32
32
  try {
33
- Object.defineProperty(resultError, "message", { value: `Request failed${(response === null || response === void 0 ? void 0 : response.status) ? ` with status code ${response.status}` : ""} [${code}]: ${resultError.message}` });
33
+ Object.defineProperty(resultError, "message", {
34
+ value: `Request failed${(response === null || response === void 0 ? void 0 : response.status) ? ` with status code ${response.status}` : ""} [${code}]: ${resultError.message}`,
35
+ });
34
36
  }
35
37
  catch (e) {
36
38
  // ignore
@@ -1,3 +1,3 @@
1
- import { ApiResponse, Body, Query, RequestConfig, RequestHost } from "./ApiTypes";
2
- import { EndpointMockingConfig } from "./MockingTypes";
1
+ import type { ApiResponse, Body, Query, RequestConfig, RequestHost } from "./ApiTypes";
2
+ import type { EndpointMockingConfig } from "./MockingTypes";
3
3
  export declare const submit: <R, P extends string | undefined, Q extends Query, B extends Body | undefined>(host: RequestHost, config: RequestConfig<P, Q, B>, mocking: EndpointMockingConfig<R, P, Q, B> | null | undefined) => Promise<ApiResponse<R>>;
package/esm/Requester.js CHANGED
@@ -234,7 +234,9 @@ const parseError = (context, rawError) => __awaiter(void 0, void 0, void 0, func
234
234
  if (extractedResponse !== undefined) {
235
235
  errorResponse = yield parseResponse(context, extractedResponse, true);
236
236
  }
237
- let code = isNetworkError(rawError) ? RequestErrorCode.REQUEST_NETWORK_ERROR : RequestErrorCode.MISC_UNKNOWN_ERROR;
237
+ let code = isNetworkError(rawError)
238
+ ? RequestErrorCode.REQUEST_NETWORK_ERROR
239
+ : RequestErrorCode.MISC_UNKNOWN_ERROR;
238
240
  if (errorResponse) {
239
241
  if (!isAcceptableStatus(errorResponse.status, context.computedConfig.acceptableStatus)) {
240
242
  code = RequestErrorCode.REQUEST_INVALID_STATUS;
@@ -19,7 +19,9 @@ export const textDecode = (inputArrayOrBuffer, options) => {
19
19
  let asObjectString;
20
20
  if (!arrayBuffer_isView(inputAs8)) {
21
21
  asObjectString = Object_prototype_toString.call(inputAs8);
22
- if (asObjectString !== arrayBufferString && asObjectString !== sharedArrayBufferString && asObjectString !== undefinedObjectString)
22
+ if (asObjectString !== arrayBufferString &&
23
+ asObjectString !== sharedArrayBufferString &&
24
+ asObjectString !== undefinedObjectString)
23
25
  throw TypeError("Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
24
26
  inputAs8 = NativeUint8Array ? new patchedU8Array(inputAs8) : inputAs8 || [];
25
27
  }
@@ -1,4 +1,4 @@
1
- import Endpoint from "./Endpoint";
1
+ import type Endpoint from "./Endpoint";
2
2
  export type ResponseOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<infer R, any, any, any> ? R : never;
3
3
  export type ParamsOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, infer P, any, any> ? P : never;
4
4
  export type QueryOf<E extends Endpoint<any, any, any, any>> = E extends Endpoint<any, any, infer Q, any> ? Q : never;
@@ -1,5 +1,5 @@
1
- import * as zod from "zod";
2
- import { Body, Params, Query } from "./ApiTypes";
1
+ import type * as zod from "zod";
2
+ import type { Body, Params, Query } from "./ApiTypes";
3
3
  export interface Validation<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
4
4
  query?: zod.Schema<Q>;
5
5
  params?: zod.Schema<P>;
@@ -1,7 +1,8 @@
1
1
  import type { AxiosError, AxiosResponse } from "axios";
2
- import { ApiResponse } from "../ApiTypes";
3
- import RequestContext from "../RequestContext";
4
- import RequestBackend, { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
2
+ import type { ApiResponse } from "../ApiTypes";
3
+ import type RequestContext from "../RequestContext";
4
+ import type RequestBackend from "./RequestBackend";
5
+ import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
5
6
  export declare const isAxiosError: (error: Error) => error is AxiosError<unknown, any>;
6
7
  export default class AxiosRequestBackend implements RequestBackend<AxiosResponse> {
7
8
  readonly id = "axios";
@@ -47,6 +47,7 @@ export default class AxiosRequestBackend {
47
47
  data: context.getParsedBody(),
48
48
  headers: computedConfig.headers || {},
49
49
  responseType: context.responseType,
50
+ withCredentials: computedConfig.includeCredentials,
50
51
  cancelToken: new axios.CancelToken((cancellerFunc) => {
51
52
  canceler = cancellerFunc;
52
53
  }),
@@ -1,7 +1,8 @@
1
- import { ApiResponse } from "../ApiTypes";
2
- import RequestContext from "../RequestContext";
3
- import { Fetch } from "../Utils";
4
- import RequestBackend, { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
1
+ import type { ApiResponse } from "../ApiTypes";
2
+ import type RequestContext from "../RequestContext";
3
+ import { type Fetch } from "../Utils";
4
+ import type RequestBackend from "./RequestBackend";
5
+ import type { ConvertedApiResponse, RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
5
6
  export default class FetchRequestBackend implements RequestBackend<Response> {
6
7
  fetch: (((input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>) & typeof fetch) | undefined;
7
8
  readonly id = "fetch";
@@ -35,8 +35,8 @@ export default class FetchRequestBackend {
35
35
  });
36
36
  }
37
37
  convertResponse(context, response) {
38
- var _a;
39
38
  return __awaiter(this, void 0, void 0, function* () {
39
+ var _a;
40
40
  const { status, headers } = response;
41
41
  const processedHeaders = {};
42
42
  headers.forEach((value, key) => {
@@ -103,13 +103,18 @@ export default class FetchRequestBackend {
103
103
  return parsedHeaders;
104
104
  }, {});
105
105
  const url = context.requestUrl;
106
- const promise = this.fetch(url.href, {
106
+ const fetchOptions = {
107
107
  method: context.method.toUpperCase(),
108
108
  body: bodyJsonify ? JSON.stringify(body) : body,
109
109
  headers: parsedHeaders,
110
- mode: "cors",
110
+ credentials: context.computedConfig.includeCredentials ? "include" : undefined,
111
111
  signal: abortSignal,
112
- }).then((response) => {
112
+ };
113
+ // edge doesn't support mode
114
+ if ("mode" in Request.prototype) {
115
+ fetchOptions.mode = "cors";
116
+ }
117
+ const promise = this.fetch(url.href, fetchOptions).then((response) => {
113
118
  responded = true;
114
119
  if (!response.ok) {
115
120
  const error = new FetchError("Fetch failed");
@@ -1,6 +1,7 @@
1
- import { ApiResponse } from "../ApiTypes";
2
- import RequestContext from "../RequestContext";
3
- import RequestBackend, { RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
1
+ import type { ApiResponse } from "../ApiTypes";
2
+ import type RequestContext from "../RequestContext";
3
+ import type RequestBackend from "./RequestBackend";
4
+ import type { RequestBackendErrorInfo, RequestOperation } from "./RequestBackend";
4
5
  export default class MockRequestBackend implements RequestBackend<ApiResponse> {
5
6
  readonly id = "mock";
6
7
  convertResponse<T>(context: RequestContext, response: ApiResponse, error?: boolean): Promise<ApiResponse<T>>;
@@ -29,8 +29,8 @@ export default class MockRequestBackend {
29
29
  });
30
30
  }
31
31
  runRequest(context) {
32
- var _a, _b, _c, _d;
33
32
  return __awaiter(this, void 0, void 0, function* () {
33
+ var _a, _b, _c, _d;
34
34
  const mockingFunc = (_a = context.mocking) === null || _a === void 0 ? void 0 : _a.handler;
35
35
  if (!mockingFunc) {
36
36
  throw convertToRequestError({
@@ -1,5 +1,5 @@
1
- import { ApiResponse } from "../ApiTypes";
2
- import RequestContext from "../RequestContext";
1
+ import type { ApiResponse } from "../ApiTypes";
2
+ import type RequestContext from "../RequestContext";
3
3
  export interface RequestOperation<R> {
4
4
  promise: Promise<R>;
5
5
  canceler: () => void;
@@ -1,4 +1,4 @@
1
- import { CacheBackend } from "./CacheBackend";
1
+ import type { CacheBackend } from "./CacheBackend";
2
2
  export declare const setCacheBackend: (backend: CacheBackend) => void;
3
3
  export declare const DEFAULT_CACHE_EXPIRY: number;
4
4
  export declare const clearCache: () => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { CacheBackend } from "./CacheBackend";
1
+ import type { CacheBackend } from "./CacheBackend";
2
2
  export default class LocalForageCacheBackend implements CacheBackend {
3
3
  private readonly store;
4
4
  constructor(localforage: any);
@@ -1,4 +1,4 @@
1
- import { CacheBackend } from "./CacheBackend";
1
+ import type { CacheBackend } from "./CacheBackend";
2
2
  export default class LocalStorageCacheBackend implements CacheBackend {
3
3
  clear(): Promise<void>;
4
4
  getItem<T>(key: string): Promise<T | null>;
@@ -1,4 +1,4 @@
1
- import { RequestMiddleware } from "../ApiTypes";
1
+ import type { RequestMiddleware } from "../ApiTypes";
2
2
  export interface CacheMiddlewareOptions {
3
3
  defaultExpiry?: number;
4
4
  predicate?: () => boolean;
@@ -1,4 +1,4 @@
1
- import { RequestMiddleware } from "../ApiTypes";
1
+ import type { RequestMiddleware } from "../ApiTypes";
2
2
  export interface LoggingMiddlewareOptions {
3
3
  predicate?: () => boolean;
4
4
  }
@@ -40,7 +40,13 @@ const log = (context, type, message, config, objects) => {
40
40
  }
41
41
  const color = COLOR_MAP[type];
42
42
  const timestamp = formatTime(new Date());
43
- const args = [`%cnetwork %c[${context.api.name}] ${context.method.toUpperCase()} ${context.path} %c${message} %c@ ${timestamp}`, "color:gray", "color:auto", `color:${color}`, "color:gray"];
43
+ const args = [
44
+ `%cnetwork %c[${context.api.name}] ${context.method.toUpperCase()} ${context.path} %c${message} %c@ ${timestamp}`,
45
+ "color:gray",
46
+ "color:auto",
47
+ `color:${color}`,
48
+ "color:gray",
49
+ ];
44
50
  /* eslint-disable-next-line no-console */
45
51
  console.groupCollapsed(...args);
46
52
  /* eslint-disable-next-line no-console */
@@ -1,3 +1,3 @@
1
- import { RetryFunction, RetryOptions } from "./interfaces";
1
+ import type { RetryFunction, RetryOptions } from "./interfaces";
2
2
  declare const retry: <A>(fn: RetryFunction<A>, opts: RetryOptions) => Promise<A>;
3
3
  export default retry;
@@ -1,3 +1,3 @@
1
- import { RetryOptions } from "../interfaces";
1
+ import type { RetryOptions } from "../interfaces";
2
2
  import RetryOperation from "./retryOperation";
3
3
  export declare const operation: (options: RetryOptions) => RetryOperation;
@@ -2,7 +2,7 @@ import RetryOperation from "./retryOperation";
2
2
  export const operation = (options) => {
3
3
  const timeouts = _timeouts(options);
4
4
  return new RetryOperation(timeouts, {
5
- forever: options && (options.forever || options.retries === Infinity),
5
+ forever: options && (options.forever || options.retries === Number.POSITIVE_INFINITY),
6
6
  unref: options === null || options === void 0 ? void 0 : options.unref,
7
7
  maxRetryTime: options === null || options === void 0 ? void 0 : options.maxRetryTime,
8
8
  });
@@ -16,7 +16,7 @@ const _timeouts = (options) => {
16
16
  return timeout;
17
17
  };
18
18
  const defaultRetries = 10;
19
- const opts = Object.assign({ retries: defaultRetries, factor: 2, minTimeout: 1 * 1000, maxTimeout: Infinity, randomize: false }, options);
19
+ const opts = Object.assign({ retries: defaultRetries, factor: 2, minTimeout: 1 * 1000, maxTimeout: Number.POSITIVE_INFINITY, randomize: false }, options);
20
20
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
21
21
  if (opts.minTimeout > opts.maxTimeout) {
22
22
  throw new Error("minTimeout is greater than maxTimeout");
@@ -2,7 +2,7 @@ function RetryOperation(timeouts, options) {
2
2
  this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
3
3
  this._timeouts = timeouts;
4
4
  this._options = options || {};
5
- this._maxRetryTime = (options === null || options === void 0 ? void 0 : options.maxRetryTime) || Infinity;
5
+ this._maxRetryTime = (options === null || options === void 0 ? void 0 : options.maxRetryTime) || Number.POSITIVE_INFINITY;
6
6
  this._fn = null;
7
7
  this._errors = [];
8
8
  this._attempts = 1;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.9.3",
3
+ "version": "0.9.4-alpha.2",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",
7
7
  "module": "esm/index.js",
8
8
  "sideEffects": false,
9
9
  "scripts": {
10
- "prepublishOnly": "npm run check && npm run test && npm run build",
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-unsafe .",
13
+ "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --apply .",
14
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",
@@ -19,26 +19,10 @@
19
19
  "website:dev": "cd website && npm run start",
20
20
  "website:deploy": "cd website && npm run deploy"
21
21
  },
22
- "keywords": [
23
- "typescript",
24
- "javascript",
25
- "node",
26
- "web",
27
- "api",
28
- "typed",
29
- "cache",
30
- "fetch",
31
- "retry",
32
- "middleware"
33
- ],
22
+ "keywords": ["typescript", "javascript", "node", "web", "api", "typed", "cache", "fetch", "retry", "middleware"],
34
23
  "author": "James Waterhouse <09jwater@gmail.com>",
35
24
  "license": "MIT",
36
- "files": [
37
- "LICENSE",
38
- "README.md",
39
- "esm/",
40
- "cjs/"
41
- ],
25
+ "files": ["LICENSE", "README.md", "esm/", "cjs/"],
42
26
  "jest": {
43
27
  "transform": {
44
28
  "^.+\\.(t|j)sx?$": "@swc/jest"
@@ -46,19 +30,20 @@
46
30
  },
47
31
  "repository": "https://github.com/Censkh/api-def",
48
32
  "devDependencies": {
49
- "@biomejs/biome": "^1.5.3",
50
- "@swc/jest": "0.2.31",
33
+ "@biomejs/biome": "latest",
34
+ "@swc/core": "latest",
35
+ "@swc/jest": "latest",
51
36
  "@types/axios": "0.14.0",
52
- "@types/jest": "^29.5.11",
53
- "@types/node": "20.11.6",
54
- "@types/qs": "6.9.11",
55
- "axios": "1.6.6",
37
+ "@types/jest": "^29.5.12",
38
+ "@types/node": "20.12.7",
39
+ "@types/qs": "6.9.15",
40
+ "axios": "1.6.8",
56
41
  "cross-env": "7.0.3",
57
- "jest": "29.7.0",
42
+ "jest": "latest",
58
43
  "npm-run-all": "4.1.5",
59
- "qs": "6.11.2",
44
+ "qs": "6.12.1",
60
45
  "rimraf": "5.0.5",
61
- "typescript": "5.3.3",
62
- "zod": "3.22.4"
46
+ "typescript": "5.4.5",
47
+ "zod": "3.22.5"
63
48
  }
64
49
  }