@smartico/public-api 0.0.111 → 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/SmarticoAPI.d.ts +2 -1
- package/dist/WSAPI/WSAPI.d.ts +6 -1
- package/dist/WSAPI/WSAPITypes.d.ts +39 -0
- package/dist/index.js +193 -92
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +91 -21
- 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/TMissionOrBadge.md +8 -0
- package/docs/interfaces/TStoreItem.md +8 -0
- package/package.json +1 -1
- package/src/Leaderboard/LeaderBoards.ts +51 -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 +45 -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,6 +923,13 @@ 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
934
|
return levels == null ? void 0 : levels.levels.map(l => {
|
|
919
935
|
var _l$level_public_meta;
|
|
@@ -940,6 +956,12 @@ var onUpdateContextKey;
|
|
|
940
956
|
onUpdateContextKey["Missions"] = "missions";
|
|
941
957
|
onUpdateContextKey["TournamentList"] = "tournamentList";
|
|
942
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";
|
|
943
965
|
})(onUpdateContextKey || (onUpdateContextKey = {}));
|
|
944
966
|
/** @group General API */
|
|
945
967
|
class WSAPI {
|
|
@@ -970,7 +992,7 @@ class WSAPI {
|
|
|
970
992
|
}
|
|
971
993
|
/** Returns all the levels available the current user */
|
|
972
994
|
async getLevels() {
|
|
973
|
-
return this.api.levelsGetT(null);
|
|
995
|
+
return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(null), CACHE_DATA_SEC);
|
|
974
996
|
}
|
|
975
997
|
/** Returns all the missions available the current user.
|
|
976
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.
|
|
@@ -988,11 +1010,11 @@ class WSAPI {
|
|
|
988
1010
|
}
|
|
989
1011
|
/** Returns all the badges available the current user */
|
|
990
1012
|
async getBadges() {
|
|
991
|
-
return this.api.badgetsGetItemsT(null);
|
|
1013
|
+
return OCache.use(onUpdateContextKey.Badges, ECacheContext.WSAPI, () => this.api.badgetsGetItemsT(null), CACHE_DATA_SEC);
|
|
992
1014
|
}
|
|
993
1015
|
/** Returns all the store items available the current user */
|
|
994
1016
|
async getStoreItems() {
|
|
995
|
-
return this.api.storeGetItemsT(null);
|
|
1017
|
+
return OCache.use(onUpdateContextKey.StoreItems, ECacheContext.WSAPI, () => this.api.storeGetItemsT(null), CACHE_DATA_SEC);
|
|
996
1018
|
}
|
|
997
1019
|
/** Buy the specific shop item by item_id. Returns the err_code.*/
|
|
998
1020
|
async buyStoreItem(item_id) {
|
|
@@ -1005,11 +1027,11 @@ class WSAPI {
|
|
|
1005
1027
|
}
|
|
1006
1028
|
/** Returns store categories */
|
|
1007
1029
|
async getStoreCategories() {
|
|
1008
|
-
return this.api.storeGetCategoriesT(null);
|
|
1030
|
+
return OCache.use(onUpdateContextKey.StoreCategories, ECacheContext.WSAPI, () => this.api.storeGetCategoriesT(null), CACHE_DATA_SEC);
|
|
1009
1031
|
}
|
|
1010
1032
|
/** Returns ach categories */
|
|
1011
1033
|
async getAchCategories() {
|
|
1012
|
-
return this.api.achGetCategoriesT(null);
|
|
1034
|
+
return OCache.use(onUpdateContextKey.AchCategories, ECacheContext.WSAPI, () => this.api.achGetCategoriesT(null), CACHE_DATA_SEC);
|
|
1013
1035
|
}
|
|
1014
1036
|
/** Returns the list of mini-games available for user
|
|
1015
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.
|
|
@@ -1073,6 +1095,12 @@ class WSAPI {
|
|
|
1073
1095
|
};
|
|
1074
1096
|
return o;
|
|
1075
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
|
+
}
|
|
1076
1104
|
/** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
|
|
1077
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.
|
|
1078
1106
|
* You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
|
|
@@ -1188,6 +1216,48 @@ class WSAPI {
|
|
|
1188
1216
|
}
|
|
1189
1217
|
}
|
|
1190
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
|
+
|
|
1191
1261
|
const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
|
|
1192
1262
|
const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
|
|
1193
1263
|
const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
|
|
@@ -1494,10 +1564,12 @@ class SmarticoAPI {
|
|
|
1494
1564
|
async missionsGetItems(user_ext_id) {
|
|
1495
1565
|
const message = this.buildMessage(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
|
|
1496
1566
|
const response = await this.send(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
|
|
1497
|
-
|
|
1498
|
-
|
|
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);
|
|
1499
1571
|
}
|
|
1500
|
-
return
|
|
1572
|
+
return responseClone;
|
|
1501
1573
|
}
|
|
1502
1574
|
async missionsGetItemsT(user_ext_id) {
|
|
1503
1575
|
return UserAchievementTransform((await this.missionsGetItems(user_ext_id)).achievements);
|
|
@@ -1512,10 +1584,12 @@ class SmarticoAPI {
|
|
|
1512
1584
|
async badgetsGetItems(user_ext_id) {
|
|
1513
1585
|
const message = this.buildMessage(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
|
|
1514
1586
|
const response = await this.send(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
|
|
1515
|
-
|
|
1516
|
-
|
|
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);
|
|
1517
1591
|
}
|
|
1518
|
-
return
|
|
1592
|
+
return responseClone;
|
|
1519
1593
|
}
|
|
1520
1594
|
async badgetsGetItemsT(user_ext_id) {
|
|
1521
1595
|
return UserAchievementTransform((await this.badgetsGetItems(user_ext_id)).achievements);
|
|
@@ -1572,6 +1646,9 @@ class SmarticoAPI {
|
|
|
1572
1646
|
}
|
|
1573
1647
|
return response.map[boardKey];
|
|
1574
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
|
+
}
|
|
1575
1652
|
async levelsGet(user_ext_id) {
|
|
1576
1653
|
const message = this.buildMessage(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
|
|
1577
1654
|
return await this.send(message, ClassId.GET_LEVEL_MAP_RESPONSE);
|
|
@@ -1669,12 +1746,5 @@ class CookieStore {
|
|
|
1669
1746
|
}
|
|
1670
1747
|
CookieStore.cookieStore = new TSMap();
|
|
1671
1748
|
|
|
1672
|
-
var LeaderBoardPeriodType;
|
|
1673
|
-
(function (LeaderBoardPeriodType) {
|
|
1674
|
-
LeaderBoardPeriodType[LeaderBoardPeriodType["DAILY"] = 1] = "DAILY";
|
|
1675
|
-
LeaderBoardPeriodType[LeaderBoardPeriodType["WEEKLY"] = 2] = "WEEKLY";
|
|
1676
|
-
LeaderBoardPeriodType[LeaderBoardPeriodType["MONTHLY"] = 3] = "MONTHLY";
|
|
1677
|
-
})(LeaderBoardPeriodType || (LeaderBoardPeriodType = {}));
|
|
1678
|
-
|
|
1679
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 };
|
|
1680
1750
|
//# sourceMappingURL=index.modern.mjs.map
|