@sumaris-net/ngx-components 1.15.13 → 1.15.14

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.
@@ -11314,18 +11314,14 @@
11314
11314
  var HttpUtils = /** @class */ (function () {
11315
11315
  function HttpUtils() {
11316
11316
  }
11317
- HttpUtils.getResource = function (http, uri, opts) {
11317
+ HttpUtils.getText = function (http, uri, opts) {
11318
11318
  return __awaiter(this, void 0, void 0, function () {
11319
11319
  var err_1;
11320
11320
  return __generator(this, function (_a) {
11321
11321
  switch (_a.label) {
11322
11322
  case 0:
11323
11323
  // Add headers
11324
- opts = Object.assign({}, opts
11325
- //headers: new HttpHeaders(),
11326
- //.append('X-App-Name', environment.name)
11327
- //.append('X-App-Version', environment.version),
11328
- );
11324
+ opts = opts || { responseType: 'text' };
11329
11325
  // Force no cache
11330
11326
  if (opts.nocache === true) {
11331
11327
  opts.headers = (opts.headers instanceof i2$1.HttpHeaders ? opts.headers : new i2$1.HttpHeaders(opts.headers));
@@ -11336,10 +11332,8 @@
11336
11332
  _a.label = 1;
11337
11333
  case 1:
11338
11334
  _a.trys.push([1, 3, , 4]);
11339
- return [4 /*yield*/, http.get(uri, opts).toPromise()];
11340
- case 2:
11341
- // Using web http client
11342
- return [2 /*return*/, (_a.sent())];
11335
+ return [4 /*yield*/, http.get(uri, Object.assign(Object.assign({}, opts), { responseType: 'text' })).toPromise()];
11336
+ case 2: return [2 /*return*/, (_a.sent())];
11343
11337
  case 3:
11344
11338
  err_1 = _a.sent();
11345
11339
  if (err_1 && err_1.message) {
@@ -11354,6 +11348,40 @@
11354
11348
  });
11355
11349
  });
11356
11350
  };
11351
+ HttpUtils.getJson = function (http, uri, opts) {
11352
+ return __awaiter(this, void 0, void 0, function () {
11353
+ var err_2;
11354
+ return __generator(this, function (_a) {
11355
+ switch (_a.label) {
11356
+ case 0:
11357
+ // Add headers
11358
+ opts = opts || {};
11359
+ // Force no cache
11360
+ if (opts.nocache === true) {
11361
+ opts.headers = (opts.headers instanceof i2$1.HttpHeaders ? opts.headers : new i2$1.HttpHeaders(opts.headers));
11362
+ opts.headers
11363
+ .append('Cache-Control', 'no-cache')
11364
+ .append('Pragma', 'no-cache');
11365
+ }
11366
+ _a.label = 1;
11367
+ case 1:
11368
+ _a.trys.push([1, 3, , 4]);
11369
+ return [4 /*yield*/, http.get(uri, Object.assign(Object.assign({}, opts), { responseType: 'json' })).toPromise()];
11370
+ case 2: return [2 /*return*/, (_a.sent())];
11371
+ case 3:
11372
+ err_2 = _a.sent();
11373
+ if (err_2 && err_2.message) {
11374
+ console.error("[network] Error on get request " + uri + ": " + err_2.message, err_2);
11375
+ }
11376
+ else {
11377
+ console.error("[network] Error on get request " + uri + ": " + (err_2 && err_2.statusText) + " - " + JSON.stringify(err_2));
11378
+ }
11379
+ throw { code: err_2.status, message: 'ERROR.UNKNOWN_NETWORK_ERROR' };
11380
+ case 4: return [2 /*return*/];
11381
+ }
11382
+ });
11383
+ });
11384
+ };
11357
11385
  return HttpUtils;
11358
11386
  }());
11359
11387
 
@@ -11374,7 +11402,7 @@
11374
11402
  if (peerUrl.endsWith('/')) {
11375
11403
  peerUrl = peerUrl.substr(0, peerUrl.length - 1);
11376
11404
  }
11377
- return [2 /*return*/, HttpUtils.getResource(http, peerUrl + '/api/node/info', opts)];
11405
+ return [2 /*return*/, HttpUtils.getJson(http, peerUrl + '/api/node/info', opts)];
11378
11406
  });
11379
11407
  });
11380
11408
  }
@@ -12639,7 +12667,7 @@
12639
12667
  if (opts === null || opts === void 0 ? void 0 : opts.nocache) {
12640
12668
  path += '?t=' + Date.now();
12641
12669
  }
12642
- return [4 /*yield*/, this.get(path, opts)];
12670
+ return [4 /*yield*/, this.getText(path, opts)];
12643
12671
  case 1:
12644
12672
  appVersion = _b.sent();
12645
12673
  if (isNotNilOrBlank(appVersion))
@@ -12906,31 +12934,43 @@
12906
12934
  });
12907
12935
  this._timerSubscription.add(function () { return console.debug('[network] Refresh timer stopped'); });
12908
12936
  };
12937
+ NetworkService.prototype.getText = function (path, opts) {
12938
+ return __awaiter(this, void 0, void 0, function () {
12939
+ var uri;
12940
+ return __generator(this, function (_b) {
12941
+ uri = this.getUri(path);
12942
+ return [2 /*return*/, HttpUtils.getText(this.http, uri, opts)];
12943
+ });
12944
+ });
12945
+ };
12909
12946
  NetworkService.prototype.get = function (path, opts) {
12910
12947
  return __awaiter(this, void 0, void 0, function () {
12911
- var uri, peerUrl;
12948
+ var uri;
12912
12949
  return __generator(this, function (_b) {
12913
- uri = path;
12914
- // If path is not an URI: prepend with peer URL
12915
- if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
12916
- peerUrl = (this.peer && this.peer.url);
12917
- // Remove trailing slash
12918
- if (peerUrl.endsWith('/')) {
12919
- peerUrl = peerUrl.substr(0, peerUrl.length - 1);
12920
- }
12921
- // Add first path
12922
- if (!path.startsWith('/')) {
12923
- path = '/' + path;
12924
- }
12925
- // Create the URI: concat peer URL and path
12926
- uri = peerUrl + path;
12927
- }
12928
- // Execute the request
12929
- return [2 /*return*/, HttpUtils.getResource(this.http, uri, opts)];
12950
+ uri = this.getUri(path);
12951
+ return [2 /*return*/, HttpUtils.getJson(this.http, uri, opts)];
12930
12952
  });
12931
12953
  });
12932
12954
  };
12933
12955
  /* -- Protected methods -- */
12956
+ NetworkService.prototype.getUri = function (path) {
12957
+ var uri = path;
12958
+ // If path is not an URI: prepend with peer URL
12959
+ if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
12960
+ var peerUrl = (this.peer && this.peer.url);
12961
+ // Remove trailing slash
12962
+ if (peerUrl.endsWith('/')) {
12963
+ peerUrl = peerUrl.substr(0, peerUrl.length - 1);
12964
+ }
12965
+ // Add first path
12966
+ if (!path.startsWith('/')) {
12967
+ path = '/' + path;
12968
+ }
12969
+ // Create the URI: concat peer URL and path
12970
+ uri = peerUrl + path;
12971
+ }
12972
+ return uri;
12973
+ };
12934
12974
  NetworkService.prototype.onDeviceConnectionChanged = function (connectionType) {
12935
12975
  connectionType = (connectionType || 'unknown').toLowerCase();
12936
12976
  if (connectionType.startsWith('cell'))