@como/como-client 0.7.4 → 0.7.53
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 +44 -20
- package/lib/services/auth.service.js +3 -6
- package/package.json +1 -1
- package/src/como.js +21 -14
package/lib/como.js
CHANGED
|
@@ -148,7 +148,7 @@ var Como = function () {
|
|
|
148
148
|
|
|
149
149
|
var enableSignon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
150
150
|
|
|
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;
|
|
151
|
+
var isExists, environmentId, locationId, installationId, source, updateCredentials, getCredentials, gateway, _APIService$getServic, service, refresher, initService, accessToken, refreshToken, expiresIn, credExist, isExpired, refreshFailed, data, interval, _data, signOnSuccessfully, _data2;
|
|
152
152
|
|
|
153
153
|
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
|
154
154
|
while (1) {
|
|
@@ -218,9 +218,9 @@ var Como = function () {
|
|
|
218
218
|
_context2.prev = 24;
|
|
219
219
|
_context2.t0 = _context2['catch'](17);
|
|
220
220
|
|
|
221
|
-
console.
|
|
221
|
+
console.error('Failed to refresh token, installationId:' + installationId + ', refreshToken:' + this.comoData.refreshToken + ', locationId:' + locationId + ', source:' + source);
|
|
222
222
|
//refresh failed - need to revoke and signOn again
|
|
223
|
-
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 });
|
|
224
224
|
refreshFailed = true;
|
|
225
225
|
|
|
226
226
|
case 29:
|
|
@@ -253,9 +253,9 @@ var Como = function () {
|
|
|
253
253
|
_context2.prev = 40;
|
|
254
254
|
_context2.t1 = _context2['catch'](32);
|
|
255
255
|
|
|
256
|
-
console.
|
|
256
|
+
console.error('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',interval:' + interval + ', error:' + _context2.t1);
|
|
257
257
|
interval += 1000;
|
|
258
|
-
initService.logError({ method: 'signOn', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval });
|
|
258
|
+
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 });
|
|
259
259
|
_context2.next = 47;
|
|
260
260
|
return new _promise2.default(function (r) {
|
|
261
261
|
return setTimeout(r, interval);
|
|
@@ -266,45 +266,69 @@ var Como = function () {
|
|
|
266
266
|
break;
|
|
267
267
|
|
|
268
268
|
case 49:
|
|
269
|
-
_context2.next =
|
|
269
|
+
_context2.next = 73;
|
|
270
270
|
break;
|
|
271
271
|
|
|
272
272
|
case 51:
|
|
273
|
-
|
|
273
|
+
if (isExpired) {
|
|
274
|
+
_context2.next = 73;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
signOnSuccessfully = false;
|
|
279
|
+
|
|
280
|
+
case 53:
|
|
281
|
+
if (!(!signOnSuccessfully && interval < 3000)) {
|
|
282
|
+
_context2.next = 73;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
_context2.prev = 54;
|
|
274
287
|
|
|
275
|
-
console.
|
|
276
|
-
_context2.next =
|
|
288
|
+
console.log('signOn with installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken);
|
|
289
|
+
_context2.next = 58;
|
|
277
290
|
return this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
|
|
278
291
|
|
|
279
|
-
case
|
|
292
|
+
case 58:
|
|
280
293
|
_data2 = _context2.sent;
|
|
281
294
|
|
|
282
|
-
console.
|
|
295
|
+
console.log('signOn with result " ' + (0, _stringify2.default)(_data2));
|
|
283
296
|
if (_data2 && _data2.accessToken) {
|
|
284
|
-
console.
|
|
297
|
+
console.log('signOn- updating credentials');
|
|
285
298
|
updateCredentials(_data2, true);
|
|
286
299
|
}
|
|
287
|
-
|
|
300
|
+
signOnSuccessfully = true;
|
|
301
|
+
_context2.next = 71;
|
|
288
302
|
break;
|
|
289
303
|
|
|
290
|
-
case
|
|
291
|
-
_context2.prev =
|
|
292
|
-
_context2.t2 = _context2['catch'](
|
|
304
|
+
case 64:
|
|
305
|
+
_context2.prev = 64;
|
|
306
|
+
_context2.t2 = _context2['catch'](54);
|
|
293
307
|
|
|
294
|
-
console.
|
|
308
|
+
console.error('Failed signOn with accessToken, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken + ', error:' + _context2.t2.message);
|
|
309
|
+
interval += 1000;
|
|
310
|
+
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 });
|
|
311
|
+
_context2.next = 71;
|
|
312
|
+
return new _promise2.default(function (r) {
|
|
313
|
+
return setTimeout(r, interval);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
case 71:
|
|
317
|
+
_context2.next = 53;
|
|
318
|
+
break;
|
|
295
319
|
|
|
296
|
-
case
|
|
320
|
+
case 73:
|
|
297
321
|
if (!this.comoData.token) {
|
|
298
322
|
this.comoData.token = this.comoData.accessToken;
|
|
299
323
|
}
|
|
300
324
|
return _context2.abrupt('return', this.getCredentials());
|
|
301
325
|
|
|
302
|
-
case
|
|
326
|
+
case 75:
|
|
303
327
|
case 'end':
|
|
304
328
|
return _context2.stop();
|
|
305
329
|
}
|
|
306
330
|
}
|
|
307
|
-
}, _callee2, this, [[17, 24], [32, 40], [
|
|
331
|
+
}, _callee2, this, [[17, 24], [32, 40], [54, 64]]);
|
|
308
332
|
}));
|
|
309
333
|
|
|
310
334
|
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
|
-
|
|
44
|
-
_context.next = 6;
|
|
43
|
+
_context.next = 5;
|
|
45
44
|
return service.post('/auth/v2/auth/signOn', params, { headers: headers });
|
|
46
45
|
|
|
47
|
-
case
|
|
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
|
|
51
|
+
case 8:
|
|
55
52
|
case "end":
|
|
56
53
|
return _context.stop();
|
|
57
54
|
}
|
package/package.json
CHANGED
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.
|
|
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,24 +123,31 @@ class Como {
|
|
|
123
123
|
updateCredentials(data, true);
|
|
124
124
|
credExist = true;
|
|
125
125
|
}catch(e){
|
|
126
|
-
console.
|
|
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 no accessToken', accessToken, isExpired, refreshFailed , credExist, 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{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
console.
|
|
140
|
-
|
|
133
|
+
else if(!isExpired){
|
|
134
|
+
let signOnSuccessfully = false;
|
|
135
|
+
while(!signOnSuccessfully && interval < 3000){
|
|
136
|
+
try{
|
|
137
|
+
console.log(`signOn with installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}`);
|
|
138
|
+
const data = await this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
|
|
139
|
+
console.log(`signOn with result " ${JSON.stringify(data)}`);
|
|
140
|
+
if(data && data.accessToken){
|
|
141
|
+
console.log(`signOn- updating credentials`);
|
|
142
|
+
updateCredentials(data, true);
|
|
143
|
+
}
|
|
144
|
+
signOnSuccessfully = true;
|
|
145
|
+
}catch(e){
|
|
146
|
+
console.error(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e.message}`);
|
|
147
|
+
interval += 1000;
|
|
148
|
+
initService.logError({method: 'signOn with credentials', accessToken, isExpired, refreshFailed , credExist, installationId, locationId, source, refreshToken, interval, error : e.message});
|
|
149
|
+
await new Promise(r => setTimeout(r, interval));
|
|
141
150
|
}
|
|
142
|
-
}catch(e){
|
|
143
|
-
console.log(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e}`);
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
if(!this.comoData.token){
|