@smartico/public-api 0.0.379 → 0.0.380

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.nvmrc +1 -1
  2. package/README.md +31 -2
  3. package/dist/Store/BuyStoreItemErrorCode.d.ts +9 -1
  4. package/dist/Tournaments/TournamentRegistrationError.d.ts +3 -1
  5. package/dist/WSAPI/WSAPI.d.ts +13 -1235
  6. package/dist/WSAPI/WSAPIAvatars.d.ts +78 -0
  7. package/dist/WSAPI/WSAPIBase.d.ts +71 -0
  8. package/dist/WSAPI/WSAPIBonuses.d.ts +26 -0
  9. package/dist/WSAPI/WSAPIClans.d.ts +388 -0
  10. package/dist/WSAPI/WSAPIGamePick.d.ts +308 -0
  11. package/dist/WSAPI/WSAPIGeneral.d.ts +30 -0
  12. package/dist/WSAPI/WSAPIInbox.d.ts +126 -0
  13. package/dist/WSAPI/WSAPIJackpots.d.ts +109 -0
  14. package/dist/WSAPI/WSAPILeaderBoard.d.ts +25 -0
  15. package/dist/WSAPI/WSAPIMiniGames.d.ts +94 -0
  16. package/dist/WSAPI/WSAPIMissions.d.ts +517 -0
  17. package/dist/WSAPI/WSAPIRaffles.d.ts +119 -0
  18. package/dist/WSAPI/WSAPIStore.d.ts +656 -0
  19. package/dist/WSAPI/WSAPITournaments.d.ts +501 -0
  20. package/dist/WSAPI/WSAPITypes.d.ts +145 -85
  21. package/dist/WSAPI/WSAPIUser.d.ts +383 -0
  22. package/dist/index.js +3818 -1528
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.modern.mjs +3180 -981
  25. package/dist/index.modern.mjs.map +1 -1
  26. package/docs/api/README.md +56 -2
  27. package/docs/api/classes/WSAPIAvatars.md +116 -0
  28. package/docs/api/classes/WSAPIBonuses.md +50 -0
  29. package/docs/api/classes/WSAPIClans.md +66 -0
  30. package/docs/api/classes/WSAPIGamePick.md +181 -0
  31. package/docs/api/classes/WSAPIGeneral.md +63 -0
  32. package/docs/api/classes/WSAPIInbox.md +277 -0
  33. package/docs/api/classes/WSAPIJackpots.md +185 -0
  34. package/docs/api/classes/WSAPILeaderBoard.md +39 -0
  35. package/docs/api/classes/WSAPIMiniGames.md +175 -0
  36. package/docs/api/classes/WSAPIMissions.md +611 -0
  37. package/docs/api/classes/WSAPIRaffles.md +195 -0
  38. package/docs/api/classes/WSAPIStore.md +744 -0
  39. package/docs/api/classes/WSAPITournaments.md +104 -0
  40. package/docs/api/classes/WSAPIUser.md +200 -0
  41. package/docs/api/enumerations/AchievementClaimPeriodTypeId.md +13 -0
  42. package/docs/api/enumerations/BuyStoreItemErrorCode.md +32 -0
  43. package/docs/api/interfaces/ClanPrizePublicMeta.md +41 -0
  44. package/docs/api/interfaces/ClanPrizeStructureEntry.md +7 -1
  45. package/docs/api/interfaces/ClanPublicMeta.md +4 -0
  46. package/docs/api/interfaces/SAWTemplateUI.md +10 -0
  47. package/docs/api/interfaces/TAchCategory.md +19 -4
  48. package/docs/api/interfaces/TBuyStoreItemResult.md +26 -8
  49. package/docs/api/interfaces/TMissionClaimRewardResult.md +14 -3
  50. package/docs/api/interfaces/TMissionOptInResult.md +10 -3
  51. package/docs/api/interfaces/TMissionOrBadge.md +6 -2
  52. package/docs/api/interfaces/TStoreItem.md +21 -1
  53. package/docs/api/interfaces/TTournamentDetailed.md +8 -0
  54. package/docs/api/interfaces/UserAchievement.md +1 -1
  55. package/docs/ui/clans/UIGuide_getClanInfo.md +153 -0
  56. package/docs/ui/clans/UIGuide_getClans.md +172 -0
  57. package/docs/ui/clans/UIGuide_joinClan.md +196 -0
  58. package/docs/ui/missions/UIGuide_getAchCategories.md +17 -0
  59. package/docs/ui/missions/UIGuide_getBadges.md +237 -0
  60. package/docs/ui/missions/UIGuide_getMissions.md +268 -0
  61. package/docs/ui/missions/UIGuide_requestMissionClaimReward.md +21 -0
  62. package/docs/ui/missions/UIGuide_requestMissionOptIn.md +16 -0
  63. package/docs/ui/store/UIGuide_buyStoreItem.md +133 -0
  64. package/docs/ui/store/UIGuide_getStoreCategories.md +19 -0
  65. package/docs/ui/store/UIGuide_getStoreItems.md +264 -0
  66. package/docs/ui/store/UIGuide_getStorePurchasedItems.md +122 -0
  67. package/docs/ui/tournaments/UIGuide_getClanTournamentPlayers.md +140 -0
  68. package/docs/ui/tournaments/UIGuide_getTournamentInstanceInfo.md +265 -0
  69. package/docs/ui/tournaments/UIGuide_getTournamentsList.md +236 -0
  70. package/docs/ui/tournaments/UIGuide_registerInTournament.md +156 -0
  71. package/docs/ui/user/UIGuide_getLevels.md +162 -0
  72. package/docs/ui/user/UIGuide_getUserProfile.md +213 -0
  73. package/package.json +3 -3
  74. package/scripts/postdoc-cleanup.js +195 -0
  75. package/src/Missions/MissionsUtils.ts +5 -2
  76. package/src/Store/BuyStoreItemErrorCode.ts +8 -0
  77. package/src/Store/StoreItem.ts +1 -0
  78. package/src/Store/StoreItemPurchased.ts +1 -0
  79. package/src/Store/StoreItemType.ts +1 -1
  80. package/src/Tournaments/TournamentRegistrationError.ts +4 -0
  81. package/src/WSAPI/WSAPI.ts +27 -2007
  82. package/src/WSAPI/WSAPIAvatars.ts +127 -0
  83. package/src/WSAPI/WSAPIBase.ts +93 -0
  84. package/src/WSAPI/WSAPIBonuses.ts +54 -0
  85. package/src/WSAPI/WSAPIClans.ts +417 -0
  86. package/src/WSAPI/WSAPIGamePick.ts +382 -0
  87. package/src/WSAPI/WSAPIGeneral.ts +57 -0
  88. package/src/WSAPI/WSAPIInbox.ts +222 -0
  89. package/src/WSAPI/WSAPIJackpots.ts +212 -0
  90. package/src/WSAPI/WSAPILeaderBoard.ts +40 -0
  91. package/src/WSAPI/WSAPIMiniGames.ts +181 -0
  92. package/src/WSAPI/WSAPIMissions.ts +572 -0
  93. package/src/WSAPI/WSAPIRaffles.ts +175 -0
  94. package/src/WSAPI/WSAPIStore.ts +732 -0
  95. package/src/WSAPI/WSAPITournaments.ts +541 -0
  96. package/src/WSAPI/WSAPITypes.ts +145 -87
  97. package/src/WSAPI/WSAPIUser.ts +456 -0
  98. package/tsconfig.json +17 -1
  99. package/docs/api/classes/WSAPI.md +0 -1927
@@ -1,130 +1,31 @@
1
1
  import { ClassId } from '../Base/ClassId';
2
- import { ActivityTypeLimited, CoreUtils } from '../Core';
3
- import {
4
- SAWSpinsCountPush,
5
- } from '../MiniGames';
2
+ import { SAWSpinsCountPush } from '../MiniGames';
6
3
  import { ECacheContext, OCache } from '../OCache';
7
4
  import { SmarticoAPI } from '../SmarticoAPI';
