@smartico/public-api 0.0.154 → 0.0.155

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.
Files changed (269) hide show
  1. package/.prettierrc +12 -0
  2. package/dist/Base/ProtocolRequest.d.ts +1 -1
  3. package/dist/Base/ProtocolResponse.d.ts +1 -1
  4. package/dist/Core/CheckSegmentMatchRequest.d.ts +1 -1
  5. package/dist/Core/CheckSegmentMatchResponse.d.ts +1 -1
  6. package/dist/Core/GetAchievementsUserInfoRequest.d.ts +1 -1
  7. package/dist/Core/GetAchievementsUserInfoResponse.d.ts +1 -1
  8. package/dist/Core/GetLabelInfoRequest.d.ts +1 -1
  9. package/dist/Core/GetLabelInfoResponse.d.ts +1 -1
  10. package/dist/Core/GetTranslationsRequest.d.ts +2 -2
  11. package/dist/Core/GetTranslationsResponse.d.ts +1 -1
  12. package/dist/Core/ResponseIdentify.d.ts +2 -2
  13. package/dist/CustomSections/GetCustomSectionsRequest.d.ts +1 -1
  14. package/dist/CustomSections/GetCustomSectionsResponse.d.ts +2 -2
  15. package/dist/CustomSections/UICustomSection.d.ts +2 -2
  16. package/dist/GResponse.d.ts +1 -1
  17. package/dist/Inbox/GetInboxMessagesRequest.d.ts +1 -1
  18. package/dist/Inbox/GetInboxMessagesResponse.d.ts +3 -3
  19. package/dist/Inbox/InboxMessage.d.ts +2 -2
  20. package/dist/Inbox/MarkInboxMessageDeletedRequest.d.ts +1 -1
  21. package/dist/Inbox/MarkInboxMessageDeletedResponse.d.ts +1 -1
  22. package/dist/Inbox/MarkInboxMessageReadRequest.d.ts +1 -1
  23. package/dist/Inbox/MarkInboxMessageReadResponse.d.ts +1 -1
  24. package/dist/Inbox/MarkInboxMessageStarredRequest.d.ts +1 -1
  25. package/dist/Inbox/MarkInboxMessageStarredResponse.d.ts +1 -1
  26. package/dist/Inbox/index.d.ts +8 -8
  27. package/dist/Jackpots/GetJackpotsPotsRequest.d.ts +1 -1
  28. package/dist/Jackpots/GetJackpotsPotsResponse.d.ts +2 -2
  29. package/dist/Jackpots/GetJackpotsRequest.d.ts +1 -1
  30. package/dist/Jackpots/GetJackpotsResponse.d.ts +2 -2
  31. package/dist/Jackpots/JackpotDetails.d.ts +6 -6
  32. package/dist/Jackpots/JackpotWinPush.d.ts +3 -3
  33. package/dist/Jackpots/JackpotsOptinRequest.d.ts +1 -1
  34. package/dist/Jackpots/JackpotsOptinResponse.d.ts +1 -1
  35. package/dist/Jackpots/JackpotsOptoutRequest.d.ts +1 -1
  36. package/dist/Jackpots/JackpotsOptoutResponse.d.ts +1 -1
  37. package/dist/Leaderboard/GetLeaderBoardsRequest.d.ts +2 -2
  38. package/dist/Leaderboard/GetLeaderBoardsResponse.d.ts +2 -2
  39. package/dist/Leaderboard/LeaderBoardDetails.d.ts +3 -3
  40. package/dist/Leaderboard/LeaderBoards.d.ts +2 -2
  41. package/dist/Leaderboard/index.d.ts +6 -6
  42. package/dist/Level/GetLevelMapResponse.d.ts +3 -3
  43. package/dist/Level/Level.d.ts +1 -1
  44. package/dist/MiniGames/SAWAcknowledgeSpinPushRequest.d.ts +1 -1
  45. package/dist/MiniGames/SAWDoAknowledgeRequest.d.ts +1 -1
  46. package/dist/MiniGames/SAWDoAknowledgeResponse.d.ts +1 -1
  47. package/dist/MiniGames/SAWDoSpinRequest.d.ts +1 -1
  48. package/dist/MiniGames/SAWDoSpinResponse.d.ts +2 -2
  49. package/dist/MiniGames/SAWEventSawPush.d.ts +1 -1
  50. package/dist/MiniGames/SAWGetTemplatesRequest.d.ts +1 -1
  51. package/dist/MiniGames/SAWGetTemplatesResponse.d.ts +3 -3
  52. package/dist/MiniGames/SAWPrize.d.ts +2 -2
  53. package/dist/MiniGames/SAWPrizeDropAknowledgeRequest.d.ts +3 -1
  54. package/dist/MiniGames/SAWPrizeDropAknowledgeResponse.d.ts +1 -1
  55. package/dist/MiniGames/SAWPrizeDropWinPush.d.ts +4 -3
  56. package/dist/MiniGames/SAWPrizeUI.d.ts +2 -2
  57. package/dist/MiniGames/SAWSpinsCountPush.d.ts +1 -1
  58. package/dist/MiniGames/SAWTemplate.d.ts +4 -4
  59. package/dist/MiniGames/SAWTemplateUI.d.ts +1 -1
  60. package/dist/MiniGames/SAWUtils.d.ts +1 -1
  61. package/dist/MiniGames/index.d.ts +24 -22
  62. package/dist/Missions/AchClaimPrizeRequest.d.ts +1 -1
  63. package/dist/Missions/AchClaimPrizeResponse.d.ts +1 -1
  64. package/dist/Missions/AchievementCategory.d.ts +2 -2
  65. package/dist/Missions/AchievementOptinRequest.d.ts +1 -1
  66. package/dist/Missions/AchievementOptinResponse.d.ts +1 -1
  67. package/dist/Missions/GetAchCategoriesRequest.d.ts +1 -1
  68. package/dist/Missions/GetAchCategoriesResponse.d.ts +2 -2
  69. package/dist/Missions/GetAchievementMapRequest.d.ts +1 -1
  70. package/dist/Missions/GetAchievementMapResponse.d.ts +2 -2
  71. package/dist/Missions/GetRelatedAchTourRequest.d.ts +1 -1
  72. package/dist/Missions/GetRelatedAchTourResponse.d.ts +3 -3
  73. package/dist/Missions/ReloadAchievementsEvent.d.ts +2 -2
  74. package/dist/Missions/UserAchievement.d.ts +7 -7
  75. package/dist/Missions/UserAchievementTask.d.ts +2 -2
  76. package/dist/Missions/index.d.ts +13 -13
  77. package/dist/Quiz/MarketsInfo.d.ts +2 -2
  78. package/dist/Quiz/MarketsPerSport.d.ts +1 -1
  79. package/dist/SmarticoAPI.d.ts +8 -8
  80. package/dist/SmarticoLib/index.d.ts +39 -39
  81. package/dist/Store/BuyStoreItemRequest.d.ts +1 -1
  82. package/dist/Store/BuyStoreItemResponse.d.ts +1 -1
  83. package/dist/Store/GetCategoriesStoreResponse.d.ts +2 -2
  84. package/dist/Store/GetStoreHistoryRequest.d.ts +1 -1
  85. package/dist/Store/GetStoreHistoryResponse.d.ts +2 -2
  86. package/dist/Store/GetStoreItemsResponse.d.ts +2 -2
  87. package/dist/Store/StoreCategory.d.ts +2 -2
  88. package/dist/Store/StoreItem.d.ts +3 -3
  89. package/dist/Store/StoreItemPurchased.d.ts +2 -2
  90. package/dist/Store/index.d.ts +10 -10
  91. package/dist/Tournaments/GetTournamentInfoRequest.d.ts +1 -1
  92. package/dist/Tournaments/GetTournamentInfoResponse.d.ts +5 -5
  93. package/dist/Tournaments/GetTournamentsRequest.d.ts +1 -1
  94. package/dist/Tournaments/GetTournamentsResponse.d.ts +2 -2
  95. package/dist/Tournaments/Tournament.d.ts +8 -8
  96. package/dist/Tournaments/TournamentPrize.d.ts +1 -1
  97. package/dist/Tournaments/TournamentRegisterRequest.d.ts +1 -1
  98. package/dist/Tournaments/TournamentRegisterResponse.d.ts +2 -2
  99. package/dist/Tournaments/TournamentUtils.d.ts +3 -3
  100. package/dist/Tournaments/index.d.ts +16 -16
  101. package/dist/WSAPI/WSAPI.d.ts +65 -65
  102. package/dist/WSAPI/WSAPITypes.d.ts +18 -18
  103. package/dist/index.js +76 -78
  104. package/dist/index.js.map +1 -1
  105. package/dist/index.modern.mjs +103 -103
  106. package/dist/index.modern.mjs.map +1 -1
  107. package/package.json +1 -1
  108. package/src/Base/AchRelatedGame.ts +13 -13
  109. package/src/Base/ClassId.ts +118 -121
  110. package/src/Base/ProtocolMessage.ts +6 -7
  111. package/src/Base/ProtocolRequest.ts +4 -5
  112. package/src/Base/ProtocolResponse.ts +3 -5
  113. package/src/CookieStore.ts +10 -11
  114. package/src/Core/ActivityTypeLimited.ts +17 -18
  115. package/src/Core/CheckSegmentMatchRequest.ts +2 -3
  116. package/src/Core/CheckSegmentMatchResponse.ts +6 -6
  117. package/src/Core/CoreUtils.ts +37 -39
  118. package/src/Core/GetAchievementsUserInfoRequest.ts +2 -4
  119. package/src/Core/GetAchievementsUserInfoResponse.ts +4 -4
  120. package/src/Core/GetLabelInfoRequest.ts +2 -4
  121. package/src/Core/GetLabelInfoResponse.ts +4 -4
  122. package/src/Core/GetTranslationsRequest.ts +5 -7
  123. package/src/Core/GetTranslationsResponse.ts +3 -5
  124. package/src/Core/PublicLabelSettings.ts +29 -30
  125. package/src/Core/PublicProperties.ts +7 -7
  126. package/src/Core/ResponseIdentify.ts +12 -12
  127. package/src/Core/TranslationArea.ts +8 -9
  128. package/src/Core/index.ts +1 -1
  129. package/src/CustomSections/AchCustomSection.ts +20 -20
  130. package/src/CustomSections/GetCustomSectionsRequest.ts +2 -4
  131. package/src/CustomSections/GetCustomSectionsResponse.ts +4 -5
  132. package/src/CustomSections/UICustomSection.ts +30 -29
  133. package/src/CustomSections/index.ts +4 -4
  134. package/src/ErrorCodes.ts +11 -12
  135. package/src/GResponse.ts +5 -5
  136. package/src/ILogger.ts +6 -10
  137. package/src/Inbox/GetInboxMessagesRequest.ts +4 -5
  138. package/src/Inbox/GetInboxMessagesResponse.ts +15 -17
  139. package/src/Inbox/InboxMessage.ts +31 -33
  140. package/src/Inbox/InboxMessageType.ts +9 -9
  141. package/src/Inbox/MarkInboxMessageDeletedRequest.ts +3 -3
  142. package/src/Inbox/MarkInboxMessageDeletedResponse.ts +3 -3
  143. package/src/Inbox/MarkInboxMessageReadRequest.ts +4 -5
  144. package/src/Inbox/MarkInboxMessageReadResponse.ts +4 -5
  145. package/src/Inbox/MarkInboxMessageStarredRequest.ts +4 -5
  146. package/src/Inbox/MarkInboxMessageStarredResponse.ts +4 -5
  147. package/src/Inbox/index.ts +10 -10
  148. package/src/IntUtils.ts +72 -85
  149. package/src/Jackpots/GetJackpotsPotsRequest.ts +3 -3
  150. package/src/Jackpots/GetJackpotsPotsResponse.ts +3 -5
  151. package/src/Jackpots/GetJackpotsRequest.ts +4 -6
  152. package/src/Jackpots/GetJackpotsResponse.ts +5 -7
  153. package/src/Jackpots/JackPotWinner.ts +11 -12
  154. package/src/Jackpots/JackpotContributionType.ts +3 -4
  155. package/src/Jackpots/JackpotDetails.ts +31 -31
  156. package/src/Jackpots/JackpotHtmlTemplate.ts +3 -3
  157. package/src/Jackpots/JackpotPot.ts +11 -12
  158. package/src/Jackpots/JackpotPublicMeta.ts +16 -16
  159. package/src/Jackpots/JackpotType.ts +2 -5
  160. package/src/Jackpots/JackpotWinPush.ts +6 -6
  161. package/src/Jackpots/JackpotsOptinRequest.ts +3 -5
  162. package/src/Jackpots/JackpotsOptinResponse.ts +2 -4
  163. package/src/Jackpots/JackpotsOptoutRequest.ts +3 -5
  164. package/src/Jackpots/JackpotsOptoutResponse.ts +2 -4
  165. package/src/Jackpots/index.ts +16 -16
  166. package/src/Leaderboard/GetLeaderBoardsRequest.ts +8 -9
  167. package/src/Leaderboard/GetLeaderBoardsResponse.ts +4 -6
  168. package/src/Leaderboard/LeaderBoardDetails.ts +11 -12
  169. package/src/Leaderboard/LeaderBoardPeriodType.ts +3 -3
  170. package/src/Leaderboard/LeaderBoardPosition.ts +9 -10
  171. package/src/Leaderboard/LeaderBoardPublicMeta.ts +3 -4
  172. package/src/Leaderboard/LeaderBoards.ts +42 -42
  173. package/src/Leaderboard/index.ts +6 -6
  174. package/src/Level/GetLevelMapResponse.ts +18 -21
  175. package/src/Level/Level.ts +10 -11
  176. package/src/Level/LevelPublicMeta.ts +17 -17
  177. package/src/Level/index.ts +3 -3
  178. package/src/MiniGames/SAWAcknowledgeSpinPushRequest.ts +3 -4
  179. package/src/MiniGames/SAWAcknowledgeType.ts +3 -4
  180. package/src/MiniGames/SAWAskForUsername.ts +3 -4
  181. package/src/MiniGames/SAWBuyInType.ts +15 -13
  182. package/src/MiniGames/SAWDoAknowledgeRequest.ts +3 -3
  183. package/src/MiniGames/SAWDoAknowledgeResponse.ts +3 -3
  184. package/src/MiniGames/SAWDoSpinRequest.ts +3 -5
  185. package/src/MiniGames/SAWDoSpinResponse.ts +10 -11
  186. package/src/MiniGames/SAWEventSawPush.ts +3 -4
  187. package/src/MiniGames/SAWGameType.ts +23 -21
  188. package/src/MiniGames/SAWGetTemplatesRequest.ts +3 -3
  189. package/src/MiniGames/SAWGetTemplatesResponse.ts +53 -65
  190. package/src/MiniGames/SAWPrize.ts +11 -12
  191. package/src/MiniGames/SAWPrizeDropAknowledgeRequest.ts +5 -3
  192. package/src/MiniGames/SAWPrizeDropAknowledgeResponse.ts +3 -3
  193. package/src/MiniGames/SAWPrizeDropWinPush.ts +9 -8
  194. package/src/MiniGames/SAWPrizeType.ts +23 -22
  195. package/src/MiniGames/SAWPrizeUI.ts +17 -17
  196. package/src/MiniGames/SAWSpinErrorCode.ts +15 -16
  197. package/src/MiniGames/SAWSpinsCountPush.ts +4 -4
  198. package/src/MiniGames/SAWTemplate.ts +29 -29
  199. package/src/MiniGames/SAWTemplateUI.ts +45 -47
  200. package/src/MiniGames/SAWUtils.ts +23 -26
  201. package/src/MiniGames/SAWWinSoundType.ts +10 -11
  202. package/src/MiniGames/index.ts +24 -22
  203. package/src/Missions/AchCategoryPublicMeta.ts +2 -3
  204. package/src/Missions/AchClaimPrizeRequest.ts +4 -5
  205. package/src/Missions/AchClaimPrizeResponse.ts +3 -4
  206. package/src/Missions/AchievementCategory.ts +14 -15
  207. package/src/Missions/AchievementOptinRequest.ts +3 -5
  208. package/src/Missions/AchievementOptinResponse.ts +2 -4
  209. package/src/Missions/AchievementPublicMeta.ts +19 -20
  210. package/src/Missions/AchievementStatus.ts +7 -8
  211. package/src/Missions/AchievementTaskPublicMeta.ts +2 -3
  212. package/src/Missions/AchievementTaskType.ts +2 -2
  213. package/src/Missions/AchievementType.ts +2 -3
  214. package/src/Missions/GetAchCategoriesRequest.ts +2 -4
  215. package/src/Missions/GetAchCategoriesResponse.ts +4 -5
  216. package/src/Missions/GetAchievementMapRequest.ts +2 -4
  217. package/src/Missions/GetAchievementMapResponse.ts +3 -5
  218. package/src/Missions/GetRelatedAchTourRequest.ts +3 -4
  219. package/src/Missions/GetRelatedAchTourResponse.ts +5 -7
  220. package/src/Missions/ReloadAchievementsEvent.ts +5 -5
  221. package/src/Missions/ScheduledMissionType.ts +4 -5
  222. package/src/Missions/UserAchievement.ts +104 -108
  223. package/src/Missions/UserAchievementTask.ts +13 -15
  224. package/src/Missions/index.ts +19 -19
  225. package/src/NodeCache.ts +44 -49
  226. package/src/OCache.ts +51 -57
  227. package/src/Quiz/MarketsAnswers.ts +34 -34
  228. package/src/Quiz/MarketsInfo.ts +184 -177
  229. package/src/Quiz/MarketsPerSport.ts +30 -37
  230. package/src/Quiz/MarketsType.ts +28 -28
  231. package/src/Quiz/ScoreResultTypes.ts +18 -18
  232. package/src/Quiz/SportTypes.ts +4 -4
  233. package/src/Quiz/index.ts +6 -6
  234. package/src/SmarticoAPI.ts +769 -730
  235. package/src/SmarticoLib/index.ts +1053 -1069
  236. package/src/Store/BuyStoreItemErrorCode.ts +10 -10
  237. package/src/Store/BuyStoreItemRequest.ts +2 -2
  238. package/src/Store/BuyStoreItemResponse.ts +2 -3
  239. package/src/Store/GetCategoriesStoreResponse.ts +3 -8
  240. package/src/Store/GetStoreHistoryRequest.ts +3 -3
  241. package/src/Store/GetStoreHistoryResponse.ts +4 -4
  242. package/src/Store/GetStoreItemsResponse.ts +3 -4
  243. package/src/Store/StoreCategory.ts +14 -15
  244. package/src/Store/StoreCategoryPublicMeta.ts +2 -3
  245. package/src/Store/StoreItem.ts +32 -33
  246. package/src/Store/StoreItemPublicMeta.ts +10 -10
  247. package/src/Store/StoreItemPurchased.ts +40 -40
  248. package/src/Store/StoreItemType.ts +20 -19
  249. package/src/Store/index.ts +13 -13
  250. package/src/Tournaments/GetTournamentInfoRequest.ts +2 -3
  251. package/src/Tournaments/GetTournamentInfoResponse.ts +45 -48
  252. package/src/Tournaments/GetTournamentsRequest.ts +2 -4
  253. package/src/Tournaments/GetTournamentsResponse.ts +7 -14
  254. package/src/Tournaments/Tournament.ts +109 -115
  255. package/src/Tournaments/TournamentInstanceStatus.ts +17 -18
  256. package/src/Tournaments/TournamentPlayer.ts +7 -8
  257. package/src/Tournaments/TournamentPrize.ts +9 -10
  258. package/src/Tournaments/TournamentPublicMeta.ts +26 -26
  259. package/src/Tournaments/TournamentRegisterRequest.ts +2 -3
  260. package/src/Tournaments/TournamentRegisterResponse.ts +3 -7
  261. package/src/Tournaments/TournamentRegistrationError.ts +9 -9
  262. package/src/Tournaments/TournamentRegistrationStatus.ts +25 -27
  263. package/src/Tournaments/TournamentRegistrationType.ts +15 -16
  264. package/src/Tournaments/TournamentType.ts +3 -4
  265. package/src/Tournaments/TournamentUtils.ts +90 -89
  266. package/src/Tournaments/index.ts +16 -16
  267. package/src/WSAPI/WSAPI.ts +781 -763
  268. package/src/WSAPI/WSAPITypes.ts +574 -586
  269. package/src/index.ts +15 -15
