@smartico/public-api 0.0.280 → 0.0.282
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/dist/MiniGames/SAWTemplateUI.d.ts +1 -0
- package/dist/Missions/AchievementTaskPublicMeta.d.ts +1 -0
- package/dist/SmarticoAPI.d.ts +2 -1
- package/dist/SmarticoLib/index.d.ts +1 -0
- package/dist/WSAPI/WSAPI.d.ts +14 -1
- package/dist/WSAPI/WSAPITypes.d.ts +9 -0
- package/dist/index.js +231 -176
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +39 -1
- package/dist/index.modern.mjs.map +1 -1
- package/docs/interfaces/SAWTemplateUI.md +6 -0
- package/package.json +1 -1
- package/src/MiniGames/SAWTemplateUI.ts +1 -0
- package/src/Missions/AchievementTaskPublicMeta.ts +1 -0
- package/src/Missions/UserAchievement.ts +1 -0
- package/src/SmarticoAPI.ts +30 -0
- package/src/SmarticoLib/index.ts +1 -0
- package/src/WSAPI/WSAPI.ts +18 -0
- package/src/WSAPI/WSAPITypes.ts +11 -0
- package/tsconfig.json +4 -5
package/dist/index.modern.mjs
CHANGED
|
@@ -1279,7 +1279,8 @@ const UserAchievementTransform = items => {
|
|
|
1279
1279
|
progress: t.userProgress,
|
|
1280
1280
|
execution_count_expected: t.executionCount,
|
|
1281
1281
|
execution_count_actual: t.userExecutedCount,
|
|
1282
|
-
display_progress_as_count: t.task_public_meta.display_progress_as_count
|
|
1282
|
+
display_progress_as_count: t.task_public_meta.display_progress_as_count,
|
|
1283
|
+
stage_image: t.task_public_meta.stage_image
|
|
1283
1284
|
};
|
|
1284
1285
|
}),
|
|
1285
1286
|
related_games: (r.related_games || []).map(g => ({
|
|
@@ -1864,6 +1865,7 @@ var onUpdateContextKey;
|
|
|
1864
1865
|
onUpdateContextKey["JackpotWinners"] = "jackpotWinners";
|
|
1865
1866
|
onUpdateContextKey["Raffles"] = "raffles";
|
|
1866
1867
|
onUpdateContextKey["JackpotEligibleGames"] = "jackpotEligibleGames";
|
|
1868
|
+
onUpdateContextKey["CurrentLevel"] = "currentLevel";
|
|
1867
1869
|
})(onUpdateContextKey || (onUpdateContextKey = {}));
|
|
1868
1870
|
/** @group General API */
|
|
1869
1871
|
class WSAPI {
|
|
@@ -1981,6 +1983,21 @@ class WSAPI {
|
|
|
1981
1983
|
async getLevels() {
|
|
1982
1984
|
return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(null), CACHE_DATA_SEC);
|
|
1983
1985
|
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Returns the current level of the user with extended information including ordinal position and progress.
|
|
1988
|
+
*
|
|
1989
|
+
* **Example**:
|
|
1990
|
+
* ```
|
|
1991
|
+
* _smartico.api.getCurrentLevel().then((result) => {
|
|
1992
|
+
* console.log(result);
|
|
1993
|
+
* });
|
|
1994
|
+
* ```
|
|
1995
|
+
*
|
|
1996
|
+
* **Visitor mode: not supported**
|
|
1997
|
+
*/
|
|
1998
|
+
async getCurrentLevel() {
|
|
1999
|
+
return OCache.use(onUpdateContextKey.CurrentLevel, ECacheContext.WSAPI, () => this.api.getLevelCurrent(null), CACHE_DATA_SEC);
|
|
2000
|
+
}
|
|
1984
2001
|
/** Returns all the missions available the current user.
|
|
1985
2002
|
* The returned missions are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
|
|
1986
2003
|
* Note that each time you call getMissions with a new onUpdate callback, the old one will be overwritten by the new one.
|
|
@@ -3534,6 +3551,27 @@ class SmarticoAPI {
|
|
|
3534
3551
|
async levelsGetT(user_ext_id) {
|
|
3535
3552
|
return GetLevelMapResponseTransform(await this.levelsGet(user_ext_id));
|
|
3536
3553
|
}
|
|
3554
|
+
async getLevelCurrent(user_ext_id) {
|
|
3555
|
+
const levels = await this.levelsGetT(user_ext_id);
|
|
3556
|
+
const userInfo = await this.getUserGamificationInfo(user_ext_id);
|
|
3557
|
+
if (!levels || levels.length === 0) return null;
|
|
3558
|
+
const userPoints = userInfo.points_balance;
|
|
3559
|
+
const sortedLevels = levels.sort((a, b) => a.required_points - b.required_points);
|
|
3560
|
+
let currentLevelIndex = sortedLevels.findIndex((level, index) => {
|
|
3561
|
+
const nextLevel = sortedLevels[index + 1];
|
|
3562
|
+
return userPoints >= level.required_points && (!nextLevel || userPoints < nextLevel.required_points);
|
|
3563
|
+
});
|
|
3564
|
+
if (currentLevelIndex === -1) {
|
|
3565
|
+
currentLevelIndex = sortedLevels.length - 1;
|
|
3566
|
+
}
|
|
3567
|
+
const currentLevel = sortedLevels[currentLevelIndex];
|
|
3568
|
+
const nextLevel = sortedLevels[currentLevelIndex + 1];
|
|
3569
|
+
const progress = nextLevel ? (userPoints - currentLevel.required_points) / (nextLevel.required_points - currentLevel.required_points) * 100 : 100;
|
|
3570
|
+
return _extends({}, currentLevel, {
|
|
3571
|
+
ordinal_position: currentLevelIndex + 1,
|
|
3572
|
+
progress: Math.min(Math.max(progress, 0), 100)
|
|
3573
|
+
});
|
|
3574
|
+
}
|
|
3537
3575
|
async customSectionsGet(user_ext_id, force_language) {
|
|
3538
3576
|
const message = this.buildMessage(user_ext_id, ClassId.GET_CUSTOM_SECTIONS_REQUEST);
|
|
3539
3577
|
return await this.send(message, ClassId.GET_CUSTOM_SECTIONS_RESPONSE, force_language);
|