roboto-js 1.4.37 → 1.4.39

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.
@@ -480,7 +480,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
480
480
  key: "refreshAuthToken",
481
481
  value: function () {
482
482
  var _refreshAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(authtoken) {
483
- var response;
483
+ var promise, response;
484
484
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
485
485
  while (1) switch (_context11.prev = _context11.next) {
486
486
  case 0:
@@ -488,31 +488,67 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
488
488
  _context11.next = 3;
489
489
  break;
490
490
  }
491
- console.warn('appServiceHost not initialized');
491
+ console.warn('RBTTOK not initialized');
492
492
  return _context11.abrupt("return", false);
493
493
  case 3:
494
- _context11.prev = 3;
495
- _context11.next = 6;
496
- return this.axios.post('/user_service/refreshAuthToken', [authtoken]);
494
+ if (!this.requestCache[authtoken]) {
495
+ _context11.next = 6;
496
+ break;
497
+ }
498
+ // If there's already a pending promise to refresh this token, return it
499
+ console.log('RBTTOK Using cached promise for token refresh');
500
+ return _context11.abrupt("return", this.requestCache[authtoken]);
497
501
  case 6:
502
+ _context11.prev = 6;
503
+ console.log('RBTTOK Req', authtoken);
504
+ // Create a new promise for the token refresh and store it in the cache
505
+ promise = this.axios.post('/user_service/refreshAuthToken', [authtoken]);
506
+ this.requestCache[authtoken] = promise;
507
+
508
+ // Await the promise to get the response
509
+ _context11.next = 12;
510
+ return promise;
511
+ case 12:
498
512
  response = _context11.sent;
499
- debugger;
513
+ console.log('RBTTOK Response ', response);
514
+ // Once the promise resolves, delete it from the cache to allow future refreshes
515
+ delete this.requestCache[authtoken];
516
+
517
+ // Return the response data
500
518
  return _context11.abrupt("return", response.data);
501
- case 11:
502
- _context11.prev = 11;
503
- _context11.t0 = _context11["catch"](3);
519
+ case 18:
520
+ _context11.prev = 18;
521
+ _context11.t0 = _context11["catch"](6);
522
+ // On error, remove the cached promise to allow retries
523
+ delete this.requestCache[authtoken];
504
524
  this._handleError(_context11.t0);
505
- case 14:
525
+ case 22:
506
526
  case "end":
507
527
  return _context11.stop();
508
528
  }
509
- }, _callee11, this, [[3, 11]]);
529
+ }, _callee11, this, [[6, 18]]);
510
530
  }));
511
531
  function refreshAuthToken(_x7) {
512
532
  return _refreshAuthToken.apply(this, arguments);
513
533
  }
514
534
  return refreshAuthToken;
515
- }()
535
+ }() // async refreshAuthToken(authtoken){
536
+ //
537
+ // if(!this.appServiceHost){
538
+ // console.warn('appServiceHost not initialized');
539
+ // return false;
540
+ // }
541
+ //
542
+ // try {
543
+ //
544
+ // const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
545
+ // return response.data;
546
+ //
547
+ // } catch (e) {
548
+ //
549
+ // this._handleError(e);
550
+ // }
551
+ // }
516
552
  /**
517
553
  * Registers a new user.
518
554
  *
@@ -522,7 +558,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
522
558
  */
