api-def 0.12.0-alpha.50 → 0.12.0-alpha.52

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.
@@ -39,36 +39,36 @@ var processRequestConfigs = function (configs) {
39
39
  };
40
40
  computedConfig.queryParser = undefined;
41
41
  var query = computedConfig.query;
42
- var queryString;
43
- var queryObject;
42
+ var queryString = "";
43
+ var queryObject = {};
44
44
  if (query) {
45
- Object.defineProperty(computedConfig, "queryString", {
46
- get: function () {
47
- if (queryString) {
48
- return queryString;
49
- }
50
- if (typeof query === "string") {
51
- return (queryString = query);
52
- }
53
- return (queryString = computedConfig.queryHandling.stringify(query));
54
- },
55
- });
56
- Object.defineProperty(computedConfig, "queryObject", {
57
- get: function () {
58
- if (queryObject) {
59
- return queryObject;
60
- }
61
- if (typeof query === "string") {
62
- return (queryObject = computedConfig.queryHandling.parse(query));
63
- }
64
- return (queryObject = query);
65
- },
66
- set: function (value) {
67
- queryObject = value;
68
- queryString = computedConfig.queryHandling.stringify(value);
69
- },
70
- });
45
+ if (typeof query === "string") {
46
+ queryString = query;
47
+ queryObject = computedConfig.queryHandling.parse(query);
48
+ }
49
+ else {
50
+ queryObject = query;
51
+ queryString = computedConfig.queryHandling.stringify(query);
52
+ }
71
53
  }
54
+ Object.defineProperty(computedConfig, "queryString", {
55
+ get: function () {
56
+ return queryString;
57
+ },
58
+ set: function (value) {
59
+ queryString = value;
60
+ queryObject = computedConfig.queryHandling.parse(value);
61
+ },
62
+ });
63
+ Object.defineProperty(computedConfig, "queryObject", {
64
+ get: function () {
65
+ return queryObject;
66
+ },
67
+ set: function (value) {
68
+ queryObject = value;
69
+ queryString = computedConfig.queryHandling.stringify(value);
70
+ },
71
+ });
72
72
  if (!computedConfig.state) {
73
73
  computedConfig.state = {};
74
74
  }
@@ -29,4 +29,5 @@ export interface RequestErrorConfig {
29
29
  response?: ApiResponse | null;
30
30
  }
31
31
  export declare const convertToRequestError: (config: RequestErrorConfig) => RequestError;
32
+ export declare const getErrorResponse: (error: Error) => ApiResponse<any> | undefined;
32
33
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToRequestError = exports.isRequestError = exports.RequestErrorCode = void 0;
3
+ exports.getErrorResponse = exports.convertToRequestError = exports.isRequestError = exports.RequestErrorCode = void 0;
4
4
  exports.RequestErrorCode = {
5
5
  MISC_UNKNOWN_ERROR: "misc/unknown-error",
6
6
  REQUEST_NETWORK_ERROR: "request/network-error",
@@ -63,3 +63,11 @@ var convertToRequestError = function (config) {
63
63
  return resultError;
64
64
  };
65
65
  exports.convertToRequestError = convertToRequestError;
66
+ var getErrorResponse = function (error) {
67
+ var _a;
68
+ if ((0, exports.isRequestError)(error)) {
69
+ return (_a = error.response) !== null && _a !== void 0 ? _a : undefined;
70
+ }
71
+ return undefined;
72
+ };
73
+ exports.getErrorResponse = getErrorResponse;
package/cjs/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * from "./UtilTypes";
4
4
  export * from "./ApiConstants";
5
5
  export { default as retry } from "./util/retry";
6
6
  export type { RetryOptions } from "./util/retry/interfaces";
7
- export { isRequestError, type RequestError } from "./RequestError";
7
+ export { isRequestError, getErrorResponse, type RequestError } from "./RequestError";
8
8
  export { default as Endpoint, type EndpointConfig } from "./Endpoint";
9
9
  export { default as EndpointBuilder, type EndpointBuildOptions } from "./EndpointBuilder";
10
10
  export { clearClientCache, setClientCacheBackend } from "./cache/ClientCaching";
package/cjs/index.js CHANGED
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.LoggingMiddleware = exports.ClientCacheMiddleware = exports.FetchRequestBackend = exports.AxiosRequestBackend = exports.LocalForageClientCacheBackend = exports.LocalStorageClientCacheBackend = exports.setClientCacheBackend = exports.clearClientCache = exports.EndpointBuilder = exports.Endpoint = exports.isRequestError = exports.retry = void 0;
18
+ exports.LoggingMiddleware = exports.ClientCacheMiddleware = exports.FetchRequestBackend = exports.AxiosRequestBackend = exports.LocalForageClientCacheBackend = exports.LocalStorageClientCacheBackend = exports.setClientCacheBackend = exports.clearClientCache = exports.EndpointBuilder = exports.Endpoint = exports.getErrorResponse = exports.isRequestError = exports.retry = void 0;
19
19
  __exportStar(require("./Api"), exports);
20
20
  __exportStar(require("./ApiTypes"), exports);
21
21
  __exportStar(require("./UtilTypes"), exports);
@@ -24,6 +24,7 @@ var retry_1 = require("./util/retry");
24
24
  Object.defineProperty(exports, "retry", { enumerable: true, get: function () { return retry_1.default; } });
25
25
  var RequestError_1 = require("./RequestError");
26
26
  Object.defineProperty(exports, "isRequestError", { enumerable: true, get: function () { return RequestError_1.isRequestError; } });
27
+ Object.defineProperty(exports, "getErrorResponse", { enumerable: true, get: function () { return RequestError_1.getErrorResponse; } });
27
28
  var Endpoint_1 = require("./Endpoint");
28
29
  Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return Endpoint_1.default; } });
