roboto-js 1.4.38 → 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",
@@ -720,13 +796,14 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
720
796
  _paramsKey,
721
797
  cacheEntry,
722
798
  responsePromise,
723
- response,
799
+ processingPromise,
724
800
  _args16 = arguments;
725
801
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
726
802
  while (1) switch (_context16.prev = _context16.next) {
727
803
  case 0:
728
804
  params = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {};
729
805
  _context16.prev = 1;
806
+ //console.log('RBTAPI.query INIT', type, params);
730
807
  params.type = type;
731
808
 
732
809
  // Default ordering and pagination
@@ -747,56 +824,67 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
747
824
  _paramsKey = JSON.stringify(mergedParams);
748
825
  cacheEntry = this.requestCache[_paramsKey];
749
826
  if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
750
- _context16.next = 12;
827
+ _context16.next = 11;
751
828
  break;
752
829
  }
753
- // 10000 ms = 10 seconds
754
- console.log("Using cached request for params:", _paramsKey);
755
830
  return _context16.abrupt("return", cacheEntry.val);
756
- case 12:
757
- // Create the response promise and store it in the cache
758
- responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Store the promise along with the current time in the cache
831
+ case 11:
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
759
841
  this.requestCache[_paramsKey] = {
760
- val: responsePromise,
842
+ val: processingPromise,
761
843
  time: currentTime
762
844
  };
763
845
 
764
- // Await the response from the API
846
+ // Await the processing promise for this call to get processed data
765
847
  _context16.next = 16;
766
- return responsePromise;
848
+ return processingPromise;
767
849
  case 16:
768
- response = _context16.sent;
769
- if (!(response.data.ok === false)) {
770
- _context16.next = 19;
771
- break;
772
- }
773
- return _context16.abrupt("return", this._handleError(response));
850
+ return _context16.abrupt("return", _context16.sent);
774
851
  case 19:
775
- // Process items into RbtObject instances
776
- if (Array.isArray(response.data.items)) {
777
- response.data.items = response.data.items.map(function (record) {
778
- return new _rbt_object["default"](record, _this.axios, {
779
- isNew: true
780
- });
781
- });
782
- }
783
- return _context16.abrupt("return", response.data.items);
784
- case 23:
785
- _context16.prev = 23;
852
+ _context16.prev = 19;
786
853
  _context16.t0 = _context16["catch"](1);
787
854
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
855
+ //console.log('RBTAPI.query ERROR', paramsKey, e);
788
856
  return _context16.abrupt("return", this._handleError(_context16.t0));
789
- case 27:
857
+ case 23:
790
858
  case "end":
791
859
  return _context16.stop();
792
860
  }
793
- }, _callee16, this, [[1, 23]]);
861
+ }, _callee16, this, [[1, 19]]);
794
862
  }));
795
863
  function query(_x11) {
796
864
  return _query.apply(this, arguments);
797
865
  }
798
866
  return query;
799
- }()
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
+
800
888
  /**
801
889
  * Loads one or multiple objects of a given type by their IDs.
802
890
  *
@@ -805,7 +893,6 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
805
893
  *
806
894
  * @returns {Promise<RbtObject|RbtObject[]>} - The loaded object(s) as RbtObject(s).
807
895
  */
