@odata2ts/http-client-jquery 0.12.0 → 0.13.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,58 +3,54 @@
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
- ### Dependencies
7
-
8
- * The following workspace dependencies were updated
9
- * dependencies
10
- * @odata2ts/http-client-base bumped from ^0.5.5 to ^0.5.6
11
-
12
- ## [0.12.0](https://github.com/odata2ts/http-client/compare/@odata2ts/jquery-v0.11.1...@odata2ts/jquery-v0.12.0) (2026-07-31)
6
+ ## [0.13.0](https://github.com/odata2ts/http-client/compare/@odata2ts/http-client-jquery-v0.12.0...@odata2ts/http-client-jquery-v0.13.0) (2026-08-02)
13
7
 
14
8
 
15
9
  ### ⚠ BREAKING CHANGES
16
10
 
17
- * **jquery:** AjaxRequestConfig becomes JQueryRequestConfig
18
- * switch to ESM tends to break stuff
19
- * additional headers are now part of the config parameter
20
- * **jquery:** removed default accept & content-type headers as well as `dataType=json`; removed merge & retrieveBigNumbersAsString methods (base-lib); all of these settings can now be configured per operation via the `additionalHeaders` option.
11
+ * the trailing constructor parameters of JQueryClientError are optional now, as they already are for AxiosClientError and FetchClientError. Reading error.jqXHR therefore yields JQuery.jqXHR | undefined and needs a check under strict TypeScript.
21
12
 
22
13
  ### Features
23
14
 
