@smartico/public-api 0.0.361 → 0.0.363

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.361",
3
+ "version": "0.0.363",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,9 @@
1
+ export enum AvatarCustomizeErrorCode {
2
+ AVATAR_USER_LIMIT = 12001,
3
+ AVATAR_LABEL_LIMIT = 12002,
4
+ }
5
+
6
+ export const AvatarCustomizeErrorMessage: Record<AvatarCustomizeErrorCode, string> = {
7
+ [AvatarCustomizeErrorCode.AVATAR_USER_LIMIT]: 'You have exceeded number of custom avatars creation, please try later',
8
+ [AvatarCustomizeErrorCode.AVATAR_LABEL_LIMIT]: 'The custom avatars are not available, please try again later',
9
+ };
@@ -0,0 +1,8 @@
1
+ export interface AvatarCustomized {
2
+ /** The avatar real id that this customization belongs to */
3
+ avatar_real_id: number;
4
+ /** CDN URL of the AI-customized avatar image */
5
+ url: string;
6
+ /** ISO date string when the customization was created */
7
+ dt_created: string;
8
+ }
@@ -0,0 +1,30 @@
1
+ export interface AvatarDefinition {
2
+ /** Unique identifier of the avatar */
3
+ avatar_real_id: number;
4
+ /** Whether this avatar is the default one */
5
+ is_default: boolean;
6
+ /** If true, avatar is hidden until user achieves/unlocks it */
7
+ hide_until_achieved: boolean;
8
+ /** Display priority — lower value means higher position */
9
+ priority: number;
10
+ /** Public metadata containing the avatar image URL and optional description */
11
+ public_meta: {
12
+ /** Optional description of the avatar */
13
+ description?: string;
14
+ /** Image path/URL of the avatar */
15
+ url: string;
16
+ };
17
+ /**
18
+ * Source type of the avatar.
19
+ * 0 = free (always available), other values = earned/purchased
20
+ */
21
+ avatar_source_type_id: number;
22
+ /** ISO date string from which the avatar becomes available */
23
+ active_from_date?: string;
24
+ /** ISO date string until which the avatar is available */
25
+ active_till_date?: string;
26
+ /** Whether the avatar has been granted/given to the current user */
27
+ is_given: boolean;
28
+ /** Whether this avatar is currently in use by the user */
29
+ is_in_use?: boolean;
30
+ }
@@ -0,0 +1,15 @@
1
+ export interface AvatarPrompt {
2
+ /** Unique identifier of the AI customization prompt */
3
+ prompt_id: number;
4
+ /** Public metadata for the prompt */
5
+ public_meta: {
6
+ /** Display name of the prompt style (e.g. "Cartoon", "Watercolor") */
7
+ name: string;
8
+ /** URL of the prompt style icon image */
9
+ icon_url: string;
10
+ };
11
+ /** Currency type used to pay for this customization (0=points, 1=gems, 2=diamonds) */
12
+ cost_currency_type_id: number;
13
+ /** Cost amount in the given currency */
14
+ cost_value: number;
15
+ }
@@ -0,0 +1,17 @@
1
+ import { TAvatarPrompt } from '../WSAPI/WSAPITypes';
2
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
3
+ import { AvatarPrompt } from './AvatarPrompt';
4
+
5
+ export interface GetAvatarPromptsResponse extends ProtocolResponse {
6
+ prompts: AvatarPrompt[];
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
+ };
@@ -0,0 +1,15 @@
1
+ import { TAvatarCustomized } from '../WSAPI/WSAPITypes';
2
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
3
+ import { AvatarCustomized } from './AvatarCustomized';
4
+
5
+ export interface GetAvatarsCustomizedResponse extends ProtocolResponse {
6
+ avatars: AvatarCustomized[];
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
+ };
@@ -0,0 +1,24 @@
1
+ import { TAvatarDefinition } from '../WSAPI/WSAPITypes';
2
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
3
+ import { AvatarDefinition } from './AvatarDefinition';
4
+
5
+ export interface GetAvatarsListResponse extends ProtocolResponse {
6
+ avatars: AvatarDefinition[];
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
+ };
@@ -0,0 +1,8 @@
1
+ import { ProtocolRequest } from '../Base/ProtocolRequest';
2
+
3
+ export interface SetAvatarRequest extends ProtocolRequest {
4
+ /** The avatar image URL or path to set */
5
+ avatar_id: string;
6
+ /** The avatar_real_id from the avatar catalog */
7
+ avatar_real_id: number;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
2
+
3
+ export interface SetAvatarResponse extends ProtocolResponse {
4
+ /** The resolved avatar URL after applying the avatar */
5
+ avatar_id: string;
6
+ }
@@ -0,0 +1,9 @@
1
+ export * from './AvatarCustomizeErrorCode';
2
+ export * from './AvatarDefinition';
3
+ export * from './AvatarCustomized';
4
+ export * from './AvatarPrompt';
5
+ export * from './GetAvatarsListResponse';
6
+ export * from './GetAvatarsCustomizedResponse';
7
+ export * from './GetAvatarPromptsResponse';
8
+ export * from './SetAvatarRequest';
9
+ export * from './SetAvatarResponse';
@@ -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,6 +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';
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';
132
139
  import { GetJackpotWinnersResponse, GetJackpotWinnersResponseTransform, JackpotWinnerHistory } from './Jackpots/GetJackpotWinnersResponse';
133
140
  import { GetJackpotWinnersRequest } from './Jackpots/GetJackpotWinnersRequest';
134
141
  import { GetJackpotEligibleGamesRequest } from './Jackpots/GetJackpotEligibleGamesRequest';
@@ -1419,6 +1426,41 @@ class SmarticoAPI {
1419
1426
  return this.sendGamesApi<GamePickRound>({ method: 'game-round-info-for-user', params });
1420
1427
  }
1421
1428
 
1429
+ public async avatarsGetList(user_ext_id: string): Promise<GetAvatarsListResponse> {
1430
+ const message = this.buildMessage<any, GetAvatarsListResponse>(user_ext_id, ClassId.GET_AVATARS_LIST_REQUEST);
1431
+ return await this.send<GetAvatarsListResponse>(message, ClassId.GET_AVATARS_LIST_RESPONSE);
1432
+ }
1433
+
1434
+ public async avatarsGetCustomized(user_ext_id: string): Promise<GetAvatarsCustomizedResponse> {
1435
+ const message = this.buildMessage<any, GetAvatarsCustomizedResponse>(user_ext_id, ClassId.GET_AVATARS_CUSTOMIZED_REQUEST);
1436
+ return await this.send<GetAvatarsCustomizedResponse>(message, ClassId.GET_AVATARS_CUSTOMIZED_RESPONSE);
1437
+ }
1438
+
1439
+ public async avatarsGetPrompts(user_ext_id: string): Promise<GetAvatarPromptsResponse> {
1440
+ const message = this.buildMessage<any, GetAvatarPromptsResponse>(user_ext_id, ClassId.GET_AVATAR_PROMPTS_REQUEST);
1441
+ return await this.send<GetAvatarPromptsResponse>(message, ClassId.GET_AVATAR_PROMPTS_RESPONSE);
1442
+ }
1443
+
1444
+ public async avatarSetAvatar(user_ext_id: string, avatar_id: string, avatar_real_id: number): Promise<SetAvatarResponse> {
1445
+ const message = this.buildMessage<SetAvatarRequest, SetAvatarResponse>(user_ext_id, ClassId.CLIENT_SET_AVATAR_REQUEST, {
1446
+ avatar_id,
1447
+ avatar_real_id,
1448
+ });
1449
+ return await this.send<SetAvatarResponse>(message, ClassId.CLIENT_SET_AVATAR_RESPONSE);
1450
+ }
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
+
1422
1464
  public getWSCalls(): WSAPI {
1423
1465
  return new WSAPI(this);
1424
1466
  }
@@ -46,6 +46,10 @@ import {
46
46
  GamePickGameInfo,
47
47
  GamePickRequestParams,
48
48
  GamePickRoundRequestParams,
49
+ TAvatarDefinition,
50
+ TAvatarCustomized,
51
+ TAvatarPrompt,
52
+ TSetAvatarResult,
49
53
  } from './WSAPITypes';
50
54
  import { LeaderBoardPeriodType } from '../Leaderboard';
51
55
  import {
@@ -103,6 +107,9 @@ enum onUpdateContextKey {
103
107
  CurrentLevel = 'currentLevel',
104
108
  InboxUnreadCount = 'inboxUnreadCount',
105
109
  ActivityLog = 'activityLog',
110
+ AvatarsList = 'avatarsList',
111
+ AvatarsCustomized = 'avatarsCustomized',
112
+ AvatarPrompts = 'avatarPrompts',
106
113
  }
107
114
 
108
115
  /** @group General API */
@@ -1445,6 +1452,118 @@ export class WSAPI {
1445
1452
  return this.api.gpGetRoundInfoForUser(props.saw_template_id, props.round_id, props.int_user_id);
1446
1453
  }
1447
1454
 
1455
+ /**
1456
+ * Returns the list of avatars available in the catalog for the current user.
1457
+ * The response includes both free avatars and earned/purchased ones.
1458
+ * Avatars with `hide_until_achieved = true` and `is_given = false` should be hidden from the user.
1459
+ * The result is cached for 30 seconds.
1460
+ *
1461
+ * **Example**:
1462
+ * ```
1463
+ * _smartico.api.getAvatarsList().then((result) => {
1464
+ * console.log(result);
1465
+ * });
1466
+ * ```
1467
+ *
1468
+ * **Visitor mode: not supported**
1469
+ */
1470
+ public async getAvatarsList(): Promise<TAvatarDefinition[]> {
1471
+ return OCache.use(
1472
+ onUpdateContextKey.AvatarsList,
1473
+ ECacheContext.WSAPI,
1474
+ () => this.api.avatarsGetListT(this.userExtId),
1475
+ CACHE_DATA_SEC,
1476
+ );
1477
+ }
1478
+
1479
+ /**
1480
+ * Returns the list of AI-customized avatars for the current user.
1481
+ * Each entry represents a previously generated AI customization for a specific base avatar.
1482
+ * The result is cached for 30 seconds.
1483
+ *
1484
+ * **Example**:
1485
+ * ```
1486
+ * _smartico.api.getAvatarsCustomized().then((result) => {
1487
+ * console.log(result);
1488
+ * });
1489
+ * ```
1490
+ *
1491
+ * **Visitor mode: not supported**
1492
+ */
1493
+ public async getAvatarsCustomized(): Promise<TAvatarCustomized[]> {
1494
+ return OCache.use(
1495
+ onUpdateContextKey.AvatarsCustomized,
1496
+ ECacheContext.WSAPI,
1497
+ () => this.api.avatarsGetCustomizedT(this.userExtId),
1498
+ CACHE_DATA_SEC,
1499
+ );
1500
+ }
1501
+
1502
+ /**
1503
+ * Returns the list of AI customization prompts (styles) available for avatar customization.
1504
+ * Each prompt represents a visual style that can be applied to a base avatar.
1505
+ * The result is cached for 30 seconds.
1506
+ *
1507
+ * **Example**:
1508
+ * ```
1509
+ * _smartico.api.getAvatarPrompts().then((result) => {
1510
+ * console.log(result);
1511
+ * });
1512
+ * ```
1513
+ *
1514
+ * **Visitor mode: not supported**
1515
+ */
1516
+ public async getAvatarPrompts(): Promise<TAvatarPrompt[]> {
1517
+ return OCache.use(
1518
+ onUpdateContextKey.AvatarPrompts,
1519
+ ECacheContext.WSAPI,
1520
+ () => this.api.avatarsGetPromptsT(this.userExtId),
1521
+ CACHE_DATA_SEC,
1522
+ );
1523
+ }
1524
+
1525
+ /**
1526
+ * Sets the specified avatar as the active avatar for the current user.
1527
+ * Pass `avatar_url` (the `TAvatarDefinition.url` path or a CDN URL for AI-customized avatars)
1528
+ * and `avatar_real_id` from the avatar catalog.
1529
+ * After a successful call, the avatar list cache is cleared so the next `getAvatarsList()` call reflects `is_in_use`.
1530
+ *
1531
+ * **Example**:
1532
+ * ```
1533
+ * _smartico.api.getAvatarsList().then((avatars) => {
1534
+ * const avatar = avatars.find((a) => !a.hide_until_achieved || a.is_given);
1535
+ * if (avatar) {
1536
+ * _smartico.api.setAvatar({
1537
+ * avatar_url: avatar.url,
1538
+ * avatar_real_id: avatar.avatar_real_id,
1539
+ * }).then((result) => {
1540
+ * console.log(result);
1541
+ * });
1542
+ * }
1543
+ * });
1544
+ * ```
1545
+ *
1546
+ * **Visitor mode: not supported**
1547
+ */
1548
+ public async setAvatar(props: { avatar_url: string; avatar_real_id: number }): Promise<TSetAvatarResult> {
1549
+ if (!props.avatar_url) {
1550
+ throw new Error('avatar_url is required');
1551
+ }
1552
+ if (!props.avatar_real_id) {
1553
+ throw new Error('avatar_real_id is required');
1554
+ }
1555
+
1556
+ const r = await this.api.avatarSetAvatar(this.userExtId, props.avatar_url, props.avatar_real_id);
1557
+
1558
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.AvatarsList);
1559
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.AvatarsCustomized);
1560
+
1561
+ return {
1562
+ err_code: r.errCode ?? 0,
1563
+ err_message: r.errMsg,
1564
+ };
1565
+ }
1566
+
1448
1567
  private async updateOnSpin(data: SAWSpinsCountPush) {
1449
1568
  const templates: TMiniGameTemplate[] = await OCache.use(
1450
1569
  onUpdateContextKey.Saw,
@@ -1880,4 +1880,77 @@ export interface GamePickRoundRequestParams extends GamePickRequestParams {
1880
1880
  round_id: number;
1881
1881
  }
1882
1882
 
1883
+ /**
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.
1886
+ */
1887
+ export interface TAvatarDefinition {
1888
+ /** Unique identifier of the avatar */
1889
+ avatar_real_id: number;
1890
+ /** Whether this avatar is the default one */
1891
+ is_default: boolean;
1892
+ /** If true, avatar is hidden until user achieves/unlocks it */
1893
+ hide_until_achieved: boolean;
1894
+ /** Display priority — lower value means higher position in the grid */
1895
+ priority: number;
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
+ /**
1903
+ * Source type of the avatar.
1904
+ * 0 = free (always available to all users), other values = earned/purchased
1905
+ */
1906
+ avatar_source_type_id: number;
1907
+ /** ISO date string from which the avatar becomes available */
1908
+ active_from_date?: string;
1909
+ /** ISO date string until which the avatar is available */
1910
+ active_till_date?: string;
1911
+ /** Whether the avatar has been granted/given to the current user */
1912
+ is_given: boolean;
1913
+ /** Whether this avatar is currently in use by the user */
1914
+ is_in_use?: boolean;
1915
+ }
1916
+
1917
+ /**
1918
+ * TAvatarCustomized describes an AI-customized version of a base avatar
1919
+ */
1920
+ export interface TAvatarCustomized {
1921
+ /** The avatar_real_id of the base avatar this customization was generated from */
1922
+ avatar_real_id: number;
1923
+ /** Full CDN URL of the AI-generated customized avatar image */
1924
+ url: string;
1925
+ /** ISO date string when the customization was created */
1926
+ dt_created: string;
1927
+ }
1928
+
1929
+ /**
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.
1932
+ */
1933
+ export interface TAvatarPrompt {
1934
+ /** Unique identifier of the AI customization prompt */
1935
+ prompt_id: number;
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;
1940
+ /** Currency type used to pay for this customization (0=points, 1=gems, 2=diamonds) */
1941
+ cost_currency_type_id: number;
1942
+ /** Cost amount in the given currency */
1943
+ cost_value: number;
1944
+ }
1945
+
1946
+ /**
1947
+ * TSetAvatarResult describes the response of call to _smartico.api.setAvatar() method
1948
+ */
1949
+ export interface TSetAvatarResult {
1950
+ /** Error code that represents outcome of the set avatar request. Successful if err_code is 0 */
1951
+ err_code: number;
1952
+ /** Optional error message */
1953
+ err_message?: string;
1954
+ }
1955
+
1883
1956
  export { SAWAcknowledgeTypeName, PrizeModifiers, SAWTemplateUI, InboxCategories, AchCustomSectionType, SAWAskForUsername, SAWGameLayout, PointChangeSourceType, UserBalanceType, SAWGPMarketType, QuizAnswersValueType }
package/src/index.ts CHANGED
@@ -22,4 +22,5 @@ export * from './OCache';
22
22
  export * from './Bonuses';
23
23
  export * from './CustomSections';
24
24
  export * from './ActivityLog';
25
- export * from './Base/AchRelatedGame';
25
+ export * from './Base/AchRelatedGame';
26
+ export * from './Avatars';