@como/como-client 0.7.52 → 0.7.56
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 +48 -21
- package/lib/services/index.js +12 -9
- package/package.json +1 -1
- package/src/como.js +22 -13
package/lib/como.js
CHANGED
|
@@ -82,7 +82,7 @@ var Como = function () {
|
|
|
82
82
|
break;
|
|
83
83
|
|
|
84
84
|
case 5:
|
|
85
|
-
if (!(expiresIn && moment(expiresIn).subtract(
|
|
85
|
+
if (!(expiresIn && moment(expiresIn).subtract(60, 'seconds').isBefore(moment()))) {
|
|
86
86
|
_context.next = 8;
|
|
87
87
|
break;
|
|
88
88
|
}
|
|
@@ -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, binaryVersion, phoenixVersion, 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) {
|
|
@@ -158,7 +158,7 @@ var Como = function () {
|
|
|
158
158
|
return !ramda.isNil(x) && !ramda.isEmpty(x);
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
environmentId = environment.id, locationId = environment.locationId, installationId = environment.installationId, source = environment.source;
|
|
161
|
+
environmentId = environment.id, locationId = environment.locationId, installationId = environment.installationId, source = environment.source, binaryVersion = environment.binaryVersion, phoenixVersion = environment.phoenixVersion;
|
|
162
162
|
|
|
163
163
|
if (!(!isExists(environmentId) || !isExists(locationId) || !isExists(installationId))) {
|
|
164
164
|
_context2.next = 4;
|
|
@@ -187,7 +187,7 @@ var Como = function () {
|
|
|
187
187
|
|
|
188
188
|
getCredentials = this.getCredentials.bind(this);
|
|
189
189
|
gateway = this.comoData.env_params.gateway;
|
|
190
|
-
_APIService$getServic = APIService.getService(gateway, installationId, getCredentials, updateCredentials, source), service = _APIService$getServic.service, refresher = _APIService$getServic.refresher, initService = _APIService$getServic.initService;
|
|
190
|
+
_APIService$getServic = APIService.getService(gateway, installationId, getCredentials, updateCredentials, source, binaryVersion, phoenixVersion), service = _APIService$getServic.service, refresher = _APIService$getServic.refresher, initService = _APIService$getServic.initService;
|
|
191
191
|
|
|
192
192
|
this.comoData.api = service;
|
|
193
193
|
this.comoData.initApi = initService;
|
|
@@ -255,7 +255,7 @@ var Como = function () {
|
|
|
255
255
|
|
|
256
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, error: _context2.t1.message });
|
|
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,22 +266,30 @@ 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 =
|
|
274
|
+
_context2.next = 73;
|
|
275
275
|
break;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
|
|
278
|
+
signOnSuccessfully = false;
|
|
279
|
+
|
|
280
|
+
case 53:
|
|
281
|
+
if (!(!signOnSuccessfully && interval < 3000)) {
|
|
282
|
+
_context2.next = 73;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
_context2.prev = 54;
|
|
279
287
|
|
|
280
288
|
console.log('signOn with installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken);
|
|
281
|
-
_context2.next =
|
|
289
|
+
_context2.next = 58;
|
|
282
290
|
return this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
|
|
283
291
|
|
|
284
|
-
case
|
|
292
|
+
case 58:
|
|
285
293
|
_data2 = _context2.sent;
|
|
286
294
|
|
|
287
295
|
console.log('signOn with result " ' + (0, _stringify2.default)(_data2));
|
|
@@ -289,27 +297,38 @@ var Como = function () {
|
|
|
289
297
|
console.log('signOn- updating credentials');
|
|
290
298
|
updateCredentials(_data2, true);
|
|
291
299
|
}
|
|
292
|
-
|
|
300
|
+
signOnSuccessfully = true;
|
|
301
|
+
_context2.next = 71;
|
|
293
302
|
break;
|
|
294
303
|
|
|
295
|
-
case
|
|
296
|
-
_context2.prev =
|
|
297
|
-
_context2.t2 = _context2['catch'](
|
|
304
|
+
case 64:
|
|
305
|
+
_context2.prev = 64;
|
|
306
|
+
_context2.t2 = _context2['catch'](54);
|
|
298
307
|
|
|
299
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
|
+
});
|
|
300
315
|
|
|
301
|
-
case
|
|
316
|
+
case 71:
|
|
317
|
+
_context2.next = 53;
|
|
318
|
+
break;
|
|
319
|
+
|
|
320
|
+
case 73:
|
|
302
321
|
if (!this.comoData.token) {
|
|
303
322
|
this.comoData.token = this.comoData.accessToken;
|
|
304
323
|
}
|
|
305
324
|
return _context2.abrupt('return', this.getCredentials());
|
|
306
325
|
|
|
307
|
-
case
|
|
326
|
+
case 75:
|
|
308
327
|
case 'end':
|
|
309
328
|
return _context2.stop();
|
|
310
329
|
}
|
|
311
330
|
}
|
|
312
|
-
}, _callee2, this, [[17, 24], [32, 40], [
|
|
331
|
+
}, _callee2, this, [[17, 24], [32, 40], [54, 64]]);
|
|
313
332
|
}));
|
|
314
333
|
|
|
315
334
|
function init(_x, _x2, _x3) {
|
|
@@ -1061,13 +1080,17 @@ var Como = function () {
|
|
|
1061
1080
|
case 0:
|
|
1062
1081
|
_comoData9 = this.comoData, env = _comoData9.env_params, locationId = _comoData9.locationId, api = _comoData9.api;
|
|
1063
1082
|
_context17.next = 3;
|
|
1064
|
-
return
|
|
1083
|
+
return this.refreshTokenIfNeeded();
|
|
1065
1084
|
|
|
1066
1085
|
case 3:
|
|
1086
|
+
_context17.next = 5;
|
|
1087
|
+
return api.getShortUserId(env.zapp_root, locationId);
|
|
1088
|
+
|
|
1089
|
+
case 5:
|
|
1067
1090
|
responseJson = _context17.sent;
|
|
1068
1091
|
return _context17.abrupt('return', responseJson.ID);
|
|
1069
1092
|
|
|
1070
|
-
case
|
|
1093
|
+
case 7:
|
|
1071
1094
|
case 'end':
|
|
1072
1095
|
return _context17.stop();
|
|
1073
1096
|
}
|
|
@@ -1189,13 +1212,17 @@ var Como = function () {
|
|
|
1189
1212
|
case 0:
|
|
1190
1213
|
_comoData11 = this.comoData, env = _comoData11.env_params, locationId = _comoData11.locationId, api = _comoData11.api;
|
|
1191
1214
|
_context20.next = 3;
|
|
1192
|
-
return
|
|
1215
|
+
return this.refreshTokenIfNeeded();
|
|
1193
1216
|
|
|
1194
1217
|
case 3:
|
|
1218
|
+
_context20.next = 5;
|
|
1219
|
+
return api.redeemAsset(env.zapp_root, locationId, assetKey);
|
|
1220
|
+
|
|
1221
|
+
case 5:
|
|
1195
1222
|
responseJson = _context20.sent;
|
|
1196
1223
|
return _context20.abrupt('return', responseJson);
|
|
1197
1224
|
|
|
1198
|
-
case
|
|
1225
|
+
case 7:
|
|
1199
1226
|
case 'end':
|
|
1200
1227
|
return _context20.stop();
|
|
1201
1228
|
}
|
package/lib/services/index.js
CHANGED
|
@@ -16,12 +16,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
16
|
|
|
17
17
|
var axios = require('axios');
|
|
18
18
|
|
|
19
|
-
var _require = require('
|
|
20
|
-
|
|
21
|
-
refreshInterceptor = _require.refreshInterceptor;
|
|
19
|
+
var _require = require('../../package.json'),
|
|
20
|
+
version = _require.version;
|
|
22
21
|
|
|
23
|
-
var _require2 = require('../interceptors/
|
|
24
|
-
|
|
22
|
+
var _require2 = require('../interceptors/refresh'),
|
|
23
|
+
tokenInterceptor = _require2.tokenInterceptor,
|
|
24
|
+
refreshInterceptor = _require2.refreshInterceptor;
|
|
25
|
+
|
|
26
|
+
var _require3 = require('../interceptors/response'),
|
|
27
|
+
responseInterceptor = _require3.responseInterceptor;
|
|
25
28
|
|
|
26
29
|
var auth = require('./auth.service');
|
|
27
30
|
var loyalty = require('./loyalty.service');
|
|
@@ -29,8 +32,8 @@ var form = require('./form.service');
|
|
|
29
32
|
var ssr = require('./ssr.service');
|
|
30
33
|
var log = require('./log.service');
|
|
31
34
|
|
|
32
|
-
exports.getService = function (baseURL, uid, getCredentials, credentialsRefresh, source) {
|
|
33
|
-
var httpClient = axios.create({ baseURL: baseURL });
|
|
35
|
+
exports.getService = function (baseURL, uid, getCredentials, credentialsRefresh, source, binaryVersion, phoenixVersion) {
|
|
36
|
+
var httpClient = axios.create({ baseURL: baseURL, headers: { 'x-comojs-version': version, 'x-binary-version': binaryVersion, 'x-phoenix-version': phoenixVersion } });
|
|
34
37
|
|
|
35
38
|
/**
|
|
36
39
|
* TODO: Make refresher prettier.
|
|
@@ -72,8 +75,8 @@ exports.getService = function (baseURL, uid, getCredentials, credentialsRefresh,
|
|
|
72
75
|
return { initService: initService, service: service, refresher: refresher };
|
|
73
76
|
};
|
|
74
77
|
|
|
75
|
-
function getInitApiCalles(baseURL) {
|
|
76
|
-
var httpInitClient = axios.create({ baseURL: baseURL });
|
|
78
|
+
function getInitApiCalles(baseURL, binaryVersion, phoenixVersion) {
|
|
79
|
+
var httpInitClient = axios.create({ baseURL: baseURL, headers: { 'x-comojs-version': version, 'x-binary-version': binaryVersion, 'x-phoenix-version': phoenixVersion } });
|
|
77
80
|
var initApiCalls = { signOn: auth.signOn, refreshToken: auth.refreshToken, logError: log.logError };
|
|
78
81
|
return (0, _keys2.default)(initApiCalls).reduce(function (prev, curr) {
|
|
79
82
|
prev[curr] = initApiCalls[curr](httpInitClient); // eslint-disable-line no-param-reassign
|
package/package.json
CHANGED
package/src/como.js
CHANGED
|
@@ -27,7 +27,7 @@ class Como {
|
|
|
27
27
|
if(!refresher){
|
|
28
28
|
console.log('No refresh for %o', this.comoData);
|
|
29
29
|
}
|
|
30
|
-
else if (expiresIn && moment(expiresIn).subtract(
|
|
30
|
+
else if (expiresIn && moment(expiresIn).subtract(60, 'seconds').isBefore(moment())) {
|
|
31
31
|
await refresher();
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -69,7 +69,7 @@ class Como {
|
|
|
69
69
|
*/
|
|
70
70
|
async init(environment, credentials, refreshCallback, enableSignon = true) {
|
|
71
71
|
const isExists = (x => !ramda.isNil(x) && !ramda.isEmpty(x));
|
|
72
|
-
const { id: environmentId, locationId, installationId, source } = environment;
|
|
72
|
+
const { id: environmentId, locationId, installationId, source, binaryVersion, phoenixVersion } = environment;
|
|
73
73
|
if (!isExists(environmentId) || !isExists(locationId) || !isExists(installationId)) {
|
|
74
74
|
throw new Error(`missing parameters: ${environment}`);
|
|
75
75
|
}
|
|
@@ -95,7 +95,7 @@ class Como {
|
|
|
95
95
|
const getCredentials = this.getCredentials.bind(this);
|
|
96
96
|
const { gateway } = this.comoData.env_params;
|
|
97
97
|
const { service, refresher, initService } = APIService
|
|
98
|
-
.getService(gateway, installationId, getCredentials, updateCredentials, source);
|
|
98
|
+
.getService(gateway, installationId, getCredentials, updateCredentials, source, binaryVersion, phoenixVersion);
|
|
99
99
|
this.comoData.api = service;
|
|
100
100
|
this.comoData.initApi = initService;
|
|
101
101
|
this.comoData.refresher = refresher;
|
|
@@ -125,22 +125,29 @@ class Como {
|
|
|
125
125
|
}catch(e){
|
|
126
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, error : e.message});
|
|
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
133
|
else if(!isExpired){
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
console.log(`signOn
|
|
140
|
-
|
|
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.error(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e.message}`);
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
if(!this.comoData.token){
|
|
@@ -437,6 +444,7 @@ class Como {
|
|
|
437
444
|
const {
|
|
438
445
|
env_params: env, locationId, api,
|
|
439
446
|
} = this.comoData;
|
|
447
|
+
await this.refreshTokenIfNeeded();
|
|
440
448
|
const responseJson = await api.getShortUserId(env.zapp_root, locationId);
|
|
441
449
|
return responseJson.ID;
|
|
442
450
|
}
|
|
@@ -477,6 +485,7 @@ class Como {
|
|
|
477
485
|
const {
|
|
478
486
|
env_params: env, locationId, api,
|
|
479
487
|
} = this.comoData;
|
|
488
|
+
await this.refreshTokenIfNeeded();
|
|
480
489
|
const responseJson = await api.redeemAsset(env.zapp_root, locationId, assetKey);
|
|
481
490
|
return responseJson;
|
|
482
491
|
}
|