@como/como-client 0.1.292 → 0.1.991

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 CHANGED
@@ -20,6 +20,14 @@ var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
20
20
 
21
21
  var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
22
22
 
23
+ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
24
+
25
+ var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
26
+
27
+ var _createClass2 = require('babel-runtime/helpers/createClass');
28
+
29
+ var _createClass3 = _interopRequireDefault(_createClass2);
30
+
23
31
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
32
 
25
33
  var moment = require('moment-timezone');
@@ -30,8 +38,6 @@ var comoExternalUrlTranslator = require('./utils/comoExternalUrlTranslator');
30
38
  var resourceNames = require('./constants/resourceNames');
31
39
  var urlsUtils = require('./utils/urls');
32
40
 
33
- var como = {};
34
- var comoData = void 0;
35
41
  var INITIAL_COMO_DATA = {
36
42
  env: environmentConfig,
37
43
  token: null,
@@ -40,1581 +46,2201 @@ var INITIAL_COMO_DATA = {
40
46
  installationId: null,
41
47
  membership: null,
42
48
  assets: null,
43
- archivedAssets: null,
44
- redeemedAssets: null,
45
49
  mainResources: {}
46
50
  };
47
51
 
48
- var refreshTokenIfNeeded = function () {
49
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
50
- var _comoData, refresher, expiresIn;
52
+ var Como = function () {
53
+ function Como() {
54
+ (0, _classCallCheck3.default)(this, Como);
51
55
 
52
- return _regenerator2.default.wrap(function _callee$(_context) {
53
- while (1) {
54
- switch (_context.prev = _context.next) {
55
- case 0:
56
- _comoData = comoData, refresher = _comoData.refresher, expiresIn = _comoData.expiresIn;
56
+ this.comoData = {};
57
+ }
57
58
 
58
- if (!(expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment()))) {
59
- _context.next = 4;
60
- break;
59
+ (0, _createClass3.default)(Como, [{
60
+ key: 'refreshTokenIfNeeded',
61
+ value: function () {
62
+ var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
63
+ var _comoData, refresher, expiresIn;
64
+
65
+ return _regenerator2.default.wrap(function _callee$(_context) {
66
+ while (1) {
67
+ switch (_context.prev = _context.next) {
68
+ case 0:
69
+ _comoData = this.comoData, refresher = _comoData.refresher, expiresIn = _comoData.expiresIn;
70
+
71
+ if (refresher) {
72
+ _context.next = 5;
73
+ break;
74
+ }
75
+
76
+ console.log('No refresh for %o', this.comoData);
77
+ _context.next = 8;
78
+ break;
79
+
80
+ case 5:
81
+ if (!(expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment()))) {
82
+ _context.next = 8;
83
+ break;
84
+ }
85
+
86
+ _context.next = 8;
87
+ return refresher();
88
+
89
+ case 8:
90
+ case 'end':
91
+ return _context.stop();
61
92
  }
93
+ }
94
+ }, _callee, this);
95
+ }));
62
96
 
63
- _context.next = 4;
64
- return refresher();
65
-
66
- case 4:
67
- case 'end':
68
- return _context.stop();
69
- }
97
+ function refreshTokenIfNeeded() {
98
+ return _ref.apply(this, arguments);
70
99
  }
71
- }, _callee, undefined);
72
- }));
73
100
 
74
- return function refreshTokenIfNeeded() {
75
- return _ref.apply(this, arguments);
76
- };
77
- }();
101
+ return refreshTokenIfNeeded;
102
+ }()
103
+
104
+ /**
105
+ * Sign the user and returns guest token & refresh token.
106
+ * Requires init.
107
+ */
108
+ // async signon(source) {
109
+ // const { InitApi: api } = this.comoData;
110
+ // try {
111
+ // const data = await api.signOn(this.comoData.installationId, this.comoData.locationId, this.comoData.refreshToken, source);
112
+ // if (data && data.config && data.config.loyaltyCDN) {
113
+ // this.comoData.env_params.services_root_cdn = data.config.loyaltyCDN;
114
+ // }
115
+ // return data;
116
+ // } catch (error) {
117
+ // if (error.response && error.response.data) {
118
+ // const { code, message } = error.response.data;
119
+ // throw new Error(code || message);
120
+ // }
121
+ // throw error;
122
+ // }
123
+ // }
124
+
125
+ /**
126
+ *
127
+ * @param {Object} environment Environemnt object
128
+ * @param {string} environment.id Environment Id
129
+ * @param {string} environment.locationId Location Id
130
+ * @param {string} environment.installationId Unique installation id
131
+ * @param {Object} credentials Member credentials (Optional)
132
+ * @param {string} accessToken session id string (Optional)
133
+ * @param {string} refreshToken refresh token string (Optional)
134
+ * @param {string} expiresIn access token expiration date formatted (Optional)
135
+ * @param {function} refreshCallback an event callback which fires each time user's tokens gets refreshed
136
+ * @param {boolean} enableSignon if disabled signOn api call will not be fired. Enabled by default.
137
+ */
138
+
139
+ }, {
140
+ key: 'init',
141
+ value: function () {
142
+ var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(environment, credentials, refreshCallback) {
143
+ var _this = this;
144
+
145
+ var enableSignon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
146
+
147
+ var isExists, environmentId, locationId, installationId, source, updateCredentials, getCredentials, gateway, _APIService$getServic, service, refresher, initService, accessToken, refreshToken, expiresIn, credExist, isExpired, refreshFailed, data, interval, _data;
148
+
149
+ return _regenerator2.default.wrap(function _callee2$(_context2) {
150
+ while (1) {
151
+ switch (_context2.prev = _context2.next) {
152
+ case 0:
153
+ isExists = function isExists(x) {
154
+ return !ramda.isNil(x) && !ramda.isEmpty(x);
155
+ };
156
+
157
+ environmentId = environment.id, locationId = environment.locationId, installationId = environment.installationId, source = environment.source;
158
+
159
+ if (!(!isExists(environmentId) || !isExists(locationId) || !isExists(installationId))) {
160
+ _context2.next = 4;
161
+ break;
162
+ }
163
+
164
+ throw new Error('missing parameters: ' + environment);
165
+
166
+ case 4:
167
+
168
+ this.comoData = (0, _extends3.default)({}, INITIAL_COMO_DATA, credentials, {
169
+ installationId: installationId,
170
+ locationId: locationId,
171
+ source: source,
172
+ env_params: (0, _extends3.default)({}, INITIAL_COMO_DATA.env[environmentId])
173
+ });
174
+
175
+ updateCredentials = function updateCredentials(creds) {
176
+ var isNew = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
177
+
178
+ _this.updateLocalCreds(creds);
179
+ if (refreshCallback && isNew) {
180
+ refreshCallback(creds);
181
+ }
182
+ };
183
+
184
+ getCredentials = this.getCredentials.bind(this);
185
+ gateway = this.comoData.env_params.gateway;
186
+ _APIService$getServic = APIService.getService(gateway, installationId, getCredentials, updateCredentials), service = _APIService$getServic.service, refresher = _APIService$getServic.refresher, initService = _APIService$getServic.initService;
187
+
188
+ this.comoData.api = service;
189
+ this.comoData.initApi = initService;
190
+ this.comoData.refresher = refresher;
191
+
192
+ accessToken = credentials.accessToken, refreshToken = credentials.refreshToken, expiresIn = credentials.expiresIn;
193
+ credExist = isExists(accessToken) && isExists(refreshToken);
194
+ isExpired = credExist && expiresIn && moment(expiresIn).isBefore(moment());
195
+ refreshFailed = false;
196
+
197
+ if (!isExpired) {
198
+ _context2.next = 29;
199
+ break;
200
+ }
201
+
202
+ _context2.prev = 17;
203
+ _context2.next = 20;
204
+ return this.comoData.initApi.refreshToken(installationId, refreshToken ? refreshToken : 'none', locationId, source);
205
+
206
+ case 20:
207
+ data = _context2.sent;
208
+
209
+ updateCredentials(data, true);
210
+ _context2.next = 29;
211
+ break;
212
+
213
+ case 24:
214
+ _context2.prev = 24;
215
+ _context2.t0 = _context2['catch'](17);
216
+
217
+ console.log('Failed to refresh token, installationId:' + installationId + ', refreshToken:' + this.comoData.refreshToken + ', locationId:' + locationId + ', source:' + source);
218
+ //refresh failed - need to revoke and signOn again
219
+ initService.logError({ method: 'refreshToken', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken });
220
+ refreshFailed = true;
221
+
222
+ case 29:
223
+ interval = 0;
224
+
225
+ if (!(refreshFailed || !credExist)) {
226
+ _context2.next = 48;
227
+ break;
228
+ }
229
+
230
+ case 31:
231
+ if (!(!credExist && interval < 3000)) {
232
+ _context2.next = 48;
233
+ break;
234
+ }
235
+
236
+ _context2.prev = 32;
237
+ _context2.next = 35;
238
+ return this.comoData.initApi.signOn(installationId, locationId, refreshToken, source);
239
+
240
+ case 35:
241
+ _data = _context2.sent;
242
+
243
+ updateCredentials(_data, true);
244
+ credExist = true;
245
+ _context2.next = 46;
246
+ break;
247
+
248
+ case 40:
249
+ _context2.prev = 40;
250
+ _context2.t1 = _context2['catch'](32);
251
+
252
+ console.log('Failed to signOn, installationId:' + installationId + ', locationId:' + locationId + ', source:' + source);
253
+ initService.logError({ method: 'signOn', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval });
254
+
255
+ interval += 1000;
256
+ setTimeout(function () {
257
+ console.log('waking for another try of signOn, interval: ' + interval + ', installationId:' + installationId + ', locationId:' + locationId + ', source:' + source);
258
+ initService.logError({ method: 'signOn', installationId: installationId, locationId: locationId, source: source, refreshToken: refreshToken, interval: interval });
259
+ }, interval);
260
+
261
+ case 46:
262
+ _context2.next = 31;
263
+ break;
264
+
265
+ case 48:
266
+ return _context2.abrupt('return', this.getCredentials());
267
+
268
+ case 49:
269
+ case 'end':
270
+ return _context2.stop();
271
+ }
272
+ }
273
+ }, _callee2, this, [[17, 24], [32, 40]]);
274
+ }));
78
275
 
79
- /**
80
- * Sign the user and returns guest token & refresh token.
81
- * Requires init.
82
- */
83
- como.signon = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
84
- var _comoData2, api, data, _error$response$data, code, message;
85
-
86
- return _regenerator2.default.wrap(function _callee2$(_context2) {
87
- while (1) {
88
- switch (_context2.prev = _context2.next) {
89
- case 0:
90
- _comoData2 = comoData, api = _comoData2.api;
91
- _context2.prev = 1;
92
- _context2.next = 4;
93
- return api.signOn(comoData.installationId, comoData.locationId);
94
-
95
- case 4:
96
- data = _context2.sent;
97
- return _context2.abrupt('return', data);
98
-
99
- case 8:
100
- _context2.prev = 8;
101
- _context2.t0 = _context2['catch'](1);
102
-
103
- if (!(_context2.t0.response && _context2.t0.response.data)) {
104
- _context2.next = 13;
105
- break;
276
+ function init(_x, _x2, _x3) {
277
+ return _ref2.apply(this, arguments);
278
+ }
279
+
280
+ return init;
281
+ }()
282
+
283
+ /**
284
+ * Updates the como.js local credentials settings.
285
+ * Used when making api calls to janua.
286
+ *
287
+ * @param {Object} credentials credentials to update.
288
+ * @param {Object} accessToken access token to update.
289
+ * @param {Object} refreshToken refresh token to update.
290
+ * @param {Object} expiresIn access token expiry date to update.
291
+ */
292
+
293
+ }, {
294
+ key: 'updateLocalCreds',
295
+ value: function updateLocalCreds() {
296
+ var credentials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
297
+
298
+ this.comoData.accessToken = credentials.accessToken;
299
+ this.comoData.token = credentials.accessToken;
300
+ this.comoData.refreshToken = credentials.refreshToken;
301
+ this.comoData.expiresIn = credentials.expiresIn;
302
+ }
303
+ }, {
304
+ key: 'getExternalUrlByID',
305
+ value: function getExternalUrlByID(itemID, gpsData, assetID, accessibilityData) {
306
+ var locationData = this.comoData.mainResources[resourceNames.LOCATION_DATA];
307
+ if (locationData && locationData.WebViews && locationData.WebViews[0].item) {
308
+ var possibleWebViews = locationData.WebViews[0].item.filter(function (u) {
309
+ return u.id === itemID;
310
+ });
311
+ var url = possibleWebViews && possibleWebViews[0] && possibleWebViews[0].url;
312
+ return this.translateExternalUrl(url, gpsData, assetID, accessibilityData);
313
+ }
314
+ return null;
315
+ }
316
+ }, {
317
+ key: 'translateExternalUrl',
318
+ value: function () {
319
+ var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(url, gpsData, assetID, accessibilityData) {
320
+ var legacyUrl, externalUrl, _comoData2, api, locationId, token, env, membership, assets, locationData, apiObjects, dataToUse;
321
+
322
+ return _regenerator2.default.wrap(function _callee3$(_context3) {
323
+ while (1) {
324
+ switch (_context3.prev = _context3.next) {
325
+ case 0:
326
+ _context3.next = 2;
327
+ return this.getAppModulesLegacyBaseUrl();
328
+
329
+ case 2:
330
+ legacyUrl = _context3.sent;
331
+ externalUrl = url;
332
+
333
+ if (externalUrl && externalUrl.startsWith(legacyUrl)) {
334
+ externalUrl = externalUrl.replace(legacyUrl, this.comoData.env_params.app_modules_root);
335
+ }
336
+ _comoData2 = this.comoData, api = _comoData2.api, locationId = _comoData2.locationId, token = _comoData2.token, env = _comoData2.env_params, membership = _comoData2.membership, assets = _comoData2.assets;
337
+ locationData = this.comoData.mainResources && this.comoData.mainResources[resourceNames.LOCATION_DATA];
338
+ apiObjects = { api: api, servicesRoot: env.services_root };
339
+ dataToUse = {
340
+ locationId: locationId, token: token, membership: membership, locationData: locationData, assets: assets, gpsData: gpsData, assetID: assetID, accessibilityData: accessibilityData
341
+ };
342
+ return _context3.abrupt('return', comoExternalUrlTranslator.translateUrl(externalUrl, apiObjects, dataToUse));
343
+
344
+ case 10:
345
+ case 'end':
346
+ return _context3.stop();
347
+ }
106
348
  }
349
+ }, _callee3, this);
350
+ }));
107
351
 
108
- _error$response$data = _context2.t0.response.data, code = _error$response$data.code, message = _error$response$data.message;
109
- throw new Error(code || message);
352
+ function translateExternalUrl(_x7, _x8, _x9, _x10) {
353
+ return _ref3.apply(this, arguments);
354
+ }
110
355
 
111
- case 13:
112
- throw _context2.t0;
356
+ return translateExternalUrl;
357
+ }()
358
+ }, {
359
+ key: 'getFeedbackFormData',
360
+ value: function () {
361
+ var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
362
+ var _comoData3, locationId, token, env, api;
363
+
364
+ return _regenerator2.default.wrap(function _callee4$(_context4) {
365
+ while (1) {
366
+ switch (_context4.prev = _context4.next) {
367
+ case 0:
368
+ _comoData3 = this.comoData, locationId = _comoData3.locationId, token = _comoData3.token, env = _comoData3.env_params, api = _comoData3.api;
369
+ return _context4.abrupt('return', api.getFeedbackFormData(env.zapp_root, locationId, token));
370
+
371
+ case 2:
372
+ case 'end':
373
+ return _context4.stop();
374
+ }
375
+ }
376
+ }, _callee4, this);
377
+ }));
113
378
 
114
- case 14:
115
- case 'end':
116
- return _context2.stop();
379
+ function getFeedbackFormData() {
380
+ return _ref4.apply(this, arguments);
117
381
  }
