@smartico/public-api 0.0.380 → 0.0.382
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/CLAUDE.md +103 -0
- package/README.md +32 -10
- package/dist/Base/ClassId.d.ts +2 -0
- package/dist/Jackpots/JackpotDetails.d.ts +14 -15
- package/dist/Jackpots/JackpotPot.d.ts +10 -6
- package/dist/MiniGames/SAWGameType.d.ts +3 -1
- package/dist/MiniGames/SAWTemplateUI.d.ts +7 -0
- package/dist/Raffle/GetRaffleWonPrizesRequest.d.ts +9 -0
- package/dist/Raffle/GetRaffleWonPrizesResponse.d.ts +52 -0
- package/dist/Raffle/index.d.ts +2 -0
- package/dist/SmarticoAPI.d.ts +6 -1
- package/dist/SmarticoLib/index.d.ts +5 -1
- package/dist/WSAPI/WSAPIAvatars.d.ts +267 -49
- package/dist/WSAPI/WSAPIBonuses.d.ts +224 -10
- package/dist/WSAPI/WSAPIGamePick.d.ts +538 -253
- package/dist/WSAPI/WSAPIGeneral.d.ts +156 -14
- package/dist/WSAPI/WSAPIInbox.d.ts +547 -58
- package/dist/WSAPI/WSAPIJackpots.d.ts +292 -57
- package/dist/WSAPI/WSAPILeaderBoard.d.ts +127 -13
- package/dist/WSAPI/WSAPIMiniGames.d.ts +465 -49
- package/dist/WSAPI/WSAPIRaffles.d.ts +576 -52
- package/dist/WSAPI/WSAPITournaments.d.ts +3 -3
- package/dist/WSAPI/WSAPITypes.d.ts +243 -132
- package/dist/WSAPI/WSAPIUser.d.ts +193 -43
- package/dist/index.js +3412 -616
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +3395 -609
- package/dist/index.modern.mjs.map +1 -1
- package/docs/Callbacks.md +162 -0
- package/docs/SmarticoObject.md +445 -0
- package/docs/Transforms.md +99 -0
- package/docs/api/README.md +26 -0
- package/docs/api/classes/WSAPIAvatars.md +282 -54
- package/docs/api/classes/WSAPIBonuses.md +233 -12
- package/docs/api/classes/WSAPIClans.md +380 -10
- package/docs/api/classes/WSAPIGamePick.md +555 -26
- package/docs/api/classes/WSAPIGeneral.md +165 -16
- package/docs/api/classes/WSAPIInbox.md +588 -64
- package/docs/api/classes/WSAPIJackpots.md +320 -66
- package/docs/api/classes/WSAPILeaderBoard.md +133 -15
- package/docs/api/classes/WSAPIMiniGames.md +501 -64
- package/docs/api/classes/WSAPIMissions.md +58 -79
- package/docs/api/classes/WSAPIRaffles.md +647 -69
- package/docs/api/classes/WSAPIStore.md +83 -108
- package/docs/api/classes/WSAPITournaments.md +495 -28
- package/docs/api/classes/WSAPIUser.md +520 -83
- package/docs/api/documents/Callbacks.md +162 -0
- package/docs/api/documents/SmarticoObject.md +445 -0
- package/docs/api/documents/Transforms.md +99 -0
- package/docs/api/enumerations/BonusStatus-1.md +11 -6
- package/docs/api/enumerations/JoinClanErrorCode.md +81 -0
- package/docs/api/enumerations/TournamentRegistrationError.md +12 -0
- package/docs/api/functions/clanTournamentPlayersTransform.md +13 -0
- package/docs/api/interfaces/AvatarCustomized.md +25 -0
- package/docs/api/interfaces/AvatarDefinition.md +94 -0
- package/docs/api/interfaces/AvatarPrompt.md +45 -0
- package/docs/api/interfaces/BonusMetaMap-1.md +4 -1
- package/docs/api/interfaces/BonusTemplateMetaMap-1.md +9 -4
- package/docs/api/interfaces/Clan.md +4 -0
- package/docs/api/interfaces/ClanInfo.md +109 -0
- package/docs/api/interfaces/ClanMember.md +53 -0
- package/docs/api/interfaces/ClanTournamentPlayerRaw.md +67 -0
- package/docs/api/interfaces/GemsDiamondsLog.md +43 -0
- package/docs/api/interfaces/GetClanInfoResponse.md +61 -0
- package/docs/api/interfaces/GetClanTournamentPlayersResponse.md +81 -0
- package/docs/api/interfaces/GetRaffleWonPrizesRequest.md +59 -0
- package/docs/api/interfaces/GetRaffleWonPrizesResponse.md +95 -0
- package/docs/api/interfaces/InboxMarkMessageAction.md +10 -2
- package/docs/api/interfaces/JackpotDetails.md +14 -15
- package/docs/api/interfaces/JackpotPot.md +9 -6
- package/docs/api/interfaces/LeaderBoardDetailsT.md +14 -8
- package/docs/api/interfaces/LeaderBoardUserT.md +8 -5
- package/docs/api/interfaces/LeaderBoardsRewardsT.md +7 -0
- package/docs/api/interfaces/PointsLog.md +43 -0
- package/docs/api/interfaces/RaffleWonPrize.md +59 -0
- package/docs/api/interfaces/RaffleWonPrizePublicMeta.md +27 -0
- package/docs/api/interfaces/RaffleWonPrizeUser.md +43 -0
- package/docs/api/interfaces/TAchCategory.md +2 -7
- package/docs/api/interfaces/TAvatarCustomized.md +4 -4
- package/docs/api/interfaces/TAvatarDefinition.md +13 -14
- package/docs/api/interfaces/TAvatarPrompt.md +6 -6
- package/docs/api/interfaces/TBonus.md +16 -8
- package/docs/api/interfaces/TBuyStoreItemResult.md +4 -29
- package/docs/api/interfaces/TClaimBonusResult.md +5 -5
- package/docs/api/interfaces/TClan.md +8 -4
- package/docs/api/interfaces/TClanInfo.md +47 -0
- package/docs/api/interfaces/TClanJoinResult.md +11 -1
- package/docs/api/interfaces/TClanTournamentPlayer.md +55 -0
- package/docs/api/interfaces/TClanTournamentPlayersResult.md +27 -0
- package/docs/api/interfaces/TClans.md +3 -1
- package/docs/api/interfaces/TGetTranslations.md +4 -0
- package/docs/api/interfaces/TInboxMessage.md +14 -6
- package/docs/api/interfaces/TInboxMessageBody.md +18 -12
- package/docs/api/interfaces/TLevel.md +17 -20
- package/docs/api/interfaces/TLevelCurrent.md +19 -18
- package/docs/api/interfaces/TMiniGamePlayBatchResult.md +14 -6
- package/docs/api/interfaces/TMiniGamePlayResult.md +9 -4
- package/docs/api/interfaces/TMissionClaimRewardResult.md +1 -9
- package/docs/api/interfaces/TMissionOptInResult.md +1 -5
- package/docs/api/interfaces/TMissionOrBadge.md +4 -7
- package/docs/api/interfaces/TRaffleOptinResponse.md +4 -2
- package/docs/api/interfaces/TSegmentCheckResult.md +10 -0
- package/docs/api/interfaces/TSetAvatarResult.md +3 -3
- package/docs/api/interfaces/TStoreItem.md +3 -13
- package/docs/api/interfaces/TTournament.md +1 -1
- package/docs/api/interfaces/TTournamentDetailed.md +1 -1
- package/docs/api/interfaces/TTournamentRegistrationResult.md +4 -2
- package/docs/api/interfaces/TUICustomSection.md +23 -19
- package/docs/api/interfaces/TUserProfile.md +18 -16
- package/docs/api/interfaces/TransformedRaffleClaimPrizeResponse.md +6 -2
- package/docs/api/interfaces/UserLevelExtraCountersT.md +9 -2
- package/docs/api/type-aliases/ActivityLogEntry.md +3 -0
- package/docs/native/ADDING_METHODS.md +7 -2
- package/docs/native/PROTOCOL.md +337 -0
- package/docs/ui/avatars/UIGuide_getAvatarPrompts.md +100 -0
- package/docs/ui/avatars/UIGuide_getAvatarsCustomized.md +90 -0
- package/docs/ui/avatars/UIGuide_getAvatarsList.md +105 -0
- package/docs/ui/avatars/UIGuide_setAvatar.md +118 -0
- package/docs/ui/bonuses/UIGuide_claimBonus.md +144 -0
- package/docs/ui/bonuses/UIGuide_getBonuses.md +176 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetActiveRound.md +99 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetActiveRounds.md +76 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetBoard.md +81 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetGameInfo.md +78 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetHistory.md +55 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetRoundInfoForUser.md +71 -0
- package/docs/ui/gamepick/UIGuide_gamePickGetUserInfo.md +64 -0
- package/docs/ui/gamepick/UIGuide_gamePickSubmitSelection.md +103 -0
- package/docs/ui/gamepick/UIGuide_gamePickSubmitSelectionQuiz.md +67 -0
- package/docs/ui/general/UIGuide_getCustomSections.md +137 -0
- package/docs/ui/general/UIGuide_getRelatedItemsForGame.md +140 -0
- package/docs/ui/inbox/UIGuide_deleteInboxMessage.md +135 -0
- package/docs/ui/inbox/UIGuide_getInboxMessageBody.md +133 -0
- package/docs/ui/inbox/UIGuide_getInboxMessages.md +186 -0
- package/docs/ui/inbox/UIGuide_markInboxMessageAsRead.md +122 -0
- package/docs/ui/inbox/UIGuide_markUnmarkInboxMessageAsFavorite.md +84 -0
- package/docs/ui/jackpots/UIGuide_getJackpotEligibleGames.md +73 -0
- package/docs/ui/jackpots/UIGuide_getJackpotWinners.md +83 -0
- package/docs/ui/jackpots/UIGuide_jackpotGet.md +138 -0
- package/docs/ui/jackpots/UIGuide_jackpotOptIn.md +85 -0
- package/docs/ui/jackpots/UIGuide_jackpotOptOut.md +65 -0
- package/docs/ui/leaderboard/UIGuide_getLeaderBoard.md +166 -0
- package/docs/ui/minigames/UIGuide_getMiniGames.md +153 -0
- package/docs/ui/minigames/UIGuide_getMiniGamesHistory.md +90 -0
- package/docs/ui/minigames/UIGuide_playMiniGame.md +150 -0
- package/docs/ui/minigames/UIGuide_playMiniGameBatch.md +128 -0
- package/docs/ui/raffles/UIGuide_claimRafflePrize.md +99 -0
- package/docs/ui/raffles/UIGuide_getRaffleDrawRun.md +117 -0
- package/docs/ui/raffles/UIGuide_getRaffleDrawRunsHistory.md +92 -0
- package/docs/ui/raffles/UIGuide_getRaffleWonPrizes.md +120 -0
- package/docs/ui/raffles/UIGuide_getRaffles.md +175 -0
- package/docs/ui/raffles/UIGuide_requestRaffleOptin.md +114 -0
- package/docs/ui/user/UIGuide_getActivityLog.md +130 -0
- package/docs/ui/user/UIGuide_getLevels.md +47 -42
- package/package.json +1 -1
- package/src/Base/ClassId.ts +2 -0
- package/src/Jackpots/JackpotDetails.ts +14 -15
- package/src/Jackpots/JackpotPot.ts +10 -6
- package/src/MiniGames/SAWGameType.ts +3 -0
- package/src/MiniGames/SAWTemplateUI.ts +10 -0
- package/src/Raffle/GetRaffleWonPrizesRequest.ts +12 -0
- package/src/Raffle/GetRaffleWonPrizesResponse.ts +56 -0
- package/src/Raffle/index.ts +3 -1
- package/src/SmarticoAPI.ts +14 -1
- package/src/SmarticoLib/index.ts +4 -0
- package/src/WSAPI/WSAPIAvatars.ts +267 -49
- package/src/WSAPI/WSAPIBonuses.ts +224 -10
- package/src/WSAPI/WSAPIGamePick.ts +538 -253
- package/src/WSAPI/WSAPIGeneral.ts +156 -14
- package/src/WSAPI/WSAPIInbox.ts +545 -56
- package/src/WSAPI/WSAPIJackpots.ts +297 -61
- package/src/WSAPI/WSAPILeaderBoard.ts +127 -13
- package/src/WSAPI/WSAPIMiniGames.ts +465 -49
- package/src/WSAPI/WSAPIRaffles.ts +592 -64
- package/src/WSAPI/WSAPITournaments.ts +3 -3
- package/src/WSAPI/WSAPITypes.ts +243 -132
- package/src/WSAPI/WSAPIUser.ts +193 -43
- package/tsconfig.json +9 -1
|
@@ -15,24 +15,98 @@ import { WSAPIRaffles } from './WSAPIRaffles';
|
|
|
15
15
|
/** @group MiniGames */
|
|
16
16
|
export class WSAPIMiniGames extends WSAPIRaffles {
|
|
17
17
|
/**
|
|
18
|
-
* Returns
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Returns all mini-game templates ("SAW" = Spin And Win — the
|
|
19
|
+
* umbrella term for wheel-spin, scratch-card, lootbox, gift-box,
|
|
20
|
+
* treasure-hunt, plinko, coin-flip, quiz, and several other formats)
|
|
21
|
+
* configured for the label. Optionally subscribes to live updates
|
|
22
|
+
* via `onUpdate`: the callback fires whenever the user's
|
|
23
|
+
* `spin_count` changes, jackpot grows, a manual spin is issued, or
|
|
24
|
+
* a spin response lands.
|
|
21
25
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* });
|
|
27
|
-
* ```
|
|
26
|
+
* The list is NOT filtered by spin availability — every configured
|
|
27
|
+
* template is returned, including ones the user cannot currently
|
|
28
|
+
* play. The `visibile_when_can_spin` flag on each template hints
|
|
29
|
+
* which to hide in a default lobby view (consumer-side filter).
|
|
28
30
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* **Subscription model (`onUpdate`)**
|
|
33
|
+
* The callback receives the FULL refreshed template list (never a
|
|
34
|
+
* diff/patch). Each subsequent call to `getMiniGames({ onUpdate })`
|
|
35
|
+
* REPLACES the prior callback. Pass `onUpdate: undefined` (or omit
|
|
36
|
+
* it) to keep the prior callback in place; the callback is never
|
|
37
|
+
* auto-cleared.
|
|
38
|
+
*
|
|
39
|
+
* **Update triggers** — the callback fires when:
|
|
40
|
+
*
|
|
41
|
+
* 1. The server pushes a `spin_count` change (campaign award,
|
|
42
|
+
* store purchase, BO manual issuance, mission reward).
|
|
43
|
+
* 2. Any {@link playMiniGame} or {@link playMiniGameBatch}
|
|
44
|
+
* resolves on this connection — the cached array refreshes
|
|
45
|
+
* with updated `spin_count`, `jackpot_current`, and any new
|
|
46
|
+
* `next_available_spin_ts`.
|
|
47
|
+
* 3. Acknowledge responses land (via auto-acknowledge or
|
|
48
|
+
* {@link miniGameWinAcknowledgeRequest}).
|
|
49
|
+
*
|
|
50
|
+
* Jackpot growth is observable on the refreshed `jackpot_current`
|
|
51
|
+
* field — the SDK inlines the live value into template `name` /
|
|
52
|
+
* `promo_text` / prize `name` via a `{{jackpot}}` template
|
|
53
|
+
* substitution at fetch time.
|
|
54
|
+
*
|
|
55
|
+
* **Game-type variants**
|
|
56
|
+
* All twelve `SAWGameType` values (`SpinAWheel`, `ScratchCard`,
|
|
57
|
+
* `MatchX`, `GiftBox`, `PrizeDrop`, `Quiz`, `LootboxWeekdays`,
|
|
58
|
+
* `LootboxCalendarDays`, `TreasureHunt`, `Voyager`, `Plinko`,
|
|
59
|
+
* `CoinFlip`) surface through the same template shape. Most are
|
|
60
|
+
* played via {@link playMiniGame}; the exceptions are:
|
|
61
|
+
* - `PrizeDrop` — server-push only; the consumer does NOT call
|
|
62
|
+
* `playMiniGame`. Prizes arrive via the prize-drop push channel.
|
|
63
|
+
* - `MatchX` / `Quiz` — predictions are submitted via a separate
|
|
64
|
+
* games server (not this SDK); the SAW spin is fired
|
|
65
|
+
* server-internally to deduct the buy-in.
|
|
66
|
+
*
|
|
67
|
+
* **Cache TTL**: the SDK caches the response for 30 seconds. Cache
|
|
68
|
+
* is fully cleared on login / logout.
|
|
69
|
+
*
|
|
70
|
+
* **Idempotency / Side effects**: safe. Read-only.
|
|
71
|
+
*
|
|
72
|
+
* **UI guidance**: see [UI Guide — `getMiniGames`](../../docs/ui/minigames/UIGuide_getMiniGames.md).
|
|
73
|
+
*
|
|
74
|
+
* **Visitor mode**: supported. Only templates configured with
|
|
75
|
+
* `is_visitor_mode = true` in the BO are returned for anonymous
|
|
76
|
+
* sessions. Spins from these templates may also be played (visitor
|
|
77
|
+
* mode is the one mini-game flow that does support play — see
|
|
78
|
+
* {@link playMiniGame} for the visitor-stop semantics).
|
|
79
|
+
*
|
|
80
|
+
* @param params Optional. Omit to fetch without subscribing.
|
|
81
|
+
* @param params.onUpdate Callback invoked with the full refreshed
|
|
82
|
+
* template array after any spin-count
|
|
83
|
+
* change, spin response, or acknowledge
|
|
84
|
+
* response on this connection.
|
|
85
|
+
* @returns Promise resolving to the template
|
|
86
|
+
* array. Empty if no templates are
|
|
87
|
+
* visible to the user.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const games = await window._smartico.api.getMiniGames({
|
|
92
|
+
* onUpdate: (refreshed) => {
|
|
93
|
+
* console.log('[smartico] mini-game templates refreshed — re-render lobby from this array:', refreshed);
|
|
94
|
+
* },
|
|
33
95
|
* });
|
|
34
|
-
* ```
|
|
35
96
|
*
|
|
97
|
+
* // Filter the lobby view per the visibility flag.
|
|
98
|
+
* const visible = games.filter(g =>
|
|
99
|
+
* !g.visibile_when_can_spin || (g.spin_count && g.spin_count > 0)
|
|
100
|
+
* );
|
|
101
|
+
*
|
|
102
|
+
* for (const g of visible) {
|
|
103
|
+
* console.log('[smartico] render game card', g.id, '—', g.name,
|
|
104
|
+
* '— type:', g.saw_game_type,
|
|
105
|
+
* '— buy-in:', g.saw_buyin_type,
|
|
106
|
+
* '— spins available:', g.spin_count ?? 0,
|
|
107
|
+
* '— jackpot:', g.jackpot_current, g.jackpot_symbol);
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
36
110
|
*/
|
|
37
111
|
public async getMiniGames({ onUpdate }: { onUpdate?: (data: TMiniGameTemplate[]) => void } = {}): Promise<
|
|
38
112
|
TMiniGameTemplate[]
|
|
@@ -45,19 +119,73 @@ export class WSAPIMiniGames extends WSAPIRaffles {
|
|
|
45
119
|
}
|
|
46
120
|
|
|
47
121
|
/**
|
|
48
|
-
* Returns
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
122
|
+
* Returns a paginated, newest-first list of the user's past
|
|
123
|
+
* mini-game spins — each row carries the won prize ID, the
|
|
124
|
+
* client-side `request_id` used for the spin, and a
|
|
125
|
+
* server-recorded `is_claimed` flag (`true` if the spin has been
|
|
126
|
+
* acknowledged). Optionally filter to a single template via
|
|
127
|
+
* `saw_template_id`.
|
|
52
128
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
129
|
+
* Use this to power a "My prizes" / win-history surface, or to
|
|
130
|
+
* recover unacknowledged spins (rows with `is_claimed === false`
|
|
131
|
+
* carry a `client_request_id` you can pass to
|
|
132
|
+
* {@link miniGameWinAcknowledgeRequest}).
|
|
59
133
|
*
|
|
60
|
-
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* **Pagination**
|
|
136
|
+
* `limit` defaults to 20, `offset` defaults to 0. Sort order is
|
|
137
|
+
* `create_date` DESC (newest first) — no client-side re-sort
|
|
138
|
+
* required. For "load more" pagination, advance `offset` by the
|
|
139
|
+
* page size on each subsequent call.
|
|
140
|
+
*
|
|
141
|
+
* The underlying protocol carries a `hasMore` boolean on the
|
|
142
|
+
* response, but the SDK strips it from the public surface —
|
|
143
|
+
* detect end of list when the returned array length is less than
|
|
144
|
+
* `limit`.
|
|
145
|
+
*
|
|
146
|
+
* **`is_claimed` semantics**
|
|
147
|
+
* Maps directly to the server's "acknowledge_date is non-null"
|
|
148
|
+
* state. A spin where the auto-acknowledge fire-and-forget
|
|
149
|
+
* succeeded shows `is_claimed: true`; a spin where the
|
|
150
|
+
* acknowledge was lost (network drop) or where the user is on an
|
|
151
|
+
* explicit-acknowledge flow shows `is_claimed: false` with a
|
|
152
|
+
* usable `client_request_id`. A server-side fallback job
|
|
153
|
+
* auto-acknowledges stale rows every ~60 seconds — so even
|
|
154
|
+
* "lost" prizes are eventually delivered without consumer action.
|
|
155
|
+
*
|
|
156
|
+
* **Cache TTL**: the SDK caches the response for 30 seconds.
|
|
157
|
+
* Cache is invalidated implicitly when a new spin or acknowledge
|
|
158
|
+
* response lands.
|
|
159
|
+
*
|
|
160
|
+
* **Idempotency / Side effects**: safe. Read-only.
|
|
161
|
+
*
|
|
162
|
+
* **UI guidance**: see [UI Guide — `getMiniGamesHistory`](../../docs/ui/minigames/UIGuide_getMiniGamesHistory.md).
|
|
163
|
+
*
|
|
164
|
+
* **Visitor mode**: not supported.
|
|
165
|
+
*
|
|
166
|
+
* @param params Optional pagination + filter bag.
|
|
167
|
+
* @param params.limit Page size. Defaults to 20.
|
|
168
|
+
* @param params.offset Number of rows to skip. Defaults to 0.
|
|
169
|
+
* @param params.saw_template_id When set, scopes the history to
|
|
170
|
+
* a single template's spins.
|
|
171
|
+
*
|
|
172
|
+
* @returns Promise resolving to `TSawHistory[]` in newest-first
|
|
173
|
+
* order. Empty when the user has no history.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const history = await window._smartico.api.getMiniGamesHistory({ limit: 20 });
|
|
178
|
+
*
|
|
179
|
+
* // Show unacknowledged spins with a Claim CTA.
|
|
180
|
+
* const unacknowledged = history.filter(h => !h.is_claimed);
|
|
181
|
+
* console.log('[smartico] surface a "Claim" CTA on these', unacknowledged.length, 'history rows:',
|
|
182
|
+
* unacknowledged.map(h => h.client_request_id));
|
|
183
|
+
*
|
|
184
|
+
* // Load-more pagination — advance offset by the prior page size.
|
|
185
|
+
* const page2 = await window._smartico.api.getMiniGamesHistory({ limit: 20, offset: 20 });
|
|
186
|
+
* console.log('[smartico] page 2 loaded —', page2.length, 'more rows;',
|
|
187
|
+
* page2.length < 20 ? 'end of list reached, hide "Load more"' : 'keep "Load more" visible');
|
|
188
|
+
* ```
|
|
61
189
|
*/
|
|
62
190
|
|
|
63
191
|
public async getMiniGamesHistory({
|
|
@@ -78,18 +206,164 @@ export class WSAPIMiniGames extends WSAPIRaffles {
|
|
|
78
206
|
}
|
|
79
207
|
|
|
80
208
|
/**
|
|
81
|
-
* Plays
|
|
82
|
-
*
|
|
83
|
-
*
|
|
209
|
+
* Plays one round of a mini-game template — runs the server's
|
|
210
|
+
* randomised prize selection, deducts the buy-in cost (if any),
|
|
211
|
+
* and returns the won `prize_id`. After the play resolves, the SDK
|
|
212
|
+
* automatically fires a server-side acknowledgement on a
|
|
213
|
+
* fire-and-forget basis, marking the spin as "delivered" so the
|
|
214
|
+
* prize takes effect.
|
|
84
215
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
216
|
+
* Works for all `SAWGameType` values EXCEPT:
|
|
217
|
+
* - `PrizeDrop` — prizes arrive server-pushed; do NOT call
|
|
218
|
+
* `playMiniGame` for this type.
|
|
219
|
+
* - `MatchX` / `Quiz` — prediction submission goes through a
|
|
220
|
+
* separate games server; `playMiniGame` is not the entry point.
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* **Preconditions**
|
|
224
|
+
* Read the candidate template from {@link getMiniGames} and check:
|
|
225
|
+
* - `spin_count > 0` for spin-based templates
|
|
226
|
+
* (`saw_buyin_type === 'spins'`).
|
|
227
|
+
* - Sufficient balance for paid templates — points / gems /
|
|
228
|
+
* diamonds from {@link getUserProfile} against
|
|
229
|
+
* `buyin_cost_points` / `_gems` / `_diamonds`.
|
|
230
|
+
* - `next_available_spin_ts` is in the past (or unset) — the
|
|
231
|
+
* server enforces a per-period max-attempts cap.
|
|
232
|
+
* - Template is currently in its active period
|
|
233
|
+
* (operator-configured `activeFromDate` / `activeTillDate`).
|
|
234
|
+
*
|
|
235
|
+
* **Error codes** (in `err_code`, typed as {@link SAWSpinErrorCode})
|
|
236
|
+
* - `0` (`SAW_OK`) — success; `prize_id` identifies the won prize
|
|
237
|
+
* in `template.prizes`.
|
|
238
|
+
* - `40001` (`SAW_NO_SPINS`) — user has no spin attempts for a
|
|
239
|
+
* spin-based template.
|
|
240
|
+
* - `40002` (`SAW_PRIZE_POOL_EMPTY`) — all prize slots in the
|
|
241
|
+
* template are depleted.
|
|
242
|
+
* - `40003` (`SAW_NOT_ENOUGH_POINTS`) — insufficient points for a
|
|
243
|
+
* points-cost template.
|
|
244
|
+
* - `40004` (`SAW_FAILED_MAX_SPINS_REACHED`) — per-period
|
|
245
|
+
* max-attempts cap reached. The server's
|
|
246
|
+
* `first_spin_in_period` value (exposed in
|
|
247
|
+
* {@link TMiniGamePlayBatchResult}; not surfaced in the single
|
|
248
|
+
* `TMiniGamePlayResult`) marks the period start.
|
|
249
|
+
* - `40007` (`SAW_TEMPLATE_NOT_ACTIVE`) — template outside its
|
|
250
|
+
* active time window.
|
|
251
|
+
* - `40009` (`SAW_NOT_IN_SEGMENT`) — user fails the template's
|
|
252
|
+
* visibility segment check, OR (for lootbox variants) the day's
|
|
253
|
+
* prize pool is empty.
|
|
254
|
+
* - `40011` (`SAW_NO_BALANCE_GEMS`) — insufficient gems.
|
|
255
|
+
* - `40012` (`SAW_NO_BALANCE_DIAMONDS`) — insufficient diamonds.
|
|
256
|
+
* - `-40001` (`SAW_VISITOR_STOP_SPIN_REQUEST`) — visitor session
|
|
257
|
+
* tried to play a non-visitor-mode template. The default UI
|
|
258
|
+
* silently stops the game; no prize awarded.
|
|
259
|
+
* - other non-zero — generic server error. Surface `err_message`.
|
|
260
|
+
*
|
|
261
|
+
* **Prize handling**
|
|
262
|
+
* On `err_code === 0`, `prize_id` matches an entry in
|
|
263
|
+
* `template.prizes`. Look up the prize's `prize_type`
|
|
264
|
+
* ({@link MiniGamePrizeTypeName}) to decide UI treatment:
|
|
265
|
+
* - `'no-prize'` — the user spun but won nothing (an operator-
|
|
266
|
+
* configured "loss" slot). Buy-in is still deducted.
|
|
267
|
+
* - `'points'` / `'gems-and-diamonds'` / `'spin'` — value
|
|
268
|
+
* credited to the user's profile / spin balance; visible on
|
|
269
|
+
* the next refresh.
|
|
270
|
+
* - `'bonus'` — surfaces via {@link getBonuses}.
|
|
271
|
+
* - `'jackpot'` — drains the template's `jackpot_current` to the
|
|
272
|
+
* user; resets the accumulator.
|
|
273
|
+
* - `'raffle-ticket'` — adds tickets to the relevant raffle.
|
|
274
|
+
* - `'mission'` / `'change-level'` — visible via the
|
|
275
|
+
* corresponding domain methods.
|
|
276
|
+
* - `'manual'` — operator delivers offline.
|
|
277
|
+
*
|
|
278
|
+
* **Auto-acknowledge**
|
|
279
|
+
* The SDK calls the server's acknowledge endpoint immediately
|
|
280
|
+
* after the spin response, on a fire-and-forget basis (not
|
|
281
|
+
* awaited). This marks the spin as "delivered" so prize effects
|
|
282
|
+
* take hold. If the auto-acknowledge fails (network drop), the
|
|
283
|
+
* spin appears as `is_claimed: false` in
|
|
284
|
+
* {@link getMiniGamesHistory}; the consumer can recover it by
|
|
285
|
+
* passing the `client_request_id` to
|
|
286
|
+
* {@link miniGameWinAcknowledgeRequest}. A server-side fallback
|
|
287
|
+
* job auto-acknowledges stale spins every ~60 seconds, so prizes
|
|
288
|
+
* are eventually delivered even without consumer action.
|
|
289
|
+
*
|
|
290
|
+
* **Idempotency**: NOT idempotent. A double-click sends two
|
|
291
|
+
* spins and deducts the buy-in twice. The SDK does NOT guard
|
|
292
|
+
* against rapid clicks at the public API level — guard the call
|
|
293
|
+
* site with an in-flight flag. The server enforces a per-user
|
|
294
|
+
* per-template lock that serialises concurrent requests, so two
|
|
295
|
+
* simultaneous calls won't be processed in parallel, but they
|
|
296
|
+
* will both be processed sequentially (i.e. both deduct).
|
|
297
|
+
*
|
|
298
|
+
* **Refresh after success (and after failure)**
|
|
299
|
+
* The SDK automatically refreshes the templates cache on every
|
|
300
|
+
* spin response and fires any `onUpdate` callback registered via
|
|
301
|
+
* {@link getMiniGames} or this method. After `err_code === 0`, the
|
|
302
|
+
* affected template's `spin_count` / `jackpot_current` /
|
|
303
|
+
* `next_available_spin_ts` reflect the new state on the
|
|
304
|
+
* refreshed array.
|
|
305
|
+
*
|
|
306
|
+
* **Side effects** (on `err_code === 0`)
|
|
307
|
+
* - Buy-in deducted from the user's balance (points / gems /
|
|
308
|
+
* diamonds / spin tickets — depending on `saw_buyin_type`).
|
|
309
|
+
* Balance updates flow via the user-properties channel
|
|
310
|
+
* (subscribe to {@link getUserProfile} `props_change` to
|
|
311
|
+
* observe).
|
|
312
|
+
* - Prize value credited per the prize's type (see "Prize
|
|
313
|
+
* handling" above).
|
|
314
|
+
* - A `minigame_attempt` analytics event fires server-side with
|
|
315
|
+
* the result status.
|
|
316
|
+
*
|
|
317
|
+
* **UI guidance**: see [UI Guide — `playMiniGame`](../../docs/ui/minigames/UIGuide_playMiniGame.md).
|
|
318
|
+
*
|
|
319
|
+
* **Visitor mode**: not supported. Visitor sessions trying to
|
|
320
|
+
* spin receive `SAW_VISITOR_STOP_SPIN_REQUEST (-40001)`.
|
|
321
|
+
*
|
|
322
|
+
* @param template_id The mini-game template ID (from
|
|
323
|
+
* `TMiniGameTemplate.id`).
|
|
324
|
+
* @param params Optional. Pass an `onUpdate` callback to
|
|
325
|
+
* subscribe to subsequent template refreshes.
|
|
326
|
+
* @returns `{ err_code, err_message, prize_id }` — success when
|
|
327
|
+
* `err_code === 0`. `prize_id` is always populated; look
|
|
328
|
+
* it up in `template.prizes` to interpret the prize.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* const games = await window._smartico.api.getMiniGames({
|
|
333
|
+
* onUpdate: (refreshed) => console.log('[smartico] templates refreshed — re-render lobby', refreshed),
|
|
89
334
|
* });
|
|
90
|
-
*
|
|
335
|
+
* const game = games.find(g => g.id === templateId);
|
|
336
|
+
*
|
|
337
|
+
* if (!game) {
|
|
338
|
+
* console.log('[smartico] template not in current list — refresh getMiniGames');
|
|
339
|
+
* return;
|
|
340
|
+
* }
|
|
341
|
+
* if (game.saw_buyin_type === 'spins' && (game.spin_count ?? 0) === 0) {
|
|
342
|
+
* console.log('[smartico] no spins available — disable Play button, show "No spins" message');
|
|
343
|
+
* return;
|
|
344
|
+
* }
|
|
345
|
+
*
|
|
346
|
+
* console.log('[smartico] play starting — set in-flight flag, start game animation (wheel spin / scratch / lootbox open / etc.)');
|
|
347
|
+
* const r = await window._smartico.api.playMiniGame(game.id);
|
|
348
|
+
* console.log('[smartico] play response received');
|
|
91
349
|
*
|
|
92
|
-
*
|
|
350
|
+
* if (r.err_code === 0) {
|
|
351
|
+
* const prize = game.prizes.find(p => p.id === r.prize_id);
|
|
352
|
+
* if (prize?.prize_type === 'no-prize') {
|
|
353
|
+
* console.log('[smartico] user lost — animate to the no-prize slot and show "Better luck next time" modal');
|
|
354
|
+
* } else {
|
|
355
|
+
* console.log('[smartico] user won — animate to prize', prize?.name,
|
|
356
|
+
* '— show acknowledge modal per template.acknowledge_type;',
|
|
357
|
+
* 'getMiniGames onUpdate fires shortly with refreshed spin_count / jackpot');
|
|
358
|
+
* }
|
|
359
|
+
* } else if (r.err_code === 40004) {
|
|
360
|
+
* console.error('[smartico] max spins reached — show countdown to next available spin (use playMiniGameBatch for first_spin_in_period if needed)');
|
|
361
|
+
* } else if (r.err_code === -40001) {
|
|
362
|
+
* console.log('[smartico] visitor stopped — silently end the game, no prize modal');
|
|
363
|
+
* } else {
|
|
364
|
+
* console.error('[smartico] play failed — show generic error with this message:', r.err_message);
|
|
365
|
+
* }
|
|
366
|
+
* ```
|
|
93
367
|
*/
|
|
94
368
|
public async playMiniGame(
|
|
95
369
|
template_id: number,
|
|
@@ -112,12 +386,63 @@ export class WSAPIMiniGames extends WSAPIRaffles {
|
|
|
112
386
|
}
|
|
113
387
|
|
|
114
388
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
389
|
+
* Manually acknowledges a mini-game spin — marks the spin as
|
|
390
|
+
* "delivered" so the prize takes effect server-side. Most consumers
|
|
391
|
+
* do NOT need to call this method directly; {@link playMiniGame}
|
|
392
|
+
* and {@link playMiniGameBatch} auto-acknowledge on success. Use
|
|
393
|
+
* this only for recovery scenarios.
|
|
394
|
+
*
|
|
395
|
+
* @remarks
|
|
396
|
+
* **When to call**
|
|
397
|
+
* - **Lost auto-acknowledge** — when the WebSocket dropped between
|
|
398
|
+
* the spin response and the auto-acknowledge fire-and-forget,
|
|
399
|
+
* the spin shows `is_claimed: false` in
|
|
400
|
+
* {@link getMiniGamesHistory}. Pass that row's
|
|
401
|
+
* `client_request_id` here to deliver the prize.
|
|
402
|
+
* - **Explicit-acknowledge UI** — for templates configured with
|
|
403
|
+
* the `ExplicitAcknowledge` acknowledge type (operator
|
|
404
|
+
* decision), the consumer's UI shows a "Claim" CTA after the
|
|
405
|
+
* prize animation. Click handler calls this method with the
|
|
406
|
+
* spin's `client_request_id` rather than auto-acknowledging.
|
|
407
|
+
*
|
|
408
|
+
* **No-op on already-acknowledged spins**
|
|
409
|
+
* The server's acknowledge SQL matches on `acknowledge_date IS
|
|
410
|
+
* NULL` — a duplicate call returns successfully with no effect.
|
|
411
|
+
*
|
|
412
|
+
* **Server-side fallback**
|
|
413
|
+
* Even without ever calling this method, a server-side job
|
|
414
|
+
* auto-acknowledges stale spins every ~60 seconds — so prizes are
|
|
415
|
+
* eventually delivered. The `is_claimed` flag flips on the next
|
|
416
|
+
* `getMiniGamesHistory` call after the job runs.
|
|
417
|
+
*
|
|
418
|
+
* **Idempotency**: safe. Repeated calls have no effect after the
|
|
419
|
+
* first.
|
|
420
|
+
*
|
|
421
|
+
* **Side effects** (on first successful call for an unacknowledged
|
|
422
|
+
* spin)
|
|
423
|
+
* - Prize value credited per the prize's type (see
|
|
424
|
+
* {@link playMiniGame} "Prize handling").
|
|
425
|
+
* - The spin's `is_claimed` flag flips to `true` on the next
|
|
426
|
+
* {@link getMiniGamesHistory} call.
|
|
427
|
+
*
|
|
428
|
+
* **Visitor mode**: not supported.
|
|
429
|
+
*
|
|
430
|
+
* @param request_id The `client_request_id` from a `TSawHistory`
|
|
431
|
+
* row returned by {@link getMiniGamesHistory}.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* const history = await window._smartico.api.getMiniGamesHistory({ limit: 20 });
|
|
436
|
+
* const unacknowledged = history.filter(h => !h.is_claimed);
|
|
437
|
+
*
|
|
438
|
+
* for (const row of unacknowledged) {
|
|
439
|
+
* console.log('[smartico] re-acknowledging stale spin', row.client_request_id);
|
|
440
|
+
* await window._smartico.api.miniGameWinAcknowledgeRequest(row.client_request_id);
|
|
441
|
+
* }
|
|
442
|
+
*
|
|
443
|
+
* // Re-fetch history to see the updated is_claimed flags.
|
|
444
|
+
* const fresh = await window._smartico.api.getMiniGamesHistory({ limit: 20 });
|
|
445
|
+
* console.log('[smartico] history after recovery —', fresh.filter(h => !h.is_claimed).length, 'still unacknowledged');
|
|
121
446
|
* ```
|
|
122
447
|
*/
|
|
123
448
|
public async miniGameWinAcknowledgeRequest(request_id: string) {
|
|
@@ -125,17 +450,108 @@ export class WSAPIMiniGames extends WSAPIRaffles {
|
|
|
125
450
|
}
|
|
126
451
|
|
|
127
452
|
/**
|
|
128
|
-
* Plays
|
|
129
|
-
*
|
|
130
|
-
*
|
|
453
|
+
* Plays a mini-game template `spin_count` times in one round-trip.
|
|
454
|
+
* Returns an array of per-spin results — each independent, each
|
|
455
|
+
* with its own error code. Like {@link playMiniGame}, the SDK
|
|
456
|
+
* auto-acknowledges every result on a fire-and-forget basis.
|
|
131
457
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
458
|
+
* Use this when a UI offers "spin N times" affordances
|
|
459
|
+
* (multi-spin buttons, lootbox open-N flows). The server processes
|
|
460
|
+
* each spin independently — there is no atomicity / rollback if
|
|
461
|
+
* one fails.
|
|
462
|
+
*
|
|
463
|
+
* @remarks
|
|
464
|
+
* **Result shape note** — `TMiniGamePlayBatchResult` uses
|
|
465
|
+
* `errCode` / `errMessage` (camelCase) — DIFFERENT from
|
|
466
|
+
* {@link TMiniGamePlayResult} which uses `err_code` / `err_message`
|
|
467
|
+
* (snake_case). Branch on the camelCase keys when reading batch
|
|
468
|
+
* results.
|
|
469
|
+
*
|
|
470
|
+
* **Per-spin independence**
|
|
471
|
+
* The server iterates the requested spins and calls the prize
|
|
472
|
+
* engine once per entry. If spin #2 fails with `SAW_NO_SPINS`,
|
|
473
|
+
* spin #3 is still attempted — the server does NOT stop on first
|
|
474
|
+
* error and does NOT roll back successful spins. Each
|
|
475
|
+
* `results[i].errCode` is independent.
|
|
476
|
+
*
|
|
477
|
+
* Practical implication: if the user has 3 spins available and
|
|
478
|
+
* requests 5, expect results 0-2 with `errCode === 0` and results
|
|
479
|
+
* 3-4 with `errCode === SAW_NO_SPINS`.
|
|
480
|
+
*
|
|
481
|
+
* **Error codes**
|
|
482
|
+
* Per-result `errCode` is from {@link SAWSpinErrorCode}. See
|
|
483
|
+
* {@link playMiniGame} for the full table; the same codes apply
|
|
484
|
+
* per spin.
|
|
485
|
+
*
|
|
486
|
+
* **`first_spin_in_period` field**
|
|
487
|
+
* Populated on results where `errCode === SAW_FAILED_MAX_SPINS_REACHED`
|
|
488
|
+
* (40004). The value is the epoch-ms timestamp of the user's
|
|
489
|
+
* first spin in the current cooldown period. Compute the
|
|
490
|
+
* countdown as:
|
|
491
|
+
* `template.max_spins_period_ms - (Date.now() - first_spin_in_period)`.
|
|
492
|
+
*
|
|
493
|
+
* **`jackpot_amount` field**
|
|
494
|
+
* Populated on results where the won prize is a jackpot
|
|
495
|
+
* (`prize_type === 'jackpot'`). The amount the user just claimed
|
|
496
|
+
* from the template's jackpot accumulator.
|
|
497
|
+
*
|
|
498
|
+
* **Auto-acknowledge**
|
|
499
|
+
* The SDK fires a batch-acknowledge for all `request_id`s after
|
|
500
|
+
* the batch response lands — fire-and-forget. Same recovery
|
|
501
|
+
* semantics as {@link playMiniGame}: lost acknowledgements
|
|
502
|
+
* become recoverable via {@link miniGameWinAcknowledgeRequest}
|
|
503
|
+
* per row, and a server-side fallback job auto-acknowledges
|
|
504
|
+
* stale spins every ~60 seconds.
|
|
505
|
+
*
|
|
506
|
+
* **Idempotency**: NOT idempotent. A double-click sends two
|
|
507
|
+
* batches. Guard the call site with an in-flight flag.
|
|
508
|
+
*
|
|
509
|
+
* **Refresh after success (and after failure)**
|
|
510
|
+
* Same as {@link playMiniGame} — the templates cache refreshes
|
|
511
|
+
* and any `onUpdate` callback registered via {@link getMiniGames}
|
|
512
|
+
* fires with the updated `spin_count` / `jackpot_current`.
|
|
513
|
+
*
|
|
514
|
+
* **Side effects** (per-spin, on `errCode === 0`)
|
|
515
|
+
* Same as {@link playMiniGame} — buy-in deducted, prize value
|
|
516
|
+
* credited per prize type.
|
|
517
|
+
*
|
|
518
|
+
* **UI guidance**: see [UI Guide — `playMiniGameBatch`](../../docs/ui/minigames/UIGuide_playMiniGameBatch.md).
|
|
519
|
+
*
|
|
520
|
+
* **Visitor mode**: not supported.
|
|
521
|
+
*
|
|
522
|
+
* @param template_id The mini-game template ID.
|
|
523
|
+
* @param spin_count Number of spins to play. The server attempts
|
|
524
|
+
* all `spin_count` spins — partial successes
|
|
525
|
+
* are normal when the user runs out of
|
|
526
|
+
* balance / spins mid-batch.
|
|
527
|
+
* @param params Optional. Pass an `onUpdate` callback to
|
|
528
|
+
* subscribe to subsequent template refreshes.
|
|
529
|
+
* @returns `TMiniGamePlayBatchResult[]` — one entry per requested
|
|
530
|
+
* spin, in request order. Note the camelCase `errCode` /
|
|
531
|
+
* `errMessage` keys (see "Result shape note" above).
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* const game = (await window._smartico.api.getMiniGames()).find(g => g.id === templateId);
|
|
536
|
+
* if (!game) return;
|
|
537
|
+
*
|
|
538
|
+
* console.log('[smartico] batch play starting — set in-flight flag, animate the chosen N spins sequentially in UI');
|
|
539
|
+
* const results = await window._smartico.api.playMiniGameBatch(game.id, 5);
|
|
540
|
+
* console.log('[smartico] batch response received — clear in-flight flag');
|
|
541
|
+
*
|
|
542
|
+
* for (const [i, r] of results.entries()) {
|
|
543
|
+
* if (r.errCode === 0) {
|
|
544
|
+
* const prize = game.prizes.find(p => p.id === r.saw_prize_id);
|
|
545
|
+
* console.log('[smartico] spin', i, 'won:', prize?.name,
|
|
546
|
+
* r.jackpot_amount ? '(jackpot: ' + r.jackpot_amount + ')' : '');
|
|
547
|
+
* } else if (r.errCode === 40004) {
|
|
548
|
+
* const msTillNext = game.max_spins_period_ms! - (Date.now() - (r.first_spin_in_period ?? 0));
|
|
549
|
+
* console.log('[smartico] spin', i, 'capped — ' + Math.ceil(msTillNext / 1000) + ' s until next allowed');
|
|
550
|
+
* } else {
|
|
551
|
+
* console.error('[smartico] spin', i, 'failed —', r.errCode, r.errMessage);
|
|
552
|
+
* }
|
|
553
|
+
* }
|
|
137
554
|
* ```
|
|
138
|
-
* **Visitor mode: not supported**
|
|
139
555
|
*/
|
|
140
556
|
public async playMiniGameBatch(
|
|
141
557
|
template_id: number,
|