@como/como-client 0.1.9-1.20 → 0.1.9-1.24
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 +39 -24
- package/lib/interceptors/refresh.js +28 -44
- package/lib/services/index.js +3 -2
- package/package.json +1 -1
- package/src/como.js +13 -4
package/lib/como.js
CHANGED
|
@@ -217,7 +217,7 @@ var Como = function () {
|
|
|
217
217
|
_APIService$getServic = APIService.getService(gateway, installationId, getCredentials, updateCredentials, source), service = _APIService$getServic.service, refresher = _APIService$getServic.refresher, initService = _APIService$getServic.initService;
|
|
218
218
|
|
|
219
219
|
this.comoData.api = service;
|
|
220
|
-
this.comoData.
|
|
220
|
+
this.comoData.initApi = initService;
|
|
221
221
|
this.comoData.refresher = refresher;
|
|
222
222
|
|
|
223
223
|
accessToken = credentials.accessToken, refreshToken = credentials.refreshToken, expiresIn = credentials.expiresIn;
|
|
@@ -237,21 +237,23 @@ var Como = function () {
|
|
|
237
237
|
|
|
238
238
|
case 22:
|
|
239
239
|
if (!credsNotExist) {
|
|
240
|
-
_context3.next =
|
|
240
|
+
_context3.next = 35;
|
|
241
241
|
break;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
_context3.prev = 23;
|
|
245
245
|
_context3.next = 26;
|
|
246
|
-
return this.
|
|
246
|
+
return this.comoData.initApi.signOn(installationId, locationId, refreshToken, source);
|
|
247
247
|
|
|
248
248
|
case 26:
|
|
249
249
|
data = _context3.sent;
|
|
250
|
-
|
|
250
|
+
|
|
251
|
+
updateCredentials(data, true);
|
|
252
|
+
_context3.next = 35;
|
|
251
253
|
break;
|
|
252
254
|
|
|
253
|
-
case
|
|
254
|
-
_context3.prev =
|
|
255
|
+
case 30:
|
|
256
|
+
_context3.prev = 30;
|
|
255
257
|
_context3.t1 = _context3['catch'](23);
|
|
256
258
|
|
|
257
259
|
//TODO: need to parse error
|
|
@@ -259,53 +261,66 @@ var Como = function () {
|
|
|
259
261
|
isExpired = true; // user uid exist - do refresh
|
|
260
262
|
this.comoData.refreshToken = 'none';
|
|
261
263
|
|
|
262
|
-
case
|
|
264
|
+
case 35:
|
|
263
265
|
refreshFailed = false;
|
|
264
266
|
|
|
265
267
|
if (!isExpired) {
|
|
266
|
-
_context3.next =
|
|
268
|
+
_context3.next = 48;
|
|
267
269
|
break;
|
|
268
270
|
}
|
|
269
271
|
|
|
270
|
-
_context3.prev =
|
|
271
|
-
_context3.next =
|
|
272
|
-
return this.comoData.
|
|
272
|
+
_context3.prev = 37;
|
|
273
|
+
_context3.next = 40;
|
|
274
|
+
return this.comoData.initApi.refreshToken(installationId, refreshToken);
|
|
273
275
|
|
|
274
|
-
case
|
|
276
|
+
case 40:
|
|
275
277
|
_data = _context3.sent;
|
|
276
|
-
|
|
278
|
+
|
|
279
|
+
updateCredentials(_data, true);
|
|
280
|
+
_context3.next = 48;
|
|
277
281
|
break;
|
|
278
282
|
|
|
279
|
-
case
|
|
280
|
-
_context3.prev =
|
|
281
|
-
_context3.t2 = _context3['catch'](
|
|
283
|
+
case 44:
|
|
284
|
+
_context3.prev = 44;
|
|
285
|
+
_context3.t2 = _context3['catch'](37);
|
|
282
286
|
|
|
283
287
|
console.log('Failed to refresh token, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source);
|
|
284
288
|
//TODO: need to parse error
|
|
285
289
|
//refresh failed - need to revoke and signOn again
|
|
286
290
|
refreshFailed = true;
|
|
287
291
|
|
|
288
|
-
case
|
|
292
|
+
case 48:
|
|
289
293
|
if (!refreshFailed) {
|
|
290
|
-
_context3.next =
|
|
294
|
+
_context3.next = 59;
|
|
291
295
|
break;
|
|
292
296
|
}
|
|
293
297
|
|
|
294
|
-
_context3.
|
|
295
|
-
|
|
298
|
+
_context3.prev = 49;
|
|
299
|
+
_context3.next = 52;
|
|
300
|
+
return this.comoData.initApi.signOn(installationId, locationId, refreshToken, source);
|
|
296
301
|
|
|
297
|
-
case
|
|
302
|
+
case 52:
|
|
298
303
|
_data2 = _context3.sent;
|
|
299
304
|
|
|
300
|
-
|
|
305
|
+
updateCredentials(_data2, true);
|
|
306
|
+
_context3.next = 59;
|
|
307
|
+
break;
|
|
308
|
+
|
|
309
|
+
case 56:
|
|
310
|
+
_context3.prev = 56;
|
|
311
|
+
_context3.t3 = _context3['catch'](49);
|
|
312
|
+
|
|
313
|
+
console.log('Failed to signOn device, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ', error: ' + _context3.t3);
|
|
314
|
+
|
|
315
|
+
case 59:
|
|
301
316
|
return _context3.abrupt('return', this.getCredentials());
|
|
302
317
|
|
|
303
|
-
case
|
|
318
|
+
case 60:
|
|
304
319
|
case 'end':
|
|
305
320
|
return _context3.stop();
|
|
306
321
|
}
|
|
307
322
|
}
|
|
308
|
-
}, _callee3, this, [[15, 20], [23,
|
|
323
|
+
}, _callee3, this, [[15, 20], [23, 30], [37, 44], [49, 56]]);
|
|
309
324
|
}));
|
|
310
325
|
|
|
311
326
|
function init(_x2, _x3, _x4) {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _promise = require('babel-runtime/core-js/promise');
|
|
4
|
-
|
|
5
|
-
var _promise2 = _interopRequireDefault(_promise);
|
|
6
|
-
|
|
7
3
|
var _regenerator = require('babel-runtime/regenerator');
|
|
8
4
|
|
|
9
5
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
@@ -56,29 +52,27 @@ exports.tokenInterceptor = function (getCredentials, refresher) {
|
|
|
56
52
|
case 0:
|
|
57
53
|
_getCredentials = getCredentials(), expiresIn = _getCredentials.expiresIn;
|
|
58
54
|
|
|
59
|
-
if (!(expiresIn && isExpired(expiresIn)
|
|
60
|
-
_context.next =
|
|
55
|
+
if (!(expiresIn && isExpired(expiresIn))) {
|
|
56
|
+
_context.next = 11;
|
|
61
57
|
break;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
_context.prev = 2;
|
|
65
|
-
|
|
66
|
-
console.log('WTFFFF = ' + (expiresIn && isExpired(expiresIn) && !config.url.toLocaleLowerCase().includes('signon') && !config.url.toLocaleLowerCase().includes('refresh-token')));
|
|
67
|
-
_context.next = 6;
|
|
61
|
+
_context.next = 5;
|
|
68
62
|
return refresher();
|
|
69
63
|
|
|
70
|
-
case
|
|
71
|
-
_context.next =
|
|
64
|
+
case 5:
|
|
65
|
+
_context.next = 11;
|
|
72
66
|
break;
|
|
73
67
|
|
|
74
|
-
case
|
|
75
|
-
_context.prev =
|
|
68
|
+
case 7:
|
|
69
|
+
_context.prev = 7;
|
|
76
70
|
_context.t0 = _context['catch'](2);
|
|
77
71
|
|
|
78
72
|
console.log(_context.t0);
|
|
79
73
|
throw new Error('Could not refresh token');
|
|
80
74
|
|
|
81
|
-
case
|
|
75
|
+
case 11:
|
|
82
76
|
_getCredentials2 = getCredentials(), accessToken = _getCredentials2.accessToken;
|
|
83
77
|
|
|
84
78
|
if (accessToken) {
|
|
@@ -89,12 +83,12 @@ exports.tokenInterceptor = function (getCredentials, refresher) {
|
|
|
89
83
|
|
|
90
84
|
return _context.abrupt('return', config);
|
|
91
85
|
|
|
92
|
-
case
|
|
86
|
+
case 14:
|
|
93
87
|
case 'end':
|
|
94
88
|
return _context.stop();
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
|
-
}, _callee, undefined, [[2,
|
|
91
|
+
}, _callee, undefined, [[2, 7]]);
|
|
98
92
|
}));
|
|
99
93
|
|
|
100
94
|
return function (_x) {
|
|
@@ -119,65 +113,55 @@ exports.refreshInterceptor = function (refresher, service) {
|
|
|
119
113
|
switch (_context2.prev = _context2.next) {
|
|
120
114
|
case 0:
|
|
121
115
|
if (!error.response) {
|
|
122
|
-
_context2.next =
|
|
116
|
+
_context2.next = 5;
|
|
123
117
|
break;
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
if (error.response.headers['janua-token-expired']) {
|
|
127
|
-
_context2.next =
|
|
121
|
+
_context2.next = 3;
|
|
128
122
|
break;
|
|
129
123
|
}
|
|
130
124
|
|
|
131
|
-
if (!(error.response.config.url.toLocaleLowerCase().includes('signon') || error.response.config.url.toLocaleLowerCase().includes('refresh-token'))) {
|
|
132
|
-
_context2.next = 6;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
_promise2.default.reject(error);
|
|
137
|
-
_context2.next = 7;
|
|
138
|
-
break;
|
|
139
|
-
|
|
140
|
-
case 6:
|
|
141
125
|
throw error;
|
|
142
126
|
|
|
143
|
-
case
|
|
144
|
-
_context2.next =
|
|
127
|
+
case 3:
|
|
128
|
+
_context2.next = 6;
|
|
145
129
|
break;
|
|
146
130
|
|
|
147
|
-
case
|
|
131
|
+
case 5:
|
|
148
132
|
throw error;
|
|
149
133
|
|
|
150
|
-
case
|
|
134
|
+
case 6:
|
|
151
135
|
config = error.config;
|
|
152
|
-
_context2.prev =
|
|
153
|
-
_context2.next =
|
|
136
|
+
_context2.prev = 7;
|
|
137
|
+
_context2.next = 10;
|
|
154
138
|
return refresher();
|
|
155
139
|
|
|
156
|
-
case
|
|
157
|
-
_context2.next =
|
|
140
|
+
case 10:
|
|
141
|
+
_context2.next = 16;
|
|
158
142
|
break;
|
|
159
143
|
|
|
160
|
-
case
|
|
161
|
-
_context2.prev =
|
|
162
|
-
_context2.t0 = _context2['catch'](
|
|
144
|
+
case 12:
|
|
145
|
+
_context2.prev = 12;
|
|
146
|
+
_context2.t0 = _context2['catch'](7);
|
|
163
147
|
|
|
164
148
|
console.log(_context2.t0);
|
|
165
149
|
throw new Error('Could not refresh token');
|
|
166
150
|
|
|
167
|
-
case
|
|
168
|
-
_context2.next =
|
|
151
|
+
case 16:
|
|
152
|
+
_context2.next = 18;
|
|
169
153
|
return service.request(config);
|
|
170
154
|
|
|
171
|
-
case
|
|
155
|
+
case 18:
|
|
172
156
|
res = _context2.sent;
|
|
173
157
|
return _context2.abrupt('return', res);
|
|
174
158
|
|
|
175
|
-
case
|
|
159
|
+
case 20:
|
|
176
160
|
case 'end':
|
|
177
161
|
return _context2.stop();
|
|
178
162
|
}
|
|
179
163
|
}
|
|
180
|
-
}, _callee2, undefined, [[
|
|
164
|
+
}, _callee2, undefined, [[7, 12]]);
|
|
181
165
|
}));
|
|
182
166
|
|
|
183
167
|
return function (_x2) {
|
package/lib/services/index.js
CHANGED
|
@@ -62,14 +62,15 @@ exports.getService = function (baseURL, uid, getCredentials, credentialsRefresh,
|
|
|
62
62
|
});
|
|
63
63
|
httpClient.interceptors.response.use(responseInterceptor(credentialsRefresh), refreshInterceptor(refresher, httpClient));
|
|
64
64
|
var apiCalls = (0, _extends3.default)({}, auth, loyalty, form, ssr);
|
|
65
|
+
var initApiCalls = { signOn: auth.signOn, refreshToken: auth.refreshToken };
|
|
65
66
|
|
|
66
67
|
// Inject service instance to all service calls
|
|
67
68
|
var service = (0, _keys2.default)(apiCalls).reduce(function (prev, curr) {
|
|
68
69
|
prev[curr] = apiCalls[curr](httpClient); // eslint-disable-line no-param-reassign
|
|
69
70
|
return prev;
|
|
70
71
|
}, {});
|
|
71
|
-
var initService = (0, _keys2.default)(
|
|
72
|
-
prev[curr] =
|
|
72
|
+
var initService = (0, _keys2.default)(initApiCalls).reduce(function (prev, curr) {
|
|
73
|
+
prev[curr] = initApiCalls[curr](httpInitClient); // eslint-disable-line no-param-reassign
|
|
73
74
|
return prev;
|
|
74
75
|
}, {});
|
|
75
76
|
|
package/package.json
CHANGED
package/src/como.js
CHANGED
|
@@ -97,7 +97,7 @@ class Como {
|
|
|
97
97
|
const { service, refresher, initService } = APIService
|
|
98
98
|
.getService(gateway, installationId, getCredentials, updateCredentials, source);
|
|
99
99
|
this.comoData.api = service;
|
|
100
|
-
this.comoData.
|
|
100
|
+
this.comoData.initApi = initService;
|
|
101
101
|
this.comoData.refresher = refresher;
|
|
102
102
|
|
|
103
103
|
const { accessToken, refreshToken, expiresIn } = credentials;
|
|
@@ -110,7 +110,8 @@ class Como {
|
|
|
110
110
|
}
|
|
111
111
|
if(credsNotExist){
|
|
112
112
|
try{
|
|
113
|
-
const data = await this.
|
|
113
|
+
const data = await this.comoData.initApi.signOn(installationId, locationId, refreshToken, source);
|
|
114
|
+
updateCredentials(data, true);
|
|
114
115
|
}catch(e){
|
|
115
116
|
//TODO: need to parse error
|
|
116
117
|
console.log(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source}`);
|
|
@@ -122,7 +123,8 @@ class Como {
|
|
|
122
123
|
let refreshFailed = false;
|
|
123
124
|
if(isExpired){
|
|
124
125
|
try{
|
|
125
|
-
const data = await this.comoData.
|
|
126
|
+
const data = await this.comoData.initApi.refreshToken(installationId, refreshToken);
|
|
127
|
+
updateCredentials(data, true);
|
|
126
128
|
}catch(e){
|
|
127
129
|
console.log(`Failed to refresh token, installationId:${installationId}, locationId:${locationId}, source:${source}`);
|
|
128
130
|
//TODO: need to parse error
|
|
@@ -131,7 +133,14 @@ class Como {
|
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
if(refreshFailed){
|
|
134
|
-
|
|
136
|
+
try{
|
|
137
|
+
const data = await this.comoData.initApi.signOn(installationId, locationId, refreshToken, source);
|
|
138
|
+
updateCredentials(data, true);
|
|
139
|
+
}
|
|
140
|
+
catch(e){
|
|
141
|
+
console.log(`Failed to signOn device, installationId:${installationId}, locationId:${locationId}, source:${source}, error: ${e}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
135
144
|
}
|
|
136
145
|
return this.getCredentials();
|
|
137
146
|
}
|