@como/como-client 0.9.2 → 0.9.3
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 +335 -418
- package/lib/services/auth.service.js +5 -38
- package/package.json +1 -1
- package/src/como.js +22 -44
|
@@ -401,19 +401,19 @@ exports.logOut = function (service) {
|
|
|
401
401
|
}));
|
|
402
402
|
};
|
|
403
403
|
|
|
404
|
-
exports.
|
|
404
|
+
exports.refreshToken = function (service) {
|
|
405
405
|
return function () {
|
|
406
|
-
var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(
|
|
406
|
+
var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(uid, token, locationId, source) {
|
|
407
407
|
var params, headers, _ref24, data;
|
|
408
408
|
|
|
409
409
|
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
|
410
410
|
while (1) {
|
|
411
411
|
switch (_context12.prev = _context12.next) {
|
|
412
412
|
case 0:
|
|
413
|
-
params = {
|
|
413
|
+
params = { uid: uid, refreshToken: token, locationId: locationId, source: source };
|
|
414
414
|
headers = getHashHeader(params);
|
|
415
415
|
_context12.next = 4;
|
|
416
|
-
return service.post('/auth/
|
|
416
|
+
return service.post('/auth/v2/auth/refresh-token', params, { headers: headers });
|
|
417
417
|
|
|
418
418
|
case 4:
|
|
419
419
|
_ref24 = _context12.sent;
|
|
@@ -428,41 +428,8 @@ exports.socialLogin = function (service) {
|
|
|
428
428
|
}, _callee12, undefined);
|
|
429
429
|
}));
|
|
430
430
|
|
|
431
|
-
return function (_x39, _x40, _x41) {
|
|
431
|
+
return function (_x39, _x40, _x41, _x42) {
|
|
432
432
|
return _ref23.apply(this, arguments);
|
|
433
433
|
};
|
|
434
434
|
}();
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
exports.refreshToken = function (service) {
|
|
438
|
-
return function () {
|
|
439
|
-
var _ref25 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(uid, token, locationId, source) {
|
|
440
|
-
var params, headers, _ref26, data;
|
|
441
|
-
|
|
442
|
-
return _regenerator2.default.wrap(function _callee13$(_context13) {
|
|
443
|
-
while (1) {
|
|
444
|
-
switch (_context13.prev = _context13.next) {
|
|
445
|
-
case 0:
|
|
446
|
-
params = { uid: uid, refreshToken: token, locationId: locationId, source: source };
|
|
447
|
-
headers = getHashHeader(params);
|
|
448
|
-
_context13.next = 4;
|
|
449
|
-
return service.post('/auth/v2/auth/refresh-token', params, { headers: headers });
|
|
450
|
-
|
|
451
|
-
case 4:
|
|
452
|
-
_ref26 = _context13.sent;
|
|
453
|
-
data = _ref26.data;
|
|
454
|
-
return _context13.abrupt("return", data);
|
|
455
|
-
|
|
456
|
-
case 7:
|
|
457
|
-
case "end":
|
|
458
|
-
return _context13.stop();
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}, _callee13, undefined);
|
|
462
|
-
}));
|
|
463
|
-
|
|
464
|
-
return function (_x42, _x43, _x44, _x45) {
|
|
465
|
-
return _ref25.apply(this, arguments);
|
|
466
|
-
};
|
|
467
|
-
}();
|
|
468
435
|
};
|
package/package.json
CHANGED
package/src/como.js
CHANGED
|
@@ -27,8 +27,7 @@ class Como {
|
|
|
27
27
|
const { refresher, expiresIn } = this.comoData;
|
|
28
28
|
if (!refresher) {
|
|
29
29
|
console.log('No refresh for %o', this.comoData);
|
|
30
|
-
}
|
|
31
|
-
else if (expiresIn && moment(expiresIn).subtract(60, 'seconds').isBefore(moment())) {
|
|
30
|
+
} else if (expiresIn && moment(expiresIn).subtract(60, 'seconds').isBefore(moment())) {
|
|
32
31
|
await refresher();
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -70,7 +69,9 @@ class Como {
|
|
|
70
69
|
*/
|
|
71
70
|
async init(environment, credentials, refreshCallback, enableSignon = true) {
|
|
72
71
|
const isExists = (x => !ramda.isNil(x) && !ramda.isEmpty(x));
|
|
73
|
-
const {
|
|
72
|
+
const {
|
|
73
|
+
id: environmentId, locationId, installationId, source, binaryVersion, phoenixVersion,
|
|
74
|
+
} = environment;
|
|
74
75
|
if (!isExists(environmentId) || !isExists(locationId) || !isExists(installationId)) {
|
|
75
76
|
throw new Error(`missing parameters: ${environment}`);
|
|
76
77
|
}
|
|
@@ -105,18 +106,20 @@ class Como {
|
|
|
105
106
|
|
|
106
107
|
const { accessToken, refreshToken, expiresIn } = credentials;
|
|
107
108
|
let credExist = isExists(accessToken) && isExists(refreshToken);
|
|
108
|
-
|
|
109
|
+
const isExpired = credExist && expiresIn && moment(expiresIn).isBefore(moment());
|
|
109
110
|
let refreshFailed = false;
|
|
110
111
|
if (isExpired) {
|
|
111
112
|
try {
|
|
112
|
-
const data = await this.comoData.initApi.refreshToken(installationId, refreshToken
|
|
113
|
+
const data = await this.comoData.initApi.refreshToken(installationId, refreshToken || 'none', locationId, source);
|
|
113
114
|
this.comoData.config = data.config;
|
|
114
115
|
console.log(`signOn with isExpired true result:${JSON.stringify(data)}`);
|
|
115
116
|
updateCredentials(data, true);
|
|
116
117
|
} catch (e) {
|
|
117
118
|
console.error(`Failed to refresh token, installationId:${installationId}, refreshToken:${this.comoData.refreshToken}, locationId:${locationId}, source:${source}`);
|
|
118
|
-
//refresh failed - need to revoke and signOn again
|
|
119
|
-
initService.logError({
|
|
119
|
+
// refresh failed - need to revoke and signOn again
|
|
120
|
+
initService.logError({
|
|
121
|
+
method: 'refreshToken', installationId, locationId, source, refreshToken, error: e.message,
|
|
122
|
+
});
|
|
120
123
|
refreshFailed = true;
|
|
121
124
|
}
|
|
122
125
|
}
|
|
@@ -132,12 +135,13 @@ class Como {
|
|
|
132
135
|
} catch (e) {
|
|
133
136
|
console.error(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source},interval:${interval}, error:${e}`);
|
|
134
137
|
interval += 1000;
|
|
135
|
-
initService.logError({
|
|
138
|
+
initService.logError({
|
|
139
|
+
method: 'signOn no accessToken', accessToken, isExpired, refreshFailed, credExist, installationId, locationId, source, refreshToken, interval, error: e.message,
|
|
140
|
+
});
|
|
136
141
|
await new Promise(r => setTimeout(r, interval));
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
|
-
}
|
|
140
|
-
else if (!isExpired) {
|
|
144
|
+
} else if (!isExpired) {
|
|
141
145
|
let signOnSuccessfully = false;
|
|
142
146
|
while (!signOnSuccessfully && interval < 3000) {
|
|
143
147
|
try {
|
|
@@ -146,7 +150,7 @@ class Como {
|
|
|
146
150
|
this.comoData.config = data.config;
|
|
147
151
|
console.log(`signOn with result " ${JSON.stringify(data)}`);
|
|
148
152
|
if (data && data.accessToken) {
|
|
149
|
-
console.log(
|
|
153
|
+
console.log('signOn- updating credentials');
|
|
150
154
|
updateCredentials(data, true);
|
|
151
155
|
}
|
|
152
156
|
if (data && data.config && data.config.recaptchaSiteKey) {
|
|
@@ -156,7 +160,9 @@ class Como {
|
|
|
156
160
|
} catch (e) {
|
|
157
161
|
console.error(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e.message}`);
|
|
158
162
|
interval += 1000;
|
|
159
|
-
initService.logError({
|
|
163
|
+
initService.logError({
|
|
164
|
+
method: 'signOn with credentials', accessToken, isExpired, refreshFailed, credExist, installationId, locationId, source, refreshToken, interval, error: e.message,
|
|
165
|
+
});
|
|
160
166
|
await new Promise(r => setTimeout(r, interval));
|
|
161
167
|
}
|
|
162
168
|
}
|
|
@@ -392,32 +398,6 @@ class Como {
|
|
|
392
398
|
}
|
|
393
399
|
}
|
|
394
400
|
|
|
395
|
-
/**
|
|
396
|
-
* Social login via Firebase SSO (Google/Facebook/Apple).
|
|
397
|
-
* @param {Object} params
|
|
398
|
-
* @param {string} params.socialId - Firebase user UID
|
|
399
|
-
* @param {string} params.provider - Social provider (google/facebook/apple)
|
|
400
|
-
* @param {string} params.idToken - Firebase ID token
|
|
401
|
-
* @returns {Promise<Object>} { success, accessToken, refreshToken, consent } or { success: false, userExists: false }
|
|
402
|
-
*/
|
|
403
|
-
async socialLogin({ socialId, provider, idToken }) {
|
|
404
|
-
const { api } = this.comoData;
|
|
405
|
-
try {
|
|
406
|
-
const data = await api.socialLogin(socialId, provider, idToken);
|
|
407
|
-
return data;
|
|
408
|
-
} catch (error) {
|
|
409
|
-
if (error.response && error.response.data) {
|
|
410
|
-
const { code, message } = error.response.data;
|
|
411
|
-
throw new Error(code || message);
|
|
412
|
-
}
|
|
413
|
-
throw error;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async socialLoginCheck({ socialId, provider, idToken }) {
|
|
418
|
-
return this.socialLogin({ socialId, provider, idToken });
|
|
419
|
-
}
|
|
420
|
-
|
|
421
401
|
/**
|
|
422
402
|
*
|
|
423
403
|
* @param {Object} identifier key-value identifiers
|
|
@@ -482,10 +462,8 @@ class Como {
|
|
|
482
462
|
} = this.comoData;
|
|
483
463
|
try {
|
|
484
464
|
return api.clientUpdateMembership(env.services_root, locationId, pushEnable, locationEnable);
|
|
485
|
-
}
|
|
486
|
-
catch (e) {
|
|
465
|
+
} catch (e) {
|
|
487
466
|
console.log(`clientUpdateMembership failed, token:${token}, locationId:${locationId}, error: ${e}`);
|
|
488
|
-
|
|
489
467
|
}
|
|
490
468
|
}
|
|
491
469
|
|
|
@@ -508,7 +486,7 @@ class Como {
|
|
|
508
486
|
resource.id,
|
|
509
487
|
('Namespace' in resource) ? resource.Namespace : `location_${this.comoData.locationId}`,
|
|
510
488
|
resource.Version,
|
|
511
|
-
this.comoData.locationId
|
|
489
|
+
this.comoData.locationId,
|
|
512
490
|
);
|
|
513
491
|
|
|
514
492
|
this.comoData.mainResources[resourceId] = responseJson;
|
|
@@ -863,7 +841,7 @@ class Como {
|
|
|
863
841
|
getFriendReferralInviteLink(referral) {
|
|
864
842
|
const { env_params: env, locationId } = this.comoData;
|
|
865
843
|
const cpBaseUrl = env.cp_base_url.replace('{location_id}', locationId);
|
|
866
|
-
return `${cpBaseUrl}/auth/
|
|
844
|
+
return `${cpBaseUrl}/auth/signin?onboardingflow=register&ReferralCode=${referral}`;
|
|
867
845
|
}
|
|
868
846
|
|
|
869
847
|
/**
|
|
@@ -1072,7 +1050,7 @@ class Como {
|
|
|
1072
1050
|
*/
|
|
1073
1051
|
async getPurchaseHistory(limit, offset) {
|
|
1074
1052
|
const {
|
|
1075
|
-
locationId, api, membership
|
|
1053
|
+
locationId, api, membership,
|
|
1076
1054
|
} = this.comoData;
|
|
1077
1055
|
return api.getPurchaseHistory(locationId, membership.Key, limit, offset);
|
|
1078
1056
|
}
|