118
- }
119
- }, _callee2, undefined, [[1, 8]]);
120
- }));
121
-
122
- /**
123
- *
124
- * @param {Object} environment Environemnt object
125
- * @param {string} environment.id Environment Id
126
- * @param {string} environment.locationId Location Id
127
- * @param {string} environment.installationId Unique installation id
128
- * @param {Object} credentials Member credentials (Optional)
129
- * @param {string} accessToken session id string (Optional)
130
- * @param {string} refreshToken refresh token string (Optional)
131
- * @param {string} expiresIn access token expiration date formatted (Optional)
132
- * @param {function} refreshCallback an event callback which fires each time user's tokens gets refreshed
133
- * @param {boolean} enableSignon if disabled signOn api call will not be fired. Enabled by default.
134
- */
135
- como.init = function () {
136
- var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(environment, credentials, refreshCallback) {
137
- var enableSignon = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
138
-
139
- var isExists, environmentId, locationId, installationId, updateCredentials, gateway, _APIService$getServic, service, refresher, accessToken, refreshToken, expiresIn, credsNotExist, isExpired;
140
-
141
- return _regenerator2.default.wrap(function _callee3$(_context3) {
142
- while (1) {
143
- switch (_context3.prev = _context3.next) {
144
- case 0:
145
- isExists = function isExists(x) {
146
- return !ramda.isNil(x) && !ramda.isEmpty(x);
147
- };
148
-
149
- environmentId = environment.id, locationId = environment.locationId, installationId = environment.installationId;
150
-
151
- if (!(!isExists(environmentId) || !isExists(locationId) || !isExists(installationId))) {
152
- _context3.next = 4;
153
- break;
382
+
383
+ return getFeedbackFormData;
384
+ }()
385
+
386
+ /**
387
+ *
388
+ * @param {Object} form registration form values
389
+ * @param {Object} verification flow
390
+ * @param {string} reCaptchaToken
391
+ * @param {Object} source(registration origin)
392
+ */
393
+
394
+ }, {
395
+ key: 'register',
396
+ value: function () {
397
+ var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(form, verification, reCaptchaToken, source) {
398
+ var api, data, _error$response$data, code, message;
399
+
400
+ return _regenerator2.default.wrap(function _callee5$(_context5) {
401
+ while (1) {
402
+ switch (_context5.prev = _context5.next) {
403
+ case 0:
404
+ api = this.comoData.api;
405
+ _context5.prev = 1;
406
+ _context5.next = 4;
407
+ return api.register(form, verification, reCaptchaToken, source);
408
+
409
+ case 4:
410
+ data = _context5.sent;
411
+ return _context5.abrupt('return', data);
412
+
413
+ case 8:
414
+ _context5.prev = 8;
415
+ _context5.t0 = _context5['catch'](1);
416
+
417
+ if (!(_context5.t0.response && _context5.t0.response.data)) {
418
+ _context5.next = 13;
419
+ break;
420
+ }
421
+
422
+ _error$response$data = _context5.t0.response.data, code = _error$response$data.code, message = _error$response$data.message;
423
+ throw new Error(code || message);
424
+
425
+ case 13:
426
+ throw _context5.t0;
427
+
428
+ case 14:
429
+ case 'end':
430
+ return _context5.stop();
154
431
  }
432
+ }
433
+ }, _callee5, this, [[1, 8]]);
434
+ }));
155
435
 
156
- throw new Error('missing parameters');
436
+ function register(_x11, _x12, _x13, _x14) {
437
+ return _ref5.apply(this, arguments);
438
+ }
157
439
 
158
- case 4:
440
+ return register;
441
+ }()
442
+
443
+ /**
444
+ *
445
+ * @param {string} verification flow (code & verification step)
446
+ * @param {string} type verification type
447
+ * @param {Object} form registration form values
448
+ * @param {string} reCaptchaToken
449
+ */
450
+
451
+ }, {
452
+ key: 'registerVerify',
453
+ value: function () {
454
+ var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(verification, type, form, reCaptchaToken) {
455
+ var api, data, _error$response$data2, code, message;
456
+
457
+ return _regenerator2.default.wrap(function _callee6$(_context6) {
458
+ while (1) {
459
+ switch (_context6.prev = _context6.next) {
460
+ case 0:
461
+ api = this.comoData.api;
462
+ _context6.prev = 1;
463
+ _context6.next = 4;
464
+ return api.registerVerify(verification, type, form, reCaptchaToken);
465
+
466
+ case 4:
467
+ data = _context6.sent;
468
+ return _context6.abrupt('return', data);
469
+
470
+ case 8:
471
+ _context6.prev = 8;
472
+ _context6.t0 = _context6['catch'](1);
473
+
474
+ if (!(_context6.t0.response && _context6.t0.response.data)) {
475
+ _context6.next = 13;
476
+ break;
477
+ }
478
+
479
+ _error$response$data2 = _context6.t0.response.data, code = _error$response$data2.code, message = _error$response$data2.message;
480
+ throw new Error(code || message);
481
+
482
+ case 13:
483
+ throw _context6.t0;
484
+
485
+ case 14:
486
+ case 'end':
487
+ return _context6.stop();
488
+ }
489
+ }
490
+ }, _callee6, this, [[1, 8]]);
491
+ }));
159
492
 
160
- comoData = (0, _extends3.default)({}, INITIAL_COMO_DATA, credentials, {
161
- installationId: installationId,
162
- locationId: locationId,
163
- env_params: (0, _extends3.default)({}, INITIAL_COMO_DATA.env[environmentId])
164
- });
493
+ function registerVerify(_x15, _x16, _x17, _x18) {
494
+ return _ref6.apply(this, arguments);
495
+ }
496
+
497
+ return registerVerify;
498
+ }()
499
+
500
+ /**
501
+ *
502
+ * @param {Object} form update form values
503
+ * @param {string} reCaptchaToken
504
+ * @param {string} source request source
505
+ */
506
+
507
+ }, {
508
+ key: 'updateProfile',
509
+ value: function () {
510
+ var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(form, reCaptchaToken, source) {
511
+ var api, data, _error$response$data3, code, message;
512
+
513
+ return _regenerator2.default.wrap(function _callee7$(_context7) {
514
+ while (1) {
515
+ switch (_context7.prev = _context7.next) {
516
+ case 0:
517
+ api = this.comoData.api;
518
+ _context7.prev = 1;
519
+ _context7.next = 4;
520
+ return api.updateProfile(form, reCaptchaToken, source);
521
+
522
+ case 4:
523
+ data = _context7.sent;
524
+ return _context7.abrupt('return', data);
525
+
526
+ case 8:
527
+ _context7.prev = 8;
528
+ _context7.t0 = _context7['catch'](1);
529
+
530
+ if (!(_context7.t0.response && _context7.t0.response.data)) {
531
+ _context7.next = 13;
532
+ break;
533
+ }
534
+
535
+ _error$response$data3 = _context7.t0.response.data, code = _error$response$data3.code, message = _error$response$data3.message;
536
+ throw new Error(code || message);
537
+
538
+ case 13:
539
+ throw _context7.t0;
540
+
541
+ case 14:
542
+ case 'end':
543
+ return _context7.stop();
544
+ }
545
+ }
546
+ }, _callee7, this, [[1, 8]]);
547
+ }));
165
548
 
166
- updateCredentials = function updateCredentials(creds) {
167
- var isNew = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
549
+ function updateProfile(_x19, _x20, _x21) {
550
+ return _ref7.apply(this, arguments);
551
+ }
168
552
 
169
- como.updateLocalCreds(creds);
170
- if (refreshCallback && isNew) {
171
- refreshCallback(creds);
172
- }
173
- };
553
+ return updateProfile;
554
+ }()
555
+
556
+ /**
557
+ *
558
+ * @param {string} verificationCode code verification sent by 3rd party
559
+ * @param {string} type verification type
560
+ * @param {Object} form update form values
561
+ * @param {string} reCaptchaToken
562
+ * @param {string} source request source
563
+ */
564
+
565
+ }, {
566
+ key: 'updateProfileVerify',
567
+ value: function () {
568
+ var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(verificationCode, type, form, reCaptchaToken, source) {
569
+ var api, data, _error$response$data4, code, message;
570
+
571
+ return _regenerator2.default.wrap(function _callee8$(_context8) {
572
+ while (1) {
573
+ switch (_context8.prev = _context8.next) {
574
+ case 0:
575
+ api = this.comoData.api;
576
+ _context8.prev = 1;
577
+ _context8.next = 4;
578
+ return api.updateProfileVerify(verificationCode, type, form, reCaptchaToken, source);
579
+
580
+ case 4:
581
+ data = _context8.sent;
582
+ return _context8.abrupt('return', data);
583
+
584
+ case 8:
585
+ _context8.prev = 8;
586
+ _context8.t0 = _context8['catch'](1);
587
+
588
+ if (!(_context8.t0.response && _context8.t0.response.data)) {
589
+ _context8.next = 13;
590
+ break;
591
+ }
592
+
593
+ _error$response$data4 = _context8.t0.response.data, code = _error$response$data4.code, message = _error$response$data4.message;
594
+ throw new Error(code || message);
595
+
596
+ case 13:
597
+ throw _context8.t0;
598
+
599
+ case 14:
600
+ case 'end':
601
+ return _context8.stop();
602
+ }
603
+ }
604
+ }, _callee8, this, [[1, 8]]);
605
+ }));
174
606
 
175
- gateway = comoData.env_params.gateway;
176
- _APIService$getServic = APIService.getService(gateway, installationId, como.getCredentials, updateCredentials), service = _APIService$getServic.service, refresher = _APIService$getServic.refresher;
607
+ function updateProfileVerify(_x22, _x23, _x24, _x25, _x26) {
608
+ return _ref8.apply(this, arguments);
609
+ }
177
610
 
178
- comoData.api = service;
179
- comoData.refresher = refresher;
611
+ return updateProfileVerify;
612
+ }()
613
+
614
+ /**
615
+ *
616
+ * @param {string} unsubscribeSms unsubscribe user at location
617
+ * @param {string} PhoneNumber phone number to identify user
618
+ */
619
+
620
+ }, {
621
+ key: 'unsubscribeSms',
622
+ value: function () {
623
+ var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(PhoneNumber) {
624
+ var _comoData4, api, locationId, identifier, data, _error$response$data5, code, message;
625
+
626
+ return _regenerator2.default.wrap(function _callee9$(_context9) {
627
+ while (1) {
628
+ switch (_context9.prev = _context9.next) {
629
+ case 0:
630
+ _comoData4 = this.comoData, api = _comoData4.api, locationId = _comoData4.locationId;
631
+ _context9.prev = 1;
632
+ identifier = { PhoneNumber: PhoneNumber };
633
+ _context9.next = 5;
634
+ return api.unsubscribeSms(locationId, identifier);
635
+
636
+ case 5:
637
+ data = _context9.sent;
638
+ return _context9.abrupt('return', data);
639
+
640
+ case 9:
641
+ _context9.prev = 9;
642
+ _context9.t0 = _context9['catch'](1);
643
+
644
+ if (!(_context9.t0.response && _context9.t0.response.data)) {
645
+ _context9.next = 14;
646
+ break;
647
+ }
648
+
649
+ _error$response$data5 = _context9.t0.response.data, code = _error$response$data5.code, message = _error$response$data5.message;
650
+ throw new Error(code || message);
651
+
652
+ case 14:
653
+ throw _context9.t0;
654
+
655
+ case 15:
656
+ case 'end':
657
+ return _context9.stop();
658
+ }
659
+ }
660
+ }, _callee9, this, [[1, 9]]);
661
+ }));
180
662
 
181
- accessToken = credentials.accessToken, refreshToken = credentials.refreshToken, expiresIn = credentials.expiresIn;
182
- credsNotExist = !isExists(accessToken) || !isExists(refreshToken);
183
- isExpired = expiresIn && moment(expiresIn).isBefore(moment());
663
+ function unsubscribeSms(_x27) {
664
+ return _ref9.apply(this, arguments);
665
+ }
184
666
 
185
- if (!(enableSignon && (credsNotExist || isExpired))) {
186
- _context3.next = 16;
187
- break;
667
+ return unsubscribeSms;
668
+ }()
669
+
670
+ /**
671
+ *
672
+ * @param {Object} identifier an object which identifies the user by its credentials
673
+ * @param {string} type login type i.e PhoneNumber/Email/etc
674
+ */
675
+
676
+ }, {
677
+ key: 'login',
678
+ value: function () {
679
+ var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(identifier, type) {
680
+ var api, data, _error$response$data6, code, message;
681
+
682
+ return _regenerator2.default.wrap(function _callee10$(_context10) {
683
+ while (1) {
684
+ switch (_context10.prev = _context10.next) {
685
+ case 0:
686
+ api = this.comoData.api;
687
+ _context10.prev = 1;
688
+ _context10.next = 4;
689
+ return api.logIn(type, identifier);
690
+
691
+ case 4:
692
+ data = _context10.sent;
693
+ return _context10.abrupt('return', data);
694
+
695
+ case 8:
696
+ _context10.prev = 8;
697
+ _context10.t0 = _context10['catch'](1);
698
+
699
+ if (!(_context10.t0.response && _context10.t0.response.data)) {
700
+ _context10.next = 13;
701
+ break;
702
+ }
703
+
704
+ _error$response$data6 = _context10.t0.response.data, code = _error$response$data6.code, message = _error$response$data6.message;
705
+ throw new Error(code || message);
706
+
707
+ case 13:
708
+ throw _context10.t0;
709
+
710
+ case 14:
711
+ case 'end':
712
+ return _context10.stop();
188
713
  }
714
+ }
715
+ }, _callee10, this, [[1, 8]]);
716
+ }));
189
717
 
190
- _context3.next = 16;
191
- return como.signon();
718
+ function login(_x28, _x29) {
719
+ return _ref10.apply(this, arguments);
720
+ }
192
721
 
193
- case 16:
194
- return _context3.abrupt('return', como.getCredentials());
722
+ return login;
723
+ }()
724
+
725
+ /**
726
+ *
727
+ * @param {Object} identifier key-value identifiers
728
+ * @param {*} type login type i.e PhoneNumber/Email/etc
729
+ * @param {*} code a 2-factor verification code sent to the client
730
+ */
731
+
732
+ }, {
733
+ key: 'loginVerify',
734
+ value: function () {
735
+ var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(identifier, type, code) {
736
+ var api, _ref12, consent, _error$response$data7, errCode, message;
737
+
738
+ return _regenerator2.default.wrap(function _callee11$(_context11) {
739
+ while (1) {
740
+ switch (_context11.prev = _context11.next) {
741
+ case 0:
742
+ api = this.comoData.api;
743
+ _context11.prev = 1;
744
+ _context11.next = 4;
745
+ return api.logInVerify(code, type, identifier);
746
+
747
+ case 4:
748
+ _ref12 = _context11.sent;
749
+ consent = _ref12.consent;
750
+
751
+ this.comoData.consent = consent;
752
+ _context11.next = 17;
753
+ break;
754
+
755
+ case 9:
756
+ _context11.prev = 9;
757
+ _context11.t0 = _context11['catch'](1);
758
+
759
+ if (!(_context11.t0.response && _context11.t0.response.data)) {
760
+ _context11.next = 16;
761
+ break;
762
+ }
763
+
764
+ _error$response$data7 = _context11.t0.response.data, errCode = _error$response$data7.code, message = _error$response$data7.message;
765
+
766
+ if (!(message && message === 'Invalid verification Code')) {
767
+ _context11.next = 15;
768
+ break;
769
+ }
770
+
771
+ throw new Error(message);
772
+
773
+ case 15:
774
+ throw new Error(errCode || message);
775
+
776
+ case 16:
777
+ throw _context11.t0;
778
+
779
+ case 17:
780
+ return _context11.abrupt('return', this.getCredentials());
781
+
782
+ case 18:
783
+ case 'end':
784
+ return _context11.stop();
785
+ }
786
+ }
787
+ }, _callee11, this, [[1, 9]]);
788
+ }));
195
789
 
196
- case 17:
197
- case 'end':
198
- return _context3.stop();
199
- }
790
+ function loginVerify(_x30, _x31, _x32) {
791
+ return _ref11.apply(this, arguments);
200
792
  }
201
- }, _callee3, undefined);
202
- }));
203
793
 
204
- return function (_x, _x2, _x3) {
205
- return _ref3.apply(this, arguments);
206
- };
207
- }();
794
+ return loginVerify;
795
+ }()
208
796
 
