@odata2ts/http-client-axios 0.12.0 → 0.12.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 +14 -0
- package/lib/AxiosClient.d.ts +4 -6
- package/lib/AxiosClient.js +8 -6
- package/lib/AxiosClient.js.map +1 -1
- package/lib/AxiosRequestConfig.d.ts +3 -7
- package/lib/AxiosRequestConfig.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
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.12.1](https://github.com/odata2ts/http-client/compare/@odata2ts/axios-v0.12.0...@odata2ts/axios-v0.12.1) (2026-06-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* create blob request ([#28](https://github.com/odata2ts/http-client/issues/28)) ([4cc238d](https://github.com/odata2ts/http-client/commit/4cc238d3fbe07c09d56732b4b12d0b1b875a3ef5))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Dependencies
|
|
15
|
+
|
|
16
|
+
* The following workspace dependencies were updated
|
|
17
|
+
* dependencies
|
|
18
|
+
* @odata2ts/http-client-base bumped from ^0.5.4 to ^0.5.5
|
|
19
|
+
|
|
6
20
|
## [0.12.0](https://github.com/odata2ts/http-client/compare/@odata2ts/axios-v0.11.3...@odata2ts/axios-v0.12.0) (2025-03-26)
|
|
7
21
|
|
|
8
22
|
|
package/lib/AxiosClient.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { HttpResponseModel, ODataHttpClient } from "@odata2ts/http-client-api";
|
|
2
|
-
import { BaseHttpClient,
|
|
1
|
+
import { HttpResponseModel, ODataHttpClient, ODataHttpClientOptions, ODataHttpMethods } from "@odata2ts/http-client-api";
|
|
2
|
+
import { BaseHttpClient, BaseRequestConfig } from "@odata2ts/http-client-base";
|
|
3
3
|
import { AxiosInstance, AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios";
|
|
4
4
|
import { AxiosRequestConfig } from "./AxiosRequestConfig";
|
|
5
|
-
export interface ClientOptions extends BaseHttpClientOptions {
|
|
6
|
-
}
|
|
7
5
|
export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
|
|
8
6
|
export declare class AxiosClient extends BaseHttpClient<AxiosRequestConfig> implements ODataHttpClient<AxiosRequestConfig> {
|
|
9
7
|
protected readonly client: AxiosInstance;
|
|
10
|
-
constructor(config?: AxiosRequestConfig, clientOptions?:
|
|
11
|
-
protected executeRequest<ResponseModel>(method:
|
|
8
|
+
constructor(config?: AxiosRequestConfig, clientOptions?: ODataHttpClientOptions);
|
|
9
|
+
protected executeRequest<ResponseModel>(method: ODataHttpMethods, url: string, data: any, requestConfig?: AxiosRequestConfig | undefined, internalConfig?: BaseRequestConfig): Promise<HttpResponseModel<ResponseModel>>;
|
|
12
10
|
protected mapHeaders(headers: AxiosResponseHeaders | RawAxiosResponseHeaders): Record<string, string>;
|
|
13
11
|
}
|
package/lib/AxiosClient.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AxiosClient = exports.DEFAULT_ERROR_MESSAGE = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const ODataHttpDataTypes_1 = require("@odata2ts/http-client-api/lib/ODataHttpDataTypes");
|
|
5
6
|
const http_client_base_1 = require("@odata2ts/http-client-base");
|
|
6
7
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
7
8
|
const AxiosClientError_1 = require("./AxiosClientError");
|
|
@@ -22,17 +23,18 @@ class AxiosClient extends http_client_base_1.BaseHttpClient {
|
|
|
22
23
|
}
|
|
23
24
|
executeRequest(method, url, data, requestConfig = {}, internalConfig = {}) {
|
|
24
25
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
// add URL, HTTP method and additional headers to the request config
|
|
26
26
|
const { headers } = internalConfig;
|
|
27
|
-
|
|
27
|
+
// set core inputs for request
|
|
28
|
+
const resultConfig = Object.assign(Object.assign({}, (0, AxiosRequestConfig_1.mergeConfig)({ headers }, requestConfig)), { url,
|
|
29
|
+
method });
|
|
28
30
|
if (typeof data !== "undefined") {
|
|
29
|
-
|
|
31
|
+
resultConfig.data = data;
|
|
30
32
|
}
|
|
31
|
-
if (internalConfig.dataType && internalConfig.dataType !==
|
|
32
|
-
|
|
33
|
+
if (internalConfig.dataType && internalConfig.dataType !== ODataHttpDataTypes_1.ODataHttpDataTypes.JSON) {
|
|
34
|
+
resultConfig.responseType = internalConfig.dataType;
|
|
33
35
|
}
|
|
34
36
|
try {
|
|
35
|
-
return yield this.client.request(
|
|
37
|
+
return yield this.client.request(resultConfig);
|
|
36
38
|
}
|
|
37
39
|
catch (error) {
|
|
38
40
|
if (error.isAxiosError) {
|
package/lib/AxiosClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AxiosClient.js","sourceRoot":"","sources":["../src/AxiosClient.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"AxiosClient.js","sourceRoot":"","sources":["../src/AxiosClient.ts"],"names":[],"mappings":";;;;AAMA,yFAAsF;AACtF,iEAA+E;AAC/E,0DAMe;AACf,yDAAsD;AACtD,6DAAuE;AAE1D,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,C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wB,EAAE,MAAM,CAAC,CAAC;wBAChE,MAAM,IAAI,mCAAgB,CACxB,GAAG,EACH,UAAU,CAAC,QAAQ,CAAC,MAAM,EAC1B,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,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;AAnED,kCAmEC","sourcesContent":["import {\n HttpResponseModel,\n ODataHttpClient,\n ODataHttpClientOptions,\n ODataHttpMethods,\n} from \"@odata2ts/http-client-api\";\nimport { ODataHttpDataTypes } from \"@odata2ts/http-client-api/lib/ODataHttpDataTypes\";\nimport { BaseHttpClient, BaseRequestConfig } from \"@odata2ts/http-client-base\";\nimport axios, {\n AxiosError,\n AxiosInstance,\n AxiosResponseHeaders,\n AxiosRequestConfig as OriginalRequestConfig,\n RawAxiosResponseHeaders,\n} from \"axios\";\nimport { AxiosClientError } from \"./AxiosClientError\";\nimport { AxiosRequestConfig, mergeConfig } from \"./AxiosRequestConfig\";\n\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\nconst FAILURE_NO_RESPONSE = \"No response from server! Failure: \";\nconst FAILURE_NO_REQUEST = \"No request was sent! Failure: \";\nconst FAILURE_RESPONSE_MESSAGE = \"OData server responded with error: \";\nconst FAILURE_AXIOS = \"Fatal Axios failure: \";\n\nfunction buildErrorMessage(prefix: string, error: any) {\n const msg = typeof error === \"string\" ? error : (error as Error)?.message;\n return prefix + (msg || DEFAULT_ERROR_MESSAGE);\n}\n\ninterface InternalRequestConfig\n extends AxiosRequestConfig,\n Pick<OriginalRequestConfig, \"method\" | \"url\" | \"responseType\"> {}\n\nexport class AxiosClient extends BaseHttpClient<AxiosRequestConfig> implements ODataHttpClient<AxiosRequestConfig> {\n protected readonly client: AxiosInstance;\n\n constructor(config?: AxiosRequestConfig, clientOptions?: ODataHttpClientOptions) {\n super(clientOptions);\n this.client = axios.create(config);\n }\n\n protected async executeRequest<ResponseModel>(\n method: ODataHttpMethods,\n url: string,\n data: any,\n requestConfig: AxiosRequestConfig | undefined = {},\n internalConfig: BaseRequestConfig = {},\n ): Promise<HttpResponseModel<ResponseModel>> {\n const { headers } = internalConfig;\n\n // set core inputs for request\n const resultConfig: InternalRequestConfig = {\n ...mergeConfig({ headers }, requestConfig),\n url,\n method,\n };\n if (typeof data !== \"undefined\") {\n resultConfig.data = data;\n }\n if (internalConfig.dataType && internalConfig.dataType !== ODataHttpDataTypes.JSON) {\n resultConfig.responseType = internalConfig.dataType;\n }\n\n try {\n return await this.client.request(resultConfig);\n } catch (error: any) {\n if ((error as AxiosError).isAxiosError) {\n const axiosError = error as AxiosError;\n\n // regular failure handling\n if (axiosError.response) {\n const errMsg = this.retrieveErrorMessage(axiosError.response.data);\n const msg = buildErrorMessage(FAILURE_RESPONSE_MESSAGE, errMsg);\n throw new AxiosClientError(\n msg,\n axiosError.response.status,\n this.mapHeaders(axiosError.response.headers),\n new Error(errMsg || DEFAULT_ERROR_MESSAGE),\n axiosError,\n );\n }\n // fatal failure without response\n else {\n throw new AxiosClientError(\n buildErrorMessage(axiosError.request ? FAILURE_NO_RESPONSE : FAILURE_NO_REQUEST, axiosError),\n undefined,\n undefined,\n error,\n axiosError,\n );\n }\n }\n // not an Axios error\n throw new AxiosClientError(buildErrorMessage(FAILURE_AXIOS, error), undefined, undefined, error);\n }\n }\n\n protected mapHeaders(headers: AxiosResponseHeaders | RawAxiosResponseHeaders): Record<string, string> {\n return headers as Record<string, string>;\n }\n}\n"]}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import { ODataRequestConfig } from "@odata2ts/http-client-api";
|
|
1
2
|
import { AxiosRequestConfig as OriginalRequestConfig } from "axios";
|
|
2
|
-
export interface AxiosRequestConfig extends Omit<OriginalRequestConfig, "method" | "url" | "headers"> {
|
|
3
|
-
headers?: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
export interface InternalRequestConfig extends Omit<OriginalRequestConfig, "headers"> {
|
|
6
|
-
url?: string;
|
|
7
|
-
headers?: Record<string, string>;
|
|
3
|
+
export interface AxiosRequestConfig extends ODataRequestConfig, Omit<OriginalRequestConfig, "method" | "url" | "headers" | "params"> {
|
|
8
4
|
}
|
|
9
5
|
export declare function mergeConfig(): undefined;
|
|
10
|
-
export declare function mergeConfig(...configs: Array<
|
|
6
|
+
export declare function mergeConfig(...configs: Array<AxiosRequestConfig | undefined>): AxiosRequestConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AxiosRequestConfig.js","sourceRoot":"","sources":["../src/AxiosRequestConfig.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"AxiosRequestConfig.js","sourceRoot":"","sources":["../src/AxiosRequestConfig.ts"],"names":[],"mappings":";;;;AASA,SAAgB,WAAW,CAAC,GAAG,OAA8C;IAC3E,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAA2B,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3C,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 { ODataRequestConfig } from \"@odata2ts/http-client-api\";\nimport { AxiosRequestConfig as OriginalRequestConfig } from \"axios\";\n\nexport interface AxiosRequestConfig\n extends ODataRequestConfig,\n Omit<OriginalRequestConfig, \"method\" | \"url\" | \"headers\" | \"params\"> {}\n\nexport function mergeConfig(): undefined;\nexport function mergeConfig(...configs: Array<AxiosRequestConfig | undefined>): AxiosRequestConfig;\nexport function mergeConfig(...configs: Array<AxiosRequestConfig | undefined>) {\n if (!configs.length) {\n return undefined;\n }\n\n return configs\n .filter((c): c is AxiosRequestConfig => !!c)\n .reduce<AxiosRequestConfig>(\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/http-client-axios",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Axios based odata HTTP client consumable by odata2ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http client",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "vitest run"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@odata2ts/http-client-base": "^0.5.
|
|
34
|
+
"@odata2ts/http-client-base": "^0.5.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^17.0.23",
|