@smartico/public-api 0.0.401 → 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.
- package/dist/ActivityLog/ActivityLogEntry.d.ts +2 -0
- package/dist/Avatars/AvatarCustomized.d.ts +2 -2
- package/dist/GamePick/GamePickTypes.d.ts +6 -6
- package/dist/NodeCache.d.ts +1 -0
- package/dist/OCache.d.ts +7 -0
- package/dist/WSAPI/WSAPIAvatars.d.ts +1 -1
- package/dist/WSAPI/WSAPITypes.d.ts +7 -4
- package/dist/WSAPI/WSAPIUser.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +92 -35
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +60 -12
- package/dist/index.modern.mjs.map +1 -1
- package/docs/api/classes/WSAPIAvatars.md +1 -1
- package/docs/api/interfaces/AvatarCustomized.md +2 -2
- package/docs/api/interfaces/GamePickEvent.md +4 -4
- package/docs/api/interfaces/GamePickUserInfo.md +2 -2
- package/docs/api/interfaces/GemsDiamondsLog.md +2 -0
- package/docs/api/interfaces/PointsLog.md +2 -0
- package/docs/api/interfaces/TAvatarCustomized.md +2 -2
- package/docs/api/interfaces/TInboxMessage.md +2 -1
- package/docs/api/interfaces/TMissionOrBadge.md +3 -1
- package/package.json +1 -1
- package/src/ActivityLog/ActivityLogEntry.ts +2 -0
- package/src/Avatars/AvatarCustomized.ts +2 -2
- package/src/GamePick/GamePickTypes.ts +6 -6
- package/src/Missions/UserAchievement.ts +2 -2
- package/src/NodeCache.ts +8 -0
- package/src/OCache.ts +17 -0
- package/src/Store/StoreItem.ts +1 -1
- package/src/WSAPI/WSAPI.ts +3 -3
- package/src/WSAPI/WSAPIAvatars.ts +1 -1
- package/src/WSAPI/WSAPIJackpots.ts +4 -1
- package/src/WSAPI/WSAPIMiniGames.ts +1 -1
- package/src/WSAPI/WSAPITypes.ts +7 -4
- package/src/WSAPI/WSAPIUser.ts +30 -5
- package/src/index.ts +20 -0
package/dist/index.modern.mjs
CHANGED
|
@@ -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();
|
|
@@ -1055,7 +1077,7 @@ const StoreItemTransform = items => {
|
|
|
1055
1077
|
id: r.id,
|
|
1056
1078
|
name: r.itemPublicMeta.name,
|
|
1057
1079
|
purchase_type: mapPurchaseType$1(r.itemPublicMeta.purchase_type),
|
|
1058
|
-
price: r.itemPublicMeta.price,
|
|
1080
|
+
price: Number(r.itemPublicMeta.price),
|
|
1059
1081
|
image: r.itemPublicMeta.image_url,
|
|
1060
1082
|
description: r.itemPublicMeta.description,
|
|
1061
1083
|
ribbon: r.itemPublicMeta.label_tag === 'custom' ? r.itemPublicMeta.custom_label_tag : r.itemPublicMeta.label_tag,
|
|
@@ -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(
|
|
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
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
@@ -7408,7 +7456,7 @@ class WSAPIAvatars extends WSAPIMiniGames {
|
|
|
7408
7456
|
*
|
|
7409
7457
|
* // Newest-first within each base.
|
|
7410
7458
|
* for (const list of byBase.values()) {
|
|
7411
|
-
* list.sort((a, b) => b.dt_created
|
|
7459
|
+
* list.sort((a, b) => b.dt_created - a.dt_created);
|
|
7412
7460
|
* }
|
|
7413
7461
|
*
|
|
7414
7462
|
* console.log('[smartico] AI variants by base avatar — render as a carousel under each base');
|
|
@@ -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.
|
|
9294
|
+
OCache.clearByPrefix(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
|
|
9247
9295
|
});
|
|
9248
9296
|
on(ClassId.SAW_DO_SPIN_RESPONSE, () => {
|
|
9249
9297
|
this.reloadMiniGameTemplate();
|
|
9250
|
-
OCache.
|
|
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.
|
|
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 => {
|