209
- /**
210
- * Updates the como.js local credentials settings.
211
- * Used when making api calls to janua.
212
- *
213
- * @param {Object} credentials credentials to update.
214
- * @param {Object} accessToken access token to update.
215
- * @param {Object} refreshToken refresh token to update.
216
- * @param {Object} expiresIn access token expiry date to update.
217
- */
218
- como.updateLocalCreds = function () {
219
- var credentials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
220
-
221
- comoData.accessToken = credentials.accessToken;
222
- comoData.token = credentials.accessToken;
223
- comoData.refreshToken = credentials.refreshToken;
224
- comoData.expiresIn = credentials.expiresIn;
225
- };
797
+ /**
798
+ * Reload and sets the internal membership state.
799
+ * To get the reloaded membership make sure to call getMembership();
800
+ * @param onlyAssetKeys - include assets list full data or only the asset keys
801
+ * @returns {Promise<void>}
802
+ */
226
803
 
227
- como.getExternalUrlByID = function (itemID, gpsData, assetID, accessibilityData) {
228
- var locationData = comoData.mainResources[resourceNames.LOCATION_DATA];
229
- if (locationData && locationData.WebViews && locationData.WebViews[0].item) {
230
- var possibleWebViews = locationData.WebViews[0].item.filter(function (u) {
231
- return u.id === itemID;
232
- });
233
- var url = possibleWebViews && possibleWebViews[0] && possibleWebViews[0].url;
234
- return como.translateExternalUrl(url, gpsData, assetID, accessibilityData);
235
- }
236
- return null;
237
- };
804
+ }, {
805
+ key: 'reloadMembership',
806
+ value: function () {
807
+ var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12() {
808
+ var onlyAssetKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
238
809
 
239
- como.translateExternalUrl = function () {
240
- var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(url, gpsData, assetID, accessibilityData) {
241
- var legacyUrl, externalUrl, _comoData3, api, locationId, token, env, membership, assets, locationData, apiObjects, dataToUse;
810
+ var _comoData5, env, locationId, api, membership;
242
811
 
243
- return _regenerator2.default.wrap(function _callee4$(_context4) {
244
- while (1) {
245
- switch (_context4.prev = _context4.next) {
246
- case 0:
247
- _context4.next = 2;
248
- return como.getAppModulesLegacyBaseUrl();
812
+ return _regenerator2.default.wrap(function _callee12$(_context12) {
813
+ while (1) {
814
+ switch (_context12.prev = _context12.next) {
815
+ case 0:
816
+ _comoData5 = this.comoData, env = _comoData5.env_params, locationId = _comoData5.locationId, api = _comoData5.api;
817
+ _context12.next = 3;
818
+ return api.getUserAtLocation(env.zapp_root, locationId, onlyAssetKeys);
249
819
 
250
- case 2:
251
- legacyUrl = _context4.sent;
252
- externalUrl = url;
820
+ case 3:
821
+ membership = _context12.sent;
253
822
 
254
- if (externalUrl && externalUrl.startsWith(legacyUrl)) {
255
- externalUrl = externalUrl.replace(legacyUrl, comoData.env_params.app_modules_root);
823
+ this.comoData.membership = membership;
824
+
825
+ case 5:
826
+ case 'end':
827
+ return _context12.stop();
256
828
  }
257
- _comoData3 = comoData, api = _comoData3.api, locationId = _comoData3.locationId, token = _comoData3.token, env = _comoData3.env_params, membership = _comoData3.membership, assets = _comoData3.assets;
258
- locationData = comoData.mainResources && comoData.mainResources[resourceNames.LOCATION_DATA];
259
- apiObjects = { api: api, servicesRoot: env.services_root };
260
- dataToUse = {
261
- locationId: locationId, token: token, membership: membership, locationData: locationData, assets: assets, gpsData: gpsData, assetID: assetID, accessibilityData: accessibilityData
262
- };
263
- return _context4.abrupt('return', comoExternalUrlTranslator.translateUrl(externalUrl, apiObjects, dataToUse));
264
-
265
- case 10:
266
- case 'end':
267
- return _context4.stop();
268
- }
829
+ }
830
+ }, _callee12, this);
831
+ }));
832
+
833
+ function reloadMembership() {
834
+ return _ref13.apply(this, arguments);
269
835
  }
270
- }, _callee4, undefined);
271
- }));
272
836
 
273
- return function (_x7, _x8, _x9, _x10) {
274
- return _ref4.apply(this, arguments);
275
- };
276
- }();
837
+ return reloadMembership;
838
+ }()
839
+
840
+ /**
841
+ * Send an Open app request to update server.
842
+ */
843
+
844
+ }, {
845
+ key: 'openApp',
846
+ value: function () {
847
+ var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(data) {
848
+ var _comoData6, api, locationId, token, env;
849
+
850
+ return _regenerator2.default.wrap(function _callee13$(_context13) {
851
+ while (1) {
852
+ switch (_context13.prev = _context13.next) {
853
+ case 0:
854
+ _comoData6 = this.comoData, api = _comoData6.api, locationId = _comoData6.locationId, token = _comoData6.token, env = _comoData6.env_params;
855
+ return _context13.abrupt('return', api.openApp(env.zapp_root, token, locationId, data));
856
+
857
+ case 2:
858
+ case 'end':
859
+ return _context13.stop();
860
+ }
861
+ }
862
+ }, _callee13, this);
863
+ }));
277
864
 
278
- como.getFeedbackFormData = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
279
- var _comoData4, locationId, token, env, api;
865
+ function openApp(_x34) {
866
+ return _ref14.apply(this, arguments);
867
+ }
280
868
 
281
- return _regenerator2.default.wrap(function _callee5$(_context5) {
282
- while (1) {
283
- switch (_context5.prev = _context5.next) {
284
- case 0:
285
- _comoData4 = comoData, locationId = _comoData4.locationId, token = _comoData4.token, env = _comoData4.env_params, api = _comoData4.api;
286
- return _context5.abrupt('return', api.getFeedbackFormData(env.zapp_root, locationId, token));
869
+ return openApp;
870
+ }()
871
+
872
+ /**
873
+ * Update membership status (permissions).
874
+ * @param {boolean} pushEnable
875
+ * @param {boolean} locationEnable
876
+ */
877
+
878
+ }, {
879
+ key: 'clientUpdateMembership',
880
+ value: function () {
881
+ var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14(pushEnable, locationEnable) {
882
+ var _comoData7, api, locationId, token, env;
883
+
884
+ return _regenerator2.default.wrap(function _callee14$(_context14) {
885
+ while (1) {
886
+ switch (_context14.prev = _context14.next) {
887
+ case 0:
888
+ _comoData7 = this.comoData, api = _comoData7.api, locationId = _comoData7.locationId, token = _comoData7.token, env = _comoData7.env_params;
889
+ return _context14.abrupt('return', api.clientUpdateMembership(env.services_root, token, locationId, pushEnable, locationEnable));
890
+
891
+ case 2:
892
+ case 'end':
893
+ return _context14.stop();
894
+ }
895
+ }
896
+ }, _callee14, this);
897
+ }));
287
898
 
288
- case 2:
289
- case 'end':
290
- return _context5.stop();
899
+ function clientUpdateMembership(_x35, _x36) {
900
+ return _ref15.apply(this, arguments);
291
901
  }
292
- }
293
- }, _callee5, undefined);
294
- }));
295
-
296
- /**
297
- *
298
- * @param {Object} form registration form values
299
- */
300
- como.register = function () {
301
- var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(form) {
302
- var _comoData5, api, data, _error$response$data2, code, message;
303
-
304
- return _regenerator2.default.wrap(function _callee6$(_context6) {
305
- while (1) {
306
- switch (_context6.prev = _context6.next) {
307
- case 0:
308
- _comoData5 = comoData, api = _comoData5.api;
309
- _context6.prev = 1;
310
- _context6.next = 4;
311
- return api.register(form);
312
-
313
- case 4:
314
- data = _context6.sent;
315
- return _context6.abrupt('return', data);
316
-
317
- case 8:
318
- _context6.prev = 8;
319
- _context6.t0 = _context6['catch'](1);
320
-
321
- if (!(_context6.t0.response && _context6.t0.response.data)) {
322
- _context6.next = 13;
323
- break;
324
- }
325
902
 
326
- _error$response$data2 = _context6.t0.response.data, code = _error$response$data2.code, message = _error$response$data2.message;
327
- throw new Error(code || message);
903
+ return clientUpdateMembership;
904
+ }()
328
905
 
329
- case 13:
330
- throw _context6.t0;
906
+ /**
907
+ * Downloads the main resource by its id and sets the resource in the main resource's map.
908
+ * @param {string} resourceId Main resource id
909
+ */
331
910
 
332
- case 14:
333
- case 'end':
334
- return _context6.stop();
335
- }
336
- }
337
- }, _callee6, undefined, [[1, 8]]);
338
- }));
911
+ }, {
912
+ key: 'downloadMainResource',
913
+ value: function () {
914
+ var _ref16 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15(resourceId) {
915
+ var resource, err, _comoData8, env, api, responseJson;
339
916
 
340
- return function (_x11) {
341
- return _ref6.apply(this, arguments);
342
- };
343
- }();
917
+ return _regenerator2.default.wrap(function _callee15$(_context15) {
918
+ while (1) {
919
+ switch (_context15.prev = _context15.next) {
920
+ case 0:
921
+ resource = this.comoData.mainResourcesMap[resourceId];
344
922
 
345
- /**
346
- *
347
- * @param {string} verificationCode code verification sent by 3rd party
348
- * @param {string} type verification type
349
- * @param {Object} form registration form values
350
- */
351
- como.registerVerify = function () {
352
- var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(verificationCode, type, form) {
353
- var _comoData6, api, data, _error$response$data3, code, message;
354
-
355
- return _regenerator2.default.wrap(function _callee7$(_context7) {
356
- while (1) {
357
- switch (_context7.prev = _context7.next) {
358
- case 0:
359
- _comoData6 = comoData, api = _comoData6.api;
360
- _context7.prev = 1;
361
- _context7.next = 4;
362
- return api.registerVerify(verificationCode, type, form);
363
-
364
- case 4:
365
- data = _context7.sent;
366
- return _context7.abrupt('return', data);
367
-
368
- case 8:
369
- _context7.prev = 8;
370
- _context7.t0 = _context7['catch'](1);
371
-
372
- if (!(_context7.t0.response && _context7.t0.response.data)) {
373
- _context7.next = 13;
374
- break;
375
- }
923
+ if (resource) {
924
+ _context15.next = 4;
925
+ break;
926
+ }
376
927
 
377
- _error$response$data3 = _context7.t0.response.data, code = _error$response$data3.code, message = _error$response$data3.message;
378
- throw new Error(code || message);
928
+ err = 'resource ' + resourceId + ' not found!';
929
+ throw new Error(err);
379
930
 
380
- case 13:
381
- throw _context7.t0;
931
+ case 4:
932
+ _comoData8 = this.comoData, env = _comoData8.env_params, api = _comoData8.api;
933
+ _context15.next = 7;
934
+ return api.getLoyaltyResource(env.services_root_cdn, resource.id, 'Namespace' in resource ? resource.Namespace : 'location_' + this.comoData.locationId, resource.Version);
382
935
 
383
- case 14:
384
- case 'end':
385
- return _context7.stop();
386
- }
387
- }
388
- }, _callee7, undefined, [[1, 8]]);
389
- }));
936
+ case 7:
937
+ responseJson = _context15.sent;
390
938
 
391
- return function (_x12, _x13, _x14) {
392
- return _ref7.apply(this, arguments);
393
- };
394
- }();
395
939
 
396
- /**
397
- *
398
- * @param {Object} form update form values
399
- */
400
- como.updateProfile = function () {
401
- var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(form) {
402
- var _comoData7, api, data, _error$response$data4, code, message;
403
-
404
- return _regenerator2.default.wrap(function _callee8$(_context8) {
405
- while (1) {
406
- switch (_context8.prev = _context8.next) {
407
- case 0:
408
- _comoData7 = comoData, api = _comoData7.api;
409
- _context8.prev = 1;
410
- _context8.next = 4;
411
- return api.updateProfile(form);
412
-
413
- case 4:
414
- data = _context8.sent;
415
- return _context8.abrupt('return', data);
416
-
417
- case 8:
418
- _context8.prev = 8;
419
- _context8.t0 = _context8['catch'](1);
420
-
421
- if (!(_context8.t0.response && _context8.t0.response.data)) {
422
- _context8.next = 13;
423
- break;
940
+ this.comoData.mainResources[resourceId] = responseJson;
941
+
942
+ case 9:
943
+ case 'end':
944
+ return _context15.stop();
424
945
  }
946
+ }
947
+ }, _callee15, this);
948
+ }));
425
949
 
426
- _error$response$data4 = _context8.t0.response.data, code = _error$response$data4.code, message = _error$response$data4.message;
427
- throw new Error(code || message);
950
+ function downloadMainResource(_x37) {
951
+ return _ref16.apply(this, arguments);
952
+ }
428
953
 
429
- case 13:
430
- throw _context8.t0;
954
+ return downloadMainResource;
955
+ }()
956
+
957
+ /**
958
+ * Reload and sets the internal location state.
959
+ * To get the reloaded location state make sure to call getLocationState();
960
+ */
961
+
962
+ }, {
963
+ key: 'reloadLocationState',
964
+ value: function () {
965
+ var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
966
+ var api, state, mainResources;
967
+ return _regenerator2.default.wrap(function _callee16$(_context16) {
968
+ while (1) {
969
+ switch (_context16.prev = _context16.next) {
970
+ case 0:
971
+ api = this.comoData.api;
972
+ _context16.next = 3;
973
+ return api.getLocationState(this.comoData.env_params.zapp_root, this.comoData.locationId);
974
+
975
+ case 3:
976
+ state = _context16.sent;
977
+
978
+ this.comoData.locationState = state;
979
+ mainResources = state.MainResources.Resource;
980
+
981
+
982
+ this.comoData.mainResourcesMap = mainResources.reduce(function (total, obj) {
983
+ total[obj.id] = obj; // eslint-disable-line no-param-reassign
984
+ return total;
985
+ }, {});
986
+
987
+ case 7:
988
+ case 'end':
989
+ return _context16.stop();
990
+ }
991
+ }
992
+ }, _callee16, this);
993
+ }));
431
994
 
432
- case 14:
433
- case 'end':
434
- return _context8.stop();
435
- }
995
+ function reloadLocationState() {
996
+ return _ref17.apply(this, arguments);
436
997
  }
437
- }, _callee8, undefined, [[1, 8]]);
438
- }));
439
-
440
- return function (_x15) {
441
- return _ref8.apply(this, arguments);
442
- };
443
- }();
444
998
 
445
- /**
446
- *
447
- * @param {string} verificationCode code verification sent by 3rd party
448
- * @param {string} type verification type
449
- * @param {Object} form update form values
450
- */
451
- como.updateProfileVerify = function () {
452
- var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(verificationCode, type, form) {
453
- var _comoData8, api, data, _error$response$data5, code, message;
454
-
455
- return _regenerator2.default.wrap(function _callee9$(_context9) {
456
- while (1) {
457
- switch (_context9.prev = _context9.next) {
458
- case 0:
459
- _comoData8 = comoData, api = _comoData8.api;
460
- _context9.prev = 1;
461
- _context9.next = 4;
462
- return api.updateProfileVerify(verificationCode, type, form);
463
-
464
- case 4:
465
- data = _context9.sent;
466
- return _context9.abrupt('return', data);
467
-
468
- case 8:
469
- _context9.prev = 8;
470
- _context9.t0 = _context9['catch'](1);
471
-
472
- if (!(_context9.t0.response && _context9.t0.response.data)) {
473
- _context9.next = 13;
474
- break;
999
+ return reloadLocationState;
1000
+ }()
1001
+
1002
+ /**
1003
+ * Requests an app client id by the user's location id.
1004
+ */
1005
+
1006
+ }, {
1007
+ key: 'getAppClientID',
1008
+ value: function () {
1009
+ var _ref18 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee17() {
1010
+ var _comoData9, env, locationId, api, responseJson;
1011
+
1012
+ return _regenerator2.default.wrap(function _callee17$(_context17) {
1013
+ while (1) {
1014
+ switch (_context17.prev = _context17.next) {
1015
+ case 0:
1016
+ _comoData9 = this.comoData, env = _comoData9.env_params, locationId = _comoData9.locationId, api = _comoData9.api;
1017
+ _context17.next = 3;
1018
+ return api.getShortUserId(env.zapp_root, locationId);
1019
+
1020
+ case 3:
1021
+ responseJson = _context17.sent;
1022
+ return _context17.abrupt('return', responseJson.ID);
1023
+
1024
+ case 5:
1025
+ case 'end':
1026
+ return _context17.stop();
475
1027
  }
1028
+ }
1029
+ }, _callee17, this);
1030
+ }));
476
1031
 
477
- _error$response$data5 = _context9.t0.response.data, code = _error$response$data5.code, message = _error$response$data5.message;
478
- throw new Error(code || message);
1032
+ function getAppClientID() {
1033
+ return _ref18.apply(this, arguments);
1034
+ }
479
1035
 
480
- case 13:
481
- throw _context9.t0;
1036
+ return getAppClientID;
1037
+ }()
1038
+
1039
+ /**
1040
+ * Requests a generated payment code from the loyalty server
1041
+ */
1042
+
1043
+ }, {
1044
+ key: 'getPaymentCode',
1045
+ value: function () {
1046
+ var _ref19 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee18() {
1047
+ var _comoData10, env, locationId, api, responseJson;
1048
+
1049
+ return _regenerator2.default.wrap(function _callee18$(_context18) {
1050
+ while (1) {
1051
+ switch (_context18.prev = _context18.next) {
1052
+ case 0:
1053
+ _comoData10 = this.comoData, env = _comoData10.env_params, locationId = _comoData10.locationId, api = _comoData10.api;
1054
+ _context18.next = 3;
1055
+ return api.getPaymentCode(env.zapp_root, locationId);
1056
+
1057
+ case 3:
1058
+ responseJson = _context18.sent;
1059
+ return _context18.abrupt('return', responseJson.VerificationCode);
1060
+
1061
+ case 5:
1062
+ case 'end':
1063
+ return _context18.stop();
1064
+ }
1065
+ }
1066
+ }, _callee18, this);
1067
+ }));
482
1068
 
483
- case 14:
484
- case 'end':
485
- return _context9.stop();
486
- }
1069
+ function getPaymentCode() {
1070
+ return _ref19.apply(this, arguments);
487
1071
  }
488
- }, _callee9, undefined, [[1, 8]]);
489
- }));
490
-
491
- return function (_x16, _x17, _x18) {
492
- return _ref9.apply(this, arguments);
493
- };
494
- }();
495
1072
 
