@odata2ts/http-client-jquery 0.7.0 → 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 CHANGED
@@ -3,6 +3,26 @@
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-jquery@0.6.0...@odata2ts/http-client-jquery@0.8.0) (2023-09-13)
7
+
8
+ ### Code Refactoring
9
+
10
+ * expand additionalHeaders param to internalConfig ([#15](https://github.com/odata2ts/http-client/issues/15)) ([7fe1d73](https://github.com/odata2ts/http-client/commit/7fe1d73a7436f64b84a060bd1dbf9e121ef901ce))
11
+
12
+ ### Features
13
+
14
+ * **jquery:** allow for query params ([afd13a8](https://github.com/odata2ts/http-client/commit/afd13a862dc07485c0f619a3e39521f7ce6fc65e))
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * additional headers are now part of the config parameter
19
+
20
+ * fix: don't lose configuration when CSRF token is active
21
+
22
+ * add new option which prevents FetchClient from evaluating response body (not needed for fetching csrf tokens & makes trouble with SAP's mockServer)
23
+
24
+ * fix: add headers for content-type and accept for main methods
25
+
6
26
  # [0.7.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery@0.6.0...@odata2ts/http-client-jquery@0.7.0) (2023-09-05)
7
27
 
8
28
  ### Features
@@ -38,7 +58,9 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
38
58
  ### Features
39
59
 
40
60
  * **jquery:** copy over jquery-client and rename ([#3](https://github.com/odata2ts/http-client/issues/3)) ([55deb6c](https://github.com/odata2ts/http-client/commit/55deb6c75159bfc46b0ae87cb3c0ec3afda9508e))
61
+
41
62
  * switch to http-client-api ([52d1b86](https://github.com/odata2ts/http-client/commit/52d1b868ee82dbaf45486da6b22fdcf4c773dfb8))
63
+
42
64
  * switch to http-client-api ([5a6da23](https://github.com/odata2ts/http-client/commit/5a6da23053b3ea5adb866bb7e30b469f1b8ed260))
43
65
 
44
66
  ## [0.3.1](https://github.com/odata2ts/odata2ts/compare/@odata2ts/jquery-odata-client@0.3.0...@odata2ts/jquery-odata-client@0.3.1) (2023-05-02)
package/README.md CHANGED
@@ -1,46 +1,46 @@
1
- [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-jquery?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-jquery)
2
-
3
- # JQuery HTTP Client
4
-
5
- [odata2ts](https://github.com/odata2ts/odata2ts) compatible odata client based on [JQuery](https://jquery.com/)
6
- and its [ajax method](https://api.jquery.com/Jquery.ajax/).
7
-
8
- JQuery is used by this client but not installed (declared as peer dependency).
9
- The existing JQuery instance must be provided when initializing the client.
10
-
11
- The whole client is meant to support usage of `odata2ts` in UI5 apps, which use Jquery for HTTP communication.
12
-
13
- ## Installation
14
-
15
- Install package `@odata2ts/http-client-jquery` as runtime dependency:
16
-
17
- ```bash
18
- npm install --save @odata2ts/http-client-jquery
19
- ```
20
-
21
- JQuery is a peer-dependency of this package, so it's not contained in or installed through this package.
22
-
23
- ## Documentation
24
-
25
- [JQuery Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client/jquery)
26
-
27
- Main documentation for the odata2ts eco system:
28
- [https://odata2ts.github.io](https://odata2ts.github.io/)
29
-
30
- ## Tests
31
-
32
- See folder [test](https://github.com/odata2ts/http-client/tree/main/packages/jquery/test)
33
- for unit tests.
34
-
35
- ## Support, Feedback, Contributing
36
-
37
- This project is open to feature requests, suggestions, bug reports, usage questions etc.
38
- via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
39
-
40
- Contributions and feedback are encouraged and always welcome.
41
-
42
- See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
43
-
44
- ## License
45
-
46
- MIT - see [License](./LICENSE).
1
+ [![npm (scoped)](https://img.shields.io/npm/v/@odata2ts/http-client-jquery?style=for-the-badge)](https://www.npmjs.com/package/@odata2ts/http-client-jquery)
2
+
3
+ # JQuery HTTP Client
4
+
5
+ [odata2ts](https://github.com/odata2ts/odata2ts) compatible odata client based on [JQuery](https://jquery.com/)
6
+ and its [ajax method](https://api.jquery.com/Jquery.ajax/).
7
+
8
+ JQuery is used by this client but not installed (declared as peer dependency).
9
+ The existing JQuery instance must be provided when initializing the client.
10
+
11
+ The whole client is meant to support usage of `odata2ts` in UI5 apps, which use Jquery for HTTP communication.
12
+
13
+ ## Installation
14
+
15
+ Install package `@odata2ts/http-client-jquery` as runtime dependency:
16
+
17
+ ```bash
18
+ npm install --save @odata2ts/http-client-jquery
19
+ ```
20
+
21
+ JQuery is a peer-dependency of this package, so it's not contained in or installed through this package.
22
+
23
+ ## Documentation
24
+
25
+ [JQuery Client Documentation](https://odata2ts.github.io/docs/odata-client/http-client/jquery)
26
+
27
+ Main documentation for the odata2ts eco system:
28
+ [https://odata2ts.github.io](https://odata2ts.github.io/)
29
+
30
+ ## Tests
31
+
32
+ See folder [test](https://github.com/odata2ts/http-client/tree/main/packages/jquery/test)
33
+ for unit tests.
34
+
35
+ ## Support, Feedback, Contributing
36
+
37
+ This project is open to feature requests, suggestions, bug reports, usage questions etc.
38
+ via [GitHub issues](https://github.com/odata2ts/odata2ts/issues).
39
+
40
+ Contributions and feedback are encouraged and always welcome.
41
+
42
+ See the [contribution guidelines](https://github.com/odata2ts/odata2ts/blob/main/CONTRIBUTING.md) for further information.
43
+
44
+ ## License
45
+
46
+ MIT - see [License](./LICENSE).
@@ -1,5 +1,5 @@
1
1
  /// <reference types="jquery/jquerystatic" />
2
- import { HttpResponseModel } from "@odata2ts/http-client-api";
2
+ import { HttpResponseModel, InternalHttpClientConfig } from "@odata2ts/http-client-api";
3
3
  import { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from "@odata2ts/http-client-base";
4
4
  import { AjaxRequestConfig } from "./AjaxRequestConfig";
5
5
  import jqXHR = JQuery.jqXHR;
@@ -7,11 +7,9 @@ export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
7
7
  export interface ClientOptions extends BaseHttpClientOptions {
8
8
  }
9
9
  export declare class JQueryClient extends BaseHttpClient<AjaxRequestConfig> {
10
- private clientOptions?;
11
10
  private readonly client;
12
11
  private readonly config;
13
- constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, clientOptions?: ClientOptions | undefined);
12
+ constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, clientOptions?: ClientOptions);
14
13
  protected mapHeaders(jqXhr: jqXHR): Record<string, string>;
15
- protected addHeaderToRequestConfig(headers: Record<string, string>, config?: AjaxRequestConfig): AjaxRequestConfig;
16
- protected executeRequest<ResponseModel>(method: HttpMethods, url: string, data: any, requestConfig?: JQuery.AjaxSettings): Promise<HttpResponseModel<ResponseModel>>;
14
+ protected executeRequest<ResponseModel>(method: HttpMethods, url: string, data: any, requestConfig?: JQuery.AjaxSettings, internalConfig?: InternalHttpClientConfig): Promise<HttpResponseModel<ResponseModel>>;
17
15
  }
@@ -10,7 +10,6 @@ exports.DEFAULT_ERROR_MESSAGE = "No error message!";
10
10
  class JQueryClient extends http_client_base_1.BaseHttpClient {
11
11
  constructor(jquery, config, clientOptions) {
12
12
  super(clientOptions);
13
- this.clientOptions = clientOptions;
14
13
  this.client = jquery;
15
14
  this.config = (0, AjaxRequestConfig_1.getDefaultConfig)(config);
16
15
  }
@@ -29,12 +28,10 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
29
28
  return collector;
30
29
  }, {});
31
30
  }
32
- addHeaderToRequestConfig(headers, config) {
33
- return (0, AjaxRequestConfig_1.mergeAjaxConfig)({ headers }, config);
34
- }
35
- executeRequest(method, url, data, requestConfig) {
31
+ executeRequest(method, url, data, requestConfig, internalConfig = {}) {
36
32
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
37
- const _a = (0, AjaxRequestConfig_1.mergeAjaxConfig)(this.config, requestConfig), { params } = _a, mergedConfig = tslib_1.__rest(_a, ["params"]);
33
+ const withInternalConfig = (0, AjaxRequestConfig_1.mergeAjaxConfig)({ headers: internalConfig.headers }, requestConfig);
34
+ const _a = (0, AjaxRequestConfig_1.mergeAjaxConfig)(this.config, withInternalConfig), { params } = _a, mergedConfig = tslib_1.__rest(_a, ["params"]);
38
35
  mergedConfig.method = method;
39
36
  mergedConfig.data = JSON.stringify(data);
40
37
  mergedConfig.url = url;
@@ -1 +1 @@
1
- {"version":3,"file":"JQueryClient.js","sourceRoot":"","sources":["../src/JQueryClient.ts"],"names":[],"mappings":";AAAA,8EAA8E;;;;AAG9E,iEAAgG;AAEhG,2DAA2F;AAC3F,2DAAwD;AAI3C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAIzD,MAAa,YAAa,SAAQ,iCAAiC;IAIjE,YAAY,MAAoB,EAAE,MAA0B,EAAU,aAA6B;QACjG,KAAK,CAAC,aAAa,CAAC,CAAC;QAD+C,kBAAa,GAAb,aAAa,CAAgB;QAEjG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAA,oCAAgB,EAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAES,UAAU,CAAC,KAAY;QAC/B,OAAO,KAAK;aACT,qBAAqB,EAAE;aACvB,IAAI,EAAE;aACN,KAAK,CAAC,SAAS,CAAC;aAChB,MAAM,CAAC,CAAC,SAAiC,EAAE,IAAY,EAAE,EAAE;YAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE/B,IAAI,MAAM,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;aACzC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACX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kB,EAAE,WAAmB,EAAE,EAAE;;wBACtE,MAAM,eAAe,GAAG,IAAI,CAAC,oBAAoB,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,CAAC,CAAC;wBACvE,MAAM,OAAO,GAAG,MAAA,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,WAAW,mCAAI,6BAAqB,CAAC;wBACxE,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,qCAAqC,GAAG,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC;wBACzG,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;wBAC/C,MAAM,CAAC,IAAI,qCAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;oBACxG,CAAC,IACD,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAtED,oCAsEC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/JQueryStatic.d.ts\" />\r\n\r\nimport { HttpResponseModel } from \"@odata2ts/http-client-api\";\r\nimport { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from \"@odata2ts/http-client-base\";\r\n\r\nimport { AjaxRequestConfig, getDefaultConfig, mergeAjaxConfig } from \"./AjaxRequestConfig\";\r\nimport { JQueryClientError } from \"./JQueryClientError\";\r\n\r\nimport jqXHR = JQuery.jqXHR;\r\n\r\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\r\n\r\nexport interface ClientOptions extends BaseHttpClientOptions {}\r\n\r\nexport class JQueryClient extends BaseHttpClient<AjaxRequestConfig> {\r\n private readonly client: JQueryStatic;\r\n private readonly config: JQuery.AjaxSettings;\r\n\r\n constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, private clientOptions?: ClientOptions) {\r\n super(clientOptions);\r\n this.client = jquery;\r\n this.config = getDefaultConfig(config);\r\n }\r\n\r\n protected mapHeaders(jqXhr: jqXHR): Record<string, string> {\r\n return jqXhr\r\n .getAllResponseHeaders()\r\n .trim()\r\n .split(/[\\r\\n]+/)\r\n .reduce((collector: Record<string, string>, line: string) => {\r\n const parts = line.split(\": \");\r\n const header = parts.shift();\r\n const value = parts.join(\": \");\r\n\r\n if (header) {\r\n collector[header.toLowerCase()] = value;\r\n }\r\n return collector;\r\n }, {});\r\n }\r\n\r\n protected addHeaderToRequestConfig(headers: Record<string, string>, config?: AjaxRequestConfig): AjaxRequestConfig {\r\n return mergeAjaxConfig({ headers }, 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?: JQuery.AjaxSettings\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n const { params, ...mergedConfig } = mergeAjaxConfig(this.config, requestConfig);\r\n mergedConfig.method = method;\r\n mergedConfig.data = JSON.stringify(data);\r\n mergedConfig.url = url;\r\n if (params && Object.values(params).length) {\r\n mergedConfig.url +=\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 return new Promise((resolve, reject) => {\r\n this.client.ajax({\r\n ...mergedConfig,\r\n success: (response: any, textStatus: string, jqXHR: JQuery.jqXHR) => {\r\n resolve({\r\n status: jqXHR.status,\r\n statusText: jqXHR.statusText,\r\n headers: this.mapHeaders(jqXHR),\r\n data: response,\r\n });\r\n },\r\n error: (jqXHR: JQuery.jqXHR, textStatus: string, thrownError: string) => {\r\n const responseMessage = this.retrieveErrorMessage(jqXHR?.responseJSON);\r\n const failMsg = responseMessage ?? thrownError ?? DEFAULT_ERROR_MESSAGE;\r\n const errorMessage = responseMessage ? \"OData server responded with error: \" + responseMessage : failMsg;\r\n const responseHeaders = this.mapHeaders(jqXHR);\r\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));\r\n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AG,eAAe,CAAC,CAAC,CAAC,qCAAqC,GAAG,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC;wBACzG,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;wBAC/C,MAAM,CAAC,IAAI,qCAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;oBACxG,CAAC,IACD,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AApED,oCAoEC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/JQueryStatic.d.ts\" />\r\n\r\nimport { HttpResponseModel, InternalHttpClientConfig } from \"@odata2ts/http-client-api\";\r\nimport { BaseHttpClient, BaseHttpClientOptions, HttpMethods } from \"@odata2ts/http-client-base\";\r\n\r\nimport { AjaxRequestConfig, getDefaultConfig, mergeAjaxConfig } from \"./AjaxRequestConfig\";\r\nimport { JQueryClientError } from \"./JQueryClientError\";\r\n\r\nimport jqXHR = JQuery.jqXHR;\r\n\r\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\r\n\r\nexport interface ClientOptions extends BaseHttpClientOptions {}\r\n\r\nexport class JQueryClient extends BaseHttpClient<AjaxRequestConfig> {\r\n private readonly client: JQueryStatic;\r\n private readonly config: JQuery.AjaxSettings;\r\n\r\n constructor(jquery: JQueryStatic, config?: AjaxRequestConfig, clientOptions?: ClientOptions) {\r\n super(clientOptions);\r\n this.client = jquery;\r\n this.config = getDefaultConfig(config);\r\n }\r\n\r\n protected mapHeaders(jqXhr: jqXHR): Record<string, string> {\r\n return jqXhr\r\n .getAllResponseHeaders()\r\n .trim()\r\n .split(/[\\r\\n]+/)\r\n .reduce((collector: Record<string, string>, line: string) => {\r\n const parts = line.split(\": \");\r\n const header = parts.shift();\r\n const value = parts.join(\": \");\r\n\r\n if (header) {\r\n collector[header.toLowerCase()] = value;\r\n }\r\n return collector;\r\n }, {});\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?: JQuery.AjaxSettings,\r\n internalConfig: InternalHttpClientConfig = {}\r\n ): Promise<HttpResponseModel<ResponseModel>> {\r\n const withInternalConfig = mergeAjaxConfig({ headers: internalConfig.headers }, requestConfig);\r\n const { params, ...mergedConfig } = mergeAjaxConfig(this.config, withInternalConfig);\r\n mergedConfig.method = method;\r\n mergedConfig.data = JSON.stringify(data);\r\n mergedConfig.url = url;\r\n if (params && Object.values(params).length) {\r\n mergedConfig.url +=\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 return new Promise((resolve, reject) => {\r\n this.client.ajax({\r\n ...mergedConfig,\r\n success: (response: any, textStatus: string, jqXHR: JQuery.jqXHR) => {\r\n resolve({\r\n status: jqXHR.status,\r\n statusText: jqXHR.statusText,\r\n headers: this.mapHeaders(jqXHR),\r\n data: response,\r\n });\r\n },\r\n error: (jqXHR: JQuery.jqXHR, textStatus: string, thrownError: string) => {\r\n const responseMessage = this.retrieveErrorMessage(jqXHR?.responseJSON);\r\n const failMsg = responseMessage ?? thrownError ?? DEFAULT_ERROR_MESSAGE;\r\n const errorMessage = responseMessage ? \"OData server responded with error: \" + responseMessage : failMsg;\r\n const responseHeaders = this.mapHeaders(jqXHR);\r\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));\r\n },\r\n });\r\n });\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"JQueryClientError.js","sourceRoot":"","sources":["../src/JQueryClientError.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;AAItE,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACE,GAAW,EACK,MAA0B,EAC1B,OAA2C,EAC3C,KAAwB,EACxB,KAAmB;QAEnC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAoC;QAC3C,UAAK,GAAL,KAAK,CAAmB;QACxB,UAAK,GAAL,KAAK,CAAc;QAInC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,8CAYC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/misc.d.ts\" />\n\nimport { ODataClientError } from \"@odata2ts/http-client-api\";\n\nexport class JQueryClientError extends Error implements ODataClientError {\n constructor(\n msg: string,\n public readonly status: number | undefined,\n public readonly headers: Record<string, string> | undefined,\n public readonly cause: Error | undefined,\n public readonly jqXHR: JQuery.jqXHR\n ) {\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\n super(msg, { cause });\n this.name = this.constructor.name;\n }\n}\n"]}
1
+ {"version":3,"file":"JQueryClientError.js","sourceRoot":"","sources":["../src/JQueryClientError.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;AAItE,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YACE,GAAW,EACK,MAA0B,EAC1B,OAA2C,EAC3C,KAAwB,EACxB,KAAmB;QAEnC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAoC;QAC3C,UAAK,GAAL,KAAK,CAAmB;QACxB,UAAK,GAAL,KAAK,CAAc;QAInC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,8CAYC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/misc.d.ts\" />\r\n\r\nimport { ODataClientError } from \"@odata2ts/http-client-api\";\r\n\r\nexport class JQueryClientError extends Error implements ODataClientError {\r\n constructor(\r\n msg: string,\r\n public readonly status: number | undefined,\r\n public readonly headers: Record<string, string> | undefined,\r\n public readonly cause: Error | undefined,\r\n public readonly jqXHR: JQuery.jqXHR\r\n ) {\r\n // @ts-ignore: fetch requires lib \"dom\" or \"webworker\", but then the \"cause\" property becomes unknown to TS\r\n super(msg, { cause });\r\n this.name = this.constructor.name;\r\n }\r\n}\r\n"]}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AACA,yDAA+B;AAC/B,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","sourcesContent":["export { AjaxRequestConfig } from \"./AjaxRequestConfig\";\nexport * from \"./JQueryClient\";\nexport { JQueryClientError } from \"./JQueryClientError\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AACA,yDAA+B;AAC/B,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA","sourcesContent":["export { AjaxRequestConfig } from \"./AjaxRequestConfig\";\r\nexport * from \"./JQueryClient\";\r\nexport { JQueryClientError } from \"./JQueryClientError\";\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-jquery",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,7 +35,7 @@
35
35
  "jquery": ">1.0"
36
36
  },
37
37
  "dependencies": {
38
- "@odata2ts/http-client-base": "^0.3.0"
38
+ "@odata2ts/http-client-base": "^0.4.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jest": "^27.4.1",
@@ -50,5 +50,5 @@
50
50
  "typescript": "5.0.4"
51
51
  },
52
52
  "types": "./lib/index.d.ts",
53
- "gitHead": "ed6b01821c2dc161f05144e3b4d8f8d899f954ae"
53
+ "gitHead": "67c7fc10f25461c33baf4e35694a457a03b81b78"
54
54
  }