@smartico/public-api 0.0.362 → 0.0.364

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.362",
3
+ "version": "0.0.364",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,17 @@
1
+ import { TAvatarPrompt } from '../WSAPI/WSAPITypes';
1
2
  import { ProtocolResponse } from '../Base/ProtocolResponse';
2
3
  import { AvatarPrompt } from './AvatarPrompt';
3
4
 
4
5
  export interface GetAvatarPromptsResponse extends ProtocolResponse {
5
6
  prompts: AvatarPrompt[];
6
7
  }
8
+
9
+ export const avatarPromptTransform = (items: AvatarPrompt[], avatarDomain: string): TAvatarPrompt[] => {
10
+ return items.map((item) => ({
11
+ prompt_id: item.prompt_id,
12
+ name: item.public_meta.name,
13
+ icon_url: item.public_meta.icon_url && !item.public_meta.icon_url.startsWith('http') ? `${avatarDomain}${item.public_meta.icon_url}` : item.public_meta.icon_url,
14
+ cost_currency_type_id: item.cost_currency_type_id,
15
+ cost_value: item.cost_value,
16
+ }));
17
+ };
@@ -1,6 +1,15 @@
1
+ import { TAvatarCustomized } from '../WSAPI/WSAPITypes';
1
2
  import { ProtocolResponse } from '../Base/ProtocolResponse';
2
3
  import { AvatarCustomized } from './AvatarCustomized';
3
4
 
4
5
  export interface GetAvatarsCustomizedResponse extends ProtocolResponse {
5
6
  avatars: AvatarCustomized[];
6
7
  }
8
+
9
+ export const avatarCustomizedTransform = (items: AvatarCustomized[], avatarDomain: string): TAvatarCustomized[] => {
10
+ return items.map((item) => ({
11
+ avatar_real_id: item.avatar_real_id,
12
+ url: item.url && !item.url.startsWith('http') ? `${avatarDomain}${item.url}` : item.url,
13
+ dt_created: item.dt_created,
14
+ }));
15
+ };
@@ -1,6 +1,24 @@
1
+ import { TAvatarDefinition } from '../WSAPI/WSAPITypes';
1
2
  import { ProtocolResponse } from '../Base/ProtocolResponse';
2
3
  import { AvatarDefinition } from './AvatarDefinition';
3
4
 
4
5
  export interface GetAvatarsListResponse extends ProtocolResponse {
5
6
  avatars: AvatarDefinition[];
6
7
  }
8
+
9
+ export const avatarDefinitionTransform = (items: AvatarDefinition[], avatarDomain: string): TAvatarDefinition[] => {
10
+ return items.map((item) => ({
11
+ avatar_real_id: item.avatar_real_id,
12
+ is_default: item.is_default,
13
+ hide_until_achieved: item.hide_until_achieved,
14
+ priority: item.priority,
15
+ description: item.public_meta.description,
16
+ url: item.public_meta.url,
17
+ avatar_url: item.public_meta.url && !item.public_meta.url.startsWith('http') ? `${avatarDomain}${item.public_meta.url}` : item.public_meta.url,
18
+ avatar_source_type_id: item.avatar_source_type_id,
19
+ active_from_date: item.active_from_date,
20
+ active_till_date: item.active_till_date,
21
+ is_given: item.is_given,
22
+ is_in_use: item.is_in_use,
23
+ }));
24
+ };
@@ -8,6 +8,35 @@ import { BadgesTimeLimitStates } from "./BadgesTimeLimitStates";
8
8
  type UserStateParamsKeys = 'core_fav_game_top3' | 'core_fav_game_type_top3' | 'core_fav_game_provider_top3' | 'core_recommended_deposit_amount' | 'core_recommended_casino_bet_amount' | 'casino_last_bet_amount' | 'casino_last_bet_amount_real' | 'casino_last_bet_amount_bonus' | 'acc_last_deposit_amount';
9
9
  const USER_STATE_PARAMS_KEYS_GAMES: UserStateParamsKeys[] = ['core_fav_game_top3', 'core_fav_game_type_top3', 'core_fav_game_provider_top3'];
