@odata2ts/http-client-fetch 0.7.1 → 0.8.0
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 +10 -0
- package/lib/FetchClient.d.ts +1 -1
- package/lib/FetchClient.js +18 -14
- package/lib/FetchClient.js.map +1 -1
- package/lib/FetchClientError.d.ts +2 -2
- package/lib/FetchClientError.js +7 -3
- package/lib/FetchClientError.js.map +1 -1
- package/lib/FetchRequestConfig.js +9 -4
- package/lib/FetchRequestConfig.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +7 -2
- package/lib/index.js.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.8.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-fetch@0.7.2...@odata2ts/http-client-fetch@0.8.0) (2024-08-24)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
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
|
+
|
|
12
|
+
## [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
|
+
|
|
14
|
+
**Note:** Version bump only for package @odata2ts/http-client-fetch
|
|
15
|
+
|
|
6
16
|
## [0.7.1](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-fetch@0.7.0...@odata2ts/http-client-fetch@0.7.1) (2024-08-14)
|
|
7
17
|
|
|
8
18
|
### Bug Fixes
|
package/lib/FetchClient.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpResponseModel, ODataHttpClient } from "@odata2ts/http-client-api";
|
|
2
2
|
import { BaseHttpClient, BaseHttpClientOptions, HttpMethods, InternalHttpClientConfig } from "@odata2ts/http-client-base";
|
|
3
|
-
import { FetchRequestConfig } from "./FetchRequestConfig
|
|
3
|
+
import { FetchRequestConfig } from "./FetchRequestConfig";
|
|
4
4
|
export interface ClientOptions extends BaseHttpClientOptions {
|
|
5
5
|
}
|
|
6
6
|
export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
|
package/lib/FetchClient.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchClient = 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 FetchClientError_1 = require("./FetchClientError");
|
|
7
|
+
const FetchRequestConfig_1 = require("./FetchRequestConfig");
|
|
8
|
+
exports.DEFAULT_ERROR_MESSAGE = "No error message!";
|
|
6
9
|
const FETCH_FAILURE_MESSAGE = "OData request failed entirely: ";
|
|
7
10
|
const JSON_RETRIEVAL_FAILURE_MESSAGE = "Retrieving JSON body from OData response failed: ";
|
|
8
11
|
const BLOB_RETRIEVAL_FAILURE_MESSAGE = "Retrieving blob from OData response failed: ";
|
|
9
12
|
const RESPONSE_FAILURE_MESSAGE = "OData server responded with error: ";
|
|
10
13
|
function buildErrorMessage(prefix, error) {
|
|
11
14
|
const msg = typeof error === "string" ? error : error === null || error === void 0 ? void 0 : error.message;
|
|
12
|
-
return prefix + (msg || DEFAULT_ERROR_MESSAGE);
|
|
15
|
+
return prefix + (msg || exports.DEFAULT_ERROR_MESSAGE);
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
class FetchClient extends http_client_base_1.BaseHttpClient {
|
|
15
18
|
constructor(config, clientOptions) {
|
|
16
19
|
super(clientOptions);
|
|
17
|
-
this.config = getDefaultConfig(config);
|
|
20
|
+
this.config = (0, FetchRequestConfig_1.getDefaultConfig)(config);
|
|
18
21
|
}
|
|
19
22
|
executeRequest(method, url, data, requestConfig = {}, internalConfig = {}) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
24
|
const { headers, noBodyEvaluation } = internalConfig;
|
|
22
|
-
const _a = mergeFetchConfig(this.config, { headers }, requestConfig), { params } = _a, config = __rest(_a, ["params"]);
|
|
25
|
+
const _a = (0, FetchRequestConfig_1.mergeFetchConfig)(this.config, { headers }, requestConfig), { params } = _a, config = tslib_1.__rest(_a, ["params"]);
|
|
23
26
|
config.method = method;
|
|
24
27
|
if (typeof data !== "undefined") {
|
|
25
28
|
config.body = internalConfig.dataType === "json" ? JSON.stringify(data) : data;
|
|
@@ -37,7 +40,7 @@ export class FetchClient extends BaseHttpClient {
|
|
|
37
40
|
response = yield fetch(finalUrl, config);
|
|
38
41
|
}
|
|
39
42
|
catch (fetchError) {
|
|
40
|
-
throw new FetchClientError(buildErrorMessage(FETCH_FAILURE_MESSAGE, fetchError), undefined, undefined, fetchError);
|
|
43
|
+
throw new FetchClientError_1.FetchClientError(buildErrorMessage(FETCH_FAILURE_MESSAGE, fetchError), undefined, undefined, fetchError);
|
|
41
44
|
}
|
|
42
45
|
// error response
|
|
43
46
|
if (!response.ok) {
|
|
@@ -49,7 +52,7 @@ export class FetchClient extends BaseHttpClient {
|
|
|
49
52
|
responseData = undefined;
|
|
50
53
|
}
|
|
51
54
|
const errMsg = this.retrieveErrorMessage(responseData);
|
|
52
|
-
throw new FetchClientError(buildErrorMessage(RESPONSE_FAILURE_MESSAGE, errMsg), response.status, this.mapHeaders(response.headers), new Error(errMsg || DEFAULT_ERROR_MESSAGE),
|
|
55
|
+
throw new FetchClientError_1.FetchClientError(buildErrorMessage(RESPONSE_FAILURE_MESSAGE, errMsg), response.status, this.mapHeaders(response.headers), new Error(errMsg || exports.DEFAULT_ERROR_MESSAGE), responseData);
|
|
53
56
|
}
|
|
54
57
|
let responseData;
|
|
55
58
|
try {
|
|
@@ -57,7 +60,7 @@ export class FetchClient extends BaseHttpClient {
|
|
|
57
60
|
}
|
|
58
61
|
catch (error) {
|
|
59
62
|
const msg = internalConfig.dataType === "blob" ? BLOB_RETRIEVAL_FAILURE_MESSAGE : JSON_RETRIEVAL_FAILURE_MESSAGE;
|
|
60
|
-
throw new FetchClientError(buildErrorMessage(msg, error), response.status, this.mapHeaders(response.headers), error);
|
|
63
|
+
throw new FetchClientError_1.FetchClientError(buildErrorMessage(msg, error), response.status, this.mapHeaders(response.headers), error);
|
|
61
64
|
}
|
|
62
65
|
return {
|
|
63
66
|
status: response.status,
|
|
@@ -68,7 +71,7 @@ export class FetchClient extends BaseHttpClient {
|
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
73
|
getResponseBody(response, options) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
72
75
|
if (response.status === 204) {
|
|
73
76
|
return undefined;
|
|
74
77
|
}
|
|
@@ -89,4 +92,5 @@ export class FetchClient extends BaseHttpClient {
|
|
|
89
92
|
return result;
|
|
90
93
|
}
|
|
91
94
|
}
|
|
95
|
+
exports.FetchClient = FetchClient;
|
|
92
96
|
//# sourceMappingURL=FetchClient.js.map
|
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":";;;;AACA,iEAKoC;AACpC,yDAAsD;AACtD,6DAA8F;AAIjF,QAAA,qBAAqB,GAA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ataHttpClient } 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 { FetchClientError } from \"./FetchClientError\";\r\nimport { FetchRequestConfig, getDefaultConfig, mergeFetchConfig } from \"./FetchRequestConfig\";\r\n\r\nexport interface ClientOptions extends BaseHttpClientOptions {}\r\n\r\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\r\nconst FETCH_FAILURE_MESSAGE = \"OData request failed entirely: \";\r\nconst JSON_RETRIEVAL_FAILURE_MESSAGE = \"Retrieving JSON body from OData response failed: \";\r\nconst BLOB_RETRIEVAL_FAILURE_MESSAGE = \"Retrieving blob from OData response failed: \";\r\nconst RESPONSE_FAILURE_MESSAGE = \"OData server responded with error: \";\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 FetchClient extends BaseHttpClient<FetchRequestConfig> implements ODataHttpClient<FetchRequestConfig> {\r\n protected readonly config: RequestInit;\r\n\r\n constructor(config?: FetchRequestConfig, clientOptions?: ClientOptions) {\r\n super(clientOptions);\r\n this.config = getDefaultConfig(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: FetchRequestConfig | undefined = {},\r\n internalConfig: InternalHttpClientConfig = {},\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n const { headers, noBodyEvaluation } = internalConfig;\r\n const { params, ...config } = mergeFetchConfig(this.config, { headers }, requestConfig);\r\n config.method = method;\r\n if (typeof data !== \"undefined\") {\r\n config.body = internalConfig.dataType === \"json\" ? JSON.stringify(data) : data;\r\n }\r\n let finalUrl = url;\r\n if (params && Object.values(params).length) {\r\n finalUrl +=\r\n (url.match(/\\?/) ? \"&\" : \"?\") +\r\n // @ts-ignore\r\n new URLSearchParams(params).toString();\r\n }\r\n\r\n // the actual request\r\n let response: Response;\r\n try {\r\n response = await fetch(finalUrl, config);\r\n } catch (fetchError) {\r\n throw new FetchClientError(\r\n buildErrorMessage(FETCH_FAILURE_MESSAGE, fetchError),\r\n undefined,\r\n undefined,\r\n fetchError as Error,\r\n );\r\n }\r\n\r\n // error response\r\n if (!response.ok) {\r\n let responseData;\r\n try {\r\n responseData = await this.getResponseBody(response, internalConfig);\r\n } catch (e) {\r\n responseData = undefined;\r\n }\r\n const errMsg = this.retrieveErrorMessage(responseData);\r\n\r\n throw new FetchClientError(\r\n buildErrorMessage(RESPONSE_FAILURE_MESSAGE, errMsg),\r\n response.status,\r\n this.mapHeaders(response.headers),\r\n new Error(errMsg || DEFAULT_ERROR_MESSAGE),\r\n responseData,\r\n );\r\n }\r\n\r\n let responseData;\r\n try {\r\n responseData = noBodyEvaluation ? undefined : await this.getResponseBody(response, internalConfig);\r\n } catch (error) {\r\n const msg = internalConfig.dataType === \"blob\" ? BLOB_RETRIEVAL_FAILURE_MESSAGE : JSON_RETRIEVAL_FAILURE_MESSAGE;\r\n throw new FetchClientError(\r\n buildErrorMessage(msg, error),\r\n response.status,\r\n this.mapHeaders(response.headers),\r\n error as Error,\r\n );\r\n }\r\n\r\n return {\r\n status: response.status,\r\n statusText: response.statusText,\r\n headers: this.mapHeaders(response.headers),\r\n data: responseData,\r\n };\r\n }\r\n\r\n protected async getResponseBody(response: Response, options: InternalHttpClientConfig) {\r\n if (response.status === 204) {\r\n return undefined;\r\n }\r\n switch (options.dataType) {\r\n case \"json\":\r\n return response.json();\r\n case \"blob\":\r\n return response.blob();\r\n case \"stream\":\r\n return response.body;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n protected mapHeaders(headers: Headers): Record<string, string> {\r\n const result: Record<string, string> = {};\r\n headers.forEach((value, key) => (result[key] = value));\r\n\r\n return result;\r\n }\r\n}\r\n"]}
|
|
@@ -3,6 +3,6 @@ export declare class FetchClientError extends Error implements ODataClientError
|
|
|
3
3
|
readonly status?: number | undefined;
|
|
4
4
|
readonly headers?: Record<string, string> | undefined;
|
|
5
5
|
readonly cause?: Error | undefined;
|
|
6
|
-
readonly
|
|
7
|
-
constructor(message: string, status?: number | undefined, headers?: Record<string, string> | undefined, cause?: Error | undefined,
|
|
6
|
+
readonly responseData?: unknown;
|
|
7
|
+
constructor(message: string, status?: number | undefined, headers?: Record<string, string> | undefined, cause?: Error | undefined, responseData?: unknown);
|
|
8
8
|
}
|
package/lib/FetchClientError.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchClientError = void 0;
|
|
4
|
+
class FetchClientError extends Error {
|
|
5
|
+
constructor(message, status, headers, cause, responseData) {
|
|
3
6
|
// @ts-ignore: fetch requires lib "dom" or "webworker", but then the "cause" property becomes unknown to TS
|
|
4
7
|
super(message, { cause });
|
|
5
8
|
this.status = status;
|
|
6
9
|
this.headers = headers;
|
|
7
10
|
this.cause = cause;
|
|
8
|
-
this.
|
|
11
|
+
this.responseData = responseData;
|
|
9
12
|
this.name = this.constructor.name;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
15
|
+
exports.FetchClientError = FetchClientError;
|
|
12
16
|
//# sourceMappingURL=FetchClientError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchClientError.js","sourceRoot":"","sources":["../src/FetchClientError.ts"],"names":[],"mappings":"AAEA,
|
|
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\";\r\n\r\nexport class FetchClientError extends Error implements ODataClientError {\r\n constructor(\r\n message: 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 responseData?: unknown,\r\n ) {\r\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\r\n super(message, { cause });\r\n this.name = this.constructor.name;\r\n }\r\n}\r\n"]}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeFetchConfig = exports.getDefaultConfig = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
2
5
|
const DEFAULT_CONFIG = {
|
|
3
6
|
// headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
4
7
|
cache: "no-store",
|
|
5
8
|
};
|
|
6
|
-
|
|
9
|
+
function getDefaultConfig(config) {
|
|
7
10
|
return mergeFetchConfig(DEFAULT_CONFIG, config);
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
13
|
+
function mergeFetchConfig(...configs) {
|
|
10
14
|
if (!configs.length) {
|
|
11
15
|
return undefined;
|
|
12
16
|
}
|
|
13
17
|
return configs
|
|
14
18
|
.filter((c) => !!c)
|
|
15
19
|
.reduce((collector, current) => {
|
|
16
|
-
const { headers } = current, passThrough = __rest(current, ["headers"]);
|
|
20
|
+
const { headers } = current, passThrough = tslib_1.__rest(current, ["headers"]);
|
|
17
21
|
const collectedHeaders = collector.headers;
|
|
18
22
|
// headers as Headers object
|
|
19
23
|
if (headers && headers instanceof Headers) {
|
|
@@ -27,4 +31,5 @@ export function mergeFetchConfig(...configs) {
|
|
|
27
31
|
return Object.assign(Object.assign({}, collector), passThrough);
|
|
28
32
|
}, { headers: new Headers() });
|
|
29
33
|
}
|
|
34
|
+
exports.mergeFetchConfig = mergeFetchConfig;
|
|
30
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":";;;;AAAA,MAAM,cAAc,GAAgB;IAClC,+EAA+E;IAC/E,KAAK,EAAE,UAAU;CAClB,CAAC;AAkBF,SAAgB,gBAAgB,CAAC,MAA2B;IAC1D,OAAO,gBAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAFD,4CAEC;AAID,SAAgB,gBAAgB,CAAC,GAAG,OAAuC;IACzE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,CAAC,EAAoB,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACpC,MAAM,CACL,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;QACrB,MAAM,EAAE,OAAO,KAAqB,OAAO,EAAvB,WAAW,kBAAK,OAAO,EAArC,WAA2B,CAAU,CAAC;QAC5C,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAkB,CAAC;QAEtD,4BAA4B;QAC5B,IAAI,OAAO,IAAI,OAAO,YAAY,OAAO,EAAE;YACzC,+BAA+B;YAC/B,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;SAC/D;QACD,yCAAyC;aACpC,IAAI,OAAO,EAAE;YAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;SACjF;QAED,uCAAY,SAAS,GAAK,WAAW,EAAG;IAC1C,CAAC,EACD,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,EAAE,CAC3B,CAAC;AACN,CAAC;AAzBD,4CAyBC","sourcesContent":["const DEFAULT_CONFIG: RequestInit = {\n // headers: { Accept: \"application/json\", \"Content-Type\": \"application/json\" },\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 Partial<Pick<RequestInit, \"credentials\" | \"cache\" | \"mode\" | \"redirect\" | \"referrerPolicy\" | \"signal\">> {\n headers?: Record<string, string> | Headers;\n /**\n * Add query params.\n */\n params?: Record<string, string | number | boolean | Array<string | number | boolean>>;\n}\n\nexport interface InternalFetchConfig extends Omit<RequestInit, \"headers\">, Pick<FetchRequestConfig, \"params\"> {\n headers: Headers;\n}\n\nexport function getDefaultConfig(config?: FetchRequestConfig): RequestInit {\n return mergeFetchConfig(DEFAULT_CONFIG, config);\n}\n\nexport function mergeFetchConfig(): undefined;\nexport function mergeFetchConfig(...configs: Array<RequestInit | undefined>): InternalFetchConfig;\nexport function mergeFetchConfig(...configs: Array<RequestInit | undefined>) {\n if (!configs.length) {\n return undefined;\n }\n return configs\n .filter((c): c is RequestInit => !!c)\n .reduce<InternalFetchConfig>(\n (collector, current) => {\n const { headers, ...passThrough } = current;\n const collectedHeaders = collector.headers as Headers;\n\n // headers as Headers object\n if (headers && headers instanceof Headers) {\n // @ts-ignore: fails on CI test\n headers.forEach((val, key) => collectedHeaders.set(key, val));\n }\n // headers as plain Record<string,string>\n else if (headers) {\n Object.entries(headers).forEach(([key, val]) => collectedHeaders.set(key, val));\n }\n\n return { ...collector, ...passThrough };\n },\n { headers: new Headers() },\n );\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./FetchClient
|
|
2
|
-
export { FetchClientError } from "./FetchClientError
|
|
3
|
-
export { FetchRequestConfig } from "./FetchRequestConfig
|
|
1
|
+
export * from "./FetchClient";
|
|
2
|
+
export { FetchClientError } from "./FetchClientError";
|
|
3
|
+
export { FetchRequestConfig } from "./FetchRequestConfig";
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchClientError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./FetchClient"), exports);
|
|
6
|
+
var FetchClientError_1 = require("./FetchClientError");
|
|
7
|
+
Object.defineProperty(exports, "FetchClientError", { enumerable: true, get: function () { return FetchClientError_1.FetchClientError; } });
|
|
3
8
|
//# 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,
|
|
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\";\r\nexport { FetchClientError } from \"./FetchClientError\";\r\nexport { FetchRequestConfig } from \"./FetchRequestConfig\";\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/http-client-fetch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "HTTP client based on fetch and consumable by odata2ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http client",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"repository": "git@github.com:odata2ts/http-client.git",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "texttechne",
|
|
15
|
-
"type": "
|
|
15
|
+
"type": "commonjs",
|
|
16
16
|
"main": "./lib/index.js",
|
|
17
17
|
"types": "./lib/index.d.ts",
|
|
18
18
|
"files": [
|
|
@@ -25,12 +25,13 @@
|
|
|
25
25
|
"check-circular-deps": "madge ./src --extensions ts --circular",
|
|
26
26
|
"clean": "rimraf lib coverage",
|
|
27
27
|
"compile": "tsc",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"test": "vitest run
|
|
28
|
+
"unit-test": "vitest run --dir test",
|
|
29
|
+
"int-test": "vitest run --dir int-test",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"prepublish": "yarn build"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@odata2ts/http-client-base": "^0.5.
|
|
34
|
+
"@odata2ts/http-client-base": "^0.5.3"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@odata2ts/odata-core": "^0.3.7",
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "d74b162906b89826cce7944308bc5950e325389f"
|
|
45
46
|
}
|