@como/como-client 0.7.3 → 0.7.52

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/lib/como.js CHANGED
@@ -4,6 +4,10 @@ var _keys = require('babel-runtime/core-js/object/keys');
4
4
 
5
5
  var _keys2 = _interopRequireDefault(_keys);
6
6
 
7
+ var _stringify = require('babel-runtime/core-js/json/stringify');
8
+
9
+ var _stringify2 = _interopRequireDefault(_stringify);
10
+
7
11
  var _promise = require('babel-runtime/core-js/promise');
8
12
 
9
13
  var _promise2 = _interopRequireDefault(_promise);
@@ -144,7 +148,7 @@ var Como = function () {
144
148
 
145
149
  var enableSignon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
146
150
 
147
- var isExists, environmentId, locationId, installationId, source, updateCredentials, getCredentials, gateway, _APIService$getServic, service, refresher, initService, accessToken, refreshToken, expiresIn, credExist, isExpired, refreshFailed, data, interval, _data;
151
+ var isExists, environmentId, locationId, installationId, source, updateCredentials, getCredentials, gateway, _APIService$getServic, service, refresher, initService, accessToken, refreshToken, expiresIn, credExist, isExpired, refreshFailed, data, interval, _data, _data2;
148
152
 
149
153
  return _regenerator2.default.wrap(function _callee2$(_context2) {
150
154
  while (1) {
@@ -214,9 +218,9 @@ var Como = function () {
214
218
  _context2.prev = 24;
215
219
  _context2.t0 = _context2['catch'](17);
216
220
 
217
- console.log('Failed to refresh token, installationId:' + installationId + ', refreshToken:' + this.comoData.refreshToken + ', locationId:' + locationId + ', source:' + source);
221
+ console.error('Failed to refresh token, installationId:' + installationId + ', refreshToken:' + this.comoData.refreshToken + ', locationId:' + locationId + ', source:' + source);
218
222
  //refresh failed - need to revoke and signOn again
219
- initService.logError({ method: 'refreshToken', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken });
223
+ initService.logError({ method: 'refreshToken', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, error: _context2.t0.message });
220
224
  refreshFailed = true;
221
225
 
222
226
  case 29:
@@ -249,9 +253,9 @@ var Como = function () {
249
253
  _context2.prev = 40;
250
254
  _context2.t1 = _context2['catch'](32);
251
255
 
252
- console.log('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',interval:' + interval + ', error:' + _context2.t1);
256
+ console.error('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',interval:' + interval + ', error:' + _context2.t1);
253
257
  interval += 1000;
254
- initService.logError({ method: 'signOn', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval });
258
+ initService.logError({ method: 'signOn', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval, error: _context2.t1.message });
255
259
  _context2.next = 47;
256
260
  return new _promise2.default(function (r) {
257
261
  return setTimeout(r, interval);
@@ -262,38 +266,50 @@ var Como = function () {
262
266
  break;
263
267
 
264
268
  case 49:
265
- _context2.next = 60;
269
+ _context2.next = 64;
266
270
  break;
267
271
 
268
272
  case 51:
269
- _context2.prev = 51;
273
+ if (isExpired) {
274
+ _context2.next = 64;
275
+ break;
276
+ }
270
277
 
271
- console.error('signOn with, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken);
272
- _context2.next = 55;
278
+ _context2.prev = 52;
279
+
280
+ console.log('signOn with installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken);
281
+ _context2.next = 56;
273
282
  return this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
274
283
 
275
- case 55:
276
- _context2.next = 60;
284
+ case 56:
285
+ _data2 = _context2.sent;
286
+
287
+ console.log('signOn with result " ' + (0, _stringify2.default)(_data2));
288
+ if (_data2 && _data2.accessToken) {
289
+ console.log('signOn- updating credentials');
290
+ updateCredentials(_data2, true);
291
+ }
292
+ _context2.next = 64;
277
293
  break;
278
294
 
279
- case 57:
280
- _context2.prev = 57;
281
- _context2.t2 = _context2['catch'](51);
295
+ case 61:
296
+ _context2.prev = 61;
297
+ _context2.t2 = _context2['catch'](52);
282
298
 
283
- console.log('Failed signOn with accessToken, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken + ', error:' + _context2.t2);
299
+ console.error('Failed signOn with accessToken, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken + ', error:' + _context2.t2.message);
284
300
 
285
- case 60:
301
+ case 64:
286
302
  if (!this.comoData.token) {
287
303
  this.comoData.token = this.comoData.accessToken;
288
304
  }
289
305
  return _context2.abrupt('return', this.getCredentials());
290
306
 
291
- case 62:
307
+ case 66:
292
308
  case 'end':
293
309
  return _context2.stop();
294
310
  }
295
311
  }
296
- }, _callee2, this, [[17, 24], [32, 40], [51, 57]]);
312
+ }, _callee2, this, [[17, 24], [32, 40], [52, 61]]);
297
313
  }));
298
314
 
299
315
  function init(_x, _x2, _x3) {
@@ -40,18 +40,15 @@ exports.signOn = function (service) {
40
40
  if (accessToken) {
41
41
  headers['Authorization'] = "Bearer " + accessToken;
42
42
  }
43
- console.error("signOn(auth) with deviceId:" + deviceId + ", locationId:" + locationId + ", source:" + source + ",accessToken:" + accessToken + ", headers: " + headers);
44
- _context.next = 6;
43
+ _context.next = 5;
45
44
  return service.post('/auth/v2/auth/signOn', params, { headers: headers });
46
45
 
47
- case 6:
46
+ case 5:
48
47
  _ref2 = _context.sent;
49
48
  data = _ref2.data;
50
-
51
- console.error("signOn(auth) result with data:" + data);
52
49
  return _context.abrupt("return", data);
53
50
 
54
- case 10:
51
+ case 8:
55
52
  case "end":
56
53
  return _context.stop();
57
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@como/como-client",
3
- "version": "0.7.3",
3
+ "version": "0.7.52",
4
4
  "description": "Client module for Como's loaylty API",
5
5
  "main": "src/como.js",
6
6
  "scripts": {
package/src/como.js CHANGED
@@ -109,9 +109,9 @@ class Como {
109
109
  const data = await this.comoData.initApi.refreshToken(installationId, refreshToken? refreshToken: 'none', locationId, source);
110
110
  updateCredentials(data, true);
111
111
  }catch(e){
112
- console.log(`Failed to refresh token, installationId:${installationId}, refreshToken:${this.comoData.refreshToken}, locationId:${locationId}, source:${source}`);
112
+ console.error(`Failed to refresh token, installationId:${installationId}, refreshToken:${this.comoData.refreshToken}, locationId:${locationId}, source:${source}`);
113
113
  //refresh failed - need to revoke and signOn again
114
- initService.logError({method: 'refreshToken', installationId, locationId, source, refreshToken});
114
+ initService.logError({method: 'refreshToken', installationId, locationId, source, refreshToken, error : e.message});
115
115
  refreshFailed = true;
116
116
  }
117
117
  }
@@ -123,21 +123,25 @@ class Como {
123
123
  updateCredentials(data, true);
124
124
  credExist = true;
125
125
  }catch(e){
126
- console.log(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source},interval:${interval}, error:${e}`);
126
+ console.error(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source},interval:${interval}, error:${e}`);
127
127
  interval += 1000;
128
- initService.logError({method: 'signOn', installationId, locationId, source, refreshToken, interval});
128
+ initService.logError({method: 'signOn', installationId, locationId, source, refreshToken, interval, error : e.message});
129
129
  await new Promise(r => setTimeout(r, interval));
130
130
  }
131
131
  }
132
132
  }
133
- else{
133
+ else if(!isExpired){
134
134
  try{
135
- console.error(`signOn with, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}`);
136
- await this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
135
+ console.log(`signOn with installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}`);
136
+ const data = await this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
137
+ console.log(`signOn with result " ${JSON.stringify(data)}`);
138
+ if(data && data.accessToken){
139
+ console.log(`signOn- updating credentials`);
140
+ updateCredentials(data, true);
141
+ }
137
142
  }catch(e){
138
- console.log(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e}`);
143
+ console.error(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e.message}`);
139
144
  }
140
-
141
145
  }
142
146
  if(!this.comoData.token){
143
147
  this.comoData.token = this.comoData.accessToken;