523
559
  }, {
524
560
  key: "registerUser",
525
- value: (function () {
561
+ value: function () {
526
562
  var _registerUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
527
563
  var dataHash,
528
564
  response,
@@ -542,9 +578,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
542
578
  case 9:
543
579
  _context12.prev = 9;
544
580
  _context12.t0 = _context12["catch"](1);
545
- debugger;
546
581
  return _context12.abrupt("return", this._handleError(_context12.t0));
547
- case 13:
582
+ case 12:
548
583
  case "end":
549
584
  return _context12.stop();
550
585
  }
@@ -562,7 +597,6 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
562
597
  * @returns {Promise<RbtFile>} - The newly created file as an RbtFile.
563
598
  *
564
599
  */
565
- )
566
600
  }, {
567
601
  key: "createFile",
568
602
  value: (function () {
@@ -706,6 +740,48 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
706
740
  *
707
741
  * Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
708
742
  */
743
+ // async query(type, params = {}) {
744
+ // try {
745
+ // console.log('RBTAPI.query INIT', type, params);
746
+ // params.type = type;
747
+ // // Default ordering and pagination
748
+ // const defaultOrderBy = { orderBy: { column: 'timeCreated', direction: 'DESC' } };
749
+ // const defaultLimit = { limit: { offset: 0, results: 50 } };
750
+ //
751
+ // // Merge defaults with provided params
752
+ // const mergedParams = { ...defaultOrderBy, ...defaultLimit, ...params };
753
+ // // Check cache for an existing request
754
+ // const currentTime = Date.now();
755
+ // const paramsKey = JSON.stringify(mergedParams);
756
+ // const cacheEntry = this.requestCache[paramsKey];
757
+ // if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
758
+ // console.log('RBTAPI.query CACHED', type, paramsKey);
759
+ // return cacheEntry.val;
760
+ // }
761
+ // // Create the response promise and store it in the cache
762
+ // const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
763
+ // // Store the promise along with the current time in the cache
764
+ // this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
765
+ // // Await the response from the API
766
+ // const response = await responsePromise;
767
+ // if (response.data.ok === false) {
768
+ // return this._handleError(response);
769
+ // }
770
+ // // Process items into RbtObject instances
771
+ // if (Array.isArray(response.data.items)) {
772
+ // response.data.items = response.data.items.map(record => {
773
+ // return new RbtObject(record, this.axios, { isNew: true });
774
+ // });
775
+ // }
776
+ // console.log('RBTAPI.query RESPONSE', type, paramsKey, response.data.items);
777
+ // return response.data.items;
778
+ // } catch (e) {
779
+ // delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
780
+ // console.log('RBTAPI.query ERROR', paramsKey, e);
781
+ // return this._handleError(e);
782
+ //
783
+ // }
784
+ // }
709
785
  )
710
786
  }, {
711
787
  key: "query",
@@ -717,15 +793,17 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
717
793
  defaultLimit,
718
794
  mergedParams,
719
795
  currentTime,
796
+ _paramsKey,
720
797
  cacheEntry,
721
798
  responsePromise,
722
- response,
799
+ processingPromise,
723
800
  _args16 = arguments;
724
801
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
725
802
  while (1) switch (_context16.prev = _context16.next) {
726
803
  case 0:
727
804
  params = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {};
728
805
  _context16.prev = 1;
806
+ //console.log('RBTAPI.query INIT', type, params);
729
807
  params.type = type;
730
808
 
731
809
  // Default ordering and pagination
@@ -743,58 +821,70 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
743
821
  }; // Merge defaults with provided params
744
822
  mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params); // Check cache for an existing request
745
823
  currentTime = Date.now();
746
- cacheEntry = this.requestCache[paramsKey];
824
+ _paramsKey = JSON.stringify(mergedParams);
825
+ cacheEntry = this.requestCache[_paramsKey];
747
826
  if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
748
827
  _context16.next = 11;
749
828
  break;
750
829
  }
751
- // 10000 ms = 10 seconds
752
- console.log("Using cached request for params:", paramsKey);
753
830
  return _context16.abrupt("return", cacheEntry.val);
754
831
  case 11:
755
- // Create the response promise and store it in the cache
756
- responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Store the promise along with the current time in the cache
757
- this.requestCache[paramsKey] = {
758
- val: responsePromise,
832
+ // Create the response promise
833
+ responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Cache the promise of processing data, not just the raw response
834
+ processingPromise = responsePromise.then(function (response) {
835
+ return _this._processResponseData(response);
836
+ })["catch"](function (e) {
837
+ delete _this.requestCache[_paramsKey]; // Ensure cache cleanup on failure
838
+ //console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
839
+ return _this._handleError(e);
840
+ }); // Store the promise of the processed data in the cache
841
+ this.requestCache[_paramsKey] = {
842
+ val: processingPromise,
759
843
  time: currentTime
760
844
  };
761
845
 
762
- // Await the response from the API
763
- _context16.next = 15;
764
- return responsePromise;
765
- case 15:
766
- response = _context16.sent;
767
- if (!(response.data.ok === false)) {
768
- _context16.next = 18;
769
- break;
770
- }
771
- return _context16.abrupt("return", this._handleError(response));
772
- case 18:
773
- // Process items into RbtObject instances
774
- if (Array.isArray(response.data.items)) {
775
- response.data.items = response.data.items.map(function (record) {
776
- return new _rbt_object["default"](record, _this.axios, {
777
- isNew: true
778
- });
779
- });
780
- }
781
- return _context16.abrupt("return", response.data.items);
782
- case 22:
783
- _context16.prev = 22;
846
+ // Await the processing promise for this call to get processed data
847
+ _context16.next = 16;
848
+ return processingPromise;
849
+ case 16:
850
+ return _context16.abrupt("return", _context16.sent);
851
+ case 19:
852
+ _context16.prev = 19;
784
853
  _context16.t0 = _context16["catch"](1);
785
854
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
855
+ //console.log('RBTAPI.query ERROR', paramsKey, e);
786
856
  return _context16.abrupt("return", this._handleError(_context16.t0));
787
- case 26:
857
+ case 23:
788
858
  case "end":
789
859
  return _context16.stop();
790
860
  }
791
- }, _callee16, this, [[1, 22]]);
861
+ }, _callee16, this, [[1, 19]]);
792
862
  }));