8
- import {
9
- InboxMarkMessageAction,
10
- LeaderBoardDetailsT,
11
- TAchCategory,
12
- TBuyStoreItemResult,
13
- TGetTranslations,
14
- TInboxMessage,
15
- TInboxMessageBody,
16
- TLevel,
17
- TMiniGamePlayResult,
18
- TMiniGameTemplate,
19
- TMissionClaimRewardResult,
20
- TMissionOptInResult,
21
- TMissionOrBadge,
22
- TSegmentCheckResult,
23
- TStoreCategory,
24
- TStoreItem,
25
- TTournament,
26
- TTournamentDetailed,
27
- TTournamentRegistrationResult,
28
- TUICustomSection,
29
- TUserProfile,
30
- UserLevelExtraCountersT,
31
- TBonus,
32
- TClaimBonusResult,
33
- TMiniGamePlayBatchResult,
34
- TSawHistory,
35
- TRaffle,
36
- TRaffleDraw,
37
- TRaffleDrawRun,
38
- TransformedRaffleClaimPrizeResponse,
39
- TLevelCurrent,
40
- TActivityLog,
41
- TRaffleOptinResponse,
42
- TClans,
43
- TClanInfo,
44
- TClanJoinResult,
45
- TClanTournamentPlayers,
46
- GamesApiResponse,
47
- GamePickRound,
48
- GamePickRoundBoard,
49
- GamePickUserInfo,
50
- GamePickGameInfo,
51
- GamePickRequestParams,
52
- GamePickRoundRequestParams,
53
- TAvatarDefinition,
54
- TAvatarCustomized,
55
- TAvatarPrompt,
56
- TSetAvatarResult,
57
- } from './WSAPITypes';
58
- import { LeaderBoardPeriodType } from '../Leaderboard';
59
- import {
60
- JackpotDetails,
61
- JackpotPot,
62
- JackpotWinPush,
63
- JackpotWinnerHistory,
64
- JackpotsOptinResponse,
65
- JackpotsOptoutRequest,
66
- JackpotsOptoutResponse,
67
- } from '../Jackpots';
68
- import { GetRelatedAchTourResponse } from '../Missions/GetRelatedAchTourResponse';
69
- import { InboxCategories } from '../Inbox/InboxCategories';
70
- import {
71
- drawRunHistoryTransform,
72
- raffleClaimPrizeResponseTransform,
73
- } from '../Raffle';
74
- import { IntUtils } from '../IntUtils';
75
- import { TGetJackpotEligibleGamesResponse } from '../Jackpots/GetJackpotEligibleGamesResponse';
76
- import { InboxReadStatus } from '../Inbox/InboxReadStatus';
77
-
78
- /** @hidden */
79
- const CACHE_DATA_SEC = 30;
80
-
81
- const JACKPOT_TEMPLATE_CACHE_SEC = 30;
82
- const JACKPOT_POT_CACHE_SEC = 1;
83
- const JACKPOT_WINNERS_CACHE_SEC = 30;
84
- const JACKPOT_ELIGIBLE_GAMES_CACHE_SEC = 30;
85
-
86
- /** @hidden */
87
- enum onUpdateContextKey {
88
- Saw = 'saw',
89
- Missions = 'missions',
90
- TournamentList = 'tournamentList',
91
- InboxMessages = 'inboxMessages',
92
- Badges = 'badges',
93
- Levels = 'levels',
94
- StoreItems = 'storeItems',
95
- StoreCategories = 'storeCategories',
96
- AchCategories = 'achCategories',
97
- LeaderBoards = 'leaderBoards',
98
- LevelExtraCounters = 'levelExtraCounters',
99
- Segments = 'segments',
100
- StoreHistory = 'storeHistory',
101
- Jackpots = 'jackpots',
102
- Pots = 'Pots',
103
- CustomSections = 'customSections',
104
- Bonuses = 'bonuses',
105
- Clans = 'clans',
106
- SAWHistory = 'sawHistory',
107
- JackpotWinners = 'jackpotWinners',
108
- Raffles = 'raffles',
109
- JackpotEligibleGames = 'jackpotEligibleGames',
110
- CurrentLevel = 'currentLevel',
111
- InboxUnreadCount = 'inboxUnreadCount',
112
- ActivityLog = 'activityLog',
113
- AvatarsList = 'avatarsList',
114
- AvatarsCustomized = 'avatarsCustomized',
115
- AvatarPrompts = 'avatarPrompts',
116
- }
117
-
118
- /** @group General API */
119
- export class WSAPI {
120
- private onUpdateCallback: Map<onUpdateContextKey, (data: any) => void> = new Map();
121
- private jackpotGetSignature: string = '';
122
- private userExtId: string = null;
123
-
5
+ import { JackpotWinPush, JackpotsOptinResponse, JackpotsOptoutRequest } from '../Jackpots';
6
+ import { onUpdateContextKey } from './WSAPIBase';
7
+ import { WSAPIInbox } from './WSAPIInbox';
8
+
9
+ /**
10
+ * Public surface of the Smartico WebSocket API. The consumer reaches every
11
+ * method on this class via `_smartico.api.X(...)`. The class is the
12
+ * terminator of an inheritance chain that splits the surface into focused
13
+ * domain classes (see `WSAPIBase` → `WSAPIUser` → ... → `WSAPIInbox` →
14
+ * `WSAPI`); each domain class hosts its own subset of methods. Consumers
15
+ * don't need to know about the chain — every method is reachable directly
16
+ * on the `WSAPI` instance via prototype-chain lookup.
17
+ *
18
+ * @group General API
19
+ */
20
+ export class WSAPI extends WSAPIInbox {
124
21
  /** @private */
125
- constructor(private api: SmarticoAPI, userExtId: string = null) {
126
- this.userExtId = userExtId;
127
- OCache.clearAll();
22
+ constructor(api: SmarticoAPI, userExtId: string = null) {
23
+ super(api, userExtId);
24
+
25
+ // Push-subscription wiring. This block must live in the terminator
26
+ // because it references `update*` helpers defined across multiple
27
+ // domain classes; only the terminator has visibility into all of
28
+ // them via the prototype chain.
128
29
  if (this.api.tracker) {
129
30
  const on = this.api.tracker.on;
130
31
 
@@ -149,9 +50,9 @@ export class WSAPI {
149
50
  on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
150
51
  on(ClassId.LOGOUT_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
151
52
  on(ClassId.IDENTIFY_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
152
- on(ClassId.JP_WIN_PUSH, (data: JackpotWinPush) => this.jackpotClearCache());
153
- on(ClassId.JP_OPTOUT_RESPONSE, (data: JackpotsOptoutRequest) => this.jackpotClearCache());
154
- on(ClassId.JP_OPTIN_RESPONSE, (data: JackpotsOptinResponse) => this.jackpotClearCache());
53
+ on(ClassId.JP_WIN_PUSH, (_data: JackpotWinPush) => this.jackpotClearCache());
54
+ on(ClassId.JP_OPTOUT_RESPONSE, (_data: JackpotsOptoutRequest) => this.jackpotClearCache());
55
+ on(ClassId.JP_OPTIN_RESPONSE, (_data: JackpotsOptinResponse) => this.jackpotClearCache());
155
56
  on(ClassId.CLAIM_BONUS_RESPONSE, () => this.updateBonuses());
156
57
  on(ClassId.SAW_DO_SPIN_BATCH_RESPONSE, () => {
157
58
  this.reloadMiniGameTemplate();
@@ -174,1885 +75,4 @@ export class WSAPI {
174
75
  on(ClassId.RAF_OPTIN_RESPONSE, () => this.updateRaffles());
175
76
  }
176
77
  }
177
-
178
- /** @private */
179
- // AA: this method is used from the _smartico script to clear cache when the context is changed,
180
- // e.g. when user is changed or language is changed
181
- public clearCaches() {
182
- OCache.clearAll();
183
- }
184
-
185
- /** Returns information about current user
186
- * Pay attention that this method is synchronous and returns the user profile object immediately, not a promise.
187
- * **Example**:
188
- * ```
189
- * var p = _smartico.api.getUserProfile();
190
- * console.log(p);
191
- * ```
192
- * **Visitor mode: not supported**
193
- * */
194
- public getUserProfile(): TUserProfile {
195
- if (this.api.tracker) {
196
- const o: TUserProfile = Object.assign({}, this.api.tracker.userPublicProps);
197
- o.avatar_url = CoreUtils.avatarUrl(this.api.tracker.userPublicProps.avatar_id, this.api.avatarDomain);
198
- return o;
199
- } else {
200
- throw new Error('Tracker is not initialized, cannot getUserProfile');
201
- }
202
- }
203
-
204
- /** Check if user belongs to specific segments
205
- * **Example**:
206
- * ```
207
- * _smartico.api.checkSegmentMatch(1).then((result) => {
208
- * console.log(result);
209
- * });
210
- * ```
211
- *
212
- * **Visitor mode: not supported**
213
- */
214
- public async checkSegmentMatch(segment_id: number): Promise<boolean> {
215
- const r = await this.api.coreCheckSegments(this.userExtId, [segment_id]);
216
- if (r && r.find((s) => s.segment_id === segment_id && s.is_matching)) {
217
- return true;
218
- } else {
219
- return false;
220
- }
221
- }
222
-
223
- /** Check if user belongs to specific list of segments
224
- * **Example**:
225
- * ```
226
- * _smartico.api.checkSegmentListMatch([1, 2, 3]).then((result) => {
227
- * console.log(result);
228
- * });
229
- * ```
230
- * **Visitor mode: not supported**
231
- */
232
- public async checkSegmentListMatch(segment_ids: number[]): Promise<TSegmentCheckResult[]> {
233
- return await this.api.coreCheckSegments(this.userExtId, Array.isArray(segment_ids) ? segment_ids : [segment_ids]);
234
- }
235
-
236
- /** Returns all the levels available to the current user
237
- * **Example**:
238
- * ```
239
- * _smartico.api.getLevels().then((result) => {
240
- * console.log(result);
241
- * });
242
- * ```
243
- *
244
- * **Example in the Visitor mode**:
245
- * ```
246
- * _smartico.vapi('EN').getLevels().then((result) => {
247
- * console.log(result);
248
- * });
249
- * ```
250
- */
251
- public async getLevels(): Promise<TLevel[]> {
252
- return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(this.userExtId), CACHE_DATA_SEC);
253
- }
254
-
255
- /**
256
- * Returns the current level of the user with extended information including ordinal position and progress.
257
- *
258
- * **Example**:
259
- * ```
260
- * _smartico.api.getCurrentLevel().then((result) => {
261
- * console.log(result);
262
- * });
263
- * ```
264
- *
265
- * **Visitor mode: not supported**
266
- */
267
- public async getCurrentLevel(): Promise<TLevelCurrent> {
268
- return OCache.use(onUpdateContextKey.CurrentLevel, ECacheContext.WSAPI, () => this.api.getLevelCurrent(this.userExtId), CACHE_DATA_SEC);
269
- }
270
-
271
- /** Returns all the missions configured for the current user (server-side scoped, not filtered by Widget visibility).
272
- * The returned missions are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
273
- * Note that each time you call getMissions with a new onUpdate callback, the old one will be overwritten by the new one.
274
- * The onUpdate callback will be called on mission OptIn and the updated missions will be passed to it.
275
- *
276
- * **Example**:
277
- * ```
278
- * _smartico.api.getMissions().then((result) => {
279
- * console.log(result);
280
- * });
281
- * ```
282
- *
283
- * **Example in the Visitor mode**:
284
- * ```
285
- * _smartico.vapi('EN').getMissions().then((result) => {
286
- * console.log(result);
287
- * });
288
- * ```
289
- */
290
- public async getMissions({ onUpdate }: { onUpdate?: (data: TMissionOrBadge[]) => void } = {}): Promise<TMissionOrBadge[]> {
291
- if (onUpdate) {
292
- this.onUpdateCallback.set(onUpdateContextKey.Missions, onUpdate);
293
- }
294
-
295
- return OCache.use(
296
- onUpdateContextKey.Missions,
297
- ECacheContext.WSAPI,
298
- () => this.api.missionsGetItemsT(this.userExtId),
299
- CACHE_DATA_SEC,
300
- );
301
- }
302
-
303
- /**
304
- * Returns all the badges available to the current user
305
- *
306
- * **Visitor mode: not supported**
307
- */
308
- public async getBadges(): Promise<TMissionOrBadge[]> {
309
- return OCache.use(onUpdateContextKey.Badges, ECacheContext.WSAPI, () => this.api.badgetsGetItemsT(this.userExtId), CACHE_DATA_SEC);
310
- }
311
-
312
- /**
313
- * Returns all the bonuses for the current user
314
- * The returned bonuses are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
315
- * Note that each time you call getBonuses with a new onUpdate callback, the old one will be overwritten by the new one.
316
- * The onUpdate callback will be called on bonus claimed and the updated bonuses will be passed to it.
317
- *
318
- * **Visitor mode: not supported**
319
- */
320
- public async getBonuses({ onUpdate }: { onUpdate?: (data: TBonus[]) => void } = {}): Promise<TBonus[]> {
321
- if (onUpdate) {
322
- this.onUpdateCallback.set(onUpdateContextKey.Bonuses, onUpdate);
323
- }
324
-
325
- return OCache.use(onUpdateContextKey.Bonuses, ECacheContext.WSAPI, () => this.api.bonusesGetItemsT(this.userExtId), CACHE_DATA_SEC);
326
- }
327
-
328
- /**
329
- * Claim the bonus by bonus_id. Returns the err_code in case of success or error.
330
- * Note that this method can be used only on integrations where originally failed bonus can be claimed again.
331
- * For example, user won a bonus in the mini-game, but Operator rejected this bonus.
332
- * This bonus will be available for the user to claim again.
333
- *
334
- * **Visitor mode: not supported**
335
- */
336
- public async claimBonus(bonus_id: number): Promise<TClaimBonusResult> {
337
- const r = await this.api.bonusClaimItem(this.userExtId, bonus_id);
338
-
339
- const o: TClaimBonusResult = {
340
- err_code: r.errCode,
341
- err_message: r.errMsg,
342
- success: r.success,
343
- };
344
-
345
- return o;
346
- }
347
-
348
- /**
349
- * Returns the extra counters for the current user level.
350
- * These are counters that are configured for each Smartico client separately by request.
351
- * For example 1st counter could be total wagering amount, 2nd counter could be total deposit amount, etc.
352
- *
353
- * **Example**:
354
- * ```
355
- * _smartico.api.getUserLevelExtraCounters().then((result) => {
356
- * console.log(result);
357
- * });
358
- * ```
359
- *
360
- * **Visitor mode: not supported**
361
- */
362
- public async getUserLevelExtraCounters(): Promise<UserLevelExtraCountersT> {
363
- return OCache.use(
364
- onUpdateContextKey.LevelExtraCounters,
365
- ECacheContext.WSAPI,
366
- () => this.api.getUserGamificationInfoT(this.userExtId),
367
- CACHE_DATA_SEC,
368
- );
369
- }
370
-
371
- /**
372
- *
373
- * Returns all the store items available to the current user
374
- * The returned store items are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
375
- * Note that each time you call getStoreItems with a new onUpdate callback, the old one will be overwritten by the new one.
376
- * The onUpdate callback will be called on purchase of the store item.
377
- *
378
- * **Example**:
379
- * ```
380
- * _smartico.api.getStoreItems().then((result) => {
381
- * console.log(result);
382
- * });
383
- * ```
384
- *
385
- * **Example in the Visitor mode**:
386
- * ```
387
- * _smartico.vapi('EN').getStoreItems().then((result) => {
388
- * console.log(result);
389
- * });
390
- * ```
391
- * @param params
392
- * @param params.onUpdate - callback function that will be called when the store items are updated
393
- */
394
-
395
- public async getStoreItems({ onUpdate }: { onUpdate?: (data: TStoreItem[]) => void } = {}): Promise<TStoreItem[]> {
396
- if (onUpdate) {
397
- this.onUpdateCallback.set(onUpdateContextKey.StoreItems, onUpdate);
398
- }
399
- return OCache.use(
400
- onUpdateContextKey.StoreItems,
401
- ECacheContext.WSAPI,
402
- () => this.api.storeGetItemsT(this.userExtId),
403
- CACHE_DATA_SEC,
404
- );
405
- }
406
-
407
- /** Buy the specific shop item by item_id. Returns the err_code in case of success or error.
408
- * **Example**:
409
- * ```
410
- * _smartico.api.buyStoreItem(1).then((result) => {
411
- * console.log(result);
412
- * });
413
- * ```
414
- *
415
- * **Visitor mode: not supported**
416
- */
417
- public async buyStoreItem(item_id: number): Promise<TBuyStoreItemResult> {
418
- const r = await this.api.buyStoreItem(this.userExtId, item_id);
419
-
420
- const o: TBuyStoreItemResult = {
421
- err_code: r.errCode,
422
- err_message: r.errMsg,
423
- };
424
-
425
- return o;
426
- }
427
-
428
- /**
429
- *
430
- * Returns store categories
431
- *
432
- * **Example**:
433
- * ```
434
- * _smartico.api.getStoreCategories().then((result) => {
435
- * console.log(result);
436
- * });
437
- * ```
438
- *
439
- * **Example in the Visitor mode**:
440
- * ```
441
- * _smartico.vapi('EN').getStoreCategories().then((result) => {
442
- * console.log(result);
443
- * });
444
- * ```
445
- */
446
- public async getStoreCategories(): Promise<TStoreCategory[]> {
447
- return OCache.use(
448
- onUpdateContextKey.StoreCategories,
449
- ECacheContext.WSAPI,
450
- () => this.api.storeGetCategoriesT(this.userExtId),
451
- CACHE_DATA_SEC,
452
- );
453
- }
454
-
455
- /**
456
- * Returns purchased items based on the provided parameters. "Limit" and "offset" indicate the range of items to be fetched.
457
- * The maximum number of items per request is limited to 20.
458
- * You can leave this params empty and by default it will return list of purchased items ranging from 0 to 20.
459
- * The returned store items are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
460
- * Note that each time you call getStorePurchasedItems with a new onUpdate callback, the old one will be overwritten by the new one.
461
- * The onUpdate callback will be called on purchase of the store item and the last 20 items will be passed to it.
462
- *
463
- * **Example**:
464
- * ```
465
- * _smartico.api.getStorePurchasedItems().then((result) => {
466
- * console.log(result);
467
- * });
468
- * ```
469
- *
470
- * **Visitor mode: not supported**
471
- */
472
-
473
- public async getStorePurchasedItems({
474
- limit,
475
- offset,
476
- onUpdate,
477
- }: { limit?: number; offset?: number; onUpdate?: (data: TStoreItem[]) => void } = {}): Promise<TStoreItem[]> {
478
- if (onUpdate) {
479
- this.onUpdateCallback.set(onUpdateContextKey.StoreHistory, onUpdate);
480
- }
481
- return OCache.use(
482
- onUpdateContextKey.StoreHistory,
483
- ECacheContext.WSAPI,
484
- () => this.api.storeGetPurchasedItemsT(this.userExtId, limit, offset),
485
- CACHE_DATA_SEC,
486
- );
487
- }
488
-
489
- /**
490
- * Returns missions & badges categories
491
- *
492
- * **Example**:
493
- * ```
494
- * _smartico.api.getAchCategories().then((result) => {
495
- * console.log(result);
496
- * });
497
- * ```
498
- *
499
- * **Example in the Visitor mode**:
500
- * ```
501
- * _smartico.vapi('EN').getAchCategories().then((result) => {
502
- * console.log(result);
503
- * });
504
- * ```
505
- *
506
- * */
507
- public async getAchCategories(): Promise<TAchCategory[]> {
508
- return OCache.use(
509
- onUpdateContextKey.AchCategories,
510
- ECacheContext.WSAPI,
511
- () => this.api.achGetCategoriesT(this.userExtId),
512
- CACHE_DATA_SEC,
513
- );
514
- }
515
-
516
- /**
517
- * Returns list of custom sections
518
- *
519
- * **Example**:
520
- * ```
521
- * _smartico.api.getCustomSections().then((result) => {
522
- * console.log(result);
523
- * });
524
- * ```
525
- *
526
- * **Example in the Visitor mode**:
527
- * ```
528
- * _smartico.vapi('EN').getCustomSections().then((result) => {
529
- * console.log(result);
530
- * });
531
- * ```
532
- *
533
- * */
534
- public async getCustomSections(): Promise<TUICustomSection[]> {
535
- return OCache.use(
536
- onUpdateContextKey.CustomSections,
537
- ECacheContext.WSAPI,
538
- () => this.api.customSectionsGetT(this.userExtId),
539
- CACHE_DATA_SEC,
540
- );
541
- }
542
-
543
- /**
544
- * Returns the list of mini-games configured for the current user (not filtered by spin availability or Widget visibility).
545
- * 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.
546
- * 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.
547
- *
548
- * **Example**:
549
- * ```
550
- * _smartico.api.getMiniGames().then((result) => {
551
- * console.log(result);
552
- * });
553
- * ```
554
- *
555
- * **Example in the Visitor mode**:
556
- * ```
557
- * _smartico.vapi('EN').getMiniGames().then((result) => {
558
- * console.log(result);
559
- * });
560
- * ```
561
- *
562
- */
563
- public async getMiniGames({ onUpdate }: { onUpdate?: (data: TMiniGameTemplate[]) => void } = {}): Promise<
564
- TMiniGameTemplate[]
565
- > {
566
- if (onUpdate) {
567
- this.onUpdateCallback.set(onUpdateContextKey.Saw, onUpdate);
568
- }
569
-
570
- return OCache.use(onUpdateContextKey.Saw, ECacheContext.WSAPI, () => this.api.sawGetTemplatesT(this.userExtId), CACHE_DATA_SEC);
571
- }
572
-
573
- /**
574
- * Returns the list of mini-games based on the provided parameters. "Limit" and "offset" indicate the range of items to be fetched.
575
- * The maximum number of items per request is limited to 20.
576
- * You can leave this params empty and by default it will return list of mini-games ranging from 0 to 20.
577
- * The returned list of mini-games history is cached for 30 seconds.
578
- *
579
- * **Example**:
580
- * ```
581
- * _smartico.api.getMiniGamesHistory().then((result) => {
582
- * console.log(result);
583
- * });
584
- * ```
585
- *
586
- * **Visitor mode: not supported**
587
- */
588
-
589
- public async getMiniGamesHistory({
590
- limit,
591
- offset,
592
- saw_template_id,
593
- }: {
594
- limit?: number;
595
- offset?: number;
596
- saw_template_id?: number;
597
- }): Promise<TSawHistory[]> {
598
- return OCache.use(
599
- onUpdateContextKey.SAWHistory,
600
- ECacheContext.WSAPI,
601
- () => this.api.getSawWinningHistoryT(this.userExtId, limit, offset, saw_template_id),
602
- CACHE_DATA_SEC,
603
- );
604
- }
605
-
606
- /**
607
- * Plays the specified by template_id mini-game on behalf of user and returns prize_id or err_code
608
- * 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.
609
- * 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.
610
- *
611
- * **Example**:
612
- * ```
613
- * _smartico.api.playMiniGame(55).then((result) => {
614
- * console.log(result);
615
- * });
616
- * ```
617
- *
618
- * **Visitor mode: not supported**
619
- */
620
- public async playMiniGame(
621
- template_id: number,
622
- { onUpdate }: { onUpdate?: (data: TMiniGameTemplate[]) => void } = {},
623
- ): Promise<TMiniGamePlayResult> {
624
- if (onUpdate) {
625
- this.onUpdateCallback.set(onUpdateContextKey.Saw, onUpdate);
626
- }
627
-
628
- const r = await this.api.sawSpinRequest(this.userExtId, template_id);
629
- this.api.doAcknowledgeRequest(this.userExtId, r.request_id);
630
-
631
- const o: TMiniGamePlayResult = {
632
- err_code: r.errCode,
633
- err_message: r.errMsg,
634
- prize_id: r.saw_prize_id,
635
- };
636
-
637
- return o;
638
- }
639
-
640
- /**
641
- * Sends the acknowledge request with specific client_request_id from minigame history in order to claim prize
642
- * **Example**:
643
- * ```
644
- * _smartico.api.miniGameWinAcknowledgeRequest('2a189322-31bb-4119-b943-bx7868ff8dc3').then((result) => {
645
- * console.log(result);
646
- * });
647
- * ```
648
- */
649
- public async miniGameWinAcknowledgeRequest(request_id: string) {
650
- return this.api.doAcknowledgeRequest(this.userExtId, request_id);
651
- }
652
-
653
- /**
654
- * Plays the specified by template_id mini-game on behalf of user spin_count times and returns array of the prizes
655
- * 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.
656
- * 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.
657
- *
658
- * **Example**:
659
- * ```
660
- * _smartico.api.playMiniGameBatch(55, 10).then((result) => {
661
- * console.log(result);
662
- * });
663
- * ```
664
- * **Visitor mode: not supported**
665
- */
666
- public async playMiniGameBatch(
667
- template_id: number,
668
- spin_count: number,
669
- { onUpdate }: { onUpdate?: (data: TMiniGameTemplate[]) => void } = {},
670
- ): Promise<TMiniGamePlayBatchResult[]> {
671
- if (onUpdate) {
672
- this.onUpdateCallback.set(onUpdateContextKey.Saw, onUpdate);
673
- }
674
-
675
- const response = await this.api.sawSpinBatchRequest(this.userExtId, template_id, spin_count);
676
-
677
- const request_ids = response.results.map((result) => result.request_id);
678
- this.api.doAcknowledgeBatchRequest(this.userExtId, request_ids);
679
-
680
- const o: TMiniGamePlayBatchResult[] = response.results.map((result) => ({
681
- errCode: result.errCode,
682
- errMessage: result.errMsg,
683
- saw_prize_id: result.saw_prize_id,
684
- jackpot_amount: result.jackpot_amount,
685
- first_spin_in_period: result.first_spin_in_period,
686
- }));
687
-
688
- return o;
689
- }
690
-
691
- /**
692
- * Requests an opt-in for the specified mission_id. Returns the err_code.
693
- *
694
- * **Visitor mode: not supported**
695
- */
696
- public async requestMissionOptIn(mission_id: number): Promise<TMissionOptInResult> {
697
- const r = await this.api.missionOptIn(this.userExtId, mission_id);
698
-
699
- const o: TMissionOptInResult = {
700
- err_code: r.errCode,
701
- err_message: r.errMsg,
702
- };
703
-
704
- return o;
705
- }
706
-
707
- /**
708
- * Request for claim reward for the specified mission id. Returns the err_code.
709
- *
710
- * **Visitor mode: not supported**
711
- */
712
- public async requestMissionClaimReward(mission_id: number, ach_completed_id: number): Promise<TMissionClaimRewardResult> {
713
- const r = await this.api.missionClaimPrize(this.userExtId, mission_id, ach_completed_id);
714
-
715
- const o: TMissionClaimRewardResult = {
716
- err_code: r.errCode,
717
- err_message: r.errMsg,
718
- };
719
-
720
- return o;
721
- }
722
-
723
- /** Returns all the active instances of tournaments
724
- * The returned list is cached for 30 seconds. But you can pass the onUpdate callback as a parameter. Note that each time you call getTournamentsList with a new onUpdate callback, the old one will be overwritten by the new one.
725
- * The onUpdate callback will be called when the user has registered in a tournament. Updated list will be passed to onUpdate callback.
726
- *
727
- * **Example**:
728
- * ```
729
- * _smartico.api.getTournamentsList().then((result) => {
730
- * console.log(result);
731
- * });
732
- * ```
733
- *
734
- * **Example in the Visitor mode**:
735
- * ```
736
- * _smartico.vapi('EN').getTournamentsList().then((result) => {
737
- * console.log(result);
738
- * });
739
- * ```
740
- * */
741
- public async getTournamentsList({ onUpdate }: { onUpdate?: (data: TTournament[]) => void } = {}): Promise<TTournament[]> {
742
- if (onUpdate) {
743
- this.onUpdateCallback.set(onUpdateContextKey.TournamentList, onUpdate);
744
- }
745
-
746
- return OCache.use(
747
- onUpdateContextKey.TournamentList,
748
- ECacheContext.WSAPI,
749
- () => this.api.tournamentsGetLobbyT(this.userExtId),
750
- CACHE_DATA_SEC,
751
- );
752
- }
753
-
754
- /**
755
- * Returns clans list payload for the current user.
756
- * The returned payload is cached for 30 seconds.
757
- * If onUpdate is passed, it will be called when clans response is received.
758
- *
759
- * **Visitor mode: not supported**
760
- */
761
- public async getClans({ onUpdate }: { onUpdate?: (data: TClans) => void } = {}): Promise<TClans> {
762
- if (onUpdate) {
763
- this.onUpdateCallback.set(onUpdateContextKey.Clans, onUpdate);
764
- }
765
-
766
- return OCache.use(
767
- onUpdateContextKey.Clans,
768
- ECacheContext.WSAPI,
769
- () => this.api.clansGetListT(this.userExtId),
770
- CACHE_DATA_SEC,
771
- );
772
- }
773
-
774
- /**
775
- * Returns detailed information for a specific clan including its members.
776
- *
777
- * **Visitor mode: not supported**
778
- */
779
- public async getClanInfo(clanId: number): Promise<TClanInfo> {
780
- return this.api.clansGetInfoT(this.userExtId, clanId);
781
- }
782
-
783
- /**
784
- * Joins a clan on behalf of the current user.
785
- *
786
- * **Visitor mode: not supported**
787
- */
788
- public async joinClan(clanId: number): Promise<TClanJoinResult> {
789
- return this.api.clanJoin(this.userExtId, clanId);
790
- }
791
-
792
- /**
793
- * Returns detailed information for a specific tournament instance; the response includes tournament info and the leaderboard of players
794
- *
795
- * **Example**:
796
- * ```
797
- * _smartico.api.getTournamentsList().then((result) => {
798
- * if (result.length > 0) {
799
- * _smartico.api.getTournamentInstanceInfo(result[0].instance_id).then((result) => {
800
- * console.log(result);
801
- * });
802
- * }
803
- * });
804
- * ```
805
- *
806
- * **Example in the Visitor mode**:
807
- * ```
808
- * _smartico.vapi('EN').getTournamentsList().then((result) => {
809
- * if (result.length > 0) {
810
- * _smartico.vapi('EN').getTournamentInstanceInfo(result[0].instance_id).then((result) => {
811
- * console.log(result);
812
- * });
813
- * }
814
- * });
815
- * ```
816
- */
817
- public async getTournamentInstanceInfo(tournamentInstanceId: number): Promise<TTournamentDetailed> {
818
- return this.api.tournamentsGetInfoT(this.userExtId, tournamentInstanceId);
819
- }
820
-
821
- /**
822
- * Returns the players of a specific clan in a clan-based tournament.
823
- *
824
- * **Visitor mode: not supported**
825
- */
826
- public async getClanTournamentPlayers(tournamentInstanceId: number, clanId: number): Promise<TClanTournamentPlayers> {
827
- return this.api.clanTournamentGetPlayers(this.userExtId, tournamentInstanceId, clanId);
828
- }
829
-
830
- /**
831
- * Requests registration for the specified tournament instance. Returns the err_code.
832
- *
833
- * **Visitor mode: not supported**
834
- */
835
- public async registerInTournament(tournamentInstanceId: number): Promise<TTournamentRegistrationResult> {
836
- const r = await this.api.registerInTournament(this.userExtId, tournamentInstanceId);
837
-
838
- const o: TTournamentRegistrationResult = {
839
- err_code: r.errCode,
840
- err_message: r.errMsg,
841
- };
842
-
843
- return o;
844
- }
845
-
846
- /**
847
- * Returns the leaderboard for the current type (default is Daily). If getPreviousPeriod is passed as true, a leaderboard for the previous period for the current type will be returned.
848
- * For example, if the type is Weekly and getPreviousPeriod is true, a leaderboard for the previous week will be returned.
849
- *
850
- * **Example**:
851
- * ```
852
- * _smartico.api.getLeaderBoard(1).then((result) => {
853
- * console.log(result);
854
- * });
855
- * ```
856
- *
857
- * **Example in the Visitor mode**:
858
- * ```
859
- * _smartico.vapi('EN').getLeaderBoard(1).then((result) => {
860
- * console.log(result);
861
- * });
862
- * ```
863
- */
864
- public async getLeaderBoard(periodType: LeaderBoardPeriodType, getPreviousPeriod?: boolean): Promise<LeaderBoardDetailsT> {
865
- return OCache.use(
866
- onUpdateContextKey.LeaderBoards,
867
- ECacheContext.WSAPI,
868
- () => this.api.leaderboardsGetT(this.userExtId, periodType, getPreviousPeriod),
869
- CACHE_DATA_SEC,
870
- );
871
- }
872
-
873
- /** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
874
- * The maximum number of messages per request is limited to 20.
875
- * An indicator "onlyFavorite" can be passed to get only messages marked as favorites.
876
- * An indicator "read_status" can be passed to get only messages marked as read or unread.
877
- * You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
878
- * This function returns a list of messages without the body of each message.
879
- * To get the body of the message you need to call getInboxMessageBody function and pass the message guid contained in each message of this request.
880
- * All other action like mark as read, favorite, delete, etc. can be done using this message GUID.
881
- * The "onUpdate" callback will be triggered when the user receives a new message. It will provide an updated list of messages, ranging from 0 to 20, to the onUpdate callback function.
882
- *
883
- * **Visitor mode: not supported**
884
- *
885
- * @param params
886
- */
887
- public async getInboxMessages({
888
- from,
889
- to,
890
- onlyFavorite,
891
- categoryId,
892
- read_status,
893
- onUpdate,
894
- }: {
895
- from?: number;
896
- to?: number;
897
- onlyFavorite?: boolean;
898
- categoryId?: InboxCategories;
899
- read_status?: InboxReadStatus;
900
- onUpdate?: (data: TInboxMessage[]) => void;
901
- } = {}): Promise<TInboxMessage[]> {
902
- if (onUpdate) {
903
- this.onUpdateCallback.set(onUpdateContextKey.InboxMessages, onUpdate);
904
- }
905
- return await this.api.getInboxMessagesT(this.userExtId, from, to, onlyFavorite, categoryId, read_status);
906
- }
907
-
908
- /**
909
- * Returns inbox unread count.
910
- *
911
- * **Visitor mode: not supported**
912
- * @param params
913
- */
914
- public async getInboxUnreadCount({ onUpdate }: { onUpdate?: (unread_count: number) => void } = {}): Promise<number> {
915
- if (onUpdate) {
916
- this.onUpdateCallback.set(onUpdateContextKey.InboxUnreadCount, onUpdate);
917
- }
918
- return OCache.use(
919
- onUpdateContextKey.InboxUnreadCount,
920
- ECacheContext.WSAPI,
921
- () => this.api.getInboxUnreadCountT(this.userExtId),
922
- CACHE_DATA_SEC,
923
- );
924
- }
925
-
926
- /**
927
- * Returns the message body of the specified message guid.
928
- *
929
- * **Visitor mode: not supported**
930
- */
931
- public async getInboxMessageBody(messageGuid: string): Promise<TInboxMessageBody> {
932
- return await this.api.getInboxMessageBodyT(messageGuid);
933
- }
934
-
935
- /**
936
- * Requests to mark inbox message with specified guid as read
937
- *
938
- * **Visitor mode: not supported**
939
- */
940
- public async markInboxMessageAsRead(messageGuid: string): Promise<InboxMarkMessageAction> {
941
- const r = await this.api.markInboxMessageRead(this.userExtId, messageGuid);
942
-
943
- return {
944
- err_code: r.errCode,
945
- err_message: r.errMsg,
946
- };
947
- }
948
-
949
- /**
950
- * Requests to mark all inbox messages as read
951
- *
952
- * **Visitor mode: not supported**
953
- */
954
- public async markAllInboxMessagesAsRead(): Promise<InboxMarkMessageAction> {
955
- const r = await this.api.markAllInboxMessageRead(this.userExtId);
956
-
957
- return {
958
- err_code: r.errCode,
959
- err_message: r.errMsg,
960
- };
961
- }
962
-
963
- /**
964
- * Requests to mark inbox message with specified guid as favorite. Pass mark true to add message to favorite and false to remove.
965
- *
966
- * **Visitor mode: not supported**
967
- */
968
- public async markUnmarkInboxMessageAsFavorite(messageGuid: string, mark: boolean): Promise<InboxMarkMessageAction> {
969
- const r = await this.api.markUnmarkInboxMessageAsFavorite(this.userExtId, messageGuid, mark);
970
-
971
- return {
972
- err_code: r.errCode,
973
- err_message: r.errMsg,
974
- };
975
- }
976
-
977
- /**
978
- * Requests to delete inbox message
979
- *
980
- * **Visitor mode: not supported**
981
- */
982
-
983
- public async deleteInboxMessage(messageGuid: string): Promise<InboxMarkMessageAction> {
984
- const r = await this.api.deleteInboxMessage(this.userExtId, messageGuid);
985
-
986
- return {
987
- err_code: r.errCode,
988
- err_message: r.errMsg,
989
- };
990
- }
991
-
992
- /**
993
- * Requests to delete all inbox messages
994
- *
995
- * **Visitor mode: not supported**
996
- */
997
-
998
- public async deleteAllInboxMessages(): Promise<InboxMarkMessageAction> {
999
- const r = await this.api.deleteAllInboxMessages(this.userExtId);
1000
-
1001
- return {
1002
- err_code: r.errCode,
1003
- err_message: r.errMsg,
1004
- };
1005
- }
1006
-
1007
- /**
1008
- * Requests translations for the given language. Returns the object including translation key/translation value pairs. All possible translation keys defined in the back office.
1009
- */
1010
- public async getTranslations(lang_code: string): Promise<TGetTranslations> {
1011
- const r = await this.api.getTranslationsT(this.userExtId, lang_code, []);
1012
-
1013
- return {
1014
- translations: r.translations,
1015
- };
1016
- }
1017
-
1018
- /**
1019
- * Reports an impression event for an engagement (when engagement content is displayed to the user).
1020
- * Use this method to track when users view engagement content such as inbox messages, popups.
1021
- * When using for Inbox cases, you need to use message guid as engagement_uid, and pass 31 as activityType.
1022
- *
1023
- * **Example**:
1024
- * ```
1025
- * _smartico.api.reportImpressionEvent({
1026
- * engagement_uid: 'abc123-def456',
1027
- * activityType: 31 // Inbox
1028
- * });
1029
- * ```
1030
- *
1031
- * **Visitor mode: not supported**
1032
- *
1033
- * @param params - Event parameters
1034
- * @param params.engagement_uid - Unique identifier for the engagement
1035
- * @param params.activityType - Type of engagement activity (Popup=30, Inbox=31)
1036
- */
1037
- public reportImpressionEvent({
1038
- engagement_uid,
1039
- activityType,
1040
- }: {
1041
- engagement_uid: string;
1042
- activityType: ActivityTypeLimited | number;
1043
- }): void {
1044
- this.api.reportEngagementImpression(this.userExtId, engagement_uid, activityType);
1045
- }
1046
-
1047
- /**
1048
- * Reports a click/action event for an engagement (when user interacts with engagement content).
1049
- * Use this method to track when users click on or interact with engagement content such as inbox messages, popups.
1050
- * When using for Inbox cases, you need to use message guid as engagement_uid, and pass 31 as activityType, and pass the action/deeplink that was triggered by the user interaction as action.
1051
- *
1052
- *
1053
- * **Example**:
1054
- * ```
1055
- * _smartico.api.reportClickEvent({
1056
- * engagement_uid: 'abc123-def456',
1057
- * activityType: 31 // Inbox
1058
- * action: 'dp:gf_missions'
1059
- * });
1060
- * ```
1061
- *
1062
- * **Visitor mode: not supported**
1063
- *
1064
- * @param params - Event parameters
1065
- * @param params.engagement_uid - Unique identifier for the engagement
1066
- * @param params.activityType - Type of engagement activity (Popup=30, Inbox=31)
1067
- * @param params.action - Optional action/deeplink that was triggered by the user interaction
1068
- */
1069
- public reportClickEvent({
1070
- engagement_uid,
1071
- activityType,
1072
- action,
1073
- }: {
1074
- engagement_uid: string;
1075
- activityType: ActivityTypeLimited | number;
1076
- action?: string;
1077
- }): void {
1078
- this.api.reportEngagementAction(this.userExtId, engagement_uid, activityType, action);
1079
- }
1080
-
1081
- /**
1082
- * Returns the activity log for a user within a specified time range.
1083
- * The response includes both points changes and gems/diamonds changes.
1084
- * Each log entry contains information about the change amount, balance, and source.
1085
- * The returned list is cached for 30 seconds.
1086
- * You can pass the onUpdate callback as a parameter, it will be called every time the activity log is updated and will provide the updated list of activity logs for the last 10 minutes.
1087
- *
1088
- * **Example**:
1089
- * ```
1090
- * const startTime = Math.floor(Date.now() / 1000) - 86400 * 30; // 30 days ago
1091
- * const endTime = Math.floor(Date.now() / 1000); // now
1092
- *
1093
- * _smartico.api.getActivityLog({
1094
- * startTimeSeconds: startTime,
1095
- * endTimeSeconds: endTime,
1096
- * from: 0,
1097
- * to: 50,
1098
- * onUpdate: (data) => console.log('Updated:', data)
1099
- * }).then((result) => {
1100
- * console.log(result);
1101
- * });
1102
- * ```
1103
- *
1104
- * **Visitor mode: not supported**
1105
- *
1106
- * @param params - Activity log parameters
1107
- * @param params.startTimeSeconds - Start time in seconds (epoch timestamp)
1108
- * @param params.endTimeSeconds - End time in seconds (epoch timestamp)
1109
- * @param params.from - Start index of records to return
1110
- * @param params.to - End index of records to return
1111
- * @param params.onUpdate - Optional callback function that will be called when the activity log is updated
1112
- */
1113
- public async getActivityLog({
1114
- startTimeSeconds,
1115
- endTimeSeconds,
1116
- from,
1117
- to,
1118
- onUpdate,
1119
- }: {
1120
- startTimeSeconds: number;
1121
- endTimeSeconds: number;
1122
- from: number;
1123
- to: number;
1124
- onUpdate?: (data: TActivityLog[]) => void;
1125
- }): Promise<TActivityLog[]> {
1126
-
1127
- if (onUpdate) {
1128
- this.onUpdateCallback.set(onUpdateContextKey.ActivityLog, onUpdate);
1129
- }
1130
-
1131
- return await OCache.use(
1132
- onUpdateContextKey.ActivityLog,
1133
- ECacheContext.WSAPI,
1134
- () => this.api.getActivityLogT(this.userExtId, startTimeSeconds, endTimeSeconds, from, to),
1135
- CACHE_DATA_SEC,
1136
- );
1137
- }
1138
-
1139
- /**
1140
- * Returns the active rounds for the specified MatchX or Quiz game.
1141
- * Each round includes its events (matches/questions) along with the current user's selections and scores.
1142
- *
1143
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1144
- *
1145
- * **Response** `GamesApiResponse<GamePickRound[]>`:
1146
- * - `errCode` - 0 on success
1147
- * - `data` - Array of rounds, each containing:
1148
- * - `round_id`, `round_name` - Round identifier and display name
1149
- * - `open_date`, `last_bet_date` - Timestamps (ms) for round open and betting deadline
1150
- * - `is_active_now`, `is_resolved` - Round state flags
1151
- * - `round_status_id` - Round status: -1 (active), 2 (no more bets), 3 (all events resolved), 4 (round resolved)
1152
- * - `score_full_win`, `score_part_win`, `score_lost` - Scoring rules per prediction outcome
1153
- * - `user_score` - Current user's total score in this round
1154
- * - `user_placed_bet` - Whether the user has submitted predictions
1155
- * - `has_open_for_bet_events` - Whether there are events still open for betting
1156
- * - `events[]` - Array of events with `gp_event_id`, `market_type_id`, `event_meta` (team names, images, sport), `match_date`, `is_open_for_bets`, `odds_details`, and user selection fields
1157
- *
1158
- * **Example**:
1159
- * ```
1160
- * _smartico.api.gamePickGetActiveRounds({
1161
- * saw_template_id: 1083,
1162
- * }).then((result) => {
1163
- * console.log(result.data); // GamePickRound[]
1164
- * result.data.forEach(round => {
1165
- * console.log(round.round_name, round.events.length);
1166
- * });
1167
- * });
1168
- * ```
1169
- *
1170
- * **Visitor mode: not supported**
1171
- */
1172
- public async gamePickGetActiveRounds(props: GamePickRequestParams): Promise<GamesApiResponse<GamePickRound[]>> {
1173
- if (!props.saw_template_id) {
1174
- throw new Error('saw_template_id is required');
1175
- }
1176
- return this.api.gpGetActiveRounds(props.saw_template_id);
1177
- }
1178
-
1179
- /**
1180
- * Returns a single active round for the specified MatchX or Quiz game.
1181
- * The round includes full event details with the current user's selections.
1182
- *
1183
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1184
- * @param props.round_id - The specific round to retrieve
1185
- *
1186
- * **Response** `GamesApiResponse<GamePickRound>`:
1187
- * - `errCode` - 0 on success
1188
- * - `data` - Single round object with the same structure as in `gamePickGetActiveRounds`,
1189
- * including `events[]` with full event details, user selections, and resolution info
1190
- *
1191
- * **Example**:
1192
- * ```
1193
- * _smartico.api.gamePickGetActiveRound({
1194
- * saw_template_id: 1083,
1195
- * round_id: 31652,
1196
- * }).then((result) => {
1197
- * console.log(result.data.round_name, result.data.events.length);
1198
- * console.log(result.data.user_score, result.data.user_placed_bet);
1199
- * });
1200
- * ```
1201
- *
1202
- * **Visitor mode: not supported**
1203
- */
1204
- public async gamePickGetActiveRound(props: GamePickRoundRequestParams): Promise<GamesApiResponse<GamePickRound>> {
1205
- if (!props.saw_template_id) {
1206
- throw new Error('saw_template_id is required');
1207
- }
1208
- if (!props.round_id) {
1209
- throw new Error('round_id is required');
1210
- }
1211
- return this.api.gpGetActiveRound(props.saw_template_id, props.round_id);
1212
- }
1213
-
1214
- /**
1215
- * Returns the history of all rounds (including resolved ones) for the specified MatchX or Quiz game.
1216
- * Each round contains full event details with results and the current user's predictions.
1217
- *
1218
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1219
- *
1220
- * **Response** `GamesApiResponse<GamePickRound[]>`:
1221
- * - `errCode` - 0 on success
1222
- * - `data` - Array of rounds ordered by `round_row_id` descending (newest first).
1223
- * Each round has the same structure as in `gamePickGetActiveRounds`, including resolved events
1224
- * with `resolution_type_id` (0=None, 2=Lost, 3=PartialWin, 4=FullWin) and `resolution_score`
1225
- *
1226
- * **Example**:
1227
- * ```
1228
- * _smartico.api.gamePickGetHistory({
1229
- * saw_template_id: 1083,
1230
- * }).then((result) => {
1231
- * result.data.forEach(round => {
1232
- * console.log(round.round_name, 'Score:', round.user_score, 'Resolved:', round.is_resolved);
1233
- * });
1234
- * });
1235
- * ```
1236
- *
1237
- * **Visitor mode: not supported**
1238
- */
1239
- public async gamePickGetHistory(props: GamePickRequestParams): Promise<GamesApiResponse<GamePickRound[]>> {
1240
- if (!props.saw_template_id) {
1241
- throw new Error('saw_template_id is required');
1242
- }
1243
- return this.api.gpGetGamesHistory(props.saw_template_id);
1244
- }
1245
-
1246
- /**
1247
- * Returns the leaderboard for a specific round within a MatchX or Quiz game.
1248
- * Use `round_id = -1` (AllRoundsGameBoardID) to get the season/overall leaderboard across all rounds.
1249
- *
1250
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1251
- * @param props.round_id - The round to get the leaderboard for. Use -1 for overall/seasonal leaderboard
1252
- *
1253
- * **Response** `GamesApiResponse<GamePickRoundBoard>`:
1254
- * - `errCode` - 0 on success
1255
- * - `data` - Leaderboard object containing:
1256
- * - Round base fields (`round_id`, `round_name`, `open_date`, `last_bet_date`, etc.)
1257
- * - `users[]` - Ranked list of players, each with:
1258
- * - `ext_user_id`, `int_user_id` - User identifiers
1259
- * - `public_username`, `avatar_url` - Display info (usernames may be masked based on label settings)
1260
- * - `gp_position` - Leaderboard rank (null if not yet ranked)
1261
- * - `resolution_score` - Total score in this round
1262
- * - `full_wins_count`, `part_wins_count`, `lost_count` - Prediction outcome counts
1263
- * - `my_user` - Current user's entry (same fields as above), or null if user hasn't participated
1264
- *
1265
- * **Example**:
1266
- * ```
1267
- * _smartico.api.gamePickGetBoard({
1268
- * saw_template_id: 1083,
1269
- * round_id: 31652,
1270
- * }).then((result) => {
1271
- * console.log('Top players:', result.data.users);
1272
- * console.log('My position:', result.data.my_user?.gp_position);
1273
- * });
1274
- * ```
1275
- *
1276
- * **Visitor mode: not supported**
1277
- */
1278
- public async gamePickGetBoard(props: GamePickRoundRequestParams): Promise<GamesApiResponse<GamePickRoundBoard>> {
1279
- if (!props.saw_template_id) {
1280
- throw new Error('saw_template_id is required');
1281
- }
1282
- if (!props.round_id) {
1283
- throw new Error('round_id is required');
1284
- }
1285
- return this.api.gpGetGameBoard(props.saw_template_id, props.round_id);
1286
- }
1287
-
1288
- /**
1289
- * Submits score predictions for a round in a MatchX game.
1290
- * Sends the round object with user selections for all events at once.
1291
- * Each event must include `team1_user_selection` and `team2_user_selection` representing predicted scores.
1292
- * If the user hasn't placed bets before, one game attempt (spin) will be consumed.
1293
- * Predictions can be edited until each match starts (if `allow_edit_answers` is enabled on the round).
1294
- *
1295
- * @param props.saw_template_id - The ID of the MatchX game template
1296
- * @param props.round - Round object containing `round_id` and `events[]`. Typically obtained from `gamePickGetActiveRound`
1297
- * and modified with user predictions. Each event needs: `gp_event_id`, `team1_user_selection`, `team2_user_selection`
1298
- *
1299
- * **Response** `GamesApiResponse<GamePickRound>`:
1300
- * - `errCode` - 0 on success. Non-zero codes indicate errors (e.g. not enough points/attempts)
1301
- * - `data` - Updated round with all events reflecting the submitted selections.
1302
- * `user_placed_bet` will be `true`, `has_not_submitted_changes` will be `false`
1303
- *
1304
- * **Example**:
1305
- * ```
1306
- * _smartico.api.gamePickGetActiveRound({
1307
- * saw_template_id: 1190,
1308
- * round_id: 38665,
1309
- * }).then((roundData) => {
1310
- * const round = roundData.data;
1311
- * round.events = round.events.map(e => ({
1312
- * gp_event_id: e.gp_event_id,
1313
- * team1_user_selection: 1,
1314
- * team2_user_selection: 0,
1315
- * }));
1316
- * _smartico.api.gamePickSubmitSelection({
1317
- * saw_template_id: 1190,
1318
- * round: round,
1319
- * }).then((result) => {
1320
- * console.log(result.data.user_placed_bet); // true
1321
- * });
1322
- * });
1323
- * ```
1324
- *
1325
- * **Visitor mode: not supported**
1326
- */
1327
- public async gamePickSubmitSelection(props: GamePickRequestParams & { round: Partial<GamePickRound> }): Promise<GamesApiResponse<GamePickRound>> {
1328
- if (!props.saw_template_id) {
1329
- throw new Error('saw_template_id is required');
1330
- }
1331
- if (!props.round?.round_id) {
1332
- throw new Error('round is required');
1333
- }
1334
- return this.api.gpSubmitSelection(props.saw_template_id, props.round, false);
1335
- }
1336
-
1337
- /**
1338
- * Submits answers for a round in a Quiz game.
1339
- * Sends the round object with user answers for all events at once.
1340
- * Each event must include `user_selection` with the answer value (e.g. '1', '2', 'x', 'yes', 'no' — depending on the market type).
1341
- * If the user hasn't placed bets before, one game attempt (spin) will be consumed.
1342
- * Answers can be edited until each match starts (if `allow_edit_answers` is enabled on the round).
1343
- *
1344
- * @param props.saw_template_id - The ID of the Quiz game template
1345
- * @param props.round - Round object containing `round_id` and `events[]`. Typically obtained from `gamePickGetActiveRound`
1346
- * and modified with user answers. Each event needs: `gp_event_id`, `user_selection`
1347
- *
1348
- * **Response** `GamesApiResponse<GamePickRound>`:
1349
- * - `errCode` - 0 on success. Non-zero codes indicate errors (e.g. not enough points/attempts)
1350
- * - `data` - Updated round with all events reflecting the submitted answers.
1351
- * `user_placed_bet` will be `true`, `has_not_submitted_changes` will be `false`
1352
- *
1353
- * **Example**:
1354
- * ```
1355
- * _smartico.api.gamePickGetActiveRound({
1356
- * saw_template_id: 1183,
1357
- * round_id: 37974,
1358
- * }).then((roundData) => {
1359
- * const round = roundData.data;
1360
- * round.events = round.events.map(e => ({
1361
- * gp_event_id: e.gp_event_id,
1362
- * user_selection: 'x',
1363
- * }));
1364
- * _smartico.api.gamePickSubmitSelectionQuiz({
1365
- * saw_template_id: 1183,
1366
- * round: round,
1367
- * }).then((result) => {
1368
- * console.log(result.data.user_placed_bet); // true
1369
- * });
1370
- * });
1371
- * ```
1372
- *
1373
- * **Visitor mode: not supported**
1374
- */
1375
- public async gamePickSubmitSelectionQuiz(props: GamePickRequestParams & { round: Partial<GamePickRound> }): Promise<GamesApiResponse<GamePickRound>> {
1376
- if (!props.saw_template_id) {
1377
- throw new Error('saw_template_id is required');
1378
- }
1379
- if (!props.round?.round_id) {
1380
- throw new Error('round is required');
1381
- }
1382
- return this.api.gpSubmitSelection(props.saw_template_id, props.round, true);
1383
- }
1384
-
1385
- /**
1386
- * Returns the current user's profile information within the specified MatchX or Quiz game.
1387
- * The user record is synced from the Smartico platform into the games DB (synced every 1 minute).
1388
- * If the user doesn't exist in the games DB yet, it will be created automatically on first call.
1389
- *
1390
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1391
- *
1392
- * **Response** `GamesApiResponse<GamePickUserInfo>`:
1393
- * - `errCode` - 0 on success
1394
- * - `data`:
1395
- * - `ext_user_id` - External user ID (Smartico internal numeric ID)
1396
- * - `int_user_id` - Internal user ID within the games system
1397
- * - `public_username` - Display name
1398
- * - `avatar_url` - User's avatar image URL
1399
- * - `last_wallet_sync_time` - Last time the user's balance was synced from Smartico
1400
- * - `ach_points_balance` - User's current points balance
1401
- * - `ach_gems_balance` - User's current gems balance
1402
- * - `ach_diamonds_balance` - User's current diamonds balance
1403
- * - `pubic_username_set` - Whether the user has set a custom username
1404
- *
1405
- * **Example**:
1406
- * ```
1407
- * _smartico.api.gamePickGetUserInfo({
1408
- * saw_template_id: 1083,
1409
- * }).then((result) => {
1410
- * console.log(result.data.public_username, result.data.ach_points_balance);
1411
- * });
1412
- * ```
1413
- *
1414
- * **Visitor mode: not supported**
1415
- */
1416
- public async gamePickGetUserInfo(props: GamePickRequestParams): Promise<GamesApiResponse<GamePickUserInfo>> {
1417
- if (!props.saw_template_id) {
1418
- throw new Error('saw_template_id is required');
1419
- }
1420
- return this.api.gpGetUserInfo(props.saw_template_id);
1421
- }
1422
-
1423
- /**
1424
- * Returns the game configuration and the list of all rounds for the specified MatchX or Quiz game.
1425
- * Includes the SAW template definition, label settings, and round metadata (without events).
1426
- *
1427
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1428
- *
1429
- * **Response** `GamesApiResponse<GamePickGameInfo>`:
1430
- * - `errCode` - 0 on success
1431
- * - `data`:
1432
- * - `sawTemplate` - Game template configuration including:
1433
- * - `saw_template_id`, `saw_game_type_id` (6 = MatchX/Quiz)
1434
- * - `saw_template_ui_definition` - UI settings (name, ranking options, ask_for_username, etc.)
1435
- * - `saw_buyin_type_id` - Cost type (1=Free, 2=Points, 3=Gems, 4=Diamonds, 5=Spins)
1436
- * - `buyin_cost_points` - Cost per attempt
1437
- * - `spin_count` - Available attempts for the current user
1438
- * - `allRounds[]` - List of all rounds (metadata only, no events), each with:
1439
- * - `round_id`, `round_name`, `round_description`
1440
- * - `open_date`, `last_bet_date` - Timestamps (ms)
1441
- * - `is_active_now`, `is_resolved`, `round_status_id`
1442
- * - `labelInfo` - Label/brand configuration and settings
1443
- *
1444
- * **Example**:
1445
- * ```
1446
- * _smartico.api.gamePickGetGameInfo({
1447
- * saw_template_id: 1189,
1448
- * }).then((result) => {
1449
- * console.log(result.data.sawTemplate.saw_template_ui_definition.name);
1450
- * console.log('Rounds:', result.data.allRounds.length);
1451
- * console.log('Buy-in type:', result.data.sawTemplate.saw_buyin_type_id);
1452
- * });
1453
- * ```
1454
- *
1455
- * **Visitor mode: not supported**
1456
- */
1457
- public async gamePickGetGameInfo(props: GamePickRequestParams): Promise<GamesApiResponse<GamePickGameInfo>> {
1458
- if (!props.saw_template_id) {
1459
- throw new Error('saw_template_id is required');
1460
- }
1461
- return this.api.gpGetGameInfo(props.saw_template_id);
1462
- }
1463
-
1464
- /**
1465
- * Returns round data with events and picks for a specific user (identified by their internal user ID).
1466
- * Useful for viewing another user's predictions from the leaderboard.
1467
- * The `int_user_id` can be obtained from the `gamePickGetBoard` response (`users[].int_user_id`).
1468
- *
1469
- * @param props.saw_template_id - The ID of the MatchX or Quiz game template
1470
- * @param props.round_id - The round to get info for
1471
- * @param props.int_user_id - Internal user ID of the player whose predictions to view (from leaderboard data)
1472
- *
1473
- * **Response** `GamesApiResponse<GamePickRound>`:
1474
- * - `errCode` - 0 on success
1475
- * - `data` - Round object with the target user's selections.
1476
- * Same structure as `gamePickGetActiveRound`, but `user_selection`/`team1_user_selection`/`team2_user_selection`
1477
- * fields on events reflect the specified user's picks instead of the current user's.
1478
- * Events also include `resolution_type_id` (0=None, 2=Lost, 3=PartialWin, 4=FullWin) showing how each prediction was scored
1479
- *
1480
- * **Example**:
1481
- * ```
1482
- * _smartico.api.gamePickGetRoundInfoForUser({
1483
- * saw_template_id: 1083,
1484
- * round_id: 31652,
1485
- * int_user_id: 65653810,
1486
- * }).then((result) => {
1487
- * result.data.events.forEach(e => {
1488
- * console.log(e.event_meta.team1_name, 'vs', e.event_meta.team2_name, '→', e.user_selection);
1489
- * });
1490
- * });
1491
- * ```
1492
- *
1493
- * **Visitor mode: not supported**
1494
- */
1495
- public async gamePickGetRoundInfoForUser(props: GamePickRoundRequestParams & { int_user_id: number }): Promise<GamesApiResponse<GamePickRound>> {
1496
- if (!props.saw_template_id) {
1497
- throw new Error('saw_template_id is required');
1498
- }
1499
- if (!props.round_id) {
1500
- throw new Error('round_id is required');
1501
- }
1502
- if (!props.int_user_id) {
1503
- throw new Error('int_user_id is required');
1504
- }
1505
- return this.api.gpGetRoundInfoForUser(props.saw_template_id, props.round_id, props.int_user_id);
1506
- }
1507
-
1508
- /**
1509
- * Returns the list of avatars available in the catalog for the current user.
1510
- * The response includes both free avatars and earned/purchased ones.
1511
- * Avatars with `hide_until_achieved = true` and `is_given = false` should be hidden from the user.
1512
- * The result is cached for 30 seconds.
1513
- *
1514
- * **Example**:
1515
- * ```
1516
- * _smartico.api.getAvatarsList().then((result) => {
1517
- * console.log(result);
1518
- * });
1519
- * ```
1520
- *
1521
- * **Visitor mode: not supported**
1522
- */
1523
- public async getAvatarsList(): Promise<TAvatarDefinition[]> {
1524
- return OCache.use(
1525
- onUpdateContextKey.AvatarsList,
1526
- ECacheContext.WSAPI,
1527
- () => this.api.avatarsGetListT(this.userExtId),
1528
- CACHE_DATA_SEC,
1529
- );
1530
- }
1531
-
1532
- /**
1533
- * Returns the list of AI-customized avatars for the current user.
1534
- * Each entry represents a previously generated AI customization for a specific base avatar.
1535
- * The result is cached for 30 seconds.
1536
- *
1537
- * **Example**:
1538
- * ```
1539
- * _smartico.api.getAvatarsCustomized().then((result) => {
1540
- * console.log(result);
1541
- * });
1542
- * ```
1543
- *
1544
- * **Visitor mode: not supported**
1545
- */
1546
- public async getAvatarsCustomized(): Promise<TAvatarCustomized[]> {
1547
- return OCache.use(
1548
- onUpdateContextKey.AvatarsCustomized,
1549
- ECacheContext.WSAPI,
1550
- () => this.api.avatarsGetCustomizedT(this.userExtId),
1551
- CACHE_DATA_SEC,
1552
- );
1553
- }
1554
-
1555
- /**
1556
- * Returns the list of AI customization prompts (styles) available for avatar customization.
1557
- * Each prompt represents a visual style that can be applied to a base avatar.
1558
- * The result is cached for 30 seconds.
1559
- *
1560
- * **Example**:
1561
- * ```
1562
- * _smartico.api.getAvatarPrompts().then((result) => {
1563
- * console.log(result);
1564
- * });
1565
- * ```
1566
- *
1567
- * **Visitor mode: not supported**
1568
- */
1569
- public async getAvatarPrompts(): Promise<TAvatarPrompt[]> {
1570
- return OCache.use(
1571
- onUpdateContextKey.AvatarPrompts,
1572
- ECacheContext.WSAPI,
1573
- () => this.api.avatarsGetPromptsT(this.userExtId),
1574
- CACHE_DATA_SEC,
1575
- );
1576
- }
1577
-
1578
- /**
1579
- * Sets the specified avatar as the active avatar for the current user.
1580
- * Pass `avatar_url` (the `TAvatarDefinition.url` path or a CDN URL for AI-customized avatars)
1581
- * and `avatar_real_id` from the avatar catalog.
1582
- * After a successful call, the avatar list cache is cleared so the next `getAvatarsList()` call reflects `is_in_use`.
1583
- *
1584
- * **Example**:
1585
- * ```
1586
- * _smartico.api.getAvatarsList().then((avatars) => {
1587
- * const avatar = avatars.find((a) => !a.hide_until_achieved || a.is_given);
1588
- * if (avatar) {
1589
- * _smartico.api.setAvatar({
1590
- * avatar_url: avatar.url,
1591
- * avatar_real_id: avatar.avatar_real_id,
1592
- * }).then((result) => {
1593
- * console.log(result);
1594
- * });
1595
- * }
1596
- * });
1597
- * ```
1598
- *
1599
- * **Visitor mode: not supported**
1600
- */
1601
- public async setAvatar(props: { avatar_url: string; avatar_real_id: number }): Promise<TSetAvatarResult> {
1602
- if (!props.avatar_url) {
1603
- throw new Error('avatar_url is required');
1604
- }
1605
- if (!props.avatar_real_id) {
1606
- throw new Error('avatar_real_id is required');
1607
- }
1608
-
1609
- const r = await this.api.avatarSetAvatar(this.userExtId, props.avatar_url, props.avatar_real_id);
1610
-
1611
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.AvatarsList);
1612
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.AvatarsCustomized);
1613
-
1614
- return {
1615
- err_code: r.errCode ?? 0,
1616
- err_message: r.errMsg,
1617
- };
1618
- }
1619
-
1620
- private async updateOnSpin(data: SAWSpinsCountPush) {
1621
- const templates: TMiniGameTemplate[] = await OCache.use(
1622
- onUpdateContextKey.Saw,
1623
- ECacheContext.WSAPI,
1624
- () => this.api.sawGetTemplatesT(this.userExtId),
1625
- CACHE_DATA_SEC,
1626
- );
1627
- const index = templates.findIndex((t) => t.id === data.saw_template_id);
1628
- templates[index].spin_count = data.spin_count;
1629
- this.updateEntity(onUpdateContextKey.Saw, templates);
1630
- }
1631
-
1632
- private async reloadMiniGameTemplate() {
1633
- const updatedTemplates = await this.api.sawGetTemplatesT(this.userExtId);
1634
- this.updateEntity(onUpdateContextKey.Saw, updatedTemplates);
1635
- }
1636
-
1637
- private async updateMissions() {
1638
- const payload = await this.api.missionsGetItemsT(this.userExtId);
1639
- this.updateEntity(onUpdateContextKey.Missions, payload);
1640
- }
1641
-
1642
- private async updateBonuses() {
1643
- const payload = await this.api.bonusesGetItemsT(this.userExtId);
1644
- this.updateEntity(onUpdateContextKey.Bonuses, payload);
1645
- }
1646
-
1647
- private async updateTournaments() {
1648
- const payload = await this.api.tournamentsGetLobbyT(this.userExtId);
1649
- this.updateEntity(onUpdateContextKey.TournamentList, payload);
1650
- }
1651
-
1652
- private async updateClans() {
1653
- const payload = await this.api.clansGetListT(this.userExtId);
1654
- this.updateEntity(onUpdateContextKey.Clans, payload);
1655
- }
1656
-
1657
- private async updateStorePurchasedItems() {
1658
- const payload = await this.api.storeGetPurchasedItemsT(this.userExtId, 20, 0);
1659
- this.updateEntity(onUpdateContextKey.StoreHistory, payload);
1660
- }
1661
-
1662
- private async updateStoreItems() {
1663
- const payload = await this.api.storeGetItemsT(this.userExtId);
1664
- this.updateEntity(onUpdateContextKey.StoreItems, payload);
1665
- }
1666
-
1667
- private async updateInboxUnreadCount(count: number) {
1668
- this.updateEntity(onUpdateContextKey.InboxUnreadCount, count);
1669
- }
1670
-
1671
- private async updateInboxMessages() {
1672
- const payload = await this.api.getInboxMessagesT(this.userExtId);
1673
- this.updateEntity(onUpdateContextKey.InboxMessages, payload);
1674
- }
1675
-
1676
- private async updateRaffles() {
1677
- const payload = await this.api.getRafflesT(this.userExtId);
1678
- this.updateEntity(onUpdateContextKey.Raffles, payload);
1679
- }
1680
-
1681
- private async notifyActivityLogUpdate() {
1682
- const startSeconds = Date.now() / 1000 - 600;
1683
- const endSeconds = Date.now() / 1000;
1684
- const payload = await this.api.getActivityLogT(this.userExtId, startSeconds, endSeconds, 0, 50);
1685
-
1686
- this.updateEntity(onUpdateContextKey.ActivityLog, payload);
1687
- }
1688
-
1689
- private async updateEntity(contextKey: onUpdateContextKey, payload: any) {
1690
- OCache.set(contextKey, payload, ECacheContext.WSAPI);
1691
-
1692
- const onUpdate = this.onUpdateCallback.get(contextKey);
1693
- if (onUpdate) {
1694
- onUpdate(payload);
1695
- }
1696
- }
1697
-
1698
- private async jackpotClearCache() {
1699
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Jackpots);
1700
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Pots);
1701
- OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.JackpotWinners);
1702
- }
1703
-
1704
- /** Returns list of Jackpots that are active in the system and matching to the filter definition.
1705
- * If filter is not provided, all active jackpots will be returned.
1706
- * Filter can be used to get jackpots related to specific game or specific jackpot template.
1707
- * You can call this method every second in order to get up to date information about current value of the jackpot(s) and present them to the end-users
1708
- *
1709
- * **Example**:
1710
- * ```
1711
- * _smartico.api.jackpotGet({ related_game_id: 'wooko-slot' }).then((result) => {
1712
- * console.log(result);
1713
- * });
1714
- * ```
1715
- *
1716
- * **Example in the Visitor mode**:
1717
- * ```
1718
- * _smartico.vapi('EN').jackpotGet({ related_game_id: 'wooko-slot' }).then((result) => {
1719
- * console.log(result);
1720
- * });
1721
- * ```
1722
- */
1723
- public async jackpotGet(filter?: { related_game_id?: string; jp_template_id?: number }): Promise<JackpotDetails[]> {
1724
- const signature: string = `${filter?.jp_template_id}:${filter?.related_game_id}`;
1725
-
1726
- if (signature !== this.jackpotGetSignature) {
1727
- this.jackpotGetSignature = signature;
1728
- this.jackpotClearCache();
1729
- }
1730
-
1731
- let jackpots: JackpotDetails[] = [];
1732
- let pots: JackpotPot[] = [];
1733
-
1734
- jackpots = await OCache.use<JackpotDetails[]>(
1735
- onUpdateContextKey.Jackpots,
1736
- ECacheContext.WSAPI,
1737
- async () => {
1738
- const _jackpots = await this.api.jackpotGet(this.userExtId, filter);
1739
- const _pots = _jackpots.items.map((jp) => jp.pot);
1740
-
1741
- _jackpots.items.forEach((jp) => {
1742
- jp.jp_public_meta.custom_data = IntUtils.JsonOrText(jp.jp_public_meta.custom_data);
1743
- });
1744
-
1745
- OCache.set(onUpdateContextKey.Pots, _pots, ECacheContext.WSAPI, JACKPOT_POT_CACHE_SEC);
1746
- return _jackpots.items;
1747
- },
1748
- JACKPOT_TEMPLATE_CACHE_SEC,
1749
- );
1750
-
1751
- if (jackpots.length > 0) {
1752
- pots = await OCache.use<JackpotPot[]>(
1753
- onUpdateContextKey.Pots,
1754
- ECacheContext.WSAPI,
1755
- async () => {
1756
- const jp_template_ids = jackpots.map((jp) => jp.jp_template_id);
1757
- return (await this.api.potGet(this.userExtId, { jp_template_ids })).items;
1758
- },
1759
- JACKPOT_POT_CACHE_SEC,
1760
- );
1761
- }
1762
-
1763
- return jackpots.map((jp) => {
1764
- let _jp: JackpotDetails = {
1765
- ...jp,
1766
- pot: pots.find((p) => p.jp_template_id === jp.jp_template_id),
1767
- };
1768
- return _jp;
1769
- });
1770
- }
1771
-
1772
- /**
1773
- * Opt-in currently logged in user to the jackpot with the specified jp_template_id.
1774
- * You may call jackpotGet method after doing optin to see that user is opted in to the jackpot.
1775
- *
1776
- * **Example**:
1777
- * ```
1778
- * _smartico.api.jackpotOptIn({ jp_template_id: 123 }).then((result) => {
1779
- * console.log('Opted in to the jackpot');
1780
- * });
1781
- * ```
1782
- *
1783
- * **Visitor mode: not supported**
1784
- *
1785
- */
1786
- public async jackpotOptIn(filter: { jp_template_id: number }): Promise<JackpotsOptinResponse> {
1787
- if (!filter.jp_template_id) {
1788
- throw new Error('jp_template_id is required in jackpotOptIn');
1789
- }
1790
-
1791
- const result = await this.api.jackpotOptIn(this.userExtId, filter);
1792
-
1793
- return result;
1794
- }
1795
-
1796
- /**
1797
- * Opt-out currently logged in user from the jackpot with the specified jp_template_id.
1798
- * You may call jackpotGet method after doing optout to see that user is not opted in to the jackpot.
1799
- *
1800
- * **Example**:
1801
- * ```
1802
- * _smartico.api.jackpotOptOut({ jp_template_id: 123 }).then((result) => {
1803
- * console.log('Opted out from the jackpot');
1804
- * });
1805
- * ```
1806
- *
1807
- * **Visitor mode: not supported**
1808
- *
1809
- */
1810
- public async jackpotOptOut(filter: { jp_template_id: number }): Promise<JackpotsOptoutResponse> {
1811
- if (!filter.jp_template_id) {
1812
- throw new Error('jp_template_id is required in jackpotOptOut');
1813
- }
1814
-
1815
- const result = await this.api.jackpotOptOut(this.userExtId, filter);
1816
-
1817
- return result;
1818
- }
1819
-
1820
- /**
1821
- * Returns jackpot winners for the given `jp_template_id` (paginated on the server).
1822
- * Default page size on the wire is 20; use `limit`, `offset`, and repeated calls to load more.
1823
- * The full protocol response also includes `has_more`; this method returns only the `winners` array.
1824
- *
1825
- * **Example**:
1826
- * ```
1827
- * _smartico.api.getJackpotWinners({
1828
- * jp_template_id: 123,
1829
- * }).then((result) => {
1830
- * console.log(result);
1831
- * });
1832
- * ```
1833
- *
1834
- * **Visitor mode: not supported**
1835
- *
1836
- * @param params - Jackpot winners parameters
1837
- * @param params.jp_template_id - Jackpot template id (required; throws if missing)
1838
- * @param params.limit - Page size (server default 20 when omitted)
1839
- * @param params.offset - Offset into the winner list
1840
- */
1841
-
1842
- public async getJackpotWinners({
1843
- limit,
1844
- offset,
1845
- jp_template_id,
1846
- }: {
1847
- limit?: number;
1848
- offset?: number;
1849
- jp_template_id?: number;
1850
- }): Promise<JackpotWinnerHistory[]> {
1851
- return OCache.use(
1852
- onUpdateContextKey.JackpotWinners + jp_template_id,
1853
- ECacheContext.WSAPI,
1854
- () => this.api.getJackpotWinnersT(this.userExtId, limit, offset, jp_template_id),
1855
- JACKPOT_WINNERS_CACHE_SEC,
1856
- );
1857
- }
1858
-
1859
- /**
1860
- * Returns the eligible games for the jackpot with the specified jp_template_id.
1861
- *
1862
- * **Example**:
1863
- * ```
1864
- * _smartico.api.getJackpotEligibleGames({ jp_template_id: 123 }).then((result) => {
1865
- * console.log(result);
1866
- * });
1867
- * ```
1868
- *
1869
- * **Visitor mode: not supported**
1870
- *
1871
- */
1872
-
1873
- public async getJackpotEligibleGames({ jp_template_id, onUpdate } : { jp_template_id: number, onUpdate?: () => void }): Promise<TGetJackpotEligibleGamesResponse> {
1874
- if (onUpdate) {
1875
- this.onUpdateCallback.set(onUpdateContextKey.JackpotEligibleGames, onUpdate);
1876
- }
1877
-
1878
- return OCache.use(
1879
- onUpdateContextKey.JackpotEligibleGames + jp_template_id,
1880
- ECacheContext.WSAPI,
1881
- () => this.api.getJackpotEligibleGamesT(this.userExtId, { jp_template_id }),
1882
- JACKPOT_ELIGIBLE_GAMES_CACHE_SEC,
1883
- );
1884
- }
1885
-
1886
- /**
1887
- * Returns all the related tournaments and missions for the provided game id for the current user
1888
- * The provided Game ID should correspond to the ID from the Games Catalog - https://help.smartico.ai/welcome/technical-guides/games-catalog-api
1889
- *
1890
- * **Example**:
1891
- * ```
1892
- * _smartico.api.getRelatedItemsForGame('gold-slot2').then((result) => {
1893
- * console.log(result);
1894
- * });
1895
- * ```
1896
- *
1897
- * **Example in the Visitor mode**:
1898
- * ```
1899
- * _smartico.vapi('EN').getRelatedItemsForGame('gold-slot2').then((result) => {
1900
- * console.log(result);
1901
- * });
1902
- * ```
1903
- */
1904
- public async getRelatedItemsForGame(related_game_id: string): Promise<GetRelatedAchTourResponse> {
1905
- const result = await this.api.getRelatedItemsForGame(this.userExtId, related_game_id);
1906
- return result;
1907
- }
1908
-
1909
- /**
1910
- * Returns the list of Raffles available for user
1911
- * 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.
1912
- * The onUpdate callback will be called on claiming prize. Updated Raffles will be passed to onUpdate callback.
1913
- *
1914
- * **Example**:
1915
- *
1916
- * ```
1917
- * _smartico.api.getRaffles().then((result) => {
1918
- * console.log(result);
1919
- * });
1920
- * ```
1921
- *
1922
- * **Example in the Visitor mode**:
1923
- *
1924
- * ```
1925
- * _smartico.vapi('EN').getRaffles().then((result) => {
1926
- * console.log(result);
1927
- * });
1928
- * ```
1929
- *
1930
- */
1931
-
1932
- public async getRaffles({ onUpdate }: { onUpdate?: (data: TRaffle[]) => void } = {}): Promise<TRaffle[]> {
1933
- if (onUpdate) {
1934
- this.onUpdateCallback.set(onUpdateContextKey.Raffles, onUpdate);
1935
- }
1936
-
1937
- return OCache.use(onUpdateContextKey.Raffles, ECacheContext.WSAPI, () => this.api.getRafflesT(this.userExtId), CACHE_DATA_SEC);
1938
- }
1939
-
1940
- /**
1941
- * Returns draw run for provided raffle_id and run_id.
1942
- * You can pass winners_from and winners_to parameters to get a specific range of winners. Default is 0-20.
1943
- *
1944
- *
1945
- * **Example**:
1946
- *
1947
- * ```javascript
1948
- * _smartico.api.getRaffleDrawRun({raffle_id: 156, run_id: 145}).then((result) => {
1949
- * console.log(result);
1950
- * });
1951
- * ```
1952
- *
1953
- * **Example in the Visitor mode**:
1954
- *
1955
- *
1956
- * ```javascript
1957
- * _smartico.vapi('EN').getRaffleDrawRun({ raffle_id: 156, run_id: 145 }).then((result) => {
1958
- * console.log(result);
1959
- * });
1960
- * ```
1961
- *
1962
- */
1963
-
1964
- public async getRaffleDrawRun(props: { raffle_id: number; run_id: number; winners_from?: number; winners_to?: number }): Promise<TRaffleDraw> {
1965
- if (!props.raffle_id || !props.run_id) {
1966
- throw new Error('both raffle_id and run_id are required');
1967
- }
1968
-
1969
- return await this.api.getRaffleDrawRunT(this.userExtId, props.raffle_id, props.run_id, props.winners_from, props.winners_to);
1970
- }
1971
-
1972
- /**
1973
- * 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
1974
- *
1975
- *
1976
- * **Example**:
1977
- *
1978
- * ```javascript
1979
- * _smartico.api.getRaffleDrawRunsHistory({ raffle_id: 156, draw_id: 432 }).then((result) => {
1980
- * console.log(result);
1981
- * });
1982
- * ```
1983
- *
1984
- * **Example in the Visitor mode**:
1985
- *
1986
- * ```javascript
1987
- * _smartico.vapi('EN').getRaffleDrawRunsHistory({ raffle_id: 156, draw_id: 432 }).then((result) => {
1988
- * console.log(result);
1989
- * });
1990
- * ```
1991
- *
1992
- */
1993
-
1994
- public async getRaffleDrawRunsHistory(props: { raffle_id: number; draw_id?: number }): Promise<TRaffleDrawRun[]> {
1995
-
1996
- const res = await this.api.getRaffleDrawRunsHistory(this.userExtId, props);
1997
-
1998
- if (!props.raffle_id) {
1999
- throw new Error('raffle_id is required');
2000
- }
2001
-
2002
- return drawRunHistoryTransform(res);
2003
- }
2004
-
2005
- /**
2006
- * Returns `err_code` and `err_message` after the call; `err_code` 0 means the request succeeded.
2007
- *
2008
- *
2009
- * **Example**:
2010
- *
2011
- * ```javascript
2012
- * _smartico.api.claimRafflePrize({won_id:251}).then((result) => {
2013
- * console.log(result);
2014
- * });
2015
- * ```
2016
- *
2017
- * **Example in the Visitor mode**:
2018
- *
2019
- * ```javascript
2020
- * _smartico.vapi('EN').claimRafflePrize({ won_id: 251 }).then((result) => {
2021
- * console.log(result);
2022
- * });
2023
- * ```
2024
- *
2025
- */
2026
- public async claimRafflePrize(props: { won_id: number }): Promise<TransformedRaffleClaimPrizeResponse> {
2027
- if (!props.won_id) {
2028
- throw new Error('won_id is required');
2029
- }
2030
-
2031
- const res = await this.api.claimRafflePrize(this.userExtId, { won_id: props.won_id });
2032
- return raffleClaimPrizeResponseTransform(res);
2033
- }
2034
-
2035
- /**
2036
- * Requests an opt-in for the specified raffle. Returns the err_code.
2037
- *
2038
- * **Visitor mode: not supported**
2039
- */
2040
- public async requestRaffleOptin(props: { raffle_id: number; draw_id: number; raffle_run_id: number }): Promise<TRaffleOptinResponse> {
2041
- if (!props.raffle_id) {
2042
- throw new Error('raffle_id is required');
2043
- }
2044
- if (!props.draw_id) {
2045
- throw new Error('draw_id is required');
2046
- }
2047
- if (!props.raffle_run_id) {
2048
- throw new Error('raffle_run_id is required');
2049
- }
2050
-
2051
- const r = await this.api.raffleOptin(this.userExtId, props);
2052
-
2053
- return {
2054
- err_code: r.errCode,
2055
- err_message: r.errMsg,
2056
- };
2057
- }
2058
78
  }