@smartico/public-api 0.0.126 → 0.0.128

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.
@@ -381,6 +381,11 @@ class NodeCache {
381
381
  ttl: new Date().getTime() + ttlSeconds * 1000
382
382
  };
383
383
  }
384
+ remove(key) {
385
+ if (NodeCache.cache.hasOwnProperty(key)) {
386
+ delete NodeCache.cache[key];
387
+ }
388
+ }
384
389
  flushAll() {
385
390
  NodeCache.cache = {};
386
391
  }
@@ -422,7 +427,13 @@ class OCache {
422
427
  return o;
423
428
  }
424
429
  }
425
- static async clear(cacheContext) {
430
+ static async clear(cacheContext, oKey) {
431
+ const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
432
+ if (this.cache[cacheContext]) {
433
+ this.cache[cacheContext].remove(key);
434
+ }
435
+ }
436
+ static async clearContext(cacheContext) {
426
437
  if (this.cache[cacheContext]) {
427
438
  this.cache[cacheContext].flushAll();
428
439
  }
@@ -1003,6 +1014,8 @@ const GetLevelMapResponseTransform = levels => {
1003
1014
 
1004
1015
  /** @hidden */
1005
1016
  const CACHE_DATA_SEC = 30;
1017
+ const JACKPOT_TEMPLATE_CACHE_SEC = 30;
1018
+ const JACKPOT_POT_CACHE_SEC = 1;
1006
1019
  /** @hidden */
1007
1020
  var onUpdateContextKey;
1008
1021
  (function (onUpdateContextKey) {
@@ -1019,6 +1032,8 @@ var onUpdateContextKey;
1019
1032
  onUpdateContextKey["LevelExtraCounters"] = "levelExtraCounters";
1020
1033
  onUpdateContextKey["Segments"] = "segments";
1021
1034
  onUpdateContextKey["StoreHistory"] = "storeHistory";
1035
+ onUpdateContextKey["Jackpots"] = "jackpots";
1036
+ onUpdateContextKey["Pots"] = "Pots";
1022
1037
  })(onUpdateContextKey || (onUpdateContextKey = {}));
1023
1038
  /** @group General API */
1024
1039
  class WSAPI {
@@ -1026,6 +1041,7 @@ class WSAPI {
1026
1041
  constructor(api) {
1027
1042
  this.api = void 0;
1028
1043
  this.onUpdateCallback = new Map();
1044
+ this.jackpotGetSignature = '';
1029
1045
  this.api = api;
1030
1046
  const on = this.api.tracker.on;
1031
1047
  on(ClassId.SAW_SPINS_COUNT_PUSH, data => this.updateOnSpin(data));
@@ -1034,8 +1050,9 @@ class WSAPI {
1034
1050
  on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissionsOnOptIn());
1035
1051
  on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournamentsOnRegistration());
1036
1052
  on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
1037
- on(ClassId.LOGOUT_RESPONSE, () => OCache.clear(ECacheContext.WSAPI));
1038
- on(ClassId.IDENTIFY_RESPONSE, () => OCache.clear(ECacheContext.WSAPI));
1053
+ on(ClassId.LOGOUT_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
1054
+ on(ClassId.IDENTIFY_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
1055
+ on(ClassId.JP_WIN_PUSH, data => this.jackpotClearCache());
1039
1056
  }
1040
1057
  /** Returns information about current user
1041
1058
  * Example usage:
@@ -1372,6 +1389,56 @@ class WSAPI {
1372
1389
  onUpdate(payload);
1373
1390
  }
1374
1391
  }
1392
+ async jackpotClearCache() {
1393
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Jackpots);
1394
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Pots);
1395
+ }
1396
+ async jackpotGet(filter) {
1397
+ var _this = this;
1398
+ const signature = `${filter.jp_template_id}:${filter.related_game_id}`;
1399
+ if (signature !== this.jackpotGetSignature) {
1400
+ this.jackpotGetSignature = signature;
1401
+ this.jackpotClearCache();
1402
+ }
1403
+ let jackpots = [];
1404
+ let pots = [];
1405
+ jackpots = await OCache.use(onUpdateContextKey.Jackpots, ECacheContext.WSAPI, async function () {
1406
+ const _jackpots = await _this.api.jackpotGet(null, filter);
1407
+ const _pots = _jackpots.map(jp => jp.pot);
1408
+ OCache.set(onUpdateContextKey.Pots, _pots, ECacheContext.WSAPI, JACKPOT_POT_CACHE_SEC);
1409
+ return _jackpots;
1410
+ }, JACKPOT_TEMPLATE_CACHE_SEC);
1411
+ if (jackpots.length > 0) {
1412
+ pots = await OCache.use(onUpdateContextKey.Pots, ECacheContext.WSAPI, async function () {
1413
+ const jp_template_ids = jackpots.map(jp => jp.jp_template_id);
1414
+ return _this.api.potGet(null, {
1415
+ jp_template_ids
1416
+ });
1417
+ }, JACKPOT_POT_CACHE_SEC);
1418
+ }
1419
+ return jackpots.map(jp => {
1420
+ let _jp = _extends({}, jp, {
1421
+ pot: pots.find(p => p.jp_template_id === jp.jp_template_id)
1422
+ });
1423
+ return _jp;
1424
+ });
1425
+ }
1426
+ async jackpotOptIn(filter) {
1427
+ if (!filter.jp_template_id) {
1428
+ throw new Error('jp_template_id is required in jackpotOptIn');
1429
+ }
1430
+ const result = await this.api.jackpotOptIn(null, filter);
1431
+ this.jackpotClearCache();
1432
+ return result;
1433
+ }
1434
+ async jackpotOptOut(filter) {
1435
+ if (!filter.jp_template_id) {
1436
+ throw new Error('jp_template_id is required in jackpotOptOut');
1437
+ }
1438
+ const result = await this.api.jackpotOptOut(null, filter);
1439
+ this.jackpotClearCache();
1440
+ return result;
1441
+ }
1375
1442
  }
1376
1443
 
1377
1444
  const pointsRewardTransform = reward_points => {
@@ -1613,6 +1680,24 @@ class SmarticoAPI {
1613
1680
  const results = await this.send(message, ClassId.CHECK_SEGMENT_MATCH_RESPONSE);
1614
1681
  return results.segments || [];
1615
1682
  }
1683
+ async jackpotGet(user_ext_id, filter) {
1684
+ const message = this.buildMessage(user_ext_id, ClassId.JP_GET_JACKPOTS_REQUEST, filter);
1685
+ const response = await this.send(message, ClassId.JP_GET_JACKPOTS_RESPONSE);
1686
+ return (response == null ? void 0 : response.items) || [];
1687
+ }
1688
+ async potGet(user_ext_id, filter) {
1689
+ const message = this.buildMessage(user_ext_id, ClassId.JP_GET_JACKPOTS_REQUEST, filter);
1690
+ const response = await this.send(message, ClassId.JP_GET_LATEST_POTS_RESPONSE);
1691
+ return (response == null ? void 0 : response.items) || [];
1692
+ }
1693
+ async jackpotOptIn(user_ext_id, payload) {
1694
+ const message = this.buildMessage(user_ext_id, ClassId.JP_OPTIN_REQUEST, payload);
1695
+ return await this.send(message, ClassId.JP_OPTIN_RESPONSE);
1696
+ }
1697
+ async jackpotOptOut(user_ext_id, payload) {
1698
+ const message = this.buildMessage(user_ext_id, ClassId.JP_OPTOUT_REQUEST, payload);
1699
+ return await this.send(message, ClassId.JP_OPTOUT_RESPONSE);
1700
+ }
1616
1701
  async sawGetTemplates(user_ext_id, lang, is_visitor_mode = false) {
1617
1702
  const message = this.buildMessage(user_ext_id, ClassId.SAW_GET_SPINS_REQUEST, lang ? {
1618
1703
  force_language: lang,