@odata2ts/http-client-base 0.5.0 → 0.5.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 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.5.2](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-base@0.5.1...@odata2ts/http-client-base@0.5.2) (2024-08-22)
7
+
8
+ **Note:** Version bump only for package @odata2ts/http-client-base
9
+
10
+ ## [0.5.1](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-base@0.5.0...@odata2ts/http-client-base@0.5.1) (2024-08-14)
11
+
12
+ ### Bug Fixes
13
+
14
+ * 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))
15
+
6
16
  # [0.5.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-base@0.4.2...@odata2ts/http-client-base@0.5.0) (2024-08-13)
7
17
 
8
18
  ### Code Refactoring
@@ -1,8 +1,11 @@
1
- import { __awaiter } from "tslib";
2
- import { retrieveErrorMessage } from "./ErrorMessageRetriever";
3
- import { HttpMethods } from "./HttpMethods";
4
- export const DEFAULT_CSRF_TOKEN_KEY = "x-csrf-token";
5
- const EDIT_METHODS = [HttpMethods.Post, HttpMethods.Put, HttpMethods.Patch, HttpMethods.Delete];
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseHttpClient = exports.DEFAULT_CSRF_TOKEN_KEY = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ErrorMessageRetriever_1 = require("./ErrorMessageRetriever");
6
+ const HttpMethods_1 = require("./HttpMethods");
7
+ exports.DEFAULT_CSRF_TOKEN_KEY = "x-csrf-token";
8
+ const EDIT_METHODS = [HttpMethods_1.HttpMethods.Post, HttpMethods_1.HttpMethods.Put, HttpMethods_1.HttpMethods.Patch, HttpMethods_1.HttpMethods.Delete];
6
9
  const FAILURE_MISSING_CSRF_URL = "When automatic CSRF token handling is activated, the URL must be supplied via attribute [csrfTokenFetchUrl]!";
7
10
  const FAILURE_MISSING_URL = "Value for URL must be provided!";
8
11
  const JSON_VALUE = "application/json";
@@ -12,12 +15,12 @@ function getInternalConfigWithJsonHeaders(headers, setContentType = true) {
12
15
  dataType: "json",
13
16
  };
14
17
  }