496
- /**
497
- *
498
- * @param {Object} identifier an object which identifies the user by its credentials
499
- * @param {string} type login type i.e PhoneNumber/Email/etc
500
- */
501
- como.login = function () {
502
- var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(identifier, type) {
503
- var _comoData9, api, data, _error$response$data6, code, message;
504
-
505
- return _regenerator2.default.wrap(function _callee10$(_context10) {
506
- while (1) {
507
- switch (_context10.prev = _context10.next) {
508
- case 0:
509
- _comoData9 = comoData, api = _comoData9.api;
510
- _context10.prev = 1;
511
- _context10.next = 4;
512
- return api.logIn(type, identifier);
513
-
514
- case 4:
515
- data = _context10.sent;
516
- return _context10.abrupt('return', data);
517
-
518
- case 8:
519
- _context10.prev = 8;
520
- _context10.t0 = _context10['catch'](1);
521
-
522
- if (!(_context10.t0.response && _context10.t0.response.data)) {
523
- _context10.next = 13;
524
- break;
1073
+ return getPaymentCode;
1074
+ }()
1075
+
1076
+ /**
1077
+ * Logout the user identified by its accessToken
1078
+ */
1079
+
1080
+ }, {
1081
+ key: 'logout',
1082
+ value: function () {
1083
+ var _ref20 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee19() {
1084
+ var api, response, _error$response$data8, errCode, message;
1085
+
1086
+ return _regenerator2.default.wrap(function _callee19$(_context19) {
1087
+ while (1) {
1088
+ switch (_context19.prev = _context19.next) {
1089
+ case 0:
1090
+ api = this.comoData.api;
1091
+ _context19.prev = 1;
1092
+ _context19.next = 4;
1093
+ return api.logOut();
1094
+
1095
+ case 4:
1096
+ response = _context19.sent;
1097
+ return _context19.abrupt('return', response);
1098
+
1099
+ case 8:
1100
+ _context19.prev = 8;
1101
+ _context19.t0 = _context19['catch'](1);
1102
+
1103
+ if (!(_context19.t0.response && _context19.t0.response.data)) {
1104
+ _context19.next = 13;
1105
+ break;
1106
+ }
1107
+
1108
+ _error$response$data8 = _context19.t0.response.data, errCode = _error$response$data8.code, message = _error$response$data8.message;
1109
+ throw new Error(errCode || message);
1110
+
1111
+ case 13:
1112
+ throw _context19.t0;
1113
+
1114
+ case 14:
1115
+ case 'end':
1116
+ return _context19.stop();
525
1117
  }
1118
+ }
1119
+ }, _callee19, this, [[1, 8]]);
1120
+ }));
526
1121
 
527
- _error$response$data6 = _context10.t0.response.data, code = _error$response$data6.code, message = _error$response$data6.message;
528
- throw new Error(code || message);
1122
+ function logout() {
1123
+ return _ref20.apply(this, arguments);
1124
+ }
529
1125
 
530
- case 13:
531
- throw _context10.t0;
1126
+ return logout;
1127
+ }()
1128
+
1129
+ /**
1130
+ *
1131
+ * @param {string} assetKey asset's id
1132
+ */
1133
+
1134
+ }, {
1135
+ key: 'redeemAsset',
1136
+ value: function () {
1137
+ var _ref21 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee20(assetKey) {
1138
+ var _comoData11, env, locationId, api, responseJson;
1139
+
1140
+ return _regenerator2.default.wrap(function _callee20$(_context20) {
1141
+ while (1) {
1142
+ switch (_context20.prev = _context20.next) {
1143
+ case 0:
1144
+ _comoData11 = this.comoData, env = _comoData11.env_params, locationId = _comoData11.locationId, api = _comoData11.api;
1145
+ _context20.next = 3;
1146
+ return api.redeemAsset(env.zapp_root, locationId, assetKey);
1147
+
1148
+ case 3:
1149
+ responseJson = _context20.sent;
1150
+ return _context20.abrupt('return', responseJson);
1151
+
1152
+ case 5:
1153
+ case 'end':
1154
+ return _context20.stop();
1155
+ }
1156
+ }
1157
+ }, _callee20, this);
1158
+ }));
532
1159
 
533
- case 14:
534
- case 'end':
535
- return _context10.stop();
536
- }
1160
+ function redeemAsset(_x38) {
1161
+ return _ref21.apply(this, arguments);
537
1162
  }
538
- }, _callee10, undefined, [[1, 8]]);
539
- }));
540
1163
 
541
- return function (_x19, _x20) {
542
- return _ref10.apply(this, arguments);
543
- };
544
- }();
1164
+ return redeemAsset;
1165
+ }()
1166
+
1167
+ /**
1168
+ *
1169
+ * @param {string} itemId item's id
1170
+ */
1171
+
1172
+ }, {
1173
+ key: 'purchaseAsset',
1174
+ value: function () {
1175
+ var _ref22 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee21(itemId) {
1176
+ var _comoData12, env, token, locationId, api, responseJson;
1177
+
1178
+ return _regenerator2.default.wrap(function _callee21$(_context21) {
1179
+ while (1) {
1180
+ switch (_context21.prev = _context21.next) {
1181
+ case 0:
1182
+ _comoData12 = this.comoData, env = _comoData12.env_params, token = _comoData12.token, locationId = _comoData12.locationId, api = _comoData12.api;
1183
+ _context21.next = 3;
1184
+ return api.purchaseAsset(env.zapp_root, locationId, token, itemId);
1185
+
1186
+ case 3:
1187
+ responseJson = _context21.sent;
1188
+ return _context21.abrupt('return', responseJson);
1189
+
1190
+ case 5:
1191
+ case 'end':
1192
+ return _context21.stop();
1193
+ }
1194
+ }
1195
+ }, _callee21, this);
1196
+ }));
545
1197
 
546
- /**
547
- *
548
- * @param {Object} identifier key-value identifiers
549
- * @param {*} type login type i.e PhoneNumber/Email/etc
550
- * @param {*} code a 2-factor verification code sent to the client
551
- */
552
- como.loginVerify = function () {
553
- var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(identifier, type, code) {
554
- var _comoData10, api, _ref12, consent, _error$response$data7, errCode, message;
555
-
556
- return _regenerator2.default.wrap(function _callee11$(_context11) {
557
- while (1) {
558
- switch (_context11.prev = _context11.next) {
559
- case 0:
560
- _comoData10 = comoData, api = _comoData10.api;
561
- _context11.prev = 1;
562
- _context11.next = 4;
563
- return api.logInVerify(code, type, identifier);
564
-
565
- case 4:
566
- _ref12 = _context11.sent;
567
- consent = _ref12.consent;
568
-
569
- comoData.consent = consent;
570
- _context11.next = 17;
571
- break;
572
-
573
- case 9:
574
- _context11.prev = 9;
575
- _context11.t0 = _context11['catch'](1);
576
-
577
- if (!(_context11.t0.response && _context11.t0.response.data)) {
578
- _context11.next = 16;
579
- break;
1198
+ function purchaseAsset(_x39) {
1199
+ return _ref22.apply(this, arguments);
1200
+ }
1201
+
1202
+ return purchaseAsset;
1203
+ }()
1204
+ }, {
1205
+ key: 'getUserPointShopDataAPI2',
1206
+ value: function () {
1207
+ var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee22() {
1208
+ var _comoData13, env, locationId, api, responseJson;
1209
+
1210
+ return _regenerator2.default.wrap(function _callee22$(_context22) {
1211
+ while (1) {
1212
+ switch (_context22.prev = _context22.next) {
1213
+ case 0:
1214
+ _comoData13 = this.comoData, env = _comoData13.env_params, locationId = _comoData13.locationId, api = _comoData13.api;
1215
+ _context22.next = 3;
1216
+ return api.getUserPointShopDataAPI2(env.zapp_root, locationId);
1217
+
1218
+ case 3:
1219
+ responseJson = _context22.sent;
1220
+ return _context22.abrupt('return', responseJson);
1221
+
1222
+ case 5:
1223
+ case 'end':
1224
+ return _context22.stop();
580
1225
  }
1226
+ }
1227
+ }, _callee22, this);
1228
+ }));
581
1229
 
582
- _error$response$data7 = _context11.t0.response.data, errCode = _error$response$data7.code, message = _error$response$data7.message;
1230
+ function getUserPointShopDataAPI2() {
1231
+ return _ref23.apply(this, arguments);
1232
+ }
583
1233
 
584
- if (!(message && message === 'Invalid verification Code')) {
585
- _context11.next = 15;
586
- break;
1234
+ return getUserPointShopDataAPI2;
1235
+ }()
1236
+ }, {
1237
+ key: 'purchaseAssetAPI2',
1238
+ value: function () {
1239
+ var _ref24 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee23(assetID) {
1240
+ var _comoData14, env, locationId, api, responseJson;
1241
+
1242
+ return _regenerator2.default.wrap(function _callee23$(_context23) {
1243
+ while (1) {
1244
+ switch (_context23.prev = _context23.next) {
1245
+ case 0:
1246
+ _comoData14 = this.comoData, env = _comoData14.env_params, locationId = _comoData14.locationId, api = _comoData14.api;
1247
+ _context23.next = 3;
1248
+ return api.purchaseAssetAPI2(env.zapp_root, locationId, assetID);
1249
+
1250
+ case 3:
1251
+ responseJson = _context23.sent;
1252
+ return _context23.abrupt('return', responseJson);
1253
+
1254
+ case 5:
1255
+ case 'end':
1256
+ return _context23.stop();
587
1257
  }
1258
+ }
1259
+ }, _callee23, this);
1260
+ }));
588
1261
 
589
- throw new Error(message);
1262
+ function purchaseAssetAPI2(_x40) {
1263
+ return _ref24.apply(this, arguments);
1264
+ }
590
1265
 
591
- case 15:
592
- throw new Error(errCode || message);
1266
+ return purchaseAssetAPI2;
1267
+ }()
593
1268
 
594
- case 16:
595
- throw _context11.t0;
1269
+ /**
1270
+ * Reload and sets the internal assets (expired and valid) state.
1271
+ * To get the reloaded assets make sure to call como.getAssets();
1272
+ */
596
1273
 
597
- case 17:
598
- return _context11.abrupt('return', como.getCredentials());
1274
+ }, {
1275
+ key: 'reloadAssets',
1276
+ value: function () {
1277
+ var _ref25 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee24() {
1278
+ var _comoData15, env, locationId, api, responseJson;
599
1279
 
600
- case 18:
601
- case 'end':
602
- return _context11.stop();
603
- }
604
- }
605
- }, _callee11, undefined, [[1, 9]]);
606
- }));
1280
+ return _regenerator2.default.wrap(function _callee24$(_context24) {
1281
+ while (1) {
1282
+ switch (_context24.prev = _context24.next) {
1283
+ case 0:
1284
+ _comoData15 = this.comoData, env = _comoData15.env_params, locationId = _comoData15.locationId, api = _comoData15.api;
1285
+ _context24.next = 3;
1286
+ return api.memberAssets(env.services_root, locationId);
607
1287
 
608
- return function (_x21, _x22, _x23) {
609
- return _ref11.apply(this, arguments);
610
- };
611
- }();
1288
+ case 3:
1289
+ responseJson = _context24.sent;
612
1290
 
613
- /**
614
- * Reload and sets the internal membership state.
615
- * To get the reloaded membership make sure to call como.getMembership();
616
- * @param onlyAssetKeys - include assets list full data or only the asset keys
617
- * @returns {Promise<void>}
618
- */
619
- como.reloadMembership = function () {
620
- var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12() {
621
- var onlyAssetKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
622
-
623
- var _comoData11, env, locationId, api, membership;
624
-
625
- return _regenerator2.default.wrap(function _callee12$(_context12) {
626
- while (1) {
627
- switch (_context12.prev = _context12.next) {
628
- case 0:
629
- _comoData11 = comoData, env = _comoData11.env_params, locationId = _comoData11.locationId, api = _comoData11.api;
630
- _context12.next = 3;
631
- return api.getUserAtLocation(env.zapp_root, locationId, onlyAssetKeys);
632
-
633
- case 3:
634
- membership = _context12.sent;
635
-
636
- comoData.membership = membership;
637
-
638
- case 5:
639
- case 'end':
640
- return _context12.stop();
641
- }
642
- }
643
- }, _callee12, undefined);
644
- }));
1291
+ this.comoData.assets = responseJson;
645
1292
 
646
- return function () {
647
- return _ref13.apply(this, arguments);
648
- };
649
- }();
1293
+ case 5:
1294
+ case 'end':
1295
+ return _context24.stop();
1296
+ }
1297
+ }
1298
+ }, _callee24, this);
1299
+ }));
650
1300
 
651
- /**
652
- * Send an Open app request to update server.
653
- */
654
- como.openApp = function () {
655
- var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(data) {
656
- var _comoData12, api, locationId, token, env;
657
-
658
- return _regenerator2.default.wrap(function _callee13$(_context13) {
659
- while (1) {
660
- switch (_context13.prev = _context13.next) {
661
- case 0:
662
- _comoData12 = comoData, api = _comoData12.api, locationId = _comoData12.locationId, token = _comoData12.token, env = _comoData12.env_params;
663
- return _context13.abrupt('return', api.openApp(env.zapp_root, token, locationId, data));
664
-
665
- case 2:
666
- case 'end':
667
- return _context13.stop();
668
- }
1301
+ function reloadAssets() {
1302
+ return _ref25.apply(this, arguments);
669
1303
  }
670
- }, _callee13, undefined);
671
- }));
672
1304
 
673
- return function (_x25) {
674
- return _ref14.apply(this, arguments);
675
- };
676
- }();
1305
+ return reloadAssets;
1306
+ }()
677
1307
 
678
- /**
679
- * Update membership status (permissions).
680
- * @param {boolean} pushEnable
681
- * @param {boolean} locationEnable
682
- */
683
- como.clientUpdateMembership = function () {
684
- var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14(pushEnable, locationEnable) {
685
- var _comoData13, api, locationId, token, env;
686
-
687
- return _regenerator2.default.wrap(function _callee14$(_context14) {
688
- while (1) {
689
- switch (_context14.prev = _context14.next) {
690
- case 0:
691
- _comoData13 = comoData, api = _comoData13.api, locationId = _comoData13.locationId, token = _comoData13.token, env = _comoData13.env_params;
692
- return _context14.abrupt('return', api.clientUpdateMembership(env.services_root, token, locationId, pushEnable, locationEnable));
693
-
694
- case 2:
695
- case 'end':
696
- return _context14.stop();
697
- }
698
- }
699
- }, _callee14, undefined);
700
- }));
1308
+ /**
1309
+ * Merge the default app text with the location specific app texts
1310
+ * Both DefaultAppTexts and AppTexts are a MainResource that needs to be downloaded before merge
1311
+ */
701
1312
 
