@como/como-client 0.9.1 → 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 +12 -6
- package/package.json +1 -1
- package/src/como.js +22 -18
package/lib/como.js
CHANGED
|
@@ -208,7 +208,7 @@ var Como = function () {
|
|
|
208
208
|
|
|
209
209
|
_context2.prev = 17;
|
|
210
210
|
_context2.next = 20;
|
|
211
|
-
return this.comoData.initApi.refreshToken(installationId, refreshToken
|
|
211
|
+
return this.comoData.initApi.refreshToken(installationId, refreshToken || 'none', locationId, source);
|
|
212
212
|
|
|
213
213
|
case 20:
|
|
214
214
|
data = _context2.sent;
|
|
@@ -224,8 +224,10 @@ var Como = function () {
|
|
|
224
224
|
_context2.t0 = _context2['catch'](17);
|
|
225
225
|
|
|
226
226
|
console.error('Failed to refresh token, installationId:' + installationId + ', refreshToken:' + this.comoData.refreshToken + ', locationId:' + locationId + ', source:' + source);
|
|
227
|
-
//refresh failed - need to revoke and signOn again
|
|
228
|
-
initService.logError({
|
|
227
|
+
// refresh failed - need to revoke and signOn again
|
|
228
|
+
initService.logError({
|
|
229
|
+
method: 'refreshToken', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, error: _context2.t0.message
|
|
230
|
+
});
|
|
229
231
|
refreshFailed = true;
|
|
230
232
|
|
|
231
233
|
case 31:
|
|
@@ -262,7 +264,9 @@ var Como = function () {
|
|
|
262
264
|
|
|
263
265
|
console.error('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',interval:' + interval + ', error:' + _context2.t1);
|
|
264
266
|
interval += 1000;
|
|
265
|
-
initService.logError({
|
|
267
|
+
initService.logError({
|
|
268
|
+
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
|
|
269
|
+
});
|
|
266
270
|
_context2.next = 51;
|
|
267
271
|
return new _promise2.default(function (r) {
|
|
268
272
|
return setTimeout(r, interval);
|
|
@@ -318,7 +322,9 @@ var Como = function () {
|
|
|
318
322
|
|
|
319
323
|
console.error('Failed signOn with accessToken, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source + ',accessToken:' + accessToken + ', error:' + _context2.t2.message);
|
|
320
324
|
interval += 1000;
|
|
321
|
-
initService.logError({
|
|
325
|
+
initService.logError({
|
|
326
|
+
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
|
|
327
|
+
});
|
|
322
328
|
_context2.next = 77;
|
|
323
329
|
return new _promise2.default(function (r) {
|
|
324
330
|
return setTimeout(r, interval);
|
|
@@ -1998,7 +2004,7 @@ var Como = function () {
|
|
|
1998
2004
|
locationId = _comoData27.locationId;
|
|
1999
2005
|
|
|
2000
2006
|
var cpBaseUrl = env.cp_base_url.replace('{location_id}', locationId);
|
|
2001
|
-
return cpBaseUrl + '/auth/
|
|
2007
|
+
return cpBaseUrl + '/auth/signin?onboardingflow=register&ReferralCode=' + referral;
|
|
2002
2008
|
}
|
|
2003
2009
|
|
|
2004
2010
|
/**
|
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
|
}
|
|
@@ -456,10 +462,8 @@ class Como {
|
|
|
456
462
|
} = this.comoData;
|
|
457
463
|
try {
|
|
458
464
|
return api.clientUpdateMembership(env.services_root, locationId, pushEnable, locationEnable);
|
|
459
|
-
}
|
|
460
|
-
catch (e) {
|
|
465
|
+
} catch (e) {
|
|
461
466
|
console.log(`clientUpdateMembership failed, token:${token}, locationId:${locationId}, error: ${e}`);
|
|
462
|
-
|
|
463
467
|
}
|
|
464
468
|
}
|
|
465
469
|
|
|
@@ -482,7 +486,7 @@ class Como {
|
|
|
482
486
|
resource.id,
|
|
483
487
|
('Namespace' in resource) ? resource.Namespace : `location_${this.comoData.locationId}`,
|
|
484
488
|
resource.Version,
|
|
485
|
-
this.comoData.locationId
|
|
489
|
+
this.comoData.locationId,
|
|
486
490
|
);
|
|
487
491
|
|
|
488
492
|
this.comoData.mainResources[resourceId] = responseJson;
|
|
@@ -837,7 +841,7 @@ class Como {
|
|
|
837
841
|
getFriendReferralInviteLink(referral) {
|
|
838
842
|
const { env_params: env, locationId } = this.comoData;
|
|
839
843
|
const cpBaseUrl = env.cp_base_url.replace('{location_id}', locationId);
|
|
840
|
-
return `${cpBaseUrl}/auth/
|
|
844
|
+
return `${cpBaseUrl}/auth/signin?onboardingflow=register&ReferralCode=${referral}`;
|
|
841
845
|
}
|
|
842
846
|
|
|
843
847
|
/**
|
|
@@ -1046,7 +1050,7 @@ class Como {
|
|
|
1046
1050
|
*/
|
|
1047
1051
|
async getPurchaseHistory(limit, offset) {
|
|
1048
1052
|
const {
|
|
1049
|
-
locationId, api, membership
|
|
1053
|
+
locationId, api, membership,
|
|
1050
1054
|
} = this.comoData;
|
|
1051
1055
|
return api.getPurchaseHistory(locationId, membership.Key, limit, offset);
|
|
1052
1056
|
}
|