@mx-space/api-client 1.8.0 → 1.8.1-alpha.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/index.cjs CHANGED
@@ -940,7 +940,8 @@ var HTTPClient = class {
940
940
  this.options = options;
941
941
  this._endpoint = _endpoint.replace(/\/*$/, "").replace("localhost", "127.0.0.1");
942
942
  this._proxy = this.buildRoute(this)();
943
- options.transformResponse = options.transformResponse || ((data) => camelcaseKeys(data));
943
+ options.transformResponse || (options.transformResponse = (data) => camelcaseKeys(data));
944
+ options.getDataFromResponse || (options.getDataFromResponse = (res) => res.data);
944
945
  this.initGetClient();
945
946
  attachRequestMethod(this);
946
947
  }
@@ -1047,7 +1048,7 @@ var HTTPClient = class {
1047
1048
  }
1048
1049
  throw that.options.customThrowResponseError ? that.options.customThrowResponseError(e) : new RequestError(message, code, url, e);
1049
1050
  }
1050
- const data = res.data;
1051
+ const data = that.options.getDataFromResponse(res);
1051
1052
  if (!data) {
1052
1053
  return null;
1053
1054
  }
package/dist/index.d.cts CHANGED
@@ -16,6 +16,11 @@ interface IClientOptions {
16
16
  };
17
17
  customThrowResponseError: <T extends Error = Error>(err: any) => T;
18
18
  transformResponse: <T = any>(data: any) => T;
19
+ /**
20
+ *
21
+ * @default (res) => res.data
22
+ */
23
+ getDataFromResponse: <T = any>(response: unknown) => T;
19
24
  }
20
25
  type ClientOptions = Partial<IClientOptions>;
21
26
 
package/dist/index.d.ts CHANGED
@@ -16,6 +16,11 @@ interface IClientOptions {
16
16
  };
17
17
  customThrowResponseError: <T extends Error = Error>(err: any) => T;
18
18
  transformResponse: <T = any>(data: any) => T;
19
+ /**
20
+ *
21
+ * @default (res) => res.data
22
+ */
23
+ getDataFromResponse: <T = any>(response: unknown) => T;
19
24
  }
20
25
  type ClientOptions = Partial<IClientOptions>;
21
26
 
@@ -876,7 +876,8 @@
876
876
  this.options = options;
877
877
  this._endpoint = _endpoint.replace(/\/*$/, "").replace("localhost", "127.0.0.1");
878
878
  this._proxy = this.buildRoute(this)();
879
- options.transformResponse = options.transformResponse || ((data) => camelcaseKeys(data));
879
+ options.transformResponse || (options.transformResponse = (data) => camelcaseKeys(data));
880
+ options.getDataFromResponse || (options.getDataFromResponse = (res) => res.data);
880
881
  this.initGetClient();
881
882
  attachRequestMethod(this);
882
883
  }
@@ -983,7 +984,7 @@
983
984
  }
984
985
  throw that.options.customThrowResponseError ? that.options.customThrowResponseError(e) : new RequestError(message, code, url, e);
985
986
  }
986
- const data = res.data;
987
+ const data = that.options.getDataFromResponse(res);
987
988
  if (!data) {
988
989
  return null;
989
990
  }
package/dist/index.js CHANGED
@@ -874,7 +874,8 @@ var HTTPClient = class {
874
874
  this.options = options;
875
875
  this._endpoint = _endpoint.replace(/\/*$/, "").replace("localhost", "127.0.0.1");
876
876
  this._proxy = this.buildRoute(this)();
877
- options.transformResponse = options.transformResponse || ((data) => camelcaseKeys(data));
877
+ options.transformResponse || (options.transformResponse = (data) => camelcaseKeys(data));
878
+ options.getDataFromResponse || (options.getDataFromResponse = (res) => res.data);
878
879
  this.initGetClient();
879
880
  attachRequestMethod(this);
880
881
  }
@@ -981,7 +982,7 @@ var HTTPClient = class {
981
982
  }
982
983
  throw that.options.customThrowResponseError ? that.options.customThrowResponseError(e) : new RequestError(message, code, url, e);
983
984
  }
984
- const data = res.data;
985
+ const data = that.options.getDataFromResponse(res);
985
986
  if (!data) {
986
987
  return null;
987
988
  }
@@ -11,5 +11,10 @@ interface IClientOptions {
11
11
  }
12
12
  customThrowResponseError: <T extends Error = Error>(err: any) => T
13
13
  transformResponse: <T = any>(data: any) => T
14
+ /**
15
+ *
16
+ * @default (res) => res.data
17
+ */
18
+ getDataFromResponse: <T = any>(response: unknown) => T
14
19
  }
15
20
  export type ClientOptions = Partial<IClientOptions>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mx-space/api-client",
3
- "version": "1.8.0",
3
+ "version": "1.8.1-alpha.0",
4
4
  "type": "module",
5
5
  "description": "A api client for mx-space server@next",
6
6
  "author": "Innei",