@smartico/public-api 0.0.379 → 0.0.380
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/.nvmrc +1 -1
- package/README.md +31 -2
- package/dist/Store/BuyStoreItemErrorCode.d.ts +9 -1
- package/dist/Tournaments/TournamentRegistrationError.d.ts +3 -1
- package/dist/WSAPI/WSAPI.d.ts +13 -1235
- package/dist/WSAPI/WSAPIAvatars.d.ts +78 -0
- package/dist/WSAPI/WSAPIBase.d.ts +71 -0
- package/dist/WSAPI/WSAPIBonuses.d.ts +26 -0
- package/dist/WSAPI/WSAPIClans.d.ts +388 -0
- package/dist/WSAPI/WSAPIGamePick.d.ts +308 -0
- package/dist/WSAPI/WSAPIGeneral.d.ts +30 -0
- package/dist/WSAPI/WSAPIInbox.d.ts +126 -0
- package/dist/WSAPI/WSAPIJackpots.d.ts +109 -0
- package/dist/WSAPI/WSAPILeaderBoard.d.ts +25 -0
- package/dist/WSAPI/WSAPIMiniGames.d.ts +94 -0
- package/dist/WSAPI/WSAPIMissions.d.ts +517 -0
- package/dist/WSAPI/WSAPIRaffles.d.ts +119 -0
- package/dist/WSAPI/WSAPIStore.d.ts +656 -0
- package/dist/WSAPI/WSAPITournaments.d.ts +501 -0
- package/dist/WSAPI/WSAPITypes.d.ts +145 -85
- package/dist/WSAPI/WSAPIUser.d.ts +383 -0
- package/dist/index.js +3818 -1528
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +3180 -981
- package/dist/index.modern.mjs.map +1 -1
- package/docs/api/README.md +56 -2
- package/docs/api/classes/WSAPIAvatars.md +116 -0
- package/docs/api/classes/WSAPIBonuses.md +50 -0
- package/docs/api/classes/WSAPIClans.md +66 -0
- package/docs/api/classes/WSAPIGamePick.md +181 -0
- package/docs/api/classes/WSAPIGeneral.md +63 -0
- package/docs/api/classes/WSAPIInbox.md +277 -0
- package/docs/api/classes/WSAPIJackpots.md +185 -0
- package/docs/api/classes/WSAPILeaderBoard.md +39 -0
- package/docs/api/classes/WSAPIMiniGames.md +175 -0
- package/docs/api/classes/WSAPIMissions.md +611 -0
- package/docs/api/classes/WSAPIRaffles.md +195 -0
- package/docs/api/classes/WSAPIStore.md +744 -0
- package/docs/api/classes/WSAPITournaments.md +104 -0
- package/docs/api/classes/WSAPIUser.md +200 -0
- package/docs/api/enumerations/AchievementClaimPeriodTypeId.md +13 -0
- package/docs/api/enumerations/BuyStoreItemErrorCode.md +32 -0
- package/docs/api/interfaces/ClanPrizePublicMeta.md +41 -0
- package/docs/api/interfaces/ClanPrizeStructureEntry.md +7 -1
- package/docs/api/interfaces/ClanPublicMeta.md +4 -0
- package/docs/api/interfaces/SAWTemplateUI.md +10 -0
- package/docs/api/interfaces/TAchCategory.md +19 -4
- package/docs/api/interfaces/TBuyStoreItemResult.md +26 -8
- package/docs/api/interfaces/TMissionClaimRewardResult.md +14 -3
- package/docs/api/interfaces/TMissionOptInResult.md +10 -3
- package/docs/api/interfaces/TMissionOrBadge.md +6 -2
- package/docs/api/interfaces/TStoreItem.md +21 -1
- package/docs/api/interfaces/TTournamentDetailed.md +8 -0
- package/docs/api/interfaces/UserAchievement.md +1 -1
- package/docs/ui/clans/UIGuide_getClanInfo.md +153 -0
- package/docs/ui/clans/UIGuide_getClans.md +172 -0
- package/docs/ui/clans/UIGuide_joinClan.md +196 -0
- package/docs/ui/missions/UIGuide_getAchCategories.md +17 -0
- package/docs/ui/missions/UIGuide_getBadges.md +237 -0
- package/docs/ui/missions/UIGuide_getMissions.md +268 -0
- package/docs/ui/missions/UIGuide_requestMissionClaimReward.md +21 -0
- package/docs/ui/missions/UIGuide_requestMissionOptIn.md +16 -0
- package/docs/ui/store/UIGuide_buyStoreItem.md +133 -0
- package/docs/ui/store/UIGuide_getStoreCategories.md +19 -0
- package/docs/ui/store/UIGuide_getStoreItems.md +264 -0
- package/docs/ui/store/UIGuide_getStorePurchasedItems.md +122 -0
- package/docs/ui/tournaments/UIGuide_getClanTournamentPlayers.md +140 -0
- package/docs/ui/tournaments/UIGuide_getTournamentInstanceInfo.md +265 -0
- package/docs/ui/tournaments/UIGuide_getTournamentsList.md +236 -0
- package/docs/ui/tournaments/UIGuide_registerInTournament.md +156 -0
- package/docs/ui/user/UIGuide_getLevels.md +162 -0
- package/docs/ui/user/UIGuide_getUserProfile.md +213 -0
- package/package.json +3 -3
- package/scripts/postdoc-cleanup.js +195 -0
- package/src/Missions/MissionsUtils.ts +5 -2
- package/src/Store/BuyStoreItemErrorCode.ts +8 -0
- package/src/Store/StoreItem.ts +1 -0
- package/src/Store/StoreItemPurchased.ts +1 -0
- package/src/Store/StoreItemType.ts +1 -1
- package/src/Tournaments/TournamentRegistrationError.ts +4 -0
- package/src/WSAPI/WSAPI.ts +27 -2007
- package/src/WSAPI/WSAPIAvatars.ts +127 -0
- package/src/WSAPI/WSAPIBase.ts +93 -0
- package/src/WSAPI/WSAPIBonuses.ts +54 -0
- package/src/WSAPI/WSAPIClans.ts +417 -0
- package/src/WSAPI/WSAPIGamePick.ts +382 -0
- package/src/WSAPI/WSAPIGeneral.ts +57 -0
- package/src/WSAPI/WSAPIInbox.ts +222 -0
- package/src/WSAPI/WSAPIJackpots.ts +212 -0
- package/src/WSAPI/WSAPILeaderBoard.ts +40 -0
- package/src/WSAPI/WSAPIMiniGames.ts +181 -0
- package/src/WSAPI/WSAPIMissions.ts +572 -0
- package/src/WSAPI/WSAPIRaffles.ts +175 -0
- package/src/WSAPI/WSAPIStore.ts +732 -0
- package/src/WSAPI/WSAPITournaments.ts +541 -0
- package/src/WSAPI/WSAPITypes.ts +145 -87
- package/src/WSAPI/WSAPIUser.ts +456 -0
- package/tsconfig.json +17 -1
- package/docs/api/classes/WSAPI.md +0 -1927
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { CoreUtils } from '../Core';
|
|
2
|
+
import { ECacheContext, OCache } from '../OCache';
|
|
3
|
+
import {
|
|
4
|
+
TActivityLog,
|
|
5
|
+
TLevel,
|
|
6
|
+
TLevelCurrent,
|
|
7
|
+
TSegmentCheckResult,
|
|
8
|
+
TUserProfile,
|
|
9
|
+
UserLevelExtraCountersT,
|
|
10
|
+
} from './WSAPITypes';
|
|
11
|
+
import {
|
|
12
|
+
CACHE_DATA_SEC,
|
|
13
|
+
onUpdateContextKey,
|
|
14
|
+
} from './WSAPIBase';
|
|
15
|
+
import { WSAPIBase } from './WSAPIBase';
|
|
16
|
+
|
|
17
|
+
/** @group User */
|
|
18
|
+
export class WSAPIUser extends WSAPIBase {
|
|
19
|
+
/**
|
|
20
|
+
* Returns the current user's public profile — the source of truth for
|
|
21
|
+
* balances (points / gems / diamonds), the current level ID, the
|
|
22
|
+
* display username + avatar, language, public tags, and the inbox
|
|
23
|
+
* unread count. **This method is synchronous** (returns `TUserProfile`,
|
|
24
|
+
* not a Promise): the SDK keeps a local snapshot of the user's public
|
|
25
|
+
* properties that is initialised at identify time and kept live by a
|
|
26
|
+
* server-driven update channel — every call returns the latest cached
|
|
27
|
+
* values without a network round-trip.
|
|
28
|
+
*
|
|
29
|
+
* Subscribe to changes by registering a callback on `_smartico.on('props_change', ...)`
|
|
30
|
+
* — the callback fires with the full snapshot at identify and with
|
|
31
|
+
* partial-key updates on every subsequent server push (typically
|
|
32
|
+
* under 1 second after the underlying state change).
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* **Preconditions**
|
|
36
|
+
* The tracker must be initialised — calling this before the identify
|
|
37
|
+
* round-trip completes throws (`"Tracker is not initialized, cannot
|
|
38
|
+
* getUserProfile"`). Safe ways to wait for readiness:
|
|
39
|
+
* - register `_smartico.on('identify', (errCode, props) => ...)` —
|
|
40
|
+
* fires once after a successful identify with the full props
|
|
41
|
+
* - register `_smartico.on('props_change', () => ...)` — fires first
|
|
42
|
+
* at identify with the full snapshot, then on every push update
|
|
43
|
+
*
|
|
44
|
+
* **What's kept live (push-updated)**
|
|
45
|
+
* Balance fields (`ach_points_balance`, `ach_gems_balance`,
|
|
46
|
+
* `ach_diamonds_balance`, `ach_points_ever`), `ach_level_current_id`,
|
|
47
|
+
* `core_public_tags`, `core_inbox_unread_count`, `core_user_language`,
|
|
48
|
+
* `avatar_url`, `public_username`, and the AI-driven recommended-amount
|
|
49
|
+
* fields all flow over the SDK's user-properties update channel as
|
|
50
|
+
* partial updates — the snapshot is patched in place when any of them
|
|
51
|
+
* change server-side. Re-call `getUserProfile()` (or watch
|
|
52
|
+
* `props_change`) to observe new values.
|
|
53
|
+
*
|
|
54
|
+
* **Reading state from the returned profile**
|
|
55
|
+
* Balances (`ach_points_balance`, `ach_gems_balance`,
|
|
56
|
+
* `ach_diamonds_balance`) are the canonical source for affordability
|
|
57
|
+
* checks across the SDK — compare against `entry_fee_amount` (clans),
|
|
58
|
+
* `registration_cost_points` / `_gems` / `_diamonds` (tournaments), and
|
|
59
|
+
* `price` / `discounted_price` + `purchase_type` (store items).
|
|
60
|
+
* `ach_points_ever` is monotonic — store purchases deduct from
|
|
61
|
+
* `ach_points_balance` but NEVER from `ach_points_ever`, so it remains
|
|
62
|
+
* useful for level-progress math (`required_points` on the next
|
|
63
|
+
* {@link getLevels} entry minus `ach_points_ever`). `ach_level_current_id`
|
|
64
|
+
* is the FK into the level ladder — resolve metadata via
|
|
65
|
+
* {@link getCurrentLevel} (richer, includes progress %) or
|
|
66
|
+
* {@link getLevels} (full ladder lookup table).
|
|
67
|
+
*
|
|
68
|
+
* **Inbox unread count** — `core_inbox_unread_count` on this profile
|
|
69
|
+
* is push-updated in real time (under 1 second). For an inbox badge,
|
|
70
|
+
* prefer this field over {@link getInboxUnreadCount} (which is cached
|
|
71
|
+
* for 30 s) — same value, fresher signal.
|
|
72
|
+
*
|
|
73
|
+
* **Language**: `core_user_language` reflects the server's stored
|
|
74
|
+
* language. If the consumer just called `_smartico.changeLanguage(...)`,
|
|
75
|
+
* the field may briefly lag the local intent until the server push
|
|
76
|
+
* arrives. Use `_smartico.getPublicProps()` for the
|
|
77
|
+
* client-fallback-applied version if instant accuracy matters.
|
|
78
|
+
*
|
|
79
|
+
* **Idempotency / Side effects**: trivially safe — no network call,
|
|
80
|
+
* no state mutation.
|
|
81
|
+
*
|
|
82
|
+
* **UI guidance**: see [UI Guide — `getUserProfile`](../../docs/ui/user/UIGuide_getUserProfile.md).
|
|
83
|
+
*
|
|
84
|
+
* **Visitor mode**: not supported — throws. Visitor sessions do not
|
|
85
|
+
* have a public-profile snapshot.
|
|
86
|
+
*
|
|
87
|
+
* @returns The current cached `TUserProfile` snapshot. A shallow copy —
|
|
88
|
+
* mutating it does not affect the SDK's internal state.
|
|
89
|
+
* @throws `Error("Tracker is not initialized, cannot getUserProfile")`
|
|
90
|
+
* if called before identify completes or from a visitor session.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Wait for identify before calling.
|
|
95
|
+
* window._smartico.on('identify', (errCode) => {
|
|
96
|
+
* if (errCode !== 0) return;
|
|
97
|
+
* const profile = window._smartico.api.getUserProfile();
|
|
98
|
+
* console.log('[smartico] initial profile loaded — render the user widget:', profile);
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* // Stay in sync with live updates.
|
|
102
|
+
* window._smartico.on('props_change', (changed) => {
|
|
103
|
+
* // `changed` is the partial keys for this push (full snapshot at identify).
|
|
104
|
+
* const profile = window._smartico.api.getUserProfile();
|
|
105
|
+
* console.log('[smartico] profile updated — re-render any widgets bound to:', Object.keys(changed),
|
|
106
|
+
* '— balances now:', profile.ach_points_balance, profile.ach_gems_balance, profile.ach_diamonds_balance);
|
|
107
|
+
*
|
|
108
|
+
* // React to specific fields.
|
|
109
|
+
* if ('ach_level_current_id' in changed) {
|
|
110
|
+
* console.log('[smartico] level changed — call getCurrentLevel() for richer detail, animate the level badge');
|
|
111
|
+
* }
|
|
112
|
+
* if ('core_inbox_unread_count' in changed) {
|
|
113
|
+
* console.log('[smartico] inbox unread count changed — update the badge to:', profile.core_inbox_unread_count);
|
|
114
|
+
* }
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // Affordability gating example — used inside a clan / tournament / store CTA handler.
|
|
118
|
+
* const profile = window._smartico.api.getUserProfile();
|
|
119
|
+
* const item = await window._smartico.api.getStoreItems().then(items => items[0]);
|
|
120
|
+
* const price = item.discounted_price ?? item.price;
|
|
121
|
+
* const balance = {
|
|
122
|
+
* points: profile.ach_points_balance,
|
|
123
|
+
* gems: profile.ach_gems_balance,
|
|
124
|
+
* diamonds: profile.ach_diamonds_balance,
|
|
125
|
+
* }[item.purchase_type];
|
|
126
|
+
* if (balance < price) {
|
|
127
|
+
* console.log('[smartico] insufficient', item.purchase_type, '— disable Buy and show deficit', price - balance);
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
public getUserProfile(): TUserProfile {
|
|
132
|
+
if (this.api.tracker) {
|
|
133
|
+
const o: TUserProfile = Object.assign({}, this.api.tracker.userPublicProps);
|
|
134
|
+
o.avatar_url = CoreUtils.avatarUrl(this.api.tracker.userPublicProps.avatar_id, this.api.avatarDomain);
|
|
135
|
+
return o;
|
|
136
|
+
} else {
|
|
137
|
+
throw new Error('Tracker is not initialized, cannot getUserProfile');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Check if user belongs to specific segments
|
|
142
|
+
* **Example**:
|
|
143
|
+
* ```
|
|
144
|
+
* _smartico.api.checkSegmentMatch(1).then((result) => {
|
|
145
|
+
* console.log(result);
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* **Visitor mode: not supported**
|
|
150
|
+
*/
|
|
151
|
+
public async checkSegmentMatch(segment_id: number): Promise<boolean> {
|
|
152
|
+
const r = await this.api.coreCheckSegments(this.userExtId, [segment_id]);
|
|
153
|
+
if (r && r.find((s) => s.segment_id === segment_id && s.is_matching)) {
|
|
154
|
+
return true;
|
|
155
|
+
} else {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Check if user belongs to specific list of segments
|
|
161
|
+
* **Example**:
|
|
162
|
+
* ```
|
|
163
|
+
* _smartico.api.checkSegmentListMatch([1, 2, 3]).then((result) => {
|
|
164
|
+
* console.log(result);
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
* **Visitor mode: not supported**
|
|
168
|
+
*/
|
|
169
|
+
public async checkSegmentListMatch(segment_ids: number[]): Promise<TSegmentCheckResult[]> {
|
|
170
|
+
return await this.api.coreCheckSegments(this.userExtId, Array.isArray(segment_ids) ? segment_ids : [segment_ids]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns the full level ladder configured for the current label —
|
|
175
|
+
* one `TLevel` per active level, server-sorted by `required_points`
|
|
176
|
+
* ASC (lowest first; `ordinal_position` is a 1-based index into the
|
|
177
|
+
* returned array). Use this to render a level map / progression
|
|
178
|
+
* screen, or as a lookup table to resolve `ach_level_current_id` from
|
|
179
|
+
* {@link getUserProfile} into a richer level object.
|
|
180
|
+
*
|
|
181
|
+
* @remarks
|
|
182
|
+
* **Server-side filtering**
|
|
183
|
+
* The server returns ALL active levels for the label. There is NO
|
|
184
|
+
* per-user filtering on visibility, level-status, or anything else —
|
|
185
|
+
* the response is identical across users of the same label. Apply
|
|
186
|
+
* `visibility_points` filtering client-side if you want to hide
|
|
187
|
+
* not-yet-reached levels (compare against
|
|
188
|
+
* `getUserProfile().ach_points_ever` and exclude levels where
|
|
189
|
+
* `visibility_points > ach_points_ever`).
|
|
190
|
+
*
|
|
191
|
+
* **Sort order**
|
|
192
|
+
* The returned array is already sorted by `required_points` ASC, and
|
|
193
|
+
* `ordinal_position` is a 1-based index into that same sort order —
|
|
194
|
+
* client-side re-sorting is not required for the default rendering.
|
|
195
|
+
* If your label uses sliding-window leveling logic
|
|
196
|
+
* (see {@link getUserLevelExtraCounters}) and you want to sort by
|
|
197
|
+
* a multi-criteria key (`required_points`, then
|
|
198
|
+
* `required_level_counter_1`, then `required_level_counter_2`), do
|
|
199
|
+
* that client-side.
|
|
200
|
+
*
|
|
201
|
+
* **Cache TTL**: the SDK caches the response for 30 seconds. Cache
|
|
202
|
+
* is fully cleared on login / logout. Operator-driven level edits
|
|
203
|
+
* surface on the next cache miss.
|
|
204
|
+
*
|
|
205
|
+
* **Idempotency / Side effects**: safe. Read-only metadata. Calls
|
|
206
|
+
* within the cache window de-duplicate to the same cached array.
|
|
207
|
+
*
|
|
208
|
+
* **UI guidance**: see [UI Guide — `getLevels`](../../docs/ui/user/UIGuide_getLevels.md).
|
|
209
|
+
*
|
|
210
|
+
* **Visitor mode**: supported. Use `_smartico.vapi(lang).getLevels()`
|
|
211
|
+
* to fetch the ladder for anonymous viewers; the level configuration
|
|
212
|
+
* is label-scoped static data so the response is meaningful even
|
|
213
|
+
* without an authenticated user. Per-user fields (the implicit
|
|
214
|
+
* "current level" via {@link getCurrentLevel}, or the user's progress)
|
|
215
|
+
* are not available in visitor mode.
|
|
216
|
+
*
|
|
217
|
+
* @returns Promise resolving to the ordered `TLevel[]` ladder. Empty
|
|
218
|
+
* if no levels are configured for the label.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* const [levels, profile] = await Promise.all([
|
|
223
|
+
* window._smartico.api.getLevels(),
|
|
224
|
+
* Promise.resolve(window._smartico.api.getUserProfile()),
|
|
225
|
+
* ]);
|
|
226
|
+
*
|
|
227
|
+
* // Resolve the user's current level by ID.
|
|
228
|
+
* const current = levels.find(l => l.id === profile.ach_level_current_id);
|
|
229
|
+
* console.log('[smartico] render header badge — current level:', current?.name,
|
|
230
|
+
* '(position', current?.ordinal_position, 'of', levels.length, ')');
|
|
231
|
+
*
|
|
232
|
+
* // Filter to levels the user has unlocked enough to see.
|
|
233
|
+
* const visible = levels.filter(l =>
|
|
234
|
+
* l.visibility_points == null || l.visibility_points <= profile.ach_points_ever
|
|
235
|
+
* );
|
|
236
|
+
* console.log('[smartico] render the level map with', visible.length, 'visible tiles');
|
|
237
|
+
*
|
|
238
|
+
* // Visitor-mode equivalent: returns the same ladder; no per-user state.
|
|
239
|
+
* // const visitorLevels = await window._smartico.vapi('EN').getLevels();
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
public async getLevels(): Promise<TLevel[]> {
|
|
243
|
+
return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(this.userExtId), CACHE_DATA_SEC);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Returns the user's current level — every `TLevel` field plus a
|
|
248
|
+
* computed `progress` percentage toward the next level. Use this to
|
|
249
|
+
* power a level badge with a progress bar.
|
|
250
|
+
*
|
|
251
|
+
* @remarks
|
|
252
|
+
* **How `progress` is computed**
|
|
253
|
+
* The SDK derives `progress` as the *delta-from-current-level-floor*:
|
|
254
|
+
* `(ach_points_ever − current.required_points) / (next.required_points
|
|
255
|
+
* − current.required_points) × 100`, clamped to `[0, 100]`. At the
|
|
256
|
+
* highest level (no next level), `progress` is `100`. Reading the
|
|
257
|
+
* source values directly from {@link getUserProfile}'s
|
|
258
|
+
* `ach_points_ever` and {@link getLevels} would also work, but
|
|
259
|
+
* `progress` saves the math.
|
|
260
|
+
*
|
|
261
|
+
* **Cache TTL**: the SDK caches the response for 30 seconds. There is
|
|
262
|
+
* no push event that refreshes this cache; a server-side level change
|
|
263
|
+
* (visible immediately on {@link getUserProfile}'s `ach_level_current_id`
|
|
264
|
+
* via the user-properties update channel) becomes visible on this
|
|
265
|
+
* method only after the cache TTL expires, or after
|
|
266
|
+
* `_smartico.api.clearCaches()` is called.
|
|
267
|
+
*
|
|
268
|
+
* **Leveling logic**
|
|
269
|
+
* The semantics of how a user advances depends on the label's
|
|
270
|
+
* leveling logic (configured per brand): points-only (the default),
|
|
271
|
+
* sliding-window with extra counters (uses
|
|
272
|
+
* {@link getUserLevelExtraCounters}), or fully-manual operator
|
|
273
|
+
* assignment. The `progress` percentage on this method assumes the
|
|
274
|
+
* points-only model — it's not meaningful for manual-only labels
|
|
275
|
+
* where level changes are operator-driven rather than points-driven.
|
|
276
|
+
*
|
|
277
|
+
* **Idempotency**: safe. Read-only. Repeated calls within the cache
|
|
278
|
+
* window return a deep-cloned cached value without a network
|
|
279
|
+
* round-trip.
|
|
280
|
+
*
|
|
281
|
+
* **Side effects**: none — pure read.
|
|
282
|
+
*
|
|
283
|
+
* **Visitor mode**: not supported.
|
|
284
|
+
*
|
|
285
|
+
* @returns Promise resolving to `TLevelCurrent` — the current level
|
|
286
|
+
* plus `progress: number` (0–100).
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* const level = await window._smartico.api.getCurrentLevel();
|
|
291
|
+
* console.log('[smartico] render level badge — name:', level.name,
|
|
292
|
+
* 'progress:', Math.round(level.progress), '%');
|
|
293
|
+
*
|
|
294
|
+
* // Detect level-up via getUserProfile's push channel.
|
|
295
|
+
* window._smartico.on('props_change', async (changed) => {
|
|
296
|
+
* if ('ach_level_current_id' in changed) {
|
|
297
|
+
* await window._smartico.api.clearCaches(); // bust the 30 s cache
|
|
298
|
+
* const fresh = await window._smartico.api.getCurrentLevel();
|
|
299
|
+
* console.log('[smartico] user levelled up — animate badge to new level:', fresh.name);
|
|
300
|
+
* }
|
|
301
|
+
* });
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
public async getCurrentLevel(): Promise<TLevelCurrent> {
|
|
305
|
+
return OCache.use(onUpdateContextKey.CurrentLevel, ECacheContext.WSAPI, () => this.api.getLevelCurrent(this.userExtId), CACHE_DATA_SEC);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Returns the user's current values for the two label-defined "extra
|
|
310
|
+
* counters" used by sliding-window leveling logic. Operators
|
|
311
|
+
* configure what each counter means per label (e.g. `level_counter_1`
|
|
312
|
+
* = total deposits in the last 30 days, `level_counter_2` = total
|
|
313
|
+
* wagering in the last 30 days). Compare against
|
|
314
|
+
* `required_level_counter_1` / `_2` on the next level from
|
|
315
|
+
* {@link getLevels} to know how close the user is to advancing.
|
|
316
|
+
*
|
|
317
|
+
* @remarks
|
|
318
|
+
* **When this matters**
|
|
319
|
+
* Only labels configured for sliding-window leveling populate the
|
|
320
|
+
* counter fields. On the default points-only leveling model, both
|
|
321
|
+
* `level_counter_1` and `level_counter_2` are `undefined`. Detect
|
|
322
|
+
* a points-only label by either counter being `undefined`.
|
|
323
|
+
*
|
|
324
|
+
* **Counter semantics — operator-defined**
|
|
325
|
+
* The SDK exposes raw numeric values; the meaning of each counter
|
|
326
|
+
* (deposit amount, wager amount, lifetime spend, etc.) is fully
|
|
327
|
+
* operator-defined per label. Resolve labels for display via
|
|
328
|
+
* {@link getTranslations} — the operator's display strings are
|
|
329
|
+
* stored under the translation keys `levelsCounter1Name` and
|
|
330
|
+
* `levelsCounter2Name`.
|
|
331
|
+
*
|
|
332
|
+
* **Refresh cadence**
|
|
333
|
+
* Sliding-window counters are recomputed by a server-side job that
|
|
334
|
+
* runs roughly every 60 seconds against the operator's BigQuery
|
|
335
|
+
* dataset; level transitions driven by counter changes have a
|
|
336
|
+
* latency of up to several minutes after the underlying activity
|
|
337
|
+
* (e.g. a deposit). The SDK caches the response for 30 seconds; no
|
|
338
|
+
* push event refreshes this cache. After a level change visible on
|
|
339
|
+
* {@link getUserProfile}'s `ach_level_current_id`, call
|
|
340
|
+
* `_smartico.api.clearCaches()` to force a fresh fetch.
|
|
341
|
+
*
|
|
342
|
+
* **Idempotency**: safe. Read-only. Repeated calls within the cache
|
|
343
|
+
* window return a deep-cloned cached value without a network
|
|
344
|
+
* round-trip.
|
|
345
|
+
*
|
|
346
|
+
* **Side effects**: none — pure read.
|
|
347
|
+
*
|
|
348
|
+
* **Visitor mode**: not supported.
|
|
349
|
+
*
|
|
350
|
+
* @returns Promise resolving to `UserLevelExtraCountersT`. Both
|
|
351
|
+
* fields are `undefined` on labels not using sliding-window
|
|
352
|
+
* leveling.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const [counters, levels, profile] = await Promise.all([
|
|
357
|
+
* window._smartico.api.getUserLevelExtraCounters(),
|
|
358
|
+
* window._smartico.api.getLevels(),
|
|
359
|
+
* Promise.resolve(window._smartico.api.getUserProfile()),
|
|
360
|
+
* ]);
|
|
361
|
+
*
|
|
362
|
+
* // Quick detection: undefined means this label doesn't use sliding-window leveling.
|
|
363
|
+
* if (counters.level_counter_1 === undefined) {
|
|
364
|
+
* console.log('[smartico] points-only label — skip counter UI; show points progress only');
|
|
365
|
+
* return;
|
|
366
|
+
* }
|
|
367
|
+
*
|
|
368
|
+
* // Find the next level and render a 3-bar progress block.
|
|
369
|
+
* const currentIdx = levels.findIndex(l => l.id === profile.ach_level_current_id);
|
|
370
|
+
* const next = levels[currentIdx + 1];
|
|
371
|
+
* if (next) {
|
|
372
|
+
* console.log('[smartico] render points bar:', profile.ach_points_ever, '/', next.required_points);
|
|
373
|
+
* if (next.required_level_counter_1) {
|
|
374
|
+
* console.log('[smartico] render counter 1 bar:', counters.level_counter_1, '/', next.required_level_counter_1);
|
|
375
|
+
* }
|
|
376
|
+
* if (next.required_level_counter_2) {
|
|
377
|
+
* console.log('[smartico] render counter 2 bar:', counters.level_counter_2, '/', next.required_level_counter_2);
|
|
378
|
+
* }
|
|
379
|
+
* }
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
public async getUserLevelExtraCounters(): Promise<UserLevelExtraCountersT> {
|
|
383
|
+
return OCache.use(
|
|
384
|
+
onUpdateContextKey.LevelExtraCounters,
|
|
385
|
+
ECacheContext.WSAPI,
|
|
386
|
+
() => this.api.getUserGamificationInfoT(this.userExtId),
|
|
387
|
+
CACHE_DATA_SEC,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Returns the activity log for a user within a specified time range.
|
|
393
|
+
* The response includes both points changes and gems/diamonds changes.
|
|
394
|
+
* Each log entry contains information about the change amount, balance, and source.
|
|
395
|
+
* The returned list is cached for 30 seconds.
|
|
396
|
+
* You can pass the onUpdate callback as a parameter, it will be called every time the activity log is updated and will provide the updated list of activity logs for the last 10 minutes.
|
|
397
|
+
*
|
|
398
|
+
* **Example**:
|
|
399
|
+
* ```
|
|
400
|
+
* const startTime = Math.floor(Date.now() / 1000) - 86400 * 30; // 30 days ago
|
|
401
|
+
* const endTime = Math.floor(Date.now() / 1000); // now
|
|
402
|
+
*
|
|
403
|
+
* _smartico.api.getActivityLog({
|
|
404
|
+
* startTimeSeconds: startTime,
|
|
405
|
+
* endTimeSeconds: endTime,
|
|
406
|
+
* from: 0,
|
|
407
|
+
* to: 50,
|
|
408
|
+
* onUpdate: (data) => console.log('Updated:', data)
|
|
409
|
+
* }).then((result) => {
|
|
410
|
+
* console.log(result);
|
|
411
|
+
* });
|
|
412
|
+
* ```
|
|
413
|
+
*
|
|
414
|
+
* **Visitor mode: not supported**
|
|
415
|
+
*
|
|
416
|
+
* @param params - Activity log parameters
|
|
417
|
+
* @param params.startTimeSeconds - Start time in seconds (epoch timestamp)
|
|
418
|
+
* @param params.endTimeSeconds - End time in seconds (epoch timestamp)
|
|
419
|
+
* @param params.from - Start index of records to return
|
|
420
|
+
* @param params.to - End index of records to return
|
|
421
|
+
* @param params.onUpdate - Optional callback function that will be called when the activity log is updated
|
|
422
|
+
*/
|
|
423
|
+
public async getActivityLog({
|
|
424
|
+
startTimeSeconds,
|
|
425
|
+
endTimeSeconds,
|
|
426
|
+
from,
|
|
427
|
+
to,
|
|
428
|
+
onUpdate,
|
|
429
|
+
}: {
|
|
430
|
+
startTimeSeconds: number;
|
|
431
|
+
endTimeSeconds: number;
|
|
432
|
+
from: number;
|
|
433
|
+
to: number;
|
|
434
|
+
onUpdate?: (data: TActivityLog[]) => void;
|
|
435
|
+
}): Promise<TActivityLog[]> {
|
|
436
|
+
|
|
437
|
+
if (onUpdate) {
|
|
438
|
+
this.onUpdateCallback.set(onUpdateContextKey.ActivityLog, onUpdate);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return await OCache.use(
|
|
442
|
+
onUpdateContextKey.ActivityLog,
|
|
443
|
+
ECacheContext.WSAPI,
|
|
444
|
+
() => this.api.getActivityLogT(this.userExtId, startTimeSeconds, endTimeSeconds, from, to),
|
|
445
|
+
CACHE_DATA_SEC,
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
protected async notifyActivityLogUpdate() {
|
|
450
|
+
const startSeconds = Date.now() / 1000 - 600;
|
|
451
|
+
const endSeconds = Date.now() / 1000;
|
|
452
|
+
const payload = await this.api.getActivityLogT(this.userExtId, startSeconds, endSeconds, 0, 50);
|
|
453
|
+
|
|
454
|
+
this.updateEntity(onUpdateContextKey.ActivityLog, payload);
|
|
455
|
+
}
|
|
456
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -14,7 +14,21 @@
|
|
|
14
14
|
"typedocOptions": {
|
|
15
15
|
"name": "Smartico API documentation",
|
|
16
16
|
"entryPoints": [
|
|
17
|
-
"src/WSAPI/
|
|
17
|
+
"src/WSAPI/WSAPIBase.ts",
|
|
18
|
+
"src/WSAPI/WSAPIUser.ts",
|
|
19
|
+
"src/WSAPI/WSAPIGeneral.ts",
|
|
20
|
+
"src/WSAPI/WSAPIMissions.ts",
|
|
21
|
+
"src/WSAPI/WSAPIBonuses.ts",
|
|
22
|
+
"src/WSAPI/WSAPIStore.ts",
|
|
23
|
+
"src/WSAPI/WSAPITournaments.ts",
|
|
24
|
+
"src/WSAPI/WSAPIClans.ts",
|
|
25
|
+
"src/WSAPI/WSAPIJackpots.ts",
|
|
26
|
+
"src/WSAPI/WSAPIRaffles.ts",
|
|
27
|
+
"src/WSAPI/WSAPIMiniGames.ts",
|
|
28
|
+
"src/WSAPI/WSAPIAvatars.ts",
|
|
29
|
+
"src/WSAPI/WSAPIGamePick.ts",
|
|
30
|
+
"src/WSAPI/WSAPILeaderBoard.ts",
|
|
31
|
+
"src/WSAPI/WSAPIInbox.ts",
|
|
18
32
|
"src/WSAPI/WSAPITypes.ts",
|
|
19
33
|
"src/Tournaments/TournamentRegistrationStatus.ts",
|
|
20
34
|
"src/Tournaments/TournamentRegistrationType.ts",
|
|
@@ -49,6 +63,7 @@
|
|
|
49
63
|
"src/Jackpots/index.ts",
|
|
50
64
|
"src/Raffle/index.ts",
|
|
51
65
|
"src/Missions/AchievementAvailabilityStatus.ts",
|
|
66
|
+
"src/Missions/AchievementClaimTypeId.ts",
|
|
52
67
|
"src/Missions/AchievementType.ts",
|
|
53
68
|
"src/Missions/AchievementStatus.ts",
|
|
54
69
|
"src/Missions/ScheduledMissionType.ts",
|
|
@@ -75,6 +90,7 @@
|
|
|
75
90
|
"entryFileName": "README.md",
|
|
76
91
|
"disableSources": true,
|
|
77
92
|
"excludePrivate": true,
|
|
93
|
+
"excludeProtected": true,
|
|
78
94
|
"readme": "none",
|
|
79
95
|
"cleanOutputDir": true,
|
|
80
96
|
"hideBreadcrumbs": true,
|