@como/como-client 0.1.90 → 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 +71 -51
- package/lib/services/auth.service.js +4 -45
- package/lib/services/log.service.js +332 -0
- package/package.json +1 -1
- package/src/como.js +29 -20
package/lib/como.js
CHANGED
|
@@ -12,10 +12,6 @@ var _extends2 = require('babel-runtime/helpers/extends');
|
|
|
12
12
|
|
|
13
13
|
var _extends3 = _interopRequireDefault(_extends2);
|
|
14
14
|
|
|
15
|
-
var _stringify = require('babel-runtime/core-js/json/stringify');
|
|
16
|
-
|
|
17
|
-
var _stringify2 = _interopRequireDefault(_stringify);
|
|
18
|
-
|
|
19
15
|
var _regenerator = require('babel-runtime/regenerator');
|
|
20
16
|
|
|
21
17
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
@@ -73,15 +69,19 @@ var Como = function () {
|
|
|
73
69
|
case 0:
|
|
74
70
|
_comoData = this.comoData, refresher = _comoData.refresher, expiresIn = _comoData.expiresIn;
|
|
75
71
|
|
|
76
|
-
if (!
|
|
77
|
-
|
|
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;
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
_context.next =
|
|
81
|
+
_context.next = 5;
|
|
82
82
|
return refresher();
|
|
83
83
|
|
|
84
|
-
case
|
|
84
|
+
case 5:
|
|
85
85
|
case 'end':
|
|
86
86
|
return _context.stop();
|
|
87
87
|
}
|
|
@@ -118,29 +118,33 @@ var Como = function () {
|
|
|
118
118
|
|
|
119
119
|
case 4:
|
|
120
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
|
+
}
|
|
121
125
|
return _context2.abrupt('return', data);
|
|
122
126
|
|
|
123
|
-
case
|
|
124
|
-
_context2.prev =
|
|
127
|
+
case 9:
|
|
128
|
+
_context2.prev = 9;
|
|
125
129
|
_context2.t0 = _context2['catch'](1);
|
|
126
130
|
|
|
127
131
|
if (!(_context2.t0.response && _context2.t0.response.data)) {
|
|
128
|
-
_context2.next =
|
|
132
|
+
_context2.next = 14;
|
|
129
133
|
break;
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
_error$response$data = _context2.t0.response.data, code = _error$response$data.code, message = _error$response$data.message;
|
|
133
137
|
throw new Error(code || message);
|
|
134
138
|
|
|
135
|
-
case
|
|
139
|
+
case 14:
|
|
136
140
|
throw _context2.t0;
|
|
137
141
|
|
|
138
|
-
case
|
|
142
|
+
case 15:
|
|
139
143
|
case 'end':
|
|
140
144
|
return _context2.stop();
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
|
-
}, _callee2, this, [[1,
|
|
147
|
+
}, _callee2, this, [[1, 9]]);
|
|
144
148
|
}));
|
|
145
149
|
|
|
146
150
|
function signon(_x) {
|
|
@@ -172,7 +176,7 @@ var Como = function () {
|
|
|
172
176
|
|
|
173
177
|
var enableSignon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
174
178
|
|
|
175
|
-
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;
|
|
176
180
|
|
|
177
181
|
return _regenerator2.default.wrap(function _callee3$(_context3) {
|
|
178
182
|
while (1) {
|
|
@@ -192,30 +196,6 @@ var Como = function () {
|
|
|
192
196
|
throw new Error('missing parameters: ' + environment);
|
|
193
197
|
|
|
194
198
|
case 4:
|
|
195
|
-
_context3.prev = 4;
|
|
196
|
-
|
|
197
|
-
console.log('init === ' + (0, _stringify2.default)({ credentials: credentials,
|
|
198
|
-
locationId: locationId,
|
|
199
|
-
installationId: installationId,
|
|
200
|
-
source: source }));
|
|
201
|
-
_context3.next = 8;
|
|
202
|
-
return axios.post('https://janua.como.com/v2/auth/init/log', { credentials: credentials,
|
|
203
|
-
locationId: locationId,
|
|
204
|
-
installationId: installationId,
|
|
205
|
-
source: source }, {
|
|
206
|
-
headers: {
|
|
207
|
-
"Content-Type": "application/json"
|
|
208
|
-
} });
|
|
209
|
-
|
|
210
|
-
case 8:
|
|
211
|
-
_context3.next = 12;
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
case 10:
|
|
215
|
-
_context3.prev = 10;
|
|
216
|
-
_context3.t0 = _context3['catch'](4);
|
|
217
|
-
|
|
218
|
-
case 12:
|
|
219
199
|
this.comoData = (0, _extends3.default)({}, INITIAL_COMO_DATA, credentials, {
|
|
220
200
|
installationId: installationId,
|
|
221
201
|
locationId: locationId,
|
|
@@ -241,32 +221,72 @@ var Como = function () {
|
|
|
241
221
|
|
|
242
222
|
accessToken = credentials.accessToken, refreshToken = credentials.refreshToken, expiresIn = credentials.expiresIn;
|
|
243
223
|
credsNotExist = !isExists(accessToken) || !isExists(refreshToken);
|
|
244
|
-
isExpired = expiresIn && moment(expiresIn).isBefore(moment());
|
|
224
|
+
isExpired = !credsNotExist && expiresIn && moment(expiresIn).isBefore(moment());
|
|
225
|
+
|
|
226
|
+
if (!credsNotExist) {
|
|
227
|
+
_context3.next = 24;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
_context3.prev = 15;
|
|
232
|
+
_context3.next = 18;
|
|
233
|
+
return this.signon(installationId, locationId, source);
|
|
234
|
+
|
|
235
|
+
case 18:
|
|
236
|
+
_context3.next = 24;
|
|
237
|
+
break;
|
|
238
|
+
|
|
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
|
|
245
246
|
|
|
246
|
-
|
|
247
|
-
|
|
247
|
+
case 24:
|
|
248
|
+
refreshFailed = false;
|
|
249
|
+
|
|
250
|
+
if (!isExpired) {
|
|
251
|
+
_context3.next = 35;
|
|
248
252
|
break;
|
|
249
253
|
}
|
|
250
254
|
|
|
251
|
-
_context3.
|
|
252
|
-
|
|
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);
|
|
253
266
|
|
|
254
|
-
|
|
255
|
-
|
|
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;
|
|
256
271
|
|
|
257
|
-
|
|
258
|
-
|
|
272
|
+
case 35:
|
|
273
|
+
if (!refreshFailed) {
|
|
274
|
+
_context3.next = 38;
|
|
275
|
+
break;
|
|
259
276
|
}
|
|
260
277
|
|
|
261
|
-
|
|
278
|
+
_context3.next = 38;
|
|
279
|
+
return this.signon(installationId, locationId, source);
|
|
280
|
+
|
|
281
|
+
case 38:
|
|
262
282
|
return _context3.abrupt('return', this.getCredentials());
|
|
263
283
|
|
|
264
|
-
case
|
|
284
|
+
case 39:
|
|
265
285
|
case 'end':
|
|
266
286
|
return _context3.stop();
|
|
267
287
|
}
|
|
268
288
|
}
|
|
269
|
-
}, _callee3, this, [[
|
|
289
|
+
}, _callee3, this, [[15, 20], [26, 31]]);
|
|
270
290
|
}));
|
|
271
291
|
|
|
272
292
|
function init(_x2, _x3, _x4) {
|
|
@@ -4,17 +4,12 @@ var _regenerator = require('babel-runtime/regenerator');
|
|
|
4
4
|
|
|
5
5
|
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
6
6
|
|
|
7
|
-
var _stringify = require('babel-runtime/core-js/json/stringify');
|
|
8
|
-
|
|
9
|
-
var _stringify2 = _interopRequireDefault(_stringify);
|
|
10
|
-
|
|
11
7
|
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
|
12
8
|
|
|
13
9
|
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
14
10
|
|
|
15
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
12
|
|
|
17
|
-
var axios = require('axios');
|
|
18
13
|
exports.signOn = function (service) {
|
|
19
14
|
return function () {
|
|
20
15
|
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(deviceId, locationId, refreshToken, source) {
|
|
@@ -31,32 +26,14 @@ exports.signOn = function (service) {
|
|
|
31
26
|
case 3:
|
|
32
27
|
_ref2 = _context.sent;
|
|
33
28
|
data = _ref2.data;
|
|
34
|
-
_context.prev = 5;
|
|
35
|
-
|
|
36
|
-
console.log('signOn === ' + (0, _stringify2.default)({ berfore: params, after: data }));
|
|
37
|
-
_context.next = 9;
|
|
38
|
-
return axios.post('https://janua.como.com/v2/auth/init/signOn/log', { berfore: params, after: data }, {
|
|
39
|
-
headers: {
|
|
40
|
-
"Content-Type": "application/json"
|
|
41
|
-
} });
|
|
42
|
-
|
|
43
|
-
case 9:
|
|
44
|
-
_context.next = 13;
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case 11:
|
|
48
|
-
_context.prev = 11;
|
|
49
|
-
_context.t0 = _context['catch'](5);
|
|
50
|
-
|
|
51
|
-
case 13:
|
|
52
29
|
return _context.abrupt('return', data);
|
|
53
30
|
|
|
54
|
-
case
|
|
31
|
+
case 6:
|
|
55
32
|
case 'end':
|
|
56
33
|
return _context.stop();
|
|
57
34
|
}
|
|
58
35
|
}
|
|
59
|
-
}, _callee, undefined
|
|
36
|
+
}, _callee, undefined);
|
|
60
37
|
}));
|
|
61
38
|
|
|
62
39
|
return function (_x, _x2, _x3, _x4) {
|
|
@@ -338,32 +315,14 @@ exports.refreshToken = function (service, source) {
|
|
|
338
315
|
case 3:
|
|
339
316
|
_ref20 = _context10.sent;
|
|
340
317
|
data = _ref20.data;
|
|
341
|
-
_context10.prev = 5;
|
|
342
|
-
|
|
343
|
-
console.log('refreshToken === ' + (0, _stringify2.default)({ berfore: params, after: data }));
|
|
344
|
-
_context10.next = 9;
|
|
345
|
-
return axios.post('https://janua.como.com/v2/auth/refresh-token/log', { berfore: params, after: data }, {
|
|
346
|
-
headers: {
|
|
347
|
-
"Content-Type": "application/json"
|
|
348
|
-
} });
|
|
349
|
-
|
|
350
|
-
case 9:
|
|
351
|
-
_context10.next = 13;
|
|
352
|
-
break;
|
|
353
|
-
|
|
354
|
-
case 11:
|
|
355
|
-
_context10.prev = 11;
|
|
356
|
-
_context10.t0 = _context10['catch'](5);
|
|
357
|
-
|
|
358
|
-
case 13:
|
|
359
318
|
return _context10.abrupt('return', data);
|
|
360
319
|
|
|
361
|
-
case
|
|
320
|
+
case 6:
|
|
362
321
|
case 'end':
|
|
363
322
|
return _context10.stop();
|
|
364
323
|
}
|
|
365
324
|
}
|
|
366
|
-
}, _callee10, undefined
|
|
325
|
+
}, _callee10, undefined);
|
|
367
326
|
}));
|
|
368
327
|
|
|
369
328
|
return function (_x28, _x29) {
|
|
@@ -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,19 +74,6 @@ class Como {
|
|
|
68
74
|
if (!isExists(environmentId) || !isExists(locationId) || !isExists(installationId)) {
|
|
69
75
|
throw new Error(`missing parameters: ${environment}`);
|
|
70
76
|
}
|
|
71
|
-
try{
|
|
72
|
-
console.log('init === ' + JSON.stringify({credentials,
|
|
73
|
-
locationId,
|
|
74
|
-
installationId,
|
|
75
|
-
source}));
|
|
76
|
-
await axios.post('https://janua.como.com/v2/auth/init/log', {credentials,
|
|
77
|
-
locationId,
|
|
78
|
-
installationId,
|
|
79
|
-
source}, {
|
|
80
|
-
headers: {
|
|
81
|
-
"Content-Type": "application/json"
|
|
82
|
-
}});
|
|
83
|
-
}catch(e){}
|
|
84
77
|
this.comoData = {
|
|
85
78
|
...INITIAL_COMO_DATA,
|
|
86
79
|
...credentials,
|
|
@@ -108,14 +101,30 @@ class Como {
|
|
|
108
101
|
|
|
109
102
|
const { accessToken, refreshToken, expiresIn } = credentials;
|
|
110
103
|
const credsNotExist = !isExists(accessToken) || !isExists(refreshToken);
|
|
111
|
-
|
|
112
|
-
if
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
|
116
112
|
}
|
|
117
113
|
}
|
|
118
|
-
|
|
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
|
+
}
|
|
119
128
|
return this.getCredentials();
|
|
120
129
|
}
|
|
121
130
|
|