@odata2ts/http-client-fetch 0.8.0 → 0.9.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 +56 -0
- package/LICENSE +21 -21
- package/lib/FetchClient.d.ts +6 -8
- package/lib/FetchClient.js +6 -3
- package/lib/FetchClient.js.map +1 -1
- package/lib/FetchClientError.js.map +1 -1
- package/lib/FetchRequestConfig.d.ts +4 -11
- package/lib/FetchRequestConfig.js +11 -11
- package/lib/FetchRequestConfig.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +5 -7
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,62 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
9
9
|
|
|
10
10
|
* **fetch:** FetchClientError with full responseData object ([#22](https://github.com/odata2ts/http-client/issues/22)) ([e66fa95](https://github.com/odata2ts/http-client/commit/e66fa952909383d55555eed23d1a8e55fe0081f2))
|
|
11
11
|
|
|
12
|
+
## [0.9.1](https://github.com/odata2ts/http-client/compare/@odata2ts/fetch-v0.9.0...@odata2ts/fetch-v0.9.1) (2026-06-10)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* create blob request ([#28](https://github.com/odata2ts/http-client/issues/28)) ([4cc238d](https://github.com/odata2ts/http-client/commit/4cc238d3fbe07c09d56732b4b12d0b1b875a3ef5))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Dependencies
|
|
21
|
+
|
|
22
|
+
* The following workspace dependencies were updated
|
|
23
|
+
* dependencies
|
|
24
|
+
* @odata2ts/http-client-base bumped from ^0.5.4 to ^0.5.5
|
|
25
|
+
|
|
26
|
+
## [0.9.0](https://github.com/odata2ts/http-client/compare/@odata2ts/fetch-v0.8.0...@odata2ts/fetch-v0.9.0) (2025-03-26)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### ⚠ BREAKING CHANGES
|
|
30
|
+
|
|
31
|
+
* switch to ESM tends to break stuff
|
|
32
|
+
* additional headers are now part of the config parameter
|
|
33
|
+
* **fetch:** removed default accept & content-type headers; removed merge & retrieveBigNumbersAsString methods (base-lib); all of these settings can now be configured per operation via the `additionalHeaders` option.
|
|
34
|
+
|
|
35
|
+
### Features
|
|
36
|
+
|
|
37
|
+
* allow for additional headers for all operations ([#10](https://github.com/odata2ts/http-client/issues/10)) ([75eedd3](https://github.com/odata2ts/http-client/commit/75eedd3ebb8534188a5a644aee9e69e17f1f0c80))
|
|
38
|
+
* blob and stream support ([#12](https://github.com/odata2ts/http-client/issues/12)) ([ae6f062](https://github.com/odata2ts/http-client/commit/ae6f062371a0ad11707fa3f9edff9571998edb5b))
|
|
39
|
+
* conventionalize client errors ([#5](https://github.com/odata2ts/http-client/issues/5)) ([a8e8912](https://github.com/odata2ts/http-client/commit/a8e89125eeda47436d48507d6a71efc90953f878))
|
|
40
|
+
* **fetch:** allow for query params ([#13](https://github.com/odata2ts/http-client/issues/13)) ([1507ed1](https://github.com/odata2ts/http-client/commit/1507ed13c2020de051827db516ae1fc9c7f4b0ac))
|
|
41
|
+
* **fetch:** FetchClientError with full responseData object ([#22](https://github.com/odata2ts/http-client/issues/22)) ([e66fa95](https://github.com/odata2ts/http-client/commit/e66fa952909383d55555eed23d1a8e55fe0081f2))
|
|
42
|
+
* **fetch:** full fetch client implementation ([a8e5fb7](https://github.com/odata2ts/http-client/commit/a8e5fb73594cf2d446eefc69e77b8b5e4bcae1ca))
|
|
43
|
+
* switch to http-client-api ([52d1b86](https://github.com/odata2ts/http-client/commit/52d1b868ee82dbaf45486da6b22fdcf4c773dfb8))
|
|
44
|
+
* switch to http-client-api ([5a6da23](https://github.com/odata2ts/http-client/commit/5a6da23053b3ea5adb866bb7e30b469f1b8ed260))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Bug Fixes
|
|
48
|
+
|
|
49
|
+
* 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))
|
|
50
|
+
* always build all packages before release ([#26](https://github.com/odata2ts/http-client/issues/26)) ([a316f6c](https://github.com/odata2ts/http-client/commit/a316f6ce54c4360c8d6f87799ba6fd9c53bff52c))
|
|
51
|
+
* delete requests with Accept json header ([ea1b06d](https://github.com/odata2ts/http-client/commit/ea1b06d509b490e1e899e96a62a10eac3f65da8e))
|
|
52
|
+
* deploy with code ([#25](https://github.com/odata2ts/http-client/issues/25)) ([3e0e78c](https://github.com/odata2ts/http-client/commit/3e0e78cd2e0b0c3215bc0ed97dd62c75d8b6c5ea))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Code Refactoring
|
|
56
|
+
|
|
57
|
+
* expand additionalHeaders param to internalConfig ([#15](https://github.com/odata2ts/http-client/issues/15)) ([7fe1d73](https://github.com/odata2ts/http-client/commit/7fe1d73a7436f64b84a060bd1dbf9e121ef901ce))
|
|
58
|
+
* **fetch:** remove default headers ([39bea92](https://github.com/odata2ts/http-client/commit/39bea92a2b8335af8a1588a4156974fcbd5ae417))
|
|
59
|
+
* switch to vitest & ESM ([#18](https://github.com/odata2ts/http-client/issues/18)) ([748558f](https://github.com/odata2ts/http-client/commit/748558f1e3f699085ade1058b1459c843f60994f))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Dependencies
|
|
63
|
+
|
|
64
|
+
* The following workspace dependencies were updated
|
|
65
|
+
* dependencies
|
|
66
|
+
* @odata2ts/http-client-base bumped from ^0.5.3 to ^0.5.4
|
|
67
|
+
|
|
12
68
|
## [0.7.2](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-fetch@0.7.1...@odata2ts/http-client-fetch@0.7.2) (2024-08-22)
|
|
13
69
|
|
|
14
70
|
**Note:** Version bump only for package @odata2ts/http-client-fetch
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 odata2ts
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 odata2ts
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/FetchClient.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 { FetchRequestConfig } from "./FetchRequestConfig";
|
|
4
|
-
export interface ClientOptions extends BaseHttpClientOptions {
|
|
5
|
-
}
|
|
6
4
|
export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
|
|
7
5
|
export declare class FetchClient extends BaseHttpClient<FetchRequestConfig> implements ODataHttpClient<FetchRequestConfig> {
|
|
8
|
-
protected readonly config:
|
|
9
|
-
constructor(config?: FetchRequestConfig, clientOptions?:
|
|
10
|
-
protected executeRequest<ResponseModel>(method:
|
|
11
|
-
protected getResponseBody(response: Response, options:
|
|
6
|
+
protected readonly config: FetchRequestConfig;
|
|
7
|
+
constructor(config?: FetchRequestConfig, clientOptions?: ODataHttpClientOptions);
|
|
8
|
+
protected executeRequest<ResponseModel>(method: ODataHttpMethods, url: string, data: any, requestConfig?: FetchRequestConfig | undefined, internalConfig?: BaseRequestConfig): Promise<HttpResponseModel<ResponseModel>>;
|
|
9
|
+
protected getResponseBody(response: Response, options: BaseRequestConfig): Promise<any>;
|
|
12
10
|
protected mapHeaders(headers: Headers): Record<string, string>;
|
|
13
11
|
}
|
package/lib/FetchClient.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FetchClient = 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 FetchClientError_1 = require("./FetchClientError");
|
|
7
8
|
const FetchRequestConfig_1 = require("./FetchRequestConfig");
|
|
@@ -23,10 +24,12 @@ class FetchClient extends http_client_base_1.BaseHttpClient {
|
|
|
23
24
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
25
|
const { headers, noBodyEvaluation } = internalConfig;
|
|
25
26
|
const _a = (0, FetchRequestConfig_1.mergeFetchConfig)(this.config, { headers }, requestConfig), { params } = _a, config = tslib_1.__rest(_a, ["params"]);
|
|
26
|
-
|
|
27
|
+
// set core inputs for request
|
|
28
|
+
const resultConfig = Object.assign(Object.assign({}, config), { method });
|
|
27
29
|
if (typeof data !== "undefined") {
|
|
28
|
-
|
|
30
|
+
resultConfig.body = internalConfig.dataType === ODataHttpDataTypes_1.ODataHttpDataTypes.JSON ? JSON.stringify(data) : data;
|
|
29
31
|
}
|
|
32
|
+
// apply additional query params to the URL
|
|
30
33
|
let finalUrl = url;
|
|
31
34
|
if (params && Object.values(params).length) {
|
|
32
35
|
finalUrl +=
|
|
@@ -37,7 +40,7 @@ class FetchClient extends http_client_base_1.BaseHttpClient {
|
|
|
37
40
|
// the actual request
|
|
38
41
|
let response;
|
|
39
42
|
try {
|
|
40
|
-
response = yield fetch(finalUrl,
|
|
43
|
+
response = yield fetch(finalUrl, resultConfig);
|
|
41
44
|
}
|
|
42
45
|
catch (fetchError) {
|
|
43
46
|
throw new FetchClientError_1.FetchClientError(buildErrorMessage(FETCH_FAILURE_MESSAGE, fetchError), undefined, undefined, fetchError);
|
package/lib/FetchClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchClient.js","sourceRoot":"","sources":["../src/FetchClient.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"FetchClient.js","sourceRoot":"","sources":["../src/FetchClient.ts"],"names":[],"mappings":";;;;AAMA,yFAAsF;AACtF,iEAA+E;AAC/E,yDAAsD;AACtD,6DAA8F;AAEjF,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AACzD,MAAM,qBAAqB,GAAG,iCAAiC,CAAC;AAChE,MAAM,8BAA8B,GAAG,mDAAmD,CAAC;AAC3F,MAAM,8BAA8B,GAAG,8CAA8C,CAAC;AACtF,MAAM,wBAAwB,GAAG,qCAAqC,CAAC;AAEvE,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;AAID,MAAa,WAAY,SAAQ,iCAAkC;IAGjE,YAAY,MAA2B,EAAE,aAAsC;QAC7E,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAA,qCAAgB,EAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAEe,cAAc,CAC5B,MAAwB,EACxB,GAAW,EACX,IAAS,EACT,gBAAgD,EAAE,EAClD,iBAAoC,EAAE;;YAEtC,MAAM,EAAE,OAAO,EAA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QAAQ,OAAO,CAAC,QAAQ,EAAE;gBACxB,KAAK,MAAM;oBACT,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACzB,KAAK,MAAM;oBACT,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACzB,KAAK,QAAQ;oBACX,OAAO,QAAQ,CAAC,IAAI,CAAC;aACxB;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAES,UAAU,CAAC,OAAgB;QACnC,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QAEvD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA/GD,kCA+GC","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 { FetchClientError } from \"./FetchClientError\";\nimport { FetchRequestConfig, getDefaultConfig, mergeFetchConfig } from \"./FetchRequestConfig\";\n\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\nconst FETCH_FAILURE_MESSAGE = \"OData request failed entirely: \";\nconst JSON_RETRIEVAL_FAILURE_MESSAGE = \"Retrieving JSON body from OData response failed: \";\nconst BLOB_RETRIEVAL_FAILURE_MESSAGE = \"Retrieving blob from OData response failed: \";\nconst RESPONSE_FAILURE_MESSAGE = \"OData server responded with error: \";\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 InternalFetchConfig extends FetchRequestConfig, Pick<RequestInit, \"method\" | \"body\"> {}\n\nexport class FetchClient extends BaseHttpClient<FetchRequestConfig> implements ODataHttpClient<FetchRequestConfig> {\n protected readonly config: FetchRequestConfig;\n\n constructor(config?: FetchRequestConfig, clientOptions?: ODataHttpClientOptions) {\n super(clientOptions);\n this.config = getDefaultConfig(config);\n }\n\n protected async executeRequest<ResponseModel>(\n method: ODataHttpMethods,\n url: string,\n data: any,\n requestConfig: FetchRequestConfig | undefined = {},\n internalConfig: BaseRequestConfig = {},\n ): Promise<HttpResponseModel<ResponseModel>> {\n const { headers, noBodyEvaluation } = internalConfig;\n const { params, ...config } = mergeFetchConfig(this.config, { headers }, requestConfig);\n\n // set core inputs for request\n const resultConfig: InternalFetchConfig = {\n ...config,\n method,\n };\n if (typeof data !== \"undefined\") {\n resultConfig.body = internalConfig.dataType === ODataHttpDataTypes.JSON ? JSON.stringify(data) : data;\n }\n\n // apply additional query params to the URL\n let finalUrl = url;\n if (params && Object.values(params).length) {\n finalUrl +=\n (url.match(/\\?/) ? \"&\" : \"?\") +\n // @ts-ignore\n new URLSearchParams(params).toString();\n }\n\n // the actual request\n let response: Response;\n try {\n response = await fetch(finalUrl, resultConfig);\n } catch (fetchError) {\n throw new FetchClientError(\n buildErrorMessage(FETCH_FAILURE_MESSAGE, fetchError),\n undefined,\n undefined,\n fetchError as Error,\n );\n }\n\n // error response\n if (!response.ok) {\n let responseData;\n try {\n responseData = await this.getResponseBody(response, internalConfig);\n } catch (e) {\n responseData = undefined;\n }\n const errMsg = this.retrieveErrorMessage(responseData);\n\n throw new FetchClientError(\n buildErrorMessage(RESPONSE_FAILURE_MESSAGE, errMsg),\n response.status,\n this.mapHeaders(response.headers),\n new Error(errMsg || DEFAULT_ERROR_MESSAGE),\n responseData,\n );\n }\n\n let responseData;\n try {\n responseData = noBodyEvaluation ? undefined : await this.getResponseBody(response, internalConfig);\n } catch (error) {\n const msg = internalConfig.dataType === \"blob\" ? BLOB_RETRIEVAL_FAILURE_MESSAGE : JSON_RETRIEVAL_FAILURE_MESSAGE;\n throw new FetchClientError(\n buildErrorMessage(msg, error),\n response.status,\n this.mapHeaders(response.headers),\n error as Error,\n );\n }\n\n return {\n status: response.status,\n statusText: response.statusText,\n headers: this.mapHeaders(response.headers),\n data: responseData,\n };\n }\n\n protected async getResponseBody(response: Response, options: BaseRequestConfig) {\n if (response.status === 204) {\n return undefined;\n }\n switch (options.dataType) {\n case \"json\":\n return response.json();\n case \"blob\":\n return response.blob();\n case \"stream\":\n return response.body;\n }\n\n return undefined;\n }\n\n protected mapHeaders(headers: Headers): Record<string, string> {\n const result: Record<string, string> = {};\n headers.forEach((value, key) => (result[key] = value));\n\n return result;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchClientError.js","sourceRoot":"","sources":["../src/FetchClientError.ts"],"names":[],"mappings":";;;AAEA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YACE,OAAe,EACC,MAAe,EACf,OAAgC,EAChC,KAAa,EACb,YAAsB;QAEtC,2GAA2G;QAC3G,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANV,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAyB;QAChC,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAU;QAItC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,4CAYC","sourcesContent":["import { ODataClientError } from \"@odata2ts/http-client-api\";\
|
|
1
|
+
{"version":3,"file":"FetchClientError.js","sourceRoot":"","sources":["../src/FetchClientError.ts"],"names":[],"mappings":";;;AAEA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YACE,OAAe,EACC,MAAe,EACf,OAAgC,EAChC,KAAa,EACb,YAAsB;QAEtC,2GAA2G;QAC3G,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANV,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAyB;QAChC,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAU;QAItC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,4CAYC","sourcesContent":["import { ODataClientError } from \"@odata2ts/http-client-api\";\n\nexport class FetchClientError extends Error implements ODataClientError {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly headers?: Record<string, string>,\n public readonly cause?: Error,\n public readonly responseData?: unknown,\n ) {\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\n super(message, { cause });\n this.name = this.constructor.name;\n }\n}\n"]}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
+
import { ODataRequestConfig } from "@odata2ts/http-client-api";
|
|
1
2
|
/**
|
|
2
3
|
* Available config options for end user when making a given request.
|
|
3
4
|
*/
|
|
4
|
-
export interface FetchRequestConfig extends Partial<Pick<RequestInit, "credentials" | "cache" | "mode" | "redirect" | "referrerPolicy" | "signal">> {
|
|
5
|
-
headers?: Record<string, string> | Headers;
|
|
6
|
-
/**
|
|
7
|
-
* Add query params.
|
|
8
|
-
*/
|
|
9
|
-
params?: Record<string, string | number | boolean | Array<string | number | boolean>>;
|
|
5
|
+
export interface FetchRequestConfig extends ODataRequestConfig, Partial<Pick<RequestInit, "credentials" | "cache" | "mode" | "redirect" | "referrerPolicy" | "signal">> {
|
|
10
6
|
}
|
|
11
|
-
export
|
|
12
|
-
headers: Headers;
|
|
13
|
-
}
|
|
14
|
-
export declare function getDefaultConfig(config?: FetchRequestConfig): RequestInit;
|
|
7
|
+
export declare function getDefaultConfig(config?: FetchRequestConfig): FetchRequestConfig;
|
|
15
8
|
export declare function mergeFetchConfig(): undefined;
|
|
16
|
-
export declare function mergeFetchConfig(...configs: Array<
|
|
9
|
+
export declare function mergeFetchConfig(...configs: Array<FetchRequestConfig | undefined>): FetchRequestConfig;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeFetchConfig = exports.getDefaultConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const DEFAULT_CONFIG = {
|
|
6
|
-
// headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
7
6
|
cache: "no-store",
|
|
8
7
|
};
|
|
9
8
|
function getDefaultConfig(config) {
|
|
@@ -17,19 +16,20 @@ function mergeFetchConfig(...configs) {
|
|
|
17
16
|
return configs
|
|
18
17
|
.filter((c) => !!c)
|
|
19
18
|
.reduce((collector, current) => {
|
|
19
|
+
const { headers: prevHeaders } = collector, prevPassThrough = tslib_1.__rest(collector, ["headers"]);
|
|
20
20
|
const { headers } = current, passThrough = tslib_1.__rest(current, ["headers"]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (headers && headers instanceof Headers) {
|
|
24
|
-
// @ts-ignore: fails on CI test
|
|
25
|
-
headers.forEach((val, key) => collectedHeaders.set(key, val));
|
|
26
|
-
}
|
|
27
|
-
// headers as plain Record<string,string>
|
|
28
|
-
else if (headers) {
|
|
29
|
-
Object.entries(headers).forEach(([key, val]) => collectedHeaders.set(key, val));
|
|
21
|
+
if (headers) {
|
|
22
|
+
Object.entries(cleanHeaders(headers)).forEach(([key, val]) => (collector.headers[key] = val));
|
|
30
23
|
}
|
|
31
24
|
return Object.assign(Object.assign({}, collector), passThrough);
|
|
32
|
-
}, { headers:
|
|
25
|
+
}, { headers: {} });
|
|
33
26
|
}
|
|
34
27
|
exports.mergeFetchConfig = mergeFetchConfig;
|
|
28
|
+
function cleanHeaders(headers) {
|
|
29
|
+
const result = {};
|
|
30
|
+
const temp = new Headers();
|
|
31
|
+
Object.entries(headers).forEach(([key, val]) => temp.set(key, val));
|
|
32
|
+
temp.forEach((val, key) => (result[key] = val));
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
35
|
//# sourceMappingURL=FetchRequestConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchRequestConfig.js","sourceRoot":"","sources":["../src/FetchRequestConfig.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"FetchRequestConfig.js","sourceRoot":"","sources":["../src/FetchRequestConfig.ts"],"names":[],"mappings":";;;;AAEA,MAAM,cAAc,GAAuB;IACzC,KAAK,EAAE,UAAU;CAClB,CAAC;AASF,SAAgB,gBAAgB,CAAC,MAA2B;IAC1D,OAAO,gBAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAFD,4CAEC;AAID,SAAgB,gBAAgB,CAAC,GAAG,OAA8C;IAChF,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IACD,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,EAAE,WAAW,KAAyB,SAAS,EAA7B,eAAe,kBAAK,SAAS,EAAxD,WAA4C,CAAY,CAAC;QAC/D,MAAM,EAAE,OAAO,KAAqB,OAAO,EAAvB,WAAW,kBAAK,OAAO,EAArC,WAA2B,CAAU,CAAC;QAE5C,IAAI,OAAO,EAAE;YACX,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,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;SAChG;QAED,uCAAY,SAAS,GAAK,WAAW,EAAG;IAC1C,CAAC,EACD,EAAE,OAAO,EAAE,EAAE,EAAE,CAChB,CAAC;AACN,CAAC;AAnBD,4CAmBC;AAED,SAAS,YAAY,CAAC,OAA+B;IACnD,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;IAC3B,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAEhD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ODataRequestConfig } from \"@odata2ts/http-client-api\";\n\nconst DEFAULT_CONFIG: FetchRequestConfig = {\n cache: \"no-store\",\n};\n\n/**\n * Available config options for end user when making a given request.\n */\nexport interface FetchRequestConfig\n extends ODataRequestConfig,\n Partial<Pick<RequestInit, \"credentials\" | \"cache\" | \"mode\" | \"redirect\" | \"referrerPolicy\" | \"signal\">> {}\n\nexport function getDefaultConfig(config?: FetchRequestConfig): FetchRequestConfig {\n return mergeFetchConfig(DEFAULT_CONFIG, config);\n}\n\nexport function mergeFetchConfig(): undefined;\nexport function mergeFetchConfig(...configs: Array<FetchRequestConfig | undefined>): FetchRequestConfig;\nexport function mergeFetchConfig(...configs: Array<FetchRequestConfig | undefined>) {\n if (!configs.length) {\n return undefined;\n }\n return configs\n .filter((c): c is FetchRequestConfig => !!c)\n .reduce<FetchRequestConfig>(\n (collector, current) => {\n const { headers: prevHeaders, ...prevPassThrough } = collector;\n const { headers, ...passThrough } = current;\n\n if (headers) {\n Object.entries(cleanHeaders(headers)).forEach(([key, val]) => (collector.headers![key] = val));\n }\n\n return { ...collector, ...passThrough };\n },\n { headers: {} },\n );\n}\n\nfunction cleanHeaders(headers: Record<string, string>): Record<string, string> {\n const result: Record<string, string> = {};\n const temp = new Headers();\n Object.entries(headers).forEach(([key, val]) => temp.set(key, val));\n temp.forEach((val, key) => (result[key] = val));\n\n return result;\n}\n"]}
|
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 \"./FetchClient\";\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAA8B;AAC9B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA","sourcesContent":["export * from \"./FetchClient\";\nexport { FetchClientError } from \"./FetchClientError\";\nexport { FetchRequestConfig } from \"./FetchRequestConfig\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/http-client-fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "HTTP client based on fetch and consumable by odata2ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http client",
|
|
@@ -27,11 +27,10 @@
|
|
|
27
27
|
"compile": "tsc",
|
|
28
28
|
"unit-test": "vitest run --dir test",
|
|
29
29
|
"int-test": "vitest run --dir int-test",
|
|
30
|
-
"test": "vitest run"
|
|
31
|
-
"prepublish": "yarn build"
|
|
30
|
+
"test": "vitest run"
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"@odata2ts/http-client-base": "^0.5.
|
|
33
|
+
"@odata2ts/http-client-base": "^0.5.5"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@odata2ts/odata-core": "^0.3.7",
|
|
@@ -41,6 +40,5 @@
|
|
|
41
40
|
},
|
|
42
41
|
"publishConfig": {
|
|
43
42
|
"access": "public"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
43
|
+
}
|
|
44
|
+
}
|