@odata2ts/http-client-axios 0.10.2 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.11.1](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-axios@0.11.0...@odata2ts/http-client-axios@0.11.1) (2024-08-14)
7
+
8
+ ### Bug Fixes
9
+
10
+ * add ".js" suffix for all relative imports ([#20](https://github.com/odata2ts/http-client/issues/20)) ([961c910](https://github.com/odata2ts/http-client/commit/961c91002c8b1e9a7a6256cccd6b6d0ec9c142cd))
11
+
12
+ # [0.11.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-axios@0.10.2...@odata2ts/http-client-axios@0.11.0) (2024-08-13)
13
+
14
+ ### Code Refactoring
15
+
16
+ * switch to vitest & ESM ([#18](https://github.com/odata2ts/http-client/issues/18)) ([748558f](https://github.com/odata2ts/http-client/commit/748558f1e3f699085ade1058b1459c843f60994f))
17
+
18
+ ### Features
19
+
20
+ * blob and stream support ([#12](https://github.com/odata2ts/http-client/issues/12)) ([ae6f062](https://github.com/odata2ts/http-client/commit/ae6f062371a0ad11707fa3f9edff9571998edb5b))
21
+
22
+ ### BREAKING CHANGES
23
+
24
+ * switch to ESM tends to break stuff
25
+
6
26
  ## [0.10.2](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-axios@0.10.1...@odata2ts/http-client-axios@0.10.2) (2023-09-13)
7
27
 
8
28
  **Note:** Version bump only for package @odata2ts/http-client-axios
package/README.md CHANGED
@@ -1,49 +1,49 @@
1
- [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-axios?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-axios)
2
-
3
- # Axios HTTP Client
4
-
5
- The **Axios HTTP Client** uses - as its name suggests - [axios](https://github.com/axios/axios) for realizing
6
- the HTTP communication for [odata2ts](https://github.com/odata2ts/odata2ts).
7
-
8
- It supports:
9
-
10
- - request configuration
11
- - automatic CSRF token handling
12
-
13
- ## Installation
14
-
15
- Install package `@odata2ts/http-client-axios` as runtime dependency:
16
-
17
- ```bash
18
- npm install --save @odata2ts/http-client-axios
19
- ```
20
-
21
- s
22
-
23
- ## Documentation
24
-
25
- [Axios HTTP Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client/axios)
26
-
27
- Main documentation for the odata2ts eco system:
28
- [https://odata2ts.github.io](https://odata2ts.github.io/)
29
-
30
- ## Tests
31
-
32
- See folder [test](https://github.com/odata2ts/http-client/tree/main/packages/axios/test)
33
- for unit tests.
34
-
35
- See folder [int-test](https://github.com/odata2ts/http-client/tree/main/packages/axios/int-test) for
36
- integration tests.
37
-
38
- ## Support, Feedback, Contributing
39
-
40
- This project is open to feature requests, suggestions, bug reports, usage questions etc.
41
- via [GitHub issues](https://github.com/odata2ts/http-client/issues).
42
-
43
- Contributions and feedback are encouraged and always welcome.
44
-
45
- See the [contribution guidelines](https://github.com/odata2ts/http-client/blob/main/CONTRIBUTING.md) for further information.
46
-
47
- ## License
48
-
49
- MIT - see [License](./LICENSE).
1
+ [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-axios?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-axios)
2
+
3
+ # Axios HTTP Client
4
+
5
+ The **Axios HTTP Client** uses - as its name suggests - [axios](https://github.com/axios/axios) for realizing
6
+ the HTTP communication for [odata2ts](https://github.com/odata2ts/odata2ts).
7
+
8
+ It supports:
9
+
10
+ - request configuration
11
+ - automatic CSRF token handling
12
+
13
+ ## Installation
14
+
15
+ Install package `@odata2ts/http-client-axios` as runtime dependency:
16
+
17
+ ```bash
18
+ npm install --save @odata2ts/http-client-axios
19
+ ```
20
+
21
+ s
22
+
23
+ ## Documentation
24
+
25
+ [Axios HTTP Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client/axios)
26
+
27
+ Main documentation for the odata2ts eco system:
28
+ [https://odata2ts.github.io](https://odata2ts.github.io/)
29
+
30
+ ## Tests
31
+
32
+ See folder [test](https://github.com/odata2ts/http-client/tree/main/packages/axios/test)
33
+ for unit tests.
34
+
35
+ See folder [int-test](https://github.com/odata2ts/http-client/tree/main/packages/axios/int-test) for
36
+ integration tests.
37
+
38
+ ## Support, Feedback, Contributing
39
+
40
+ This project is open to feature requests, suggestions, bug reports, usage questions etc.
41
+ via [GitHub issues](https://github.com/odata2ts/http-client/issues).
42
+
43
+ Contributions and feedback are encouraged and always welcome.
44
+
45
+ See the [contribution guidelines](https://github.com/odata2ts/http-client/blob/main/CONTRIBUTING.md) for further information.
46
+
47
+ ## License
48
+
49
+ MIT - see [License](./LICENSE).
@@ -1,7 +1,7 @@
1
1
  import { HttpResponseModel, ODataHttpClient } from "@odata2ts/http-client-api";
2
2
  import { BaseHttpClient, BaseHttpClientOptions, HttpMethods, InternalHttpClientConfig } from "@odata2ts/http-client-base";
3
3
  import { AxiosInstance, AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios";
4
- import { AxiosRequestConfig } from "./AxiosRequestConfig";
4
+ import { AxiosRequestConfig } from "./AxiosRequestConfig.js";
5
5
  export interface ClientOptions extends BaseHttpClientOptions {
6
6
  }
7
7
  export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
@@ -1,33 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AxiosClient = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
- const tslib_1 = require("tslib");
5
- const http_client_base_1 = require("@odata2ts/http-client-base");
6
- const axios_1 = tslib_1.__importDefault(require("axios"));
7
- const AxiosClientError_1 = require("./AxiosClientError");
8
- const AxiosRequestConfig_1 = require("./AxiosRequestConfig");
9
- exports.DEFAULT_ERROR_MESSAGE = "No error message!";
1
+ import { __awaiter } from "tslib";
2
+ import { BaseHttpClient, } from "@odata2ts/http-client-base";
3
+ import axios from "axios";
4
+ import { AxiosClientError } from "./AxiosClientError.js";
5
+ import { mergeConfig } from "./AxiosRequestConfig.js";
6
+ export const DEFAULT_ERROR_MESSAGE = "No error message!";
10
7
  const FAILURE_NO_RESPONSE = "No response from server! Failure: ";
11
8
  const FAILURE_NO_REQUEST = "No request was sent! Failure: ";
12
9
  const FAILURE_RESPONSE_MESSAGE = "OData server responded with error: ";
13
10
  const FAILURE_AXIOS = "Fatal Axios failure: ";
14
11
  function buildErrorMessage(prefix, error) {
15
12
  const msg = typeof error === "string" ? error : error === null || error === void 0 ? void 0 : error.message;
16
- return prefix + (msg || exports.DEFAULT_ERROR_MESSAGE);
13
+ return prefix + (msg || DEFAULT_ERROR_MESSAGE);
17
14
  }
18
- class AxiosClient extends http_client_base_1.BaseHttpClient {
15
+ export class AxiosClient extends BaseHttpClient {
19
16
  constructor(config, clientOptions) {
20
17
  super(clientOptions);
21
- this.client = axios_1.default.create(config);
18
+ this.client = axios.create(config);
22
19
  }
23
20
  executeRequest(method, url, data, requestConfig = {}, internalConfig = {}) {
24
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ return __awaiter(this, void 0, void 0, function* () {
25
22
  // add URL, HTTP method and additional headers to the request config
26
23
  const { headers } = internalConfig;
27
- const config = (0, AxiosRequestConfig_1.mergeConfig)({ headers }, requestConfig, { url, method });
24
+ const config = mergeConfig({ headers }, requestConfig, { url, method });
28
25
  if (typeof data !== "undefined") {
29
26
  config.data = data;
30
27
  }
28
+ if (internalConfig.dataType && internalConfig.dataType !== "json") {
29
+ config.responseType = internalConfig.dataType;
30
+ }
31
31
  try {
32
32
  return yield this.client.request(config);
33
33
  }
@@ -38,15 +38,15 @@ class AxiosClient extends http_client_base_1.BaseHttpClient {
38
38
  if (axiosError.response) {
39
39
  const errMsg = this.retrieveErrorMessage(axiosError.response.data);
40
40
  const msg = buildErrorMessage(FAILURE_RESPONSE_MESSAGE, errMsg);
41
- throw new AxiosClientError_1.AxiosClientError(msg, axiosError.response.status, this.mapHeaders(axiosError.response.headers), new Error(errMsg || exports.DEFAULT_ERROR_MESSAGE), axiosError);
41
+ throw new AxiosClientError(msg, axiosError.response.status, this.mapHeaders(axiosError.response.headers), new Error(errMsg || DEFAULT_ERROR_MESSAGE), axiosError);
42
42
  }
43
43
  // fatal failure without response
44
44
  else {
45
- throw new AxiosClientError_1.AxiosClientError(buildErrorMessage(axiosError.request ? FAILURE_NO_RESPONSE : FAILURE_NO_REQUEST, axiosError), undefined, undefined, error, axiosError);
45
+ throw new AxiosClientError(buildErrorMessage(axiosError.request ? FAILURE_NO_RESPONSE : FAILURE_NO_REQUEST, axiosError), undefined, undefined, error, axiosError);
46
46
  }
47
47
  }
48
48
  // not an Axios error
49
- throw new AxiosClientError_1.AxiosClientError(buildErrorMessage(FAILURE_AXIOS, error), undefined, undefined, error);
49
+ throw new AxiosClientError(buildErrorMessage(FAILURE_AXIOS, error), undefined, undefined, error);
50
50
  }
51
51
  });
52
52
  }
@@ -54,5 +54,4 @@ class AxiosClient extends http_client_base_1.BaseHttpClient {
54
54
  return headers;
55
55
  }
56
56
  }
57
- exports.AxiosClient = AxiosClient;
58
57
  //# sourceMappingURL=AxiosClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosClient.js","sourceRoot":"","sources":["../src/AxiosClient.ts"],"names":[],"mappings":";;;;AACA,iEAKoC;AACpC,0DAMe;AAEf,yDAAsD;AACtD,6DAAuE;AAI1D,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AACzD,MAAM,mBAAmB,GAAG,oCAAoC,CAAC;AACjE,MAAM,kBAAkB,GAAG,gCAAgC,CAAC;AAC5D,MAAM,wBAAwB,GAAG,qCAAqC,CAAC;AACvE,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,SAAS,iBAAiB,CAAC,MAAc,EAAE,KAAU;IACnD,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC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AAC,OAAO,CAAC,EAC5C,IAAI,KAAK,CAAC,MAAM,IAAI,6BAAqB,CAAC,EAC1C,UAAU,CACX,CAAC;qBACH;oBACD,iCAAiC;yBAC5B;wBACH,MAAM,IAAI,mCAAgB,CACxB,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAC5F,SAAS,EACT,SAAS,EACT,KAAK,EACL,UAAU,CACX,CAAC;qBACH;iBACF;gBACD,qBAAqB;gBACrB,MAAM,IAAI,mCAAgB,CAAC,iBAAiB,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;aAClG;QACH,CAAC;KAAA;IAES,UAAU,CAAC,OAAuD;QAC1E,OAAO,OAAiC,CAAC;IAC3C,CAAC;CACF;AA3DD,kCA2DC","sourcesContent":["import { HttpResponseModel, ODataHttpClient } from \"@odata2ts/http-client-api\";\r\nimport {\r\n BaseHttpClient,\r\n BaseHttpClientOptions,\r\n HttpMethods,\r\n InternalHttpClientConfig,\r\n} from \"@odata2ts/http-client-base\";\r\nimport axios, {\r\n AxiosError,\r\n AxiosInstance,\r\n AxiosResponseHeaders,\r\n AxiosRequestConfig as OriginalRequestConfig,\r\n RawAxiosResponseHeaders,\r\n} from \"axios\";\r\n\r\nimport { AxiosClientError } from \"./AxiosClientError\";\r\nimport { AxiosRequestConfig, mergeConfig } from \"./AxiosRequestConfig\";\r\n\r\nexport interface ClientOptions extends BaseHttpClientOptions {}\r\n\r\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\r\nconst FAILURE_NO_RESPONSE = \"No response from server! Failure: \";\r\nconst FAILURE_NO_REQUEST = \"No request was sent! Failure: \";\r\nconst FAILURE_RESPONSE_MESSAGE = \"OData server responded with error: \";\r\nconst FAILURE_AXIOS = \"Fatal Axios failure: \";\r\n\r\nfunction buildErrorMessage(prefix: string, error: any) {\r\n const msg = typeof error === \"string\" ? error : (error as Error)?.message;\r\n return prefix + (msg || DEFAULT_ERROR_MESSAGE);\r\n}\r\n\r\nexport class AxiosClient extends BaseHttpClient<AxiosRequestConfig> implements ODataHttpClient<AxiosRequestConfig> {\r\n protected readonly client: AxiosInstance;\r\n\r\n constructor(config?: AxiosRequestConfig, clientOptions?: ClientOptions) {\r\n super(clientOptions);\r\n this.client = axios.create(config);\r\n }\r\n\r\n protected async executeRequest<ResponseModel>(\r\n method: HttpMethods,\r\n url: string,\r\n data: any,\r\n requestConfig: AxiosRequestConfig | undefined = {},\r\n internalConfig: InternalHttpClientConfig = {}\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n // add URL, HTTP method and additional headers to the request config\r\n const { headers } = internalConfig;\r\n const config: OriginalRequestConfig = mergeConfig({ headers }, requestConfig, { url, method });\r\n if (typeof data !== \"undefined\") {\r\n config.data = data;\r\n }\r\n\r\n try {\r\n return await this.client.request(config);\r\n } catch (error: any) {\r\n if ((error as AxiosError).isAxiosError) {\r\n const axiosError = error as AxiosError;\r\n\r\n // regular failure handling\r\n if (axiosError.response) {\r\n const errMsg = this.retrieveErrorMessage(axiosError.response.data);\r\n const msg = buildErrorMessage(FAILURE_RESPONSE_MESSAGE, errMsg);\r\n throw new AxiosClientError(\r\n msg,\r\n axiosError.response.status,\r\n this.mapHeaders(axiosError.response.headers),\r\n new Error(errMsg || DEFAULT_ERROR_MESSAGE),\r\n axiosError\r\n );\r\n }\r\n // fatal failure without response\r\n else {\r\n throw new AxiosClientError(\r\n buildErrorMessage(axiosError.request ? FAILURE_NO_RESPONSE : FAILURE_NO_REQUEST, axiosError),\r\n undefined,\r\n undefined,\r\n error,\r\n axiosError\r\n );\r\n }\r\n }\r\n // not an Axios error\r\n throw new AxiosClientError(buildErrorMessage(FAILURE_AXIOS, error), undefined, undefined, error);\r\n }\r\n }\r\n\r\n protected mapHeaders(headers: AxiosResponseHeaders | RawAxiosResponseHeaders): Record<string, string> {\r\n return headers as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;aAClG;QACH,CAAC;KAAA;IAES,UAAU,CAAC,OAAuD;QAC1E,OAAO,OAAiC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { HttpResponseModel, ODataHttpClient, ODataResponse } from \"@odata2ts/http-client-api\";\r\nimport {\r\n BaseHttpClient,\r\n BaseHttpClientOptions,\r\n HttpMethods,\r\n InternalHttpClientConfig,\r\n} from \"@odata2ts/http-client-base\";\r\nimport axios, {\r\n AxiosError,\r\n AxiosInstance,\r\n AxiosResponseHeaders,\r\n AxiosRequestConfig as OriginalRequestConfig,\r\n RawAxiosResponseHeaders,\r\n} from \"axios\";\r\nimport { AxiosClientError } from \"./AxiosClientError.js\";\r\nimport { AxiosRequestConfig, mergeConfig } from \"./AxiosRequestConfig.js\";\r\n\r\nexport interface ClientOptions extends BaseHttpClientOptions {}\r\n\r\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\r\nconst FAILURE_NO_RESPONSE = \"No response from server! Failure: \";\r\nconst FAILURE_NO_REQUEST = \"No request was sent! Failure: \";\r\nconst FAILURE_RESPONSE_MESSAGE = \"OData server responded with error: \";\r\nconst FAILURE_AXIOS = \"Fatal Axios failure: \";\r\n\r\nfunction buildErrorMessage(prefix: string, error: any) {\r\n const msg = typeof error === \"string\" ? error : (error as Error)?.message;\r\n return prefix + (msg || DEFAULT_ERROR_MESSAGE);\r\n}\r\n\r\nexport class AxiosClient extends BaseHttpClient<AxiosRequestConfig> implements ODataHttpClient<AxiosRequestConfig> {\r\n protected readonly client: AxiosInstance;\r\n\r\n constructor(config?: AxiosRequestConfig, clientOptions?: ClientOptions) {\r\n super(clientOptions);\r\n this.client = axios.create(config);\r\n }\r\n\r\n protected async executeRequest<ResponseModel>(\r\n method: HttpMethods,\r\n url: string,\r\n data: any,\r\n requestConfig: AxiosRequestConfig | undefined = {},\r\n internalConfig: InternalHttpClientConfig = {},\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n // add URL, HTTP method and additional headers to the request config\r\n const { headers } = internalConfig;\r\n const config: OriginalRequestConfig = mergeConfig({ headers }, requestConfig, { url, method });\r\n if (typeof data !== \"undefined\") {\r\n config.data = data;\r\n }\r\n\r\n if (internalConfig.dataType && internalConfig.dataType !== \"json\") {\r\n config.responseType = internalConfig.dataType;\r\n }\r\n\r\n try {\r\n return await this.client.request(config);\r\n } catch (error: any) {\r\n if ((error as AxiosError).isAxiosError) {\r\n const axiosError = error as AxiosError;\r\n\r\n // regular failure handling\r\n if (axiosError.response) {\r\n const errMsg = this.retrieveErrorMessage(axiosError.response.data);\r\n const msg = buildErrorMessage(FAILURE_RESPONSE_MESSAGE, errMsg);\r\n throw new AxiosClientError(\r\n msg,\r\n axiosError.response.status,\r\n this.mapHeaders(axiosError.response.headers),\r\n new Error(errMsg || DEFAULT_ERROR_MESSAGE),\r\n axiosError,\r\n );\r\n }\r\n // fatal failure without response\r\n else {\r\n throw new AxiosClientError(\r\n buildErrorMessage(axiosError.request ? FAILURE_NO_RESPONSE : FAILURE_NO_REQUEST, axiosError),\r\n undefined,\r\n undefined,\r\n error,\r\n axiosError,\r\n );\r\n }\r\n }\r\n // not an Axios error\r\n throw new AxiosClientError(buildErrorMessage(FAILURE_AXIOS, error), undefined, undefined, error);\r\n }\r\n }\r\n\r\n protected mapHeaders(headers: AxiosResponseHeaders | RawAxiosResponseHeaders): Record<string, string> {\r\n return headers as Record<string, string>;\r\n }\r\n}\r\n"]}
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AxiosClientError = void 0;
4
- class AxiosClientError extends Error {
1
+ export class AxiosClientError extends Error {
5
2
  constructor(msg, status, headers, cause, axiosError) {
6
3
  // @ts-ignore: fetch requires lib "dom" or "webworker", but then the "cause" property becomes unknown to TS
7
4
  super(msg, { cause });
@@ -12,5 +9,4 @@ class AxiosClientError extends Error {
12
9
  this.name = this.constructor.name;
13
10
  }
14
11
  }
15
- exports.AxiosClientError = AxiosClientError;
16
12
  //# sourceMappingURL=AxiosClientError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosClientError.js","sourceRoot":"","sources":["../src/AxiosClientError.ts"],"names":[],"mappings":";;;AAGA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YACE,GAAW,EACK,MAAe,EACf,OAAgC,EAChC,KAAa,EACb,UAAuB;QAEvC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAyB;QAChC,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAa;QAIvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,4CAYC","sourcesContent":["import { ODataClientError } from \"@odata2ts/http-client-api\";\r\nimport type { AxiosError } from \"axios\";\r\n\r\nexport class AxiosClientError extends Error implements ODataClientError {\r\n constructor(\r\n msg: string,\r\n public readonly status?: number,\r\n public readonly headers?: Record<string, string>,\r\n public readonly cause?: Error,\r\n public readonly axiosError?: AxiosError\r\n ) {\r\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\r\n super(msg, { cause });\r\n this.name = this.constructor.name;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"AxiosClientError.js","sourceRoot":"","sources":["../src/AxiosClientError.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YACE,GAAW,EACK,MAAe,EACf,OAAgC,EAChC,KAAa,EACb,UAAuB;QAEvC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAyB;QAChC,UAAK,GAAL,KAAK,CAAQ;QACb,eAAU,GAAV,UAAU,CAAa;QAIvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF","sourcesContent":["import { ODataClientError } from \"@odata2ts/http-client-api\";\nimport type { AxiosError } from \"axios\";\n\nexport class AxiosClientError extends Error implements ODataClientError {\n constructor(\n msg: string,\n public readonly status?: number,\n public readonly headers?: Record<string, string>,\n public readonly cause?: Error,\n public readonly axiosError?: AxiosError,\n ) {\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\n super(msg, { cause });\n this.name = this.constructor.name;\n }\n}\n"]}
@@ -1,20 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeConfig = void 0;
4
- const tslib_1 = require("tslib");
5
- function mergeConfig(...configs) {
1
+ import { __rest } from "tslib";
2
+ export function mergeConfig(...configs) {
6
3
  if (!configs.length) {
7
4
  return undefined;
8
5
  }
9
6
  return configs
10
7
  .filter((c) => !!c)
11
8
  .reduce((collector, current) => {
12
- const { headers } = current, passThrough = tslib_1.__rest(current, ["headers"]);
9
+ const { headers } = current, passThrough = __rest(current, ["headers"]);
13
10
  if (headers) {
14
11
  Object.entries(headers).forEach(([key, val]) => (collector.headers[key] = val));
15
12
  }
16
13
  return Object.assign(Object.assign({}, collector), passThrough);
17
14
  }, { headers: {} });
18
15
  }
19
- exports.mergeConfig = mergeConfig;
20
16
  //# sourceMappingURL=AxiosRequestConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosRequestConfig.js","sourceRoot":"","sources":["../src/AxiosRequestConfig.ts"],"names":[],"mappings":";;;;AAaA,SAAgB,WAAW,CAAC,GAAG,OAAiD;IAC9E,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAA8B,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAC9C,MAAM,CACL,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;QACrB,MAAM,EAAE,OAAO,KAAqB,OAAO,EAAvB,WAAW,kBAAK,OAAO,EAArC,WAA2B,CAAU,CAAC;QAE5C,IAAI,OAAO,EAAE;YACX,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,OAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;SAClF;QACD,uCAAY,SAAS,GAAK,WAAW,EAAG;IAC1C,CAAC,EACD,EAAE,OAAO,EAAE,EAAE,EAAE,CAChB,CAAC;AACN,CAAC;AAlBD,kCAkBC","sourcesContent":["import { CreateAxiosDefaults, AxiosRequestConfig as OriginalRequestConfig } from \"axios\";\r\n\r\nexport interface AxiosRequestConfig extends Omit<OriginalRequestConfig, \"method\" | \"url\" | \"headers\"> {\r\n headers?: Record<string, string>;\r\n}\r\n\r\nexport interface InternalRequestConfig extends Omit<OriginalRequestConfig, \"headers\"> {\r\n url?: string;\r\n headers?: Record<string, string>;\r\n}\r\n\r\nexport function mergeConfig(): undefined;\r\nexport function mergeConfig(...configs: Array<InternalRequestConfig | undefined>): InternalRequestConfig;\r\nexport function mergeConfig(...configs: Array<InternalRequestConfig | undefined>) {\r\n if (!configs.length) {\r\n return undefined;\r\n }\r\n\r\n return configs\r\n .filter((c): c is InternalRequestConfig => !!c)\r\n .reduce<InternalRequestConfig>(\r\n (collector, current) => {\r\n const { headers, ...passThrough } = current;\r\n\r\n if (headers) {\r\n Object.entries(headers).forEach(([key, val]) => (collector.headers![key] = val));\r\n }\r\n return { ...collector, ...passThrough };\r\n },\r\n { headers: {} }\r\n );\r\n}\r\n"]}
1
+ {"version":3,"file":"AxiosRequestConfig.js","sourceRoot":"","sources":["../src/AxiosRequestConfig.ts"],"names":[],"mappings":";AAaA,MAAM,UAAU,WAAW,CAAC,GAAG,OAAiD;IAC9E,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAA8B,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAC9C,MAAM,CACL,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;QACrB,MAAM,EAAE,OAAO,KAAqB,OAAO,EAAvB,WAAW,UAAK,OAAO,EAArC,WAA2B,CAAU,CAAC;QAE5C,IAAI,OAAO,EAAE;YACX,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,OAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;SAClF;QACD,uCAAY,SAAS,GAAK,WAAW,EAAG;IAC1C,CAAC,EACD,EAAE,OAAO,EAAE,EAAE,EAAE,CAChB,CAAC;AACN,CAAC","sourcesContent":["import { CreateAxiosDefaults, AxiosRequestConfig as OriginalRequestConfig } from \"axios\";\n\nexport interface AxiosRequestConfig extends Omit<OriginalRequestConfig, \"method\" | \"url\" | \"headers\"> {\n headers?: Record<string, string>;\n}\n\nexport interface InternalRequestConfig extends Omit<OriginalRequestConfig, \"headers\"> {\n url?: string;\n headers?: Record<string, string>;\n}\n\nexport function mergeConfig(): undefined;\nexport function mergeConfig(...configs: Array<InternalRequestConfig | undefined>): InternalRequestConfig;\nexport function mergeConfig(...configs: Array<InternalRequestConfig | undefined>) {\n if (!configs.length) {\n return undefined;\n }\n\n return configs\n .filter((c): c is InternalRequestConfig => !!c)\n .reduce<InternalRequestConfig>(\n (collector, current) => {\n const { headers, ...passThrough } = current;\n\n if (headers) {\n Object.entries(headers).forEach(([key, val]) => (collector.headers![key] = val));\n }\n return { ...collector, ...passThrough };\n },\n { headers: {} },\n );\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./AxiosClient";
2
- export { AxiosClientError } from "./AxiosClientError";
3
- export { AxiosRequestConfig } from "./AxiosRequestConfig";
1
+ export * from "./AxiosClient.js";
2
+ export { AxiosClientError } from "./AxiosClientError.js";
3
+ export { AxiosRequestConfig } from "./AxiosRequestConfig.js";
package/lib/index.js CHANGED
@@ -1,8 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AxiosClientError = void 0;
4
- const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./AxiosClient"), exports);
6
- var AxiosClientError_1 = require("./AxiosClientError");
7
- Object.defineProperty(exports, "AxiosClientError", { enumerable: true, get: function () { return AxiosClientError_1.AxiosClientError; } });
1
+ export * from "./AxiosClient.js";
2
+ export { AxiosClientError } from "./AxiosClientError.js";
8
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAA8B;AAC9B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA","sourcesContent":["export * from \"./AxiosClient\";\r\nexport { AxiosClientError } from \"./AxiosClientError\";\r\nexport { AxiosRequestConfig } from \"./AxiosRequestConfig\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export * from \"./AxiosClient.js\";\r\nexport { AxiosClientError } from \"./AxiosClientError.js\";\r\nexport { AxiosRequestConfig } from \"./AxiosRequestConfig.js\";\r\n"]}
package/package.json CHANGED
@@ -1,51 +1,49 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-axios",
3
- "version": "0.10.2",
4
- "publishConfig": {
5
- "access": "public"
6
- },
3
+ "version": "0.11.1",
7
4
  "description": "Axios based odata HTTP client consumable by odata2ts",
8
- "license": "MIT",
5
+ "keywords": [
6
+ "http client",
7
+ "axios",
8
+ "odata",
9
+ "odata2ts",
10
+ "ts",
11
+ "typescript"
12
+ ],
9
13
  "repository": "git@github.com:odata2ts/http-client.git",
14
+ "license": "MIT",
10
15
  "author": "texttechne",
16
+ "type": "module",
11
17
  "main": "./lib/index.js",
18
+ "types": "./lib/index.d.ts",
19
+ "files": [
20
+ "*.md",
21
+ "lib",
22
+ "LICENSE"
23
+ ],
12
24
  "scripts": {
13
25
  "build": "yarn clean && yarn compile",
14
26
  "check-circular-deps": "madge ./src --extensions ts --circular",
15
27
  "clean": "rimraf lib coverage",
16
28
  "compile": "tsc",
29
+ "int-test": "vitest run int-test/**",
17
30
  "prepublish": "yarn build",
18
- "test": "jest --passWithNoTests"
19
- },
20
- "files": [
21
- "*.md",
22
- "lib",
23
- "LICENSE"
24
- ],
25
- "keywords": [
26
- "http client",
27
- "axios",
28
- "odata",
29
- "odata2ts",
30
- "ts",
31
- "typescript"
32
- ],
33
- "peerDependencies": {
34
- "axios": "^0.27.0 || ^1.0.0"
31
+ "test": "vitest run test/**"
35
32
  },
36
33
  "dependencies": {
37
- "@odata2ts/http-client-base": "^0.4.2"
34
+ "@odata2ts/http-client-base": "^0.5.1"
38
35
  },
39
36
  "devDependencies": {
40
- "@types/jest": "^27.4.1",
41
37
  "@types/node": "^17.0.23",
42
38
  "axios": "^1.4.0",
43
- "jest": "29.5.0",
44
39
  "rimraf": "^5.0.1",
45
- "ts-jest": "^29.1.0",
46
- "ts-node": "10.9.1",
47
40
  "typescript": "5.0.4"
48
41
  },
49
- "types": "./lib/index.d.ts",
50
- "gitHead": "0886c9e292a84560001d4c4e4503babf3809e1d7"
42
+ "peerDependencies": {
43
+ "axios": "^0.27.0 || ^1.0.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "gitHead": "232521cbfae692d00900237845bd317b11e442d2"
51
49
  }