@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
@@ -1,55 +1,221 @@
1
1
  import { TRaffle, TRaffleDraw, TRaffleDrawRun, TransformedRaffleClaimPrizeResponse, TRaffleOptinResponse } from './WSAPITypes';
2
+ import { GetRaffleWonPrizesResponse } from '../Raffle';
2
3
  import { WSAPIJackpots } from './WSAPIJackpots';
3
4
  /** @group Raffles */
4
5
  export declare class WSAPIRaffles extends WSAPIJackpots {
5
6
  protected updateRaffles(): Promise<void>;
6
7
  /**
7
- * Returns the list of Raffles available for user
8
- * The returned list of Raffles is cached for 30 seconds. But you can pass the onUpdate callback as a parameter. Note that each time you call getRaffles with a new onUpdate callback, the old one will be overwritten by the new one.
9
- * The onUpdate callback will be called on claiming prize. Updated Raffles will be passed to onUpdate callback.
8
+ * Returns all raffles visible to the current user, each carrying an
9
+ * embedded `draws[]` array with per-draw state (current state, ticket
10
+ * counts, opt-in status, prize structure). Use this to power a
11
+ * raffles lobby screen and to drive per-draw CTAs (opt-in, view
12
+ * winners, claim).
10
13
  *
11
- * **Example**:
14
+ * The embedded `draws[i]` objects are sufficient for rendering all
15
+ * draw cards — winner details with usernames / avatars require a
16
+ * follow-up {@link getRaffleDrawRun} call (the embedded form carries
17
+ * only `winners_total` / `winners_limit` / `winners_offset` metadata,
18
+ * not individual winner rows).
12
19
  *
13
- * ```
14
- * _smartico.api.getRaffles().then((result) => {
15
- * console.log(result);
16
- * });
17
- * ```
20
+ * @remarks
21
+ * **Subscription model (`onUpdate`)**
22
+ * The callback receives the FULL refreshed raffle list (never a
23
+ * diff/patch). Each subsequent call to `getRaffles({ 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.
18
27
  *
19
- * **Example in the Visitor mode**:
28
+ * **Update triggers** — the callback fires when:
20
29
  *
21
- * ```
22
- * _smartico.vapi('EN').getRaffles().then((result) => {
23
- * console.log(result);
30
+ * 1. {@link claimRafflePrize} resolves on this connection (any
31
+ * response code) — the refreshed list reflects the new
32
+ * `has_unclaimed_prize` / `claimed_date` state.
33
+ * 2. {@link requestRaffleOptin} resolves on this connection (any
34
+ * response code) — the refreshed list reflects the new
35
+ * `user_opted_in` state on the affected draw.
36
+ *
37
+ * Does NOT fire for: server-side draw executions, ticket increments
38
+ * (other users earning tickets), or operator-side raffle/draw config
39
+ * changes. Those changes surface only on the next cache miss (after
40
+ * the 30 s TTL) — poll manually if your UI needs sub-30s freshness
41
+ * during an in-progress draw.
42
+ *
43
+ * **Reading state from the returned raffle**
44
+ * - `current_tickets_count` vs `max_tickets_count` drives the
45
+ * `ticket_cap_visualization` banner (enum
46
+ * {@link RaffleTicketCapVisualization}: `Empty` = no banner,
47
+ * `Counter` = show "X tickets remaining", `Message` = show
48
+ * sold-out message).
49
+ * - Within each draw, `current_state`
50
+ * ({@link RaffleDrawInstanceState}) buckets the draw into Open
51
+ * (accepting tickets), WinnerSelection (currently drawing), or
52
+ * Executed (winners selected).
53
+ * - `execution_type` ({@link RaffleDrawTypeExecution}) distinguishes
54
+ * one-shot (`ExecDate`), repeating (`Recurring`), or special
55
+ * one-shot (`Grand`) draws. Recurring draws share a stable
56
+ * `draws[i].id` (the schedule definition) across runs — `run_id`
57
+ * is the per-execution instance.
58
+ *
59
+ * **Cache TTL**: the SDK caches the response for 30 seconds. Cache
60
+ * is fully cleared on login / logout. The server also invalidates
61
+ * the SDK cache when a draw executes on the server side.
62
+ *
63
+ * **Idempotency / Side effects**: safe. Read-only.
64
+ *
65
+ * **UI guidance**: see [UI Guide — `getRaffles`](../../docs/ui/raffles/UIGuide_getRaffles.md).
66
+ *
67
+ * **Visitor mode**: supported. The same shape is returned, scoped
68
+ * to the brand's public raffles. Per-user fields (`my_tickets_count`,
69
+ * `my_last_tickets`, `user_opted_in`) are not meaningful for
70
+ * visitors. The `onUpdate` callback is accepted but never fires
71
+ * because the mutation methods that trigger it
72
+ * ({@link claimRafflePrize}, {@link requestRaffleOptin}) are not
73
+ * available / not effective in visitor mode.
74
+ *
75
+ * @param params Optional. Omit to fetch without subscribing.
76
+ * @param params.onUpdate Callback invoked with the full refreshed
77
+ * raffles list after every
78
+ * {@link claimRafflePrize} or
79
+ * {@link requestRaffleOptin} round-trip
80
+ * on this connection.
81
+ * @returns Promise resolving to the raffles list.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const raffles = await window._smartico.api.getRaffles({
86
+ * onUpdate: (refreshed) => {
87
+ * console.log('[smartico] raffles refreshed (after claim/optin) — re-render from this array:', refreshed);
88
+ * },
24
89
  * });
25
- * ```
26
90
  *
91
+ * for (const raffle of raffles) {
92
+ * console.log('[smartico] render raffle', raffle.id, '—', raffle.name, ':', raffle.draws.length, 'draws');
93
+ *
94
+ * // Bucket draws: active/upcoming first (sorted by execution_ts ASC), then executed last.
95
+ * const sorted = [...raffle.draws].sort((a, b) => {
96
+ * const aDone = a.current_state === 3; // Executed
97
+ * const bDone = b.current_state === 3;
98
+ * if (aDone !== bDone) return aDone ? 1 : -1; // executed sink to the bottom
99
+ * return a.execution_ts - b.execution_ts;
100
+ * });
101
+ *
102
+ * for (const d of sorted) {
103
+ * if (d.requires_optin && !d.user_opted_in && d.is_active && d.current_state !== 3) {
104
+ * console.log('[smartico] draw', d.run_id, '— show OPT IN CTA (requires_optin + not yet opted in + still active)');
105
+ * }
106
+ * if (d.current_state === 3) {
107
+ * console.log('[smartico] draw', d.run_id, 'executed — fetch winner details via getRaffleDrawRun');
108
+ * }
109
+ * }
110
+ * }
111
+ *
112
+ * // For winner detail on an executed draw, call getRaffleDrawRun separately.
113
+ * ```
27
114
  */
28
115
  getRaffles({ onUpdate }?: {
29
116
  onUpdate?: (data: TRaffle[]) => void;
30
117
  }): Promise<TRaffle[]>;
31
118
  /**
32
- * Returns draw run for provided raffle_id and run_id.
33
- * You can pass winners_from and winners_to parameters to get a specific range of winners. Default is 0-20.
119
+ * Returns the full detail of a single raffle draw run — same shape
120
+ * as the embedded `TRaffleDraw` in {@link getRaffles}, but populated
121
+ * with paginated `prizes[].winners[]` rows including usernames and
122
+ * avatars. Use this to render a draw detail / winners screen, or to
123
+ * page through the winner list of an executed draw.
34
124
  *
125
+ * Each call is a fresh server round-trip — there is no client cache.
126
+ * Re-call to refresh.
35
127
  *
36
- * **Example**:
128
+ * @remarks
129
+ * **Preconditions**
130
+ * Pass `raffle_id` (the parent raffle's `id`) and `run_id` (the
131
+ * specific run instance — `TRaffleDraw.run_id` from
132
+ * {@link getRaffles}'s embedded draws). Note that
133
+ * `TRaffleDraw.id` is the *schedule_id* (stable across runs of a
134
+ * recurring draw) — that's NOT what this method takes; it takes the
135
+ * per-instance `run_id`.
37
136
  *
38
- * ```javascript
39
- * _smartico.api.getRaffleDrawRun({raffle_id: 156, run_id: 145}).then((result) => {
40
- * console.log(result);
41
- * });
42
- * ```
137
+ * **Refresh model**
138
+ * - **No subscription.** One-shot promise.
139
+ * - **No client cache.** Every call sends a network request.
140
+ * - **No push event** refreshes the response. Live winner-list
141
+ * updates require a fresh call.
142
+ * - The default Smartico UI polls this method on a variable cadence
143
+ * while a draw is in flight: every 3 s during `WinnerSelection`,
144
+ * every 10 s when the countdown is under 5 minutes, every 30 s
145
+ * otherwise.
146
+ *
147
+ * **Winner pagination**
148
+ * `winners_from` / `winners_to` define a half-open range of winner
149
+ * indices. The default window is `0–20` (20 winners). The server
150
+ * caps the window at 50 rows per call — passing a larger range
151
+ * silently truncates. For "load more" pagination, advance
152
+ * `winners_from` by the prior page size and pass the same
153
+ * `winners_to` offset. `winners_total` on the returned
154
+ * `TRaffleDraw` is the authoritative total count for pagination.
155
+ *
156
+ * The current user's own winning rows (if any) are server-sorted
157
+ * to the top of the result.
158
+ *
159
+ * **Throws**
160
+ * Both `raffle_id` and `run_id` are required — the SDK throws
161
+ * synchronously when either is missing or falsy.
162
+ *
163
+ * **Idempotency / Side effects**: safe. Read-only.
43
164
  *
44
- * **Example in the Visitor mode**:
165
+ * **UI guidance**: see [UI Guide — `getRaffleDrawRun`](../../docs/ui/raffles/UIGuide_getRaffleDrawRun.md).
45
166
  *
167
+ * **Visitor mode**: supported.
46
168
  *
47
- * ```javascript
48
- * _smartico.vapi('EN').getRaffleDrawRun({ raffle_id: 156, run_id: 145 }).then((result) => {
49
- * console.log(result);
169
+ * @param props.raffle_id The parent raffle's `id` (from `TRaffle.id`).
170
+ * @param props.run_id The draw run instance ID (from
171
+ * `TRaffleDraw.run_id`, not `TRaffleDraw.id`).
172
+ * @param props.winners_from First winner index to return (0-based).
173
+ * Defaults to `0`.
174
+ * @param props.winners_to Last winner index (exclusive).
175
+ * Defaults to `20`. Server caps the
176
+ * window at 50 rows per call.
177
+ * @returns Promise resolving to `TRaffleDraw`
178
+ * with `prizes[].winners[]` populated
179
+ * and `winners_total` set.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * const raffles = await window._smartico.api.getRaffles();
184
+ * const raffle = raffles[0];
185
+ * const draw = raffle.draws.find(d => d.current_state === 3); // Executed
186
+ *
187
+ * if (!draw) {
188
+ * console.log('[smartico] no executed draw — skip detail view');
189
+ * return;
190
+ * }
191
+ *
192
+ * // First page of winners.
193
+ * const detail = await window._smartico.api.getRaffleDrawRun({
194
+ * raffle_id: raffle.id,
195
+ * run_id: draw.run_id, // NOTE: run_id, NOT draw.id
196
+ * winners_from: 0,
197
+ * winners_to: 20,
50
198
  * });
51
- * ```
52
199
  *
200
+ * for (const prize of detail.prizes) {
201
+ * console.log('[smartico] prize', prize.name, '— winners on this page:', prize.winners.length);
202
+ * const myWin = prize.winners.find(w => w.username === currentUsername); // or another match
203
+ * if (myWin) {
204
+ * console.log('[smartico] current user won this prize — surface a Claim CTA if not yet claimed');
205
+ * }
206
+ * }
207
+ *
208
+ * // Load more — pagination via winners_from / winners_to.
209
+ * if ((detail.winners_total ?? 0) > 20) {
210
+ * const next = await window._smartico.api.getRaffleDrawRun({
211
+ * raffle_id: raffle.id,
212
+ * run_id: draw.run_id,
213
+ * winners_from: 20,
214
+ * winners_to: 40,
215
+ * });
216
+ * console.log('[smartico] page 2 loaded — append', next.prizes.flatMap(p => p.winners).length, 'winners');
217
+ * }
218
+ * ```
53
219
  */
54
220
  getRaffleDrawRun(props: {
55
221
  raffle_id: number;
@@ -58,62 +224,420 @@ export declare class WSAPIRaffles extends WSAPIJackpots {
58
224
  winners_to?: number;
59
225
  }): Promise<TRaffleDraw>;
60
226
  /**
61
- * Returns history of draw runs for the provided raffle_id and draw_id, if the draw_id is not provided will return history of all the draws for the provided raffle_id
227
+ * Returns the history of past-executed draw runs for a raffle —
228
+ * optionally scoped to a single recurring draw schedule. Each row
229
+ * is a previously-executed run with its scheduled and
230
+ * actual-execution timestamps, the user's win status, and an
231
+ * unclaimed-prize flag for surfacing a Claim CTA on history rows.
232
+ *
233
+ * @remarks
234
+ * **Preconditions**
235
+ * `raffle_id` is required. `draw_id` is optional — when omitted,
236
+ * the response includes history for ALL draws of the raffle; when
237
+ * supplied, it scopes to that one draw's recurring history. The
238
+ * `draw_id` to pass is `TRaffleDraw.id` (the schedule_id, stable
239
+ * across runs), not `run_id`.
240
+ *
241
+ * **Server-side filtering**
242
+ * Draws configured by the operator to hide their history are
243
+ * excluded from the response automatically. Cancelled runs are
244
+ * also excluded.
245
+ *
246
+ * **Sort order**
247
+ * Server returns rows by scheduled `execution_ts` descending
248
+ * (newest first). No client-side sort required.
249
+ *
250
+ * **Refresh model**
251
+ * - **No subscription.** One-shot promise.
252
+ * - **No client cache.** Every call hits the server.
253
+ * - **No push event** refreshes the response. Re-call manually to
254
+ * pick up newly-executed runs or `has_unclaimed_prize` flips
255
+ * after a {@link claimRafflePrize} call.
256
+ *
257
+ * **Idempotency / Side effects**: safe. Read-only.
258
+ *
259
+ * **UI guidance**: see [UI Guide — `getRaffleDrawRunsHistory`](../../docs/ui/raffles/UIGuide_getRaffleDrawRunsHistory.md).
62
260
  *
261
+ * **Visitor mode**: supported. The same shape is returned with
262
+ * `is_winner` and `has_unclaimed_prize` always `false` for visitors.
63
263
  *
64
- * **Example**:
264
+ * @param props.raffle_id The parent raffle's `id` (from `TRaffle.id`).
265
+ * Required.
266
+ * @param props.draw_id Optional — the draw's schedule_id
267
+ * (`TRaffleDraw.id`). When set, scopes the
268
+ * history to that one draw's runs. When
269
+ * omitted, includes all draws of the raffle.
270
+ * @returns Promise resolving to a `TRaffleDrawRun[]`
271
+ * ordered newest-first. Empty if no executed
272
+ * runs exist.
65
273
  *
66
- * ```javascript
67
- * _smartico.api.getRaffleDrawRunsHistory({ raffle_id: 156, draw_id: 432 }).then((result) => {
68
- * console.log(result);
274
+ * @example
275
+ * ```ts
276
+ * const raffles = await window._smartico.api.getRaffles();
277
+ * const raffle = raffles[0];
278
+ *
279
+ * // History across all draws of the raffle.
280
+ * const allHistory = await window._smartico.api.getRaffleDrawRunsHistory({
281
+ * raffle_id: raffle.id,
69
282
  * });
70
- * ```
71
283
  *
72
- * **Example in the Visitor mode**:
284
+ * // Highlight rows where the user has an unclaimed prize.
285
+ * const unclaimed = allHistory.filter(r => r.has_unclaimed_prize);
286
+ * if (unclaimed.length > 0) {
287
+ * console.log('[smartico] surface a "Claim" CTA on these', unclaimed.length, 'history rows:', unclaimed.map(r => r.run_id));
288
+ * }
73
289
  *
74
- * ```javascript
75
- * _smartico.vapi('EN').getRaffleDrawRunsHistory({ raffle_id: 156, draw_id: 432 }).then((result) => {
76
- * console.log(result);
290
+ * // Scoped history of one recurring draw (use draw.id, the schedule_id).
291
+ * const oneDrawHistory = await window._smartico.api.getRaffleDrawRunsHistory({
292
+ * raffle_id: raffle.id,
293
+ * draw_id: raffle.draws[0].id, // schedule_id (stable across recurring runs)
77
294
  * });
295
+ * console.log('[smartico] render history rows for the daily draw — newest first:', oneDrawHistory.length, 'rows');
78
296
  * ```
79
- *
80
297
  */
81
298
  getRaffleDrawRunsHistory(props: {
82
299
  raffle_id: number;
83
300
  draw_id?: number;
84
301
  }): Promise<TRaffleDrawRun[]>;
85
302
  /**
86
- * Returns `err_code` and `err_message` after the call; `err_code` 0 means the request succeeded.
303
+ * Claims a raffle prize the user has won. Call this when the user
304
+ * has a winning row with `should_claim === true` and an unclaimed
305
+ * `won_id` (read from a `TRafflePrizeWinner` on a
306
+ * {@link getRaffleDrawRun} result, or surfaced by `has_unclaimed_prize`
307
+ * on a {@link getRaffleDrawRunsHistory} row that the consumer drills
308
+ * into).
87
309
  *
310
+ * On success (`errorCode === 0`), the server records the claim and
311
+ * triggers prize delivery through the operator's integration —
312
+ * delivery is server-side, not part of this response.
88
313
  *
89
- * **Example**:
314
+ * @remarks
315
+ * **Result shape note**: this method returns
316
+ * `TransformedRaffleClaimPrizeResponse` with `errorCode` /
317
+ * `errorMessage` (camelCase full-word) — different from most other
318
+ * SDK result types which use `err_code` / `err_message` (snake_case
319
+ * short-word). Branch on the camelCase keys when reading this
320
+ * method's result.
90
321
  *
91
- * ```javascript
92
- * _smartico.api.claimRafflePrize({won_id:251}).then((result) => {
93
- * console.log(result);
94
- * });
95
- * ```
322
+ * **Preconditions**
323
+ * Pass a `won_id` that identifies an unclaimed winning row for the
324
+ * current user. The `won_id` comes from
325
+ * `TRafflePrizeWinner.raf_won_id` returned by
326
+ * {@link getRaffleDrawRun}.
327
+ *
328
+ * **Error codes** (in `errorCode`)
329
+ * - `0` — success; the claim is recorded and prize delivery is
330
+ * queued server-side.
331
+ * - `1` — generic claim failure. The `errorMessage` distinguishes
332
+ * the specific cause (the server uses one error code for several
333
+ * distinct conditions): the prize has already been claimed, the
334
+ * `won_id` doesn't match a winning row for this user, or the user
335
+ * is in a control group for this raffle. Treat `1` as a retryable
336
+ * error if the message suggests a transient condition; treat as
337
+ * idempotent success if the message indicates already-claimed
338
+ * (the underlying state is what the consumer wants either way —
339
+ * the prize is claimed).
340
+ * - other non-zero — generic server error. Surface `errorMessage`
341
+ * if any.
342
+ *
343
+ * **Claim window**
344
+ * There is no server-enforced claim deadline. Won prizes remain
345
+ * claimable indefinitely until the operator archives them.
346
+ *
347
+ * **Idempotency**: NOT idempotent. A second call on the same
348
+ * `won_id` returns `errorCode === 1` with `errorMessage` indicating
349
+ * the prize has already been claimed. The SDK does NOT enforce an
350
+ * in-flight lock. Guard the call site against double-clicks (set
351
+ * a local "claiming" flag on click, clear it on response).
352
+ *
353
+ * **Refresh after success (and after failure)**
354
+ * The SDK automatically refreshes the raffles cache on every
355
+ * response — both success and failure paths fire the `onUpdate`
356
+ * callback registered via {@link getRaffles}. After `errorCode === 0`,
357
+ * the affected `TRaffleDrawRun.has_unclaimed_prize` (in history)
358
+ * and the winner row's `claimed_date` reflect the claim on the next
359
+ * refresh.
360
+ *
361
+ * **Side effects** (on `errorCode === 0`)
362
+ * - The winner row's `claimed_date` is set server-side.
363
+ * - Prize delivery is queued for the operator's integration to
364
+ * process. Balance / bonus / inbox updates that result from the
365
+ * delivery arrive through their own channels — not in this
366
+ * response.
367
+ *
368
+ * **Throws**
369
+ * `won_id` is required — the SDK throws synchronously when missing
370
+ * or falsy.
96
371
  *
97
- * **Example in the Visitor mode**:
372
+ * **UI guidance**: see [UI Guide — `claimRafflePrize`](../../docs/ui/raffles/UIGuide_claimRafflePrize.md).
98
373
  *
99
- * ```javascript
100
- * _smartico.vapi('EN').claimRafflePrize({ won_id: 251 }).then((result) => {
101
- * console.log(result);
374
+ * **Visitor mode**: not meaningfully supported. The SDK does not
375
+ * block the call, but visitor sessions have no win history and the
376
+ * server will reject it.
377
+ *
378
+ * @param props.won_id The winning row's `raf_won_id` (from
379
+ * `TRafflePrizeWinner` returned by
380
+ * {@link getRaffleDrawRun}).
381
+ * @returns `{ errorCode, errorMessage? }`; success when
382
+ * `errorCode === 0`. Note camelCase keys (see "Result
383
+ * shape note" above).
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * const detail = await window._smartico.api.getRaffleDrawRun({
388
+ * raffle_id: raffleId,
389
+ * run_id: runId,
102
390
  * });
103
- * ```
391
+ * const myWin = detail.prizes.flatMap(p => p.winners).find(w => /* user match here *\/ true);
104
392
  *
393
+ * if (!myWin || !myWin.raf_won_id || myWin.claimed_date) {
394
+ * console.log('[smartico] nothing to claim — keep CTA hidden');
395
+ * return;
396
+ * }
397
+ *
398
+ * console.log('[smartico] claim starting — set in-flight flag, show loading dots on the Claim button, keep the modal open');
399
+ * const r = await window._smartico.api.claimRafflePrize({ won_id: myWin.raf_won_id });
400
+ * console.log('[smartico] claim response received — clear in-flight flag');
401
+ *
402
+ * if (r.errorCode === 0) {
403
+ * console.log('[smartico] claim succeeded — show a success toast; getRaffles onUpdate above will fire with refreshed state; prize delivery happens server-side');
404
+ * } else if (r.errorCode === 1 && r.errorMessage?.toLowerCase().includes('already claimed')) {
405
+ * console.log('[smartico] prize was already claimed (perhaps from another tab) — treat as success, hide the Claim CTA');
406
+ * } else {
407
+ * console.error('[smartico] claim failed — surface this error message to the user and allow retry:', r.errorMessage);
408
+ * }
409
+ * ```
105
410
  */
106
411
  claimRafflePrize(props: {
107
412
  won_id: number;
108
413
  }): Promise<TransformedRaffleClaimPrizeResponse>;
109
414
  /**
110
- * Requests an opt-in for the specified raffle. Returns the err_code.
415
+ * Opts the current user into a specific raffle draw run. Required
416
+ * for draws where `TRaffleDraw.requires_optin === true` — without
417
+ * opt-in, the user's tickets do NOT participate in that run, even
418
+ * if they hold tickets for the raffle.
419
+ *
420
+ * Opt-in is per-run: a recurring draw's next run requires a fresh
421
+ * opt-in. The user's `TRaffleDraw.user_opted_in` flag reflects the
422
+ * current state for the current run only.
423
+ *
424
+ * @remarks
425
+ * **Preconditions**
426
+ * Read the candidate draw from {@link getRaffles}'s embedded
427
+ * `draws[]` and gate the call on
428
+ * `requires_optin === true && !user_opted_in && is_active &&
429
+ * current_state !== Executed`. Calling without these guards may
430
+ * return a non-zero `err_code`.
431
+ *
432
+ * **Argument mapping** — the three IDs come from different fields:
433
+ * - `raffle_id` — the parent raffle's `TRaffle.id`
434
+ * - `draw_id` — `TRaffleDraw.id` (schedule_id, stable across runs)
435
+ * - `raffle_run_id` — `TRaffleDraw.run_id` (instance ID for this
436
+ * specific run)
437
+ *
438
+ * **Error codes** (in `err_code`)
439
+ * - `0` — success; the user is opted into this run. Tickets
440
+ * collected after the run's `ticket_start_ts` will participate.
441
+ * - `1` — generic opt-in failure. The `err_message` distinguishes
442
+ * the specific cause: the draw doesn't require opt-in
443
+ * (`requires_optin === false`), `raffle_id` doesn't match the
444
+ * `draw_id`, the user is already opted in (or the draw has
445
+ * completed), or the user is in a control group for this raffle.
446
+ * - other non-zero — generic server error. Surface `err_message`.
447
+ *
448
+ * **Idempotency**: NOT idempotent. A second call on the same
449
+ * `raffle_run_id` returns `err_code === 1` with `err_message`
450
+ * indicating the user is already opted in. Treat as success in
451
+ * the UI — the underlying state is what the consumer wants.
452
+ * Guard the call site against double-clicks.
453
+ *
454
+ * **Refresh after success (and after failure)**
455
+ * The SDK automatically refreshes the raffles cache on every
456
+ * response and fires the `onUpdate` callback registered via
457
+ * {@link getRaffles}. After `err_code === 0`, the affected draw's
458
+ * `user_opted_in` flips to `true` on the refreshed list.
111
459
  *
112
- * **Visitor mode: not supported**
460
+ * **Side effects** (on `err_code === 0`)
461
+ * - The user is registered for this run. Tickets earned within
462
+ * the run's eligibility window will participate in the draw.
463
+ * - No balance change. No CRM-side rewards. Opt-in is a metadata
464
+ * operation only.
465
+ *
466
+ * **Throws**
467
+ * `raffle_id`, `draw_id`, and `raffle_run_id` are all required —
468
+ * the SDK throws synchronously when any is missing or falsy.
469
+ *
470
+ * **UI guidance**: see [UI Guide — `requestRaffleOptin`](../../docs/ui/raffles/UIGuide_requestRaffleOptin.md).
471
+ *
472
+ * **Visitor mode**: not supported.
473
+ *
474
+ * @param props.raffle_id The parent raffle's `id`.
475
+ * @param props.draw_id The draw's schedule_id (`TRaffleDraw.id`).
476
+ * @param props.raffle_run_id The run instance ID (`TRaffleDraw.run_id`).
477
+ * @returns `{ err_code, err_message? }`; success
478
+ * when `err_code === 0` (treat
479
+ * "already opted in" as idempotent
480
+ * success).
481
+ *
482
+ * @example
483
+ * ```ts
484
+ * const raffles = await window._smartico.api.getRaffles({
485
+ * onUpdate: (refreshed) => console.log('[smartico] raffles refreshed — re-render', refreshed),
486
+ * });
487
+ * const raffle = raffles[0];
488
+ * const draw = raffle.draws.find(d =>
489
+ * d.requires_optin && !d.user_opted_in && d.is_active && d.current_state !== 3
490
+ * );
491
+ *
492
+ * if (!draw) {
493
+ * console.log('[smartico] no opt-in-required draw available — keep CTA hidden');
494
+ * return;
495
+ * }
496
+ *
497
+ * console.log('[smartico] opt-in starting — set in-flight flag, show loading dots on the Opt-in button');
498
+ * const r = await window._smartico.api.requestRaffleOptin({
499
+ * raffle_id: raffle.id,
500
+ * draw_id: draw.id, // schedule_id, NOT run_id
501
+ * raffle_run_id: draw.run_id,
502
+ * });
503
+ * console.log('[smartico] opt-in response received — clear in-flight flag');
504
+ *
505
+ * if (r.err_code === 0) {
506
+ * console.log('[smartico] opted in successfully — show "Fully opted in" state on the draw card; onUpdate above will fire with user_opted_in: true');
507
+ * } else if (r.err_code === 1 && r.err_message?.toLowerCase().includes('already opted in')) {
508
+ * console.log('[smartico] already opted in (perhaps from another tab) — treat as success, show "Fully opted in"');
509
+ * } else {
510
+ * console.error('[smartico] opt-in failed — surface this error to the user:', r.err_message);
511
+ * }
512
+ * ```
113
513
  */
114
514
  requestRaffleOptin(props: {
115
515
  raffle_id: number;
116
516
  draw_id: number;
117
517
  raffle_run_id: number;
118
518
  }): Promise<TRaffleOptinResponse>;
519
+ /**
520
+ * Returns every prize the current user has won within a single raffle —
521
+ * across ALL of that raffle's draws, newest-won first — in one paginated
522
+ * call. Use this to power a "my prizes" screen for a raffle (prize name,
523
+ * prize image, the user's name/avatar) without walking
524
+ * {@link getRaffleDrawRunsHistory} and then paging
525
+ * {@link getRaffleDrawRun}'s per-draw winner lists.
526
+ *
527
+ * Each row carries its own `raf_won_id`, which IS the `won_id` to pass to
528
+ * {@link claimRafflePrize}: a row with `requires_claim === true` and no
529
+ * `claimed_date` is directly claimable.
530
+ *
531
+ * @remarks
532
+ * **Authentication required**
533
+ * Works only for an identified (logged-in) user. Visitor / anonymous
534
+ * sessions are rejected — call this only after identify.
535
+ *
536
+ * **Preconditions**
537
+ * `raffle_id` is required — the SDK throws synchronously when it is
538
+ * missing or falsy.
539
+ *
540
+ * **Coverage & sort order**
541
+ * Includes the user's wins from every draw of the raffle — recurring,
542
+ * one-shot, and grand draws, across all historical runs. Rows are ordered
543
+ * newest-win first; there is no "unclaimed first" ordering, so sort
544
+ * client-side if you want claimable prizes at the top.
545
+ *
546
+ * **Pagination**
547
+ * `offset` / `limit` page the `won_prizes[]` rows (the SDK defaults to
548
+ * `0` / `20`). `total` is the authoritative full count of the user's wins
549
+ * for this raffle across all draws — drive "load more" from it
550
+ * (`offset + won_prizes.length < total`). An `offset` past the end returns
551
+ * an empty `won_prizes[]` with the real `total` and `errCode 0` — not an
552
+ * error. The server does NOT clamp `limit`, so always pass an explicit,
553
+ * sane page size.
554
+ *
555
+ * **Rate limit**
556
+ * The server caps this at roughly 30 calls per minute with a ~5-second
557
+ * minimum gap between calls. Fetch on screen open and on explicit "load
558
+ * more" — don't poll it on a timer.
559
+ *
560
+ * **Error codes** (in `errCode`)
561
+ * - `0` — success. Also returned with an empty `won_prizes[]` and
562
+ * `total 0` when the user has no wins, or is not eligible to see this
563
+ * raffle.
564
+ * - `1` — generic server error; surface `errMsg` if present.
565
+ *
566
+ * There are no granular codes — an unknown raffle, an ineligible user,
567
+ * and "no wins" all surface as `errCode 0` with an empty list.
568
+ *
569
+ * **Reading the result**
570
+ * - Null-check `user` before reading it — it is `null` whenever
571
+ * `won_prizes` is empty.
572
+ * - For the avatar, use `user.avatar_id` (already a full URL for a system
573
+ * avatar, otherwise an avatar token to resolve against the widget's
574
+ * avatar domain); `user.avatar_url` is always `null`.
575
+ * - Render `public_username` as-is (it is server-masked for privacy, e.g.
576
+ * `"32:r*****"`) and substitute a "You" label for the current user.
577
+ * - Treat `claimed_date` as the claim flag: `null` until claimed, then
578
+ * epoch ms.
579
+ *
580
+ * **Idempotency / Side effects**: safe and read-only — one-shot promise,
581
+ * no client cache, no subscription. The server caches the response
582
+ * briefly; a successful {@link claimRafflePrize} invalidates that cache,
583
+ * so a follow-up call reflects the new `claimed_date`. This method does
584
+ * NOT refresh the {@link getRaffles} list or fire its `onUpdate` — re-call
585
+ * manually to pick up newly-won prizes or a `claimed_date` flip.
586
+ *
587
+ * **UI guidance**: see [UI Guide — `getRaffleWonPrizes`](../../docs/ui/raffles/UIGuide_getRaffleWonPrizes.md).
588
+ *
589
+ * **Visitor mode**: not supported (see "Authentication required").
590
+ *
591
+ * @param props.raffle_id The parent raffle's `id` (from `TRaffle.id`). Required.
592
+ * @param props.offset Zero-based index of the first row to return. Defaults to `0`.
593
+ * @param props.limit Page size. Defaults to `20`.
594
+ * @returns Promise resolving to {@link GetRaffleWonPrizesResponse}
595
+ * (`user`, this page of `won_prizes`, and `total`;
596
+ * `errCode 0` on success).
597
+ *
598
+ * @example
599
+ * ```ts
600
+ * const raffles = await window._smartico.api.getRaffles();
601
+ * const raffle = raffles[0];
602
+ *
603
+ * // First page of the user's won prizes for this raffle.
604
+ * const page = await window._smartico.api.getRaffleWonPrizes({
605
+ * raffle_id: raffle.id,
606
+ * offset: 0,
607
+ * limit: 20,
608
+ * });
609
+ *
610
+ * if (page.errCode !== 0) {
611
+ * console.error('[smartico] could not load won prizes — show a retry state:', page.errMsg);
612
+ * return;
613
+ * }
614
+ * if (page.won_prizes.length === 0) {
615
+ * console.log('[smartico] no wins in this raffle (or not eligible) — render the empty state');
616
+ * return;
617
+ * }
618
+ *
619
+ * console.log('[smartico]', page.user?.public_username, 'won', page.total, 'prizes total');
620
+ * for (const prize of page.won_prizes) {
621
+ * console.log('[smartico] render prize card —', prize.public_meta.name, prize.public_meta.image_url);
622
+ * if (prize.requires_claim && !prize.claimed_date) {
623
+ * console.log('[smartico] show a Claim CTA — on click call claimRafflePrize({ won_id:', prize.raf_won_id, '})');
624
+ * }
625
+ * }
626
+ *
627
+ * // Load more.
628
+ * if (page.offset + page.won_prizes.length < page.total) {
629
+ * const next = await window._smartico.api.getRaffleWonPrizes({
630
+ * raffle_id: raffle.id,
631
+ * offset: page.offset + page.limit,
632
+ * limit: 20,
633
+ * });
634
+ * console.log('[smartico] appended', next.won_prizes.length, 'more prizes');
635
+ * }
636
+ * ```
637
+ */
638
+ getRaffleWonPrizes(props: {
639
+ raffle_id: number;
640
+ offset?: number;
641
+ limit?: number;
642
+ }): Promise<GetRaffleWonPrizesResponse>;
119
643
  }