@@ -1,740 +1,779 @@
1
- import { ClassId } from "./Base/ClassId";
2
- import { ProtocolRequest } from './Base/ProtocolRequest';
3
- import { ProtocolResponse } from './Base/ProtocolResponse';
4
- import { SAWGetTemplatesResponse } from './MiniGames/SAWGetTemplatesResponse';
5
- import { SAWGetTemplatesRequest } from './MiniGames/SAWGetTemplatesRequest';
6
- import { IntUtils } from './IntUtils';
7
- import { ILogger } from './ILogger';
8
- import { SAWDoAknowledgeRequest, SAWDoAknowledgeResponse, SAWDoSpinRequest, SAWDoSpinResponse, SAWSpinErrorCode, SAWTemplatesTransform } from './MiniGames';
9
- import { ECacheContext, OCache } from './OCache';
10
- import { CoreUtils, GetTranslationsRequest, GetTranslationsResponse, PublicLabelSettings, ResponseIdentify, TranslationArea } from './Core';
11
- import { GetLabelInfoResponse } from './Core/GetLabelInfoResponse';
12
- import { GetLabelInfoRequest } from './Core/GetLabelInfoRequest';
13
- import { GetInboxMessagesRequest, GetInboxMessagesResponse, InboxMessageBody, InboxMessageBodyTransform, InboxMessagesTransform, MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse, MarkInboxMessageReadRequest, MarkInboxMessageReadResponse, MarkInboxMessageStarredRequest, MarkInboxMessageStarredResponse } from './Inbox';
14
- import { BuyStoreItemRequest, BuyStoreItemResponse, GetCategoriesStoreResponse, GetStoreHistoryRequest, GetStoreHistoryResponse, GetStoreItemsResponse, StoreCategoryTransform, StoreItemPurchasedTransform, StoreItemTransform } from './Store';
15
- import { AchCategoryTransform, AchClaimPrizeRequest, AchClaimPrizeResponse, AchievementOptinRequest, AchievementOptinResponse, AchievementType, GetAchCategoriesResponse, GetAchievementMapRequest, GetAchievementMapResponse, UserAchievementTransform } from './Missions';
16
- import { GetTournamentInfoRequest, GetTournamentInfoResponse, GetTournamentsRequest, GetTournamentsResponse, TournamentItemsTransform, TournamentRegisterRequest, TournamentRegisterResponse, tournamentInfoItemTransform } from './Tournaments';
17
- import { GetLeaderBoardsRequest, GetLeaderBoardsResponse, LeaderBoardDetails, LeaderBoardPeriodType } from "./Leaderboard";
18
- import { GetLevelMapResponse, GetLevelMapResponseTransform } from "./Level";
19
- import { WSAPI } from "./WSAPI/WSAPI";
20
- import { TInboxMessage, TInboxMessageBody, TLevel, TMiniGameTemplate, TMissionOrBadge, TStoreCategory, TAchCategory, TStoreItem, TTournament, TTournamentDetailed, LeaderBoardDetailsT, UserLevelExtraCountersT, TSegmentCheckResult, TUICustomSection } from "./WSAPI/WSAPITypes";
21
- import { getLeaderBoardTransform } from "./Leaderboard/LeaderBoards";
22
- import { GetAchievementsUserInfoResponse } from "./Core/GetAchievementsUserInfoResponse";
23
- import { CheckSegmentMatchResponse } from "./Core/CheckSegmentMatchResponse";
24
- import { CheckSegmentMatchRequest } from "./Core/CheckSegmentMatchRequest";
25
- import { GetJackpotsPotsRequest, GetJackpotsPotsResponse, GetJackpotsRequest, GetJackpotsResponse, JackpotDetails, JackpotPot, JackpotsOptinRequest, JackpotsOptinResponse, JackpotsOptoutRequest, JackpotsOptoutResponse } from "./Jackpots";
26
- import { GetCustomSectionsRequest, GetCustomSectionsResponse, UICustomSectionTransform } from "./CustomSections";
27
-
28
- const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
29
- const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
30
- const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
31
- const DEFAULT_LANG_EN = "EN";
1
+ import { ClassId } from './Base/ClassId'
2
+ import { ProtocolRequest } from './Base/ProtocolRequest'
3
+ import { ProtocolResponse } from './Base/ProtocolResponse'
4
+ import { SAWGetTemplatesResponse } from './MiniGames/SAWGetTemplatesResponse'
5
+ import { SAWGetTemplatesRequest } from './MiniGames/SAWGetTemplatesRequest'
6
+ import { IntUtils } from './IntUtils'
7
+ import { ILogger } from './ILogger'
8
+ import { SAWDoAknowledgeRequest, SAWDoAknowledgeResponse, SAWDoSpinRequest, SAWDoSpinResponse, SAWSpinErrorCode, SAWTemplatesTransform } from './MiniGames'
9
+ import { ECacheContext, OCache } from './OCache'
10
+ import { CoreUtils, GetTranslationsRequest, GetTranslationsResponse, PublicLabelSettings, ResponseIdentify, TranslationArea } from './Core'
11
+ import { GetLabelInfoResponse } from './Core/GetLabelInfoResponse'
12
+ import { GetLabelInfoRequest } from './Core/GetLabelInfoRequest'
13
+ import {
14
+ GetInboxMessagesRequest,
15
+ GetInboxMessagesResponse,
16
+ InboxMessageBody,
17
+ InboxMessageBodyTransform,
18
+ InboxMessagesTransform,
19
+ MarkInboxMessageDeletedRequest,
20
+ MarkInboxMessageDeletedResponse,
21
+ MarkInboxMessageReadRequest,
22
+ MarkInboxMessageReadResponse,
23
+ MarkInboxMessageStarredRequest,
24
+ MarkInboxMessageStarredResponse,
25
+ } from './Inbox'
26
+ import {
27
+ BuyStoreItemRequest,
28
+ BuyStoreItemResponse,
29
+ GetCategoriesStoreResponse,
30
+ GetStoreHistoryRequest,
31
+ GetStoreHistoryResponse,
32
+ GetStoreItemsResponse,
33
+ StoreCategoryTransform,
34
+ StoreItemPurchasedTransform,
35
+ StoreItemTransform,
36
+ } from './Store'
37
+ import {
38
+ AchCategoryTransform,
39
+ AchClaimPrizeRequest,
40
+ AchClaimPrizeResponse,
41
+ AchievementOptinRequest,
42
+ AchievementOptinResponse,
43
+ AchievementType,
44
+ GetAchCategoriesResponse,
45
+ GetAchievementMapRequest,
46
+ GetAchievementMapResponse,
47
+ UserAchievementTransform,
48
+ } from './Missions'
49
+ import {
50
+ GetTournamentInfoRequest,
51
+ GetTournamentInfoResponse,
52
+ GetTournamentsRequest,
53
+ GetTournamentsResponse,
54
+ TournamentItemsTransform,
55
+ TournamentRegisterRequest,
56
+ TournamentRegisterResponse,
57
+ tournamentInfoItemTransform,
58
+ } from './Tournaments'
59
+ import { GetLeaderBoardsRequest, GetLeaderBoardsResponse, LeaderBoardDetails, LeaderBoardPeriodType } from './Leaderboard'
60
+ import { GetLevelMapResponse, GetLevelMapResponseTransform } from './Level'
61
+ import { WSAPI } from './WSAPI/WSAPI'
62
+ import {
63
+ TInboxMessage,
64
+ TInboxMessageBody,
65
+ TLevel,
66
+ TMiniGameTemplate,
67
+ TMissionOrBadge,
68
+ TStoreCategory,
69
+ TAchCategory,
70
+ TStoreItem,
71
+ TTournament,
72
+ TTournamentDetailed,
73
+ LeaderBoardDetailsT,
74
+ UserLevelExtraCountersT,
75
+ TSegmentCheckResult,
76
+ TUICustomSection,
77
+ } from './WSAPI/WSAPITypes'
78
+ import { getLeaderBoardTransform } from './Leaderboard/LeaderBoards'
79
+ import { GetAchievementsUserInfoResponse } from './Core/GetAchievementsUserInfoResponse'
80
+ import { CheckSegmentMatchResponse } from './Core/CheckSegmentMatchResponse'
81
+ import { CheckSegmentMatchRequest } from './Core/CheckSegmentMatchRequest'
82
+ import {
83
+ GetJackpotsPotsRequest,
84
+ GetJackpotsPotsResponse,
85
+ GetJackpotsRequest,
86
+ GetJackpotsResponse,
87
+ JackpotDetails,
88
+ JackpotPot,
89
+ JackpotsOptinRequest,
90
+ JackpotsOptinResponse,
91
+ JackpotsOptoutRequest,
92
+ JackpotsOptoutResponse,
93
+ } from './Jackpots'
94
+ import { GetCustomSectionsRequest, GetCustomSectionsResponse, UICustomSectionTransform } from './CustomSections'
95
+
96
+ const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public'
97
+ const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services'
98
+ const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc'
99
+ const DEFAULT_LANG_EN = 'EN'
32
100
 