29
30
  var EndpointBuilder_1 = require("./EndpointBuilder");
@@ -22,36 +22,36 @@ export const processRequestConfigs = (configs) => {
22
22
  };
23
23
  computedConfig.queryParser = undefined;
24
24
  const query = computedConfig.query;
25
- let queryString;
26
- let queryObject;
25
+ let queryString = "";
26
+ let queryObject = {};
27
27
  if (query) {
28
- Object.defineProperty(computedConfig, "queryString", {
29
- get() {
30
- if (queryString) {
31
- return queryString;
32
- }
33
- if (typeof query === "string") {
34
- return (queryString = query);
35
- }
36
- return (queryString = computedConfig.queryHandling.stringify(query));
37
- },
38
- });
39
- Object.defineProperty(computedConfig, "queryObject", {
40
- get() {
41
- if (queryObject) {
42
- return queryObject;
43
- }
44
- if (typeof query === "string") {
45
- return (queryObject = computedConfig.queryHandling.parse(query));
46
- }
47
- return (queryObject = query);
48
- },
49
- set(value) {
50
- queryObject = value;
51
- queryString = computedConfig.queryHandling.stringify(value);
52
- },
53
- });
28
+ if (typeof query === "string") {
29
+ queryString = query;
30
+ queryObject = computedConfig.queryHandling.parse(query);
31
+ }
32
+ else {
33
+ queryObject = query;
34
+ queryString = computedConfig.queryHandling.stringify(query);
35
+ }
54
36
  }
37
+ Object.defineProperty(computedConfig, "queryString", {
38
+ get() {
39
+ return queryString;
40
+ },
41
+ set(value) {
42
+ queryString = value;
43
+ queryObject = computedConfig.queryHandling.parse(value);
44
+ },
45
+ });
46
+ Object.defineProperty(computedConfig, "queryObject", {
47
+ get() {
48
+ return queryObject;
49
+ },
50
+ set(value) {
51
+ queryObject = value;
52
+ queryString = computedConfig.queryHandling.stringify(value);
53
+ },
54
+ });
55
55
  if (!computedConfig.state) {
56
56
  computedConfig.state = {};
57
57
  }
@@ -29,4 +29,5 @@ export interface RequestErrorConfig {
29
29
  response?: ApiResponse | null;
30
30
  }
31
31
  export declare const convertToRequestError: (config: RequestErrorConfig) => RequestError;
32
+ export declare const getErrorResponse: (error: Error) => ApiResponse<any> | undefined;
32
33
  export {};
@@ -56,3 +56,10 @@ export const convertToRequestError = (config) => {
56
56
  resultError.toJSON = undefined;
57
57
  return resultError;
58
58
  };
59
+ export const getErrorResponse = (error) => {
60
+ var _a;
61
+ if (isRequestError(error)) {
62
+ return (_a = error.response) !== null && _a !== void 0 ? _a : undefined;
63
+ }
64
+ return undefined;
65
+ };
package/esm/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export * from "./UtilTypes";
4
4
  export * from "./ApiConstants";
5
5
  export { default as retry } from "./util/retry";
6
6
  export type { RetryOptions } from "./util/retry/interfaces";
7
- export { isRequestError, type RequestError } from "./RequestError";
7
+ export { isRequestError, getErrorResponse, type RequestError } from "./RequestError";
8
8
  export { default as Endpoint, type EndpointConfig } from "./Endpoint";
9
9
  export { default as EndpointBuilder, type EndpointBuildOptions } from "./EndpointBuilder";
10
10
  export { clearClientCache, setClientCacheBackend } from "./cache/ClientCaching";
package/esm/index.js CHANGED
@@ -4,7 +4,7 @@ export * from "./ApiTypes";
4
4
  export * from "./UtilTypes";
5
5
  export * from "./ApiConstants";
6
6
  export { default as retry } from "./util/retry";
7
- export { isRequestError } from "./RequestError";
7
+ export { isRequestError, getErrorResponse } from "./RequestError";
8
8
  export { default as Endpoint } from "./Endpoint";
9
9
  export { default as EndpointBuilder } from "./EndpointBuilder";
10
10
  export { clearClientCache, setClientCacheBackend } from "./cache/ClientCaching";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.12.0-alpha.50",
3
+ "version": "0.12.0-alpha.52",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",