@smartico/public-api 0.0.361 → 0.0.362

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.362",
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,6 @@
1
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
2
+ import { AvatarPrompt } from './AvatarPrompt';
3
+
4
+ export interface GetAvatarPromptsResponse extends ProtocolResponse {
5
+ prompts: AvatarPrompt[];
6
+ }
@@ -0,0 +1,6 @@
1
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
2
+ import { AvatarCustomized } from './AvatarCustomized';
3
+
4
+ export interface GetAvatarsCustomizedResponse extends ProtocolResponse {
5
+ avatars: AvatarCustomized[];
6
+ }
@@ -0,0 +1,6 @@
1
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
2
+ import { AvatarDefinition } from './AvatarDefinition';
3
+
4
+ export interface GetAvatarsListResponse extends ProtocolResponse {
5
+ avatars: AvatarDefinition[];
6
+ }
@@ -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';
@@ -129,6 +129,7 @@ import { GetRafflesRequest } from './Raffle/GetRafflesRequest';
129
129
  import { GetActivityLogRequest, GetActivityLogResponse, ActivityLogTransform } from './ActivityLog';
130
130
  import { InboxCategories } from './Inbox/InboxCategories';
131
131
  import { GetDrawRunRequest, GetDrawRunResponse, GetRaffleDrawRunsHistoryRequest, GetRaffleDrawRunsHistoryResponse, RaffleClaimPrizeRequest, RaffleClaimPrizeResponse, RaffleOptinRequest, RaffleOptinResponse, drawRunTransform } from './Raffle';
132
+ import { GetAvatarsListResponse, GetAvatarsCustomizedResponse, GetAvatarPromptsResponse, SetAvatarRequest, SetAvatarResponse } from './Avatars';
132
133
  import { GetJackpotWinnersResponse, GetJackpotWinnersResponseTransform, JackpotWinnerHistory } from './Jackpots/GetJackpotWinnersResponse';
133
134
  import { GetJackpotWinnersRequest } from './Jackpots/GetJackpotWinnersRequest';
134
135
  import { GetJackpotEligibleGamesRequest } from './Jackpots/GetJackpotEligibleGamesRequest';
@@ -1419,6 +1420,29 @@ class SmarticoAPI {
1419
1420
  return this.sendGamesApi<GamePickRound>({ method: 'game-round-info-for-user', params });
1420
1421
  }
1421
1422
 
1423
+ public async avatarsGetList(user_ext_id: string): Promise<GetAvatarsListResponse> {
1424
+ const message = this.buildMessage<any, GetAvatarsListResponse>(user_ext_id, ClassId.GET_AVATARS_LIST_REQUEST);
1425
+ return await this.send<GetAvatarsListResponse>(message, ClassId.GET_AVATARS_LIST_RESPONSE);
1426
+ }
1427
+
1428
+ public async avatarsGetCustomized(user_ext_id: string): Promise<GetAvatarsCustomizedResponse> {
1429
+ const message = this.buildMessage<any, GetAvatarsCustomizedResponse>(user_ext_id, ClassId.GET_AVATARS_CUSTOMIZED_REQUEST);
1430
+ return await this.send<GetAvatarsCustomizedResponse>(message, ClassId.GET_AVATARS_CUSTOMIZED_RESPONSE);
1431
+ }
1432
+
1433
+ public async avatarsGetPrompts(user_ext_id: string): Promise<GetAvatarPromptsResponse> {
1434
+ const message = this.buildMessage<any, GetAvatarPromptsResponse>(user_ext_id, ClassId.GET_AVATAR_PROMPTS_REQUEST);
1435
+ return await this.send<GetAvatarPromptsResponse>(message, ClassId.GET_AVATAR_PROMPTS_RESPONSE);
1436
+ }
1437
+
1438
+ public async avatarSetAvatar(user_ext_id: string, avatar_id: string, avatar_real_id: number): Promise<SetAvatarResponse> {
1439
+ const message = this.buildMessage<SetAvatarRequest, SetAvatarResponse>(user_ext_id, ClassId.CLIENT_SET_AVATAR_REQUEST, {
1440
+ avatar_id,
1441
+ avatar_real_id,
1442
+ });
1443
+ return await this.send<SetAvatarResponse>(message, ClassId.CLIENT_SET_AVATAR_RESPONSE);
1444
+ }
1445
+
1422
1446
  public getWSCalls(): WSAPI {
1423
1447
  return new WSAPI(this);
1424
1448
  }
