roboto-js 1.3.4 → 1.3.6

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.
@@ -35,6 +35,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
35
35
  _ref$localStorageAdap = _ref.localStorageAdaptor,
36
36
  localStorageAdaptor = _ref$localStorageAdap === void 0 ? null : _ref$localStorageAdap;
37
37
  _classCallCheck(this, RbtApi);
38
+ console.log('RbtApi');
39
+ console.log(' .. localStorageAdaptor', localStorageAdaptor);
38
40
  this.axios = _axios["default"].create({
39
41
  baseURL: baseUrl,
40
42
  headers: {
@@ -56,6 +58,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
56
58
  }
57
59
  };
58
60
  }
61
+ console.log(' .. this.localStorageAdaptor', this.localStorageAdaptor);
59
62
  this.localDb = null;
60
63
  this.iac_session = null;
61
64
  this.appServiceHost = null;
@@ -146,38 +149,45 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
146
149
  while (1) switch (_context3.prev = _context3.next) {
147
150
  case 0:
148
151
  _context3.prev = 0;
152
+ console.log('RbtApi.login with localStorageAdaptor', this.localStorageAdaptor);
149
153
  // create a md5 hash of the password using crypto-js
150
154
  hash_password = _cryptoJs["default"].MD5(params.password).toString(_cryptoJs["default"].enc.Hex);
151
- _context3.next = 4;
155
+ _context3.next = 5;
152
156
  return this.axios.post('/user_service/loginUser', [{
153
157
  email: params.email,
154
158
  password: hash_password
155
159
  }]);
156
- case 4:
160
+ case 5:
157
161
  response = _context3.sent;
158
162
  if (!(response.data.ok === false)) {
159
- _context3.next = 7;
163
+ _context3.next = 8;
160
164
  break;
161
165
  }
162
166
  return _context3.abrupt("return", this._handleError(response));
163
- case 7:
167
+ case 8:
164
168
  this.iac_session = response.data;
165
169
  this.currentUser = this.iac_session ? new _rbt_user["default"](this.iac_session.user, this.axios) : null;
166
170
  // update axios instance headers with authtoken
167
171
  this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
168
- if (typeof localStorage != 'undefined') {
169
- localStorage.setItem('authtoken', response.data.authToken);
172
+ if (!this.localStorageAdaptor) {
173
+ _context3.next = 15;
174
+ break;
170
175
  }
176
+ console.log('RbtApi. localStorageAdaptor setItem', this.localStorageAdaptor);
177
+ _context3.next = 15;
178
+ return this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
179
+ case 15:
171
180
  return _context3.abrupt("return", response.data);
172
- case 14:
173
- _context3.prev = 14;
181
+ case 18:
182
+ _context3.prev = 18;
174
183
  _context3.t0 = _context3["catch"](0);
184
+ console.log('RbtApi. error', _context3.t0);
175
185
  this._handleError(_context3.t0);
176
- case 17:
186
+ case 22:
177
187
  case "end":
178
188
  return _context3.stop();
179
189
  }
180
- }, _callee3, this, [[0, 14]]);
190
+ }, _callee3, this, [[0, 18]]);
181
191
  }));
182
192
  function login(_x2) {
183
193
  return _login.apply(this, arguments);
@@ -211,21 +221,23 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
211
221
  }
212
222
 
213
223
  // Clear localStorage if it's being used
214
- if (typeof localStorage !== 'undefined') {
215
- localStorage.removeItem('authtoken');
224
+ if (!this.localStorageAdaptor) {
225
+ _context4.next = 12;
226
+ break;
216
227
  }
217
-
218
- // Return some kind of success response or the response from the server
228
+ _context4.next = 12;
229
+ return this.localStorageAdaptor.removeItem('authtoken');
230
+ case 12:
219
231
  return _context4.abrupt("return", response.data);
220
- case 13:
221
- _context4.prev = 13;
232
+ case 15:
233
+ _context4.prev = 15;
222
234
  _context4.t0 = _context4["catch"](0);
223
235
  this._handleError(_context4.t0);
224
- case 16:
236
+ case 18:
225
237
  case "end":
226
238
  return _context4.stop();
227
239
  }
228
- }, _callee4, this, [[0, 13]]);
240
+ }, _callee4, this, [[0, 15]]);
229
241
  }));
