@como/como-client 0.7.53 → 0.7.57
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 +16 -8
- package/lib/services/index.js +14 -8
- package/package.json +1 -1
- package/src/como.js +5 -3
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, signOnSuccessfully, _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;
|
|
@@ -1080,13 +1080,17 @@ var Como = function () {
|
|
|
1080
1080
|
case 0:
|
|
1081
1081
|
_comoData9 = this.comoData, env = _comoData9.env_params, locationId = _comoData9.locationId, api = _comoData9.api;
|
|
1082
1082
|
_context17.next = 3;
|
|
1083
|
-
return
|
|
1083
|
+
return this.refreshTokenIfNeeded();
|
|
1084
1084
|
|
|
1085
1085
|
case 3:
|
|
1086
|
+
_context17.next = 5;
|
|
1087
|
+
return api.getShortUserId(env.zapp_root, locationId);
|
|
1088
|
+
|
|
1089
|
+
case 5:
|
|
1086
1090
|
responseJson = _context17.sent;
|
|
1087
1091
|
return _context17.abrupt('return', responseJson.ID);
|
|
1088
1092
|
|
|
1089
|
-
case
|
|
1093
|
+
case 7:
|
|
1090
1094
|
case 'end':
|
|
1091
1095
|
return _context17.stop();
|
|
1092
1096
|
}
|
|
@@ -1208,13 +1212,17 @@ var Como = function () {
|
|
|
1208
1212
|
case 0:
|
|
1209
1213
|
_comoData11 = this.comoData, env = _comoData11.env_params, locationId = _comoData11.locationId, api = _comoData11.api;
|
|
1210
1214
|
_context20.next = 3;
|
|
1211
|
-
return
|
|
1215
|
+
return this.refreshTokenIfNeeded();
|
|
1212
1216
|
|
|
1213
1217
|
case 3:
|
|
1218
|
+
_context20.next = 5;
|
|
1219
|
+
return api.redeemAsset(env.zapp_root, locationId, assetKey);
|
|
1220
|
+
|
|
1221
|
+
case 5:
|
|
1214
1222
|
responseJson = _context20.sent;
|
|
1215
1223
|
return _context20.abrupt('return', responseJson);
|
|
1216
1224
|
|
|
1217
|
-
case
|
|
1225
|
+
case 7:
|
|
1218
1226
|
case 'end':
|
|
1219
1227
|
return _context20.stop();
|
|
1220
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');
|
|
@@ -30,7 +33,10 @@ var ssr = require('./ssr.service');
|
|
|
30
33
|
var log = require('./log.service');
|
|
31
34
|
|
|
32
35
|
exports.getService = function (baseURL, uid, getCredentials, credentialsRefresh, source) {
|
|
33
|
-
var
|
|
36
|
+
var binaryVersion = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'not-defined';
|
|
37
|
+
var phoenixVersion = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'not-defined';
|
|
38
|
+
|
|
39
|
+
var httpClient = axios.create({ baseURL: baseURL, headers: { 'x-comojs-version': version, 'x-binary-version': binaryVersion, 'x-phoenix-version': phoenixVersion } });
|
|
34
40
|
|
|
35
41
|
/**
|
|
36
42
|
* TODO: Make refresher prettier.
|
|
@@ -72,8 +78,8 @@ exports.getService = function (baseURL, uid, getCredentials, credentialsRefresh,
|
|
|
72
78
|
return { initService: initService, service: service, refresher: refresher };
|
|
73
79
|
};
|
|
74
80
|
|
|
75
|
-
function getInitApiCalles(baseURL) {
|
|
76
|
-
var httpInitClient = axios.create({ baseURL: baseURL });
|
|
81
|
+
function getInitApiCalles(baseURL, binaryVersion, phoenixVersion) {
|
|
82
|
+
var httpInitClient = axios.create({ baseURL: baseURL, headers: { 'x-comojs-version': version, 'x-binary-version': binaryVersion, 'x-phoenix-version': phoenixVersion } });
|
|
77
83
|
var initApiCalls = { signOn: auth.signOn, refreshToken: auth.refreshToken, logError: log.logError };
|
|
78
84
|
return (0, _keys2.default)(initApiCalls).reduce(function (prev, curr) {
|
|
79
85
|
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;
|
|
@@ -444,6 +444,7 @@ class Como {
|
|
|
444
444
|
const {
|
|
445
445
|
env_params: env, locationId, api,
|
|
446
446
|
} = this.comoData;
|
|
447
|
+
await this.refreshTokenIfNeeded();
|
|
447
448
|
const responseJson = await api.getShortUserId(env.zapp_root, locationId);
|
|
448
449
|
return responseJson.ID;
|
|
449
450
|
}
|
|
@@ -484,6 +485,7 @@ class Como {
|
|
|
484
485
|
const {
|
|
485
486
|
env_params: env, locationId, api,
|
|
486
487
|
} = this.comoData;
|
|
488
|
+
await this.refreshTokenIfNeeded();
|
|
487
489
|
const responseJson = await api.redeemAsset(env.zapp_root, locationId, assetKey);
|
|
488
490
|
return responseJson;
|
|
489
491
|
}
|