@como/como-client 0.7.98 → 0.8.0

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.
Files changed (3) hide show
  1. package/lib/como.js +46 -45
  2. package/package.json +1 -1
  3. package/src/como.js +5 -3
package/lib/como.js CHANGED
@@ -4,14 +4,14 @@ 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
-
11
7
  var _promise = require('babel-runtime/core-js/promise');
12
8
 
13
9
  var _promise2 = _interopRequireDefault(_promise);
14
10
 
11
+ var _stringify = require('babel-runtime/core-js/json/stringify');
12
+
13
+ var _stringify2 = _interopRequireDefault(_stringify);
14
+
15
15
  var _extends2 = require('babel-runtime/helpers/extends');
16
16
 
17
17
  var _extends3 = _interopRequireDefault(_extends2);
@@ -201,7 +201,7 @@ var Como = function () {
201
201
  refreshFailed = false;
202
202
 
203
203
  if (!isExpired) {
204
- _context2.next = 29;
204
+ _context2.next = 30;
205
205
  break;
206
206
  }
207
207
 
@@ -212,12 +212,13 @@ var Como = function () {
212
212
  case 20:
213
213
  data = _context2.sent;
214
214
 
215
+ console.log('signOn with isExpired true result:' + (0, _stringify2.default)(data));
215
216
  updateCredentials(data, true);
216
- _context2.next = 29;
217
+ _context2.next = 30;
217
218
  break;
218
219
 
219
- case 24:
220
- _context2.prev = 24;
220
+ case 25:
221
+ _context2.prev = 25;
221
222
  _context2.t0 = _context2['catch'](17);
222
223
 
223
224
  console.error('Failed to refresh token, installationId:' + installationId + ', refreshToken:' + this.comoData.refreshToken + ', locationId:' + locationId + ', source:' + source);
@@ -225,73 +226,74 @@ var Como = function () {
225
226
  initService.logError({ method: 'refreshToken', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, error: _context2.t0.message });
226
227
  refreshFailed = true;
227
228
 
228
- case 29:
229
+ case 30:
229
230
  interval = 0;
230
231
 
231
232
  if (!(refreshFailed || !credExist)) {
232
- _context2.next = 51;
233
+ _context2.next = 53;
233
234
  break;
234
235
  }
235
236
 
236
- case 31:
237
+ case 32:
237
238
  if (!(!credExist && interval < 3000)) {
238
- _context2.next = 49;
239
+ _context2.next = 51;
239
240
  break;
240
241
  }
241
242
 
242
- _context2.prev = 32;
243
- _context2.next = 35;
243
+ _context2.prev = 33;
244
+ _context2.next = 36;
244
245
  return this.comoData.initApi.signOn(installationId, locationId, source);
245
246
 
246
- case 35:
247
+ case 36:
247
248
  _data = _context2.sent;
248
249
 
250
+ console.log('signOn with refreshFailed result:' + (0, _stringify2.default)(_data));
249
251
  updateCredentials(_data, true);
250
252
  credExist = true;
251
- _context2.next = 47;
253
+ _context2.next = 49;
252
254
  break;
253
255
 
254
- case 40:
255
- _context2.prev = 40;
256
- _context2.t1 = _context2['catch'](32);
256
+ case 42:
257
+ _context2.prev = 42;
258
+ _context2.t1 = _context2['catch'](33);
257
259
 
258
260
  console.error('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',interval:' + interval + ', error:' + _context2.t1);
259
261
  interval += 1000;
260
262
  initService.logError({ method: 'signOn no accessToken', accessToken: accessToken, isExpired: isExpired, refreshFailed: refreshFailed, credExist: credExist, installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval, error: _context2.t1.message });
261
- _context2.next = 47;
263
+ _context2.next = 49;
262
264
  return new _promise2.default(function (r) {
263
265
  return setTimeout(r, interval);
264
266
  });
265
267
 
266
- case 47:
267
- _context2.next = 31;
268
- break;
269
-
270
268
  case 49:
271
- _context2.next = 74;
269
+ _context2.next = 32;
272
270
  break;
273
271
 
274
272
  case 51:
273
+ _context2.next = 76;
274
+ break;
275
+
276
+ case 53:
275
277
  if (isExpired) {
276
- _context2.next = 74;
278
+ _context2.next = 76;
277
279
  break;
278
280
  }
279
281
 
280
282
  signOnSuccessfully = false;
281
283
 
282
- case 53:
284
+ case 55:
283
285
  if (!(!signOnSuccessfully && interval < 3000)) {
284
- _context2.next = 74;
286
+ _context2.next = 76;
285
287
  break;
286
288
  }
287
289
 
288
- _context2.prev = 54;
290
+ _context2.prev = 56;
289
291
 
290
292
  console.log('signOn with installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken);
291
- _context2.next = 58;
293
+ _context2.next = 60;
292
294
  return this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
293
295
 
294
- case 58:
296
+ case 60:
295
297
  _data2 = _context2.sent;
296
298
 
297
299
  console.log('signOn with result " ' + (0, _stringify2.default)(_data2));
@@ -303,37 +305,37 @@ var Como = function () {
303
305
  this.comoData.reCaptchaSiteKey = _data2.config.recaptchaSiteKey;
304
306
  }
305
307
  signOnSuccessfully = true;
306
- _context2.next = 72;
308
+ _context2.next = 74;
307
309
  break;
308
310
 
309
- case 65:
310
- _context2.prev = 65;
311
- _context2.t2 = _context2['catch'](54);
311
+ case 67:
312
+ _context2.prev = 67;
313
+ _context2.t2 = _context2['catch'](56);
312
314
 
313
315
  console.error('Failed signOn with accessToken, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken + ', error:' + _context2.t2.message);
314
316
  interval += 1000;
315
317
  initService.logError({ method: 'signOn with credentials', accessToken: accessToken, isExpired: isExpired, refreshFailed: refreshFailed, credExist: credExist, installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval, error: _context2.t2.message });
316
- _context2.next = 72;
318
+ _context2.next = 74;
317
319
  return new _promise2.default(function (r) {
318
320
  return setTimeout(r, interval);
319
321
  });
320
322
 
321
- case 72:
322
- _context2.next = 53;
323
+ case 74:
324
+ _context2.next = 55;
323
325
  break;
324
326
 
325
- case 74:
327
+ case 76:
326
328
  if (!this.comoData.token) {
327
329
  this.comoData.token = this.comoData.accessToken;
328
330
  }
329
331
  return _context2.abrupt('return', this.getCredentials());
330
332
 
331
- case 76:
333
+ case 78:
332
334
  case 'end':
333
335
  return _context2.stop();
334
336
  }
335
337
  }
336
- }, _callee2, this, [[17, 24], [32, 40], [54, 65]]);
338
+ }, _callee2, this, [[17, 25], [33, 42], [56, 67]]);
337
339
  }));