702
- return function (_x26, _x27) {
703
- return _ref15.apply(this, arguments);
704
- };
705
- }();
1313
+ }, {
1314
+ key: 'mergeTexts',
1315
+ value: function mergeTexts() {
1316
+ var _this2 = this;
706
1317
 
707
- /**
708
- * Downloads the main resource by its id and sets the resource in the main resource's map.
709
- * @param {string} resourceId Main resource id
710
- */
1318
+ if (this.comoData.mainResources.AppTexts && this.comoData.mainResources.DefaultAppTexts) {
1319
+ this.comoData.app_texts = this.comoData.mainResources.DefaultAppTexts;
1320
+ (0, _keys2.default)(this.comoData.mainResources.AppTexts).forEach(function (key) {
1321
+ _this2.comoData.app_texts[key] = _this2.comoData.mainResources.AppTexts[key];
1322
+ });
1323
+ }
1324
+ }
711
1325
 
712
- como.downloadMainResource = function () {
713
- var _ref16 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15(resourceId) {
714
- var resource, err, _comoData14, env, api, responseJson;
1326
+ /**
1327
+ *
1328
+ * @param {string} key app text key
1329
+ */
715
1330
 
716
- return _regenerator2.default.wrap(function _callee15$(_context15) {
717
- while (1) {
718
- switch (_context15.prev = _context15.next) {
719
- case 0:
720
- resource = comoData.mainResourcesMap[resourceId];
1331
+ }, {
1332
+ key: 'getTextForKey',
1333
+ value: function getTextForKey(key) {
1334
+ return this.comoData.app_texts[key];
1335
+ }
721
1336
 
722
- if (resource) {
723
- _context15.next = 4;
724
- break;
1337
+ /**
1338
+ * Downloads the main resources:
1339
+ * - LocationData
1340
+ * - Menu
1341
+ * - Updates
1342
+ * - TCAlts
1343
+ * - AppTexts
1344
+ * - DefaultAppTexts
1345
+ */
1346
+
1347
+ }, {
1348
+ key: 'downloadMainResources',
1349
+ value: function () {
1350
+ var _ref26 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee25() {
1351
+ var resources, downloadMainResource, downloads;
1352
+ return _regenerator2.default.wrap(function _callee25$(_context25) {
1353
+ while (1) {
1354
+ switch (_context25.prev = _context25.next) {
1355
+ case 0:
1356
+ resources = ['LocationData', 'Menu', 'Updates', 'TCAlts', 'AppTexts', 'DefaultAppTexts'];
1357
+ downloadMainResource = this.downloadMainResource.bind(this);
1358
+ downloads = resources.map(downloadMainResource);
1359
+ _context25.next = 5;
1360
+ return _promise2.default.all(downloads);
1361
+
1362
+ case 5:
1363
+ this.mergeTexts();
1364
+
1365
+ case 6:
1366
+ case 'end':
1367
+ return _context25.stop();
725
1368
  }
1369
+ }
1370
+ }, _callee25, this);
1371
+ }));
726
1372
 
727
- err = 'resource ' + resourceId + ' not found!';
728
- throw new Error(err);
1373
+ function downloadMainResources() {
1374
+ return _ref26.apply(this, arguments);
1375
+ }
729
1376
 
730
- case 4:
731
- _comoData14 = comoData, env = _comoData14.env_params, api = _comoData14.api;
732
- _context15.next = 7;
733
- return api.getLoyaltyResource(env.services_root_temp, resource.id, 'Namespace' in resource ? resource.Namespace : 'location_' + comoData.locationId, resource.Version);
1377
+ return downloadMainResources;
1378
+ }()
734
1379
 
735
- case 7:
736
- responseJson = _context15.sent;
1380
+ /**
1381
+ *
1382
+ * @param {string} type form type
1383
+ */
737
1384
 
1385
+ }, {
1386
+ key: 'loadForm',
1387
+ value: function loadForm(type) {
1388
+ var _comoData16 = this.comoData,
1389
+ api = _comoData16.api,
1390
+ locationId = _comoData16.locationId;
738
1391
 
739
- comoData.mainResources[resourceId] = responseJson;
740
1392
 
741
- case 9:
742
- case 'end':
743
- return _context15.stop();
744
- }
745
- }
746
- }, _callee15, undefined);
747
- }));
1393
+ return api.getForm(type, locationId);
1394
+ }
748
1395
 
749
- return function (_x28) {
750
- return _ref16.apply(this, arguments);
751
- };
752
- }();
1396
+ /**
1397
+ *
1398
+ * @param {string} type configuration type
1399
+ */
1400
+
1401
+ }, {
1402
+ key: 'getConfigration',
1403
+ value: function getConfigration(type) {
1404
+ var _comoData17 = this.comoData,
1405
+ api = _comoData17.api,
1406
+ locationId = _comoData17.locationId;
1407
+
1408
+ var locationState = this.getLocationState();
1409
+ var version = null;
1410
+ if (locationState) {
1411
+ version = locationState.PublishVersion;
1412
+ }
753
1413
 
754
- /**
755
- * Reload and sets the internal location state.
756
- * To get the reloaded location state make sure to call como.getLocationState();
757
- */
758
- como.reloadLocationState = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
759
- var _comoData15, api, state, mainResources;
1414
+ return api.getConfiguration(type, locationId, version);
1415
+ }
760
1416
 
761
- return _regenerator2.default.wrap(function _callee16$(_context16) {
762
- while (1) {
763
- switch (_context16.prev = _context16.next) {
764
- case 0:
765
- _comoData15 = comoData, api = _comoData15.api;
766
- _context16.next = 3;
767
- return api.getLocationState(comoData.env_params.zapp_root, comoData.locationId);
1417
+ /**
1418
+ *
1419
+ * @param {string} type resource type
1420
+ */
768
1421
 
769
- case 3:
770
- state = _context16.sent;
1422
+ }, {
1423
+ key: 'getResource',
1424
+ value: function getResource(type) {
1425
+ var _comoData18 = this.comoData,
1426
+ api = _comoData18.api,
1427
+ locationId = _comoData18.locationId;
771
1428
 
772
- comoData.locationState = state;
773
- mainResources = state.MainResources.Resource;
1429
+ return api.getResource(type, locationId);
1430
+ }
774
1431
 
1432
+ /**
1433
+ *
1434
+ * Get all legacy resources (Zapp)
1435
+ */
775
1436
 
776
- comoData.mainResourcesMap = mainResources.reduce(function (total, obj) {
777
- total[obj.id] = obj; // eslint-disable-line no-param-reassign
778
- return total;
779
- }, {});
1437
+ }, {
1438
+ key: 'getLegacyResources',
1439
+ value: function getLegacyResources() {
1440
+ var _comoData19 = this.comoData,
1441
+ api = _comoData19.api,
1442
+ locationId = _comoData19.locationId;
780
1443
 
781
- case 7:
782
- case 'end':
783
- return _context16.stop();
784
- }
1444
+ return api.getZappResource(locationId);
785
1445
  }
786
- }, _callee16, undefined);
787
- }));
788
-
789
- /**
790
- * Requests an app client id by the user's location id.
791
- */
792
- como.getAppClientID = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee17() {
793
- var _comoData16, env, locationId, api, responseJson;
794
-
795
- return _regenerator2.default.wrap(function _callee17$(_context17) {
796
- while (1) {
797
- switch (_context17.prev = _context17.next) {
798
- case 0:
799
- _comoData16 = comoData, env = _comoData16.env_params, locationId = _comoData16.locationId, api = _comoData16.api;
800
- _context17.next = 3;
801
- return api.getShortUserId(env.zapp_root, locationId);
802
-
803
- case 3:
804
- responseJson = _context17.sent;
805
- return _context17.abrupt('return', responseJson.ID);
806
-
807
- case 5:
808
- case 'end':
809
- return _context17.stop();
810
- }
1446
+
1447
+ /**
1448
+ * Generates a new referral code for friend-referral
1449
+ */
1450
+
1451
+ }, {
1452
+ key: 'generateReferralCode',
1453
+ value: function generateReferralCode() {
1454
+ var _comoData20 = this.comoData,
1455
+ api = _comoData20.api,
1456
+ locationId = _comoData20.locationId,
1457
+ token = _comoData20.token,
1458
+ env = _comoData20.env_params;
1459
+
1460
+
1461
+ return api.generateReferralCode(env.services_root, token, locationId);
811
1462
  }
812
- }, _callee17, undefined);
813
- }));
814
-
815
- /**
816
- * Requests a generated payment code from the loyalty server
817
- */
818
- como.getPaymentCode = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee18() {
819
- var _comoData17, env, locationId, api, responseJson;
820
-
821
- return _regenerator2.default.wrap(function _callee18$(_context18) {
822
- while (1) {
823
- switch (_context18.prev = _context18.next) {
824
- case 0:
825
- _comoData17 = comoData, env = _comoData17.env_params, locationId = _comoData17.locationId, api = _comoData17.api;
826
- _context18.next = 3;
827
- return api.getPaymentCode(env.zapp_root, locationId);
828
-
829
- case 3:
830
- responseJson = _context18.sent;
831
- return _context18.abrupt('return', responseJson.VerificationCode);
832
-
833
- case 5:
834
- case 'end':
835
- return _context18.stop();
836
- }
1463
+
1464
+ /**
1465
+ * Check that referral code is valid
1466
+ */
1467
+
1468
+ }, {
1469
+ key: 'verifyReferralCode',
1470
+ value: function verifyReferralCode(code) {
1471
+ var _comoData21 = this.comoData,
1472
+ api = _comoData21.api,
1473
+ locationId = _comoData21.locationId,
1474
+ token = _comoData21.token,
1475
+ env = _comoData21.env_params;
1476
+
1477
+
1478
+ return api.verifyReferralCode(env.services_root, token, locationId, code);
837
1479
  }
838
- }, _callee18, undefined);
839
- }));
840
-
841
- /**
842
- * Logout the user identified by its accessToken
843
- */
844
- como.logout = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee19() {
845
- var _comoData18, api, response, _error$response$data8, errCode, message;
846
-
847
- return _regenerator2.default.wrap(function _callee19$(_context19) {
848
- while (1) {
849
- switch (_context19.prev = _context19.next) {
850
- case 0:
851
- _comoData18 = comoData, api = _comoData18.api;
852
- _context19.prev = 1;
853
- _context19.next = 4;
854
- return api.logOut();
855
-
856
- case 4:
857
- response = _context19.sent;
858
- return _context19.abrupt('return', response);
859
-
860
- case 8:
861
- _context19.prev = 8;
862
- _context19.t0 = _context19['catch'](1);
863
-
864
- if (!(_context19.t0.response && _context19.t0.response.data)) {
865
- _context19.next = 13;
866
- break;
867
- }
868
1480
 
869
- _error$response$data8 = _context19.t0.response.data, errCode = _error$response$data8.code, message = _error$response$data8.message;
870
- throw new Error(errCode || message);
1481
+ /**
1482
+ * Returns current accessToken and refreshToken
1483
+ * Caution: make sure to pass refresh callback to init to get the latest credentials
1484
+ */
1485
+
1486
+ }, {
1487
+ key: 'getCredentials',
1488
+ value: function getCredentials() {
1489
+ var _comoData22 = this.comoData,
1490
+ accessToken = _comoData22.accessToken,
1491
+ refreshToken = _comoData22.refreshToken,
1492
+ expiresIn = _comoData22.expiresIn,
1493
+ consent = _comoData22.consent,
1494
+ locationId = _comoData22.locationId;
1495
+
1496
+ return {
1497
+ accessToken: accessToken, refreshToken: refreshToken, expiresIn: expiresIn, consent: consent, locationId: locationId
1498
+ };
1499
+ }
871
1500
 
872
- case 13:
873
- throw _context19.t0;
1501
+ /**
1502
+ * Returns the current accessToken
1503
+ * Caution: make sure to pass refresh callback to como.init to get the latest credentials
1504
+ */
874
1505
 
875
- case 14:
876
- case 'end':
877
- return _context19.stop();
878
- }
1506
+ }, {
1507
+ key: 'getToken',
1508
+ value: function getToken() {
1509
+ return this.comoData.token;
879
1510
  }
880
- }, _callee19, undefined, [[1, 8]]);
881
- }));
882
-
883
- /**
884
- *
885
- * @param {string} assetKey asset's id
886
- */
887
- como.redeemAsset = function () {
888
- var _ref21 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee20(assetKey) {
889
- var _comoData19, env, locationId, api, responseJson;
890
-
891
- return _regenerator2.default.wrap(function _callee20$(_context20) {
892
- while (1) {
893
- switch (_context20.prev = _context20.next) {
894
- case 0:
895
- _comoData19 = comoData, env = _comoData19.env_params, locationId = _comoData19.locationId, api = _comoData19.api;
896
- _context20.next = 3;
897
- return api.redeemAsset(env.zapp_root, locationId, assetKey);
898
-
899
- case 3:
900
- responseJson = _context20.sent;
901
- return _context20.abrupt('return', responseJson);
902
-
903
- case 5:
904
- case 'end':
905
- return _context20.stop();
906
- }
907
- }
908
- }, _callee20, undefined);
909
- }));
910
1511
 
911
- return function (_x29) {
912
- return _ref21.apply(this, arguments);
913
- };
914
- }();
1512
+ /**
1513
+ * Returns the como.js initialized installation id
1514
+ */
915
1515
 
916
- /**
917
- *
918
- * @param {string} itemId item's id
919
- */
920
- como.purchaseAsset = function () {
921
- var _ref22 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee21(itemId) {
922
- var _comoData20, env, token, locationId, api, responseJson;
923
-
924
- return _regenerator2.default.wrap(function _callee21$(_context21) {
925
- while (1) {
926
- switch (_context21.prev = _context21.next) {
927
- case 0:
928
- _comoData20 = comoData, env = _comoData20.env_params, token = _comoData20.token, locationId = _comoData20.locationId, api = _comoData20.api;
929
- _context21.next = 3;
930
- return api.purchaseAsset(env.zapp_root, locationId, token, itemId);
931
-
932
- case 3:
933
- responseJson = _context21.sent;
934
- return _context21.abrupt('return', responseJson);
935
-
936
- case 5:
937
- case 'end':
938
- return _context21.stop();
939
- }
940
- }
941
- }, _callee21, undefined);
942
- }));
1516
+ }, {
1517
+ key: 'getInstallationId',
1518
+ value: function getInstallationId() {
1519
+ return this.comoData.installationId;
1520
+ }
943
1521
 
944
- return function (_x30) {
945
- return _ref22.apply(this, arguments);
946
- };
947
- }();
1522
+ /**
1523
+ * Return the user membership object
1524
+ * Make sure to call reloadMembership() to reload the membership object.
1525
+ */
948
1526
 