33
101
  interface Tracker {
34
- label_api_key: string;
35
- userPublicProps: any;
36
- on: (callBackKey: ClassId, func: (data: any) => void) => void;
37
- getLabelSetting: (key: PublicLabelSettings) => any;
102
+ label_api_key: string
103
+ userPublicProps: any
104
+ on: (callBackKey: ClassId, func: (data: any) => void) => void
105
+ getLabelSetting: (key: PublicLabelSettings) => any
38
106
  }
39
107
  interface IOptions {
40
- logger?: ILogger;
41
- logCIDs?: ClassId[];
42
- logHTTPTiming?: boolean;
43
- tracker?: Tracker;
108
+ logger?: ILogger
109
+ logCIDs?: ClassId[]
110
+ logHTTPTiming?: boolean
111
+ tracker?: Tracker
44
112
  }
45
113
 
46
- type MessageSender = (message: any, publicApuUrl?: string, expectCID?: ClassId) => Promise<any>;
47
-
114
+ type MessageSender = (message: any, publicApuUrl?: string, expectCID?: ClassId) => Promise<any>
48
115
 
49
116
  class SmarticoAPI {
50
-
51
- private publicUrl: string;
52
- private wsUrl: string;
53
- private inboxCdnUrl: string;
54
- private partnerUrl: string;
55
- public avatarDomain: string;
56
-
57
- private logger: ILogger;
58
- private logCIDs: ClassId[];
59
- private logHTTPTiming: boolean;
60
- public tracker?: Tracker;
61
-
62
- public constructor(private label_api_key: string, private brand_api_key: string, private messageSender: MessageSender, options: IOptions = {}) {
63
-
64
- this.logger = options.logger || (console as any);
65
-
66
- if (this.logger.always === undefined) {
67
- this.logger.always = this.logger.info;
68
- }
69
-
70
- this.logCIDs = options.logCIDs || [];
71
- this.logHTTPTiming = options.logHTTPTiming || false;
72
- this.tracker = options.tracker;
73
-
74
- this.publicUrl = SmarticoAPI.getPublicUrl(label_api_key);
75
- this.wsUrl = SmarticoAPI.getPublicWsUrl(label_api_key);
76
-
77
- this.avatarDomain = SmarticoAPI.getAvatarUrl(label_api_key || options.tracker?.label_api_key);
78
-
79
- this.label_api_key = SmarticoAPI.getCleanLabelApiKey(label_api_key);
80
-
81
- }
82
-
83
- public static getEnvDnsSuffix(label_api_key: string): string {
84
-
85
- let ENV_ID = label_api_key.length === 38 ? label_api_key.substring(37, 38) : '';
86
-
87
- if (ENV_ID === '1' || ENV_ID === '2') {
88
- ENV_ID = ''
89
- }
90
- return ENV_ID;
91
- }
92
-
93
- public static getEnvId(label_api_key: string): number {
94
-
95
- return label_api_key.length === 38 ? parseInt(label_api_key.substring(37, 38), 10) : 2;
96
-
97
- }
98
-
99
- public static getCleanLabelApiKey(label_api_key: string): string {
100
- return label_api_key.substring(0, 36);
101
- }
102
-
103
- public static getPublicUrl(label_api_key: string): string {
104
- return PUBLIC_API_URL.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key));
105
- }
106
-
107
- public static getPublicWsUrl(label_api_key: string): string {
108
- return C_SOCKET_PROD.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key));
109
- }
110
-
111
- public static getAvatarUrl(label_api_key: string): string {
112
- return AVATAR_DOMAIN.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key));
113
- }
114
-
115
- private async send<T>(message: any, expectCID?: ClassId, force_language?: string): Promise<T> {
116
-
117
-
118
- if (this.logCIDs.includes(message.cid)) {
119
- this.logger.info('REQ', message)
120
- }
121
-
122
- if (force_language) {
123
- message.force_language = force_language;
124
- }
125
-
126
- let result: any;
127
-
128
- try {
129
- const timeStart = new Date().getTime();
130
- result = await this.messageSender(message, this.publicUrl, expectCID);
131
- const timeEnd = new Date().getTime();
132
-
133
- if (this.logHTTPTiming) {
134
- this.logger.always('HTTP time, ms:' + (timeEnd - timeStart))
135
- }
136
-
137
- } catch (e) {
138
- this.logger.error(`Failed to make request to smartico channel, L2. ${e.message}`, { url: this.publicUrl, request: message, error: e.message });
139
- throw(new Error(`Failed to make request to smartico channel, L2 L1. ${e.message}`));
140
- }
141
-
142
- if (this.logCIDs.includes(message.cid)) {
143
- this.logger.info('RES', result)
144
- }
145
-
146
- if (expectCID) {
147
- if (Array.isArray(result)) {
148
- for (const str of result as string[]) {
149
- const obj: ProtocolResponse = JSON.parse(str);
150
- if (this.logCIDs.includes(obj.cid)) {
151
- this.logger.info('RES', result)
152
- }
153
- if (obj.cid === expectCID) {
154
- return obj as any;
155
- }
156
- }
157
- this.logger.error(`Cant find proper response in array, expected CID ${expectCID}`, { request: message, response: result });
158
- } else {
159
- return result;
160
- }
161
- } else {
162
- if (Array.isArray(result)) {
163
- if (result.length === 1) {
164
- const obj = JSON.parse(result[0]);
165
- if (this.logCIDs.includes(obj.cid)) {
166
- this.logger.info('RES', result)
167
- }
168
- return obj;
169
- } else {
170
- this.logger.error('Expected one response, but got array', { request: message, response: result });
171
- }
172
- }
173
- return result;
174
- }
175
- }
176
-
177
- private buildMessage<TRequest,TResponse>(user_ext_id: string, cid: ClassId, payload: Partial<TRequest> = {}): TResponse {
178
-
179
- const message: ProtocolRequest = {
180
- // AA: in fact we need api and brand keys and ext_user_id only in the context of HTTP
181
- // its not needed in WebSocket and can be deleted
182
- api_key: this.label_api_key,
183
- brand_key: this.brand_api_key,
184
- ext_user_id: user_ext_id,
185
- cid,
186
- uuid: IntUtils.uuid(),
187
- ts: new Date().getTime(),
188
- ...payload
189
- };
190
-
191
- if (message.ext_user_id === undefined || message.ext_user_id === null) {
192
- delete message.ext_user_id;
193
- }
194
-
195
- if (message.brand_key === undefined || message.brand_key === null) {
196
- delete message.brand_key;
197
- }
198
-
199
- return message as any
200
- }
201
-
202
- public async coreReportCustomEvent(user_ext_id: string, eventType: string, payload: any = {}): Promise<any> {
203
- const eventMessage = this.buildMessage<any, any>(user_ext_id, ClassId.EVENT, {
204
- eventType,
205
- payload
206
- });
207
-
208
- const eventResponse = await this.send<any>(eventMessage, ClassId.EVENT_RESPONSE);
209
- return eventResponse;
210
- }
211
-
212
- public async coreGetTranslations(user_ext_id: string, lang_code: string, areas: TranslationArea[], cacheSec: number = 60): Promise<GetTranslationsResponse> {
213
-
214
- if (lang_code === undefined || lang_code === null || lang_code.trim && lang_code.trim() === '') {
215
- lang_code = DEFAULT_LANG_EN;
216
- }
217
-
218
- const response = await OCache.use<GetTranslationsResponse>(`${lang_code}-${this.label_api_key}-${this.brand_api_key}`, ECacheContext.Translations, async () => {
219
-
220
- const tsBaseRQ = this.buildMessage<GetTranslationsRequest, GetTranslationsResponse>(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
221
- lang_code: DEFAULT_LANG_EN,
222
- hash_code: 0,
223
- areas
224
- });
225
-
226
- const trBase = await this.send<GetTranslationsResponse>(tsBaseRQ, ClassId.GET_TRANSLATIONS_RESPONSE);
227
-
228
- if (lang_code !== DEFAULT_LANG_EN) {
229
- const trUserRQ = this.buildMessage<GetTranslationsRequest, GetTranslationsResponse>(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
230
- lang_code,
231
- hash_code: 0,
232
- areas
233
- });
234
-
235
- const trUser = await this.send<GetTranslationsResponse>(trUserRQ, ClassId.GET_TRANSLATIONS_RESPONSE);
236
-
237
- Object.keys(trUser?.translations ?? {}).forEach( k => {
238
- trBase.translations[k] = trUser.translations[k];
239
- })
240
- }
241
-
242
- return trBase;
243
-
244
- }, cacheSec );
245
-
246
- return response;
247
- }
248
-
249
- public async coreIdentifyLabel(user_ext_id: string, cacheSec: number = 60): Promise<GetLabelInfoResponse> {
250
-
251
- return OCache.use<GetLabelInfoResponse>(`${this.label_api_key} - ${this.brand_api_key}`, ECacheContext.LabelInfo, async () => {
252
-
253
- const message = this.buildMessage<GetLabelInfoResponse, GetLabelInfoRequest>(user_ext_id, ClassId.INIT);
254
-
255
- return this.send<GetLabelInfoResponse>(message, ClassId.INIT_RESPONSE)
256
-
257
- }, cacheSec);
258
-
259
- }
260
-
261
- public async coreIdentifyUser(user_ext_id: string): Promise<ResponseIdentify> {
262
-
263
- const message = this.buildMessage<any, ResponseIdentify>(user_ext_id, ClassId.IDENTIFY, {
264
- request_id: IntUtils.uuid() // AA: do we need request_id?
265
- });
266
-
267
- const r = await this.send<ResponseIdentify>(message, ClassId.IDENTIFY_RESPONSE);
268
-
269
- r.avatar_id = CoreUtils.avatarUrl(r.avatar_id, this.avatarDomain);
270
-
271
- return r;
272
- }
273
-
274
- public async coreChangeUsername(user_ext_id: string, public_username_custom: string): Promise<{ public_username_custom: string }> {
275
-
276
- const message = this.buildMessage<any, any>(user_ext_id, ClassId.CLIENT_SET_CUSTOM_USERNAME_REQUEST, {
277
- public_username_custom
278
- });
279
-
280
- return await this.send(message, ClassId.CLIENT_SET_CUSTOM_USERNAME_RESPONSE);
281
- }
282
-
283
- public async coreCheckSegments(user_ext_id: string, segment_id: number[]): Promise<TSegmentCheckResult[]> {
284
-
285
- const message = this.buildMessage<CheckSegmentMatchRequest, any>(user_ext_id, ClassId.CHECK_SEGMENT_MATCH_REQUEST, {
286
- segment_id
287
- });
288
-
289
- const results = await this.send<CheckSegmentMatchResponse>(message, ClassId.CHECK_SEGMENT_MATCH_RESPONSE);
290
-
291
- return results.segments || [];
292
- }
293
-
294
- public async jackpotGet(user_ext_id: string, filter?: { related_game_id?: string, jp_template_id?: number }, force_language?: string ): Promise<GetJackpotsResponse> {
295
-
296
- const message = this.buildMessage<GetJackpotsRequest, GetJackpotsResponse>(user_ext_id, ClassId.JP_GET_JACKPOTS_REQUEST, filter);
297
- return await this.send<GetJackpotsResponse>(message, ClassId.JP_GET_JACKPOTS_RESPONSE, force_language);
298
- }
299
-
300
- public async potGet(user_ext_id: string, filter: { jp_template_ids: number[] }): Promise<GetJackpotsPotsResponse> {
301
- const message = this.buildMessage<GetJackpotsPotsRequest, GetJackpotsPotsResponse>(user_ext_id, ClassId.JP_GET_LATEST_POTS_REQUEST, filter);
302
- return await this.send<GetJackpotsPotsResponse>(message, ClassId.JP_GET_LATEST_POTS_RESPONSE);
303
- }
304
-
305
- public async jackpotOptIn(user_ext_id: string, payload: { jp_template_id: number }): Promise<JackpotsOptinResponse> {
306
- const message = this.buildMessage<JackpotsOptinRequest, JackpotsOptinResponse>(user_ext_id, ClassId.JP_OPTIN_REQUEST, payload);
307
- return await this.send<JackpotsOptinResponse>(message, ClassId.JP_OPTIN_RESPONSE);
308
- }
309
-
310
- public async jackpotOptOut(user_ext_id: string, payload: { jp_template_id: number }): Promise<JackpotsOptoutResponse> {
311
- const message = this.buildMessage<JackpotsOptoutRequest, JackpotsOptoutResponse>(user_ext_id, ClassId.JP_OPTOUT_REQUEST, payload);
312
- return await this.send<JackpotsOptoutResponse>(message, ClassId.JP_OPTOUT_RESPONSE);
313
- }
314
-
315
- public async sawGetTemplates(user_ext_id: string, force_language?: string, is_visitor_mode: boolean = false): Promise<SAWGetTemplatesResponse> {
316
-
317
- const message = this.buildMessage<SAWGetTemplatesRequest, SAWGetTemplatesResponse>(user_ext_id, ClassId.SAW_GET_SPINS_REQUEST, { is_visitor_mode });
318
-
319
- const response = await this.send<SAWGetTemplatesResponse>(message, ClassId.SAW_GET_SPINS_RESPONSE, force_language);
320
-
321
- if (response && response.templates) {
322
- response.templates.forEach(t => {
323
-
324
- if (t.jackpot_current !== undefined && t.jackpot_current !== null) {
325
- const jackpotValue = t.jackpot_current + (t.saw_template_ui_definition?.jackpot_symbol ? ' ' + t.saw_template_ui_definition?.jackpot_symbol : '');
326
- t.saw_template_ui_definition.name = IntUtils.replaceAll(t.saw_template_ui_definition.name, '{{jackpot}}', jackpotValue);
327
- t.saw_template_ui_definition.description = IntUtils.replaceAll(t.saw_template_ui_definition.description, '{{jackpot}}', jackpotValue);
328
- t.saw_template_ui_definition.promo_text = IntUtils.replaceAll(t.saw_template_ui_definition.promo_text, '{{jackpot}}', jackpotValue);
329
- t.prizes.forEach(p => {
330
- p.saw_prize_ui_definition.name = IntUtils.replaceAll(p.saw_prize_ui_definition.name, '{{jackpot}}', jackpotValue);
331
- p.saw_prize_ui_definition.aknowledge_message = IntUtils.replaceAll(p.saw_prize_ui_definition.aknowledge_message, '{{jackpot}}', jackpotValue);
332
- })
333
- }
334
- });
335
- }
336
-
337
- return response;
338
- }
339
-
340
- public async sawGetTemplatesT(user_ext_id: string): Promise<TMiniGameTemplate[]> {
341
- return SAWTemplatesTransform((await this.sawGetTemplates(user_ext_id)).templates);
342
- }
343
-
344
- public async doAcknowledgeRequest(user_ext_id: string, request_id: string): Promise<SAWDoAknowledgeResponse>{
345
- const message = this.buildMessage<SAWDoAknowledgeRequest, SAWDoAknowledgeResponse>(user_ext_id, ClassId.SAW_AKNOWLEDGE_REQUEST, {
346
- request_id
347
- });
348
-
349
- return await this.send<SAWDoAknowledgeResponse>(message, ClassId.SAW_AKNOWLEDGE_RESPONSE);
350
- }
351
-
352
- public async sawSpinRequest(user_ext_id: string, saw_template_id: number, round_id?: number): Promise<SAWDoSpinResponse> {
353
- if (!saw_template_id) {
354
- throw new Error('Missing template id');
355
- }
356
-
357
- const request_id = IntUtils.uuid();
358
-
359
- const message = this.buildMessage<SAWDoSpinRequest, SAWDoSpinResponse>(user_ext_id, ClassId.SAW_DO_SPIN_REQUEST, {
360
- saw_template_id,
361
- request_id
362
- });
363
-
364
- const spinAttemptResponse = await this.send<SAWDoSpinResponse>(message, ClassId.SAW_DO_SPIN_RESPONSE);
365
-
366
- // to simulate fail
367
- // response.errCode = SAWSpinErrorCode.SAW_NO_SPINS;
368
-
369
- const status: string = {
370
- [SAWSpinErrorCode.SAW_OK]: 'OK',
371
- [SAWSpinErrorCode.SAW_NO_SPINS]: 'NO SPINS AVAILABLE',
372
- [SAWSpinErrorCode.SAW_PRIZE_POOL_EMPTY]: 'PRIZE POOL IS EMPTY',
373
- [SAWSpinErrorCode.SAW_NOT_ENOUGH_POINTS]: 'NOT ENOUGH POINTS',
374
- [SAWSpinErrorCode.SAW_FAILED_MAX_SPINS_REACHED]: 'MAX SPIN ATTEMPTS REACHED',
375
- }[spinAttemptResponse.errCode] || 'OTHER';
376
-
377
- await this.coreReportCustomEvent(user_ext_id, 'minigame_attempt', {
378
- saw_template_id,
379
- status,
380
- round_id,
381
- });
382
-
383
- return {...spinAttemptResponse, request_id };
384
- }
385
-
386
- public async missionOptIn(user_ext_id: string, mission_id: number) {
387
- if (!mission_id) {
388
- throw new Error('Missing mission id');
389
- }
390
- const message = this.buildMessage<AchievementOptinRequest, AchievementOptinResponse>(user_ext_id, ClassId.MISSION_OPTIN_REQUEST, {
391
- achievementId: mission_id
392
- });
393
-
394
- const res = await this.send<AchievementOptinResponse>(message, ClassId.MISSION_OPTIN_RESPONSE);
395
-
396
- return res;
397
- }
398
-
399
- public async missionClaimPrize(user_ext_id: string, mission_id: number, ach_completed_id: number) {
400
- if (!mission_id) {
401
- throw new Error('Missing mission id');
402
- }
403
-
404
- const message = this.buildMessage<AchClaimPrizeRequest, AchClaimPrizeResponse>(user_ext_id, ClassId.ACHIEVEMENT_CLAIM_PRIZE_REQUEST, {
405
- ach_id: mission_id,
406
- ach_completed_id: ach_completed_id
407
- })
408
-
409
- const res = await this.send<AchClaimPrizeResponse>(message, ClassId.ACHIEVEMENT_CLAIM_PRIZE_RESPONSE);
410
-
411
- return res;
412
- }
413
-
414
- public async registerInTournament(user_ext_id: string, tournamentInstanceId: number) {
415
- if (!tournamentInstanceId) {
416
- throw new Error('Missing tournament instance id');
417
- }
418
- const message = this.buildMessage<TournamentRegisterRequest, TournamentRegisterResponse>(user_ext_id, ClassId.TOURNAMENT_REGISTER_REQUEST, {
419
- tournamentInstanceId
420
- });
421
-
422
- const res = await this.send<TournamentRegisterResponse>(message, ClassId.TOURNAMENT_REGISTER_RESPONSE);
423
-
424
- return res;
425
- }
426
-
427
- public async buyStoreItem(user_ext_id: string, itemId: number) {
428
- if (!itemId) {
429
- throw new Error('Missing store item id');
430
- }
431
- const message = this.buildMessage<BuyStoreItemRequest, BuyStoreItemResponse>(user_ext_id, ClassId.BUY_SHOP_ITEM_REQUEST, {
432
- itemId
433
- });
434
-
435
- const res = await this.send<BuyStoreItemResponse>(message, ClassId.BUY_SHOP_ITEM_RESPONSE);
436
-
437
- return res;
438
- }
439
-
440
- public async inboxGetMessages(user_ext_id: string, limit: number = 10, offset: number = 0): Promise<GetInboxMessagesResponse> {
441
-
442
- const message = this.buildMessage<GetInboxMessagesRequest, GetInboxMessagesResponse>(user_ext_id, ClassId.GET_INBOX_MESSAGES_REQUEST, {
443
- limit,
444
- offset
445
- });
446
-
447
- return await this.send<GetInboxMessagesResponse>(message, ClassId.GET_INBOX_MESSAGES_RESPONSE);
448
-
449
- }
450
-
451
- public async storeGetItems(user_ext_id: string, force_language?: string): Promise<GetStoreItemsResponse> {
452
- const message = this.buildMessage<any, GetStoreItemsResponse>(user_ext_id, ClassId.GET_SHOP_ITEMS_REQUEST);
453
- return await this.send<GetStoreItemsResponse>(message, ClassId.GET_SHOP_ITEMS_RESPONSE, force_language);
454
- }
455
-
456
- public async storeGetItemsT(user_ext_id: string): Promise<TStoreItem[]> {
457
- return StoreItemTransform((await this.storeGetItems(user_ext_id)).items);
458
- }
459
-
460
- public async storeGetCategories(user_ext_id: string, force_language?: string): Promise<GetCategoriesStoreResponse> {
461
- const message = this.buildMessage<any, GetCategoriesStoreResponse>(user_ext_id, ClassId.GET_SHOP_CATEGORIES_REQUEST);
462
- return await this.send<GetCategoriesStoreResponse>(message, ClassId.GET_SHOP_CATEGORIES_RESPONSE, force_language);
463
- }
464
-
465
- public async storeGetCategoriesT(user_ext_id: string): Promise<TStoreCategory[]> {
466
- return StoreCategoryTransform((await this.storeGetCategories(user_ext_id)).categories);
467
- }
468
-
469
- public async storeGetPurchasedItems(user_ext_id: string, limit: number = 20, offset: number = 0): Promise<GetStoreHistoryResponse> {
470
-
471
- const message = this.buildMessage<GetStoreHistoryRequest, GetStoreHistoryResponse>(user_ext_id, ClassId.ACH_SHOP_ITEM_HISTORY_REQUEST, {
472
- limit,
473
- offset
474
- });
475
-
476
- return await this.send<GetStoreHistoryResponse>(message, ClassId.ACH_SHOP_ITEM_HISTORY_RESPONSE);
477
- }
478
-
479
- public async storeGetPurchasedItemsT(user_ext_id: string, limit?: number, offset?: number): Promise<TStoreItem[]> {
480
- return StoreItemPurchasedTransform((await this.storeGetPurchasedItems(user_ext_id, limit, offset)).items);
481
- }
482
-
483
- public async missionsGetItems(user_ext_id: string, force_language?: string): Promise<GetAchievementMapResponse> {
484
-
485
- const message = this.buildMessage<GetAchievementMapRequest, GetAchievementMapResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
486
- const response = await this.send<GetAchievementMapResponse>(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE, force_language);
487
- // we need to clone response to avoid changing original object,for cases when its called together with badgesGetItems (e.g. in Promise.all)
488
- const responseClone = { ...response };
489
-
490
- if (responseClone.achievements) {
491
- responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Mission);
492
- }
493
- return responseClone;
494
- }
495
-
496
- public async missionsGetItemsT(user_ext_id: string): Promise<TMissionOrBadge[]> {
497
- return UserAchievementTransform((await this.missionsGetItems(user_ext_id)).achievements);
498
- }
499
-
500
- public async getUserGamificationInfo(user_ext_id: string): Promise<GetAchievementsUserInfoResponse> {
501
- const message = this.buildMessage<GetAchievementMapRequest, GetAchievementsUserInfoResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_USER_REQUEST);
502
-
503
- return await this.send<GetAchievementsUserInfoResponse>(message, ClassId.GET_ACHIEVEMENT_USER_RESPONSE);
504
- }
505
-
506
- public async getUserGamificationInfoT(user_ext_id: string): Promise<UserLevelExtraCountersT> {
507
- const response = await this.getUserGamificationInfo(user_ext_id);
508
-
509
- return {
510
- level_counter_1: response.level_counter_1,
511
- level_counter_2: response.level_counter_2,
512
- }
513
- }
514
-
515
- public async achGetCategories(user_ext_id: string, force_language?: string): Promise<GetAchCategoriesResponse> {
516
-
517
- const message = this.buildMessage<any, GetAchCategoriesResponse>(user_ext_id, ClassId.GET_ACH_CATEGORIES_REQUEST);
518
- return await this.send<GetAchCategoriesResponse>(message, ClassId.GET_ACH_CATEGORIES_RESPONSE, force_language);
519
- }
520
-
521
- public async achGetCategoriesT(user_ext_id: string): Promise<TAchCategory[]> {
522
- return AchCategoryTransform((await this.achGetCategories(user_ext_id)).categories);
523
- }
524
-
525
- public async badgetsGetItems(user_ext_id: string, force_language?: string): Promise<GetAchievementMapResponse> {
526
-
527
- const message = this.buildMessage<GetAchievementMapRequest, GetAchievementMapResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST);
528
- const response = await this.send<GetAchievementMapResponse>(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE, force_language);
529
- // we need to clone response to avoid changing original object,for cases when its called together with missionsGetItems (e.g. in Promise.all)
530
- const responseClone = { ...response };
531
-
532
- if (responseClone.achievements) {
533
- responseClone.achievements = responseClone.achievements.filter(a => a.ach_type_id === AchievementType.Badge);
534
- }
535
- return responseClone;
536
- }
537
-
538
- public async badgetsGetItemsT(user_ext_id: string): Promise<TMissionOrBadge[]> {
539
- return UserAchievementTransform((await this.badgetsGetItems(user_ext_id)).achievements);
540
- }
541
-
542
-
543
- public async tournamentsGetLobby(user_ext_id: string, force_language?: string): Promise<GetTournamentsResponse> {
544
-
545
- const message = this.buildMessage<GetTournamentsRequest, GetTournamentsResponse>(user_ext_id, ClassId.GET_TOURNAMENT_LOBBY_REQUEST);
546
- return await this.send<GetTournamentsResponse>(message, ClassId.GET_TOURNAMENT_LOBBY_RESPONSE, force_language);
547
-
548
- }
549
-
550
- public async tournamentsGetLobbyT(user_ext_id: string): Promise<TTournament[]> {
551
- return TournamentItemsTransform((await this.tournamentsGetLobby(user_ext_id)).tournaments);
552
- }
553
-
554
- public async tournamentsGetInfo(user_ext_id: string, tournamentInstanceId: number, force_language?: string): Promise<GetTournamentInfoResponse> {
555
-
556
- const message = this.buildMessage<GetTournamentInfoRequest, GetTournamentInfoResponse>(user_ext_id, ClassId.GET_TOURNAMENT_INFO_REQUEST,
557
- {
558
- tournamentInstanceId
559
- }
560
- );
561
- const response = await this.send<GetTournamentInfoResponse>(message, ClassId.GET_TOURNAMENT_INFO_RESPONSE, force_language);
562
-
563
- if (response.userPosition?.avatar_id) {
564
- response.userPosition.avatar_url = CoreUtils.avatarUrl(response.userPosition.avatar_id, this.avatarDomain);
565
- }
566
-
567
- if (response.tournamentInfo.players?.length) {
568
- response.tournamentInfo.players.forEach(p => {
569
- p.avatar_url = CoreUtils.avatarUrl(p.avatar_id, this.avatarDomain);
570
- });
571
- }
572
-
573
- return response;
574
-
575
- }
576
-
577
- public async tournamentsGetInfoT(user_ext_id: string, tournamentInstanceId: number): Promise<TTournamentDetailed> {
578
- if (!tournamentInstanceId) {
579
- throw new Error('Missing tournament instance id');
580
- }
581
- const response = await this.tournamentsGetInfo(user_ext_id, tournamentInstanceId);
582
- return tournamentInfoItemTransform(response);
583
- }
584
-
585
- public async leaderboardGet(user_ext_id: string, period_type_id?: LeaderBoardPeriodType, prevPeriod: boolean = false, force_language?: string): Promise<LeaderBoardDetails> {
586
-
587
- const message = this.buildMessage<GetLeaderBoardsRequest, GetLeaderBoardsResponse>(user_ext_id, ClassId.GET_LEADERS_BOARD_REQUEST,
588
- {
589
- period_type_id,
590
- snapshot_offset: prevPeriod ? 1 : 0,
591
- include_users: true
592
- }
593
- );
594
-
595
- const response = await this.send<GetLeaderBoardsResponse>(message, ClassId.GET_LEADERS_BOARD_RESPONSE, force_language);
596
-
597
- const boardKey = Object.keys(response.map).find( k => period_type_id === undefined || k === period_type_id?.toString());
598
-
599
- if (boardKey === undefined) {
600
- return undefined;
601
- }
602
-
603
- if (response.map[boardKey]?.userPosition?.avatar_id) {
604
- response.map[boardKey].userPosition.avatar_url = CoreUtils.avatarUrl(response.map[boardKey].userPosition.avatar_id, this.avatarDomain);
605
- }
606
-
607
- if (response.map[boardKey]?.positions?.length) {
608
- response.map[boardKey].positions.forEach(p => {
609
- p.avatar_url = CoreUtils.avatarUrl(p.avatar_id, this.avatarDomain);
610
- });
611
-
612
- }
613
-
614
- return response.map[boardKey];
615
-
616
- }
617
-
618
- public async leaderboardsGetT(user_ext_id: string, period_type_id: LeaderBoardPeriodType = LeaderBoardPeriodType.DAILY, prevPeriod: boolean = false): Promise<LeaderBoardDetailsT> {
619
- return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod));
620
- }
621
-
622
- public async levelsGet(user_ext_id: string, force_language?: string): Promise<GetLevelMapResponse> {
623
- const message = this.buildMessage<any, GetLevelMapResponse>(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
624
- return await this.send<GetLevelMapResponse>(message, ClassId.GET_LEVEL_MAP_RESPONSE, force_language);
625
- }
626
-
627
- public async levelsGetT(user_ext_id: string): Promise<TLevel[]> {
628
- return GetLevelMapResponseTransform(await this.levelsGet(user_ext_id));
629
- }
630
-
631
- public async getCustomSections(user_ext_id: string): Promise<GetCustomSectionsResponse> {
632
- const message = this.buildMessage<GetCustomSectionsRequest, GetCustomSectionsResponse>(user_ext_id, ClassId.GET_CUSTOM_SECTIONS_REQUEST);
633
- return await this.send<GetCustomSectionsResponse>(message, ClassId.GET_CUSTOM_SECTIONS_RESPONSE);
634
- }
635
-
636
- public async getCustomSectionsT(user_ext_id: string): Promise<TUICustomSection[]> {
637
- return UICustomSectionTransform(Object.values((await this.getCustomSections(user_ext_id)).customSections));
638
- }
639
-
640
- public async getTranslationsT(user_ext_id: string, lang_code: string, areas: TranslationArea[], cacheSec: number = 60): Promise<GetTranslationsResponse> {
641
- return await this.coreGetTranslations(user_ext_id, lang_code, areas, 30);
642
- }
643
-
644
- public async getInboxMessages(user_ext_id: string, limit: number = 20, offset: number = 0, starred_only: boolean): Promise<GetInboxMessagesResponse> {
645
- const message = this.buildMessage<GetInboxMessagesRequest, GetInboxMessagesResponse>(user_ext_id, ClassId.GET_INBOX_MESSAGES_REQUEST, {
646
- limit,
647
- offset,
648
- starred_only
649
- });
650
- return await this.send<GetInboxMessagesResponse>(message, ClassId.GET_INBOX_MESSAGES_RESPONSE);
651
- }
652
-
653
- public async getInboxMessagesT(user_ext_id: string, from: number = 0, to: number = 20, favoriteOnly: boolean = false): Promise<TInboxMessage[]> {
654
- const limit = (to - from) > 20 ? 20 : to - from;
655
- const offset = from;
656
-
657
- return InboxMessagesTransform((await this.getInboxMessages(user_ext_id, limit, offset, favoriteOnly)).log);
658
- }
659
-
660
- public async getInboxMessageBody(messageGuid: string): Promise<InboxMessageBody> {
661
-
662
- const getMessageBody = async (messageGuid: string): Promise<InboxMessageBody>=> {
663
- const inboxCdnUrl = this.tracker.getLabelSetting(PublicLabelSettings.INBOX_PUBLIC_CDN);
664
-
665
- try {
666
- const url = `${inboxCdnUrl}${messageGuid}.json`;
667
-
668
- const response = await fetch(url, {
669
- method: 'GET',
670
- headers: {
671
- 'Accept': 'application/json',
672
- 'Content-Type': 'application/json',
673
- 'Access-Control-Allow-Origin': '*'
674
- }
675
- });
676
- const data = await response.json();
677
- return data || {};
678
- } catch (error) {
679
- this.logger.error('Error fetching inbox message body:', error);
680
- return null;
681
- }
682
- };
683
-
684
- return await getMessageBody(messageGuid)
685
- }
686
-
687
- public async getInboxMessageBodyT(messageGuid: string): Promise<TInboxMessageBody> {
688
- const message = await this.getInboxMessageBody(messageGuid);
689
- return InboxMessageBodyTransform(message);
690
- }
691
-
692
- public async markInboxMessageRead(user_ext_id: string, messageGuid: string): Promise<MarkInboxMessageReadResponse> {
693
- const message = this.buildMessage<MarkInboxMessageReadRequest, MarkInboxMessageReadResponse>(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
694
- engagement_uid: messageGuid
695
- });
696
-
697
- return await this.send<MarkInboxMessageReadResponse>(message, ClassId.MARK_INBOX_READ_RESPONSE);
698
- }
699
-
700
- public async markAllInboxMessageRead(user_ext_id: string): Promise<MarkInboxMessageReadResponse> {
701
- const message = this.buildMessage<MarkInboxMessageReadRequest, MarkInboxMessageReadResponse>(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
702
- all_read: true
703
- });
704
-
705
- return await this.send<MarkInboxMessageReadResponse>(message, ClassId.MARK_INBOX_READ_RESPONSE);
706
- }
707
-
708
- public async markUnmarkInboxMessageAsFavorite(user_ext_id: string, messageGuid: string, mark: boolean): Promise<MarkInboxMessageStarredResponse> {
709
- const message = this.buildMessage<MarkInboxMessageStarredRequest, MarkInboxMessageStarredResponse>(user_ext_id, ClassId.MARK_INBOX_STARRED_REQUEST, {
710
- engagement_uid: messageGuid,
711
- is_starred: mark
712
- });
713
-
714
- return await this.send<MarkInboxMessageStarredResponse>(message, ClassId.MARK_INBOX_STARRED_RESPONSE);
715
- }
716
-
717
- public async deleteInboxMessage(user_ext_id: string, messageGuid: string): Promise<MarkInboxMessageDeletedResponse> {
718
- const message = this.buildMessage<MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse>(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
719
- engagement_uid: messageGuid,
720
- });
721
-
722
- return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
723
- }
724
-
725
- public async deleteAllInboxMessages(user_ext_id: string): Promise<MarkInboxMessageDeletedResponse> {
726
- const message = this.buildMessage<MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse>(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
727
- all_deleted: true
728
- });
729
-
730
- return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
731
- }
732
-
733
-
734
- public getWSCalls(): WSAPI {
735
- return new WSAPI(this);
736
- }
737
-
117
+ private publicUrl: string
118
+ private wsUrl: string
119
+ private inboxCdnUrl: string
120
+ private partnerUrl: string
121
+ public avatarDomain: string
122
+
123
+ private logger: ILogger
124
+ private logCIDs: ClassId[]
125
+ private logHTTPTiming: boolean
126
+ public tracker?: Tracker
127
+
128
+ public constructor(
129
+ private label_api_key: string,
130
+ private brand_api_key: string,
131
+ private messageSender: MessageSender,
132
+ options: IOptions = {},
133
+ ) {
134
+ this.logger = options.logger || (console as any)
135
+
136
+ if (this.logger.always === undefined) {
137
+ this.logger.always = this.logger.info
138
+ }
139
+
140
+ this.logCIDs = options.logCIDs || []
141
+ this.logHTTPTiming = options.logHTTPTiming || false
142
+ this.tracker = options.tracker
143
+
144
+ this.publicUrl = SmarticoAPI.getPublicUrl(label_api_key)
145
+ this.wsUrl = SmarticoAPI.getPublicWsUrl(label_api_key)
146
+
147
+ this.avatarDomain = SmarticoAPI.getAvatarUrl(label_api_key || options.tracker?.label_api_key)
148
+
149
+ this.label_api_key = SmarticoAPI.getCleanLabelApiKey(label_api_key)
150
+ }
151
+
152
+ public static getEnvDnsSuffix(label_api_key: string): string {
153
+ let ENV_ID = label_api_key.length === 38 ? label_api_key.substring(37, 38) : ''
154
+
155
+ if (ENV_ID === '1' || ENV_ID === '2') {
156
+ ENV_ID = ''
157
+ }
158
+ return ENV_ID
159
+ }
160
+
161
+ public static getEnvId(label_api_key: string): number {
162
+ return label_api_key.length === 38 ? parseInt(label_api_key.substring(37, 38), 10) : 2
163
+ }
164
+
165
+ public static getCleanLabelApiKey(label_api_key: string): string {
166
+ return label_api_key.substring(0, 36)
167
+ }
168
+
169
+ public static getPublicUrl(label_api_key: string): string {
170
+ return PUBLIC_API_URL.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key))
171
+ }
172
+
173
+ public static getPublicWsUrl(label_api_key: string): string {
174
+ return C_SOCKET_PROD.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key))
175
+ }
176
+
177
+ public static getAvatarUrl(label_api_key: string): string {
178
+ return AVATAR_DOMAIN.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key))
179
+ }
180
+
181
+ private async send<T>(message: any, expectCID?: ClassId, force_language?: string): Promise<T> {
182
+ if (this.logCIDs.includes(message.cid)) {
183
+ this.logger.info('REQ', message)
184
+ }
185
+
186
+ if (force_language) {
187
+ message.force_language = force_language
188
+ }
189
+
190
+ let result: any
191
+
192
+ try {
193
+ const timeStart = new Date().getTime()
194
+ result = await this.messageSender(message, this.publicUrl, expectCID)
195
+ const timeEnd = new Date().getTime()
196
+
197
+ if (this.logHTTPTiming) {
198
+ this.logger.always('HTTP time, ms:' + (timeEnd - timeStart))
199
+ }
200
+ } catch (e) {
201
+ this.logger.error(`Failed to make request to smartico channel, L2. ${e.message}`, { url: this.publicUrl, request: message, error: e.message })
202
+ throw new Error(`Failed to make request to smartico channel, L2 L1. ${e.message}`)
203
+ }
204
+
205
+ if (this.logCIDs.includes(message.cid)) {
206
+ this.logger.info('RES', result)
207
+ }
208
+
209
+ if (expectCID) {
210
+ if (Array.isArray(result)) {
211
+ for (const str of result as string[]) {
212
+ const obj: ProtocolResponse = JSON.parse(str)
213
+ if (this.logCIDs.includes(obj.cid)) {
214
+ this.logger.info('RES', result)
215
+ }
216
+ if (obj.cid === expectCID) {
217
+ return obj as any
218
+ }
219
+ }
220
+ this.logger.error(`Cant find proper response in array, expected CID ${expectCID}`, { request: message, response: result })
221
+ } else {
222
+ return result
223
+ }
224
+ } else {
225
+ if (Array.isArray(result)) {
226
+ if (result.length === 1) {
227
+ const obj = JSON.parse(result[0])
228
+ if (this.logCIDs.includes(obj.cid)) {
229
+ this.logger.info('RES', result)
230
+ }
231
+ return obj
232
+ } else {
233
+ this.logger.error('Expected one response, but got array', { request: message, response: result })
234
+ }
235
+ }
236
+ return result
237
+ }
238
+ }
239
+
240
+ private buildMessage<TRequest, TResponse>(user_ext_id: string, cid: ClassId, payload: Partial<TRequest> = {}): TResponse {
241
+ const message: ProtocolRequest = {
242
+ // AA: in fact we need api and brand keys and ext_user_id only in the context of HTTP
243
+ // its not needed in WebSocket and can be deleted
244
+ api_key: this.label_api_key,
245
+ brand_key: this.brand_api_key,
246
+ ext_user_id: user_ext_id,
247
+ cid,
248
+ uuid: IntUtils.uuid(),
249
+ ts: new Date().getTime(),
250
+ ...payload,
251
+ }
252
+
253
+ if (message.ext_user_id === undefined || message.ext_user_id === null) {
254
+ delete message.ext_user_id
255
+ }
256
+
257
+ if (message.brand_key === undefined || message.brand_key === null) {
258
+ delete message.brand_key
259
+ }
260
+
261
+ return message as any
262
+ }
263
+
264
+ public async coreReportCustomEvent(user_ext_id: string, eventType: string, payload: any = {}): Promise<any> {
265
+ const eventMessage = this.buildMessage<any, any>(user_ext_id, ClassId.EVENT, {
266
+ eventType,
267
+ payload,
268
+ })
269
+
270
+ const eventResponse = await this.send<any>(eventMessage, ClassId.EVENT_RESPONSE)
271
+ return eventResponse
272
+ }
273
+
274
+ public async coreGetTranslations(user_ext_id: string, lang_code: string, areas: TranslationArea[], cacheSec: number = 60): Promise<GetTranslationsResponse> {
275
+ if (lang_code === undefined || lang_code === null || (lang_code.trim && lang_code.trim() === '')) {
276
+ lang_code = DEFAULT_LANG_EN
277
+ }
278
+
279
+ const response = await OCache.use<GetTranslationsResponse>(
280
+ `${lang_code}-${this.label_api_key}-${this.brand_api_key}`,
281
+ ECacheContext.Translations,
282
+ async () => {
283
+ const tsBaseRQ = this.buildMessage<GetTranslationsRequest, GetTranslationsResponse>(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
284
+ lang_code: DEFAULT_LANG_EN,
285
+ hash_code: 0,
286
+ areas,
287
+ })
288
+
289
+ const trBase = await this.send<GetTranslationsResponse>(tsBaseRQ, ClassId.GET_TRANSLATIONS_RESPONSE)
290
+
291
+ if (lang_code !== DEFAULT_LANG_EN) {
292
+ const trUserRQ = this.buildMessage<GetTranslationsRequest, GetTranslationsResponse>(user_ext_id, ClassId.GET_TRANSLATIONS_REQUEST, {
293
+ lang_code,
294
+ hash_code: 0,
295
+ areas,
296
+ })
297
+
298
+ const trUser = await this.send<GetTranslationsResponse>(trUserRQ, ClassId.GET_TRANSLATIONS_RESPONSE)
299
+
300
+ Object.keys(trUser?.translations ?? {}).forEach((k) => {
301
+ trBase.translations[k] = trUser.translations[k]
302
+ })
303
+ }
304
+
305
+ return trBase
306
+ },
307
+ cacheSec,
308
+ )
309
+
310
+ return response
311
+ }
312
+
313
+ public async coreIdentifyLabel(user_ext_id: string, cacheSec: number = 60): Promise<GetLabelInfoResponse> {
314
+ return OCache.use<GetLabelInfoResponse>(
315
+ `${this.label_api_key} - ${this.brand_api_key}`,
316
+ ECacheContext.LabelInfo,
317
+ async () => {
318
+ const message = this.buildMessage<GetLabelInfoResponse, GetLabelInfoRequest>(user_ext_id, ClassId.INIT)
319
+
320
+ return this.send<GetLabelInfoResponse>(message, ClassId.INIT_RESPONSE)
321
+ },
322
+ cacheSec,
323
+ )
324
+ }
325
+
326
+ public async coreIdentifyUser(user_ext_id: string): Promise<ResponseIdentify> {
327
+ const message = this.buildMessage<any, ResponseIdentify>(user_ext_id, ClassId.IDENTIFY, {
328
+ request_id: IntUtils.uuid(), // AA: do we need request_id?
329
+ })
330
+
331
+ const r = await this.send<ResponseIdentify>(message, ClassId.IDENTIFY_RESPONSE)
332
+
333
+ r.avatar_id = CoreUtils.avatarUrl(r.avatar_id, this.avatarDomain)
334
+
335
+ return r
336
+ }
337
+
338
+ public async coreChangeUsername(user_ext_id: string, public_username_custom: string): Promise<{ public_username_custom: string }> {
339
+ const message = this.buildMessage<any, any>(user_ext_id, ClassId.CLIENT_SET_CUSTOM_USERNAME_REQUEST, {
340
+ public_username_custom,
341
+ })
342
+
343
+ return await this.send(message, ClassId.CLIENT_SET_CUSTOM_USERNAME_RESPONSE)
344
+ }
345
+
346
+ public async coreCheckSegments(user_ext_id: string, segment_id: number[]): Promise<TSegmentCheckResult[]> {
347
+ const message = this.buildMessage<CheckSegmentMatchRequest, any>(user_ext_id, ClassId.CHECK_SEGMENT_MATCH_REQUEST, {
348
+ segment_id,
349
+ })
350
+
351
+ const results = await this.send<CheckSegmentMatchResponse>(message, ClassId.CHECK_SEGMENT_MATCH_RESPONSE)
352
+
353
+ return results.segments || []
354
+ }
355
+
356
+ public async jackpotGet(user_ext_id: string, filter?: { related_game_id?: string; jp_template_id?: number }, force_language?: string): Promise<GetJackpotsResponse> {
357
+ const message = this.buildMessage<GetJackpotsRequest, GetJackpotsResponse>(user_ext_id, ClassId.JP_GET_JACKPOTS_REQUEST, filter)
358
+ return await this.send<GetJackpotsResponse>(message, ClassId.JP_GET_JACKPOTS_RESPONSE, force_language)
359
+ }
360
+
361
+ public async potGet(user_ext_id: string, filter: { jp_template_ids: number[] }): Promise<GetJackpotsPotsResponse> {
362
+ const message = this.buildMessage<GetJackpotsPotsRequest, GetJackpotsPotsResponse>(user_ext_id, ClassId.JP_GET_LATEST_POTS_REQUEST, filter)
363
+ return await this.send<GetJackpotsPotsResponse>(message, ClassId.JP_GET_LATEST_POTS_RESPONSE)
364
+ }
365
+
366
+ public async jackpotOptIn(user_ext_id: string, payload: { jp_template_id: number }): Promise<JackpotsOptinResponse> {
367
+ const message = this.buildMessage<JackpotsOptinRequest, JackpotsOptinResponse>(user_ext_id, ClassId.JP_OPTIN_REQUEST, payload)
368
+ return await this.send<JackpotsOptinResponse>(message, ClassId.JP_OPTIN_RESPONSE)
369
+ }
370
+
371
+ public async jackpotOptOut(user_ext_id: string, payload: { jp_template_id: number }): Promise<JackpotsOptoutResponse> {
372
+ const message = this.buildMessage<JackpotsOptoutRequest, JackpotsOptoutResponse>(user_ext_id, ClassId.JP_OPTOUT_REQUEST, payload)
373
+ return await this.send<JackpotsOptoutResponse>(message, ClassId.JP_OPTOUT_RESPONSE)
374
+ }
375
+
376
+ public async sawGetTemplates(user_ext_id: string, force_language?: string, is_visitor_mode: boolean = false): Promise<SAWGetTemplatesResponse> {
377
+ const message = this.buildMessage<SAWGetTemplatesRequest, SAWGetTemplatesResponse>(user_ext_id, ClassId.SAW_GET_SPINS_REQUEST, { is_visitor_mode })
378
+
379
+ const response = await this.send<SAWGetTemplatesResponse>(message, ClassId.SAW_GET_SPINS_RESPONSE, force_language)
380
+
381
+ if (response && response.templates) {
382
+ response.templates.forEach((t) => {
383
+ if (t.jackpot_current !== undefined && t.jackpot_current !== null) {
384
+ const jackpotValue = t.jackpot_current + (t.saw_template_ui_definition?.jackpot_symbol ? ' ' + t.saw_template_ui_definition?.jackpot_symbol : '')
385
+ t.saw_template_ui_definition.name = IntUtils.replaceAll(t.saw_template_ui_definition.name, '{{jackpot}}', jackpotValue)
386
+ t.saw_template_ui_definition.description = IntUtils.replaceAll(t.saw_template_ui_definition.description, '{{jackpot}}', jackpotValue)
387
+ t.saw_template_ui_definition.promo_text = IntUtils.replaceAll(t.saw_template_ui_definition.promo_text, '{{jackpot}}', jackpotValue)
388
+ t.prizes.forEach((p) => {
389
+ p.saw_prize_ui_definition.name = IntUtils.replaceAll(p.saw_prize_ui_definition.name, '{{jackpot}}', jackpotValue)
390
+ p.saw_prize_ui_definition.aknowledge_message = IntUtils.replaceAll(p.saw_prize_ui_definition.aknowledge_message, '{{jackpot}}', jackpotValue)
391
+ })
392
+ }
393
+ })
394
+ }
395
+
396
+ return response
397
+ }
398
+
399
+ public async sawGetTemplatesT(user_ext_id: string): Promise<TMiniGameTemplate[]> {
400
+ return SAWTemplatesTransform((await this.sawGetTemplates(user_ext_id)).templates)
401
+ }
402
+
403
+ public async doAcknowledgeRequest(user_ext_id: string, request_id: string): Promise<SAWDoAknowledgeResponse> {
404
+ const message = this.buildMessage<SAWDoAknowledgeRequest, SAWDoAknowledgeResponse>(user_ext_id, ClassId.SAW_AKNOWLEDGE_REQUEST, {
405
+ request_id,
406
+ })
407
+
408
+ return await this.send<SAWDoAknowledgeResponse>(message, ClassId.SAW_AKNOWLEDGE_RESPONSE)
409
+ }
410
+
411
+ public async sawSpinRequest(user_ext_id: string, saw_template_id: number, round_id?: number): Promise<SAWDoSpinResponse> {
412
+ if (!saw_template_id) {
413
+ throw new Error('Missing template id')
414
+ }
415
+
416
+ const request_id = IntUtils.uuid()
417
+
418
+ const message = this.buildMessage<SAWDoSpinRequest, SAWDoSpinResponse>(user_ext_id, ClassId.SAW_DO_SPIN_REQUEST, {
419
+ saw_template_id,
420
+ request_id,
421
+ })
422
+
423
+ const spinAttemptResponse = await this.send<SAWDoSpinResponse>(message, ClassId.SAW_DO_SPIN_RESPONSE)
424
+
425
+ // to simulate fail
426
+ // response.errCode = SAWSpinErrorCode.SAW_NO_SPINS;
427
+
428
+ const status: string =
429
+ {
430
+ [SAWSpinErrorCode.SAW_OK]: 'OK',
431
+ [SAWSpinErrorCode.SAW_NO_SPINS]: 'NO SPINS AVAILABLE',
432
+ [SAWSpinErrorCode.SAW_PRIZE_POOL_EMPTY]: 'PRIZE POOL IS EMPTY',
433
+ [SAWSpinErrorCode.SAW_NOT_ENOUGH_POINTS]: 'NOT ENOUGH POINTS',
434
+ [SAWSpinErrorCode.SAW_FAILED_MAX_SPINS_REACHED]: 'MAX SPIN ATTEMPTS REACHED',
435
+ }[spinAttemptResponse.errCode] || 'OTHER'
436
+
437
+ await this.coreReportCustomEvent(user_ext_id, 'minigame_attempt', {
438
+ saw_template_id,
439
+ status,
440
+ round_id,
441
+ })
442
+
443
+ return { ...spinAttemptResponse, request_id }
444
+ }
445
+
446
+ public async missionOptIn(user_ext_id: string, mission_id: number) {
447
+ if (!mission_id) {
448
+ throw new Error('Missing mission id')
449
+ }
450
+ const message = this.buildMessage<AchievementOptinRequest, AchievementOptinResponse>(user_ext_id, ClassId.MISSION_OPTIN_REQUEST, {
451
+ achievementId: mission_id,
452
+ })
453
+
454
+ const res = await this.send<AchievementOptinResponse>(message, ClassId.MISSION_OPTIN_RESPONSE)
455
+
456
+ return res
457
+ }
458
+
459
+ public async missionClaimPrize(user_ext_id: string, mission_id: number, ach_completed_id: number) {
460
+ if (!mission_id) {
461
+ throw new Error('Missing mission id')
462
+ }
463
+
464
+ const message = this.buildMessage<AchClaimPrizeRequest, AchClaimPrizeResponse>(user_ext_id, ClassId.ACHIEVEMENT_CLAIM_PRIZE_REQUEST, {
465
+ ach_id: mission_id,
466
+ ach_completed_id: ach_completed_id,
467
+ })
468
+
469
+ const res = await this.send<AchClaimPrizeResponse>(message, ClassId.ACHIEVEMENT_CLAIM_PRIZE_RESPONSE)
470
+
471
+ return res
472
+ }
473
+
474
+ public async registerInTournament(user_ext_id: string, tournamentInstanceId: number) {
475
+ if (!tournamentInstanceId) {
476
+ throw new Error('Missing tournament instance id')
477
+ }
478
+ const message = this.buildMessage<TournamentRegisterRequest, TournamentRegisterResponse>(user_ext_id, ClassId.TOURNAMENT_REGISTER_REQUEST, {
479
+ tournamentInstanceId,
480
+ })
481
+
482
+ const res = await this.send<TournamentRegisterResponse>(message, ClassId.TOURNAMENT_REGISTER_RESPONSE)
483
+
484
+ return res
485
+ }
486
+
487
+ public async buyStoreItem(user_ext_id: string, itemId: number) {
488
+ if (!itemId) {
489
+ throw new Error('Missing store item id')
490
+ }
491
+ const message = this.buildMessage<BuyStoreItemRequest, BuyStoreItemResponse>(user_ext_id, ClassId.BUY_SHOP_ITEM_REQUEST, {
492
+ itemId,
493
+ })
494
+
495
+ const res = await this.send<BuyStoreItemResponse>(message, ClassId.BUY_SHOP_ITEM_RESPONSE)
496
+
497
+ return res
498
+ }
499
+
500
+ public async inboxGetMessages(user_ext_id: string, limit: number = 10, offset: number = 0): Promise<GetInboxMessagesResponse> {
501
+ const message = this.buildMessage<GetInboxMessagesRequest, GetInboxMessagesResponse>(user_ext_id, ClassId.GET_INBOX_MESSAGES_REQUEST, {
502
+ limit,
503
+ offset,
504
+ })
505
+
506
+ return await this.send<GetInboxMessagesResponse>(message, ClassId.GET_INBOX_MESSAGES_RESPONSE)
507
+ }
508
+
509
+ public async storeGetItems(user_ext_id: string, force_language?: string): Promise<GetStoreItemsResponse> {
510
+ const message = this.buildMessage<any, GetStoreItemsResponse>(user_ext_id, ClassId.GET_SHOP_ITEMS_REQUEST)
511
+ return await this.send<GetStoreItemsResponse>(message, ClassId.GET_SHOP_ITEMS_RESPONSE, force_language)
512
+ }
513
+
514
+ public async storeGetItemsT(user_ext_id: string): Promise<TStoreItem[]> {
515
+ return StoreItemTransform((await this.storeGetItems(user_ext_id)).items)
516
+ }
517
+
518
+ public async storeGetCategories(user_ext_id: string, force_language?: string): Promise<GetCategoriesStoreResponse> {
519
+ const message = this.buildMessage<any, GetCategoriesStoreResponse>(user_ext_id, ClassId.GET_SHOP_CATEGORIES_REQUEST)
520
+ return await this.send<GetCategoriesStoreResponse>(message, ClassId.GET_SHOP_CATEGORIES_RESPONSE, force_language)
521
+ }
522
+
523
+ public async storeGetCategoriesT(user_ext_id: string): Promise<TStoreCategory[]> {
524
+ return StoreCategoryTransform((await this.storeGetCategories(user_ext_id)).categories)
525
+ }
526
+
527
+ public async storeGetPurchasedItems(user_ext_id: string, limit: number = 20, offset: number = 0): Promise<GetStoreHistoryResponse> {
528
+ const message = this.buildMessage<GetStoreHistoryRequest, GetStoreHistoryResponse>(user_ext_id, ClassId.ACH_SHOP_ITEM_HISTORY_REQUEST, {
529
+ limit,
530
+ offset,
531
+ })
532
+
533
+ return await this.send<GetStoreHistoryResponse>(message, ClassId.ACH_SHOP_ITEM_HISTORY_RESPONSE)
534
+ }
535
+
536
+ public async storeGetPurchasedItemsT(user_ext_id: string, limit?: number, offset?: number): Promise<TStoreItem[]> {
537
+ return StoreItemPurchasedTransform((await this.storeGetPurchasedItems(user_ext_id, limit, offset)).items)
538
+ }
539
+
540
+ public async missionsGetItems(user_ext_id: string, force_language?: string): Promise<GetAchievementMapResponse> {
541
+ const message = this.buildMessage<GetAchievementMapRequest, GetAchievementMapResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST)
542
+ const response = await this.send<GetAchievementMapResponse>(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE, force_language)
543
+ // we need to clone response to avoid changing original object,for cases when its called together with badgesGetItems (e.g. in Promise.all)
544
+ const responseClone = { ...response }
545
+
546
+ if (responseClone.achievements) {
547
+ responseClone.achievements = responseClone.achievements.filter((a) => a.ach_type_id === AchievementType.Mission)
548
+ }
549
+ return responseClone
550
+ }
551
+
552
+ public async missionsGetItemsT(user_ext_id: string): Promise<TMissionOrBadge[]> {
553
+ return UserAchievementTransform((await this.missionsGetItems(user_ext_id)).achievements)
554
+ }
555
+
556
+ public async getUserGamificationInfo(user_ext_id: string): Promise<GetAchievementsUserInfoResponse> {
557
+ const message = this.buildMessage<GetAchievementMapRequest, GetAchievementsUserInfoResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_USER_REQUEST)
558
+
559
+ return await this.send<GetAchievementsUserInfoResponse>(message, ClassId.GET_ACHIEVEMENT_USER_RESPONSE)
560
+ }
561
+
562
+ public async getUserGamificationInfoT(user_ext_id: string): Promise<UserLevelExtraCountersT> {
563
+ const response = await this.getUserGamificationInfo(user_ext_id)
564
+
565
+ return {
566
+ level_counter_1: response.level_counter_1,
567
+ level_counter_2: response.level_counter_2,
568
+ }
569
+ }
570
+
571
+ public async achGetCategories(user_ext_id: string, force_language?: string): Promise<GetAchCategoriesResponse> {
572
+ const message = this.buildMessage<any, GetAchCategoriesResponse>(user_ext_id, ClassId.GET_ACH_CATEGORIES_REQUEST)
573
+ return await this.send<GetAchCategoriesResponse>(message, ClassId.GET_ACH_CATEGORIES_RESPONSE, force_language)
574
+ }
575
+
576
+ public async achGetCategoriesT(user_ext_id: string): Promise<TAchCategory[]> {
577
+ return AchCategoryTransform((await this.achGetCategories(user_ext_id)).categories)
578
+ }
579
+
580
+ public async badgetsGetItems(user_ext_id: string, force_language?: string): Promise<GetAchievementMapResponse> {
581
+ const message = this.buildMessage<GetAchievementMapRequest, GetAchievementMapResponse>(user_ext_id, ClassId.GET_ACHIEVEMENT_MAP_REQUEST)
582
+ const response = await this.send<GetAchievementMapResponse>(message, ClassId.GET_ACHIEVEMENT_MAP_RESPONSE, force_language)
583
+ // we need to clone response to avoid changing original object,for cases when its called together with missionsGetItems (e.g. in Promise.all)
584
+ const responseClone = { ...response }
585
+
586
+ if (responseClone.achievements) {
587
+ responseClone.achievements = responseClone.achievements.filter((a) => a.ach_type_id === AchievementType.Badge)
588
+ }
589
+ return responseClone
590
+ }
591
+
592
+ public async badgetsGetItemsT(user_ext_id: string): Promise<TMissionOrBadge[]> {
593
+ return UserAchievementTransform((await this.badgetsGetItems(user_ext_id)).achievements)
594
+ }
595
+
596
+ public async tournamentsGetLobby(user_ext_id: string, force_language?: string): Promise<GetTournamentsResponse> {
597
+ const message = this.buildMessage<GetTournamentsRequest, GetTournamentsResponse>(user_ext_id, ClassId.GET_TOURNAMENT_LOBBY_REQUEST)
598
+ return await this.send<GetTournamentsResponse>(message, ClassId.GET_TOURNAMENT_LOBBY_RESPONSE, force_language)
599
+ }
600
+
601
+ public async tournamentsGetLobbyT(user_ext_id: string): Promise<TTournament[]> {
602
+ return TournamentItemsTransform((await this.tournamentsGetLobby(user_ext_id)).tournaments)
603
+ }
604
+
605
+ public async tournamentsGetInfo(user_ext_id: string, tournamentInstanceId: number, force_language?: string): Promise<GetTournamentInfoResponse> {
606
+ const message = this.buildMessage<GetTournamentInfoRequest, GetTournamentInfoResponse>(user_ext_id, ClassId.GET_TOURNAMENT_INFO_REQUEST, {
607
+ tournamentInstanceId,
608
+ })
609
+ const response = await this.send<GetTournamentInfoResponse>(message, ClassId.GET_TOURNAMENT_INFO_RESPONSE, force_language)
610
+
611
+ if (response.userPosition?.avatar_id) {
612
+ response.userPosition.avatar_url = CoreUtils.avatarUrl(response.userPosition.avatar_id, this.avatarDomain)
613
+ }
614
+
615
+ if (response.tournamentInfo.players?.length) {
616
+ response.tournamentInfo.players.forEach((p) => {
617
+ p.avatar_url = CoreUtils.avatarUrl(p.avatar_id, this.avatarDomain)
618
+ })
619
+ }
620
+
621
+ return response
622
+ }
623
+
624
+ public async tournamentsGetInfoT(user_ext_id: string, tournamentInstanceId: number): Promise<TTournamentDetailed> {
625
+ if (!tournamentInstanceId) {
626
+ throw new Error('Missing tournament instance id')
627
+ }
628
+ const response = await this.tournamentsGetInfo(user_ext_id, tournamentInstanceId)
629
+ return tournamentInfoItemTransform(response)
630
+ }
631
+
632
+ public async leaderboardGet(user_ext_id: string, period_type_id?: LeaderBoardPeriodType, prevPeriod: boolean = false, force_language?: string): Promise<LeaderBoardDetails> {
633
+ const message = this.buildMessage<GetLeaderBoardsRequest, GetLeaderBoardsResponse>(user_ext_id, ClassId.GET_LEADERS_BOARD_REQUEST, {
634
+ period_type_id,
635
+ snapshot_offset: prevPeriod ? 1 : 0,
636
+ include_users: true,
637
+ })
638
+
639
+ const response = await this.send<GetLeaderBoardsResponse>(message, ClassId.GET_LEADERS_BOARD_RESPONSE, force_language)
640
+
641
+ const boardKey = Object.keys(response.map).find((k) => period_type_id === undefined || k === period_type_id?.toString())
642
+
643
+ if (boardKey === undefined) {
644
+ return undefined
645
+ }
646
+
647
+ if (response.map[boardKey]?.userPosition?.avatar_id) {
648
+ response.map[boardKey].userPosition.avatar_url = CoreUtils.avatarUrl(response.map[boardKey].userPosition.avatar_id, this.avatarDomain)
649
+ }
650
+
651
+ if (response.map[boardKey]?.positions?.length) {
652
+ response.map[boardKey].positions.forEach((p) => {
653
+ p.avatar_url = CoreUtils.avatarUrl(p.avatar_id, this.avatarDomain)
654
+ })
655
+ }
656
+
657
+ return response.map[boardKey]
658
+ }
659
+
660
+ public async leaderboardsGetT(user_ext_id: string, period_type_id: LeaderBoardPeriodType = LeaderBoardPeriodType.DAILY, prevPeriod: boolean = false): Promise<LeaderBoardDetailsT> {
661
+ return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod))
662
+ }
663
+
664
+ public async levelsGet(user_ext_id: string, force_language?: string): Promise<GetLevelMapResponse> {
665
+ const message = this.buildMessage<any, GetLevelMapResponse>(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST)
666
+ return await this.send<GetLevelMapResponse>(message, ClassId.GET_LEVEL_MAP_RESPONSE, force_language)
667
+ }
668
+
669
+ public async levelsGetT(user_ext_id: string): Promise<TLevel[]> {
670
+ return GetLevelMapResponseTransform(await this.levelsGet(user_ext_id))
671
+ }
672
+
673
+ public async getCustomSections(user_ext_id: string): Promise<GetCustomSectionsResponse> {
674
+ const message = this.buildMessage<GetCustomSectionsRequest, GetCustomSectionsResponse>(user_ext_id, ClassId.GET_CUSTOM_SECTIONS_REQUEST)
675
+ return await this.send<GetCustomSectionsResponse>(message, ClassId.GET_CUSTOM_SECTIONS_RESPONSE)
676
+ }
677
+
678
+ public async getCustomSectionsT(user_ext_id: string): Promise<TUICustomSection[]> {
679
+ return UICustomSectionTransform(Object.values((await this.getCustomSections(user_ext_id)).customSections))
680
+ }
681
+
682
+ public async getTranslationsT(user_ext_id: string, lang_code: string, areas: TranslationArea[], cacheSec: number = 60): Promise<GetTranslationsResponse> {
683
+ return await this.coreGetTranslations(user_ext_id, lang_code, areas, 30)
684
+ }
685
+
686
+ public async getInboxMessages(user_ext_id: string, limit: number = 20, offset: number = 0, starred_only: boolean): Promise<GetInboxMessagesResponse> {
687
+ const message = this.buildMessage<GetInboxMessagesRequest, GetInboxMessagesResponse>(user_ext_id, ClassId.GET_INBOX_MESSAGES_REQUEST, {
688
+ limit,
689
+ offset,
690
+ starred_only,
691
+ })
692
+ return await this.send<GetInboxMessagesResponse>(message, ClassId.GET_INBOX_MESSAGES_RESPONSE)
693
+ }
694
+
695
+ public async getInboxMessagesT(user_ext_id: string, from: number = 0, to: number = 20, favoriteOnly: boolean = false): Promise<TInboxMessage[]> {
696
+ const limit = to - from > 20 ? 20 : to - from
697
+ const offset = from
698
+
699
+ return InboxMessagesTransform((await this.getInboxMessages(user_ext_id, limit, offset, favoriteOnly)).log)
700
+ }
701
+
702
+ public async getInboxMessageBody(messageGuid: string): Promise<InboxMessageBody> {
703
+ const getMessageBody = async (messageGuid: string): Promise<InboxMessageBody> => {
704
+ const inboxCdnUrl = this.tracker.getLabelSetting(PublicLabelSettings.INBOX_PUBLIC_CDN)
705
+
706
+ try {
707
+ const url = `${inboxCdnUrl}${messageGuid}.json`
708
+
709
+ const response = await fetch(url, {
710
+ method: 'GET',
711
+ headers: {
712
+ 'Accept': 'application/json',
713
+ 'Content-Type': 'application/json',
714
+ 'Access-Control-Allow-Origin': '*',
715
+ },
716
+ })
717
+ const data = await response.json()
718
+ return data || {}
719
+ } catch (error) {
720
+ this.logger.error('Error fetching inbox message body:', error)
721
+ return null
722
+ }
723
+ }
724
+
725
+ return await getMessageBody(messageGuid)
726
+ }
727
+
728
+ public async getInboxMessageBodyT(messageGuid: string): Promise<TInboxMessageBody> {
729
+ const message = await this.getInboxMessageBody(messageGuid)
730
+ return InboxMessageBodyTransform(message)
731
+ }
732
+
733
+ public async markInboxMessageRead(user_ext_id: string, messageGuid: string): Promise<MarkInboxMessageReadResponse> {
734
+ const message = this.buildMessage<MarkInboxMessageReadRequest, MarkInboxMessageReadResponse>(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
735
+ engagement_uid: messageGuid,
736
+ })
737
+
738
+ return await this.send<MarkInboxMessageReadResponse>(message, ClassId.MARK_INBOX_READ_RESPONSE)
739
+ }
740
+
741
+ public async markAllInboxMessageRead(user_ext_id: string): Promise<MarkInboxMessageReadResponse> {
742
+ const message = this.buildMessage<MarkInboxMessageReadRequest, MarkInboxMessageReadResponse>(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
743
+ all_read: true,
744
+ })
745
+
746
+ return await this.send<MarkInboxMessageReadResponse>(message, ClassId.MARK_INBOX_READ_RESPONSE)
747
+ }
748
+
749
+ public async markUnmarkInboxMessageAsFavorite(user_ext_id: string, messageGuid: string, mark: boolean): Promise<MarkInboxMessageStarredResponse> {
750
+ const message = this.buildMessage<MarkInboxMessageStarredRequest, MarkInboxMessageStarredResponse>(user_ext_id, ClassId.MARK_INBOX_STARRED_REQUEST, {
751
+ engagement_uid: messageGuid,
752
+ is_starred: mark,
753
+ })
754
+
755
+ return await this.send<MarkInboxMessageStarredResponse>(message, ClassId.MARK_INBOX_STARRED_RESPONSE)
756
+ }
757
+
758
+ public async deleteInboxMessage(user_ext_id: string, messageGuid: string): Promise<MarkInboxMessageDeletedResponse> {
759
+ const message = this.buildMessage<MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse>(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
760
+ engagement_uid: messageGuid,
761
+ })
762
+
763
+ return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE)
764
+ }
765
+
766
+ public async deleteAllInboxMessages(user_ext_id: string): Promise<MarkInboxMessageDeletedResponse> {
767
+ const message = this.buildMessage<MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse>(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
768
+ all_deleted: true,
769
+ })
770
+
771
+ return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE)
772
+ }
773
+
774
+ public getWSCalls(): WSAPI {
775
+ return new WSAPI(this)
776
+ }
738
777
  }
739
778
 
740
- export { SmarticoAPI, MessageSender }
779
+ export { SmarticoAPI, MessageSender }