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