@smartico/public-api 0.0.111 → 0.0.113

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.
@@ -322,6 +322,7 @@ var SAWWinSoundType;
322
322
  SAWWinSoundType[SAWWinSoundType["Positive"] = 2] = "Positive";
323
323
  SAWWinSoundType[SAWWinSoundType["HighlyPositive"] = 3] = "HighlyPositive";
324
324
  SAWWinSoundType[SAWWinSoundType["NoSound"] = 4] = "NoSound";
325
+ SAWWinSoundType[SAWWinSoundType["Custom"] = 5] = "Custom";
325
326
  })(SAWWinSoundType || (SAWWinSoundType = {}));
326
327
  const SAWWinSoundFiles = {
327
328
  [SAWWinSoundType.NoSound]: null,
@@ -380,12 +381,12 @@ class OCache {
380
381
  static get(oKey, cacheContext) {
381
382
  const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
382
383
  this.init(cacheContext);
383
- return this.cache[cacheContext].get(key);
384
+ return deepClone(this.cache[cacheContext].get(key));
384
385
  }
385
386
  static set(oKey, o, cacheContext, ttlSeconds = 60) {
386
387
  const key = cacheContext.toString() + '_' + JSON.stringify(oKey);
387
388
  this.init(cacheContext);
388
- this.cache[cacheContext].set(key, o, ttlSeconds);
389
+ this.cache[cacheContext].set(key, deepClone(o), ttlSeconds);
389
390
  }
390
391
  static async use(oKey, cacheContext, f, ttlSeconds = 60) {
391
392
  if (ttlSeconds <= 0) {
@@ -406,6 +407,12 @@ class OCache {
406
407
  }
407
408
  }
408
409
  OCache.cache = {};
410
+ const deepClone = o => {
411
+ if (o) {
412
+ return JSON.parse(JSON.stringify(o));
413
+ }
414
+ return o;
415
+ };
409
416
 
410
417
  var ActivityTypeLimited;
411
418
  (function (ActivityTypeLimited) {
@@ -571,6 +578,7 @@ const StoreItemTransform = items => {
571
578
  limit_message: r.itemPublicMeta.limit_message,
572
579
  priority: r.itemPublicMeta.priority,
573
580
  related_item_ids: r.itemPublicMeta.related_items,
581
+ hint_text: r.itemPublicMeta.hint_text,
574
582
  type: {
575
583
  [StoreItemType.Bonus]: 'bonus',
576
584
  [StoreItemType.Manual]: 'manual'
@@ -608,10 +616,11 @@ var AchievementType;
608
616
  const UserAchievementTransform = items => {
609
617
  return items.filter(r => r.ach_id >= 1).map(r => {
610
618
  var _r$ach_categories;
611
- return {
619
+ const x = {
612
620
  id: r.ach_id,
613
621
  name: r.ach_public_meta.name,
614
622
  description: r.ach_public_meta.description,
623
+ hint_text: r.ach_public_meta.hint_text,
615
624
  unlock_mission_description: r.ach_public_meta.unlock_mission_description,
616
625
  image: r.ach_public_meta.image_url,
617
626
  is_completed: r.isCompleted,
@@ -651,6 +660,7 @@ const UserAchievementTransform = items => {
651
660
  })),
652
661
  category_ids: (_r$ach_categories = r.ach_categories) != null ? _r$ach_categories : []
653
662
  };
663
+ return x;
654
664
  });
655
665
  };
656
666
 
@@ -914,6 +924,13 @@ var TournamentType;
914
924
  TournamentType[TournamentType["TEST"] = 3] = "TEST";
915
925
  })(TournamentType || (TournamentType = {}));
916
926
 
927
+ var LeaderBoardPeriodType;
928
+ (function (LeaderBoardPeriodType) {
929
+ LeaderBoardPeriodType[LeaderBoardPeriodType["DAILY"] = 1] = "DAILY";
930
+ LeaderBoardPeriodType[LeaderBoardPeriodType["WEEKLY"] = 2] = "WEEKLY";
931
+ LeaderBoardPeriodType[LeaderBoardPeriodType["MONTHLY"] = 3] = "MONTHLY";
932
+ })(LeaderBoardPeriodType || (LeaderBoardPeriodType = {}));
933
+
917
934
  const GetLevelMapResponseTransform = levels => {
918
935
  return levels == null ? void 0 : levels.levels.map(l => {
919
936
  var _l$level_public_meta;
@@ -940,6 +957,12 @@ var onUpdateContextKey;
940
957
  onUpdateContextKey["Missions"] = "missions";
941
958
  onUpdateContextKey["TournamentList"] = "tournamentList";
942
959
  onUpdateContextKey["InboxMessages"] = "inboxMessages";
960
+ onUpdateContextKey["Badges"] = "badges";
961
+ onUpdateContextKey["Levels"] = "levels";
962
+ onUpdateContextKey["StoreItems"] = "storeItems";
963
+ onUpdateContextKey["StoreCategories"] = "storeCategories";
964
+ onUpdateContextKey["AchCategories"] = "achCategories";
965
+ onUpdateContextKey["LeaderBoards"] = "leaderBoards";
943
966
  })(onUpdateContextKey || (onUpdateContextKey = {}));
944
967
  /** @group General API */
945
968
  class WSAPI {
@@ -970,7 +993,7 @@ class WSAPI {
970
993
  }
971
994
  /** Returns all the levels available the current user */
972
995
  async getLevels() {
973
- return this.api.levelsGetT(null);
996
+ return OCache.use(onUpdateContextKey.Levels, ECacheContext.WSAPI, () => this.api.levelsGetT(null), CACHE_DATA_SEC);
974
997
  }
975
998
  /** Returns all the missions available the current user.
976
999
  * 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 +1011,11 @@ class WSAPI {
988
1011
  }
989
1012
  /** Returns all the badges available the current user */
990
1013
  async getBadges() {
991
- return this.api.badgetsGetItemsT(null);
1014
+ return OCache.use(onUpdateContextKey.Badges, ECacheContext.WSAPI, () => this.api.badgetsGetItemsT(null), CACHE_DATA_SEC);
992
1015
  }
993
1016
  /** Returns all the store items available the current user */
994
1017
  async getStoreItems() {
995
- return this.api.storeGetItemsT(null);
1018
+ return OCache.use(onUpdateContextKey.StoreItems, ECacheContext.WSAPI, () => this.api.storeGetItemsT(null), CACHE_DATA_SEC);
996
1019
  }
997
1020
  /** Buy the specific shop item by item_id. Returns the err_code.*/
998
1021
  async buyStoreItem(item_id) {
@@ -1005,11 +1028,11 @@ class WSAPI {
1005
1028
  }
1006
1029
  /** Returns store categories */
1007
1030
  async getStoreCategories() {
1008
- return this.api.storeGetCategoriesT(null);
1031
+ return OCache.use(onUpdateContextKey.StoreCategories, ECacheContext.WSAPI, () => this.api.storeGetCategoriesT(null), CACHE_DATA_SEC);
1009
1032
  }
1010
1033
  /** Returns ach categories */
1011
1034
  async getAchCategories() {
1012
- return this.api.achGetCategoriesT(null);
1035
+ return OCache.use(onUpdateContextKey.AchCategories, ECacheContext.WSAPI, () => this.api.achGetCategoriesT(null), CACHE_DATA_SEC);
1013
1036
  }
1014
1037
  /** Returns the list of mini-games available for user
1015
1038
  * 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 +1096,12 @@ class WSAPI {
1073
1096
  };
1074
1097
  return o;
1075
1098
  }
1099
+ /** 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.
1100
+ For example, if the type is Weekly and getPreviousPeriod is true, a leaderboard for the previous week will be returned.
1101
+ */
1102
+ async getLeaderBoard(periodType, getPreviousPeriod) {
1103
+ return OCache.use(onUpdateContextKey.LeaderBoards, ECacheContext.WSAPI, () => this.api.leaderboardsGetT(null, periodType, getPreviousPeriod), CACHE_DATA_SEC);
1104
+ }
1076
1105
  /** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
1077
1106
  * 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
1107
  * You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
@@ -1188,6 +1217,48 @@ class WSAPI {
1188
1217
  }
1189
1218
  }
1190
1219
 
1220
+ const pointsRewardTransform = reward_points => {
1221
+ if (reward_points && reward_points.length) {
1222
+ return reward_points.map((r, i) => ({
1223
+ place: i + 1,
1224
+ points: r
1225
+ }));
1226
+ }
1227
+ return null;
1228
+ };
1229
+ const getLeaderBoardPlayerTransformed = (user, isMe) => {
1230
+ if (user) {
1231
+ const x = {
1232
+ public_username: (user == null ? void 0 : user.public_username) || user.user_alt_name,
1233
+ avatar_url: user.avatar_url,
1234
+ position: user.position_in_board,
1235
+ points: user.points_accumulated,
1236
+ is_me: user.is_me
1237
+ };
1238
+ if (isMe) {
1239
+ delete x.is_me;
1240
+ }
1241
+ return x;
1242
+ }
1243
+ return null;
1244
+ };
1245
+ const getLeaderBoardTransform = board => {
1246
+ if (board) {
1247
+ const x = {
1248
+ board_id: board.board_id,
1249
+ name: board.board_public_meta.name,
1250
+ description: board.board_public_meta.description,
1251
+ rules: board.board_public_meta.rules,
1252
+ period_type_id: board.period_type_id,
1253
+ rewards: pointsRewardTransform(board.reward_points),
1254
+ users: board.positions.map(p => getLeaderBoardPlayerTransformed(p)),
1255
+ me: getLeaderBoardPlayerTransformed(board.userPosition, true)
1256
+ };
1257
+ return x;
1258
+ }
1259
+ return null;
1260
+ };
1261
+
1191
1262
  const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
1192
1263
  const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
1193
1264
  const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
@@ -1494,10 +1565,12 @@ class SmarticoAPI {
1494
1565
  async missionsGetItems(user_ext_id) {
1495
1566
  const message = this.buildMessage(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
1496
1567
  const response = await this.send(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
1497
- if (response.achievements) {
1498
- response.achievements = response.achievements.filter(a => a.ach_type_id === AchievementType.Mission);
1568
+ // we need to clone response to avoid changing original object,for cases when its called together with badgesGetItems (e.g. in Promise.all)
1569
+ const responseClone = _extends({}, response);
1570
+ if (responseClone.achievements) {
1571
+ responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Mission);
1499
1572
  }
1500
- return response;
1573
+ return responseClone;
1501
1574
  }
1502
1575
  async missionsGetItemsT(user_ext_id) {
1503
1576
  return UserAchievementTransform((await this.missionsGetItems(user_ext_id)).achievements);
@@ -1512,10 +1585,12 @@ class SmarticoAPI {
1512
1585
  async badgetsGetItems(user_ext_id) {
1513
1586
  const message = this.buildMessage(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
1514
1587
  const response = await this.send(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE);
1515
- if (response.achievements) {
1516
- response.achievements = response.achievements.filter(a => a.ach_type_id === AchievementType.Badge);
1588
+ // we need to clone response to avoid changing original object,for cases when its called together with missionsGetItems (e.g. in Promise.all)
1589
+ const responseClone = _extends({}, response);
1590
+ if (responseClone.achievements) {
1591
+ responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Badge);
1517
1592
  }
1518
- return response;
1593
+ return responseClone;
1519
1594
  }
1520
1595
  async badgetsGetItemsT(user_ext_id) {
1521
1596
  return UserAchievementTransform((await this.badgetsGetItems(user_ext_id)).achievements);
@@ -1572,6 +1647,9 @@ class SmarticoAPI {
1572
1647
  }
1573
1648
  return response.map[boardKey];
1574
1649
  }
1650
+ async leaderboardsGetT(user_ext_id, period_type_id = LeaderBoardPeriodType.DAILY, prevPeriod = false) {
1651
+ return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod));
1652
+ }
1575
1653
  async levelsGet(user_ext_id) {
1576
1654
  const message = this.buildMessage(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
1577
1655
  return await this.send(message, ClassId.GET_LEVEL_MAP_RESPONSE);
@@ -1669,12 +1747,5 @@ class CookieStore {
1669
1747
  }
1670
1748
  CookieStore.cookieStore = new TSMap();
1671
1749
 
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
1750
  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
1751
  //# sourceMappingURL=index.modern.mjs.map