230
242
  function logout() {
231
243
  return _logout.apply(this, arguments);
@@ -13,6 +13,8 @@ export default class RbtApi {
13
13
  accesskey = null,
14
14
  localStorageAdaptor = null
15
15
  }) {
16
+ console.log('RbtApi');
17
+ console.log(' .. localStorageAdaptor', localStorageAdaptor);
16
18
  this.axios = axios.create({
17
19
  baseURL: baseUrl,
18
20
  headers: {
@@ -30,6 +32,7 @@ export default class RbtApi {
30
32
  setItem: (key, value) => Promise.resolve(localStorage.setItem(key, value))
31
33
  };
32
34
  }
35
+ console.log(' .. this.localStorageAdaptor', this.localStorageAdaptor);
33
36
  this.localDb = null;
34
37
  this.iac_session = null;
35
38
  this.appServiceHost = null;
@@ -70,6 +73,7 @@ export default class RbtApi {
70
73
  */
71
74
  async login(params) {
72
75
  try {
76
+ console.log('RbtApi.login with localStorageAdaptor', this.localStorageAdaptor);
73
77
  // create a md5 hash of the password using crypto-js
74
78
  const hash_password = CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex);
75
79
  const response = await this.axios.post('/user_service/loginUser', [{
@@ -83,11 +87,13 @@ export default class RbtApi {
83
87
  this.currentUser = this.iac_session ? new RbtUser(this.iac_session.user, this.axios) : null;
84
88
  // update axios instance headers with authtoken
85
89
  this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
86
- if (typeof localStorage != 'undefined') {
87
- localStorage.setItem('authtoken', response.data.authToken);
90
+ if (this.localStorageAdaptor) {
91
+ console.log('RbtApi. localStorageAdaptor setItem', this.localStorageAdaptor);
92
+ await this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
88
93
  }
89
94
  return response.data;
90
95
  } catch (e) {
96
+ console.log('RbtApi. error', e);
91
97
  this._handleError(e);
92
98
  }
93
99
  }
@@ -108,8 +114,8 @@ export default class RbtApi {
108
114
  }
109
115
 
110
116
  // Clear localStorage if it's being used
111
- if (typeof localStorage !== 'undefined') {
112
- localStorage.removeItem('authtoken');
117
+ if (this.localStorageAdaptor) {
118
+ await this.localStorageAdaptor.removeItem('authtoken');
113
119
  }
114
120
 
115
121
  // Return some kind of success response or the response from the server
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -10,6 +10,8 @@ export default class RbtApi {
10
10
 
11
11
  constructor({ apiKey, baseUrl, authtoken=null, accesskey=null, localStorageAdaptor=null }) {
12
12
 
13
+ console.log('RbtApi');
14
+ console.log(' .. localStorageAdaptor', localStorageAdaptor);
13
15
  this.axios = axios.create({
14
16
  baseURL: baseUrl,
15
17
  headers: {
@@ -29,6 +31,9 @@ export default class RbtApi {
29
31
  setItem: (key, value) => Promise.resolve(localStorage.setItem(key, value)),
30
32
  };
31
33
  }
34
+
35
+ console.log(' .. this.localStorageAdaptor', this.localStorageAdaptor);
36
+
32
37
  this.localDb = null;
33
38
  this.iac_session = null;
34
39
  this.appServiceHost = null;
@@ -79,6 +84,8 @@ export default class RbtApi {
79
84
  async login(params) {
80
85
  try {
81
86
 
87
+
88
+ console.log('RbtApi.login with localStorageAdaptor', this.localStorageAdaptor);
82
89
  // create a md5 hash of the password using crypto-js
83
90
  const hash_password = CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex);
84
91
 
@@ -97,13 +104,15 @@ export default class RbtApi {
97
104
  // update axios instance headers with authtoken
98
105
  this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
99
106
 
100
- if(typeof localStorage != 'undefined'){
101
- localStorage.setItem('authtoken', response.data.authToken);
107
+ if(this.localStorageAdaptor){
108
+ console.log('RbtApi. localStorageAdaptor setItem', this.localStorageAdaptor);
109
+ await this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
102
110
  }
103
111
 
104
112
  return response.data;
105
113
  } catch (e) {
106
114
 
115
+ console.log('RbtApi. error', e);
107
116
  this._handleError(e);
108
117
  }
109
118
  }
@@ -126,8 +135,8 @@ export default class RbtApi {
126
135
  }
127
136
 
128
137
  // Clear localStorage if it's being used
129
- if (typeof localStorage !== 'undefined') {
130
- localStorage.removeItem('authtoken');
138
+ if (this.localStorageAdaptor) {
139
+ await this.localStorageAdaptor.removeItem('authtoken');
131
140
  }
132
141
 
133
142
  // Return some kind of success response or the response from the server