asab_webui_shell 25.1.9 → 25.1.11

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.
@@ -124,6 +124,10 @@ var Application = /*#__PURE__*/function (_Component) {
124
124
  _this.ReduxService.addReducer("sidebar", _reducer2["default"]);
125
125
  _this.ReduxService.addReducer("navigation", _reducer4["default"]);
126
126
  _this.ReduxService.addReducer("router", _reducer5["default"]);
127
+
128
+ // The application can provide a list of keys that should be automatically parsed as BigInt, when received from the server in Axios call
129
+ // This is important to preserve 64bit numbers from the server such as IP addresses, timestamps etc.
130
+ _this.JSONParseBigInt = new Set(props === null || props === void 0 ? void 0 : props.bigint);
127
131
  _this._handleKeyUp = _this._handleKeyUp.bind(_this);
128
132
  _this.state = {
129
133
  networking: 0,
@@ -337,6 +341,10 @@ var Application = /*#__PURE__*/function (_Component) {
337
341
  return undefined;
338
342
  }
339
343
  var axios = _axios["default"].create(_objectSpread(_objectSpread({}, props), {}, {
344
+ transformResponse: function transformResponse(res) {
345
+ return res;
346
+ },
347
+ // Disable implicit JSON parsing, we explicitly parse JSON in the interceptor ( https://stackoverflow.com/questions/41013082/disable-json-parsing-in-axios )
340
348
  baseURL: service_url
341
349
  }));
342
350
 
@@ -370,9 +378,49 @@ var Application = /*#__PURE__*/function (_Component) {
370
378
  return Promise.reject(error);
371
379
  });
372
380
 
373
- // We want to remove networking indicator when we recieve the response
381
+ // We want to remove the networking indicator when we receive the response
374
382
  axios.interceptors.response.use(function (response) {
383
+ var _response$headers$con;
384
+ // Call the `popNetworkingIndicator` method to remove the networking indicator (e.g., loading spinner)
375
385
  that.popNetworkingIndicator();
386
+
387
+ /*
388
+ Custom flag to control JSON parsing for specific requests.
389
+ If 'skipJsonParsing' is set to true in the request config,
390
+ we return the raw response and skip automatic JSON parsing in the interceptor.
391
+ This is useful when we need to get the response as plain text (e.g., for retrieving raw content).
392
+ */
393
+ if (response.config.skipJsonParsing) {
394
+ return response;
395
+ }
396
+
397
+ // Check if the response content type is 'application/json' or starts with 'application/json'
398
+ if (response !== null && response !== void 0 && (_response$headers$con = response.headers['content-type']) !== null && _response$headers$con !== void 0 && _response$headers$con.startsWith('application/json')) {
399
+ // If the response is JSON, then parse it with respect to BigInt
400
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
401
+ try {
402
+ // Parse the response data using a custom reviver function
403
+ response.data = JSON.parse(response.data,
404
+ // Custom reviver function to handle BigInt values
405
+ function (key, value, context) {
406
+ // If there is no data in the JSONParseBigInt, return the value immediately
407
+ if (that.JSONParseBigInt.size === 0) {
408
+ return value;
409
+ }
410
+ // Check if the key is in the `JSONParseBigInt` set and the value is a number
411
+ if (that.JSONParseBigInt.has(key) && typeof value === 'number') {
412
+ // Convert the number to a BigInt
413
+ return BigInt(context.source);
414
+ }
415
+ // Return the original value if no conversion is needed
416
+ return value;
417
+ });
418
+ } catch (e) {
419
+ // Log any errors that occur during JSON parsing
420
+ console.error("Error in axios.interceptors.response", e);
421
+ }
422
+ }
423
+ // If the request was satisfied (application/json and presence of BigInt) return the modified object. If not, we return unchanged object
376
424
  return response;
377
425
  }, function (error) {
378
426
  that.popNetworkingIndicator();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_shell",
3
- "version": "25.1.9",
3
+ "version": "25.1.11",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Shell Application",
6
6
  "contributors": [
@@ -43,7 +43,7 @@
43
43
  "@babel/runtime": "^7.22.11",
44
44
  "react": "^17.0.0",
45
45
  "react-dom": "^17.0.0",
46
- "axios": "^0.21.1",
46
+ "axios": "^1.8.4",
47
47
  "i18next": "^20.3.5",
48
48
  "react-i18next": "^11.8.12",
49
49
  "react-redux": "^7.2.0",