949
- /**
950
- * Reload and sets the internal assets (expired and valid) state.
951
- * To get the reloaded assets make sure to call como.getAssets(); and como.getArchivedAssets();
952
- */
953
- como.reloadAssets = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee22() {
954
- var _comoData21, env, locationId, api, responseJson, assets, archivedAssets, dateNow;
955
-
956
- return _regenerator2.default.wrap(function _callee22$(_context22) {
957
- while (1) {
958
- switch (_context22.prev = _context22.next) {
959
- case 0:
960
- _comoData21 = comoData, env = _comoData21.env_params, locationId = _comoData21.locationId, api = _comoData21.api;
961
- _context22.next = 3;
962
- return api.memberAssets(env.services_root, locationId);
963
-
964
- case 3:
965
- responseJson = _context22.sent;
966
- assets = [];
967
- archivedAssets = [];
968
- dateNow = moment().utc();
969
-
970
-
971
- responseJson.forEach(function (asset) {
972
- var archived = ramda.pathOr(false, ['Archived'], asset);
973
- var active = ramda.pathOr(true, ['Active'], asset);
974
- var validUntil = ramda.pathOr(null, ['Data', 'ValidUntil'], asset);
975
- var lastAssign = ramda.pathOr(null, ['LastAssignDate'], asset);
976
- var secondsValid = ramda.pathOr(null, ['Data', 'SecondsValid'], asset);
977
- var lastAssignDate = moment.utc(lastAssign, 'DD.MM.YYYY HH:mm:ss');
978
- var validUntilDate = moment.utc(validUntil, 'DD/MM/YYYY HH:mm:ss');
979
-
980
- if (!archived && active) {
981
- if (secondsValid !== null) {
982
- validUntilDate = lastAssignDate.clone().add(secondsValid, 'seconds');
983
- }
984
-
985
- if (validUntilDate.isBefore(dateNow)) {
986
- archivedAssets.push(asset);
987
- } else {
988
- assets.push(asset);
989
- }
990
- } else {
991
- archivedAssets.push(asset);
992
- }
993
- });
1527
+ }, {
1528
+ key: 'getMembership',
1529
+ value: function getMembership() {
1530
+ return this.comoData.membership;
1531
+ }
994
1532
 
995
- comoData.archivedAssets = archivedAssets;
996
- comoData.assets = assets; // saperate assest from archivedAssets
1533
+ /**
1534
+ * Return the user assets object
1535
+ * Make sure to call reloadAssets() to reload the assets object.
1536
+ */
997
1537
 
998
- case 10:
999
- case 'end':
1000
- return _context22.stop();
1001
- }
1538
+ }, {
1539
+ key: 'getAssets',
1540
+ value: function getAssets() {
1541
+ return this.comoData.assets;
1002
1542
  }
1003
- }, _callee22, undefined);
1004
- }));
1005
-
1006
- /**
1007
- * Reload and sets the internal archived assets state
1008
- * To get the reloaded assets make sure to call como.getArchivedAssets();
1009
- */
1010
- como.reloadArchivedAssets = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee23() {
1011
- var _comoData22, env, locationId, api, responseJson;
1012
-
1013
- return _regenerator2.default.wrap(function _callee23$(_context23) {
1014
- while (1) {
1015
- switch (_context23.prev = _context23.next) {
1016
- case 0:
1017
- _comoData22 = comoData, env = _comoData22.env_params, locationId = _comoData22.locationId, api = _comoData22.api;
1018
- _context23.next = 3;
1019
- return api.memberAssets(env.services_root, locationId, true);
1020
-
1021
- case 3:
1022
- responseJson = _context23.sent;
1023
-
1024
- comoData.redeemedAssets = responseJson;
1025
-
1026
- case 5:
1027
- case 'end':
1028
- return _context23.stop();
1543
+
1544
+ /**
1545
+ * Returns the location specific registration web url
1546
+ */
1547
+
1548
+ }, {
1549
+ key: 'getRegistrationUrl',
1550
+ value: function () {
1551
+ var _ref27 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee26(overrides) {
1552
+ var _comoData23, token, installationId, locationId, env;
1553
+
1554
+ return _regenerator2.default.wrap(function _callee26$(_context26) {
1555
+ while (1) {
1556
+ switch (_context26.prev = _context26.next) {
1557
+ case 0:
1558
+ _context26.next = 2;
1559
+ return this.refreshTokenIfNeeded();
1560
+
1561
+ case 2:
1562
+ _comoData23 = this.comoData, token = _comoData23.token, installationId = _comoData23.installationId, locationId = _comoData23.locationId, env = _comoData23.env_params;
1563
+ return _context26.abrupt('return', urlsUtils.appendQuery(env.app_modules_root + '/register?token=' + token + '&locationid=' + locationId, (0, _extends3.default)({}, this.getCredentials(), {
1564
+ installationId: installationId,
1565
+ disableSuccessScreen: 'true'
1566
+ }, overrides)));
1567
+
1568
+ case 4:
1569
+ case 'end':
1570
+ return _context26.stop();
1571
+ }
1572
+ }
1573
+ }, _callee26, this);
1574
+ }));
1575
+
1576
+ function getRegistrationUrl(_x41) {
1577
+ return _ref27.apply(this, arguments);
1029
1578
  }
1030
- }
1031
- }, _callee23, undefined);
1032
- }));
1033
-
1034
- /**
1035
- * Merge the default app text with the location specific app texts
1036
- * Both DefaultAppTexts and AppTexts are a MainResource that needs to be downloaded before merge
1037
- */
1038
- como.mergeTexts = function () {
1039
- if (comoData.mainResources.AppTexts && comoData.mainResources.DefaultAppTexts) {
1040
- comoData.app_texts = comoData.mainResources.DefaultAppTexts;
1041
- (0, _keys2.default)(comoData.mainResources.AppTexts).forEach(function (key) {
1042
- comoData.app_texts[key] = comoData.mainResources.AppTexts[key];
1043
- });
1044
- }
1045
- };
1046
1579
 
1047
- /**
1048
- *
1049
- * @param {string} key app text key
1050
- */
1051
- como.getTextForKey = function (key) {
1052
- return comoData.app_texts[key];
1053
- };
1580
+ return getRegistrationUrl;
1581
+ }()
1582
+
1583
+ /**
1584
+ * Returns the location specific profile web url
1585
+ */
1586
+
1587
+ }, {
1588
+ key: 'getProfileUrl',
1589
+ value: function () {
1590
+ var _ref28 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee27(overrides) {
1591
+ var _comoData24, token, installationId, locationId, env;
1592
+
1593
+ return _regenerator2.default.wrap(function _callee27$(_context27) {
1594
+ while (1) {
1595
+ switch (_context27.prev = _context27.next) {
1596
+ case 0:
1597
+ _context27.next = 2;
1598
+ return this.refreshTokenIfNeeded();
1599
+
1600
+ case 2:
1601
+ _comoData24 = this.comoData, token = _comoData24.token, installationId = _comoData24.installationId, locationId = _comoData24.locationId, env = _comoData24.env_params;
1602
+ return _context27.abrupt('return', urlsUtils.appendQuery(env.app_modules_root + '/profile?token=' + token + '&locationid=' + locationId, (0, _extends3.default)({}, this.getCredentials(), {
1603
+ installationId: installationId,
1604
+ disableSuccessScreen: 'true'
1605
+ }, overrides)));
1606
+
1607
+ case 4:
1608
+ case 'end':
1609
+ return _context27.stop();
1610
+ }
1611
+ }
1612
+ }, _callee27, this);
1613
+ }));
1054
1614
 
1055
- /**
1056
- * Downloads the main resources:
1057
- * - LocationData
1058
- * - Menu
1059
- * - Updates
1060
- * - TCAlts
1061
- * - AppTexts
1062
- * - DefaultAppTexts
1063
- */
1064
- como.downloadMainResources = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee24() {
1065
- var resources, downloads;
1066
- return _regenerator2.default.wrap(function _callee24$(_context24) {
1067
- while (1) {
1068
- switch (_context24.prev = _context24.next) {
1069
- case 0:
1070
- resources = ['LocationData', 'Menu', 'Updates', 'TCAlts', 'AppTexts', 'DefaultAppTexts'];
1071
- downloads = resources.map(como.downloadMainResource);
1072
- _context24.next = 4;
1073
- return _promise2.default.all(downloads);
1074
-
1075
- case 4:
1076
- como.mergeTexts();
1077
-
1078
- case 5:
1079
- case 'end':
1080
- return _context24.stop();
1615
+ function getProfileUrl(_x42) {
1616
+ return _ref28.apply(this, arguments);
1081
1617
  }
1082
- }
1083
- }, _callee24, undefined);
1084
- }));
1085
1618
 
1086
- /**
1087
- *
1088
- * @param {string} type form type
1089
- */
1090
- como.loadForm = function (type) {
1091
- var _comoData23 = comoData,
1092
- api = _comoData23.api,
1093
- locationId = _comoData23.locationId;
1619
+ return getProfileUrl;
1620
+ }()
1621
+
1622
+ /**
1623
+ * Returns the location specific login web url
1624
+ */
1625
+
1626
+ }, {
1627
+ key: 'getLoginUrl',
1628
+ value: function () {
1629
+ var _ref29 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee28() {
1630
+ var _comoData25, token, locationId, env;
1631
+
1632
+ return _regenerator2.default.wrap(function _callee28$(_context28) {
1633
+ while (1) {
1634
+ switch (_context28.prev = _context28.next) {
1635
+ case 0:
1636
+ _context28.next = 2;
1637
+ return this.refreshTokenIfNeeded();
1638
+
1639
+ case 2:
1640
+ _comoData25 = this.comoData, token = _comoData25.token, locationId = _comoData25.locationId, env = _comoData25.env_params;
1641
+ return _context28.abrupt('return', env.app_modules_root + '/login?token=' + token + '&locationid=' + locationId);
1642
+
1643
+ case 4:
1644
+ case 'end':
1645
+ return _context28.stop();
1646
+ }
1647
+ }
1648
+ }, _callee28, this);
1649
+ }));
1094
1650
 
1651
+ function getLoginUrl() {
1652
+ return _ref29.apply(this, arguments);
1653
+ }
1095
1654
 
1096
- return api.getForm(type, locationId);
1097
- };
1655
+ return getLoginUrl;
1656
+ }()
1657
+
1658
+ /**
1659
+ * Returns the location data Portability url
1660
+ */
1661
+
1662
+ }, {
1663
+ key: 'getDataPortabilityUrl',
1664
+ value: function () {
1665
+ var _ref30 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee29(url, overrides) {
1666
+ var installationId;
1667
+ return _regenerator2.default.wrap(function _callee29$(_context29) {
1668
+ while (1) {
1669
+ switch (_context29.prev = _context29.next) {
1670
+ case 0:
1671
+ _context29.next = 2;
1672
+ return this.refreshTokenIfNeeded();
1673
+
1674
+ case 2:
1675
+ installationId = this.comoData.installationId;
1676
+ return _context29.abrupt('return', urlsUtils.appendQuery('' + url, (0, _extends3.default)({
1677
+ installationId: installationId
1678
+ }, overrides)));
1679
+
1680
+ case 4:
1681
+ case 'end':
1682
+ return _context29.stop();
1683
+ }
1684
+ }
1685
+ }, _callee29, this);
1686
+ }));
1098
1687
 
1099
- /**
1100
- *
1101
- * @param {string} type configuration type
1102
- */
1103
- como.getConfigration = function (type) {
1104
- var _comoData24 = comoData,
1105
- api = _comoData24.api,
1106
- locationId = _comoData24.locationId;
1688
+ function getDataPortabilityUrl(_x43, _x44) {
1689
+ return _ref30.apply(this, arguments);
1690
+ }
1107
1691
 
1108
- var _como$getLocationStat = como.getLocationState(),
1109
- version = _como$getLocationStat.PublishVersion;
1692
+ return getDataPortabilityUrl;
1693
+ }()
1694
+
1695
+ /**
1696
+ * Returns app-modules legacy root url
1697
+ */
1698
+
1699
+ }, {
1700
+ key: 'getAppModulesLegacyBaseUrl',
1701
+ value: function () {
1702
+ var _ref31 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee30() {
1703
+ var env;
1704
+ return _regenerator2.default.wrap(function _callee30$(_context30) {
1705
+ while (1) {
1706
+ switch (_context30.prev = _context30.next) {
1707
+ case 0:
1708
+ _context30.next = 2;
1709
+ return this.refreshTokenIfNeeded();
1710
+
1711
+ case 2:
1712
+ env = this.comoData.env_params;
1713
+ return _context30.abrupt('return', '' + env.app_modules_legacy_root);
1714
+
1715
+ case 4:
1716
+ case 'end':
1717
+ return _context30.stop();
1718
+ }
1719
+ }
1720
+ }, _callee30, this);
1721
+ }));
1110
1722
 
1111
- return api.getConfiguration(type, locationId, version);
1112
- };
1723
+ function getAppModulesLegacyBaseUrl() {
1724
+ return _ref31.apply(this, arguments);
1725
+ }
1113
1726
 
1114
- /**
1115
- *
1116
- * @param {string} type resource type
1117
- */
1118
- como.getResource = function (type) {
1119
- var _comoData25 = comoData,
1120
- api = _comoData25.api,
1121
- locationId = _comoData25.locationId;
1727
+ return getAppModulesLegacyBaseUrl;
1728
+ }()
1122
1729
 
1123
- return api.getResource(type, locationId);
1124
- };
1730
+ /**
1731
+ * Returns the location specific friend referral web url
1732
+ */
1125
1733
 
1126
- /**
1127
- * Generates a new referral code for friend-referral
1128
- */
1129
- como.generateReferralCode = function () {
1130
- var _comoData26 = comoData,
1131
- api = _comoData26.api,
1132
- locationId = _comoData26.locationId,
1133
- token = _comoData26.token,
1134
- env = _comoData26.env_params;
1734
+ }, {
1735
+ key: 'getFriendReferralInviteLink',
1736
+ value: function getFriendReferralInviteLink(referral) {
1737
+ return this.comoData.env_params.gateway + '/ssr-modules/friend-referral/' + this.comoData.locationId + '?referral=' + referral;
1738
+ }
1135
1739
 
1740
+ /**
1741
+ * Return the location state
1742
+ * Make sure to call reloadLocationState() to reload the location state object.
1743
+ */
1136
1744
 
1137
- return api.generateReferralCode(env.services_root, token, locationId);
1138
- };
1745
+ }, {
1746
+ key: 'getLocationState',
1747
+ value: function getLocationState() {
1748
+ return this.comoData.locationState;
1749
+ }
1139
1750
 
1140
- /**
1141
- * Returns current accessToken and refreshToken
1142
- * Caution: make sure to pass refresh callback to como.init to get the latest credentials
1143
- */
1144
- como.getCredentials = function () {
1145
- return {
1146
- accessToken: comoData.accessToken,
1147
- refreshToken: comoData.refreshToken,
1148
- expiresIn: comoData.expiresIn,
1149
- consent: comoData.consent
1150
- };
1151
- };
1751
+ /**
1752
+ * Returns the location point shop items
1753
+ */
1152
1754
 
1153
- /**
1154
- * Returns the current accessToken
1155
- * Caution: make sure to pass refresh callback to como.init to get the latest credentials
1156
- */
1157
- como.getToken = function () {
1158
- return comoData.token;
1159
- };
1755
+ }, {
1756
+ key: 'getPointShopItems',
1757
+ value: function getPointShopItems() {
1758
+ return this.comoData.mainResources.menu.gifts_shop_item;
1759
+ }
1160
1760
 
1161
- /**
1162
- * Returns the como.js initialized installation id
1163
- */
1164
- como.getInstallationId = function () {
1165
- return comoData.installationId;
1166
- };
1761
+ /**
1762
+ *
1763
+ * @param {string} resourceName resource name
1764
+ */
1167
1765
 
1168
- /**
1169
- * Return the user membership object
1170
- * Make sure to call reloadMembership() to reload the membership object.
1171
- */
1172
- como.getMembership = function () {
1173
- return comoData.membership;
1174
- };
1766
+ }, {
1767
+ key: 'getMainResource',
1768
+ value: function getMainResource(resourceName) {
1769
+ return this.comoData.mainResources[resourceName];
1770
+ }
1175
1771
 
1176
- /**
1177
- * Return the user assets object
1178
- * Make sure to call reloadAssets() to reload the assets object.
1179
- */
1180
- como.getAssets = function () {
1181
- return comoData.assets;
1182
- };
1772
+ /**
1773
+ *
1774
+ * @param {string} resourceId resource id
1775
+ * @param {string} namespace resource namespace
1776
+ * @param {string|number} version resource version
1777
+ */
1778
+
1779
+ }, {
1780
+ key: 'getResourceUrl',
1781
+ value: function getResourceUrl(resourceId, namespace, version) {
1782
+ var _comoData26 = this.comoData,
1783
+ api = _comoData26.api,
1784
+ env = _comoData26.env_params;
1785
+
1786
+ return api.getResourceUrl(env.services_root_cdn, resourceId, namespace, version);
1787
+ }
1788
+ }, {
1789
+ key: 'getCdnUrl',
1790
+ value: function getCdnUrl() {
1791
+ return this.comoData.env_params.services_root_cdn;
1792
+ }
1183
1793
 
1184
- /**
1185
- * Return the user archived and expired assets object
1186
- * Make sure to call reloadAssets() and reloadArchivedAssets() to reload the archived assets object.
1187
- */
1188
- como.getArchivedAssets = function () {
1189
- return (comoData.archivedAssets || []).concat(comoData.redeemedAssets);
1190
- };
1794
+ /**
1795
+ * @param {string} identifier fcm token created by firebase
1796
+ * @param {boolean} isFirebaseProjectMigrated is migrated to new firebase project
1797
+ */
1798
+
1799
+ }, {
1800
+ key: 'sendPushChannel',
1801
+ value: function sendPushChannel(identifier) {
1802
+ var isFirebaseProjectMigrated = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1803
+ var _comoData27 = this.comoData,
1804
+ api = _comoData27.api,
1805
+ locationId = _comoData27.locationId,
1806
+ token = _comoData27.token,
1807
+ env = _comoData27.env_params;
1808
+
1809
+ return api.sendPushChannel(env.services_root, locationId, token, identifier, isFirebaseProjectMigrated);
1810
+ }
1811
+ }, {
1812
+ key: 'getRegionConfig',
1813
+ value: function () {
1814
+ var _ref32 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee31() {
1815
+ var _comoData28, api, locationId, token, env;
1816
+
1817
+ return _regenerator2.default.wrap(function _callee31$(_context31) {
1818
+ while (1) {
1819
+ switch (_context31.prev = _context31.next) {
1820
+ case 0:
1821
+ _comoData28 = this.comoData, api = _comoData28.api, locationId = _comoData28.locationId, token = _comoData28.token, env = _comoData28.env_params;
1822
+ return _context31.abrupt('return', api.getClientBusinessBackend(env.zapp_root, token, locationId));
1823
+
1824
+ case 2:
1825
+ case 'end':
1826
+ return _context31.stop();
1827
+ }
1828
+ }
1829
+ }, _callee31, this);
1830
+ }));
1191
1831
 
