roboto-js 1.6.0 → 1.6.2

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.
@@ -64,12 +64,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
64
64
  this.requestCache = {};
65
65
 
66
66
  // Use the storageAdaptor to get the authToken, if available
67
- if (authtoken) {
68
- this.initAuthToken(authtoken);
69
- }
70
- if (apikey) {
71
- this.initApiKey(apikey);
72
- }
67
+ this.initAuthToken(authtoken);
68
+ this.initApiKey(apikey);
73
69
  }
74
70
  _createClass(RbtApi, [{
75
71
  key: "initAuthToken",
@@ -87,9 +83,11 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
87
83
  case 3:
88
84
  authtoken = _context.sent;
89
85
  case 4:
90
- this.authtoken = authtoken;
91
- this.axios.defaults.headers.common['authtoken'] = this.authtoken;
92
- case 6:
86
+ if (authtoken) {
87
+ this.authtoken = authtoken;
88
+ this.axios.defaults.headers.common['authtoken'] = this.authtoken;
89
+ }
90
+ case 5:
93
91
  case "end":
94
92
  return _context.stop();
95
93
  }
@@ -116,9 +114,11 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
116
114
  case 3:
117
115
  apikey = _context2.sent;
118
116
  case 4:
119
- this.apikey = apikey;
120
- this.axios.defaults.headers.common['apikey'] = this.apikey;
121
- case 6:
117
+ if (apikey) {
118
+ this.apikey = apikey;
119
+ this.axios.defaults.headers.common['apikey'] = this.apikey;
120
+ }
121
+ case 5:
122
122
  case "end":
123
123
  return _context2.stop();
124
124
  }
@@ -893,11 +893,11 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
893
893
  var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(type) {
894
894
  var _this2 = this;
895
895
  var params,
896
+ paramsKey,
896
897
  defaultOrderBy,
897
898
  defaultLimit,
898
899
  mergedParams,
899
900
  currentTime,
900
- _paramsKey,
901
901
  cacheEntry,
902
902
  responsePromise,
903
903
  processingPromise,
@@ -925,8 +925,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
925
925
  }; // Merge defaults with provided params
926
926
  mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params); // Check cache for an existing request
927
927
  currentTime = Date.now();
928
- _paramsKey = JSON.stringify(mergedParams);
929
- cacheEntry = this.requestCache[_paramsKey];
928
+ paramsKey = JSON.stringify(mergedParams);
929
+ cacheEntry = this.requestCache[paramsKey];
930
930
  if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
931
931
  _context18.next = 11;
932
932
  break;
@@ -938,11 +938,11 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
938
938
  processingPromise = responsePromise.then(function (response) {
939
939
  return _this2._processResponseData(response);
940
940
  })["catch"](function (e) {
941
- delete _this2.requestCache[_paramsKey]; // Ensure cache cleanup on failure
941
+ delete _this2.requestCache[paramsKey]; // Ensure cache cleanup on failure
942
942
  //console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
943
943
  return _this2._handleError(e);
944
944
  }); // Store the promise of the processed data in the cache
