api-def 0.12.1 → 0.14.0-alpha.1

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 (87) hide show
  1. package/README.md +3 -0
  2. package/bin/index.js +312 -313
  3. package/cjs/Api.d.ts +1 -1
  4. package/cjs/Api.js +99 -145
  5. package/cjs/ApiTypes.d.ts +3 -2
  6. package/cjs/ApiUtils.js +30 -32
  7. package/cjs/Endpoint.d.ts +1 -1
  8. package/cjs/Endpoint.js +112 -175
  9. package/cjs/EndpointBuilder.d.ts +17 -0
  10. package/cjs/EndpointBuilder.js +55 -36
  11. package/cjs/QueryHandling.js +12 -13
  12. package/cjs/RequestConfig.js +54 -36
  13. package/cjs/RequestContext.d.ts +2 -1
  14. package/cjs/RequestContext.js +143 -180
  15. package/cjs/RequestError.js +16 -19
  16. package/cjs/Requester.js +231 -312
  17. package/cjs/TextDecoding.js +31 -31
  18. package/cjs/Utils.d.ts +1 -0
  19. package/cjs/Utils.js +74 -25
  20. package/cjs/Validation.d.ts +8 -1
  21. package/cjs/backend/AxiosRequestBackend.d.ts +1 -1
  22. package/cjs/backend/AxiosRequestBackend.js +65 -172
  23. package/cjs/backend/FetchRequestBackend.d.ts +1 -1
  24. package/cjs/backend/FetchRequestBackend.js +108 -154
  25. package/cjs/backend/MockRequestBackend.d.ts +1 -1
  26. package/cjs/backend/MockRequestBackend.js +146 -208
  27. package/cjs/cache/ClientCaching.js +26 -74
  28. package/cjs/cache/LocalForageClientCacheBackend.js +15 -83
  29. package/cjs/cache/LocalStorageClientCacheBackend.js +14 -73
  30. package/cjs/index.d.ts +11 -11
  31. package/cjs/index.js +24 -21
  32. package/cjs/middleware/ClientCacheMiddleware.js +80 -103
  33. package/cjs/middleware/LoggingMiddleware.js +71 -42
  34. package/cjs/util/retry/index.js +42 -9
  35. package/cjs/util/retry/lib/retry.js +25 -27
  36. package/cjs/util/retry/lib/retryOperation.d.ts +1 -26
  37. package/cjs/util/retry/lib/retryOperation.js +21 -23
  38. package/esm/Api.d.ts +6 -6
  39. package/esm/Api.js +12 -25
  40. package/esm/ApiConstants.d.ts +1 -1
  41. package/esm/ApiTypes.d.ts +7 -6
  42. package/esm/ApiUtils.d.ts +2 -2
  43. package/esm/ApiUtils.js +4 -5
  44. package/esm/Endpoint.d.ts +6 -6
  45. package/esm/Endpoint.js +22 -28
  46. package/esm/EndpointBuilder.d.ts +21 -4
  47. package/esm/EndpointBuilder.js +38 -10
  48. package/esm/MockingTypes.d.ts +1 -1
  49. package/esm/QueryHandling.d.ts +1 -1
  50. package/esm/QueryHandling.js +2 -3
  51. package/esm/RequestConfig.d.ts +1 -1
  52. package/esm/RequestConfig.js +6 -7
  53. package/esm/RequestContext.d.ts +8 -7
  54. package/esm/RequestContext.js +33 -27
  55. package/esm/RequestError.d.ts +3 -3
  56. package/esm/RequestError.js +2 -3
  57. package/esm/Requester.d.ts +2 -2
  58. package/esm/Requester.js +45 -50
  59. package/esm/UtilTypes.d.ts +1 -1
  60. package/esm/Utils.d.ts +1 -0
  61. package/esm/Utils.js +54 -2
  62. package/esm/Validation.d.ts +8 -1
  63. package/esm/backend/AxiosRequestBackend.d.ts +4 -4
  64. package/esm/backend/AxiosRequestBackend.js +47 -84
  65. package/esm/backend/FetchRequestBackend.d.ts +5 -5
  66. package/esm/backend/FetchRequestBackend.js +50 -64
  67. package/esm/backend/MockRequestBackend.d.ts +4 -4
  68. package/esm/backend/MockRequestBackend.js +105 -136
  69. package/esm/backend/RequestBackend.d.ts +2 -2
  70. package/esm/cache/ClientCaching.d.ts +1 -1
  71. package/esm/cache/ClientCaching.js +8 -17
  72. package/esm/cache/LocalForageClientCacheBackend.d.ts +1 -1
  73. package/esm/cache/LocalForageClientCacheBackend.js +8 -25
  74. package/esm/cache/LocalStorageClientCacheBackend.d.ts +1 -1
  75. package/esm/cache/LocalStorageClientCacheBackend.js +9 -26
  76. package/esm/index.d.ts +16 -16
  77. package/esm/index.js +15 -15
  78. package/esm/middleware/ClientCacheMiddleware.d.ts +1 -1
  79. package/esm/middleware/ClientCacheMiddleware.js +8 -17
  80. package/esm/middleware/LoggingMiddleware.d.ts +1 -1
  81. package/esm/middleware/LoggingMiddleware.js +5 -6
  82. package/esm/util/retry/index.js +1 -1
  83. package/esm/util/retry/lib/retry.d.ts +1 -1
  84. package/esm/util/retry/lib/retry.js +13 -7
  85. package/esm/util/retry/lib/retryOperation.d.ts +1 -26
  86. package/esm/util/retry/lib/retryOperation.js +1 -1
  87. package/package.json +67 -28
