@odata2ts/http-client-axios 0.10.0 → 0.10.2
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 +8 -0
- package/lib/AxiosClient.d.ts +3 -3
- package/lib/AxiosClient.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.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
|
+
|
|
8
|
+
**Note:** Version bump only for package @odata2ts/http-client-axios
|
|
9
|
+
|
|
10
|
+
## [0.10.1](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-axios@0.10.0...@odata2ts/http-client-axios@0.10.1) (2023-09-13)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @odata2ts/http-client-axios
|
|
13
|
+
|
|
6
14
|
# [0.10.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-axios@0.9.0...@odata2ts/http-client-axios@0.10.0) (2023-09-13)
|
|
7
15
|
|
|
8
16
|
### Code Refactoring
|
package/lib/AxiosClient.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { HttpResponseModel,
|
|
2
|
-
import { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from "@odata2ts/http-client-base";
|
|
1
|
+
import { HttpResponseModel, ODataHttpClient } from "@odata2ts/http-client-api";
|
|
2
|
+
import { BaseHttpClient, BaseHttpClientOptions, HttpMethods, InternalHttpClientConfig } from "@odata2ts/http-client-base";
|
|
3
3
|
import { AxiosInstance, AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios";
|
|
4
4
|
import { AxiosRequestConfig } from "./AxiosRequestConfig";
|
|
5
5
|
export interface ClientOptions extends BaseHttpClientOptions {
|
|
6
6
|
}
|
|
7
7
|
export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
|
|
8
|
-
export declare class AxiosClient extends BaseHttpClient<AxiosRequestConfig> {
|
|
8
|
+
export declare class AxiosClient extends BaseHttpClient<AxiosRequestConfig> implements ODataHttpClient<AxiosRequestConfig> {
|
|
9
9
|
protected readonly client: AxiosInstance;
|
|
10
10
|
constructor(config?: AxiosRequestConfig, clientOptions?: ClientOptions);
|
|
11
11
|
protected executeRequest<ResponseModel>(method: HttpMethods, url: string, data: any, requestConfig?: AxiosRequestConfig | undefined, internalConfig?: InternalHttpClientConfig): Promise<HttpResponseModel<ResponseModel>>;
|
package/lib/AxiosClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AxiosClient.js","sourceRoot":"","sources":["../src/AxiosClient.ts"],"names":[],"mappings":";;;;AACA,
|
|
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,CAAE,KAAe,aAAf,KAAK,uBAAL,KAAK,CAAY,OAAO,CAAC;IAC1E,OAAO,MAAM,GAAG,CAAC,GAAG,IAAI,6BAAqB,CAAC,CAAC;AACjD,CAAC;AAED,MAAa,WAAY,SAAQ,iCAAkC;IAGjE,YAAY,MAA2B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O,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 Record<string, string>;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/http-client-axios",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"axios": "^0.27.0 || ^1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@odata2ts/http-client-base": "^0.4.
|
|
37
|
+
"@odata2ts/http-client-base": "^0.4.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/jest": "^27.4.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"typescript": "5.0.4"
|
|
48
48
|
},
|
|
49
49
|
"types": "./lib/index.d.ts",
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0886c9e292a84560001d4c4e4503babf3809e1d7"
|
|
51
51
|
}
|