945
- this.requestCache[_paramsKey] = {
945
+ this.requestCache[paramsKey] = {
946
946
  val: processingPromise,
947
947
  time: currentTime
948
948
  };
@@ -36,26 +36,26 @@ export default class RbtApi {
36
36
  this.requestCache = {};
37
37
 
38
38
  // Use the storageAdaptor to get the authToken, if available
39
- if (authtoken) {
40
- this.initAuthToken(authtoken);
41
- }
42
- if (apikey) {
43
- this.initApiKey(apikey);
44
- }
39
+ this.initAuthToken(authtoken);
40
+ this.initApiKey(apikey);
45
41
  }
46
42
  async initAuthToken(authtoken) {
47
43
  if (!authtoken && this.localStorageAdaptor) {
48
44
  authtoken = await this.localStorageAdaptor.getItem('authtoken');
49
45
  }
50
- this.authtoken = authtoken;
51
- this.axios.defaults.headers.common['authtoken'] = this.authtoken;
46
+ if (authtoken) {
47
+ this.authtoken = authtoken;
48
+ this.axios.defaults.headers.common['authtoken'] = this.authtoken;
49
+ }
52
50
  }
53
51
  async initApiKey(apikey) {
54
52
  if (!apikey && this.localStorageAdaptor) {
55
53
  apikey = await this.localStorageAdaptor.getItem('apikey');
56
54
  }
57
- this.apikey = apikey;
58
- this.axios.defaults.headers.common['apikey'] = this.apikey;
55
+ if (apikey) {
56
+ this.apikey = apikey;
57
+ this.axios.defaults.headers.common['apikey'] = this.apikey;
58
+ }
59
59
  }
60
60
  async initLocalDb() {
61
61
  this.localDb = await openDB('RBTFileDatabase', 1, {
@@ -470,6 +470,7 @@ export default class RbtApi {
470
470
  // }
471
471
 
472
472
  async query(type, params = {}) {
473
+ let paramsKey;
473
474
  try {
474
475
  //console.log('RBTAPI.query INIT', type, params);
475
476
  params.type = type;
@@ -497,7 +498,7 @@ export default class RbtApi {
497
498
 
498
499
  // Check cache for an existing request
499
500
  const currentTime = Date.now();
500
- const paramsKey = JSON.stringify(mergedParams);
501
+ paramsKey = JSON.stringify(mergedParams);
501
502
  const cacheEntry = this.requestCache[paramsKey];
502
503
  if (cacheEntry && currentTime - cacheEntry.time < 10000) {
503
504
  // 10000 ms = 10 seconds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -35,13 +35,9 @@ export default class RbtApi {
35
35
  this.requestCache = {};
36
36
 
37
37
  // Use the storageAdaptor to get the authToken, if available
38
- if(authtoken){
39
- this.initAuthToken(authtoken);
40
- }
41
- if(apikey){
42
- this.initApiKey(apikey);
43
- }
44
-
38
+ this.initAuthToken(authtoken);
39
+ this.initApiKey(apikey);
40
+
45
41
  }
46
42
 
47
43
  async initAuthToken(authtoken) {
@@ -50,9 +46,10 @@ export default class RbtApi {
50
46
  authtoken = await this.localStorageAdaptor.getItem('authtoken');
51
47
  }
52
48
 
53
- this.authtoken = authtoken;
54
- this.axios.defaults.headers.common['authtoken'] = this.authtoken;
55
-
49
+ if(authtoken){
50
+ this.authtoken = authtoken;
51
+ this.axios.defaults.headers.common['authtoken'] = this.authtoken;
52
+ }
56
53
  }
57
54
 
58
55
  async initApiKey(apikey) {
@@ -61,8 +58,10 @@ export default class RbtApi {
61
58
  apikey = await this.localStorageAdaptor.getItem('apikey');
62
59
  }
63
60
 
64
- this.apikey = apikey;
65
- this.axios.defaults.headers.common['apikey'] = this.apikey;
61
+ if(apikey){
62
+ this.apikey = apikey;
63
+ this.axios.defaults.headers.common['apikey'] = this.apikey;
64
+ }
66
65
 
67
66
  }
68
67
 
@@ -567,6 +566,8 @@ export default class RbtApi {
567
566
 
568
567
 
569
568
  async query(type, params = {}) {
569
+
570
+ let paramsKey;
570
571
  try {
571
572
  //console.log('RBTAPI.query INIT', type, params);
572
573
  params.type = type;
@@ -580,7 +581,7 @@ export default class RbtApi {
580
581
 
581
582
  // Check cache for an existing request
582
583
  const currentTime = Date.now();
583
- const paramsKey = JSON.stringify(mergedParams);
584
+ paramsKey = JSON.stringify(mergedParams);
584
585
  const cacheEntry = this.requestCache[paramsKey];
585
586
  if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
586
587
  //console.log('RBTAPI.query CACHED', type, paramsKey);