package/cjs/Api.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { ApiResponse, BaseRequestConfig, RequestConfig, RequestMiddleware } from "./ApiTypes";
2
2
  import { type ResolveUrlOptions } from "./ApiUtils";
3
+ import type RequestBackend from "./backend/RequestBackend";
3
4
  import type Endpoint from "./Endpoint";
4
5
  import EndpointBuilder from "./EndpointBuilder";
5
6
  import type { ApiMockingConfig } from "./MockingTypes";
6
- import type RequestBackend from "./backend/RequestBackend";
7
7
  export declare const getRequestBackend: () => RequestBackend | null;
8
8
  export declare const isRequestBackendDefault: () => boolean;
9
9
  export declare const setRequestBackend: (backend: RequestBackend) => void;
package/cjs/Api.js CHANGED
@@ -1,95 +1,88 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
36
7
  }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.Api = exports.setRequestBackend = exports.isRequestBackendDefault = exports.getRequestBackend = void 0;
40
- var ApiConstants_1 = require("./ApiConstants");
41
- var ApiUtils_1 = require("./ApiUtils");
42
- var EndpointBuilder_1 = require("./EndpointBuilder");
43
- var RequestConfig_1 = require("./RequestConfig");
44
- var Requester = require("./Requester");
45
- var Utils = require("./Utils");
46
- var FetchRequestBackend_1 = require("./backend/FetchRequestBackend");
40
+ const ApiConstants_1 = require("./ApiConstants");
41
+ const ApiUtils_1 = require("./ApiUtils");
42
+ const FetchRequestBackend_1 = __importDefault(require("./backend/FetchRequestBackend"));
43
+ const EndpointBuilder_1 = __importDefault(require("./EndpointBuilder"));
44
+ const RequestConfig_1 = require("./RequestConfig");
45
+ const Requester = __importStar(require("./Requester"));
46
+ const Utils = __importStar(require("./Utils"));
47
47
  // use fetch as default if it is present
