@smartico/public-api 0.0.402 → 0.0.403

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.
@@ -5,6 +5,7 @@ declare class NodeCache {
5
5
  get(key: string): any;
6
6
  set(key: string, value: any, ttlSeconds?: number): void;
7
7
  remove(key: string): void;
8
+ removeByPrefix(prefix: string): void;
8
9
  flushAll(): void;
9
10
  }
10
11
  export { NodeCache };
package/dist/OCache.d.ts CHANGED
@@ -10,6 +10,13 @@ export declare class OCache {
10
10
  static set(oKey: any, o: any, cacheContext: ECacheContext, ttlSeconds?: number): void;
11
11
  static use<T>(oKey: any, cacheContext: ECacheContext, f: () => Promise<T>, ttlSeconds?: number): Promise<T>;
12
12
  static clear(cacheContext: ECacheContext, oKey: any): Promise<void>;
13
+ /**
14
+ * Remove every entry whose string key starts with `oKeyBase` — the bare key
15
+ * AND all per-parameter composite variants (`${oKeyBase}:…` / `${oKeyBase}<id>`).
16
+ * Use when a cache is keyed per parameter (paginated, per-template, per-window):
17
+ * an exact-key `clear(oKeyBase)` would miss every variant. `oKeyBase` must be a string.
18
+ */
19
+ static clearByPrefix(cacheContext: ECacheContext, oKeyBase: string): Promise<void>;
13
20
  static clearContext(cacheContext: ECacheContext): Promise<void>;
14
21
  static clearAll(): Promise<void>;
15
22
  }
@@ -540,5 +540,8 @@ export declare class WSAPIUser extends WSAPIBase {
540
540
  /** Optional push callback; payload is a fixed 10-min / 50-entry refresh on every wallet change (see Subscription model). */
541
541
  onUpdate?: (data: TActivityLog[]) => void;
542
542
  }): Promise<TActivityLog[]>;
543
+ /** @hidden Last window passed to `getActivityLog` with an `onUpdate`, so a push
544
+ * refresh re-fetches the same window and updates its matching composite cache key. */
545
+ private activityLogOnUpdateParams;
543
546
  protected notifyActivityLogUpdate(): Promise<void>;
544
547
  }
package/dist/index.js CHANGED
@@ -706,6 +706,13 @@ var NodeCache = /*#__PURE__*/function () {
706
706
  delete this.cache[key];
707
707
  }
708
708
  };
