@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.
@@ -713,6 +713,13 @@ class NodeCache {
713
713
  delete this.cache[key];
714
714
  }
715
715
  }
716
+ removeByPrefix(prefix) {
717
+ for (const key in this.cache) {
718
+ if (this.cache.hasOwnProperty(key) && key.indexOf(prefix) === 0) {
719
+ delete this.cache[key];
720
+ }
721
+ }
722
+ }
716
723
  flushAll() {
717
724
  this.cache = {};
718
725
  if (this.ttlChecker) {
@@ -762,6 +769,21 @@ class OCache {
762
769
  this.cache[cacheContext].remove(key);
763
770
  }
764
771
  }
772
+ /**
773
+ * Remove every entry whose string key starts with `oKeyBase` — the bare key
774
+ * AND all per-parameter composite variants (`${oKeyBase}:…` / `${oKeyBase}<id>`).
775
+ * Use when a cache is keyed per parameter (paginated, per-template, per-window):
776
+ * an exact-key `clear(oKeyBase)` would miss every variant. `oKeyBase` must be a string.
777
+ */
778
+ static async clearByPrefix(cacheContext, oKeyBase) {
779
+ // `set`/`get` build keys as `<context>_<JSON.stringify(oKey)>`; JSON.stringify
780
+ // wraps a string in quotes, so dropping the trailing quote yields a prefix that
781
+ // matches both the bare `"base"` key and every `"base…"` composite key.
782
+ const prefix = cacheContext.toString() + '_' + JSON.stringify(oKeyBase).slice(0, -1);
783
+ if (this.cache[cacheContext]) {
784
+ this.cache[cacheContext].removeByPrefix(prefix);
785
+ }
786
+ }
765
787
  static async clearContext(cacheContext) {
766
788
  if (this.cache[cacheContext]) {
767
789
  this.cache[cacheContext].flushAll();
@@ -2426,6 +2448,12 @@ const raffleClaimPrizeResponseTransform = info => {
2426
2448
 
2427
2449
  /** @group User */
2428
2450
  class WSAPIUser extends WSAPIBase {
2451
+ constructor(...args) {
2452
+ super(...args);
2453
+ /** @hidden Last window passed to `getActivityLog` with an `onUpdate`, so a push
2454
+ * refresh re-fetches the same window and updates its matching composite cache key. */
2455
+ this.activityLogOnUpdateParams = void 0;
2456
+ }
2429
2457
  /**
2430
2458
  * Returns the current user's public profile — the source of truth for
2431
2459
  * balances (points / gems / diamonds), the current level ID, the
@@ -2982,16 +3010,33 @@ class WSAPIUser extends WSAPIBase {
2982
3010
  to,
2983
3011
  onUpdate
2984
3012
  }) {
3013
+ const cacheKey = `${onUpdateContextKey.ActivityLog}:${startTimeSeconds}:${endTimeSeconds}:${from}:${to}`;
2985
3014
  if (typeof onUpdate === 'function') {
2986
3015
  this.onUpdateCallback.set(onUpdateContextKey.ActivityLog, onUpdate);
3016
+ // Remember the requested window so a push refresh re-fetches THIS window
3017
+ // and writes the matching composite cache key (see notifyActivityLogUpdate).
3018
+ this.activityLogOnUpdateParams = {
3019
+ startTimeSeconds,
3020
+ endTimeSeconds,
3021
+ from,
3022
+ to
3023
+ };
2987
3024
  }
2988
- return await OCache.use(onUpdateContextKey.ActivityLog, ECacheContext.WSAPI, () => this.api.getActivityLogT(this.userExtId, startTimeSeconds, endTimeSeconds, from, to), CACHE_DATA_SEC);
3025
+ return await OCache.use(cacheKey, ECacheContext.WSAPI, () => this.api.getActivityLogT(this.userExtId, startTimeSeconds, endTimeSeconds, from, to), CACHE_DATA_SEC);
2989
3026
  }
2990
3027
  async notifyActivityLogUpdate() {
2991
- const startSeconds = Date.now() / 1000 - 600;
2992
- const endSeconds = Date.now() / 1000;
2993
- const payload = await this.api.getActivityLogT(this.userExtId, startSeconds, endSeconds, 0, 50);
2994
- this.updateEntity(onUpdateContextKey.ActivityLog, payload);
3028
+ const params = this.activityLogOnUpdateParams;
3029
+ // No consumer has subscribed to a specific window yet — nothing to refresh.
3030
+ if (!params) {
3031
+ return;
3032
+ }
3033
+ const payload = await this.api.getActivityLogT(this.userExtId, params.startTimeSeconds, params.endTimeSeconds, params.from, params.to);
3034
+ const cacheKey = `${onUpdateContextKey.ActivityLog}:${params.startTimeSeconds}:${params.endTimeSeconds}:${params.from}:${params.to}`;
3035
+ OCache.set(cacheKey, payload, ECacheContext.WSAPI);
3036
+ const onUpdate = this.onUpdateCallback.get(onUpdateContextKey.ActivityLog);
3037
+ if (typeof onUpdate === 'function') {
3038
+ onUpdate(payload);
3039
+ }
2995
3040
  }
2996
3041
  }
2997
3042
 
@@ -5610,7 +5655,10 @@ class WSAPIJackpots extends WSAPIClans {
5610
5655
  async jackpotClearCache() {
5611
5656
  OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Jackpots);
5612
5657
  OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Pots);
5613
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.JackpotWinners);
5658
+ // Winners + eligible-games are cached per jp_template_id (composite keys),
5659
+ // so a bare clear misses every variant — clear by prefix.
5660
+ OCache.clearByPrefix(ECacheContext.WSAPI, onUpdateContextKey.JackpotWinners);
5661
+ OCache.clearByPrefix(ECacheContext.WSAPI, onUpdateContextKey.JackpotEligibleGames);
5614
5662
  }
5615
5663
  /**
5616
5664
  * Returns the user-eligible jackpots active for the label, fused with their live
@@ -6846,7 +6894,7 @@ class WSAPIMiniGames extends WSAPIRaffles {
6846
6894
  offset,
6847
6895
  saw_template_id
6848
6896
  }) {
6849
- return OCache.use(onUpdateContextKey.SAWHistory, ECacheContext.WSAPI, () => this.api.getSawWinningHistoryT(this.userExtId, limit, offset, saw_template_id), CACHE_DATA_SEC);
6897
+ return OCache.use(`${onUpdateContextKey.SAWHistory}:${saw_template_id != null ? saw_template_id : ''}:${limit != null ? limit : ''}:${offset != null ? offset : ''}`, ECacheContext.WSAPI, () => this.api.getSawWinningHistoryT(this.userExtId, limit, offset, saw_template_id), CACHE_DATA_SEC);
6850
6898
  }
6851
6899
  /**
6852
6900
  * Plays one round of a mini-game template — runs the server's
@@ -9243,11 +9291,11 @@ class WSAPI extends WSAPIInbox {
9243
9291
  on(ClassId.SAW_SHOW_SPIN_PUSH, () => this.reloadMiniGameTemplate());
9244
9292
  on(ClassId.SAW_AKNOWLEDGE_RESPONSE, () => {
9245
9293
  this.reloadMiniGameTemplate();
9246
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9294
+ OCache.clearByPrefix(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9247
9295
  });
9248
9296
  on(ClassId.SAW_DO_SPIN_RESPONSE, () => {
9249
9297
  this.reloadMiniGameTemplate();
9250
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9298
+ OCache.clearByPrefix(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9251
9299
  });
9252
9300
  on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissions());
9253
9301
  on(ClassId.ACHIEVEMENT_CLAIM_PRIZE_RESPONSE, () => this.updateMissions());
@@ -9266,7 +9314,7 @@ class WSAPI extends WSAPIInbox {
9266
9314
  on(ClassId.CLAIM_BONUS_RESPONSE, () => this.updateBonuses());
9267
9315
  on(ClassId.SAW_DO_SPIN_BATCH_RESPONSE, () => {
9268
9316
  this.reloadMiniGameTemplate();
9269
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9317
+ OCache.clearByPrefix(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
9270
9318
  });
9271
9319
  on(ClassId.RAF_CLAIM_PRIZE_RESPONSE, () => this.updateRaffles());
9272
9320
  on(ClassId.GET_INBOX_MESSAGES_RESPONSE, res => {