793
863
  function query(_x11) {
794
864
  return _query.apply(this, arguments);
795
865
  }
796
866
  return query;
797
- }()
867
+ }())
868
+ }, {
869
+ key: "_processResponseData",
870
+ value: function _processResponseData(response) {
871
+ var _this2 = this;
872
+ if (response.data.ok === false) {
873
+ return this._handleError(response);
874
+ }
875
+ if (Array.isArray(response.data.items)) {
876
+ //console.log('RBTAPI.query RESPONSE PRE', response.data.items);
877
+ response.data.items = response.data.items.map(function (record) {
878
+ return new _rbt_object["default"](record, _this2.axios, {
879
+ isNew: true
880
+ });
881
+ });
882
+ }
883
+
884
+ //console.log('RBTAPI.query RESPONSE POST', response.data.items);
885
+ return response.data.items;
886
+ }
887
+
798
888
  /**
799
889
  * Loads one or multiple objects of a given type by their IDs.
800
890
  *
@@ -803,7 +893,6 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
803
893
  *
804
894
  * @returns {Promise<RbtObject|RbtObject[]>} - The loaded object(s) as RbtObject(s).
805
895
  */
806
- )
807
896
  }, {
808
897
  key: "load",
809
898
  value: (function () {
@@ -1016,7 +1105,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1016
1105
  key: "pollTaskProgress",
1017
1106
  value: (function () {
1018
1107
  var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(jobId, callbacks) {
1019
- var _this2 = this;
1108
+ var _this3 = this;
1020
1109
  var onProgress, onError, onStopped, onDone, checkProgress;
1021
1110
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1022
1111
  while (1) switch (_context21.prev = _context21.next) {
@@ -1030,7 +1119,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1030
1119
  while (1) switch (_context20.prev = _context20.next) {
1031
1120
  case 0:
1032
1121
  _context20.next = 2;
1033
- return _this2.get("/task_service/pollChainProgress", {
1122
+ return _this3.get("/task_service/pollChainProgress", {
1034
1123
  jobId: jobId
1035
1124
  });
1036
1125
  case 2:
@@ -1111,35 +1200,34 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1111
1200
  while (1) switch (_context22.prev = _context22.next) {
1112
1201
  case 0:
1113
1202
  params = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
1114
- debugger;
1115
- _context22.prev = 2;
1203
+ _context22.prev = 1;
1116
1204
  // Add the authToken to the headers
1117
1205
  headers = {
1118
1206
  authtoken: this.authtoken
1119
1207
  }; // Make the GET request using Axios
1120
- _context22.next = 6;
1208
+ _context22.next = 5;
1121
1209
  return this.axios.get(endpoint, {
1122
1210
  params: params,
1123
1211
  headers: headers
1124
1212
  });
1125
- case 6:
1213
+ case 5:
1126
1214
  response = _context22.sent;
1127
1215
  if (!(response.data.ok === false)) {
1128
- _context22.next = 9;
1216
+ _context22.next = 8;
1129
1217
  break;
1130
1218
  }
1131
1219
  return _context22.abrupt("return", this._handleError(response));
1132
- case 9:
1220
+ case 8:
1133
1221
  return _context22.abrupt("return", response.data);
1134
- case 12:
1135
- _context22.prev = 12;
1136
- _context22.t0 = _context22["catch"](2);
1222
+ case 11:
1223
+ _context22.prev = 11;
1224
+ _context22.t0 = _context22["catch"](1);
1137
1225
  return _context22.abrupt("return", this._handleError(_context22.t0));
1138
- case 15:
1226
+ case 14:
1139
1227
  case "end":
1140
1228
  return _context22.stop();
1141
1229
  }
1142
- }, _callee22, this, [[2, 12]]);
1230
+ }, _callee22, this, [[1, 11]]);
1143
1231
  }));
1144
1232
  function get(_x16) {
1145
1233
  return _get.apply(this, arguments);
@@ -217,18 +217,53 @@ export default class RbtApi {
217
217
  }
218
218
  async refreshAuthToken(authtoken) {
219
219
  if (!this.appServiceHost) {
220
- console.warn('appServiceHost not initialized');
220
+ console.warn('RBTTOK not initialized');
221
221
  return false;
222
222
  }
223
+ if (this.requestCache[authtoken]) {
224
+ // If there's already a pending promise to refresh this token, return it
225
+ console.log('RBTTOK Using cached promise for token refresh');
226
+ return this.requestCache[authtoken];
227
+ }
223
228
  try {
224
- const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
225
- debugger;
229
+ console.log('RBTTOK Req', authtoken);
230
+ // Create a new promise for the token refresh and store it in the cache
231
+ const promise = this.axios.post('/user_service/refreshAuthToken', [authtoken]);
232
+ this.requestCache[authtoken] = promise;
233
+
234
+ // Await the promise to get the response
235
+ const response = await promise;
236
+ console.log('RBTTOK Response ', response);
237
+ // Once the promise resolves, delete it from the cache to allow future refreshes
238
+ delete this.requestCache[authtoken];
239
+
240
+ // Return the response data
226
241
  return response.data;
227
242
  } catch (e) {
243
+ // On error, remove the cached promise to allow retries
244
+ delete this.requestCache[authtoken];
228
245
  this._handleError(e);
229
246
  }
230
247
  }
231
248
 
249
+ // async refreshAuthToken(authtoken){
250
+ //
251
+ // if(!this.appServiceHost){
252
+ // console.warn('appServiceHost not initialized');
253
+ // return false;
254
+ // }
255
+ //
256
+ // try {
257
+ //
258
+ // const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
259
+ // return response.data;
260
+ //
261
+ // } catch (e) {
262
+ //
263
+ // this._handleError(e);
264
+ // }
265
+ // }
266
+
232
267
  /**
233
268
  * Registers a new user.
234
269
  *
@@ -242,7 +277,6 @@ export default class RbtApi {
242
277
  const record = response.data;
243
278
  return new RbtUser(record, this.axios);
244
279
  } catch (e) {
245
- debugger;
246
280
  return this._handleError(e);
247
281
  }
248
282
  }
@@ -331,8 +365,65 @@ export default class RbtApi {
331
365
  *
332
366
  * Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
333
367
  */
368
+ // async query(type, params = {}) {
369
+
370
+ // try {
371
+
372
+ // console.log('RBTAPI.query INIT', type, params);
373
+ // params.type = type;
374
+
375
+ // // Default ordering and pagination
376
+ // const defaultOrderBy = { orderBy: { column: 'timeCreated', direction: 'DESC' } };
377
+ // const defaultLimit = { limit: { offset: 0, results: 50 } };
378
+ //
379
+ // // Merge defaults with provided params
380
+ // const mergedParams = { ...defaultOrderBy, ...defaultLimit, ...params };
381
+
382
+ // // Check cache for an existing request
383
+ // const currentTime = Date.now();
384
+ // const paramsKey = JSON.stringify(mergedParams);
385
+ // const cacheEntry = this.requestCache[paramsKey];
386
+ // if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
387
+ // console.log('RBTAPI.query CACHED', type, paramsKey);
388
+ // return cacheEntry.val;
389
+ // }
390
+
391
+ // // Create the response promise and store it in the cache
392
+ // const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
393
+
394
+ // // Store the promise along with the current time in the cache
395
+ // this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
396
+
397
+ // // Await the response from the API
398
+ // const response = await responsePromise;
399
+
400
+ // if (response.data.ok === false) {
401
+ // return this._handleError(response);
402
+ // }
403
+
404
+ // // Process items into RbtObject instances
405
+ // if (Array.isArray(response.data.items)) {
406
+ // response.data.items = response.data.items.map(record => {
407
+ // return new RbtObject(record, this.axios, { isNew: true });
408
+ // });
409
+ // }
410
+
411
+ // console.log('RBTAPI.query RESPONSE', type, paramsKey, response.data.items);
412
+ // return response.data.items;
413
+
414
+ // } catch (e) {
415
+
416
+ // delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
417
+ // console.log('RBTAPI.query ERROR', paramsKey, e);
418
+ // return this._handleError(e);
419
+ //
420
+ // }
421
+
422
+ // }
423
+
334
424
  async query(type, params = {}) {
335
425
  try {
426
+ //console.log('RBTAPI.query INIT', type, params);
336
427
  params.type = type;
337
428
 
338
429
  // Default ordering and pagination
@@ -358,42 +449,54 @@ export default class RbtApi {
358
449
 
359
450
  // Check cache for an existing request
360
451
  const currentTime = Date.now();
452
+ const paramsKey = JSON.stringify(mergedParams);
361
453
  const cacheEntry = this.requestCache[paramsKey];
362
454
  if (cacheEntry && currentTime - cacheEntry.time < 10000) {
363
455
  // 10000 ms = 10 seconds
364
- console.log("Using cached request for params:", paramsKey);
456
+ //console.log('RBTAPI.query CACHED', type, paramsKey);
365
457
  return cacheEntry.val;
366
458
  }
367
459
 
368
- // Create the response promise and store it in the cache
460
+ // Create the response promise
369
461
  const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
370
462
 
371
- // Store the promise along with the current time in the cache
463
+ // Cache the promise of processing data, not just the raw response
464
+ const processingPromise = responsePromise.then(response => this._processResponseData(response)).catch(e => {
465
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on failure
466
+ //console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
467
+ return this._handleError(e);
468
+ });
469
+
470
+ // Store the promise of the processed data in the cache
372
471
  this.requestCache[paramsKey] = {
373
- val: responsePromise,
472
+ val: processingPromise,
374
473
  time: currentTime
375
474
  };
376
475
 
377
- // Await the response from the API
378
- const response = await responsePromise;
379
- if (response.data.ok === false) {
380
- return this._handleError(response);
381
- }
382
-
383
- // Process items into RbtObject instances
384
- if (Array.isArray(response.data.items)) {
385
- response.data.items = response.data.items.map(record => {
386
- return new RbtObject(record, this.axios, {
387
- isNew: true
388
- });
389
- });
390
- }
391
- return response.data.items;
476
+ // Await the processing promise for this call to get processed data
477
+ return await processingPromise;
392
478
  } catch (e) {
393
479
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
480
+ //console.log('RBTAPI.query ERROR', paramsKey, e);
394
481
  return this._handleError(e);
395
482
  }
396
483
  }
484
+ _processResponseData(response) {
485
+ if (response.data.ok === false) {
486
+ return this._handleError(response);
487
+ }
488
+ if (Array.isArray(response.data.items)) {
489
+ //console.log('RBTAPI.query RESPONSE PRE', response.data.items);
490
+ response.data.items = response.data.items.map(record => {
491
+ return new RbtObject(record, this.axios, {
492
+ isNew: true
493
+ });
494
+ });
495
+ }
496
+
497
+ //console.log('RBTAPI.query RESPONSE POST', response.data.items);
498
+ return response.data.items;
499
+ }
397
500
 
398
501
  /**
399
502
  * Loads one or multiple objects of a given type by their IDs.
@@ -587,7 +690,6 @@ export default class RbtApi {
587
690
  * @returns {Promise<Object>} - The response data from the API.
588
691
  */
589
692
  async get(endpoint, params = {}) {
590
- debugger;
591
693
  try {
592
694
  // Add the authToken to the headers
593
695
  const headers = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.37",
3
+ "version": "1.4.39",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -274,27 +274,63 @@ export default class RbtApi {
274
274
  }
275
275
 
276
276
 
277
- async refreshAuthToken(authtoken){
278
277
 
279
- if(!this.appServiceHost){
280
- console.warn('appServiceHost not initialized');
278
+ async refreshAuthToken(authtoken) {
279
+
280
+ if (!this.appServiceHost) {
281
+ console.warn('RBTTOK not initialized');
281
282
  return false;
282
283
  }
283
284
 
285
+ if (this.requestCache[authtoken]) {
286
+ // If there's already a pending promise to refresh this token, return it
287
+ console.log('RBTTOK Using cached promise for token refresh');
288
+ return this.requestCache[authtoken];
289
+ }
290
+
284
291
  try {
292
+ console.log('RBTTOK Req', authtoken);
293
+ // Create a new promise for the token refresh and store it in the cache
294
+ const promise = this.axios.post('/user_service/refreshAuthToken', [authtoken]);
295
+ this.requestCache[authtoken] = promise;
285
296
 
286
- const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
297
+ // Await the promise to get the response
298
+ const response = await promise;
287
299
 
288
- debugger;
300
+ console.log('RBTTOK Response ',response);
301
+ // Once the promise resolves, delete it from the cache to allow future refreshes
302
+ delete this.requestCache[authtoken];
303
+
304
+ // Return the response data
289
305
  return response.data;
290
306
 
291
307
  } catch (e) {
292
-
308
+ // On error, remove the cached promise to allow retries
309
+ delete this.requestCache[authtoken];
293
310
  this._handleError(e);
294
311
  }
295
312
  }
296
313
 
297
314
 
315
+ // async refreshAuthToken(authtoken){
316
+ //
317
+ // if(!this.appServiceHost){
318
+ // console.warn('appServiceHost not initialized');
319
+ // return false;
320
+ // }
321
+ //
322
+ // try {
323
+ //
324
+ // const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
325
+ // return response.data;
326
+ //
327
+ // } catch (e) {
328
+ //
329
+ // this._handleError(e);
330
+ // }
331
+ // }
332
+
333
+
298
334
  /**
299
335
  * Registers a new user.
300
336
  *
@@ -309,7 +345,7 @@ export default class RbtApi {
309
345
  const record = response.data;
310
346
  return new RbtUser(record, this.axios);
311
347
  } catch (e) {
312
- debugger;
348
+
313
349
  return this._handleError(e);
314
350
  }
315
351
  }
@@ -405,10 +441,66 @@ export default class RbtApi {
405
441
  *
406
442
  * Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
407
443
  */
408
- async query(type, params = {}) {
444
+ // async query(type, params = {}) {
409
445
 
410
- try {
446
+ // try {
447
+
448
+ // console.log('RBTAPI.query INIT', type, params);
449
+ // params.type = type;
450
+
451
+ // // Default ordering and pagination
452
+ // const defaultOrderBy = { orderBy: { column: 'timeCreated', direction: 'DESC' } };
453
+ // const defaultLimit = { limit: { offset: 0, results: 50 } };
454
+ //
455
+ // // Merge defaults with provided params
456
+ // const mergedParams = { ...defaultOrderBy, ...defaultLimit, ...params };
457
+
458
+ // // Check cache for an existing request
459
+ // const currentTime = Date.now();
460
+ // const paramsKey = JSON.stringify(mergedParams);
461
+ // const cacheEntry = this.requestCache[paramsKey];
462
+ // if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
463
+ // console.log('RBTAPI.query CACHED', type, paramsKey);
464
+ // return cacheEntry.val;
465
+ // }
466
+
467
+ // // Create the response promise and store it in the cache
468
+ // const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
469
+
470
+ // // Store the promise along with the current time in the cache
471
+ // this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
472
+
473
+ // // Await the response from the API
474
+ // const response = await responsePromise;
475
+
476
+ // if (response.data.ok === false) {
477
+ // return this._handleError(response);
478
+ // }
479
+
480
+ // // Process items into RbtObject instances
481
+ // if (Array.isArray(response.data.items)) {
482
+ // response.data.items = response.data.items.map(record => {
483
+ // return new RbtObject(record, this.axios, { isNew: true });
484
+ // });
485
+ // }
486
+
487
+ // console.log('RBTAPI.query RESPONSE', type, paramsKey, response.data.items);
488
+ // return response.data.items;
489
+
490
+ // } catch (e) {
411
491
 
492
+ // delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
493
+ // console.log('RBTAPI.query ERROR', paramsKey, e);
494
+ // return this._handleError(e);
495
+ //
496
+ // }
497
+
498
+ // }
499
+
500
+
501
+ async query(type, params = {}) {
502
+ try {
503
+ //console.log('RBTAPI.query INIT', type, params);
412
504
  params.type = type;
413
505
 
414
506
  // Default ordering and pagination
@@ -420,43 +512,53 @@ export default class RbtApi {
420
512
 
421
513
  // Check cache for an existing request
422
514
  const currentTime = Date.now();
515
+ const paramsKey = JSON.stringify(mergedParams);
423
516
  const cacheEntry = this.requestCache[paramsKey];
424
517
  if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
425
- console.log("Using cached request for params:", paramsKey);
518
+ //console.log('RBTAPI.query CACHED', type, paramsKey);
426
519
  return cacheEntry.val;
427
520
  }
428
521
 
429
- // Create the response promise and store it in the cache
522
+ // Create the response promise
430
523
  const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
431
524
 
432
- // Store the promise along with the current time in the cache
433
- this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
434
-
435
- // Await the response from the API
436
- const response = await responsePromise;
437
-
438
- if (response.data.ok === false) {
439
- return this._handleError(response);
440
- }
525
+ // Cache the promise of processing data, not just the raw response
526
+ const processingPromise = responsePromise.then(response => this._processResponseData(response)).catch(e => {
527
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on failure
528
+ //console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
529
+ return this._handleError(e);
530
+ });
441
531
 
442
- // Process items into RbtObject instances
443
- if (Array.isArray(response.data.items)) {
444
- response.data.items = response.data.items.map(record => {
445
- return new RbtObject(record, this.axios, { isNew: true });
446
- });
447
- }
532
+ // Store the promise of the processed data in the cache
533
+ this.requestCache[paramsKey] = { val: processingPromise, time: currentTime };
448
534
 
449
- return response.data.items;
535
+ // Await the processing promise for this call to get processed data
536
+ return await processingPromise;
450
537
 
451
538
  } catch (e) {
452
-
453
539
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
540
+ //console.log('RBTAPI.query ERROR', paramsKey, e);
454
541
  return this._handleError(e);
455
-
542
+ }
543
+ }
544
+
545
+ _processResponseData(response) {
546
+ if (response.data.ok === false) {
547
+ return this._handleError(response);
548
+ }
549
+
550
+ if (Array.isArray(response.data.items)) {
551
+ //console.log('RBTAPI.query RESPONSE PRE', response.data.items);
552
+ response.data.items = response.data.items.map(record => {
553
+ return new RbtObject(record, this.axios, { isNew: true });
554
+ });
456
555
  }
457
556
 
557
+ //console.log('RBTAPI.query RESPONSE POST', response.data.items);
558
+ return response.data.items;
458
559
  }
459
560
 
561
+
460
562
  /**
461
563
  * Loads one or multiple objects of a given type by their IDs.
462
564
  *
@@ -634,7 +736,7 @@ export default class RbtApi {
634
736
  * @returns {Promise<Object>} - The response data from the API.
635
737
  */
636
738
  async get(endpoint, params = {}) {
637
- debugger;
739
+
638
740
  try {
639
741
 
640
742
  // Add the authToken to the headers