338
340
 
339
341
  function init(_x, _x2, _x3) {
@@ -362,7 +364,7 @@ var Como = function () {
362
364
  this.comoData.token = credentials.accessToken;
363
365
  this.comoData.refreshToken = credentials.refreshToken;
364
366
  this.comoData.expiresIn = credentials.expiresIn;
365
- if (credentials.config) {
367
+ if (credentials && credentials.config) {
366
368
  this.comoData.reCaptchaSiteKey = credentials.config.recaptchaSiteKey;
367
369
  if (credentials.config.recaptcha) {
368
370
  this.comoData.recaptchaConfig = credentials.config.recaptcha;
@@ -1652,11 +1654,10 @@ var Como = function () {
1652
1654
  refreshToken = _comoData22.refreshToken,
1653
1655
  expiresIn = _comoData22.expiresIn,
1654
1656
  consent = _comoData22.consent,
1655
- locationId = _comoData22.locationId,
1656
- recaptchaConfig = _comoData22.recaptchaConfig;
1657
+ locationId = _comoData22.locationId;
1657
1658
 
1658
1659
  return {
1659
- accessToken: accessToken, refreshToken: refreshToken, expiresIn: expiresIn, consent: consent, locationId: locationId, recaptchaConfig: recaptchaConfig
1660
+ accessToken: accessToken, refreshToken: refreshToken, expiresIn: expiresIn, consent: consent, locationId: locationId
1660
1661
  };
1661
1662
  }
1662
1663
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@como/como-client",
3
- "version": "0.7.98",
3
+ "version": "0.8.0",
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,6 +109,7 @@ class Como {
109
109
  if(isExpired){
110
110
  try{
111
111
  const data = await this.comoData.initApi.refreshToken(installationId, refreshToken? refreshToken: 'none', locationId, source);
112
+ console.log(`signOn with isExpired true result:${JSON.stringify(data)}`);
112
113
  updateCredentials(data, true);
113
114
  }catch(e){
114
115
  console.error(`Failed to refresh token, installationId:${installationId}, refreshToken:${this.comoData.refreshToken}, locationId:${locationId}, source:${source}`);
@@ -122,6 +123,7 @@ class Como {
122
123
  while(!credExist && interval < 3000){
123
124
  try{
124
125
  const data = await this.comoData.initApi.signOn(installationId, locationId, source);
126
+ console.log(`signOn with refreshFailed result:${JSON.stringify(data)}`);
125
127
  updateCredentials(data, true);
126
128
  credExist = true;
127
129
  }catch(e){
@@ -175,7 +177,7 @@ class Como {
175
177
  this.comoData.token = credentials.accessToken;
176
178
  this.comoData.refreshToken = credentials.refreshToken;
177
179
  this.comoData.expiresIn = credentials.expiresIn;
178
- if(credentials.config){
180
+ if (credentials && credentials.config) {
179
181
  this.comoData.reCaptchaSiteKey = credentials.config.recaptchaSiteKey;
180
182
  if (credentials.config.recaptcha) {
181
183
  this.comoData.recaptchaConfig = credentials.config.recaptcha;
@@ -690,10 +692,10 @@ class Como {
690
692
  */
691
693
  getCredentials() {
692
694
  const {
693
- accessToken, refreshToken, expiresIn, consent, locationId, recaptchaConfig,
695
+ accessToken, refreshToken, expiresIn, consent, locationId,
694
696
  } = this.comoData;
695
697
  return {
696
- accessToken, refreshToken, expiresIn, consent, locationId, recaptchaConfig,
698
+ accessToken, refreshToken, expiresIn, consent, locationId,
697
699
  };
698
700
  }
699
701