709
+ _proto.removeByPrefix = function removeByPrefix(prefix) {
710
+ for (var key in this.cache) {
711
+ if (this.cache.hasOwnProperty(key) && key.indexOf(prefix) === 0) {
712
+ delete this.cache[key];
713
+ }
714
+ }
715
+ };
709
716
  _proto.flushAll = function flushAll() {
710
717
  this.cache = {};
711
718
  if (this.ttlChecker) {
@@ -778,27 +785,49 @@ var OCache = /*#__PURE__*/function () {
778
785
  } catch (e) {
779
786
  return Promise.reject(e);
780
787
  }
781
- };
782
- OCache.clearContext = function clearContext(cacheContext) {
788
+ }
789
+ /**
790
+ * Remove every entry whose string key starts with `oKeyBase` — the bare key
791
+ * AND all per-parameter composite variants (`${oKeyBase}:…` / `${oKeyBase}<id>`).
792
+ * Use when a cache is keyed per parameter (paginated, per-template, per-window):
793
+ * an exact-key `clear(oKeyBase)` would miss every variant. `oKeyBase` must be a string.
794
+ */
795
+ ;
796
+ OCache.clearByPrefix = function clearByPrefix(cacheContext, oKeyBase) {
783
797
  try {
784
798
  var _this2 = this;
799
+ // `set`/`get` build keys as `<context>_<JSON.stringify(oKey)>`; JSON.stringify
800
+ // wraps a string in quotes, so dropping the trailing quote yields a prefix that
801
+ // matches both the bare `"base"` key and every `"base…"` composite key.
802
+ var prefix = cacheContext.toString() + '_' + JSON.stringify(oKeyBase).slice(0, -1);
785
803
  if (_this2.cache[cacheContext]) {
786
- _this2.cache[cacheContext].flushAll();
804
+ _this2.cache[cacheContext].removeByPrefix(prefix);
787
805
  }
788
806
  return Promise.resolve();
789
807
  } catch (e) {
790
808
  return Promise.reject(e);
791
809
  }
792
810
  };
793
- OCache.clearAll = function clearAll() {
811
+ OCache.clearContext = function clearContext(cacheContext) {
794
812
  try {
795
813
  var _this3 = this;
796
- for (var cacheContext in _this3.cache) {
797
- if (_this3.cache.hasOwnProperty(cacheContext)) {
798
- _this3.cache[cacheContext].flushAll();
814
+ if (_this3.cache[cacheContext]) {
815
+ _this3.cache[cacheContext].flushAll();
816
+ }
817
+ return Promise.resolve();
818
+ } catch (e) {
819
+ return Promise.reject(e);
820
+ }
821
+ };
822
+ OCache.clearAll = function clearAll() {
823
+ try {
824
+ var _this4 = this;
825
+ for (var cacheContext in _this4.cache) {
826
+ if (_this4.cache.hasOwnProperty(cacheContext)) {
827
+ _this4.cache[cacheContext].flushAll();
799
828
  }
800
829
  }
801
- _this3.cache = {};
830
+ _this4.cache = {};
802
831
  return Promise.resolve();
803
832
  } catch (e) {
804
833
  return Promise.reject(e);
@@ -2461,7 +2490,15 @@ var raffleClaimPrizeResponseTransform = function raffleClaimPrizeResponseTransfo
2461
2490
  /** @group User */
2462
2491
  var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
2463
2492
  function WSAPIUser() {
2464
- return _WSAPIBase.apply(this, arguments) || this;
2493
+ var _this;
2494
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2495
+ args[_key] = arguments[_key];
2496
+ }
2497
+ _this = _WSAPIBase.call.apply(_WSAPIBase, [this].concat(args)) || this;
2498
+ /** @hidden Last window passed to `getActivityLog` with an `onUpdate`, so a push
2499
+ * refresh re-fetches the same window and updates its matching composite cache key. */
2500
+ _this.activityLogOnUpdateParams = void 0;
2501
+ return _this;
2465
2502
  }
2466
2503
  _inheritsLoose(WSAPIUser, _WSAPIBase);
2467
2504
  var _proto = WSAPIUser.prototype;
@@ -2658,8 +2695,8 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
2658
2695
  */;
2659
2696
  _proto.checkSegmentMatch = function checkSegmentMatch(segment_id) {
2660
2697
  try {
2661
- var _this = this;
2662
- return Promise.resolve(_this.api.coreCheckSegments(_this.userExtId, [segment_id])).then(function (r) {
2698
+ var _this2 = this;
2699
+ return Promise.resolve(_this2.api.coreCheckSegments(_this2.userExtId, [segment_id])).then(function (r) {
2663
2700
  if (r && r.find(function (s) {
2664
2701
  return s.segment_id === segment_id && s.is_matching;
2665
2702
  })) {
@@ -2737,8 +2774,8 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
2737
2774
  ;
2738
2775
  _proto.checkSegmentListMatch = function checkSegmentListMatch(segment_ids) {
2739
2776
  try {
2740
- var _this2 = this;
2741
- return Promise.resolve(_this2.api.coreCheckSegments(_this2.userExtId, Array.isArray(segment_ids) ? segment_ids : [segment_ids]));
2777
+ var _this3 = this;
2778
+ return Promise.resolve(_this3.api.coreCheckSegments(_this3.userExtId, Array.isArray(segment_ids) ? segment_ids : [segment_ids]));
2742
2779
  } catch (e) {
2743
2780
  return Promise.reject(e);
2744
2781
  }
@@ -2815,9 +2852,9 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
2815
2852
  ;
2816
2853
  _proto.getLevels = function getLevels() {
2817
2854
  try {
2818
- var _this3 = this;
2855
+ var _this4 = this;
2819
2856
  return Promise.resolve(OCache.use(onUpdateContextKey.Levels, exports.ECacheContext.WSAPI, function () {
2820
- return _this3.api.levelsGetT(_this3.userExtId);
2857
+ return _this4.api.levelsGetT(_this4.userExtId);
2821
2858
  }, CACHE_DATA_SEC));
2822
2859
  } catch (e) {
2823
2860
  return Promise.reject(e);
@@ -2897,9 +2934,9 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
2897
2934
  ;
2898
2935
  _proto.getCurrentLevel = function getCurrentLevel() {
2899
2936
  try {
2900
- var _this4 = this;
2937
+ var _this5 = this;
2901
2938
  return Promise.resolve(OCache.use(onUpdateContextKey.CurrentLevel, exports.ECacheContext.WSAPI, function () {
2902
- return _this4.api.getLevelCurrent(_this4.userExtId);
2939
+ return _this5.api.getLevelCurrent(_this5.userExtId);
2903
2940
  }, CACHE_DATA_SEC));
2904
2941
  } catch (e) {
2905
2942
  return Promise.reject(e);
@@ -2980,9 +3017,9 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
2980
3017
  ;
2981
3018
  _proto.getUserLevelExtraCounters = function getUserLevelExtraCounters() {
2982
3019
  try {
2983
- var _this5 = this;
3020
+ var _this6 = this;
2984
3021
  return Promise.resolve(OCache.use(onUpdateContextKey.LevelExtraCounters, exports.ECacheContext.WSAPI, function () {
2985
- return _this5.api.getUserGamificationInfoT(_this5.userExtId);
3022
+ return _this6.api.getUserGamificationInfoT(_this6.userExtId);
2986
3023
  }, CACHE_DATA_SEC));
2987
3024
  } catch (e) {
2988
3025
  return Promise.reject(e);
@@ -3060,12 +3097,21 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
3060
3097
  to = _ref.to,
3061
3098
  onUpdate = _ref.onUpdate;
3062
3099
  try {
3063
- var _this6 = this;
3100
+ var _this7 = this;
3101
+ var cacheKey = onUpdateContextKey.ActivityLog + ":" + startTimeSeconds + ":" + endTimeSeconds + ":" + from + ":" + to;
3064
3102
  if (typeof onUpdate === 'function') {
3065
- _this6.onUpdateCallback.set(onUpdateContextKey.ActivityLog, onUpdate);
3103
+ _this7.onUpdateCallback.set(onUpdateContextKey.ActivityLog, onUpdate);
3104
+ // Remember the requested window so a push refresh re-fetches THIS window
3105
+ // and writes the matching composite cache key (see notifyActivityLogUpdate).
3106
+ _this7.activityLogOnUpdateParams = {
3107
+ startTimeSeconds: startTimeSeconds,
3108
+ endTimeSeconds: endTimeSeconds,
3109
+ from: from,
3110
+ to: to
3111
+ };
3066
3112
  }
3067
- return Promise.resolve(OCache.use(onUpdateContextKey.ActivityLog, exports.ECacheContext.WSAPI, function () {
3068
- return _this6.api.getActivityLogT(_this6.userExtId, startTimeSeconds, endTimeSeconds, from, to);
3113
+ return Promise.resolve(OCache.use(cacheKey, exports.ECacheContext.WSAPI, function () {
3114
+ return _this7.api.getActivityLogT(_this7.userExtId, startTimeSeconds, endTimeSeconds, from, to);
3069
3115
  }, CACHE_DATA_SEC));
3070
3116
  } catch (e) {
3071
3117
  return Promise.reject(e);
@@ -3073,11 +3119,19 @@ var WSAPIUser = /*#__PURE__*/function (_WSAPIBase) {
3073
3119
  };
3074
3120
  _proto.notifyActivityLogUpdate = function notifyActivityLogUpdate() {
3075
3121
  try {
3076
- var _this7 = this;
3077
- var startSeconds = Date.now() / 1000 - 600;
3078
- var endSeconds = Date.now() / 1000;
3079
- return Promise.resolve(_this7.api.getActivityLogT(_this7.userExtId, startSeconds, endSeconds, 0, 50)).then(function (payload) {
3080
- _this7.updateEntity(onUpdateContextKey.ActivityLog, payload);
3122
+ var _this8 = this;
3123
+ var params = _this8.activityLogOnUpdateParams;
3124
+ // No consumer has subscribed to a specific window yet — nothing to refresh.
3125
+ if (!params) {
3126
+ return Promise.resolve();
3127
+ }
3128
+ return Promise.resolve(_this8.api.getActivityLogT(_this8.userExtId, params.startTimeSeconds, params.endTimeSeconds, params.from, params.to)).then(function (payload) {
3129
+ var cacheKey = onUpdateContextKey.ActivityLog + ":" + params.startTimeSeconds + ":" + params.endTimeSeconds + ":" + params.from + ":" + params.to;
3130
+ OCache.set(cacheKey, payload, exports.ECacheContext.WSAPI);
3131
+ var onUpdate = _this8.onUpdateCallback.get(onUpdateContextKey.ActivityLog);
3132
+ if (typeof onUpdate === 'function') {
3133
+ onUpdate(payload);
3134
+ }
3081
3135
  });
3082
3136
  } catch (e) {
3083
3137
  return Promise.reject(e);
@@ -5928,7 +5982,10 @@ var WSAPIJackpots = /*#__PURE__*/function (_WSAPIClans) {
5928
5982
  try {
5929
5983
  OCache.clear(exports.ECacheContext.WSAPI, onUpdateContextKey.Jackpots);
5930
5984
  OCache.clear(exports.ECacheContext.WSAPI, onUpdateContextKey.Pots);
5931
- OCache.clear(exports.ECacheContext.WSAPI, onUpdateContextKey.JackpotWinners);
5985
+ // Winners + eligible-games are cached per jp_template_id (composite keys),
5986
+ // so a bare clear misses every variant — clear by prefix.
5987
+ OCache.clearByPrefix(exports.ECacheContext.WSAPI, onUpdateContextKey.JackpotWinners);
5988
+ OCache.clearByPrefix(exports.ECacheContext.WSAPI, onUpdateContextKey.JackpotEligibleGames);
5932
5989
  return Promise.resolve();
5933
5990
  } catch (e) {
5934
5991
  return Promise.reject(e);
@@ -7289,7 +7346,7 @@ var WSAPIMiniGames = /*#__PURE__*/function (_WSAPIRaffles) {
7289
7346
  saw_template_id = _ref2.saw_template_id;
7290
7347
  try {
7291
7348
  var _this2 = this;
7292
- return Promise.resolve(OCache.use(onUpdateContextKey.SAWHistory, exports.ECacheContext.WSAPI, function () {
7349
+ return Promise.resolve(OCache.use(onUpdateContextKey.SAWHistory + ":" + (saw_template_id != null ? saw_template_id : '') + ":" + (limit != null ? limit : '') + ":" + (offset != null ? offset : ''), exports.ECacheContext.WSAPI, function () {
7293
7350
  return _this2.api.getSawWinningHistoryT(_this2.userExtId, limit, offset, saw_template_id);
7294
7351
  }, CACHE_DATA_SEC));
7295
7352
  } catch (e) {
@@ -9940,11 +9997,11 @@ var WSAPI = /*#__PURE__*/function (_WSAPIInbox) {
9940
9997
  });
9941
9998
  on(exports.ClassId.SAW_AKNOWLEDGE_RESPONSE, function () {
9942
9999
  _this.reloadMiniGameTemplate();
9943
- OCache.clear(exports.ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
10000
+ OCache.clearByPrefix(exports.ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9944
10001
  });
9945
10002
  on(exports.ClassId.SAW_DO_SPIN_RESPONSE, function () {
9946
10003
  _this.reloadMiniGameTemplate();
9947
- OCache.clear(exports.ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
10004
+ OCache.clearByPrefix(exports.ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9948
10005
  });
9949
10006
  on(exports.ClassId.MISSION_OPTIN_RESPONSE, function () {
9950
10007
  return _this.updateMissions();
@@ -9985,7 +10042,7 @@ var WSAPI = /*#__PURE__*/function (_WSAPIInbox) {
9985
10042
  });
9986
10043
  on(exports.ClassId.SAW_DO_SPIN_BATCH_RESPONSE, function () {
9987
10044
  _this.reloadMiniGameTemplate();
9988
- OCache.clear(exports.ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
10045
+ OCache.clearByPrefix(exports.ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9989
10046
  });
9990
10047
  on(exports.ClassId.RAF_CLAIM_PRIZE_RESPONSE, function () {
9991
10048
  return _this.updateRaffles();