1192
- /**
1193
- * Returns the location specific registration web url
1194
- */
1195
- como.getRegistrationUrl = function () {
1196
- var _ref26 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee25(overrides) {
1197
- var _comoData27, token, installationId, locationId, env;
1198
-
1199
- return _regenerator2.default.wrap(function _callee25$(_context25) {
1200
- while (1) {
1201
- switch (_context25.prev = _context25.next) {
1202
- case 0:
1203
- _context25.next = 2;
1204
- return refreshTokenIfNeeded();
1205
-
1206
- case 2:
1207
- _comoData27 = comoData, token = _comoData27.token, installationId = _comoData27.installationId, locationId = _comoData27.locationId, env = _comoData27.env_params;
1208
- return _context25.abrupt('return', urlsUtils.appendQuery(env.app_modules_root + '/register?token=' + token + '&locationid=' + locationId, (0, _extends3.default)({}, como.getCredentials(), {
1209
- installationId: installationId,
1210
- disableSuccessScreen: 'true'
1211
- }, overrides)));
1212
-
1213
- case 4:
1214
- case 'end':
1215
- return _context25.stop();
1216
- }
1832
+ function getRegionConfig() {
1833
+ return _ref32.apply(this, arguments);
1217
1834
  }
1218
- }, _callee25, undefined);
1219
- }));
1220
1835
 
1221
- return function (_x31) {
1222
- return _ref26.apply(this, arguments);
1223
- };
1224
- }();
1836
+ return getRegionConfig;
1837
+ }()
1225
1838
 
1226
- /**
1227
- * Returns the location specific profile web url
1228
- */
1229
- como.getProfileUrl = function () {
1230
- var _ref27 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee26(overrides) {
1231
- var _comoData28, token, installationId, locationId, env;
1232
-
1233
- return _regenerator2.default.wrap(function _callee26$(_context26) {
1234
- while (1) {
1235
- switch (_context26.prev = _context26.next) {
1236
- case 0:
1237
- _context26.next = 2;
1238
- return refreshTokenIfNeeded();
1239
-
1240
- case 2:
1241
- _comoData28 = comoData, token = _comoData28.token, installationId = _comoData28.installationId, locationId = _comoData28.locationId, env = _comoData28.env_params;
1242
- return _context26.abrupt('return', urlsUtils.appendQuery(env.app_modules_root + '/profile?token=' + token + '&locationid=' + locationId, (0, _extends3.default)({}, como.getCredentials(), {
1243
- installationId: installationId,
1244
- disableSuccessScreen: 'true'
1245
- }, overrides)));
1246
-
1247
- case 4:
1248
- case 'end':
1249
- return _context26.stop();
1250
- }
1251
- }
1252
- }, _callee26, undefined);
1253
- }));
1839
+ /**
1840
+ * @param {string} code coupon code entered by user on App
1841
+ */
1254
1842
 
1255
- return function (_x32) {
1256
- return _ref27.apply(this, arguments);
1257
- };
1258
- }();
1843
+ }, {
1844
+ key: 'sendCouponCode',
1845
+ value: function sendCouponCode(code) {
1846
+ var _comoData29 = this.comoData,
1847
+ api = _comoData29.api,
1848
+ locationId = _comoData29.locationId,
1849
+ token = _comoData29.token,
1850
+ env = _comoData29.env_params;
1259
1851
 
1260
- /**
1261
- * Returns the location specific login web url
1262
- */
1263
- como.getLoginUrl = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee27() {
1264
- var _comoData29, token, locationId, env;
1265
-
1266
- return _regenerator2.default.wrap(function _callee27$(_context27) {
1267
- while (1) {
1268
- switch (_context27.prev = _context27.next) {
1269
- case 0:
1270
- _context27.next = 2;
1271
- return refreshTokenIfNeeded();
1272
-
1273
- case 2:
1274
- _comoData29 = comoData, token = _comoData29.token, locationId = _comoData29.locationId, env = _comoData29.env_params;
1275
- return _context27.abrupt('return', env.app_modules_root + '/login?token=' + token + '&locationid=' + locationId);
1276
-
1277
- case 4:
1278
- case 'end':
1279
- return _context27.stop();
1280
- }
1852
+ return api.sendCouponCode(env.zapp_root, locationId, token, code);
1281
1853
  }
1282
- }, _callee27, undefined);
1283
- }));
1284
-
1285
- /**
1286
- * Returns app-modules legacy root url
1287
- */
1288
- como.getAppModulesLegacyBaseUrl = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee28() {
1289
- var _comoData30, env;
1290
-
1291
- return _regenerator2.default.wrap(function _callee28$(_context28) {
1292
- while (1) {
1293
- switch (_context28.prev = _context28.next) {
1294
- case 0:
1295
- _context28.next = 2;
1296
- return refreshTokenIfNeeded();
1297
-
1298
- case 2:
1299
- _comoData30 = comoData, env = _comoData30.env_params;
1300
- return _context28.abrupt('return', '' + env.app_modules_legacy_root);
1301
-
1302
- case 4:
1303
- case 'end':
1304
- return _context28.stop();
1854
+ }, {
1855
+ key: 'addPaymentMethod',
1856
+ value: function () {
1857
+ var _ref33 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee32(cardToken) {
1858
+ var _comoData30, api, locationId, token, env;
1859
+
1860
+ return _regenerator2.default.wrap(function _callee32$(_context32) {
1861
+ while (1) {
1862
+ switch (_context32.prev = _context32.next) {
1863
+ case 0:
1864
+ _comoData30 = this.comoData, api = _comoData30.api, locationId = _comoData30.locationId, token = _comoData30.token, env = _comoData30.env_params;
1865
+ return _context32.abrupt('return', api.addPaymentMethod(env.services_root, locationId, token, cardToken));
1866
+
1867
+ case 2:
1868
+ case 'end':
1869
+ return _context32.stop();
1870
+ }
1871
+ }
1872
+ }, _callee32, this);
1873
+ }));
1874
+
1875
+ function addPaymentMethod(_x46) {
1876
+ return _ref33.apply(this, arguments);
1305
1877
  }
1306
- }
1307
- }, _callee28, undefined);
1308
- }));
1309
-
1310
- /**
1311
- * Returns the location specific friend referral web url
1312
- */
1313
- como.getFriendReferralInviteLink = function (referral) {
1314
- return comoData.env_params.gateway + '/ssr-modules/friend-referral/' + comoData.locationId + '?referral=' + referral;
1315
- };
1316
1878
 
1317
- /**
1318
- * Return the location state
1319
- * Make sure to call reloadLocationState() to reload the location state object.
1320
- */
1321
- como.getLocationState = function () {
1322
- return comoData.locationState;
1323
- };
1879
+ return addPaymentMethod;
1880
+ }()
1881
+ }, {
1882
+ key: 'knowYourData',
1883
+ value: function () {
1884
+ var _ref34 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee33(email) {
1885
+ var _comoData31, api, locationId, token, env;
1886
+
1887
+ return _regenerator2.default.wrap(function _callee33$(_context33) {
1888
+ while (1) {
1889
+ switch (_context33.prev = _context33.next) {
1890
+ case 0:
1891
+ _comoData31 = this.comoData, api = _comoData31.api, locationId = _comoData31.locationId, token = _comoData31.token, env = _comoData31.env_params;
1892
+ return _context33.abrupt('return', api.knowYourData(env.services_root, locationId, token, email));
1893
+
1894
+ case 2:
1895
+ case 'end':
1896
+ return _context33.stop();
1897
+ }
1898
+ }
1899
+ }, _callee33, this);
1900
+ }));
1324
1901
 
1325
- /**
1326
- * Returns the location point shop items
1327
- */
1328
- como.getPointShopItems = function () {
1329
- return comoData.mainResources.menu.gifts_shop_item;
1330
- };
1902
+ function knowYourData(_x47) {
1903
+ return _ref34.apply(this, arguments);
1904
+ }
1331
1905
 
1332
- /**
1333
- *
1334
- * @param {string} resourceName resource name
1335
- */
1336
- como.getMainResource = function (resourceName) {
1337
- return comoData.mainResources[resourceName];
1338
- };
1906
+ return knowYourData;
1907
+ }()
1908
+ }, {
1909
+ key: 'consentWithdraw',
1910
+ value: function () {
1911
+ var _ref35 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee34(consentData) {
1912
+ var _comoData32, api, locationId, token, env;
1913
+
1914
+ return _regenerator2.default.wrap(function _callee34$(_context34) {
1915
+ while (1) {
1916
+ switch (_context34.prev = _context34.next) {
1917
+ case 0:
1918
+ _comoData32 = this.comoData, api = _comoData32.api, locationId = _comoData32.locationId, token = _comoData32.token, env = _comoData32.env_params;
1919
+ return _context34.abrupt('return', api.consentWithdraw(env.services_root, locationId, token, consentData));
1920
+
1921
+ case 2:
1922
+ case 'end':
1923
+ return _context34.stop();
1924
+ }
1925
+ }
1926
+ }, _callee34, this);
1927
+ }));
1339
1928
 
1340
- /**
1341
- *
1342
- * @param {string} resourceId resource id
1343
- * @param {string} namespace resource namespace
1344
- * @param {string|number} version resource version
1345
- */
1346
- como.getResourceUrl = function (resourceId, namespace, version) {
1347
- var _comoData31 = comoData,
1348
- api = _comoData31.api,
1349
- env = _comoData31.env_params;
1350
-
1351
- return api.getResourceUrl(env.services_root_temp, resourceId, namespace, version);
1352
- };
1929
+ function consentWithdraw(_x48) {
1930
+ return _ref35.apply(this, arguments);
1931
+ }
1353
1932
 
1354
- /**
1355
- * @param {string} identifier fcm token created by firebase
1356
- */
1357
- como.sendPushChannel = function (identifier) {
1358
- var _comoData32 = comoData,
1359
- api = _comoData32.api,
1360
- locationId = _comoData32.locationId,
1361
- token = _comoData32.token,
1362
- env = _comoData32.env_params;
1363
-
1364
- return api.sendPushChannel(env.services_root, locationId, token, identifier);
1365
- };
1933
+ return consentWithdraw;
1934
+ }()
1935
+ }, {
1936
+ key: 'getPaymentMethods',
1937
+ value: function () {
1938
+ var _ref36 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee35() {
1939
+ var _comoData33, env, locationId, api, responseJson;
1940
+
1941
+ return _regenerator2.default.wrap(function _callee35$(_context35) {
1942
+ while (1) {
1943
+ switch (_context35.prev = _context35.next) {
1944
+ case 0:
1945
+ _comoData33 = this.comoData, env = _comoData33.env_params, locationId = _comoData33.locationId, api = _comoData33.api;
1946
+ _context35.next = 3;
1947
+ return api.getPaymentMethods(env.services_root, locationId);
1948
+
1949
+ case 3:
1950
+ responseJson = _context35.sent;
1951
+ return _context35.abrupt('return', responseJson);
1952
+
1953
+ case 5:
1954
+ case 'end':
1955
+ return _context35.stop();
1956
+ }
1957
+ }
1958
+ }, _callee35, this);
1959
+ }));
1366
1960
 
1367
- como.getRegionConfig = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee29() {
1368
- var _comoData33, api, locationId, token, env;
1961
+ function getPaymentMethods() {
1962
+ return _ref36.apply(this, arguments);
1963
+ }
1369
1964
 
1370
- return _regenerator2.default.wrap(function _callee29$(_context29) {
1371
- while (1) {
1372
- switch (_context29.prev = _context29.next) {
1373
- case 0:
1374
- _comoData33 = comoData, api = _comoData33.api, locationId = _comoData33.locationId, token = _comoData33.token, env = _comoData33.env_params;
1375
- return _context29.abrupt('return', api.getClientBusinessBackend(env.zapp_root, token, locationId));
1965
+ return getPaymentMethods;
1966
+ }()
1967
+
1968
+ /**
1969
+ * @param {Integer} amount to charge
1970
+ * @param {String} creditCardToken to charge from
1971
+ * @param {String} itemName for submit purchase
1972
+ * @param {String} itemNumber for submit purchase
1973
+ * @param {String} membershipKey for user identification
1974
+ */
1975
+
1976
+ }, {
1977
+ key: 'payInApp',
1978
+ value: function () {
1979
+ var _ref37 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee36(amount, creditCardToken, itemName, itemNumber, membershipKey) {
1980
+ var _comoData34, env, token, locationId, api, responseJson;
1981
+
1982
+ return _regenerator2.default.wrap(function _callee36$(_context36) {
1983
+ while (1) {
1984
+ switch (_context36.prev = _context36.next) {
1985
+ case 0:
1986
+ _comoData34 = this.comoData, env = _comoData34.env_params, token = _comoData34.token, locationId = _comoData34.locationId, api = _comoData34.api;
1987
+ _context36.next = 3;
1988
+ return api.payInApp(env.services_root, locationId, token, amount, creditCardToken, itemName, itemNumber, membershipKey);
1989
+
1990
+ case 3:
1991
+ responseJson = _context36.sent;
1992
+ return _context36.abrupt('return', responseJson);
1993
+
1994
+ case 5:
1995
+ case 'end':
1996
+ return _context36.stop();
1997
+ }
1998
+ }
1999
+ }, _callee36, this);
2000
+ }));
1376
2001
 
1377
- case 2:
1378
- case 'end':
1379
- return _context29.stop();
2002
+ function payInApp(_x49, _x50, _x51, _x52, _x53) {
2003
+ return _ref37.apply(this, arguments);
1380
2004
  }
1381
- }
1382
- }, _callee29, undefined);
1383
- }));
1384
-
1385
- /**
1386
- * @param {string} code coupon code entered by user on App
1387
- */
1388
- como.sendCouponCode = function (code) {
1389
- var _comoData34 = comoData,
1390
- api = _comoData34.api,
1391
- locationId = _comoData34.locationId,
1392
- token = _comoData34.token,
1393
- env = _comoData34.env_params;
1394
-
1395
- return api.sendCouponCode(env.zapp_root, locationId, token, code);
1396
- };
1397
2005
 