808
- )
809
896
  }, {
810
897
  key: "load",
811
898
  value: (function () {
@@ -1018,7 +1105,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1018
1105
  key: "pollTaskProgress",
1019
1106
  value: (function () {
1020
1107
  var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(jobId, callbacks) {
1021
- var _this2 = this;
1108
+ var _this3 = this;
1022
1109
  var onProgress, onError, onStopped, onDone, checkProgress;
1023
1110
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1024
1111
  while (1) switch (_context21.prev = _context21.next) {
@@ -1032,7 +1119,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1032
1119
  while (1) switch (_context20.prev = _context20.next) {
1033
1120
  case 0:
1034
1121
  _context20.next = 2;
1035
- return _this2.get("/task_service/pollChainProgress", {
1122
+ return _this3.get("/task_service/pollChainProgress", {
1036
1123
  jobId: jobId
1037
1124
  });
1038
1125
  case 2:
@@ -1113,35 +1200,34 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1113
1200
  while (1) switch (_context22.prev = _context22.next) {
1114
1201
  case 0:
1115
1202
  params = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
1116
- debugger;
1117
- _context22.prev = 2;
1203
+ _context22.prev = 1;
1118
1204
  // Add the authToken to the headers
1119
1205
  headers = {
1120
1206
  authtoken: this.authtoken
1121
1207
  }; // Make the GET request using Axios
1122
- _context22.next = 6;
1208
+ _context22.next = 5;
1123
1209
  return this.axios.get(endpoint, {
1124
1210
  params: params,
1125
1211
  headers: headers
1126
1212
  });
1127
- case 6:
1213
+ case 5:
1128
1214
  response = _context22.sent;
1129
1215
  if (!(response.data.ok === false)) {
1130
- _context22.next = 9;
1216
+ _context22.next = 8;
1131
1217
  break;
1132
1218
  }
1133
1219
  return _context22.abrupt("return", this._handleError(response));
1134
- case 9:
1220
+ case 8:
1135
1221
  return _context22.abrupt("return", response.data);
1136
- case 12:
1137
- _context22.prev = 12;
1138
- _context22.t0 = _context22["catch"](2);
1222
+ case 11:
1223
+ _context22.prev = 11;
1224
+ _context22.t0 = _context22["catch"](1);
1139
1225
  return _context22.abrupt("return", this._handleError(_context22.t0));
1140
- case 15:
1226
+ case 14:
1141
1227
  case "end":
1142
1228
  return _context22.stop();
1143
1229
  }
1144
- }, _callee22, this, [[2, 12]]);
1230
+ }, _callee22, this, [[1, 11]]);
1145
1231
  }));
1146
1232
  function get(_x16) {
1147
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
@@ -362,39 +453,50 @@ export default class RbtApi {
362
453
  const cacheEntry = this.requestCache[paramsKey];
363
454
  if (cacheEntry && currentTime - cacheEntry.time < 10000) {
364
455
  // 10000 ms = 10 seconds
365
- console.log("Using cached request for params:", paramsKey);
456
+ //console.log('RBTAPI.query CACHED', type, paramsKey);
366
457
  return cacheEntry.val;
367
458
  }
368
459
 
369
- // Create the response promise and store it in the cache
460
+ // Create the response promise
370
461
  const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
371
462
 
372
- // 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
373
471
  this.requestCache[paramsKey] = {
374
- val: responsePromise,
472
+ val: processingPromise,
375
473
  time: currentTime
376
474
  };
377
475
 
378
- // Await the response from the API
379
- const response = await responsePromise;
380
- if (response.data.ok === false) {
381
- return this._handleError(response);
382
- }
383
-
384
- // Process items into RbtObject instances
385
- if (Array.isArray(response.data.items)) {
386
- response.data.items = response.data.items.map(record => {
387
- return new RbtObject(record, this.axios, {
388
- isNew: true
389
- });
390
- });
391
- }
392
- return response.data.items;
476
+ // Await the processing promise for this call to get processed data
477
+ return await processingPromise;
393
478
  } catch (e) {
394
479
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
480
+ //console.log('RBTAPI.query ERROR', paramsKey, e);
395
481
  return this._handleError(e);
396
482
  }
397
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
+ }
398
500
 
399
501
  /**
400
502
  * Loads one or multiple objects of a given type by their IDs.
@@ -588,7 +690,6 @@ export default class RbtApi {
588
690
  * @returns {Promise<Object>} - The response data from the API.
589
691
  */
590
692
  async get(endpoint, params = {}) {
591
- debugger;
592
693
  try {
593
694
  // Add the authToken to the headers
594
695
  const headers = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.38",
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
@@ -423,41 +515,50 @@ export default class RbtApi {
423
515
  const paramsKey = JSON.stringify(mergedParams);
424
516
  const cacheEntry = this.requestCache[paramsKey];
425
517
  if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
426
- console.log("Using cached request for params:", paramsKey);
518
+ //console.log('RBTAPI.query CACHED', type, paramsKey);
427
519
  return cacheEntry.val;
428
520
  }
429
521
 
430
- // Create the response promise and store it in the cache
522
+ // Create the response promise
431
523
  const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
432
524
 
433
- // Store the promise along with the current time in the cache
434
- this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
435
-
436
- // Await the response from the API
437
- const response = await responsePromise;
438
-
439
- if (response.data.ok === false) {
440
- return this._handleError(response);
441
- }
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
+ });
442
531
 
443
- // Process items into RbtObject instances
444
- if (Array.isArray(response.data.items)) {
445
- response.data.items = response.data.items.map(record => {
446
- return new RbtObject(record, this.axios, { isNew: true });
447
- });
448
- }
532
+ // Store the promise of the processed data in the cache
533
+ this.requestCache[paramsKey] = { val: processingPromise, time: currentTime };
449
534
 
450
- return response.data.items;
535
+ // Await the processing promise for this call to get processed data
536
+ return await processingPromise;
451
537
 
452
538
  } catch (e) {
453
-
454
539
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
540
+ //console.log('RBTAPI.query ERROR', paramsKey, e);
455
541
  return this._handleError(e);
456
-
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
+ });
457
555
  }
458
556
 
557
+ //console.log('RBTAPI.query RESPONSE POST', response.data.items);
558
+ return response.data.items;
459
559
  }
460
560
 
561
+
461
562
  /**
462
563
  * Loads one or multiple objects of a given type by their IDs.
463
564
  *
@@ -635,7 +736,7 @@ export default class RbtApi {
635
736
  * @returns {Promise<Object>} - The response data from the API.
636
737
  */
637
738
  async get(endpoint, params = {}) {
638
- debugger;
739
+
639
740
  try {
640
741
 
641
742
  // Add the authToken to the headers