15
- export class BaseHttpClient {
18
+ class BaseHttpClient {
16
19
  constructor(baseOptions = { useCsrfProtection: false }) {
17
20
  var _a;
18
21
  this.baseOptions = baseOptions;
19
- this.csrfTokenKey = DEFAULT_CSRF_TOKEN_KEY;
20
- this.retrieveErrorMessage = retrieveErrorMessage;
22
+ this.csrfTokenKey = exports.DEFAULT_CSRF_TOKEN_KEY;
23
+ this.retrieveErrorMessage = ErrorMessageRetriever_1.retrieveErrorMessage;
21
24
  if (baseOptions.useCsrfProtection && !((_a = baseOptions.csrfTokenFetchUrl) === null || _a === void 0 ? void 0 : _a.trim())) {
22
25
  throw new Error(FAILURE_MISSING_CSRF_URL);
23
26
  }
@@ -26,13 +29,13 @@ export class BaseHttpClient {
26
29
  return this.csrfTokenKey;
27
30
  }
28
31
  setCsrfTokenKey(newKey) {
29
- this.csrfTokenKey = newKey || DEFAULT_CSRF_TOKEN_KEY;
32
+ this.csrfTokenKey = newKey || exports.DEFAULT_CSRF_TOKEN_KEY;
30
33
  }
31
34
  setErrorMessageRetriever(getErrorMsg) {
32
35
  this.retrieveErrorMessage = getErrorMsg;
33
36
  }
34
37
  setupSecurityToken() {
35
- return __awaiter(this, void 0, void 0, function* () {
38
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
39
  if (!this.csrfToken) {
37
40
  this.csrfToken = yield this.fetchSecurityToken();
38
41
  }
@@ -40,9 +43,9 @@ export class BaseHttpClient {
40
43
  });
41
44
  }
42
45
  fetchSecurityToken() {
43
- return __awaiter(this, void 0, void 0, function* () {
46
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
47
  const fetchUrl = this.baseOptions.csrfTokenFetchUrl;
45
- const response = yield this.sendRequest(HttpMethods.Get, fetchUrl, undefined, undefined, {
48
+ const response = yield this.sendRequest(HttpMethods_1.HttpMethods.Get, fetchUrl, undefined, undefined, {
46
49
  noBodyEvaluation: true,
47
50
  headers: { [this.csrfTokenKey]: "Fetch", Accept: JSON_VALUE },
48
51
  });
@@ -60,7 +63,7 @@ export class BaseHttpClient {
60
63
  * @private
61
64
  */
62
65
  sendRequest(method, url, data, requestConfig, internalConfig = {}) {
63
- return __awaiter(this, void 0, void 0, function* () {
66
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
64
67
  // noinspection SuspiciousTypeOfGuard
65
68
  if (typeof url !== "string") {
66
69
  throw new Error(FAILURE_MISSING_URL);
@@ -94,34 +97,35 @@ export class BaseHttpClient {
94
97
  });
95
98
  }
96
99
  get(url, requestConfig, additionalHeaders) {
97
- return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders, false));
100
+ return this.sendRequest(HttpMethods_1.HttpMethods.Get, url, undefined, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders, false));
98
101
  }
99
102
  post(url, data, requestConfig, additionalHeaders) {
100
- return this.sendRequest(HttpMethods.Post, url, data, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders));
103
+ return this.sendRequest(HttpMethods_1.HttpMethods.Post, url, data, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders));
101
104
  }
102
105
  put(url, data, requestConfig, additionalHeaders) {
103
- return this.sendRequest(HttpMethods.Put, url, data, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders));
106
+ return this.sendRequest(HttpMethods_1.HttpMethods.Put, url, data, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders));
104
107
  }
105
108
  patch(url, data, requestConfig, additionalHeaders) {
106
- return this.sendRequest(HttpMethods.Patch, url, data, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders));
109
+ return this.sendRequest(HttpMethods_1.HttpMethods.Patch, url, data, requestConfig, getInternalConfigWithJsonHeaders(additionalHeaders));
107
110
  }
108
111
  getAdditionalHeaders(additionalHeaders) {
109
112
  return additionalHeaders ? { headers: additionalHeaders } : undefined;
110
113
  }
111
114
  delete(url, requestConfig, additionalHeaders) {
112
- return this.sendRequest(HttpMethods.Delete, url, undefined, requestConfig, this.getAdditionalHeaders(additionalHeaders));
115
+ return this.sendRequest(HttpMethods_1.HttpMethods.Delete, url, undefined, requestConfig, this.getAdditionalHeaders(additionalHeaders));
113
116
  }
114
117
  getBlob(url, requestConfig, additionalHeaders) {
115
- return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, Object.assign(Object.assign({}, this.getAdditionalHeaders(additionalHeaders)), { dataType: "blob" }));
118
+ return this.sendRequest(HttpMethods_1.HttpMethods.Get, url, undefined, requestConfig, Object.assign(Object.assign({}, this.getAdditionalHeaders(additionalHeaders)), { dataType: "blob" }));
116
119
  }
117
120
  getStream(url, requestConfig, additionalHeaders) {
118
- return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, Object.assign(Object.assign({}, this.getAdditionalHeaders(additionalHeaders)), { dataType: "stream" }));
121
+ return this.sendRequest(HttpMethods_1.HttpMethods.Get, url, undefined, requestConfig, Object.assign(Object.assign({}, this.getAdditionalHeaders(additionalHeaders)), { dataType: "stream" }));
119
122
  }
120
123
  updateBlob(url, data, mimeType, requestConfig, additionalHeaders) {
121
- return this.sendRequest(HttpMethods.Put, url, data, requestConfig, {
124
+ return this.sendRequest(HttpMethods_1.HttpMethods.Put, url, data, requestConfig, {
122
125
  headers: Object.assign(Object.assign({}, additionalHeaders), { Accept: mimeType, "Content-Type": mimeType }),
123
126
  dataType: "blob",
124
127
  });
125
128
  }
126
129
  }
130
+ exports.BaseHttpClient = BaseHttpClient;
127
131
  //# sourceMappingURL=B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AAC,iBAAiB,CAAC,KAC/C,QAAQ,EAAE,QAAQ,IAClB,CAAC;IACL,CAAC;IAEM,UAAU,CACf,GAAW,EACX,IAAU,EACV,QAAgB,EAChB,aAAiC,EACjC,iBAA0C;QAE1C,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE;YACjE,OAAO,kCAAO,iBAAiB,KAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,GAAE;YAC7E,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { HttpResponseModel, ODataClientError, ODataResponse } from \"@odata2ts/http-client-api\";\nimport { ErrorMessageRetriever, retrieveErrorMessage } from \"./ErrorMessageRetriever\";\nimport { HttpMethods } from \"./HttpMethods\";\n\nexport interface BaseHttpClientOptions {\n /**\n * Enable automatic CSRF token handling.\n */\n useCsrfProtection?: boolean;\n /**\n * Specify the URL from which the token is fetched.\n * This could be any path to your OData service, since the token is exchanged via HTTP request headers.\n * However, it should be a fast response and usually the root URL to the OData service is a good choice.\n */\n csrfTokenFetchUrl?: string;\n}\n\nexport interface InternalHttpClientConfig {\n dataType?: \"json\" | \"blob\" | \"stream\";\n /**\n * Additional headers set internally by services or HttpClient implementation.\n */\n headers?: Record<string, string>;\n /**\n * Very special option needed for FetchClient to not evaluate the response body in certain situations.\n */\n noBodyEvaluation?: boolean;\n}\n\nexport const DEFAULT_CSRF_TOKEN_KEY = \"x-csrf-token\";\n\nconst EDIT_METHODS = [HttpMethods.Post, HttpMethods.Put, HttpMethods.Patch, HttpMethods.Delete];\nconst FAILURE_MISSING_CSRF_URL =\n \"When automatic CSRF token handling is activated, the URL must be supplied via attribute [csrfTokenFetchUrl]!\";\nconst FAILURE_MISSING_URL = \"Value for URL must be provided!\";\nconst JSON_VALUE = \"application/json\";\n\nfunction getInternalConfigWithJsonHeaders(\n headers?: Record<string, string>,\n setContentType: boolean = true,\n): InternalHttpClientConfig {\n return {\n headers: {\n Accept: JSON_VALUE,\n ...(setContentType ? { \"Content-Type\": JSON_VALUE } : undefined),\n ...headers,\n },\n dataType: \"json\",\n };\n}\n\nexport abstract class BaseHttpClient<RequestConfigType> {\n private csrfToken: string | undefined;\n private csrfTokenKey = DEFAULT_CSRF_TOKEN_KEY;\n\n protected retrieveErrorMessage: ErrorMessageRetriever = retrieveErrorMessage;\n\n protected constructor(private baseOptions: BaseHttpClientOptions = { useCsrfProtection: false }) {\n if (baseOptions.useCsrfProtection && !baseOptions.csrfTokenFetchUrl?.trim()) {\n throw new Error(FAILURE_MISSING_CSRF_URL);\n }\n }\n\n /**\n * Main function to implement by any extending http client.\n * As it name suggests, the request gets executed in this method.\n * Additionally, failures should be handled and errors of type <code>HttpClientError</code> should be thrown.\n *\n * @param method the http method to use\n * @param url the URL to use\n * @param data data for the request body if any\n * @param config request configuration from end user which should override default settings\n * @param internalConfig request configuration from base client including additional headers which should override end user configurations\n */\n protected abstract executeRequest<ResponseModel>(\n method: HttpMethods,\n url: string,\n data: any,\n config?: RequestConfigType,\n internalConfig?: InternalHttpClientConfig,\n ): Promise<HttpResponseModel<ResponseModel>>;\n\n public getCsrfTokenKey() {\n return this.csrfTokenKey;\n }\n\n public setCsrfTokenKey(newKey: string) {\n this.csrfTokenKey = newKey || DEFAULT_CSRF_TOKEN_KEY;\n }\n\n public setErrorMessageRetriever(getErrorMsg: ErrorMessageRetriever) {\n this.retrieveErrorMessage = getErrorMsg;\n }\n\n protected async setupSecurityToken(): Promise<[string, string | undefined]> {\n if (!this.csrfToken) {\n this.csrfToken = await this.fetchSecurityToken();\n }\n return [this.csrfTokenKey, this.csrfToken];\n }\n\n protected async fetchSecurityToken(): Promise<string | undefined> {\n const fetchUrl = this.baseOptions!.csrfTokenFetchUrl!;\n const response = await this.sendRequest(HttpMethods.Get, fetchUrl, undefined, undefined, {\n noBodyEvaluation: true,\n headers: { [this.csrfTokenKey]: \"Fetch\", Accept: JSON_VALUE },\n });\n\n return response.headers[this.csrfTokenKey];\n }\n\n /**\n * Follows the template pattern.\n *\n * @param method\n * @param url\n * @param data\n * @param requestConfig\n * @param internalConfig\n * @private\n */\n private async sendRequest<ResponseModel>(\n method: HttpMethods,\n url: string,\n data: any,\n requestConfig?: RequestConfigType,\n internalConfig: InternalHttpClientConfig = {},\n ): Promise<HttpResponseModel<ResponseModel>> {\n // noinspection SuspiciousTypeOfGuard\n if (typeof url !== \"string\") {\n throw new Error(FAILURE_MISSING_URL);\n }\n\n // setup automatic CSRF token handling\n if (this.baseOptions.useCsrfProtection && EDIT_METHODS.includes(method)) {\n const [tokenKey, tokenValue] = await this.setupSecurityToken();\n if (tokenValue) {\n if (!internalConfig.headers) {\n internalConfig.headers = {};\n }\n internalConfig.headers[tokenKey] = tokenValue;\n }\n }\n\n try {\n return await this.executeRequest<ResponseModel>(\n method,\n url,\n data,\n requestConfig,\n Object.keys(internalConfig).length ? internalConfig : undefined,\n );\n } catch (e) {\n const clientError = e as ODataClientError;\n\n // automatic CSRF token handling\n if (\n !!this.baseOptions.useCsrfProtection &&\n clientError.status === 403 &&\n !!clientError.headers &&\n clientError.headers[\"x-csrf-token\"] === \"Required\"\n ) {\n // token has expired: reset csrf token & perform the original request again\n this.csrfToken = undefined;\n return this.sendRequest<ResponseModel>(method, url, data, requestConfig);\n }\n\n throw e;\n }\n }\n\n public get<ResponseModel>(\n url: string,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): Promise<HttpResponseModel<ResponseModel>> {\n return this.sendRequest<ResponseModel>(\n HttpMethods.Get,\n url,\n undefined,\n requestConfig,\n getInternalConfigWithJsonHeaders(additionalHeaders, false),\n );\n }\n\n public post<ResponseModel>(\n url: string,\n data: any,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): Promise<HttpResponseModel<ResponseModel>> {\n return this.sendRequest<ResponseModel>(\n HttpMethods.Post,\n url,\n data,\n requestConfig,\n getInternalConfigWithJsonHeaders(additionalHeaders),\n );\n }\n\n public put<ResponseModel>(\n url: string,\n data: any,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): Promise<HttpResponseModel<ResponseModel>> {\n return this.sendRequest<ResponseModel>(\n HttpMethods.Put,\n url,\n data,\n requestConfig,\n getInternalConfigWithJsonHeaders(additionalHeaders),\n );\n }\n\n public patch<ResponseModel>(\n url: string,\n data: any,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): Promise<HttpResponseModel<ResponseModel>> {\n return this.sendRequest<ResponseModel>(\n HttpMethods.Patch,\n url,\n data,\n requestConfig,\n getInternalConfigWithJsonHeaders(additionalHeaders),\n );\n }\n\n private getAdditionalHeaders(additionalHeaders?: Record<string, string>) {\n return additionalHeaders ? { headers: additionalHeaders } : undefined;\n }\n\n public delete(\n url: string,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): Promise<HttpResponseModel<void>> {\n return this.sendRequest<void>(\n HttpMethods.Delete,\n url,\n undefined,\n requestConfig,\n this.getAdditionalHeaders(additionalHeaders),\n );\n }\n\n public getBlob(\n url: string,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): ODataResponse<Blob> {\n return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, {\n ...this.getAdditionalHeaders(additionalHeaders),\n dataType: \"blob\",\n });\n }\n\n public getStream(\n url: string,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): ODataResponse<ReadableStream> {\n return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, {\n ...this.getAdditionalHeaders(additionalHeaders),\n dataType: \"stream\",\n });\n }\n\n public updateBlob(\n url: string,\n data: Blob,\n mimeType: string,\n requestConfig?: RequestConfigType,\n additionalHeaders?: Record<string, string>,\n ): ODataResponse<void | Blob> {\n return this.sendRequest(HttpMethods.Put, url, data, requestConfig, {\n headers: { ...additionalHeaders, Accept: mimeType, \"Content-Type\": mimeType },\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IAEM,UAAU,CACf,GAAW,EACX,IAAU,EACV,QAAgB,EAChB,aAAiC,EACjC,iBAA0C;QAE1C,OAAO,IAAI,CAAC,WAAW,CAAC,yBAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE;YACjE,OAAO,kCAAO,iBAAiB,KAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,GAAE;YAC7E,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;IACL,CAAC;CACF;AAvOD,wCAuOC","sourcesContent":["import { HttpResponseModel, ODataClientError, ODataResponse } from \"@odata2ts/http-client-api\";\r\nimport { ErrorMessageRetriever, retrieveErrorMessage } from \"./ErrorMessageRetriever\";\r\nimport { HttpMethods } from \"./HttpMethods\";\r\n\r\nexport interface BaseHttpClientOptions {\r\n /**\r\n * Enable automatic CSRF token handling.\r\n */\r\n useCsrfProtection?: boolean;\r\n /**\r\n * Specify the URL from which the token is fetched.\r\n * This could be any path to your OData service, since the token is exchanged via HTTP request headers.\r\n * However, it should be a fast response and usually the root URL to the OData service is a good choice.\r\n */\r\n csrfTokenFetchUrl?: string;\r\n}\r\n\r\nexport interface InternalHttpClientConfig {\r\n dataType?: \"json\" | \"blob\" | \"stream\";\r\n /**\r\n * Additional headers set internally by services or HttpClient implementation.\r\n */\r\n headers?: Record<string, string>;\r\n /**\r\n * Very special option needed for FetchClient to not evaluate the response body in certain situations.\r\n */\r\n noBodyEvaluation?: boolean;\r\n}\r\n\r\nexport const DEFAULT_CSRF_TOKEN_KEY = \"x-csrf-token\";\r\n\r\nconst EDIT_METHODS = [HttpMethods.Post, HttpMethods.Put, HttpMethods.Patch, HttpMethods.Delete];\r\nconst FAILURE_MISSING_CSRF_URL =\r\n \"When automatic CSRF token handling is activated, the URL must be supplied via attribute [csrfTokenFetchUrl]!\";\r\nconst FAILURE_MISSING_URL = \"Value for URL must be provided!\";\r\nconst JSON_VALUE = \"application/json\";\r\n\r\nfunction getInternalConfigWithJsonHeaders(\r\n headers?: Record<string, string>,\r\n setContentType: boolean = true,\r\n): InternalHttpClientConfig {\r\n return {\r\n headers: {\r\n Accept: JSON_VALUE,\r\n ...(setContentType ? { \"Content-Type\": JSON_VALUE } : undefined),\r\n ...headers,\r\n },\r\n dataType: \"json\",\r\n };\r\n}\r\n\r\nexport abstract class BaseHttpClient<RequestConfigType> {\r\n private csrfToken: string | undefined;\r\n private csrfTokenKey = DEFAULT_CSRF_TOKEN_KEY;\r\n\r\n protected retrieveErrorMessage: ErrorMessageRetriever = retrieveErrorMessage;\r\n\r\n protected constructor(private baseOptions: BaseHttpClientOptions = { useCsrfProtection: false }) {\r\n if (baseOptions.useCsrfProtection && !baseOptions.csrfTokenFetchUrl?.trim()) {\r\n throw new Error(FAILURE_MISSING_CSRF_URL);\r\n }\r\n }\r\n\r\n /**\r\n * Main function to implement by any extending http client.\r\n * As it name suggests, the request gets executed in this method.\r\n * Additionally, failures should be handled and errors of type <code>HttpClientError</code> should be thrown.\r\n *\r\n * @param method the http method to use\r\n * @param url the URL to use\r\n * @param data data for the request body if any\r\n * @param config request configuration from end user which should override default settings\r\n * @param internalConfig request configuration from base client including additional headers which should override end user configurations\r\n */\r\n protected abstract executeRequest<ResponseModel>(\r\n method: HttpMethods,\r\n url: string,\r\n data: any,\r\n config?: RequestConfigType,\r\n internalConfig?: InternalHttpClientConfig,\r\n ): Promise<HttpResponseModel<ResponseModel>>;\r\n\r\n public getCsrfTokenKey() {\r\n return this.csrfTokenKey;\r\n }\r\n\r\n public setCsrfTokenKey(newKey: string) {\r\n this.csrfTokenKey = newKey || DEFAULT_CSRF_TOKEN_KEY;\r\n }\r\n\r\n public setErrorMessageRetriever(getErrorMsg: ErrorMessageRetriever) {\r\n this.retrieveErrorMessage = getErrorMsg;\r\n }\r\n\r\n protected async setupSecurityToken(): Promise<[string, string | undefined]> {\r\n if (!this.csrfToken) {\r\n this.csrfToken = await this.fetchSecurityToken();\r\n }\r\n return [this.csrfTokenKey, this.csrfToken];\r\n }\r\n\r\n protected async fetchSecurityToken(): Promise<string | undefined> {\r\n const fetchUrl = this.baseOptions!.csrfTokenFetchUrl!;\r\n const response = await this.sendRequest(HttpMethods.Get, fetchUrl, undefined, undefined, {\r\n noBodyEvaluation: true,\r\n headers: { [this.csrfTokenKey]: \"Fetch\", Accept: JSON_VALUE },\r\n });\r\n\r\n return response.headers[this.csrfTokenKey];\r\n }\r\n\r\n /**\r\n * Follows the template pattern.\r\n *\r\n * @param method\r\n * @param url\r\n * @param data\r\n * @param requestConfig\r\n * @param internalConfig\r\n * @private\r\n */\r\n private async sendRequest<ResponseModel>(\r\n method: HttpMethods,\r\n url: string,\r\n data: any,\r\n requestConfig?: RequestConfigType,\r\n internalConfig: InternalHttpClientConfig = {},\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n // noinspection SuspiciousTypeOfGuard\r\n if (typeof url !== \"string\") {\r\n throw new Error(FAILURE_MISSING_URL);\r\n }\r\n\r\n // setup automatic CSRF token handling\r\n if (this.baseOptions.useCsrfProtection && EDIT_METHODS.includes(method)) {\r\n const [tokenKey, tokenValue] = await this.setupSecurityToken();\r\n if (tokenValue) {\r\n if (!internalConfig.headers) {\r\n internalConfig.headers = {};\r\n }\r\n internalConfig.headers[tokenKey] = tokenValue;\r\n }\r\n }\r\n\r\n try {\r\n return await this.executeRequest<ResponseModel>(\r\n method,\r\n url,\r\n data,\r\n requestConfig,\r\n Object.keys(internalConfig).length ? internalConfig : undefined,\r\n );\r\n } catch (e) {\r\n const clientError = e as ODataClientError;\r\n\r\n // automatic CSRF token handling\r\n if (\r\n !!this.baseOptions.useCsrfProtection &&\r\n clientError.status === 403 &&\r\n !!clientError.headers &&\r\n clientError.headers[\"x-csrf-token\"] === \"Required\"\r\n ) {\r\n // token has expired: reset csrf token & perform the original request again\r\n this.csrfToken = undefined;\r\n return this.sendRequest<ResponseModel>(method, url, data, requestConfig);\r\n }\r\n\r\n throw e;\r\n }\r\n }\r\n\r\n public get<ResponseModel>(\r\n url: string,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n return this.sendRequest<ResponseModel>(\r\n HttpMethods.Get,\r\n url,\r\n undefined,\r\n requestConfig,\r\n getInternalConfigWithJsonHeaders(additionalHeaders, false),\r\n );\r\n }\r\n\r\n public post<ResponseModel>(\r\n url: string,\r\n data: any,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n return this.sendRequest<ResponseModel>(\r\n HttpMethods.Post,\r\n url,\r\n data,\r\n requestConfig,\r\n getInternalConfigWithJsonHeaders(additionalHeaders),\r\n );\r\n }\r\n\r\n public put<ResponseModel>(\r\n url: string,\r\n data: any,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n return this.sendRequest<ResponseModel>(\r\n HttpMethods.Put,\r\n url,\r\n data,\r\n requestConfig,\r\n getInternalConfigWithJsonHeaders(additionalHeaders),\r\n );\r\n }\r\n\r\n public patch<ResponseModel>(\r\n url: string,\r\n data: any,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n return this.sendRequest<ResponseModel>(\r\n HttpMethods.Patch,\r\n url,\r\n data,\r\n requestConfig,\r\n getInternalConfigWithJsonHeaders(additionalHeaders),\r\n );\r\n }\r\n\r\n private getAdditionalHeaders(additionalHeaders?: Record<string, string>) {\r\n return additionalHeaders ? { headers: additionalHeaders } : undefined;\r\n }\r\n\r\n public delete(\r\n url: string,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): Promise<HttpResponseModel<void>> {\r\n return this.sendRequest<void>(\r\n HttpMethods.Delete,\r\n url,\r\n undefined,\r\n requestConfig,\r\n this.getAdditionalHeaders(additionalHeaders),\r\n );\r\n }\r\n\r\n public getBlob(\r\n url: string,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): ODataResponse<Blob> {\r\n return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, {\r\n ...this.getAdditionalHeaders(additionalHeaders),\r\n dataType: \"blob\",\r\n });\r\n }\r\n\r\n public getStream(\r\n url: string,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): ODataResponse<ReadableStream> {\r\n return this.sendRequest(HttpMethods.Get, url, undefined, requestConfig, {\r\n ...this.getAdditionalHeaders(additionalHeaders),\r\n dataType: \"stream\",\r\n });\r\n }\r\n\r\n public updateBlob(\r\n url: string,\r\n data: Blob,\r\n mimeType: string,\r\n requestConfig?: RequestConfigType,\r\n additionalHeaders?: Record<string, string>,\r\n ): ODataResponse<void | Blob> {\r\n return this.sendRequest(HttpMethods.Put, url, data, requestConfig, {\r\n headers: { ...additionalHeaders, Accept: mimeType, \"Content-Type\": mimeType },\r\n dataType: \"blob\",\r\n });\r\n }\r\n}\r\n"]}
@@ -1,12 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveErrorMessage = void 0;
1
4
  /**
2
5
  * Retrieves the OData error message from the response (V2 and V4 are supported).
3
6
  * The structure of the error message is specified by OData.
4
7
  *
5
8
  * @param errorResponse
6
9
  */
7
- export const retrieveErrorMessage = (errorResponse) => {
10
+ const retrieveErrorMessage = (errorResponse) => {
8
11
  var _a;
9
12
  const eMsg = (_a = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.error) === null || _a === void 0 ? void 0 : _a.message;
10
13
  return typeof (eMsg === null || eMsg === void 0 ? void 0 : eMsg.value) === "string" ? eMsg.value : eMsg;
11
14
  };
15
+ exports.retrieveErrorMessage = retrieveErrorMessage;
12
16
  //# sourceMappingURL=ErrorMessageRetriever.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorMessageRetriever.js","sourceRoot":"","sources":["../src/ErrorMessageRetriever.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0B,CAAC,aAAkB,EAAsB,EAAE;;IACpG,MAAM,IAAI,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,KAAK,0CAAE,OAAO,CAAC;IAC3C,OAAO,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAA,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC,CAAC","sourcesContent":["/**\n * Function type used to retrieve the error message from the response payload.\n *\n * @return error message or <code>undefined</code> if retrieval failed / had no outcome\n */\nexport type ErrorMessageRetriever = (errorResponse: any) => string | undefined;\n\n/**\n * Retrieves the OData error message from the response (V2 and V4 are supported).\n * The structure of the error message is specified by OData.\n *\n * @param errorResponse\n */\nexport const retrieveErrorMessage: ErrorMessageRetriever = (errorResponse: any): string | undefined => {\n const eMsg = errorResponse?.error?.message;\n return typeof eMsg?.value === \"string\" ? eMsg.value : eMsg;\n};\n"]}
1
+ {"version":3,"file":"ErrorMessageRetriever.js","sourceRoot":"","sources":["../src/ErrorMessageRetriever.ts"],"names":[],"mappings":";;;AAOA;;;;;GAKG;AACI,MAAM,oBAAoB,GAA0B,CAAC,aAAkB,EAAsB,EAAE;;IACpG,MAAM,IAAI,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,KAAK,0CAAE,OAAO,CAAC;IAC3C,OAAO,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAA,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC,CAAC;AAHW,QAAA,oBAAoB,wBAG/B","sourcesContent":["/**\n * Function type used to retrieve the error message from the response payload.\n *\n * @return error message or <code>undefined</code> if retrieval failed / had no outcome\n */\nexport type ErrorMessageRetriever = (errorResponse: any) => string | undefined;\n\n/**\n * Retrieves the OData error message from the response (V2 and V4 are supported).\n * The structure of the error message is specified by OData.\n *\n * @param errorResponse\n */\nexport const retrieveErrorMessage: ErrorMessageRetriever = (errorResponse: any): string | undefined => {\n const eMsg = errorResponse?.error?.message;\n return typeof eMsg?.value === \"string\" ? eMsg.value : eMsg;\n};\n"]}
@@ -1,9 +1,12 @@
1
- export var HttpMethods;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpMethods = void 0;
4
+ var HttpMethods;
2
5
  (function (HttpMethods) {
3
6
  HttpMethods["Get"] = "GET";
4
7
  HttpMethods["Post"] = "POST";
5
8
  HttpMethods["Put"] = "PUT";
6
9
  HttpMethods["Patch"] = "PATCH";
7
10
  HttpMethods["Delete"] = "DELETE";
8
- })(HttpMethods || (HttpMethods = {}));
11
+ })(HttpMethods = exports.HttpMethods || (exports.HttpMethods = {}));
9
12
  //# sourceMappingURL=HttpMethods.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HttpMethods.js","sourceRoot":"","sources":["../src/HttpMethods.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,0BAAW,CAAA;IACX,8BAAe,CAAA;IACf,gCAAiB,CAAA;AACnB,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB","sourcesContent":["export enum HttpMethods {\n Get = \"GET\",\n Post = \"POST\",\n Put = \"PUT\",\n Patch = \"PATCH\",\n Delete = \"DELETE\",\n}\n"]}
1
+ {"version":3,"file":"HttpMethods.js","sourceRoot":"","sources":["../src/HttpMethods.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,0BAAW,CAAA;IACX,8BAAe,CAAA;IACf,gCAAiB,CAAA;AACnB,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB","sourcesContent":["export enum HttpMethods {\n Get = \"GET\",\n Post = \"POST\",\n Put = \"PUT\",\n Patch = \"PATCH\",\n Delete = \"DELETE\",\n}\n"]}
package/lib/index.js CHANGED
@@ -1,4 +1,10 @@
1
- export * from "./ErrorMessageRetriever";
2
- export { BaseHttpClient } from "./BaseHttpClient";
3
- export { HttpMethods } from "./HttpMethods";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpMethods = exports.BaseHttpClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./ErrorMessageRetriever"), exports);
6
+ var BaseHttpClient_1 = require("./BaseHttpClient");
7
+ Object.defineProperty(exports, "BaseHttpClient", { enumerable: true, get: function () { return BaseHttpClient_1.BaseHttpClient; } });
8
+ var HttpMethods_1 = require("./HttpMethods");
9
+ Object.defineProperty(exports, "HttpMethods", { enumerable: true, get: function () { return HttpMethods_1.HttpMethods; } });
4
10
  //# 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,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAmD,MAAM,kBAAkB,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export * from \"./ErrorMessageRetriever\";\nexport { BaseHttpClient, BaseHttpClientOptions, InternalHttpClientConfig } from \"./BaseHttpClient\";\nexport { HttpMethods } from \"./HttpMethods\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,kEAAwC;AACxC,mDAAmG;AAA1F,gHAAA,cAAc,OAAA;AACvB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA","sourcesContent":["export * from \"./ErrorMessageRetriever\";\r\nexport { BaseHttpClient, BaseHttpClientOptions, InternalHttpClientConfig } from \"./BaseHttpClient\";\r\nexport { HttpMethods } from \"./HttpMethods\";\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-base",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Core functionality for odata2ts HTTP clients",
5
5
  "keywords": [
6
6
  "http client",
@@ -11,7 +11,7 @@
11
11
  "repository": "git@github.com:odata2ts/http-client.git",
12
12
  "license": "MIT",
13
13
  "author": "texttechne",
14
- "type": "module",
14
+ "type": "commonjs",
15
15
  "main": "./lib/index.js",
16
16
  "types": "./lib/index.d.ts",
17
17
  "files": [
@@ -28,7 +28,7 @@
28
28
  "test": "vitest run ./test"
29
29
  },
30
30
  "dependencies": {
31
- "@odata2ts/http-client-api": "^0.6.0"
31
+ "@odata2ts/http-client-api": "^0.6.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@odata2ts/odata-core": "^0.3.7",
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "6a0905bd7f201a5c91d83a9319c2a0325a017651"
42
+ "gitHead": "20d77b211d6c7a44e7f1d14e9b63be531bb30e87"
43
43
  }