@como/como-client 0.8.6 → 0.8.8

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.
@@ -265,28 +265,25 @@ exports.unsubscribeSms = function (service) {
265
265
  }();
266
266
  };
267
267
 
268
- exports.logIn = function (service) {
268
+ exports.unsubscribeWhatsapp = function (service) {
269
269
  return function () {
270
- var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform) {
271
- var params, headers, _ref16, data;
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
- params = {
278
- type: type, identifier: identifier, reCaptchaToken: reCaptchaToken, recaptchaTokenType: recaptchaTokenType, devicePlatform: devicePlatform
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 4:
281
+ case 3:
285
282
  _ref16 = _context8.sent;
286
283
  data = _ref16.data;
287
284
  return _context8.abrupt("return", data);
288
285
 
289
- case 7:
286
+ case 6:
290
287
  case "end":
291
288
  return _context8.stop();
292
289
  }
@@ -294,15 +291,15 @@ exports.logIn = function (service) {
294
291
  }, _callee8, undefined);
295
292
  }));
296
293
 
297
- return function (_x25, _x26, _x27, _x28, _x29) {
294
+ return function (_x25, _x26) {
298
295
  return _ref15.apply(this, arguments);
299
296
  };
300
297
  }();
301
298
  };
302
299
 
303
- exports.logInVerify = function (service) {
300
+ exports.logIn = function (service) {
304
301
  return function () {
305
- var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(code, type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform) {
302
+ var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform) {
306
303
  var params, headers, _ref18, data;
307
304
 
308
305
  return _regenerator2.default.wrap(function _callee9$(_context9) {
@@ -310,16 +307,11 @@ exports.logInVerify = function (service) {
310
307
  switch (_context9.prev = _context9.next) {
311
308
  case 0:
312
309
  params = {
313
- identifier: identifier,
314
- code: code,
315
- type: type,
316
- reCaptchaToken: reCaptchaToken,
317
- recaptchaTokenType: recaptchaTokenType,
318
- devicePlatform: devicePlatform
310
+ type: type, identifier: identifier, reCaptchaToken: reCaptchaToken, recaptchaTokenType: recaptchaTokenType, devicePlatform: devicePlatform
319
311
  };
320
312
  headers = getHashHeader(params);
321
313
  _context9.next = 4;
322
- return service.post('/auth/v4/auth/logInVerify', params, { headers: headers });
314
+ return service.post('/auth/v4/auth/logIn', params, { headers: headers });
323
315
 
324
316
  case 4:
325
317
  _ref18 = _context9.sent;
@@ -334,66 +326,106 @@ exports.logInVerify = function (service) {
334
326
  }, _callee9, undefined);
335
327
  }));
336
328
 
337
- return function (_x30, _x31, _x32, _x33, _x34, _x35) {
329
+ return function (_x27, _x28, _x29, _x30, _x31) {
338
330
  return _ref17.apply(this, arguments);
339
331
  };
340
332
  }();
341
333
  };
342
334
 
335
+ exports.logInVerify = function (service) {
336
+ return function () {
337
+ var _ref19 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(code, type, identifier, reCaptchaToken, recaptchaTokenType, devicePlatform) {
338
+ var params, headers, _ref20, data;
339
+
340
+ return _regenerator2.default.wrap(function _callee10$(_context10) {
341
+ while (1) {
342
+ switch (_context10.prev = _context10.next) {
343
+ case 0:
344
+ params = {
345
+ identifier: identifier,
346
+ code: code,
347
+ type: type,
348
+ reCaptchaToken: reCaptchaToken,
349
+ recaptchaTokenType: recaptchaTokenType,
350
+ devicePlatform: devicePlatform
351
+ };
352
+ headers = getHashHeader(params);
353
+ _context10.next = 4;
354
+ return service.post('/auth/v4/auth/logInVerify', params, { headers: headers });
355
+
356
+ case 4:
357
+ _ref20 = _context10.sent;
358
+ data = _ref20.data;
359
+ return _context10.abrupt("return", data);
360
+
361
+ case 7:
362
+ case "end":
363
+ return _context10.stop();
364
+ }
365
+ }
366
+ }, _callee10, undefined);
367
+ }));
368
+
369
+ return function (_x32, _x33, _x34, _x35, _x36, _x37) {
370
+ return _ref19.apply(this, arguments);
371
+ };
372
+ }();
373
+ };
374
+
343
375
  exports.logOut = function (service) {
344
- return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10() {
345
- var _ref20, data;
376
+ return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11() {
377
+ var _ref22, data;
346
378
 
347
- return _regenerator2.default.wrap(function _callee10$(_context10) {
379
+ return _regenerator2.default.wrap(function _callee11$(_context11) {
348
380
  while (1) {
349
- switch (_context10.prev = _context10.next) {
381
+ switch (_context11.prev = _context11.next) {
350
382
  case 0:
351
- _context10.next = 2;
383
+ _context11.next = 2;
352
384
  return service.post('/auth/v1/auth/logOut');
353
385
 
354
386
  case 2:
355
- _ref20 = _context10.sent;
356
- data = _ref20.data;
357
- return _context10.abrupt("return", data);
387
+ _ref22 = _context11.sent;
388
+ data = _ref22.data;
389
+ return _context11.abrupt("return", data);
358
390
 
359
391
  case 5:
360
392
  case "end":
361
- return _context10.stop();
393
+ return _context11.stop();
362
394
  }
363
395
  }
364
- }, _callee10, undefined);
396
+ }, _callee11, undefined);
365
397
  }));
366
398
  };
367
399
 
368
400
  exports.refreshToken = function (service) {
369
401
  return function () {
370
- var _ref21 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(uid, token, locationId, source) {
371
- var params, headers, _ref22, data;
402
+ var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(uid, token, locationId, source) {
403
+ var params, headers, _ref24, data;
372
404
 
373
- return _regenerator2.default.wrap(function _callee11$(_context11) {
405
+ return _regenerator2.default.wrap(function _callee12$(_context12) {
374
406
  while (1) {
375
- switch (_context11.prev = _context11.next) {
407
+ switch (_context12.prev = _context12.next) {
376
408
  case 0:
377
409
  params = { uid: uid, refreshToken: token, locationId: locationId, source: source };
378
410
  headers = getHashHeader(params);
379
- _context11.next = 4;
411
+ _context12.next = 4;
380
412
  return service.post('/auth/v2/auth/refresh-token', params, { headers: headers });
381
413
 
382
414
  case 4:
383
- _ref22 = _context11.sent;
384
- data = _ref22.data;
385
- return _context11.abrupt("return", data);
415
+ _ref24 = _context12.sent;
416
+ data = _ref24.data;
417
+ return _context12.abrupt("return", data);
386
418
 
387
419
  case 7:
388
420
  case "end":
389
- return _context11.stop();
421
+ return _context12.stop();
390
422
  }
391
423
  }
392
- }, _callee11, undefined);
424
+ }, _callee12, undefined);
393
425
  }));
394
426
 
395
- return function (_x36, _x37, _x38, _x39) {
396
- return _ref21.apply(this, arguments);
427
+ return function (_x38, _x39, _x40, _x41) {
428
+ return _ref23.apply(this, arguments);
397
429
  };
398
430
  }();
399
431
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@como/como-client",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "Client module for Como's loaylty API",
5
5
  "main": "src/como.js",
6
6
  "scripts": {
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "homepage": "https://github.com/ConduitMobileRND/como-client-lib#readme",
28
28
  "dependencies": {
29
- "axios": "^0.18.0",
29
+ "axios": "^0.30.2",
30
30
  "chai": "^4.1.2",
31
31
  "json-stable-stringify": "1.0.1",
32
32
  "jssha": "^3.2.0",
33
33
  "mocha": "^5.2.0",
34
- "moment-timezone": "^0.5.17",
34
+ "moment-timezone": "^0.5.35",
35
35
  "ramda": "^0.25.0"
36
36
  },
37
37
  "devDependencies": {
@@ -50,4 +50,4 @@
50
50
  "webpack": "^4.8.3",
51
51
  "webpack-cli": "^2.1.4"
52
52
  }
53
- }
53
+ }
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? refreshToken: 'none', locationId, source);
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 : e.message});
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 , credExist, installationId, locationId, source, refreshToken, interval, error : e.message});
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 , credExist, installationId, locationId, source, refreshToken, interval, error : e.message});
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
@@ -433,10 +453,10 @@ class Como {
433
453
  const {
434
454
  api, locationId, token, env_params: env,
435
455
  } = this.comoData;
436
- try{
456
+ try {
437
457
  return api.clientUpdateMembership(env.services_root, locationId, pushEnable, locationEnable);
438
458
  }
439
- catch(e){
459
+ catch (e) {
440
460
  console.log(`clientUpdateMembership failed, token:${token}, locationId:${locationId}, error: ${e}`);
441
461
 
442
462
  }
@@ -448,13 +468,13 @@ class Como {
448
468
  */
449
469
 
450
470
  async downloadMainResource(resourceId) {
451
- try{
471
+ try {
452
472
  const resource = this.comoData.mainResourcesMap[resourceId];
453
473
  if (!resource) {
454
474
  const err = `resource ${resourceId} not found!`;
455
475
  throw new Error(err);
456
476
  }
457
-
477
+
458
478
  const { env_params: env, api } = this.comoData;
459
479
  const responseJson = await api.getLoyaltyResource(
460
480
  env.services_root_cdn,
@@ -463,9 +483,9 @@ class Como {
463
483
  resource.Version,
464
484
  this.comoData.locationId
465
485
  );
466
-
486
+
467
487
  this.comoData.mainResources[resourceId] = responseJson;
468
- }catch(e){
488
+ } catch (e) {
469
489
  console.log(`downloadMainResource failed, resourceId:${resourceId}, locationId:${this.comoData.locationId}, this.comoData.mainResourcesMap: ${this.comoData.mainResourcesMap}, error: ${e}`);
470
490
  throw new Error(e);
471
491
  }
@@ -783,9 +803,9 @@ class Como {
783
803
  return `${env.app_modules_root}/login?token=${token}&locationid=${locationId}`;
784
804
  }
785
805
 
786
- /**
787
- * Returns the location data Portability url
788
- */
806
+ /**
807
+ * Returns the location data Portability url
808
+ */
789
809
  async getDataPortabilityUrl(url, overrides) {
790
810
  await this.refreshTokenIfNeeded();
791
811
  const {