10
10
  const USER_STATE_PARAMS_KEYS_BET_AMOUNT: UserStateParamsKeys[] = ['core_recommended_deposit_amount', 'core_recommended_casino_bet_amount', 'casino_last_bet_amount', 'casino_last_bet_amount_real', 'casino_last_bet_amount_bonus', 'acc_last_deposit_amount'];
11
+
12
+ const MINOR_WORDS = new Set([
13
+ 'of', 'at', 'in', 'on', 'to', 'up', 'as', 'by', 'for',
14
+ 'from', 'into', 'onto', 'with', 'upon', 'via',
15
+ 'and', 'but', 'or', 'nor', 'so', 'yet',
16
+ 'vs', 'v',
17
+ 'a', 'an', 'the',
18
+ ]);
19
+
20
+ function toGameTitleCase(raw: string): string {
21
+ if (!raw) return raw;
22
+ const tokens = raw.toLowerCase().split(/(\b\w+\b)/);
23
+ const wordTokens = tokens.filter((t) => /^\w+$/.test(t));
24
+ const lastWordIdx = wordTokens.length - 1;
25
+ let wordIndex = 0;
26
+ return tokens
27
+ .map((token) => {
28
+ if (!/^\w+$/.test(token)) return token;
29
+ const isFirst = wordIndex === 0;
30
+ const isLast = wordIndex === lastWordIdx;
31
+ wordIndex++;
32
+ if (isFirst || isLast || !MINOR_WORDS.has(token)) {
33
+ return token.charAt(0).toUpperCase() + token.slice(1);
34
+ }
35
+ return token;
36
+ })
37
+ .join('');
38
+ }
39
+
11
40
  export class MissionUtils {
12
41
 
13
42
  public static getAvailabilityStatus = (mission: UserAchievement) => {
@@ -199,8 +228,8 @@ export class MissionUtils {
199
228
  const value = userStateParams[k]?.filter(v => Boolean(v));
200
229
  if (value && value.length > 0) {
201
230
  suggestedGames = value.map((v: string) => {
202
- const cleaned = v.replace(/_/g, ' ').toLowerCase();
203
- return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
231
+ const cleaned = v.replace(/_/g, ' ');
232
+ return toGameTitleCase(cleaned);
204
233
  }).join(', ');
205
234
  }
206
235
  }
@@ -213,8 +242,7 @@ export class MissionUtils {
213
242
  suggestedGames = value[pos];
214
243
 
215
244
  if (suggestedGames) {
216
- suggestedGames = suggestedGames.replace('_', ' ').toLowerCase();
217
- suggestedGames = suggestedGames.charAt(0).toUpperCase() + suggestedGames.slice(1);
245
+ suggestedGames = toGameTitleCase(suggestedGames.replace(/_/g, ' '));
218
246
  }
219
247
 
220
248
  }
@@ -100,6 +100,9 @@ import {
100
100
  TLevelCurrent,
101
101
  TActivityLog,
102
102
  TRaffleDraw,
103
+ TAvatarDefinition,
104
+ TAvatarCustomized,
105
+ TAvatarPrompt,
103
106
  } from './WSAPI/WSAPITypes';
104
107
  import { getLeaderBoardTransform } from './Leaderboard/LeaderBoards';
105
108
  import { GetAchievementsUserInfoResponse } from './Core/GetAchievementsUserInfoResponse';
@@ -129,7 +132,10 @@ import { GetRafflesRequest } from './Raffle/GetRafflesRequest';
129
132
  import { GetActivityLogRequest, GetActivityLogResponse, ActivityLogTransform } from './ActivityLog';
130
133
  import { InboxCategories } from './Inbox/InboxCategories';
131
134
  import { GetDrawRunRequest, GetDrawRunResponse, GetRaffleDrawRunsHistoryRequest, GetRaffleDrawRunsHistoryResponse, RaffleClaimPrizeRequest, RaffleClaimPrizeResponse, RaffleOptinRequest, RaffleOptinResponse, drawRunTransform } from './Raffle';
132
- import { GetAvatarsListResponse, GetAvatarsCustomizedResponse, GetAvatarPromptsResponse, SetAvatarRequest, SetAvatarResponse } from './Avatars';
135
+ import { GetAvatarsListResponse, avatarDefinitionTransform } from './Avatars/GetAvatarsListResponse';
136
+ import { GetAvatarsCustomizedResponse, avatarCustomizedTransform } from './Avatars/GetAvatarsCustomizedResponse';
137
+ import { GetAvatarPromptsResponse, avatarPromptTransform } from './Avatars/GetAvatarPromptsResponse';
138
+ import { SetAvatarRequest, SetAvatarResponse } from './Avatars';
133
139
  import { GetJackpotWinnersResponse, GetJackpotWinnersResponseTransform, JackpotWinnerHistory } from './Jackpots/GetJackpotWinnersResponse';
134
140
  import { GetJackpotWinnersRequest } from './Jackpots/GetJackpotWinnersRequest';
135
141
  import { GetJackpotEligibleGamesRequest } from './Jackpots/GetJackpotEligibleGamesRequest';
@@ -1443,6 +1449,18 @@ class SmarticoAPI {
1443
1449
  return await this.send<SetAvatarResponse>(message, ClassId.CLIENT_SET_AVATAR_RESPONSE);
1444
1450
  }
1445
1451
 
1452
+ public async avatarsGetListT(user_ext_id: string): Promise<TAvatarDefinition[]> {
1453
+ return avatarDefinitionTransform((await this.avatarsGetList(user_ext_id)).avatars ?? [], this.avatarDomain);
1454
+ }
1455
+
1456
+ public async avatarsGetCustomizedT(user_ext_id: string): Promise<TAvatarCustomized[]> {
1457
+ return avatarCustomizedTransform((await this.avatarsGetCustomized(user_ext_id)).avatars ?? [], this.avatarDomain);
1458
+ }
1459
+
1460
+ public async avatarsGetPromptsT(user_ext_id: string): Promise<TAvatarPrompt[]> {
1461
+ return avatarPromptTransform((await this.avatarsGetPrompts(user_ext_id)).prompts ?? [], this.avatarDomain);
1462
+ }
1463
+
1446
1464
  public getWSCalls(): WSAPI {
1447
1465
  return new WSAPI(this);
1448
1466
  }
@@ -1471,15 +1471,7 @@ export class WSAPI {
1471
1471
  return OCache.use(
1472
1472
  onUpdateContextKey.AvatarsList,
1473
1473
  ECacheContext.WSAPI,
1474
- async () => {
1475
- const response = await this.api.avatarsGetList(this.userExtId);
1476
- return (response.avatars || []).map((a) => ({
1477
- ...a,
1478
- avatar_url: this.api.avatarDomain && a.public_meta?.url
1479
- ? (a.public_meta.url.startsWith('http') ? a.public_meta.url : `${this.api.avatarDomain}${a.public_meta.url}`)
1480
- : (a.public_meta?.url || ''),
1481
- }));
1482
- },
1474
+ () => this.api.avatarsGetListT(this.userExtId),
1483
1475
  CACHE_DATA_SEC,
1484
1476
  );
1485
1477
  }
@@ -1502,10 +1494,7 @@ export class WSAPI {
1502
1494
  return OCache.use(
1503
1495
  onUpdateContextKey.AvatarsCustomized,
1504
1496
  ECacheContext.WSAPI,
1505
- async () => {
1506
- const response = await this.api.avatarsGetCustomized(this.userExtId);
1507
- return response.avatars || [];
1508
- },
1497
+ () => this.api.avatarsGetCustomizedT(this.userExtId),
1509
1498
  CACHE_DATA_SEC,
1510
1499
  );
1511
1500
  }
@@ -1528,17 +1517,14 @@ export class WSAPI {
1528
1517
  return OCache.use(
1529
1518
  onUpdateContextKey.AvatarPrompts,
1530
1519
  ECacheContext.WSAPI,
1531
- async () => {
1532
- const response = await this.api.avatarsGetPrompts(this.userExtId);
1533
- return response.prompts || [];
1534
- },
1520
+ () => this.api.avatarsGetPromptsT(this.userExtId),
1535
1521
  CACHE_DATA_SEC,
1536
1522
  );
1537
1523
  }
1538
1524
 
1539
1525
  /**
1540
1526
  * Sets the specified avatar as the active avatar for the current user.
1541
- * Pass `avatar_url` (the image path from `TAvatarDefinition.public_meta.url` or a CDN URL for AI-customized avatars)
1527
+ * Pass `avatar_url` (the `TAvatarDefinition.url` path or a CDN URL for AI-customized avatars)
1542
1528
  * and `avatar_real_id` from the avatar catalog.
1543
1529
  * After a successful call, the avatar list cache is cleared so the next `getAvatarsList()` call reflects `is_in_use`.
1544
1530
  *
@@ -1548,7 +1534,7 @@ export class WSAPI {
1548
1534
  * const avatar = avatars.find((a) => !a.hide_until_achieved || a.is_given);
1549
1535
  * if (avatar) {
1550
1536
  * _smartico.api.setAvatar({
1551
- * avatar_url: avatar.public_meta.url,
1537
+ * avatar_url: avatar.url,
1552
1538
  * avatar_real_id: avatar.avatar_real_id,
1553
1539
  * }).then((result) => {
1554
1540
  * console.log(result);
@@ -1881,7 +1881,8 @@ export interface GamePickRoundRequestParams extends GamePickRequestParams {
1881
1881
  }
1882
1882
 
1883
1883
  /**
1884
- * TAvatarDefinition describes a single avatar available in the avatar catalog
1884
+ * TAvatarDefinition describes a single avatar available in the avatar catalog.
1885
+ * Fields from the raw `public_meta` object are flattened to the top level.
1885
1886
  */
1886
1887
  export interface TAvatarDefinition {
1887
1888
  /** Unique identifier of the avatar */
@@ -1892,13 +1893,12 @@ export interface TAvatarDefinition {
1892
1893
  hide_until_achieved: boolean;
1893
1894
  /** Display priority — lower value means higher position in the grid */
1894
1895
  priority: number;
1895
- /** Public metadata containing the avatar image URL and optional description */
1896
- public_meta: {
1897
- /** Optional description of the avatar */
1898
- description?: string;
1899
- /** Image path/URL of the avatar */
1900
- url: string;
1901
- };
1896
+ /** Optional description of the avatar (from public_meta) */
1897
+ description?: string;
1898
+ /** Raw image path/URL of the avatar as returned by the server (from public_meta) */
1899
+ url: string;
1900
+ /** Full CDN URL of the avatar image, built from avatar_domain + url */
1901
+ avatar_url: string;
1902
1902
  /**
1903
1903
  * Source type of the avatar.
1904
1904
  * 0 = free (always available to all users), other values = earned/purchased
@@ -1912,8 +1912,6 @@ export interface TAvatarDefinition {
1912
1912
  is_given: boolean;
1913
1913
  /** Whether this avatar is currently in use by the user */
1914
1914
  is_in_use?: boolean;
1915
- /** Full CDN URL of the avatar image, built from avatar_domain + public_meta.url */
1916
- avatar_url: string;
1917
1915
  }
1918
1916
 
1919
1917
  /**
@@ -1929,18 +1927,16 @@ export interface TAvatarCustomized {
1929
1927
  }
1930
1928
 
1931
1929
  /**
1932
- * TAvatarPrompt describes an AI style prompt available for avatar customization
1930
+ * TAvatarPrompt describes an AI style prompt available for avatar customization.
1931
+ * Fields from the raw `public_meta` object are flattened to the top level.
1933
1932
  */
1934
1933
  export interface TAvatarPrompt {
1935
1934
  /** Unique identifier of the AI customization prompt */
1936
1935
  prompt_id: number;
1937
- /** Public metadata for the prompt */
1938
- public_meta: {
1939
- /** Display name of the prompt style (e.g. "Cartoon", "Watercolor") */
1940
- name: string;
1941
- /** URL of the prompt style icon image */
1942
- icon_url: string;
1943
- };
1936
+ /** Display name of the prompt style, e.g. "Cartoon", "Watercolor" (from public_meta) */
1937
+ name: string;
1938
+ /** Full CDN URL of the prompt style icon image (from public_meta) */
1939
+ icon_url: string;
1944
1940
  /** Currency type used to pay for this customization (0=points, 1=gems, 2=diamonds) */
1945
1941
  cost_currency_type_id: number;
1946
1942
  /** Cost amount in the given currency */