@@ -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,132 @@ 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
+ 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
+ },
1483
+ CACHE_DATA_SEC,
1484
+ );
1485
+ }
1486
+
1487
+ /**
1488
+ * Returns the list of AI-customized avatars for the current user.
1489
+ * Each entry represents a previously generated AI customization for a specific base avatar.
1490
+ * The result is cached for 30 seconds.
1491
+ *
1492
+ * **Example**:
1493
+ * ```
1494
+ * _smartico.api.getAvatarsCustomized().then((result) => {
1495
+ * console.log(result);
1496
+ * });
1497
+ * ```
1498
+ *
1499
+ * **Visitor mode: not supported**
1500
+ */
1501
+ public async getAvatarsCustomized(): Promise<TAvatarCustomized[]> {
1502
+ return OCache.use(
1503
+ onUpdateContextKey.AvatarsCustomized,
1504
+ ECacheContext.WSAPI,
1505
+ async () => {
1506
+ const response = await this.api.avatarsGetCustomized(this.userExtId);
1507
+ return response.avatars || [];
1508
+ },
1509
+ CACHE_DATA_SEC,
1510
+ );
1511
+ }
1512
+
1513
+ /**
1514
+ * Returns the list of AI customization prompts (styles) available for avatar customization.
1515
+ * Each prompt represents a visual style that can be applied to a base avatar.
1516
+ * The result is cached for 30 seconds.
1517
+ *
1518
+ * **Example**:
1519
+ * ```
1520
+ * _smartico.api.getAvatarPrompts().then((result) => {
1521
+ * console.log(result);
1522
+ * });
1523
+ * ```
1524
+ *
1525
+ * **Visitor mode: not supported**
1526
+ */
1527
+ public async getAvatarPrompts(): Promise<TAvatarPrompt[]> {
1528
+ return OCache.use(
1529
+ onUpdateContextKey.AvatarPrompts,
1530
+ ECacheContext.WSAPI,
1531
+ async () => {
1532
+ const response = await this.api.avatarsGetPrompts(this.userExtId);
1533
+ return response.prompts || [];
1534
+ },
1535
+ CACHE_DATA_SEC,
1536
+ );
1537
+ }
1538
+
1539
+ /**
1540
+ * 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)
1542
+ * and `avatar_real_id` from the avatar catalog.
1543
+ * After a successful call, the avatar list cache is cleared so the next `getAvatarsList()` call reflects `is_in_use`.
1544
+ *
1545
+ * **Example**:
1546
+ * ```
1547
+ * _smartico.api.getAvatarsList().then((avatars) => {
1548
+ * const avatar = avatars.find((a) => !a.hide_until_achieved || a.is_given);
1549
+ * if (avatar) {
1550
+ * _smartico.api.setAvatar({
1551
+ * avatar_url: avatar.public_meta.url,
1552
+ * avatar_real_id: avatar.avatar_real_id,
1553
+ * }).then((result) => {
1554
+ * console.log(result);
1555
+ * });
1556
+ * }
1557
+ * });
1558
+ * ```
1559
+ *
1560
+ * **Visitor mode: not supported**
1561
+ */
1562
+ public async setAvatar(props: { avatar_url: string; avatar_real_id: number }): Promise<TSetAvatarResult> {
1563
+ if (!props.avatar_url) {
1564
+ throw new Error('avatar_url is required');
1565
+ }
1566
+ if (!props.avatar_real_id) {
1567
+ throw new Error('avatar_real_id is required');
1568
+ }
1569
+
1570
+ const r = await this.api.avatarSetAvatar(this.userExtId, props.avatar_url, props.avatar_real_id);
1571
+
1572
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.AvatarsList);
1573
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.AvatarsCustomized);
1574
+
1575
+ return {
1576
+ err_code: r.errCode ?? 0,
1577
+ err_message: r.errMsg,
1578
+ };
1579
+ }
1580
+
1448
1581
  private async updateOnSpin(data: SAWSpinsCountPush) {
1449
1582
  const templates: TMiniGameTemplate[] = await OCache.use(
1450
1583
  onUpdateContextKey.Saw,
@@ -1880,4 +1880,81 @@ 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
+ */
1886
+ export interface TAvatarDefinition {
1887
+ /** Unique identifier of the avatar */
1888
+ avatar_real_id: number;
1889
+ /** Whether this avatar is the default one */
1890
+ is_default: boolean;
1891
+ /** If true, avatar is hidden until user achieves/unlocks it */
1892
+ hide_until_achieved: boolean;
1893
+ /** Display priority — lower value means higher position in the grid */
1894
+ 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
+ };
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
+ /** Full CDN URL of the avatar image, built from avatar_domain + public_meta.url */
1916
+ avatar_url: string;
1917
+ }
1918
+
1919
+ /**
1920
+ * TAvatarCustomized describes an AI-customized version of a base avatar
1921
+ */
1922
+ export interface TAvatarCustomized {
1923
+ /** The avatar_real_id of the base avatar this customization was generated from */
1924
+ avatar_real_id: number;
1925
+ /** Full CDN URL of the AI-generated customized avatar image */
1926
+ url: string;
1927
+ /** ISO date string when the customization was created */
1928
+ dt_created: string;
1929
+ }
1930
+
1931
+ /**
1932
+ * TAvatarPrompt describes an AI style prompt available for avatar customization
1933
+ */
1934
+ export interface TAvatarPrompt {
1935
+ /** Unique identifier of the AI customization prompt */
1936
+ 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
+ };
1944
+ /** Currency type used to pay for this customization (0=points, 1=gems, 2=diamonds) */
1945
+ cost_currency_type_id: number;
1946
+ /** Cost amount in the given currency */
1947
+ cost_value: number;
1948
+ }
1949
+
1950
+ /**
1951
+ * TSetAvatarResult describes the response of call to _smartico.api.setAvatar() method
1952
+ */
1953
+ export interface TSetAvatarResult {
1954
+ /** Error code that represents outcome of the set avatar request. Successful if err_code is 0 */
1955
+ err_code: number;
1956
+ /** Optional error message */
1957
+ err_message?: string;
1958
+ }
1959
+
1883
1960
  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';