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