@ffflorian/api-client 2.1.8 → 2.2.0

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/dist/APIClient.js CHANGED
@@ -29,7 +29,7 @@ export class APIClient {
29
29
  }
30
30
  async request(endpoint, options) {
31
31
  var _a;
32
- const url = new URL(endpoint, this.baseUrl);
32
+ let url = new URL(endpoint, this.baseUrl);
33
33
  if (options.params) {
34
34
  for (const [key, param] of Object.entries(options.params)) {
35
35
  if (param !== null && param !== undefined) {
@@ -39,6 +39,7 @@ export class APIClient {
39
39
  }
40
40
  let requestOptions = {
41
41
  method: options.method.toUpperCase(),
42
+ url,
42
43
  ...this.config,
43
44
  };
44
45
  if (options.headers) {
@@ -67,9 +68,10 @@ export class APIClient {
67
68
  }
68
69
  if (this.interceptors.request.length > 0) {
69
70
  for (const interceptor of this.interceptors.request) {
70
- requestOptions = await interceptor(url, requestOptions);
71
+ requestOptions = { ...requestOptions, ...(await interceptor({ ...requestOptions, url })) };
71
72
  }
72
73
  }
74
+ url = requestOptions.url;
73
75
  const response = await fetch(url, requestOptions);
74
76
  if (!response.ok) {
75
77
  throw new Error(`Request failed with status code ${response.status}`);
package/dist/types.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface Interceptors {
21
21
  request: RequestInterceptor[];
22
22
  response: ResponseInterceptor[];
23
23
  }
24
- export type RequestInitWithMethod = Required<Pick<RequestInit, 'method'>> & Omit<RequestInit, 'method'>;
25
- export type RequestInterceptor = (url: URL, options: RequestInitWithMethod) => RequestInitWithMethod | Promise<RequestInitWithMethod>;
24
+ export type RequestInitWithMethodAndURL = Required<Pick<RequestInit, 'method'>> & Omit<RequestInit, 'method'> & {
25
+ url: URL;
26
+ };
27
+ export type RequestInterceptor = (options: RequestInitWithMethodAndURL) => RequestInitWithMethodAndURL | Promise<RequestInitWithMethodAndURL>;
26
28
  export type ResponseInterceptor = (response: Response) => void | Promise<void>;
package/package.json CHANGED
@@ -28,5 +28,5 @@
28
28
  "test": "exit 0"
29
29
  },
30
30
  "type": "module",
31
- "version": "2.1.8"
31
+ "version": "2.2.0"
32
32
  }