@como/como-client 0.8.7 → 0.8.9
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 +505 -448
- package/lib/services/auth.service.js +80 -44
- package/package.json +1 -1
- package/src/como.js +51 -30
|
@@ -265,28 +265,25 @@ exports.unsubscribeSms = function (service) {
|
|
|
265
265
|
}();
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
-
exports.
|
|
268
|
+
exports.unsubscribeWhatsapp = function (service) {
|
|
269
269
|
return function () {
|
|
270
|
-
var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(
|
|
271
|
-
var
|
|
270
|
+
var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(locationId, identifier) {
|
|
271
|
+
var body, _ref16, data;
|
|
272
272
|
|
|
273
273
|
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
|
274
274
|
while (1) {
|
|
275
275
|
switch (_context8.prev = _context8.next) {
|
|
276
276
|
case 0:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
headers = getHashHeader(params);
|
|
281
|
-
_context8.next = 4;
|
|
282
|
-
return service.post('/auth/v4/auth/logIn', params, { headers: headers });
|
|
277
|
+
body = { locationId: locationId, identifier: identifier };
|
|
278
|
+
_context8.next = 3;
|
|
279
|
+
return service.post('/auth/v1/update-profile/unsubscribeWhatsapp', body);
|
|
283
280
|
|
|
284
|
-
case
|
|
281
|
+
case 3:
|
|
285
282
|
_ref16 = _context8.sent;
|
|
286
283
|
data = _ref16.data;
|
|
287
284
|
return _context8.abrupt("return", data);
|
|
288
285
|
|
|
289
|
-
case
|
|
286
|
+
case 6:
|
|
290
287
|
case "end":
|
|
291
288
|
return _context8.stop();
|
|
292
289
|
}
|
|
@@ -294,20 +291,59 @@ exports.logIn = function (service) {
|
|
|
294
291
|
}, _callee8, undefined);
|
|
295
292
|
}));
|
|
296
293
|
|
|
297
|
-
return function (_x25, _x26
|
|
294
|
+
return function (_x25, _x26) {
|
|
298
295
|
return _ref15.apply(this, arguments);
|
|
299
296
|
};
|
|
300
297
|
}();
|
|
301
298
|
};
|
|
302
299
|
|
|
303
|
-
exports.
|
|
300
|
+
exports.logIn = function (service) {
|
|
304
301
|
return function () {
|
|
305
|
-
var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(
|
|
302
|
+
var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform, isWhatsapp) {
|
|
306
303
|
var params, headers, _ref18, data;
|
|
307
304
|
|
|
308
305
|
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
|
309
306
|
while (1) {
|
|
310
307
|
switch (_context9.prev = _context9.next) {
|
|
308
|
+
case 0:
|
|
309
|
+
params = {
|
|
310
|
+
type: type, identifier: identifier, reCaptchaToken: reCaptchaToken, recaptchaTokenType: recaptchaTokenType, devicePlatform: devicePlatform
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
if (typeof isWhatsapp === 'boolean') {
|
|
314
|
+
params.isWhatsapp = isWhatsapp;
|
|
315
|
+
}
|
|
316
|
+
headers = getHashHeader(params);
|
|
317
|
+
_context9.next = 5;
|
|
318
|
+
return service.post('/auth/v4/auth/logIn', params, { headers: headers });
|
|
319
|
+
|
|
320
|
+
case 5:
|
|
321
|
+
_ref18 = _context9.sent;
|
|
322
|
+
data = _ref18.data;
|
|
323
|
+
return _context9.abrupt("return", data);
|
|
324
|
+
|
|
325
|
+
case 8:
|
|
326
|
+
case "end":
|
|
327
|
+
return _context9.stop();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}, _callee9, undefined);
|
|
331
|
+
}));
|
|
332
|
+
|
|
333
|
+
return function (_x27, _x28, _x29, _x30, _x31, _x32) {
|
|
334
|
+
return _ref17.apply(this, arguments);
|
|
335
|
+
};
|
|
336
|
+
}();
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
exports.logInVerify = function (service) {
|
|
340
|
+
return function () {
|
|
341
|
+
var _ref19 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(code, type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform) {
|
|
342
|
+
var params, headers, _ref20, data;
|
|
343
|
+
|
|
344
|
+
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
|
345
|
+
while (1) {
|
|
346
|
+
switch (_context10.prev = _context10.next) {
|
|
311
347
|
case 0:
|
|
312
348
|
params = {
|
|
313
349
|
identifier: identifier,
|
|
@@ -318,82 +354,82 @@ exports.logInVerify = function (service) {
|
|
|
318
354
|
devicePlatform: devicePlatform
|
|
319
355
|
};
|
|
320
356
|
headers = getHashHeader(params);
|
|
321
|
-
|
|
357
|
+
_context10.next = 4;
|
|
322
358
|
return service.post('/auth/v4/auth/logInVerify', params, { headers: headers });
|
|
323
359
|
|
|
324
360
|
case 4:
|
|
325
|
-
|
|
326
|
-
data =
|
|
327
|
-
return
|
|
361
|
+
_ref20 = _context10.sent;
|
|
362
|
+
data = _ref20.data;
|
|
363
|
+
return _context10.abrupt("return", data);
|
|
328
364
|
|
|
329
365
|
case 7:
|
|
330
366
|
case "end":
|
|
331
|
-
return
|
|
367
|
+
return _context10.stop();
|
|
332
368
|
}
|
|
333
369
|
}
|
|
334
|
-
},
|
|
370
|
+
}, _callee10, undefined);
|
|
335
371
|
}));
|
|
336
372
|
|
|
337
|
-
return function (
|
|
338
|
-
return
|
|
373
|
+
return function (_x33, _x34, _x35, _x36, _x37, _x38) {
|
|
374
|
+
return _ref19.apply(this, arguments);
|
|
339
375
|
};
|
|
340
376
|
}();
|
|
341
377
|
};
|
|
342
378
|
|
|
343
379
|
exports.logOut = function (service) {
|
|
344
|
-
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function
|
|
345
|
-
var
|
|
380
|
+
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11() {
|
|
381
|
+
var _ref22, data;
|
|
346
382
|
|
|
347
|
-
return _regenerator2.default.wrap(function
|
|
383
|
+
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
|
348
384
|
while (1) {
|
|
349
|
-
switch (
|
|
385
|
+
switch (_context11.prev = _context11.next) {
|
|
350
386
|
case 0:
|
|
351
|
-
|
|
387
|
+
_context11.next = 2;
|
|
352
388
|
return service.post('/auth/v1/auth/logOut');
|
|
353
389
|
|
|
354
390
|
case 2:
|
|
355
|
-
|
|
356
|
-
data =
|
|
357
|
-
return
|
|
391
|
+
_ref22 = _context11.sent;
|
|
392
|
+
data = _ref22.data;
|
|
393
|
+
return _context11.abrupt("return", data);
|
|
358
394
|
|
|
359
395
|
case 5:
|
|
360
396
|
case "end":
|
|
361
|
-
return
|
|
397
|
+
return _context11.stop();
|
|
362
398
|
}
|
|
363
399
|
}
|
|
364
|
-
},
|
|
400
|
+
}, _callee11, undefined);
|
|
365
401
|
}));
|
|
366
402
|
};
|
|
367
403
|
|
|
368
404
|
exports.refreshToken = function (service) {
|
|
369
405
|
return function () {
|
|
370
|
-
var
|
|
371
|
-
var params, headers,
|
|
406
|
+
var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(uid, token, locationId, source) {
|
|
407
|
+
var params, headers, _ref24, data;
|
|
372
408
|
|
|
373
|
-
return _regenerator2.default.wrap(function
|
|
409
|
+
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
|
374
410
|
while (1) {
|
|
375
|
-
switch (
|
|
411
|
+
switch (_context12.prev = _context12.next) {
|
|
376
412
|
case 0:
|
|
377
413
|
params = { uid: uid, refreshToken: token, locationId: locationId, source: source };
|
|
378
414
|
headers = getHashHeader(params);
|
|
379
|
-
|
|
415
|
+
_context12.next = 4;
|
|
380
416
|
return service.post('/auth/v2/auth/refresh-token', params, { headers: headers });
|
|
381
417
|
|
|
382
418
|
case 4:
|
|
383
|
-
|
|
384
|
-
data =
|
|
385
|
-
return
|
|
419
|
+
_ref24 = _context12.sent;
|
|
420
|
+
data = _ref24.data;
|
|
421
|
+
return _context12.abrupt("return", data);
|
|
386
422
|
|
|
387
423
|
case 7:
|
|
388
424
|
case "end":
|
|
389
|
-
return
|
|
425
|
+
return _context12.stop();
|
|
390
426
|
}
|
|
391
427
|
}
|
|
392
|
-
},
|
|
428
|
+
}, _callee12, undefined);
|
|
393
429
|
}));
|
|
394
430
|
|
|
395
|
-
return function (
|
|
396
|
-
return
|
|
431
|
+
return function (_x39, _x40, _x41, _x42) {
|
|
432
|
+
return _ref23.apply(this, arguments);
|
|
397
433
|
};
|
|
398
434
|
}();
|
|
399
435
|
};
|
package/package.json
CHANGED
package/src/como.js
CHANGED
|
@@ -25,7 +25,7 @@ class Como {
|
|
|
25
25
|
|
|
26
26
|
async refreshTokenIfNeeded() {
|
|
27
27
|
const { refresher, expiresIn } = this.comoData;
|
|
28
|
-
if(!refresher){
|
|
28
|
+
if (!refresher) {
|
|
29
29
|
console.log('No refresh for %o', this.comoData);
|
|
30
30
|
}
|
|
31
31
|
else if (expiresIn && moment(expiresIn).subtract(60, 'seconds').isBefore(moment())) {
|
|
@@ -107,61 +107,61 @@ class Como {
|
|
|
107
107
|
let credExist = isExists(accessToken) && isExists(refreshToken);
|
|
108
108
|
let isExpired = credExist && expiresIn && moment(expiresIn).isBefore(moment());
|
|
109
109
|
let refreshFailed = false;
|
|
110
|
-
if(isExpired){
|
|
111
|
-
try{
|
|
112
|
-
const data = await this.comoData.initApi.refreshToken(installationId, refreshToken?
|
|
110
|
+
if (isExpired) {
|
|
111
|
+
try {
|
|
112
|
+
const data = await this.comoData.initApi.refreshToken(installationId, refreshToken ? refreshToken : 'none', locationId, source);
|
|
113
113
|
this.comoData.config = data.config;
|
|
114
114
|
console.log(`signOn with isExpired true result:${JSON.stringify(data)}`);
|
|
115
115
|
updateCredentials(data, true);
|
|
116
|
-
}catch(e){
|
|
116
|
+
} catch (e) {
|
|
117
117
|
console.error(`Failed to refresh token, installationId:${installationId}, refreshToken:${this.comoData.refreshToken}, locationId:${locationId}, source:${source}`);
|
|
118
118
|
//refresh failed - need to revoke and signOn again
|
|
119
|
-
initService.logError({method: 'refreshToken', installationId, locationId, source, refreshToken, error
|
|
119
|
+
initService.logError({ method: 'refreshToken', installationId, locationId, source, refreshToken, error: e.message });
|
|
120
120
|
refreshFailed = true;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
let interval = 0;
|
|
124
|
-
if(refreshFailed || !credExist){
|
|
125
|
-
while(!credExist && interval < 3000){
|
|
126
|
-
try{
|
|
124
|
+
if (refreshFailed || !credExist) {
|
|
125
|
+
while (!credExist && interval < 3000) {
|
|
126
|
+
try {
|
|
127
127
|
const data = await this.comoData.initApi.signOn(installationId, locationId, source);
|
|
128
128
|
this.comoData.config = data.config;
|
|
129
129
|
console.log(`signOn with refreshFailed result:${JSON.stringify(data)}`);
|
|
130
130
|
updateCredentials(data, true);
|
|
131
131
|
credExist = true;
|
|
132
|
-
}catch(e){
|
|
132
|
+
} catch (e) {
|
|
133
133
|
console.error(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source},interval:${interval}, error:${e}`);
|
|
134
134
|
interval += 1000;
|
|
135
|
-
initService.logError({method: 'signOn no accessToken', accessToken, isExpired, refreshFailed
|
|
135
|
+
initService.logError({ method: 'signOn no accessToken', accessToken, isExpired, refreshFailed, credExist, installationId, locationId, source, refreshToken, interval, error: e.message });
|
|
136
136
|
await new Promise(r => setTimeout(r, interval));
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
else if(!isExpired){
|
|
140
|
+
else if (!isExpired) {
|
|
141
141
|
let signOnSuccessfully = false;
|
|
142
|
-
while(!signOnSuccessfully && interval < 3000){
|
|
143
|
-
try{
|
|
142
|
+
while (!signOnSuccessfully && interval < 3000) {
|
|
143
|
+
try {
|
|
144
144
|
console.log(`signOn with installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}`);
|
|
145
145
|
const data = await this.comoData.initApi.signOn(installationId, locationId, source, accessToken);
|
|
146
146
|
this.comoData.config = data.config;
|
|
147
147
|
console.log(`signOn with result " ${JSON.stringify(data)}`);
|
|
148
|
-
if(data && data.accessToken){
|
|
148
|
+
if (data && data.accessToken) {
|
|
149
149
|
console.log(`signOn- updating credentials`);
|
|
150
150
|
updateCredentials(data, true);
|
|
151
151
|
}
|
|
152
|
-
if(data && data.config && data.config.recaptchaSiteKey){
|
|
152
|
+
if (data && data.config && data.config.recaptchaSiteKey) {
|
|
153
153
|
this.comoData.reCaptchaSiteKey = data.config.recaptchaSiteKey;
|
|
154
154
|
}
|
|
155
155
|
signOnSuccessfully = true;
|
|
156
|
-
}catch(e){
|
|
156
|
+
} catch (e) {
|
|
157
157
|
console.error(`Failed signOn with accessToken, installationId:${installationId}, locationId:${locationId}, source:${source},accessToken:${accessToken}, error:${e.message}`);
|
|
158
158
|
interval += 1000;
|
|
159
|
-
initService.logError({method: 'signOn with credentials', accessToken, isExpired, refreshFailed
|
|
159
|
+
initService.logError({ method: 'signOn with credentials', accessToken, isExpired, refreshFailed, credExist, installationId, locationId, source, refreshToken, interval, error: e.message });
|
|
160
160
|
await new Promise(r => setTimeout(r, interval));
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
if(!this.comoData.token){
|
|
164
|
+
if (!this.comoData.token) {
|
|
165
165
|
this.comoData.token = this.comoData.accessToken;
|
|
166
166
|
}
|
|
167
167
|
return this.getCredentials();
|
|
@@ -349,6 +349,26 @@ class Como {
|
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
+
/**
|
|
353
|
+
*
|
|
354
|
+
* @param {string} unsubscribeWhatsapp unsubscribe user at location
|
|
355
|
+
* @param {string} PhoneNumber phone number to identify user
|
|
356
|
+
*/
|
|
357
|
+
async unsubscribeWhatsapp(PhoneNumber) {
|
|
358
|
+
const { api, locationId } = this.comoData;
|
|
359
|
+
try {
|
|
360
|
+
const identifier = { PhoneNumber };
|
|
361
|
+
const data = await api.unsubscribeWhatsapp(locationId, identifier);
|
|
362
|
+
return data;
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (error.response && error.response.data) {
|
|
365
|
+
const { code, message } = error.response.data;
|
|
366
|
+
throw new Error(code || message);
|
|
367
|
+
}
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
352
372
|
/**
|
|
353
373
|
*
|
|
354
374
|
* @param {Object} identifier an object which identifies the user by its credentials
|
|
@@ -356,11 +376,12 @@ class Como {
|
|
|
356
376
|
* @param {reCaptchaToken} reCaptcha token for login chalenge
|
|
357
377
|
* @param {recaptchaTokenType} recaptcha token type - score/human
|
|
358
378
|
* @param {devicePlatform} device platform i.e. ios/android
|
|
379
|
+
* @param {boolean} isWhatsapp optional flag for whatsapp login flow
|
|
359
380
|
*/
|
|
360
|
-
async login(identifier, type, reCaptchaToken, recaptchaTokenType, devicePlatform) {
|
|
381
|
+
async login(identifier, type, reCaptchaToken, recaptchaTokenType, devicePlatform, isWhatsapp) {
|
|
361
382
|
const { api } = this.comoData;
|
|
362
383
|
try {
|
|
363
|
-
const data = await api.logIn(type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform);
|
|
384
|
+
const data = await api.logIn(type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform, isWhatsapp);
|
|
364
385
|
return data;
|
|
365
386
|
} catch (error) {
|
|
366
387
|
if (error.response && error.response.data) {
|
|
@@ -433,10 +454,10 @@ class Como {
|
|
|
433
454
|
const {
|
|
434
455
|
api, locationId, token, env_params: env,
|
|
435
456
|
} = this.comoData;
|
|
436
|
-
try{
|
|
457
|
+
try {
|
|
437
458
|
return api.clientUpdateMembership(env.services_root, locationId, pushEnable, locationEnable);
|
|
438
459
|
}
|
|
439
|
-
catch(e){
|
|
460
|
+
catch (e) {
|
|
440
461
|
console.log(`clientUpdateMembership failed, token:${token}, locationId:${locationId}, error: ${e}`);
|
|
441
462
|
|
|
442
463
|
}
|
|
@@ -448,13 +469,13 @@ class Como {
|
|
|
448
469
|
*/
|
|
449
470
|
|
|
450
471
|
async downloadMainResource(resourceId) {
|
|
451
|
-
try{
|
|
472
|
+
try {
|
|
452
473
|
const resource = this.comoData.mainResourcesMap[resourceId];
|
|
453
474
|
if (!resource) {
|
|
454
475
|
const err = `resource ${resourceId} not found!`;
|
|
455
476
|
throw new Error(err);
|
|
456
477
|
}
|
|
457
|
-
|
|
478
|
+
|
|
458
479
|
const { env_params: env, api } = this.comoData;
|
|
459
480
|
const responseJson = await api.getLoyaltyResource(
|
|
460
481
|
env.services_root_cdn,
|
|
@@ -463,9 +484,9 @@ class Como {
|
|
|
463
484
|
resource.Version,
|
|
464
485
|
this.comoData.locationId
|
|
465
486
|
);
|
|
466
|
-
|
|
487
|
+
|
|
467
488
|
this.comoData.mainResources[resourceId] = responseJson;
|
|
468
|
-
}catch(e){
|
|
489
|
+
} catch (e) {
|
|
469
490
|
console.log(`downloadMainResource failed, resourceId:${resourceId}, locationId:${this.comoData.locationId}, this.comoData.mainResourcesMap: ${this.comoData.mainResourcesMap}, error: ${e}`);
|
|
470
491
|
throw new Error(e);
|
|
471
492
|
}
|
|
@@ -783,9 +804,9 @@ class Como {
|
|
|
783
804
|
return `${env.app_modules_root}/login?token=${token}&locationid=${locationId}`;
|
|
784
805
|
}
|
|
785
806
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
807
|
+
/**
|
|
808
|
+
* Returns the location data Portability url
|
|
809
|
+
*/
|
|
789
810
|
async getDataPortabilityUrl(url, overrides) {
|
|
790
811
|
await this.refreshTokenIfNeeded();
|
|
791
812
|
const {
|