24
- * 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))
25
- * blob and stream support ([#12](https://github.com/odata2ts/http-client/issues/12)) ([ae6f062](https://github.com/odata2ts/http-client/commit/ae6f062371a0ad11707fa3f9edff9571998edb5b))
26
- * conventionalize client errors ([#5](https://github.com/odata2ts/http-client/issues/5)) ([a8e8912](https://github.com/odata2ts/http-client/commit/a8e89125eeda47436d48507d6a71efc90953f878))
27
- * create blob request ([#28](https://github.com/odata2ts/http-client/issues/28)) ([4cc238d](https://github.com/odata2ts/http-client/commit/4cc238d3fbe07c09d56732b4b12d0b1b875a3ef5))
28
- * **jquery:** allow for query params ([afd13a8](https://github.com/odata2ts/http-client/commit/afd13a862dc07485c0f619a3e39521f7ce6fc65e))
29
- * **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))
30
- * switch to http-client-api ([52d1b86](https://github.com/odata2ts/http-client/commit/52d1b868ee82dbaf45486da6b22fdcf4c773dfb8))
31
- * switch to http-client-api ([5a6da23](https://github.com/odata2ts/http-client/commit/5a6da23053b3ea5adb866bb7e30b469f1b8ed260))
15
+ * upload binary data as a stream ([#44](https://github.com/odata2ts/http-client/issues/44)) ([ccee77a](https://github.com/odata2ts/http-client/commit/ccee77a7f6ad13bcf147485b2b9b91ac3a899fc2))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **http-client-jquery:** send binary data as it is ([#37](https://github.com/odata2ts/http-client/issues/37)) ([0615acc](https://github.com/odata2ts/http-client/commit/0615acc56ad183df7d93aaa9f55e5ee48a6db26a))
21
+ * report a refused or absent stream honestly ([#45](https://github.com/odata2ts/http-client/issues/45)) ([43be086](https://github.com/odata2ts/http-client/commit/43be086884c59cff45ae596b848e72a55b59ac83))
22
+
23
+
24
+ ### Dependencies
25
+
26
+ * The following workspace dependencies were updated
27
+ * dependencies
28
+ * @odata2ts/http-client-base bumped from ^0.5.7 to ^0.5.8
29
+
30
+ ## [0.12.0](https://github.com/odata2ts/http-client/compare/@odata2ts/jquery-v0.11.1...@odata2ts/jquery-v0.12.0) (2026-07-31)
32
31
 
33
32
 
34
33
  ### Bug Fixes
35
34
 
36
- * 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))
37
- * always build all packages before release ([#26](https://github.com/odata2ts/http-client/issues/26)) ([a316f6c](https://github.com/odata2ts/http-client/commit/a316f6ce54c4360c8d6f87799ba6fd9c53bff52c))
38
- * delete requests with Accept json header ([ea1b06d](https://github.com/odata2ts/http-client/commit/ea1b06d509b490e1e899e96a62a10eac3f65da8e))
39
- * deploy with code ([#25](https://github.com/odata2ts/http-client/issues/25)) ([3e0e78c](https://github.com/odata2ts/http-client/commit/3e0e78cd2e0b0c3215bc0ed97dd62c75d8b6c5ea))
40
- * **http-client-jquery:** stop pinning an external image's exact byte size ([fb3fece](https://github.com/odata2ts/http-client/commit/fb3fece1b5d39459acdd69d0d3c37798641a2288))
41
35
  * send a plain text request body as it is ([#35](https://github.com/odata2ts/http-client/issues/35)) ([2d44aff](https://github.com/odata2ts/http-client/commit/2d44aff43d4804070d53ea84dae271365bab4cf8))
42
36
  * update typescript to 6.0.3 and migrate to nodenext resolution ([f713098](https://github.com/odata2ts/http-client/commit/f71309861d7a58b7f0fb65cf8395f0262a932a9f))
37
+ * **http-client-jquery:** stop pinning an external image's exact byte size ([fb3fece](https://github.com/odata2ts/http-client/commit/fb3fece1b5d39459acdd69d0d3c37798641a2288))
43
38
 
44
39
 
45
- ### Code Refactoring
40
+ ### Dependencies
46
41
 
47
- * expand additionalHeaders param to internalConfig ([#15](https://github.com/odata2ts/http-client/issues/15)) ([7fe1d73](https://github.com/odata2ts/http-client/commit/7fe1d73a7436f64b84a060bd1dbf9e121ef901ce))
48
- * **jquery:** benefit from api additions & improve config handling ([d08e4f3](https://github.com/odata2ts/http-client/commit/d08e4f30140d4c1d8968c71b89c9eb009ab44a93))
49
- * **jquery:** remove default headers ([3106d97](https://github.com/odata2ts/http-client/commit/3106d9768765e7cc228097ed1270439d47ff0e0c))
50
- * switch to vitest & ESM ([#18](https://github.com/odata2ts/http-client/issues/18)) ([748558f](https://github.com/odata2ts/http-client/commit/748558f1e3f699085ade1058b1459c843f60994f))
42
+ * The following workspace dependencies were updated
43
+ * dependencies
44
+ * @odata2ts/http-client-base bumped from ^0.5.6 to ^0.5.7
45
+
46
+ ## [0.11.1](https://github.com/odata2ts/http-client/compare/@odata2ts/jquery-v0.11.0...@odata2ts/jquery-v0.11.1) (2026-06-10)
51
47
 
52
48
 
53
49
  ### Dependencies
54
50
 
55
51
  * The following workspace dependencies were updated
56
52
  * dependencies
57
- * @odata2ts/http-client-base bumped from ^0.5.6 to ^0.5.7
53
+ * @odata2ts/http-client-base bumped from ^0.5.5 to ^0.5.6
58
54
 
59
55
  ## [0.11.0](https://github.com/odata2ts/http-client/compare/@odata2ts/jquery-v0.10.0...@odata2ts/jquery-v0.11.0) (2026-06-10)
60
56
 
package/README.md CHANGED
@@ -10,6 +10,11 @@ The existing JQuery instance must be provided when initializing the client.
10
10
 
11
11
  The whole client is meant to support usage of `odata2ts` in UI5 apps, which use Jquery for HTTP communication.
12
12
 
13
+ It does **not** support **streaming** in either direction (`getStream`, `createStream` / `updateStream`):
14
+ XmlHttpRequest, which jQuery's ajax method builds upon, has no streaming API at all. Those calls are
15
+ refused with an error - use the [Fetch Client](https://www.npmjs.com/package/@odata2ts/http-client-fetch)
16
+ for streams. Binary data as `Blob` works (`getBlob` / `createBlob` / `updateBlob`).
17
+
13
18
  ## Installation
14
19
 
15
20
  Install package `@odata2ts/http-client-jquery` as runtime dependency:
@@ -3,10 +3,11 @@ import { BaseHttpClient, BaseRequestConfig } from "@odata2ts/http-client-base";
3
3
  import { JQueryRequestConfig } from "./JQueryRequestConfig";
4
4
  import jqXHR = JQuery.jqXHR;
5
5
  export declare const DEFAULT_ERROR_MESSAGE = "No error message!";
6
+ export declare const FAILURE_STREAM_UNSUPPORTED: string;
6
7
  export declare class JQueryClient extends BaseHttpClient<JQueryRequestConfig> implements ODataHttpClient<JQueryRequestConfig> {
7
8
  private readonly client;
8
9
  private readonly config;
9
10
  constructor(jquery: JQueryStatic, config?: JQueryRequestConfig, clientOptions?: ODataHttpClientOptions);
10
11
  protected mapHeaders(jqXhr: jqXHR): Record<string, string>;
11
- protected executeRequest<ResponseModel>(method: ODataHttpMethods, url: string, data: any, requestConfig?: JQueryRequestConfig, internalConfig?: BaseRequestConfig): Promise<HttpResponseModel<ResponseModel>>;
12
+ protected executeRequest<ResponseModel>(method: ODataHttpMethods, url: string, data: any, requestConfig: JQueryRequestConfig | undefined, internalConfig: BaseRequestConfig): Promise<HttpResponseModel<ResponseModel>>;
12
13
  }
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  /// <reference path="../../../node_modules/@types/jquery/JQueryStatic.d.ts" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.JQueryClient = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
+ exports.JQueryClient = exports.FAILURE_STREAM_UNSUPPORTED = exports.DEFAULT_ERROR_MESSAGE = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const http_client_base_1 = require("@odata2ts/http-client-base");
7
7
  const JQueryClientError_1 = require("./JQueryClientError");
8
8
  const JQueryRequestConfig_1 = require("./JQueryRequestConfig");
9
9
  exports.DEFAULT_ERROR_MESSAGE = "No error message!";
10
+ exports.FAILURE_STREAM_UNSUPPORTED = "Streaming is not supported by the JqueryClient! XmlHttpRequest, which jQuery's ajax method builds " +
11
+ "upon, has no streaming API at all - neither for reading a response nor for sending a request body. " +
12
+ "Use the FetchClient for streams.";
10
13
  class JQueryClient extends http_client_base_1.BaseHttpClient {
11
14
  constructor(jquery, config, clientOptions) {
12
15
  super(clientOptions);
@@ -28,14 +31,15 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
28
31
  return collector;
29
32
  }, {});
30
33
  }
31
- executeRequest(method_1, url_1, data_1, requestConfig_1) {
32
- return tslib_1.__awaiter(this, arguments, void 0, function* (method, url, data, requestConfig, internalConfig = {}) {
34
+ executeRequest(method, url, data, requestConfig, internalConfig) {
35
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
33
36
  const { headers } = internalConfig;
34
37
  const _a = (0, JQueryRequestConfig_1.mergeConfigs)(this.config, (0, JQueryRequestConfig_1.mergeConfigs)({ headers }, requestConfig)), { params } = _a, mergedConfig = tslib_1.__rest(_a, ["params"]);
38
+ const isBinary = internalConfig.dataType === "blob";
35
39
  // set core inputs for request
36
40
  const resultConfig = Object.assign(Object.assign({}, mergedConfig), { method,
37
- // only an explicitly plain text body is passed through as it is
38
- data: this.isPlainTextBody(internalConfig.headers) ? data : JSON.stringify(data), url });
41
+ // only binary data and an explicitly plain text body are passed through as they are
42
+ data: isBinary || this.isPlainTextBody(internalConfig.headers) ? data : JSON.stringify(data), url });
39
43
  // apply additional query params to the URL
40
44
  if (params && Object.values(params).length) {
41
45
  resultConfig.url +=
@@ -44,11 +48,16 @@ class JQueryClient extends http_client_base_1.BaseHttpClient {
44
48
  new URLSearchParams(params).toString();
45
49
  }
46
50
  // handling of extra data types: blob and stream (not supported)
47
- if (internalConfig.dataType === "blob") {
51
+ if (isBinary) {
48
52
  resultConfig.xhrFields = { responseType: "blob" };
53
+ // jQuery would otherwise turn the blob into a query string (processData defaults to true)
54
+ // and add its own urlencoded content type; the actual mime type is already part of the headers
55
+ resultConfig.processData = false;
56
+ resultConfig.contentType = false;
49
57
  }
50
58
  else if (internalConfig.dataType === "stream") {
51
- throw new Error("Streaming is not supported by the JqueryClient!");
59
+ // a refusal is a failure of this client like any other, hence it carries the same error type
60
+ throw new JQueryClientError_1.JQueryClientError(exports.FAILURE_STREAM_UNSUPPORTED);
52
61
  }
53
62
  // the actual request
54
63
  return new Promise((resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"JQueryClient.js","sourceRoot":"","sources":["../src/JQueryClient.ts"],"names":[],"mappings":";AAAA,8EAA8E;;;;AAQ9E,iEAA+E;AAC/E,2DAAwD;AACxD,+DAA0E;AAI7D,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAMzD,MAAa,YAAa,SAAQ,iCAAmC;IAInE,YAAY,MAAoB,EAAE,MAA4B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AO,GAAG,eAAe,IAAI,WAAW,IAAI,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;AAnFD,oCAmFC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/JQueryStatic.d.ts\" />\n\nimport {\n HttpResponseModel,\n ODataHttpClient,\n ODataHttpClientOptions,\n ODataHttpMethods,\n} from \"@odata2ts/http-client-api\";\nimport { BaseHttpClient, BaseRequestConfig } from \"@odata2ts/http-client-base\";\nimport { JQueryClientError } from \"./JQueryClientError\";\nimport { JQueryRequestConfig, mergeConfigs } from \"./JQueryRequestConfig\";\n\nimport jqXHR = JQuery.jqXHR;\n\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\n\ninterface InternalRequestConfig\n extends JQueryRequestConfig,\n Pick<JQuery.AjaxSettings, \"url\" | \"data\" | \"dataType\" | \"method\" | \"xhrFields\"> {}\n\nexport class JQueryClient extends BaseHttpClient<JQueryRequestConfig> implements ODataHttpClient<JQueryRequestConfig> {\n private readonly client: JQueryStatic;\n private readonly config: JQueryRequestConfig;\n\n constructor(jquery: JQueryStatic, config?: JQueryRequestConfig, clientOptions?: ODataHttpClientOptions) {\n super(clientOptions);\n this.client = jquery;\n this.config = config ?? {};\n }\n\n protected mapHeaders(jqXhr: jqXHR): Record<string, string> {\n return jqXhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/)\n .reduce((collector: Record<string, string>, line: string) => {\n const parts = line.split(\": \");\n const header = parts.shift();\n const value = parts.join(\": \");\n\n if (header) {\n collector[header.toLowerCase()] = value;\n }\n return collector;\n }, {});\n }\n\n protected async executeRequest<ResponseModel>(\n method: ODataHttpMethods,\n url: string,\n data: any,\n requestConfig?: JQueryRequestConfig,\n internalConfig: BaseRequestConfig = {},\n ): Promise<HttpResponseModel<ResponseModel>> {\n const { headers } = internalConfig;\n const { params, ...mergedConfig } = mergeConfigs(this.config, mergeConfigs({ headers }, requestConfig));\n\n // set core inputs for request\n const resultConfig: InternalRequestConfig = {\n ...mergedConfig,\n method,\n // only an explicitly plain text body is passed through as it is\n data: this.isPlainTextBody(internalConfig.headers) ? data : JSON.stringify(data),\n url,\n };\n\n // apply additional query params to the URL\n if (params && Object.values(params).length) {\n resultConfig.url +=\n (url.match(/\\?/) ? \"&\" : \"?\") +\n // @ts-ignore\n new URLSearchParams(params).toString();\n }\n\n // handling of extra data types: blob and stream (not supported)\n if (internalConfig.dataType === \"blob\") {\n resultConfig.xhrFields = { responseType: \"blob\" };\n } else if (internalConfig.dataType === \"stream\") {\n throw new Error(\"Streaming is not supported by the JqueryClient!\");\n }\n\n // the actual request\n return new Promise((resolve, reject) => {\n this.client.ajax({\n ...resultConfig,\n success: (response: any, textStatus: string, jqXHR: JQuery.jqXHR) => {\n resolve({\n status: jqXHR.status,\n statusText: jqXHR.statusText,\n headers: this.mapHeaders(jqXHR),\n data: response,\n });\n },\n error: (jqXHR: JQuery.jqXHR, textStatus: string, thrownError: string) => {\n const responseMessage = this.retrieveErrorMessage(jqXHR?.responseJSON);\n const failMsg = responseMessage || thrownError || DEFAULT_ERROR_MESSAGE;\n const errorMessage = responseMessage ? \"OData server responded with error: \" + responseMessage : failMsg;\n const responseHeaders = this.mapHeaders(jqXHR);\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));\n },\n });\n });\n }\n}\n"]}
1
+ {"version":3,"file":"JQueryClient.js","sourceRoot":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AY,KACf,OAAO,EAAE,CAAC,QAAa,EAAE,UAAkB,EAAE,KAAmB,EAAE,EAAE;wBAClE,OAAO,CAAC;4BACN,MAAM,EAAE,KAAK,CAAC,MAAM;4BACpB,UAAU,EAAE,KAAK,CAAC,UAAU;4BAC5B,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;4BAC/B,IAAI,EAAE,QAAQ;yBACf,CAAC,CAAC;oBACL,CAAC,EACD,KAAK,EAAE,CAAC,KAAmB,EAAE,UAAkB,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,eAAe,IAAI,WAAW,IAAI,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;AAzFD,oCAyFC","sourcesContent":["/// <reference path=\"../../../node_modules/@types/jquery/JQueryStatic.d.ts\" />\n\nimport {\n HttpResponseModel,\n ODataHttpClient,\n ODataHttpClientOptions,\n ODataHttpMethods,\n} from \"@odata2ts/http-client-api\";\nimport { BaseHttpClient, BaseRequestConfig } from \"@odata2ts/http-client-base\";\nimport { JQueryClientError } from \"./JQueryClientError\";\nimport { JQueryRequestConfig, mergeConfigs } from \"./JQueryRequestConfig\";\n\nimport jqXHR = JQuery.jqXHR;\n\nexport const DEFAULT_ERROR_MESSAGE = \"No error message!\";\nexport const FAILURE_STREAM_UNSUPPORTED =\n \"Streaming is not supported by the JqueryClient! XmlHttpRequest, which jQuery's ajax method builds \" +\n \"upon, has no streaming API at all - neither for reading a response nor for sending a request body. \" +\n \"Use the FetchClient for streams.\";\n\ninterface InternalRequestConfig\n extends\n JQueryRequestConfig,\n Pick<JQuery.AjaxSettings, \"url\" | \"data\" | \"dataType\" | \"method\" | \"xhrFields\" | \"processData\" | \"contentType\"> {}\n\nexport class JQueryClient extends BaseHttpClient<JQueryRequestConfig> implements ODataHttpClient<JQueryRequestConfig> {\n private readonly client: JQueryStatic;\n private readonly config: JQueryRequestConfig;\n\n constructor(jquery: JQueryStatic, config?: JQueryRequestConfig, clientOptions?: ODataHttpClientOptions) {\n super(clientOptions);\n this.client = jquery;\n this.config = config ?? {};\n }\n\n protected mapHeaders(jqXhr: jqXHR): Record<string, string> {\n return jqXhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/)\n .reduce((collector: Record<string, string>, line: string) => {\n const parts = line.split(\": \");\n const header = parts.shift();\n const value = parts.join(\": \");\n\n if (header) {\n collector[header.toLowerCase()] = value;\n }\n return collector;\n }, {});\n }\n\n protected async executeRequest<ResponseModel>(\n method: ODataHttpMethods,\n url: string,\n data: any,\n requestConfig: JQueryRequestConfig | undefined,\n internalConfig: BaseRequestConfig,\n ): Promise<HttpResponseModel<ResponseModel>> {\n const { headers } = internalConfig;\n const { params, ...mergedConfig } = mergeConfigs(this.config, mergeConfigs({ headers }, requestConfig));\n const isBinary = internalConfig.dataType === \"blob\";\n\n // set core inputs for request\n const resultConfig: InternalRequestConfig = {\n ...mergedConfig,\n method,\n // only binary data and an explicitly plain text body are passed through as they are\n data: isBinary || this.isPlainTextBody(internalConfig.headers) ? data : JSON.stringify(data),\n url,\n };\n\n // apply additional query params to the URL\n if (params && Object.values(params).length) {\n resultConfig.url +=\n (url.match(/\\?/) ? \"&\" : \"?\") +\n // @ts-ignore\n new URLSearchParams(params).toString();\n }\n\n // handling of extra data types: blob and stream (not supported)\n if (isBinary) {\n resultConfig.xhrFields = { responseType: \"blob\" };\n // jQuery would otherwise turn the blob into a query string (processData defaults to true)\n // and add its own urlencoded content type; the actual mime type is already part of the headers\n resultConfig.processData = false;\n resultConfig.contentType = false;\n } else if (internalConfig.dataType === \"stream\") {\n // a refusal is a failure of this client like any other, hence it carries the same error type\n throw new JQueryClientError(FAILURE_STREAM_UNSUPPORTED);\n }\n\n // the actual request\n return new Promise((resolve, reject) => {\n this.client.ajax({\n ...resultConfig,\n success: (response: any, textStatus: string, jqXHR: JQuery.jqXHR) => {\n resolve({\n status: jqXHR.status,\n statusText: jqXHR.statusText,\n headers: this.mapHeaders(jqXHR),\n data: response,\n });\n },\n error: (jqXHR: JQuery.jqXHR, textStatus: string, thrownError: string) => {\n const responseMessage = this.retrieveErrorMessage(jqXHR?.responseJSON);\n const failMsg = responseMessage || thrownError || DEFAULT_ERROR_MESSAGE;\n const errorMessage = responseMessage ? \"OData server responded with error: \" + responseMessage : failMsg;\n const responseHeaders = this.mapHeaders(jqXHR);\n reject(new JQueryClientError(errorMessage, jqXHR.status, responseHeaders, new Error(failMsg), jqXHR));\n },\n });\n });\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { ODataClientError } from "@odata2ts/http-client-api";
2
2
  export declare class JQueryClientError extends Error implements ODataClientError {
3
- readonly status: number | undefined;
4
- readonly headers: Record<string, string> | undefined;
5
- readonly cause: Error | undefined;
6
- readonly jqXHR: JQuery.jqXHR;
7
- constructor(msg: string, status: number | undefined, headers: Record<string, string> | undefined, cause: Error | undefined, jqXHR: JQuery.jqXHR);
3
+ readonly status?: number | undefined;
4
+ readonly headers?: Record<string, string> | undefined;
5
+ readonly cause?: Error | undefined;
6
+ readonly jqXHR?: JQuery.jqXHR | undefined;
7
+ constructor(msg: string, status?: number | undefined, headers?: Record<string, string> | undefined, cause?: Error | undefined, jqXHR?: JQuery.jqXHR | undefined);
8
8
  }
@@ -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,MAAe,EACf,OAAgC,EAChC,KAAa,EACb,KAAoB;QAEpC,2GAA2G;QAC3G,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QANN,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAyB;QAChC,UAAK,GAAL,KAAK,CAAQ;QACb,UAAK,GAAL,KAAK,CAAe;QAIpC,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,\n public readonly headers?: Record<string, string>,\n public readonly cause?: Error,\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/http-client-jquery",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "JQuery based http client usable by odata2ts",
5
5
  "keywords": [
6
6
  "http client",
@@ -31,7 +31,7 @@
31
31
  "unit-test": "vitest run --dir test"
32
32
  },
33
33
  "dependencies": {
34
- "@odata2ts/http-client-base": "^0.5.7",
34
+ "@odata2ts/http-client-base": "^0.5.8",
35
35
  "tslib": "^2.8.1"
36
36
  },
37
37
  "devDependencies": {