@como/como-client 0.1.87 → 0.1.91
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 +69 -28
- package/lib/services/auth.service.js +3 -17
- package/lib/services/log.service.js +332 -0
- package/package.json +1 -1
- package/src/como.js +29 -14
package/lib/como.js
CHANGED
|
@@ -69,15 +69,19 @@ var Como = function () {
|
|
|
69
69
|
case 0:
|
|
70
70
|
_comoData = this.comoData, refresher = _comoData.refresher, expiresIn = _comoData.expiresIn;
|
|
71
71
|
|
|
72
|
-
if (!
|
|
73
|
-
|
|
72
|
+
if (!refresher) {
|
|
73
|
+
console.log('No refresh for %o', this.comoData);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!(refresher && expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment()))) {
|
|
77
|
+
_context.next = 5;
|
|
74
78
|
break;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
_context.next =
|
|
81
|
+
_context.next = 5;
|
|
78
82
|
return refresher();
|
|
79
83
|
|
|
80
|
-
case
|
|
84
|
+
case 5:
|
|
81
85
|
case 'end':
|
|
82
86
|
return _context.stop();
|
|
83
87
|
}
|
|
@@ -114,29 +118,33 @@ var Como = function () {
|
|
|
114
118
|
|
|
115
119
|
case 4:
|
|
116
120
|
data = _context2.sent;
|
|
121
|
+
|
|
122
|
+
if (data && data.config && data.config.loyaltyCDN) {
|
|
123
|
+
this.comoData.env_params.services_root_cdn = data.config.loyaltyCDN;
|
|
124
|
+
}
|
|
117
125
|
return _context2.abrupt('return', data);
|
|
118
126
|
|
|
119
|
-
case
|
|
120
|
-
_context2.prev =
|
|
127
|
+
case 9:
|
|
128
|
+
_context2.prev = 9;
|
|
121
129
|
_context2.t0 = _context2['catch'](1);
|
|
122
130
|
|
|
123
131
|
if (!(_context2.t0.response && _context2.t0.response.data)) {
|
|
124
|
-
_context2.next =
|
|
132
|
+
_context2.next = 14;
|
|
125
133
|
break;
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
_error$response$data = _context2.t0.response.data, code = _error$response$data.code, message = _error$response$data.message;
|
|
129
137
|
throw new Error(code || message);
|
|
130
138
|
|
|
131
|
-
case
|
|
139
|
+
case 14:
|
|
132
140
|
throw _context2.t0;
|
|
133
141
|
|
|
134
|
-
case
|
|
142
|
+
case 15:
|
|
135
143
|
case 'end':
|
|
136
144
|
return _context2.stop();
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
|
-
}, _callee2, this, [[1,
|
|
147
|
+
}, _callee2, this, [[1, 9]]);
|
|
140
148
|
}));
|
|
141
149
|
|
|
142
150
|
function signon(_x) {
|
|
@@ -168,7 +176,7 @@ var Como = function () {
|
|
|
168
176
|
|
|
169
177
|
var enableSignon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
170
178
|
|
|
171
|
-
var isExists, environmentId, locationId, installationId, source, updateCredentials, getCredentials, gateway, _APIService$getServic, service, refresher, accessToken, refreshToken, expiresIn, credsNotExist, isExpired,
|
|
179
|
+
var isExists, environmentId, locationId, installationId, source, updateCredentials, getCredentials, gateway, _APIService$getServic, service, refresher, accessToken, refreshToken, expiresIn, credsNotExist, isExpired, refreshFailed;
|
|
172
180
|
|
|
173
181
|
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
|
174
182
|
while (1) {
|
|
@@ -188,13 +196,6 @@ var Como = function () {
|
|
|
188
196
|
throw new Error('missing parameters: ' + environment);
|
|
189
197
|
|
|
190
198
|
case 4:
|
|
191
|
-
axios.post('https://janua.como.com/v2/auth/init/log', { credentials: credentials,
|
|
192
|
-
locationId: locationId,
|
|
193
|
-
installationId: installationId,
|
|
194
|
-
source: source }, {
|
|
195
|
-
headers: {
|
|
196
|
-
"Content-Type": "application/json"
|
|
197
|
-
} });
|
|
198
199
|
this.comoData = (0, _extends3.default)({}, INITIAL_COMO_DATA, credentials, {
|
|
199
200
|
installationId: installationId,
|
|
200
201
|
locationId: locationId,
|
|
@@ -220,32 +221,72 @@ var Como = function () {
|
|
|
220
221
|
|
|
221
222
|
accessToken = credentials.accessToken, refreshToken = credentials.refreshToken, expiresIn = credentials.expiresIn;
|
|
222
223
|
credsNotExist = !isExists(accessToken) || !isExists(refreshToken);
|
|
223
|
-
isExpired = expiresIn && moment(expiresIn).isBefore(moment());
|
|
224
|
+
isExpired = !credsNotExist && expiresIn && moment(expiresIn).isBefore(moment());
|
|
224
225
|
|
|
225
|
-
if (!
|
|
226
|
-
_context3.next =
|
|
226
|
+
if (!credsNotExist) {
|
|
227
|
+
_context3.next = 24;
|
|
227
228
|
break;
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
_context3.prev = 15;
|
|
230
232
|
_context3.next = 18;
|
|
231
|
-
return this.signon(source);
|
|
233
|
+
return this.signon(installationId, locationId, source);
|
|
232
234
|
|
|
233
235
|
case 18:
|
|
234
|
-
|
|
236
|
+
_context3.next = 24;
|
|
237
|
+
break;
|
|
235
238
|
|
|
236
|
-
|
|
237
|
-
|
|
239
|
+
case 20:
|
|
240
|
+
_context3.prev = 20;
|
|
241
|
+
_context3.t0 = _context3['catch'](15);
|
|
242
|
+
|
|
243
|
+
//TODO: need to parse error
|
|
244
|
+
console.log('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source);
|
|
245
|
+
isExpired = true; // user uid exist - do refresh
|
|
246
|
+
|
|
247
|
+
case 24:
|
|
248
|
+
refreshFailed = false;
|
|
249
|
+
|
|
250
|
+
if (!isExpired) {
|
|
251
|
+
_context3.next = 35;
|
|
252
|
+
break;
|
|
238
253
|
}
|
|
239
254
|
|
|
240
|
-
|
|
255
|
+
_context3.prev = 26;
|
|
256
|
+
_context3.next = 29;
|
|
257
|
+
return this.refreshTokenIfNeeded();
|
|
258
|
+
|
|
259
|
+
case 29:
|
|
260
|
+
_context3.next = 35;
|
|
261
|
+
break;
|
|
262
|
+
|
|
263
|
+
case 31:
|
|
264
|
+
_context3.prev = 31;
|
|
265
|
+
_context3.t1 = _context3['catch'](26);
|
|
266
|
+
|
|
267
|
+
console.log('Failed to refresh token, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source);
|
|
268
|
+
//TODO: need to parse error
|
|
269
|
+
//refresh failed - need to revoke and signOn again
|
|
270
|
+
refreshFailed = true;
|
|
271
|
+
|
|
272
|
+
case 35:
|
|
273
|
+
if (!refreshFailed) {
|
|
274
|
+
_context3.next = 38;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
_context3.next = 38;
|
|
279
|
+
return this.signon(installationId, locationId, source);
|
|
280
|
+
|
|
281
|
+
case 38:
|
|
241
282
|
return _context3.abrupt('return', this.getCredentials());
|
|
242
283
|
|
|
243
|
-
case
|
|
284
|
+
case 39:
|
|
244
285
|
case 'end':
|
|
245
286
|
return _context3.stop();
|
|
246
287
|
}
|
|
247
288
|
}
|
|
248
|
-
}, _callee3, this);
|
|
289
|
+
}, _callee3, this, [[15, 20], [26, 31]]);
|
|
249
290
|
}));
|
|
250
291
|
|
|
251
292
|
function init(_x2, _x3, _x4) {
|
|
@@ -10,7 +10,6 @@ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
|
10
10
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
|
|
13
|
-
var axios = require('axios');
|
|
14
13
|
exports.signOn = function (service) {
|
|
15
14
|
return function () {
|
|
16
15
|
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(deviceId, locationId, refreshToken, source) {
|
|
@@ -22,22 +21,14 @@ exports.signOn = function (service) {
|
|
|
22
21
|
case 0:
|
|
23
22
|
params = { deviceId: deviceId, locationId: locationId, refreshToken: refreshToken, source: source };
|
|
24
23
|
_context.next = 3;
|
|
25
|
-
return service.post('/auth/
|
|
24
|
+
return service.post('/auth/v2/auth/signOn', params);
|
|
26
25
|
|
|
27
26
|
case 3:
|
|
28
27
|
_ref2 = _context.sent;
|
|
29
28
|
data = _ref2.data;
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
axios.post('https://janua.como.com/v2/auth/init/signOn/log', { berfore: params, after: data }, {
|
|
33
|
-
headers: {
|
|
34
|
-
"Content-Type": "application/json"
|
|
35
|
-
} }).catch();
|
|
36
|
-
} catch (e) {}
|
|
37
|
-
|
|
38
29
|
return _context.abrupt('return', data);
|
|
39
30
|
|
|
40
|
-
case
|
|
31
|
+
case 6:
|
|
41
32
|
case 'end':
|
|
42
33
|
return _context.stop();
|
|
43
34
|
}
|
|
@@ -324,14 +315,9 @@ exports.refreshToken = function (service, source) {
|
|
|
324
315
|
case 3:
|
|
325
316
|
_ref20 = _context10.sent;
|
|
326
317
|
data = _ref20.data;
|
|
327
|
-
|
|
328
|
-
axios.post('https://janua.como.com/v2/auth/refresh-token/log', { berfore: params, after: data }, {
|
|
329
|
-
headers: {
|
|
330
|
-
"Content-Type": "application/json"
|
|
331
|
-
} });
|
|
332
318
|
return _context10.abrupt('return', data);
|
|
333
319
|
|
|
334
|
-
case
|
|
320
|
+
case 6:
|
|
335
321
|
case 'end':
|
|
336
322
|
return _context10.stop();
|
|
337
323
|
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _regenerator = require('babel-runtime/regenerator');
|
|
4
|
+
|
|
5
|
+
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
6
|
+
|
|
7
|
+
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
|
8
|
+
|
|
9
|
+
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
exports.signOn = function (service) {
|
|
14
|
+
return function () {
|
|
15
|
+
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(deviceId, locationId, refreshToken, source) {
|
|
16
|
+
var params, _ref2, data;
|
|
17
|
+
|
|
18
|
+
return _regenerator2.default.wrap(function _callee$(_context) {
|
|
19
|
+
while (1) {
|
|
20
|
+
switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
params = { deviceId: deviceId, locationId: locationId, refreshToken: refreshToken, source: source };
|
|
23
|
+
_context.next = 3;
|
|
24
|
+
return service.post('/auth/v2/auth/signOn', params);
|
|
25
|
+
|
|
26
|
+
case 3:
|
|
27
|
+
_ref2 = _context.sent;
|
|
28
|
+
data = _ref2.data;
|
|
29
|
+
return _context.abrupt('return', data);
|
|
30
|
+
|
|
31
|
+
case 6:
|
|
32
|
+
case 'end':
|
|
33
|
+
return _context.stop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, _callee, undefined);
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
return function (_x, _x2, _x3, _x4) {
|
|
40
|
+
return _ref.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
}();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.register = function (service) {
|
|
46
|
+
return function () {
|
|
47
|
+
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(form, verification, reCaptchaToken) {
|
|
48
|
+
var source = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'App';
|
|
49
|
+
|
|
50
|
+
var _ref4, data;
|
|
51
|
+
|
|
52
|
+
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
|
53
|
+
while (1) {
|
|
54
|
+
switch (_context2.prev = _context2.next) {
|
|
55
|
+
case 0:
|
|
56
|
+
_context2.next = 2;
|
|
57
|
+
return service.post('/auth/v1/registration', { form: form, verification: verification, reCaptchaToken: reCaptchaToken, source: source });
|
|
58
|
+
|
|
59
|
+
case 2:
|
|
60
|
+
_ref4 = _context2.sent;
|
|
61
|
+
data = _ref4.data;
|
|
62
|
+
return _context2.abrupt('return', data);
|
|
63
|
+
|
|
64
|
+
case 5:
|
|
65
|
+
case 'end':
|
|
66
|
+
return _context2.stop();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, _callee2, undefined);
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
return function (_x5, _x6, _x7) {
|
|
73
|
+
return _ref3.apply(this, arguments);
|
|
74
|
+
};
|
|
75
|
+
}();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.registerVerify = function (service) {
|
|
79
|
+
return function () {
|
|
80
|
+
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(verification, type, form, reCaptchaToken) {
|
|
81
|
+
var body, _ref6, data;
|
|
82
|
+
|
|
83
|
+
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
|
84
|
+
while (1) {
|
|
85
|
+
switch (_context3.prev = _context3.next) {
|
|
86
|
+
case 0:
|
|
87
|
+
body = { verification: verification, type: type, form: form, reCaptchaToken: reCaptchaToken };
|
|
88
|
+
_context3.next = 3;
|
|
89
|
+
return service.post('/auth/v1/registration/verify', body);
|
|
90
|
+
|
|
91
|
+
case 3:
|
|
92
|
+
_ref6 = _context3.sent;
|
|
93
|
+
data = _ref6.data;
|
|
94
|
+
return _context3.abrupt('return', data);
|
|
95
|
+
|
|
96
|
+
case 6:
|
|
97
|
+
case 'end':
|
|
98
|
+
return _context3.stop();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, _callee3, undefined);
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
return function (_x9, _x10, _x11, _x12) {
|
|
105
|
+
return _ref5.apply(this, arguments);
|
|
106
|
+
};
|
|
107
|
+
}();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.updateProfile = function (service) {
|
|
111
|
+
return function () {
|
|
112
|
+
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(form, reCaptchaToken) {
|
|
113
|
+
var source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'App';
|
|
114
|
+
|
|
115
|
+
var _ref8, data;
|
|
116
|
+
|
|
117
|
+
return _regenerator2.default.wrap(function _callee4$(_context4) {
|
|
118
|
+
while (1) {
|
|
119
|
+
switch (_context4.prev = _context4.next) {
|
|
120
|
+
case 0:
|
|
121
|
+
_context4.next = 2;
|
|
122
|
+
return service.post('/auth/v1/update-profile', { form: form, source: source, reCaptchaToken: reCaptchaToken });
|
|
123
|
+
|
|
124
|
+
case 2:
|
|
125
|
+
_ref8 = _context4.sent;
|
|
126
|
+
data = _ref8.data;
|
|
127
|
+
return _context4.abrupt('return', data);
|
|
128
|
+
|
|
129
|
+
case 5:
|
|
130
|
+
case 'end':
|
|
131
|
+
return _context4.stop();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, _callee4, undefined);
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
return function (_x13, _x14) {
|
|
138
|
+
return _ref7.apply(this, arguments);
|
|
139
|
+
};
|
|
140
|
+
}();
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
exports.updateProfileVerify = function (service) {
|
|
144
|
+
return function () {
|
|
145
|
+
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(code, type, form, reCaptchaToken) {
|
|
146
|
+
var source = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'App';
|
|
147
|
+
|
|
148
|
+
var body, _ref10, data;
|
|
149
|
+
|
|
150
|
+
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
|
151
|
+
while (1) {
|
|
152
|
+
switch (_context5.prev = _context5.next) {
|
|
153
|
+
case 0:
|
|
154
|
+
body = { code: code, type: type, form: form, source: source, reCaptchaToken: reCaptchaToken };
|
|
155
|
+
_context5.next = 3;
|
|
156
|
+
return service.post('/auth/v1/update-profile/verify', body);
|
|
157
|
+
|
|
158
|
+
case 3:
|
|
159
|
+
_ref10 = _context5.sent;
|
|
160
|
+
data = _ref10.data;
|
|
161
|
+
return _context5.abrupt('return', data);
|
|
162
|
+
|
|
163
|
+
case 6:
|
|
164
|
+
case 'end':
|
|
165
|
+
return _context5.stop();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}, _callee5, undefined);
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
return function (_x16, _x17, _x18, _x19) {
|
|
172
|
+
return _ref9.apply(this, arguments);
|
|
173
|
+
};
|
|
174
|
+
}();
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
exports.unsubscribeSms = function (service) {
|
|
178
|
+
return function () {
|
|
179
|
+
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(locationId, identifier) {
|
|
180
|
+
var body, _ref12, data;
|
|
181
|
+
|
|
182
|
+
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
|
183
|
+
while (1) {
|
|
184
|
+
switch (_context6.prev = _context6.next) {
|
|
185
|
+
case 0:
|
|
186
|
+
body = { locationId: locationId, identifier: identifier };
|
|
187
|
+
_context6.next = 3;
|
|
188
|
+
return service.post('/auth/v1/update-profile/unsubscribeSms', body);
|
|
189
|
+
|
|
190
|
+
case 3:
|
|
191
|
+
_ref12 = _context6.sent;
|
|
192
|
+
data = _ref12.data;
|
|
193
|
+
return _context6.abrupt('return', data);
|
|
194
|
+
|
|
195
|
+
case 6:
|
|
196
|
+
case 'end':
|
|
197
|
+
return _context6.stop();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, _callee6, undefined);
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
return function (_x21, _x22) {
|
|
204
|
+
return _ref11.apply(this, arguments);
|
|
205
|
+
};
|
|
206
|
+
}();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
exports.logIn = function (service) {
|
|
210
|
+
return function () {
|
|
211
|
+
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(type, identifier) {
|
|
212
|
+
var params, _ref14, data;
|
|
213
|
+
|
|
214
|
+
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
|
215
|
+
while (1) {
|
|
216
|
+
switch (_context7.prev = _context7.next) {
|
|
217
|
+
case 0:
|
|
218
|
+
params = { type: type, identifier: identifier };
|
|
219
|
+
_context7.next = 3;
|
|
220
|
+
return service.post('/auth/v1/auth/logIn', params);
|
|
221
|
+
|
|
222
|
+
case 3:
|
|
223
|
+
_ref14 = _context7.sent;
|
|
224
|
+
data = _ref14.data;
|
|
225
|
+
return _context7.abrupt('return', data);
|
|
226
|
+
|
|
227
|
+
case 6:
|
|
228
|
+
case 'end':
|
|
229
|
+
return _context7.stop();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, _callee7, undefined);
|
|
233
|
+
}));
|
|
234
|
+
|
|
235
|
+
return function (_x23, _x24) {
|
|
236
|
+
return _ref13.apply(this, arguments);
|
|
237
|
+
};
|
|
238
|
+
}();
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
exports.logInVerify = function (service) {
|
|
242
|
+
return function () {
|
|
243
|
+
var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(code, type, identifier) {
|
|
244
|
+
var params, _ref16, data;
|
|
245
|
+
|
|
246
|
+
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
|
247
|
+
while (1) {
|
|
248
|
+
switch (_context8.prev = _context8.next) {
|
|
249
|
+
case 0:
|
|
250
|
+
params = {
|
|
251
|
+
identifier: identifier,
|
|
252
|
+
code: code,
|
|
253
|
+
type: type
|
|
254
|
+
};
|
|
255
|
+
_context8.next = 3;
|
|
256
|
+
return service.post('/auth/v1/auth/logInVerify', params);
|
|
257
|
+
|
|
258
|
+
case 3:
|
|
259
|
+
_ref16 = _context8.sent;
|
|
260
|
+
data = _ref16.data;
|
|
261
|
+
return _context8.abrupt('return', data);
|
|
262
|
+
|
|
263
|
+
case 6:
|
|
264
|
+
case 'end':
|
|
265
|
+
return _context8.stop();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}, _callee8, undefined);
|
|
269
|
+
}));
|
|
270
|
+
|
|
271
|
+
return function (_x25, _x26, _x27) {
|
|
272
|
+
return _ref15.apply(this, arguments);
|
|
273
|
+
};
|
|
274
|
+
}();
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
exports.logOut = function (service) {
|
|
278
|
+
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9() {
|
|
279
|
+
var _ref18, data;
|
|
280
|
+
|
|
281
|
+
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
|
282
|
+
while (1) {
|
|
283
|
+
switch (_context9.prev = _context9.next) {
|
|
284
|
+
case 0:
|
|
285
|
+
_context9.next = 2;
|
|
286
|
+
return service.post('/auth/v1/auth/logOut');
|
|
287
|
+
|
|
288
|
+
case 2:
|
|
289
|
+
_ref18 = _context9.sent;
|
|
290
|
+
data = _ref18.data;
|
|
291
|
+
return _context9.abrupt('return', data);
|
|
292
|
+
|
|
293
|
+
case 5:
|
|
294
|
+
case 'end':
|
|
295
|
+
return _context9.stop();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}, _callee9, undefined);
|
|
299
|
+
}));
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
exports.refreshToken = function (service, source) {
|
|
303
|
+
return function () {
|
|
304
|
+
var _ref19 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(uid, token) {
|
|
305
|
+
var params, _ref20, data;
|
|
306
|
+
|
|
307
|
+
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
|
308
|
+
while (1) {
|
|
309
|
+
switch (_context10.prev = _context10.next) {
|
|
310
|
+
case 0:
|
|
311
|
+
params = { uid: uid, refreshToken: token, source: source };
|
|
312
|
+
_context10.next = 3;
|
|
313
|
+
return service.post('/auth/v1/auth/refresh-token', params);
|
|
314
|
+
|
|
315
|
+
case 3:
|
|
316
|
+
_ref20 = _context10.sent;
|
|
317
|
+
data = _ref20.data;
|
|
318
|
+
return _context10.abrupt('return', data);
|
|
319
|
+
|
|
320
|
+
case 6:
|
|
321
|
+
case 'end':
|
|
322
|
+
return _context10.stop();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}, _callee10, undefined);
|
|
326
|
+
}));
|
|
327
|
+
|
|
328
|
+
return function (_x28, _x29) {
|
|
329
|
+
return _ref19.apply(this, arguments);
|
|
330
|
+
};
|
|
331
|
+
}();
|
|
332
|
+
};
|
package/package.json
CHANGED
package/src/como.js
CHANGED
|
@@ -25,7 +25,10 @@ class Como {
|
|
|
25
25
|
|
|
26
26
|
async refreshTokenIfNeeded() {
|
|
27
27
|
const { refresher, expiresIn } = this.comoData;
|
|
28
|
-
if
|
|
28
|
+
if(!refresher){
|
|
29
|
+
console.log('No refresh for %o', this.comoData);
|
|
30
|
+
}
|
|
31
|
+
if (refresher && expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment())) {
|
|
29
32
|
await refresher();
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -39,6 +42,9 @@ class Como {
|
|
|
39
42
|
const { api } = this.comoData;
|
|
40
43
|
try {
|
|
41
44
|
const data = await api.signOn(this.comoData.installationId, this.comoData.locationId, this.comoData.refreshToken, source);
|
|
45
|
+
if (data && data.config && data.config.loyaltyCDN) {
|
|
46
|
+
this.comoData.env_params.services_root_cdn = data.config.loyaltyCDN;
|
|
47
|
+
}
|
|
42
48
|
return data;
|
|
43
49
|
} catch (error) {
|
|
44
50
|
if (error.response && error.response.data) {
|
|
@@ -68,13 +74,6 @@ class Como {
|
|
|
68
74
|
if (!isExists(environmentId) || !isExists(locationId) || !isExists(installationId)) {
|
|
69
75
|
throw new Error(`missing parameters: ${environment}`);
|
|
70
76
|
}
|
|
71
|
-
axios.post('https://janua.como.com/v2/auth/init/log', {credentials,
|
|
72
|
-
locationId,
|
|
73
|
-
installationId,
|
|
74
|
-
source}, {
|
|
75
|
-
headers: {
|
|
76
|
-
"Content-Type": "application/json"
|
|
77
|
-
}});
|
|
78
77
|
this.comoData = {
|
|
79
78
|
...INITIAL_COMO_DATA,
|
|
80
79
|
...credentials,
|
|
@@ -102,14 +101,30 @@ class Como {
|
|
|
102
101
|
|
|
103
102
|
const { accessToken, refreshToken, expiresIn } = credentials;
|
|
104
103
|
const credsNotExist = !isExists(accessToken) || !isExists(refreshToken);
|
|
105
|
-
|
|
106
|
-
if
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
let isExpired = !credsNotExist && expiresIn && moment(expiresIn).isBefore(moment());
|
|
105
|
+
if(credsNotExist){
|
|
106
|
+
try{
|
|
107
|
+
await this.signon(installationId, locationId, source);
|
|
108
|
+
}catch(e){
|
|
109
|
+
//TODO: need to parse error
|
|
110
|
+
console.log(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source}`);
|
|
111
|
+
isExpired = true;// user uid exist - do refresh
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
|
-
|
|
114
|
+
let refreshFailed = false;
|
|
115
|
+
if(isExpired){
|
|
116
|
+
try{
|
|
117
|
+
await this.refreshTokenIfNeeded();
|
|
118
|
+
}catch(e){
|
|
119
|
+
console.log(`Failed to refresh token, installationId:${installationId}, locationId:${locationId}, source:${source}`);
|
|
120
|
+
//TODO: need to parse error
|
|
121
|
+
//refresh failed - need to revoke and signOn again
|
|
122
|
+
refreshFailed = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if(refreshFailed){
|
|
126
|
+
await this.signon(installationId, locationId, source);
|
|
127
|
+
}
|
|
113
128
|
return this.getCredentials();
|
|
114
129
|
}
|
|
115
130
|
|