@smartico/public-api 0.0.281 → 0.0.283

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/docs/README.md CHANGED
@@ -106,6 +106,7 @@
106
106
  - [TMiniGameTemplate](interfaces/TMiniGameTemplate.md)
107
107
  - [TUserProfile](interfaces/TUserProfile.md)
108
108
  - [TLevel](interfaces/TLevel.md)
109
+ - [TLevelCurrent](interfaces/TLevelCurrent.md)
109
110
  - [TTournament](interfaces/TTournament.md)
110
111
  - [TTournamentDetailed](interfaces/TTournamentDetailed.md)
111
112
  - [TStoreCategory](interfaces/TStoreCategory.md)
@@ -98,6 +98,27 @@ _smartico.vapi('EN').getLevels().then((result) => {
98
98
 
99
99
  ___
100
100
 
101
+ ### getCurrentLevel
102
+
103
+ ▸ **getCurrentLevel**(): `Promise`\<[`TLevelCurrent`](../interfaces/TLevelCurrent.md)\>
104
+
105
+ Returns the current level of the user with extended information including ordinal position and progress.
106
+
107
+ **Example**:
108
+ ```
109
+ _smartico.api.getCurrentLevel().then((result) => {
110
+ console.log(result);
111
+ });
112
+ ```
113
+
114
+ **Visitor mode: not supported**
115
+
116
+ #### Returns
117
+
118
+ `Promise`\<[`TLevelCurrent`](../interfaces/TLevelCurrent.md)\>
119
+
120
+ ___
121
+
101
122
  ### getMissions
102
123
 
103
124
  ▸ **getMissions**(`«destructured»?`): `Promise`\<[`TMissionOrBadge`](../interfaces/TMissionOrBadge.md)[]\>
@@ -5,6 +5,12 @@ There is no order of the levels, but it can be calculated using required_points
5
5
  The current level of user can be taken from the user object using ach_level_current_id property
6
6
  The progress to the next level can be calculated using ach_points_ever and required_points properties of next level
7
7
 
8
+ ## Hierarchy
9
+
10
+ - **`TLevel`**
11
+
12
+ ↳ [`TLevelCurrent`](TLevelCurrent.md)
13
+
8
14
  ## Properties
9
15
 
10
16
  ### id
@@ -0,0 +1,139 @@
1
+ # Interface: TLevelCurrent
2
+
3
+ TLevelCurrent describes the information of each level defined in the system along with ordinal position and progress of the current level
4
+
5
+ ## Hierarchy
6
+
7
+ - [`TLevel`](TLevel.md)
8
+
9
+ ↳ **`TLevelCurrent`**
10
+
11
+ ## Properties
12
+
13
+ ### id
14
+
15
+ • **id**: `number`
16
+
17
+ The ID of the Level
18
+
19
+ #### Inherited from
20
+
21
+ [TLevel](TLevel.md).[id](TLevel.md#id)
22
+
23
+ ___
24
+
25
+ ### name
26
+
27
+ • **name**: `string`
28
+
29
+ The name of the Level, translated to the user language
30
+
31
+ #### Inherited from
32
+
33
+ [TLevel](TLevel.md).[name](TLevel.md#name)
34
+
35
+ ___
36
+
37
+ ### description
38
+
39
+ • **description**: `string`
40
+
41
+ The description of the Level, translated to the user language
42
+
43
+ #### Inherited from
44
+
45
+ [TLevel](TLevel.md).[description](TLevel.md#description)
46
+
47
+ ___
48
+
49
+ ### image
50
+
51
+ • **image**: `string`
52
+
53
+ The URL of the image of the Level
54
+
55
+ #### Inherited from
56
+
57
+ [TLevel](TLevel.md).[image](TLevel.md#image)
58
+
59
+ ___
60
+
61
+ ### required\_points
62
+
63
+ • **required\_points**: `number`
64
+
65
+ The amount of points required to reach the Level
66
+
67
+ #### Inherited from
68
+
69
+ [TLevel](TLevel.md).[required_points](TLevel.md#required_points)
70
+
71
+ ___
72
+
73
+ ### visibility\_points
74
+
75
+ • **visibility\_points**: `number`
76
+
77
+ Number of points that user should collect in order to see this level
78
+
79
+ #### Inherited from
80
+
81
+ [TLevel](TLevel.md).[visibility_points](TLevel.md#visibility_points)
82
+
83
+ ___
84
+
85
+ ### required\_level\_counter\_1
86
+
87
+ • **required\_level\_counter\_1**: `number`
88
+
89
+ The counter of 1st metric used to reach the Level.
90
+ Relevant in case of using advanced leveling logic
91
+ https://help.smartico.ai/welcome/more/release-notes/september-2022#new-logic-for-leveling-users
92
+
93
+ #### Inherited from
94
+
95
+ [TLevel](TLevel.md).[required_level_counter_1](TLevel.md#required_level_counter_1)
96
+
97
+ ___
98
+
99
+ ### required\_level\_counter\_2
100
+
101
+ • **required\_level\_counter\_2**: `number`
102
+
103
+ The counter of 2nd metric used to reach the Level.
104
+ Relevant in case of using advanced leveling logic
105
+ https://help.smartico.ai/welcome/more/release-notes/september-2022#new-logic-for-leveling-users
106
+
107
+ #### Inherited from
108
+
109
+ [TLevel](TLevel.md).[required_level_counter_2](TLevel.md#required_level_counter_2)
110
+
111
+ ___
112
+
113
+ ### custom\_data
114
+
115
+ • **custom\_data**: `string`
116
+
117
+ Custom data as string or JSON string that can be used in API to build custom UI
118
+ You can request from Smartico to define fields for your specific case that will be managed from Smartico BackOffice
119
+ Read more here - https://help.smartico.ai/welcome/products/general-concepts/custom-fields-attributes
120
+
121
+ #### Inherited from
122
+
123
+ [TLevel](TLevel.md).[custom_data](TLevel.md#custom_data)
124
+
125
+ ___
126
+
127
+ ### ordinal\_position
128
+
129
+ • **ordinal\_position**: `number`
130
+
131
+ The ordinal position of the level
132
+
133
+ ___
134
+
135
+ ### progress
136
+
137
+ • **progress**: `number`
138
+
139
+ The progress of the level
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.281",
3
+ "version": "0.0.283",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,5 @@
1
1
  export interface AchievementTaskPublicMeta {
2
2
  name?: string;
3
3
  display_progress_as_count?: boolean;
4
+ stage_image?: string;
4
5
  }
@@ -92,6 +92,7 @@ export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBa
92
92
  execution_count_expected: t.executionCount,
93
93
  execution_count_actual: t.userExecutedCount,
94
94
  display_progress_as_count: t.task_public_meta.display_progress_as_count,
95
+ stage_image: t.task_public_meta.stage_image,
95
96
  })),
96
97
  related_games: (r.related_games || []).map((g) => ({
97
98
  ext_game_id: g.ext_game_id,
@@ -94,6 +94,7 @@ import {
94
94
  TUICustomSection,
95
95
  TBonus,
96
96
  TRaffle,
97
+ TLevelCurrent,
97
98
  } from './WSAPI/WSAPITypes';
98
99
  import { getLeaderBoardTransform } from './Leaderboard/LeaderBoards';
99
100
  import { GetAchievementsUserInfoResponse } from './Core/GetAchievementsUserInfoResponse';
@@ -1028,6 +1029,35 @@ class SmarticoAPI {
1028
1029
  return GetLevelMapResponseTransform(await this.levelsGet(user_ext_id));
1029
1030
  }
1030
1031
 
1032
+ public async getLevelCurrent(user_ext_id: string): Promise<TLevelCurrent> {
1033
+ const levels = await this.levelsGetT(user_ext_id);
1034
+ const userInfo = await this.getUserGamificationInfo(user_ext_id);
1035
+ if (!levels || levels.length === 0) return null;
1036
+
1037
+ const userPoints = userInfo.points_balance;
1038
+
1039
+ const sortedLevels = levels.sort((a, b) => a.required_points - b.required_points);
1040
+
1041
+ let currentLevelIndex = sortedLevels.findIndex((level, index) => {
1042
+ const nextLevel = sortedLevels[index + 1];
1043
+ return userPoints >= level.required_points && (!nextLevel || userPoints < nextLevel.required_points);
1044
+ });
1045
+
1046
+ if (currentLevelIndex === -1) {
1047
+ currentLevelIndex = sortedLevels.length - 1;
1048
+ }
1049
+
1050
+ const currentLevel = sortedLevels[currentLevelIndex];
1051
+ const nextLevel = sortedLevels[currentLevelIndex + 1];
1052
+ const progress = nextLevel ? ((userPoints - currentLevel.required_points) / (nextLevel.required_points - currentLevel.required_points)) * 100 : 100;
1053
+
1054
+ return {
1055
+ ...currentLevel,
1056
+ ordinal_position: currentLevelIndex + 1,
1057
+ progress: Math.min(Math.max(progress, 0), 100)
1058
+ };
1059
+ }
1060
+
1031
1061
  public async customSectionsGet(user_ext_id: string, force_language?: string): Promise<GetCustomSectionsResponse> {
1032
1062
  const message = this.buildMessage<GetCustomSectionsRequest, GetCustomSectionsResponse>(
1033
1063
  user_ext_id,
@@ -36,6 +36,7 @@ import {
36
36
  TRaffleDraw,
37
37
  TRaffleDrawRun,
38
38
  TransformedRaffleClaimPrizeResponse,
39
+ TLevelCurrent
39
40
  } from './WSAPITypes';
40
41
  import { LeaderBoardPeriodType } from '../Leaderboard';
41
42
  import {
@@ -88,6 +89,7 @@ enum onUpdateContextKey {
88
89
  JackpotWinners = 'jackpotWinners',
89
90
  Raffles = 'raffles',
90
91
  JackpotEligibleGames = 'jackpotEligibleGames',
92
+ CurrentLevel = 'currentLevel',
91
93
  }
92
94
 
93
95
  /** @group General API */
@@ -211,6 +213,22 @@ export class WSAPI {
211
213
  return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(null), CACHE_DATA_SEC);
212
214
  }
213
215
 
216
+ /**
217
+ * Returns the current level of the user with extended information including ordinal position and progress.
218
+ *
219
+ * **Example**:
220
+ * ```
221
+ * _smartico.api.getCurrentLevel().then((result) => {
222
+ * console.log(result);
223
+ * });
224
+ * ```
225
+ *
226
+ * **Visitor mode: not supported**
227
+ */
228
+ public async getCurrentLevel(): Promise<TLevelCurrent> {
229
+ return OCache.use(onUpdateContextKey.CurrentLevel, ECacheContext.WSAPI, () => this.api.getLevelCurrent(null), CACHE_DATA_SEC);
230
+ }
231
+
214
232
  /** Returns all the missions available the current user.
215
233
  * The returned missions are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
216
234
  * Note that each time you call getMissions with a new onUpdate callback, the old one will be overwritten by the new one.
@@ -260,6 +260,17 @@ export interface TLevel {
260
260
  custom_data: string;
261
261
  }
262
262
 
263
+ /**
264
+ * TLevelCurrent describes the information of each level defined in the system along with ordinal position and progress of the current level
265
+ */
266
+
267
+ export interface TLevelCurrent extends TLevel {
268
+ /** The ordinal position of the level */
269
+ ordinal_position: number;
270
+ /** The progress of the level */
271
+ progress: number;
272
+ }
273
+
263
274
  /**
264
275
  * TTournament describes the general information of the tournament item
265
276
  */