1398
- como.addPaymentMethod = function () {
1399
- var _ref31 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee30(cardToken) {
1400
- var _comoData35, api, locationId, token, env;
1401
-
1402
- return _regenerator2.default.wrap(function _callee30$(_context30) {
1403
- while (1) {
1404
- switch (_context30.prev = _context30.next) {
1405
- case 0:
1406
- _comoData35 = comoData, api = _comoData35.api, locationId = _comoData35.locationId, token = _comoData35.token, env = _comoData35.env_params;
1407
- return _context30.abrupt('return', api.addPaymentMethod(env.services_root, locationId, token, cardToken));
1408
-
1409
- case 2:
1410
- case 'end':
1411
- return _context30.stop();
1412
- }
1413
- }
1414
- }, _callee30, undefined);
1415
- }));
2006
+ return payInApp;
2007
+ }()
2008
+
2009
+ /**
2010
+ * @param {string} creditCardToken which card to delete
2011
+ */
2012
+
2013
+ }, {
2014
+ key: 'deletePayment',
2015
+ value: function () {
2016
+ var _ref38 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee37(creditCardToken) {
2017
+ var _comoData35, env, token, locationId, api, responseJson;
2018
+
2019
+ return _regenerator2.default.wrap(function _callee37$(_context37) {
2020
+ while (1) {
2021
+ switch (_context37.prev = _context37.next) {
2022
+ case 0:
2023
+ _comoData35 = this.comoData, env = _comoData35.env_params, token = _comoData35.token, locationId = _comoData35.locationId, api = _comoData35.api;
2024
+ _context37.next = 3;
2025
+ return api.deletePayment(env.services_root, locationId, token, creditCardToken);
2026
+
2027
+ case 3:
2028
+ responseJson = _context37.sent;
2029
+ return _context37.abrupt('return', responseJson);
2030
+
2031
+ case 5:
2032
+ case 'end':
2033
+ return _context37.stop();
2034
+ }
2035
+ }
2036
+ }, _callee37, this);
2037
+ }));
1416
2038
 
1417
- return function (_x33) {
1418
- return _ref31.apply(this, arguments);
1419
- };
1420
- }();
2039
+ function deletePayment(_x54) {
2040
+ return _ref38.apply(this, arguments);
2041
+ }
1421
2042
 
1422
- como.getPaymentMethods = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee31() {
1423
- var _comoData36, env, locationId, api, responseJson;
2043
+ return deletePayment;
2044
+ }()
2045
+ /**
2046
+ * @param {string} tag for Pop-up Message Trigger (Optional param)
2047
+ */
2048
+
2049
+ }, {
2050
+ key: 'getMemberMessages',
2051
+ value: function getMemberMessages(tag, limit, offset) {
2052
+ var _comoData36 = this.comoData,
2053
+ api = _comoData36.api,
2054
+ locationId = _comoData36.locationId,
2055
+ env = _comoData36.env_params;
2056
+
2057
+ return api.getMemberMessages(env.services_root, locationId, tag, limit, offset);
2058
+ }
1424
2059
 
1425
- return _regenerator2.default.wrap(function _callee31$(_context31) {
1426
- while (1) {
1427
- switch (_context31.prev = _context31.next) {
1428
- case 0:
1429
- _comoData36 = comoData, env = _comoData36.env_params, locationId = _comoData36.locationId, api = _comoData36.api;
1430
- _context31.next = 3;
1431
- return api.getPaymentMethods(env.services_root, locationId);
2060
+ /**
2061
+ * @param {string} keysList keys of the messages to mark as read
2062
+ */
1432
2063
 
1433
- case 3:
1434
- responseJson = _context31.sent;
1435
- return _context31.abrupt('return', responseJson);
2064
+ }, {
2065
+ key: 'markAsReadMemberMessages',
2066
+ value: function markAsReadMemberMessages(keysList) {
2067
+ var _comoData37 = this.comoData,
2068
+ api = _comoData37.api,
2069
+ locationId = _comoData37.locationId,
2070
+ env = _comoData37.env_params;
1436
2071
 
1437
- case 5:
1438
- case 'end':
1439
- return _context31.stop();
1440
- }
2072
+ return api.markAsReadMemberMessages(env.services_root, locationId, keysList);
1441
2073
  }
1442
- }, _callee31, undefined);
1443
- }));
1444
-
1445
- /**
1446
- * @param {Integer} amount to charge
1447
- * @param {String} creditCardToken to charge from
1448
- * @param {String} itemName for submit purchase
1449
- * @param {String} itemNumber for submit purchase
1450
- * @param {String} membershipKey for user identification
1451
- */
1452
- como.payInApp = function () {
1453
- var _ref33 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee32(amount, creditCardToken, itemName, itemNumber, membershipKey) {
1454
- var _comoData37, env, token, locationId, api, responseJson;
1455
-
1456
- return _regenerator2.default.wrap(function _callee32$(_context32) {
1457
- while (1) {
1458
- switch (_context32.prev = _context32.next) {
1459
- case 0:
1460
- _comoData37 = comoData, env = _comoData37.env_params, token = _comoData37.token, locationId = _comoData37.locationId, api = _comoData37.api;
1461
- _context32.next = 3;
1462
- return api.payInApp(env.services_root, locationId, token, amount, creditCardToken, itemName, itemNumber, membershipKey);
1463
-
1464
- case 3:
1465
- responseJson = _context32.sent;
1466
- return _context32.abrupt('return', responseJson);
1467
-
1468
- case 5:
1469
- case 'end':
1470
- return _context32.stop();
1471
- }
1472
- }
1473
- }, _callee32, undefined);
1474
- }));
1475
2074
 
1476
- return function (_x34, _x35, _x36, _x37, _x38) {
1477
- return _ref33.apply(this, arguments);
1478
- };
1479
- }();
2075
+ /**
2076
+ * @param {String} receiver to share with
2077
+ * @param {String} sender name
2078
+ * @param {Integer} amount to share
2079
+ * @param {String} type of wallet
2080
+ */
2081
+
2082
+ }, {
2083
+ key: 'budgetTransfer',
2084
+ value: function () {
2085
+ var _ref39 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee38(receiver, sender, amount, wallet) {
2086
+ var _comoData38, api, locationId, env;
2087
+
2088
+ return _regenerator2.default.wrap(function _callee38$(_context38) {
2089
+ while (1) {
2090
+ switch (_context38.prev = _context38.next) {
2091
+ case 0:
2092
+ _comoData38 = this.comoData, api = _comoData38.api, locationId = _comoData38.locationId, env = _comoData38.env_params;
2093
+ return _context38.abrupt('return', api.budgetTransfer(env.services_root, locationId, receiver, sender, amount, wallet));
2094
+
2095
+ case 2:
2096
+ case 'end':
2097
+ return _context38.stop();
2098
+ }
2099
+ }
2100
+ }, _callee38, this);
2101
+ }));
1480
2102
 
1481
- /**
1482
- * @param {string} creditCardToken which card to delete
1483
- */
1484
- como.deletePayment = function () {
1485
- var _ref34 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee33(creditCardToken) {
1486
- var _comoData38, env, token, locationId, api, responseJson;
1487
-
1488
- return _regenerator2.default.wrap(function _callee33$(_context33) {
1489
- while (1) {
1490
- switch (_context33.prev = _context33.next) {
1491
- case 0:
1492
- _comoData38 = comoData, env = _comoData38.env_params, token = _comoData38.token, locationId = _comoData38.locationId, api = _comoData38.api;
1493
- _context33.next = 3;
1494
- return api.deletePayment(env.services_root, locationId, token, creditCardToken);
1495
-
1496
- case 3:
1497
- responseJson = _context33.sent;
1498
- return _context33.abrupt('return', responseJson);
1499
-
1500
- case 5:
1501
- case 'end':
1502
- return _context33.stop();
1503
- }
2103
+ function budgetTransfer(_x55, _x56, _x57, _x58) {
2104
+ return _ref39.apply(this, arguments);
1504
2105
  }
1505
- }, _callee33, undefined);
1506
- }));
1507
2106
 
1508
- return function (_x39) {
1509
- return _ref34.apply(this, arguments);
1510
- };
1511
- }();
1512
- /**
1513
- * @param {string} tag for Pop-up Message Trigger (Optional param)
1514
- */
1515
- como.getMemberMessages = function (tag, limit, offset) {
1516
- var _comoData39 = comoData,
1517
- api = _comoData39.api,
1518
- locationId = _comoData39.locationId,
1519
- env = _comoData39.env_params;
1520
-
1521
- return api.getMemberMessages(env.services_root, locationId, tag, limit, offset);
1522
- };
2107
+ return budgetTransfer;
2108
+ }()
1523
2109
 
1524
- /**
1525
- * @param {string} keysList keys of the messages to mark as read
1526
- */
1527
- como.markAsReadMemberMessages = function (keysList) {
1528
- var _comoData40 = comoData,
1529
- api = _comoData40.api,
1530
- locationId = _comoData40.locationId,
1531
- env = _comoData40.env_params;
2110
+ /**
2111
+ * @param {string} claimId key of the credit claim to read the data for
2112
+ */
1532
2113
 
1533
- return api.markAsReadMemberMessages(env.services_root, locationId, keysList);
1534
- };
2114
+ }, {
2115
+ key: 'getCreditClaimData',
2116
+ value: function getCreditClaimData(claimId) {
2117
+ var _comoData39 = this.comoData,
2118
+ api = _comoData39.api,
2119
+ env = _comoData39.env_params;
2120
+
2121
+ return api.getCreditClaimData(env.services_root, claimId);
2122
+ }
1535
2123
 
1536
- /**
1537
- * @param {String} receiver to share with
1538
- * @param {String} sender name
1539
- * @param {Integer} amount to share
1540
- * @param {String} type of wallet
1541
- */
1542
- como.budgetTransfer = function () {
1543
- var _ref35 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee34(receiver, sender, amount, wallet) {
1544
- var _comoData41, api, locationId, env;
1545
-
1546
- return _regenerator2.default.wrap(function _callee34$(_context34) {
1547
- while (1) {
1548
- switch (_context34.prev = _context34.next) {
1549
- case 0:
1550
- _comoData41 = comoData, api = _comoData41.api, locationId = _comoData41.locationId, env = _comoData41.env_params;
1551
- return _context34.abrupt('return', api.budgetTransfer(env.services_root, locationId, receiver, sender, amount, wallet));
1552
-
1553
- case 2:
1554
- case 'end':
1555
- return _context34.stop();
1556
- }
2124
+ /**
2125
+ * @param {String} claimCode to use for budget transfer claim
2126
+ */
2127
+
2128
+ }, {
2129
+ key: 'budgetTransferClaim',
2130
+ value: function () {
2131
+ var _ref40 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee39(claimCode) {
2132
+ var _comoData40, api, locationId, env;
2133
+
2134
+ return _regenerator2.default.wrap(function _callee39$(_context39) {
2135
+ while (1) {
2136
+ switch (_context39.prev = _context39.next) {
2137
+ case 0:
2138
+ _comoData40 = this.comoData, api = _comoData40.api, locationId = _comoData40.locationId, env = _comoData40.env_params;
2139
+ return _context39.abrupt('return', api.budgetTransferClaim(env.services_root, locationId, claimCode));
2140
+
2141
+ case 2:
2142
+ case 'end':
2143
+ return _context39.stop();
2144
+ }
2145
+ }
2146
+ }, _callee39, this);
2147
+ }));
2148
+
2149
+ function budgetTransferClaim(_x59) {
2150
+ return _ref40.apply(this, arguments);
1557
2151
  }
1558
- }, _callee34, undefined);
1559
- }));
1560
2152
 
1561
- return function (_x40, _x41, _x42, _x43) {
1562
- return _ref35.apply(this, arguments);
1563
- };
1564
- }();
2153
+ return budgetTransferClaim;
2154
+ }()
2155
+
2156
+ /**
2157
+ * API call for claim generic action. To specify your trigger button, you need to associate it with a particular item, asset or tag.
2158
+ * @param {string} assetKey - asset to claim
2159
+ * @param {string} itemId - item id to claim
2160
+ * @param {string} tag - claim all with tag
2161
+ */
2162
+
2163
+ }, {
2164
+ key: 'claim',
2165
+ value: function claim(assetKey, itemId, tag) {
2166
+ var _comoData41 = this.comoData,
2167
+ env = _comoData41.env_params,
2168
+ locationId = _comoData41.locationId,
2169
+ api = _comoData41.api,
2170
+ token = _comoData41.token;
2171
+
2172
+ return api.claim(env.zapp_root, locationId, token, assetKey, itemId, tag);
2173
+ }
2174
+
2175
+ /**
2176
+ * Log user action
2177
+ * @param {string} action
2178
+ * @param {string} logData - log information
2179
+ */
2180
+
2181
+ }, {
2182
+ key: 'logUserAction',
2183
+ value: function () {
2184
+ var _ref41 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee40(action, logData) {
2185
+ var _comoData42, env, locationId, api, token;
2186
+
2187
+ return _regenerator2.default.wrap(function _callee40$(_context40) {
2188
+ while (1) {
2189
+ switch (_context40.prev = _context40.next) {
2190
+ case 0:
2191
+ _comoData42 = this.comoData, env = _comoData42.env_params, locationId = _comoData42.locationId, api = _comoData42.api, token = _comoData42.token;
2192
+ return _context40.abrupt('return', api.logUserAction(env.zapp_root, locationId, token, action, logData));
2193
+
2194
+ case 2:
2195
+ case 'end':
2196
+ return _context40.stop();
2197
+ }
2198
+ }
2199
+ }, _callee40, this);
2200
+ }));
1565
2201
 
1566
- /**
1567
- * @param {string} claimId key of the credit claim to read the data for
1568
- */
1569
- como.getCreditClaimData = function (claimId) {
1570
- var _comoData42 = comoData,
1571
- api = _comoData42.api,
1572
- env = _comoData42.env_params;
2202
+ function logUserAction(_x60, _x61) {
2203
+ return _ref41.apply(this, arguments);
2204
+ }
1573
2205
 
1574
- return api.getCreditClaimData(env.services_root, claimId);
1575
- };
2206
+ return logUserAction;
2207
+ }()
2208
+
2209
+ /**
2210
+ * Member purchase history
2211
+ * @param {string} limit - how manay items to return (if exists) - default value is 25
2212
+ * @param {string} offset - default value is 0(next offset would be 25)
2213
+ */
2214
+
2215
+ }, {
2216
+ key: 'getPurchaseHistory',
2217
+ value: function () {
2218
+ var _ref42 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee41(limit, offset) {
2219
+ var _comoData43, locationId, api, membership;
2220
+
2221
+ return _regenerator2.default.wrap(function _callee41$(_context41) {
2222
+ while (1) {
2223
+ switch (_context41.prev = _context41.next) {
2224
+ case 0:
2225
+ _comoData43 = this.comoData, locationId = _comoData43.locationId, api = _comoData43.api, membership = _comoData43.membership;
2226
+ return _context41.abrupt('return', api.getPurchaseHistory(locationId, membership.Key, limit, offset));
2227
+
2228
+ case 2:
2229
+ case 'end':
2230
+ return _context41.stop();
2231
+ }
2232
+ }
2233
+ }, _callee41, this);
2234
+ }));
1576
2235
 
1577
- /**
1578
- * @param {String} claimCode to use for budget transfer claim
1579
- */
1580
- como.budgetTransferClaim = function () {
1581
- var _ref36 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee35(claimCode) {
1582
- var _comoData43, api, locationId, env;
1583
-
1584
- return _regenerator2.default.wrap(function _callee35$(_context35) {
1585
- while (1) {
1586
- switch (_context35.prev = _context35.next) {
1587
- case 0:
1588
- _comoData43 = comoData, api = _comoData43.api, locationId = _comoData43.locationId, env = _comoData43.env_params;
1589
- return _context35.abrupt('return', api.budgetTransferClaim(env.services_root, locationId, claimCode));
1590
-
1591
- case 2:
1592
- case 'end':
1593
- return _context35.stop();
1594
- }
2236
+ function getPurchaseHistory(_x62, _x63) {
2237
+ return _ref42.apply(this, arguments);
1595
2238
  }
1596
- }, _callee35, undefined);
1597
- }));
1598
2239
 
1599
- return function (_x44) {
1600
- return _ref36.apply(this, arguments);
1601
- };
2240
+ return getPurchaseHistory;
2241
+ }()
2242
+ }]);
2243
+ return Como;
1602
2244
  }();
1603
2245
 
1604
- /**
1605
- * API call for claim generic action. To specify your trigger button, you need to associate it with a particular item, asset or tag.
1606
- * @param {string} assetKey - asset to claim
1607
- * @param {string} itemId - item id to claim
1608
- * @param {string} tag - claim all with tag
1609
- */
1610
- como.claim = function (assetKey, itemId, tag) {
1611
- var _comoData44 = comoData,
1612
- env = _comoData44.env_params,
1613
- locationId = _comoData44.locationId,
1614
- api = _comoData44.api,
1615
- token = _comoData44.token;
1616
-
1617
- return api.claim(env.zapp_root, locationId, token, assetKey, itemId, tag);
1618
- };
1619
-
1620
- module.exports = como;
2246
+ module.exports = Como;