48
- var requestBackend = Utils.getGlobalFetch() ? new FetchRequestBackend_1.default() : null;
49
- var requestBackendIsDefault = true;
50
- var getRequestBackend = function () {
48
+ let requestBackend = Utils.getGlobalFetch() ? new FetchRequestBackend_1.default() : null;
49
+ let requestBackendIsDefault = true;
50
+ const getRequestBackend = () => {
51
51
  return requestBackend;
52
52
  };
53
53
  exports.getRequestBackend = getRequestBackend;
54
- var isRequestBackendDefault = function () {
54
+ const isRequestBackendDefault = () => {
55
55
  return requestBackendIsDefault;
56
56
  };
57
57
  exports.isRequestBackendDefault = isRequestBackendDefault;
58
- var setRequestBackend = function (backend) {
58
+ const setRequestBackend = (backend) => {
59
59
  requestBackendIsDefault = false;
60
60
  requestBackend = backend;
61
61
  };
62
62
  exports.setRequestBackend = setRequestBackend;
63
- var HotRequestHost = /** @class */ (function () {
64
- function HotRequestHost(api, path, method) {
63
+ class HotRequestHost {
64
+ constructor(api, path, method) {
65
65
  this.responseType = undefined;
66
66
  this.validation = {};
67
67
  this.api = api;
68
68
  this.method = method;
69
69
  this.path = path;
70
70
  }
71
- Object.defineProperty(HotRequestHost.prototype, "baseUrl", {
72
- get: function () {
73
- return this.api.baseUrl;
74
- },
75
- enumerable: false,
76
- configurable: true
77
- });
78
- HotRequestHost.prototype.computeConfig = function (config) {
79
- var apiDefaults = this.api.computeRequestConfig();
71
+ get baseUrl() {
72
+ return this.api.baseUrl;
73
+ }
74
+ computeConfig(config) {
75
+ const apiDefaults = this.api.computeRequestConfig();
80
76
  return (0, RequestConfig_1.processRequestConfigs)([apiDefaults, config]);
81
- };
82
- HotRequestHost.prototype.getRequestBackend = function () {
77
+ }
78
+ getRequestBackend() {
83
79
  return this.api.requestBackend;
84
- };
85
- return HotRequestHost;
86
- }());
87
- var Api = /** @class */ (function () {
80
+ }
81
+ }
82
+ class Api {
88
83
  //private mutable = false;
89
84
  //private wasMutable = false;
90
- function Api(options) {
91
- var _this = this;
92
- var _a, _b, _c, _d;
85
+ constructor(options) {
93
86
  this.endpoints = {};
94
87
  /*configure(info: Partial<ApiInfo>): void {
95
88
  if (!this.mutable) {
@@ -101,22 +94,13 @@ var Api = /** @class */ (function () {
101
94
  Object.assign(this.info, info);
102
95
  this.mutable = false;
103
96
  }*/
104
- this.hotRequest = function (requestMethod) {
105
- return function (path, config) { return __awaiter(_this, void 0, void 0, function () {
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0: return [4 /*yield*/, Requester.submit(new HotRequestHost(this, path instanceof URL ? path.href : path, requestMethod), config, null)];
109
- case 1: return [2 /*return*/, _a.sent()];
110
- }
111
- });
112
- }); };
113
- };
97
+ this.hotRequest = (requestMethod) => async (path, config) => await Requester.submit(new HotRequestHost(this, path instanceof URL ? path.href : path, requestMethod), config, null);
114
98
  this.get = this.hotRequest(ApiConstants_1.RequestMethod.GET);
115
99
  this.post = this.hotRequest(ApiConstants_1.RequestMethod.POST);
116
100
  this.put = this.hotRequest(ApiConstants_1.RequestMethod.PUT);
117
101
  this.delete = this.hotRequest(ApiConstants_1.RequestMethod.DELETE);
118
102
  this.patch = this.hotRequest(ApiConstants_1.RequestMethod.PATCH);
119
- var requestBackend = (_a = options.requestBackend) !== null && _a !== void 0 ? _a : (0, exports.getRequestBackend)();
103
+ const requestBackend = options.requestBackend ?? (0, exports.getRequestBackend)();
120
104
  if (!requestBackend) {
121
105
  throw new Error("[api-def] No request backend provided in either Api options or globally, use `setRequestBackend()` to set one or pass one via `requestBackend`");
122
106
  }
@@ -124,91 +108,61 @@ var Api = /** @class */ (function () {
124
108
  name: options.name,
125
109
  baseUrl: options.baseUrl,
126
110
  middleware: options.middleware || [],
127
- defaultRequestConfig: (_c = (_b = options.defaultRequestConfig) !== null && _b !== void 0 ? _b : options.config) !== null && _c !== void 0 ? _c : undefined,
128
- mocking: (_d = options.mocking) !== null && _d !== void 0 ? _d : undefined,
111
+ defaultRequestConfig: options.defaultRequestConfig ?? options.config ?? undefined,
112
+ mocking: options.mocking ?? undefined,
129
113
  requestBackend: requestBackend,
130
114
  };
131
115
  //this.mutable = options.mutable ?? false;
132
116
  //this.wasMutable = this.mutable;
133
117
  this.endpoints = {};
134
118
  }
135
- Object.defineProperty(Api.prototype, "requestBackend", {
136
- get: function () {
137
- return this.info.requestBackend;
138
- },
139
- enumerable: false,
140
- configurable: true
141
- });
142
- Object.defineProperty(Api.prototype, "baseUrl", {
143
- get: function () {
144
- return this.info.baseUrl;
145
- },
146
- enumerable: false,
147
- configurable: true
148
- });
149
- Object.defineProperty(Api.prototype, "config", {
150
- /**
151
- * @deprecated use `defaultRequestConfig` instead
152
- */
153
- get: function () {
154
- return this.info.defaultRequestConfig;
155
- },
156
- enumerable: false,
157
- configurable: true
158
- });
159
- Object.defineProperty(Api.prototype, "defaultRequestConfig", {
160
- get: function () {
161
- return this.info.defaultRequestConfig;
162
- },
163
- enumerable: false,
164
- configurable: true
165
- });
166
- Object.defineProperty(Api.prototype, "middleware", {
167
- get: function () {
168
- return this.info.middleware;
169
- },
170
- enumerable: false,
171
- configurable: true
172
- });
173
- Object.defineProperty(Api.prototype, "mocking", {
174
- get: function () {
175
- return this.info.mocking;
176
- },
177
- enumerable: false,
178
- configurable: true
179
- });
180
- Object.defineProperty(Api.prototype, "name", {
181
- get: function () {
182
- return this.info.name;
183
- },
184
- enumerable: false,
185
- configurable: true
186
- });
187
- Api.prototype.endpoint = function () {
119
+ get requestBackend() {
120
+ return this.info.requestBackend;
121
+ }
122
+ get baseUrl() {
123
+ return this.info.baseUrl;
124
+ }
125
+ /**
126
+ * @deprecated use `defaultRequestConfig` instead
127
+ */
128
+ get config() {
129
+ return this.info.defaultRequestConfig;
130
+ }
131
+ get defaultRequestConfig() {
132
+ return this.info.defaultRequestConfig;
133
+ }
134
+ get middleware() {
135
+ return this.info.middleware;
136
+ }
137
+ get mocking() {
138
+ return this.info.mocking;
139
+ }
140
+ get name() {
141
+ return this.info.name;
142
+ }
143
+ endpoint() {
188
144
  return new EndpointBuilder_1.default(this);
189
- };
145
+ }
190
146
  /**
191
147
  * @deprecated use `requestBackend` instead
192
148
  */
193
- Api.prototype.getRequestBackend = function () {
149
+ getRequestBackend() {
194
150
  return this.requestBackend;
195
- };
151
+ }
196
152
  /**
197
153
  * @deprecated use `computeRequestConfig()` instead
198
154
  */
199
- Api.prototype.getConfig = function () {
155
+ getConfig() {
200
156
  return this.computeRequestConfig();
201
- };
202
- Api.prototype.computeRequestConfig = function () {
157
+ }
158
+ computeRequestConfig() {
203
159
  return ((typeof this.defaultRequestConfig === "function" ? this.defaultRequestConfig() : this.defaultRequestConfig) || {});
204
- };
205
- Api.prototype.resolveUrl = function (options) {
206
- var _a;
160
+ }
161
+ resolveUrl(options) {
207
162
  return (0, ApiUtils_1.resolveUrl)({
208
- baseUrl: (_a = options.baseUrl) !== null && _a !== void 0 ? _a : this.baseUrl,
163
+ baseUrl: options.baseUrl ?? this.baseUrl,
209
164
  path: options.path,
210
165
  });
211
- };
212
- return Api;
213
- }());
166
+ }
167
+ }
214
168
  exports.Api = Api;
package/cjs/ApiTypes.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import type { Api } from "./Api";
2
2
  import type { CacheSource, EventResultType, RequestEvent, RequestMethod, ResponseType } from "./ApiConstants";
3
+ import type RequestBackend from "./backend/RequestBackend";
3
4
  import type RequestContext from "./RequestContext";
4
5
  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 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
- export type Body = string | number | Record<string, any>;
10
+ export type Body = string | number | Record<string, any> | FormData;
11
+ export type RequestBodyEncoding = "application/json" | "multipart/form-data" | "application/x-www-form-urlencoded";
11
12
  export type State = Record<string, any>;
12
13
  export interface ApiResponse<T = any> {
13
14
  readonly method: RequestMethod;
package/cjs/ApiUtils.js CHANGED
@@ -1,28 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveUrl = exports.resolvePathParams = exports.inferResponseType = exports.isAcceptableStatus = exports.isAbsoluteUrl = exports.isNetworkError = exports.isCancelledError = void 0;
4
- var isCancelledError = function (error) {
4
+ const isCancelledError = (error) => {
5
5
  return "isCancelledRequest" in error;
6
6
  };
7
7
  exports.isCancelledError = isCancelledError;
8
- var isNetworkError = function (error) {
9
- var _a;
8
+ const isNetworkError = (error) => {
10
9
  return (error.name === "NetworkError" ||
11
10
  error.message === "Network Error" ||
12
- ((_a = error.constructor) === null || _a === void 0 ? void 0 : _a.name) === "NetworkError");
11
+ error.constructor?.name === "NetworkError");
13
12
  };
14
13
  exports.isNetworkError = isNetworkError;
15
- var isAbsoluteUrl = function (url) {
14
+ const isAbsoluteUrl = (url) => {
16
15
  return /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(url);
17
16
  };
18
17
  exports.isAbsoluteUrl = isAbsoluteUrl;
19
- var DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
20
- var isAcceptableStatus = function (status, acceptableStatus) {
21
- var acceptable = acceptableStatus !== null && acceptableStatus !== void 0 ? acceptableStatus : DEFAULT_ACCEPTABLE_STATUS;
22
- for (var _i = 0, acceptable_1 = acceptable; _i < acceptable_1.length; _i++) {
23
- var cmpStatus = acceptable_1[_i];
18
+ const DEFAULT_ACCEPTABLE_STATUS = [[200, 299], 304];
19
+ const isAcceptableStatus = (status, acceptableStatus) => {
20
+ const acceptable = acceptableStatus ?? DEFAULT_ACCEPTABLE_STATUS;
21
+ for (const cmpStatus of acceptable) {
24
22
  if (Array.isArray(cmpStatus)) {
25
- var min = cmpStatus[0], max = cmpStatus[1];
23
+ const [min, max] = cmpStatus;
26
24
  if (status >= min && status <= max) {
27
25
  return true;
28
26
  }
@@ -36,12 +34,12 @@ var isAcceptableStatus = function (status, acceptableStatus) {
36
34
  return false;
37
35
  };
38
36
  exports.isAcceptableStatus = isAcceptableStatus;
39
- var TEXT_CONTENT_TYPES = ["text/plain", "text/html", "text/xml", "application/xml"];
40
- var JSON_CONTENT_TYPES = ["text/json", "application/json"];
41
- var ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
42
- var STREAM_CONTENT_TYPES = ["text/event-stream", "application/x-ndjson"];
43
- var inferResponseType = function (contentType) {
44
- var contentTypePart = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0].trim();
37
+ const TEXT_CONTENT_TYPES = ["text/plain", "text/html", "text/xml", "application/xml"];
38
+ const JSON_CONTENT_TYPES = ["text/json", "application/json"];
39
+ const ARRAY_BUFFER_CONTENT_TYPES = ["application/octet-stream"];
40
+ const STREAM_CONTENT_TYPES = ["text/event-stream", "application/x-ndjson"];
41
+ const inferResponseType = (contentType) => {
42
+ const contentTypePart = contentType?.split(";")[0].trim();
45
43
  if (contentTypePart) {
46
44
  if (TEXT_CONTENT_TYPES.includes(contentTypePart)) {
47
45
  return "text";
@@ -59,14 +57,14 @@ var inferResponseType = function (contentType) {
59
57
  return "text";
60
58
  };
61
59
  exports.inferResponseType = inferResponseType;
62
- var resolvePathParams = function (path, params, allowMissing) {
63
- var computedPath = path.startsWith("/") || (0, exports.isAbsoluteUrl)(path) ? path : "/".concat(path);
60
+ const resolvePathParams = (path, params, allowMissing) => {
61
+ const computedPath = path.startsWith("/") || (0, exports.isAbsoluteUrl)(path) ? path : `/${path}`;
64
62
  if (params) {
65
- var computedPathParts = computedPath.split("/");
66
- var unusedKeys = new Set(Object.keys(params));
67
- for (var i = 0; i < computedPathParts.length; i++) {
68
- var part = computedPathParts[i];
69
- var paramKey = void 0;
63
+ const computedPathParts = computedPath.split("/");
64
+ const unusedKeys = new Set(Object.keys(params));
65
+ for (let i = 0; i < computedPathParts.length; i++) {
66
+ const part = computedPathParts[i];
67
+ let paramKey;
70
68
  if (part.startsWith(":")) {
71
69
  paramKey = part.substring(1);
72
70
  }
@@ -74,42 +72,42 @@ var resolvePathParams = function (path, params, allowMissing) {
74
72
  paramKey = part.substring(1, part.length - 1);
75
73
  }
76
74
  if (paramKey) {
77
- var paramValue = params[paramKey];
75
+ const paramValue = params[paramKey];
78
76
  if (!paramValue) {
79
77
  if (allowMissing) {
80
78
  continue;
81
79
  }
82
- throw new Error("[api-def] Missing param '".concat(paramKey, "'"));
80
+ throw new Error(`[api-def] Missing param '${paramKey}'`);
83
81
  }
84
82
  computedPathParts[i] = paramValue;
85
83
  unusedKeys.delete(paramKey);
86
84
  }
87
85
  }
88
86
  if (unusedKeys.size > 0 && !allowMissing) {
89
- throw new Error("[api-def] Missing param '".concat(Array.from(unusedKeys)[0], "'"));
87
+ throw new Error(`[api-def] Missing param '${Array.from(unusedKeys)[0]}'`);
90
88
  }
91
89
  return computedPathParts.join("/");
92
90
  }
93
91
  return computedPath;
94
92
  };
95
93
  exports.resolvePathParams = resolvePathParams;
96
- var resolveUrl = function (options) {
97
- var baseUrl = options.baseUrl, path = options.path;
94
+ const resolveUrl = (options) => {
95
+ const { baseUrl, path } = options;
98
96
  if (path instanceof URL) {
99
97
  return new URL(path.href);
100
98
  }
101
99
  if ((0, exports.isAbsoluteUrl)(path)) {
102
100
  return new URL(path);
103
101
  }
104
- var result = !baseUrl.endsWith("/") ? "".concat(baseUrl, "/") : baseUrl;
102
+ let result = !baseUrl.endsWith("/") ? `${baseUrl}/` : baseUrl;
105
103
  result += path.startsWith("/") ? path.substring(1) : path;
106
- var origin = undefined;
104
+ let origin;
107
105
  if (typeof window !== "undefined") {
108
106
  origin = window.origin;
109
107
  }
110
108
  if (!origin) {
111
109
  if (!(0, exports.isAbsoluteUrl)(result)) {
112
- result = "https://".concat(result);
110
+ result = `https://${result}`;
113
111
  }
114
112
  }
115
113
  return new URL(result, origin);
package/cjs/Endpoint.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Api } from "./Api";
2
2
  import type { RequestMethod, ResponseType } from "./ApiConstants";
3
3
  import type { ApiResponse, BaseRequestConfig, Body, ComputedRequestConfig, Params, Query, RawHeaders, RequestConfig, RequestHost, RequestMiddleware, State } from "./ApiTypes";
4
+ import type RequestBackend from "./backend/RequestBackend";
4
5
  import type * as Mocking from "./MockingTypes";
5
6
  import type { Validation } from "./Validation";
6
- import type RequestBackend from "./backend/RequestBackend";
7
7
  export interface EndpointResolveUrlOptions<TParams extends Params | undefined, TQuery extends Query | undefined> {
8
8
  baseUrl?: string;
9
9
  params?: (TParams extends string | symbol | number ? Record<TParams, string> : never) | undefined;