@smartico/public-api 0.0.110 → 0.0.112
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/Leaderboard/LeaderBoards.d.ts +3 -0
- package/dist/Level/LevelPublicMeta.d.ts +2 -0
- package/dist/SmarticoAPI.d.ts +2 -1
- package/dist/WSAPI/WSAPI.d.ts +6 -1
- package/dist/WSAPI/WSAPITypes.d.ts +41 -0
- package/dist/index.js +196 -93
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +105 -31
- package/dist/index.modern.mjs.map +1 -1
- package/docs/README.md +3 -0
- package/docs/classes/WSAPI.md +25 -6
- package/docs/interfaces/LeaderBoardDetailsT.md +65 -0
- package/docs/interfaces/LeaderBoardUserT.md +41 -0
- package/docs/interfaces/LeaderBoardsRewardsT.md +13 -0
- package/docs/interfaces/TAchCategory.md +1 -1
- package/docs/interfaces/TLevel.md +8 -0
- package/docs/interfaces/TMissionOrBadge.md +6 -1
- package/docs/interfaces/TStoreItem.md +9 -1
- package/package.json +1 -1
- package/src/Leaderboard/LeaderBoards.ts +51 -0
- package/src/Level/GetLevelMapResponse.ts +2 -0
- package/src/Level/LevelPublicMeta.ts +2 -0
- package/src/Missions/UserAchievement.ts +5 -3
- package/src/OCache.ts +10 -3
- package/src/SmarticoAPI.ts +18 -7
- package/src/Store/StoreItem.ts +1 -0
- package/src/WSAPI/WSAPI.ts +20 -6
- package/src/WSAPI/WSAPITypes.ts +48 -1
package/dist/index.modern.mjs
CHANGED
|
@@ -380,12 +380,12 @@ class OCache {
|
|
|
380
380
|
static get(oKey, cacheContext) {
|
|
381
381
|
const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
|
|
382
382
|
this.init(cacheContext);
|
|
383
|
-
return this.cache[cacheContext].get(key);
|
|
383
|
+
return deepClone(this.cache[cacheContext].get(key));
|
|
384
384
|
}
|
|
385
385
|
static set(oKey, o, cacheContext, ttlSeconds = 60) {
|
|
386
386
|
const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
|
|
387
387
|
this.init(cacheContext);
|
|
388
|
-
this.cache[cacheContext].set(key, o, ttlSeconds);
|
|
388
|
+
this.cache[cacheContext].set(key, deepClone(o), ttlSeconds);
|
|
389
389
|
}
|
|
390
390
|
static async use(oKey, cacheContext, f, ttlSeconds = 60) {
|
|
391
391
|
if (ttlSeconds <= 0) {
|
|
@@ -406,6 +406,12 @@ class OCache {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
OCache.cache = {};
|
|
409
|
+
const deepClone = o => {
|
|
410
|
+
if (o) {
|
|
411
|
+
return JSON.parse(JSON.stringify(o));
|
|
412
|
+
}
|
|
413
|
+
return o;
|
|
414
|
+
};
|
|
409
415
|
|
|
410
416
|
var ActivityTypeLimited;
|
|
411
417
|
(function (ActivityTypeLimited) {
|
|
@@ -571,6 +577,7 @@ const StoreItemTransform = items => {
|
|
|
571
577
|
limit_message: r.itemPublicMeta.limit_message,
|
|
572
578
|
priority: r.itemPublicMeta.priority,
|
|
573
579
|
related_item_ids: r.itemPublicMeta.related_items,
|
|
580
|
+
hint_text: r.itemPublicMeta.hint_text,
|
|
574
581
|
type: {
|
|
575
582
|
[StoreItemType.Bonus]: 'bonus',
|
|
576
583
|
[StoreItemType.Manual]: 'manual'
|
|
@@ -608,10 +615,11 @@ var AchievementType;
|
|
|
608
615
|
const UserAchievementTransform = items => {
|
|
609
616
|
return items.filter(r => r.ach_id >= 1).map(r => {
|
|
610
617
|
var _r$ach_categories;
|
|
611
|
-
|
|
618
|
+
const x = {
|
|
612
619
|
id: r.ach_id,
|
|
613
620
|
name: r.ach_public_meta.name,
|
|
614
621
|
description: r.ach_public_meta.description,
|
|
622
|
+
hint_text: r.ach_public_meta.hint_text,
|
|
615
623
|
unlock_mission_description: r.ach_public_meta.unlock_mission_description,
|
|
616
624
|
image: r.ach_public_meta.image_url,
|
|
617
625
|
is_completed: r.isCompleted,
|
|
@@ -651,6 +659,7 @@ const UserAchievementTransform = items => {
|
|
|
651
659
|
})),
|
|
652
660
|
category_ids: (_r$ach_categories = r.ach_categories) != null ? _r$ach_categories : []
|
|
653
661
|
};
|
|
662
|
+
return x;
|
|
654
663
|
});
|
|
655
664
|
};
|
|
656
665
|
|
|
@@ -914,17 +923,28 @@ var TournamentType;
|
|
|
914
923
|
TournamentType[TournamentType["TEST"] = 3] = "TEST";
|
|
915
924
|
})(TournamentType || (TournamentType = {}));
|
|
916
925
|
|
|
926
|
+
var LeaderBoardPeriodType;
|
|
927
|
+
(function (LeaderBoardPeriodType) {
|
|
928
|
+
LeaderBoardPeriodType[LeaderBoardPeriodType["DAILY"] = 1] = "DAILY";
|
|
929
|
+
LeaderBoardPeriodType[LeaderBoardPeriodType["WEEKLY"] = 2] = "WEEKLY";
|
|
930
|
+
LeaderBoardPeriodType[LeaderBoardPeriodType["MONTHLY"] = 3] = "MONTHLY";
|
|
931
|
+
})(LeaderBoardPeriodType || (LeaderBoardPeriodType = {}));
|
|
932
|
+
|
|
917
933
|
const GetLevelMapResponseTransform = levels => {
|
|
918
|
-
return levels == null ? void 0 : levels.levels.map(l =>
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
934
|
+
return levels == null ? void 0 : levels.levels.map(l => {
|
|
935
|
+
var _l$level_public_meta;
|
|
936
|
+
return {
|
|
937
|
+
id: l.level_id,
|
|
938
|
+
name: l.level_public_meta.name,
|
|
939
|
+
description: l.level_public_meta.description,
|
|
940
|
+
image: l.level_public_meta.image_url,
|
|
941
|
+
required_points: l.required_points,
|
|
942
|
+
visibility_points: parseInt(l.level_public_meta.visibility_points),
|
|
943
|
+
required_level_counter_1: l.required_level_counter_1,
|
|
944
|
+
required_level_counter_2: l.required_level_counter_2,
|
|
945
|
+
custom_data: IntUtils.JsonOrText((_l$level_public_meta = l.level_public_meta) == null ? void 0 : _l$level_public_meta.custom_data)
|
|
946
|
+
};
|
|
947
|
+
});
|
|
928
948
|
};
|
|
929
949
|
|
|
930
950
|
/** @hidden */
|
|
@@ -936,6 +956,12 @@ var onUpdateContextKey;
|
|
|
936
956
|
onUpdateContextKey["Missions"] = "missions";
|
|
937
957
|
onUpdateContextKey["TournamentList"] = "tournamentList";
|
|
938
958
|
onUpdateContextKey["InboxMessages"] = "inboxMessages";
|
|
959
|
+
onUpdateContextKey["Badges"] = "badges";
|
|
960
|
+
onUpdateContextKey["Levels"] = "levels";
|
|
961
|
+
onUpdateContextKey["StoreItems"] = "storeItems";
|
|
962
|
+
onUpdateContextKey["StoreCategories"] = "storeCategories";
|
|
963
|
+
onUpdateContextKey["AchCategories"] = "achCategories";
|
|
964
|
+
onUpdateContextKey["LeaderBoards"] = "leaderBoards";
|
|
939
965
|
})(onUpdateContextKey || (onUpdateContextKey = {}));
|
|
940
966
|
/** @group General API */
|
|
941
967
|
class WSAPI {
|
|
@@ -966,7 +992,7 @@ class WSAPI {
|
|
|
966
992
|
}
|
|
967
993
|
/** Returns all the levels available the current user */
|
|
968
994
|
async getLevels() {
|
|
969
|
-
return this.api.levelsGetT(null);
|
|
995
|
+
return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(null), CACHE_DATA_SEC);
|
|
970
996
|
}
|
|
971
997
|
/** Returns all the missions available the current user.
|
|
972
998
|
* The returned missions is cached for 30 seconds. But you can pass the onUpdate callback as a parameter. Note that each time you call getMissions with a new onUpdate callback, the old one will be overwritten by the new one.
|
|
@@ -984,11 +1010,11 @@ class WSAPI {
|
|
|
984
1010
|
}
|
|
985
1011
|
/** Returns all the badges available the current user */
|
|
986
1012
|
async getBadges() {
|
|
987
|
-
return this.api.badgetsGetItemsT(null);
|
|
1013
|
+
return OCache.use(onUpdateContextKey.Badges, ECacheContext.WSAPI, () => this.api.badgetsGetItemsT(null), CACHE_DATA_SEC);
|
|
988
1014
|
}
|
|
989
1015
|
/** Returns all the store items available the current user */
|
|
990
1016
|
async getStoreItems() {
|
|
991
|
-
return this.api.storeGetItemsT(null);
|
|
1017
|
+
return OCache.use(onUpdateContextKey.StoreItems, ECacheContext.WSAPI, () => this.api.storeGetItemsT(null), CACHE_DATA_SEC);
|
|
992
1018
|
}
|
|
993
1019
|
/** Buy the specific shop item by item_id. Returns the err_code.*/
|
|
994
1020
|
async buyStoreItem(item_id) {
|
|
@@ -1001,11 +1027,11 @@ class WSAPI {
|
|
|
1001
1027
|
}
|
|
1002
1028
|
/** Returns store categories */
|
|
1003
1029
|
async getStoreCategories() {
|
|
1004
|
-
return this.api.storeGetCategoriesT(null);
|
|
1030
|
+
return OCache.use(onUpdateContextKey.StoreCategories, ECacheContext.WSAPI, () => this.api.storeGetCategoriesT(null), CACHE_DATA_SEC);
|
|
1005
1031
|
}
|
|
1006
1032
|
/** Returns ach categories */
|
|
1007
1033
|
async getAchCategories() {
|
|
1008
|
-
return this.api.achGetCategoriesT(null);
|
|
1034
|
+
return OCache.use(onUpdateContextKey.AchCategories, ECacheContext.WSAPI, () => this.api.achGetCategoriesT(null), CACHE_DATA_SEC);
|
|
1009
1035
|
}
|
|
1010
1036
|
/** Returns the list of mini-games available for user
|
|
1011
1037
|
* The returned list of mini-games is cached for 30 seconds. But you can pass the onUpdate callback as a parameter. Note that each time you call getMiniGames with a new onUpdate callback, the old one will be overwritten by the new one.
|
|
@@ -1069,6 +1095,12 @@ class WSAPI {
|
|
|
1069
1095
|
};
|
|
1070
1096
|
return o;
|
|
1071
1097
|
}
|
|
1098
|
+
/** Returns the leaderboard for the current type (default is Daily). If getPreviousPeriod is passed as true, a leaderboard for the previous period for the current type will be returned.
|
|
1099
|
+
For example, if the type is Weekly and getPreviousPeriod is true, a leaderboard for the previous week will be returned.
|
|
1100
|
+
*/
|
|
1101
|
+
async getLeaderBoard(periodType, getPreviousPeriod) {
|
|
1102
|
+
return OCache.use(onUpdateContextKey.LeaderBoards, ECacheContext.WSAPI, () => this.api.leaderboardsGetT(null, periodType, getPreviousPeriod), CACHE_DATA_SEC);
|
|
1103
|
+
}
|
|
1072
1104
|
/** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
|
|
1073
1105
|
* The maximum number of messages per request is limited to 20. An indicator "onlyFavorite" can be passed to get only messages marked as favorites.
|
|
1074
1106
|
* You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
|
|
@@ -1184,6 +1216,48 @@ class WSAPI {
|
|
|
1184
1216
|
}
|
|
1185
1217
|
}
|
|
1186
1218
|
|
|
1219
|
+
const pointsRewardTransform = reward_points => {
|
|
1220
|
+
if (reward_points && reward_points.length) {
|
|
1221
|
+
return reward_points.map((r, i) => ({
|
|
1222
|
+
place: i + 1,
|
|
1223
|
+
points: r
|
|
1224
|
+
}));
|
|
1225
|
+
}
|
|
1226
|
+
return null;
|
|
1227
|
+
};
|
|
1228
|
+
const getLeaderBoardPlayerTransformed = (user, isMe) => {
|
|
1229
|
+
if (user) {
|
|
1230
|
+
const x = {
|
|
1231
|
+
public_username: (user == null ? void 0 : user.public_username) || user.user_alt_name,
|
|
1232
|
+
avatar_url: user.avatar_url,
|
|
1233
|
+
position: user.position_in_board,
|
|
1234
|
+
points: user.points_accumulated,
|
|
1235
|
+
is_me: user.is_me
|
|
1236
|
+
};
|
|
1237
|
+
if (isMe) {
|
|
1238
|
+
delete x.is_me;
|
|
1239
|
+
}
|
|
1240
|
+
return x;
|
|
1241
|
+
}
|
|
1242
|
+
return null;
|
|
1243
|
+
};
|
|
1244
|
+
const getLeaderBoardTransform = board => {
|
|
1245
|
+
if (board) {
|
|
1246
|
+
const x = {
|
|
1247
|
+
board_id: board.board_id,
|
|
1248
|
+
name: board.board_public_meta.name,
|
|
1249
|
+
description: board.board_public_meta.description,
|
|
1250
|
+
rules: board.board_public_meta.rules,
|
|
1251
|
+
period_type_id: board.period_type_id,
|
|
1252
|
+
rewards: pointsRewardTransform(board.reward_points),
|
|
1253
|
+
users: board.positions.map(p => getLeaderBoardPlayerTransformed(p)),
|
|
1254
|
+
me: getLeaderBoardPlayerTransformed(board.userPosition, true)
|
|
1255
|
+
};
|
|
1256
|
+
return x;
|
|
1257
|
+
}
|
|
1258
|
+
return null;
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1187
1261
|
const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
|
|
1188
1262
|
const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
|
|
1189
1263
|
const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
|
|
@@ -1490,10 +1564,12 @@ class SmarticoAPI {
|
|
|
1490
1564
|
async missionsGetItems(user_ext_id) {
|
|
1491
1565
|
const message = this.buildMessage(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
|
|
1492
1566
|
const response = await this.send(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
|
|
1493
|
-
|
|
1494
|
-
|
|
1567
|
+
// we need to clone response to avoid changing original object,for cases when its called together with badgesGetItems (e.g. in Promise.all)
|
|
1568
|
+
const responseClone = _extends({}, response);
|
|
1569
|
+
if (responseClone.achievements) {
|
|
1570
|
+
responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Mission);
|
|
1495
1571
|
}
|
|
1496
|
-
return
|
|
1572
|
+
return responseClone;
|
|
1497
1573
|
}
|
|
1498
1574
|
async missionsGetItemsT(user_ext_id) {
|
|
1499
1575
|
return UserAchievementTransform((await this.missionsGetItems(user_ext_id)).achievements);
|
|
@@ -1508,10 +1584,12 @@ class SmarticoAPI {
|
|
|
1508
1584
|
async badgetsGetItems(user_ext_id) {
|
|
1509
1585
|
const message = this.buildMessage(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
|
|
1510
1586
|
const response = await this.send(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
|
|
1511
|
-
|
|
1512
|
-
|
|
1587
|
+
// we need to clone response to avoid changing original object,for cases when its called together with missionsGetItems (e.g. in Promise.all)
|
|
1588
|
+
const responseClone = _extends({}, response);
|
|
1589
|
+
if (responseClone.achievements) {
|
|
1590
|
+
responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Badge);
|
|
1513
1591
|
}
|
|
1514
|
-
return
|
|
1592
|
+
return responseClone;
|
|
1515
1593
|
}
|
|
1516
1594
|
async badgetsGetItemsT(user_ext_id) {
|
|
1517
1595
|
return UserAchievementTransform((await this.badgetsGetItems(user_ext_id)).achievements);
|
|
@@ -1568,6 +1646,9 @@ class SmarticoAPI {
|
|
|
1568
1646
|
}
|
|
1569
1647
|
return response.map[boardKey];
|
|
1570
1648
|
}
|
|
1649
|
+
async leaderboardsGetT(user_ext_id, period_type_id = LeaderBoardPeriodType.DAILY, prevPeriod = false) {
|
|
1650
|
+
return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod));
|
|
1651
|
+
}
|
|
1571
1652
|
async levelsGet(user_ext_id) {
|
|
1572
1653
|
const message = this.buildMessage(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
|
|
1573
1654
|
return await this.send(message, ClassId.GET_LEVEL_MAP_RESPONSE);
|
|
@@ -1665,12 +1746,5 @@ class CookieStore {
|
|
|
1665
1746
|
}
|
|
1666
1747
|
CookieStore.cookieStore = new TSMap();
|
|
1667
1748
|
|
|
1668
|
-
var LeaderBoardPeriodType;
|
|
1669
|
-
(function (LeaderBoardPeriodType) {
|
|
1670
|
-
LeaderBoardPeriodType[LeaderBoardPeriodType["DAILY"] = 1] = "DAILY";
|
|
1671
|
-
LeaderBoardPeriodType[LeaderBoardPeriodType["WEEKLY"] = 2] = "WEEKLY";
|
|
1672
|
-
LeaderBoardPeriodType[LeaderBoardPeriodType["MONTHLY"] = 3] = "MONTHLY";
|
|
1673
|
-
})(LeaderBoardPeriodType || (LeaderBoardPeriodType = {}));
|
|
1674
|
-
|
|
1675
1749
|
export { AchCategoryTransform, AchievementStatus, AchievementTaskType, AchievementType, ActivityTypeLimited, BuyStoreItemErrorCode, ClassId, CookieStore, CoreUtils, GetLevelMapResponseTransform, InboxMessageBodyTransform, InboxMessageType, InboxMessagesTransform, LeaderBoardPeriodType, MiniGamePrizeTypeName, MiniGamePrizeTypeNamed, PublicLabelSettings, SAWAcknowledgeType, SAWAskForUsername, SAWBuyInType, SAWBuyInTypeName, SAWBuyInTypeNamed, SAWGameType, SAWGameTypeName, SAWGameTypeNamed, SAWPrizeType, SAWSpinErrorCode, SAWTemplatesTransform, SAWUtils, SAWWinSoundFiles, SAWWinSoundType, ScheduledMissionType, SmarticoAPI, StoreCategoryTransform, StoreItemTransform, StoreItemType, TournamentInstanceStatus, TournamentInstanceStatusName, TournamentItemsTransform, TournamentRegistrationError, TournamentRegistrationStatus, TournamentRegistrationStatusName, TournamentRegistrationStatusNamed, TournamentRegistrationType, TournamentRegistrationTypeGetName, TournamentType, TournamentUtils, TranslationArea, UserAchievementTransform, tournamentInfoItemTransform };
|
|
1676
1750
|
//# sourceMappingURL=index.modern.mjs.map
|