@smartico/public-api 0.0.106 → 0.0.108

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 (33) hide show
  1. package/dist/Inbox/GetInboxMessagesResponse.d.ts +2 -0
  2. package/dist/Inbox/InboxMessage.d.ts +15 -12
  3. package/dist/Inbox/MarkInboxMessageDeletedResponse.d.ts +1 -0
  4. package/dist/Inbox/MarkInboxMessageReadResponse.d.ts +1 -0
  5. package/dist/Inbox/MarkInboxMessageStarredResponse.d.ts +1 -0
  6. package/dist/SmarticoAPI.d.ts +14 -3
  7. package/dist/Store/BuyStoreItemErrorCode.d.ts +2 -1
  8. package/dist/Store/StoreItem.d.ts +1 -0
  9. package/dist/WSAPI/WSAPI.d.ts +31 -2
  10. package/dist/WSAPI/WSAPITypes.d.ts +41 -1
  11. package/dist/index.js +325 -40
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.modern.mjs +193 -17
  14. package/dist/index.modern.mjs.map +1 -1
  15. package/docs/README.md +3 -0
  16. package/docs/classes/WSAPI.md +118 -1
  17. package/docs/enums/BuyStoreItemErrorCode.md +6 -0
  18. package/docs/interfaces/InboxMarkMessageAction.md +17 -0
  19. package/docs/interfaces/TInboxMessage.md +33 -0
  20. package/docs/interfaces/TInboxMessageBody.md +52 -0
  21. package/docs/interfaces/TMissionOrBadge.md +1 -1
  22. package/docs/interfaces/TStoreItem.md +8 -0
  23. package/package.json +1 -1
  24. package/src/Inbox/GetInboxMessagesResponse.ts +14 -0
  25. package/src/Inbox/InboxMessage.ts +35 -9
  26. package/src/Inbox/MarkInboxMessageDeletedResponse.ts +1 -0
  27. package/src/Inbox/MarkInboxMessageReadResponse.ts +1 -0
  28. package/src/Inbox/MarkInboxMessageStarredResponse.ts +1 -0
  29. package/src/SmarticoAPI.ts +94 -3
  30. package/src/Store/BuyStoreItemErrorCode.ts +2 -1
  31. package/src/Store/StoreItem.ts +3 -1
  32. package/src/WSAPI/WSAPI.ts +82 -2
  33. package/src/WSAPI/WSAPITypes.ts +44 -1
@@ -480,6 +480,51 @@ var TranslationArea;
480
480
  TranslationArea[TranslationArea["AffIliateAdminNew"] = 7] = "AffIliateAdminNew";
481
481
  })(TranslationArea || (TranslationArea = {}));
482
482
 
483
+ const InboxMessagesTransform = items => {
484
+ return items.map(item => {
485
+ const x = {
486
+ sent_date: item.createDate,
487
+ message_guid: item.engagement_uid,
488
+ read: item.is_read,
489
+ favorite: item.is_starred
490
+ };
491
+ return x;
492
+ });
493
+ };
494
+
495
+ const InboxMessageBodyTransform = item => {
496
+ const x = {
497
+ action: item.action,
498
+ icon: item.image,
499
+ title: item.title,
500
+ preview_body: item.body
501
+ };
502
+ if (item.action === 'dp:inbox') {
503
+ if (item.additional_buttons && item.additional_buttons.length) {
504
+ x.buttons = item.additional_buttons.map(b => ({
505
+ action: b.action,
506
+ text: b.inbox_cta_text
507
+ }));
508
+ }
509
+ x.html_body = (item == null ? void 0 : item.html_body) || null;
510
+ }
511
+ return x;
512
+ };
513
+
514
+ var InboxMessageType;
515
+ (function (InboxMessageType) {
516
+ InboxMessageType[InboxMessageType["Custom"] = 0] = "Custom";
517
+ InboxMessageType[InboxMessageType["MissionCompleted"] = 1] = "MissionCompleted";
518
+ InboxMessageType[InboxMessageType["MissionUnlocked"] = 2] = "MissionUnlocked";
519
+ InboxMessageType[InboxMessageType["LeaderboardWon"] = 3] = "LeaderboardWon";
520
+ InboxMessageType[InboxMessageType["LevelChanged"] = 4] = "LevelChanged";
521
+ InboxMessageType[InboxMessageType["BonusGiven"] = 5] = "BonusGiven";
522
+ InboxMessageType[InboxMessageType["PointsAdded"] = 6] = "PointsAdded";
523
+ InboxMessageType[InboxMessageType["PointsUsed"] = 7] = "PointsUsed";
524
+ InboxMessageType[InboxMessageType["PersonalMessage"] = 8] = "PersonalMessage";
525
+ })(InboxMessageType || (InboxMessageType = {}));
526
+ // keep in sync with BO enum
527
+
483
528
  var BuyStoreItemErrorCode;
484
529
  (function (BuyStoreItemErrorCode) {
485
530
  BuyStoreItemErrorCode[BuyStoreItemErrorCode["FAILED_TO_BUY_SHOP_ITEM"] = 121] = "FAILED_TO_BUY_SHOP_ITEM";
@@ -490,6 +535,7 @@ var BuyStoreItemErrorCode;
490
535
  BuyStoreItemErrorCode[BuyStoreItemErrorCode["SHOP_FAILED_TO_BUY_SHOP_ITEM_CONDITION_PURSHASE"] = 11004] = "SHOP_FAILED_TO_BUY_SHOP_ITEM_CONDITION_PURSHASE";
491
536
  BuyStoreItemErrorCode[BuyStoreItemErrorCode["SHOP_FAILED_TO_BUY_MATCHING_BONUS"] = 11005] = "SHOP_FAILED_TO_BUY_MATCHING_BONUS";
492
537
  BuyStoreItemErrorCode[BuyStoreItemErrorCode["SHOP_FAILED_MAX_BOUGHT_ITEMS_REACHED"] = 11006] = "SHOP_FAILED_MAX_BOUGHT_ITEMS_REACHED";
538
+ BuyStoreItemErrorCode[BuyStoreItemErrorCode["SHOP_FAILED_POOL_EMPTY"] = 11009] = "SHOP_FAILED_POOL_EMPTY";
493
539
  })(BuyStoreItemErrorCode || (BuyStoreItemErrorCode = {}));
494
540
 
495
541
  const StoreCategoryTransform = items => {
@@ -528,7 +574,8 @@ const StoreItemTransform = items => {
528
574
  [StoreItemType.Manual]: 'manual'
529
575
  }[r.itemTypeId],
530
576
  can_buy: r.canBuy,
531
- category_ids: (_r$categoryIds = r.categoryIds) != null ? _r$categoryIds : []
577
+ category_ids: (_r$categoryIds = r.categoryIds) != null ? _r$categoryIds : [],
578
+ pool: r.shopPool
532
579
  };
533
580
  return x;
534
581
  });
@@ -870,6 +917,7 @@ var onUpdateContextKey;
870
917
  onUpdateContextKey["Saw"] = "saw";
871
918
  onUpdateContextKey["Missions"] = "missions";
872
919
  onUpdateContextKey["TournamentList"] = "tournamentList";
920
+ onUpdateContextKey["InboxMessages"] = "inboxMessages";
873
921
  })(onUpdateContextKey || (onUpdateContextKey = {}));
874
922
  /** @group General API */
875
923
  class WSAPI {
@@ -884,6 +932,7 @@ class WSAPI {
884
932
  on(ClassId.SAW_DO_SPIN_RESPONSE, data => on(ClassId.SAW_AKNOWLEDGE_RESPONSE, () => this.updateOnPrizeWin(data)));
885
933
  on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissionsOnOptIn());
886
934
  on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournamentsOnRegistration());
935
+ on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
887
936
  }
888
937
  /** Returns information about current user */
889
938
  getUserProfile() {
@@ -983,7 +1032,7 @@ class WSAPI {
983
1032
  }
984
1033
  return OCache.use(onUpdateContextKey.TournamentList, ECacheContext.WSAPI, () => this.api.tournamentsGetLobbyT(null), CACHE_DATA_SEC);
985
1034
  }
986
- /** Returns details information of specific tournament instance, the response will includ tournamnet info and the leaderboard of players */
1035
+ /** Returns details information of specific tournament instance, the response will include tournament info and the leaderboard of players */
987
1036
  async getTournamentInstanceInfo(tournamentInstanceId) {
988
1037
  return this.api.tournamentsGetInfoT(null, tournamentInstanceId);
989
1038
  }
@@ -996,6 +1045,71 @@ class WSAPI {
996
1045
  };
997
1046
  return o;
998
1047
  }
1048
+ /** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
1049
+ * The maximum number of messages per request is limited to 20. An indicator "onlyFavorite" can be passed to get only messages marked as favorites.
1050
+ * You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
1051
+ * This functions return list of messages without the body of the message.
1052
+ * To get the body of the message you need to call getInboxMessageBody function and pass the message guid contained in each message of this request.
1053
+ * All other action like mark as read, favorite, delete, etc. can be done using this message GUID.
1054
+ * The "onUpdate" callback will be triggered when the user receives a new message. It will provide an updated list of messages, ranging from 0 to 20, to the onUpdate callback function. */
1055
+ /**
1056
+ * @param params
1057
+ */
1058
+ async getInboxMessages({
1059
+ from,
1060
+ to,
1061
+ onlyFavorite,
1062
+ onUpdate
1063
+ } = {}) {
1064
+ if (onUpdate) {
1065
+ this.onUpdateCallback.set(onUpdateContextKey.InboxMessages, onUpdate);
1066
+ }
1067
+ return await this.api.getInboxMessagesT(null, from, to, onlyFavorite);
1068
+ }
1069
+ /** Returns the message body of the specified message guid. */
1070
+ async getInboxMessageBody(messageGuid) {
1071
+ return await this.api.getInboxMessageBodyT(messageGuid);
1072
+ }
1073
+ /** Requests to mark inbox message with specified guid as read */
1074
+ async markInboxMessageAsRead(messageGuid) {
1075
+ const r = await this.api.markInboxMessageRead(null, messageGuid);
1076
+ return {
1077
+ err_code: r.errCode,
1078
+ err_message: r.errMsg
1079
+ };
1080
+ }
1081
+ /** Requests to mark all inbox messages as read */
1082
+ async markAllInboxMessagesAsRead() {
1083
+ const r = await this.api.markAllInboxMessageRead(null);
1084
+ return {
1085
+ err_code: r.errCode,
1086
+ err_message: r.errMsg
1087
+ };
1088
+ }
1089
+ /** Requests to mark inbox message with specified guid as favorite. Pass mark true to add message to favorite and false to remove. */
1090
+ async markUnmarkInboxMessageAsFavorite(messageGuid, mark) {
1091
+ const r = await this.api.markUnmarkInboxMessageAsFavorite(null, messageGuid, mark);
1092
+ return {
1093
+ err_code: r.errCode,
1094
+ err_message: r.errMsg
1095
+ };
1096
+ }
1097
+ /** Requests to delete inbox message */
1098
+ async deleteInboxMessage(messageGuid) {
1099
+ const r = await this.api.deleteInboxMessage(null, messageGuid);
1100
+ return {
1101
+ err_code: r.errCode,
1102
+ err_message: r.errMsg
1103
+ };
1104
+ }
1105
+ /** Requests to delete all inbox messages */
1106
+ async deleteAllInboxMessages() {
1107
+ const r = await this.api.deleteAllInboxMessages(null);
1108
+ return {
1109
+ err_code: r.errCode,
1110
+ err_message: r.errMsg
1111
+ };
1112
+ }
999
1113
  /** Requests translations for the given language. Returns the object including translation key/translation value pairs. All possible translation keys defined in the back office. */
1000
1114
  async getTranslations(lang_code) {
1001
1115
  const r = await this.api.getTranslationsT(null, lang_code, []);
@@ -1033,6 +1147,10 @@ class WSAPI {
1033
1147
  const payload = await this.api.tournamentsGetLobbyT(null);
1034
1148
  this.updateEntity(onUpdateContextKey.TournamentList, payload);
1035
1149
  }
1150
+ async updateInboxMessages() {
1151
+ const payload = await this.api.getInboxMessagesT(null);
1152
+ this.updateEntity(onUpdateContextKey.InboxMessages, payload);
1153
+ }
1036
1154
  async updateEntity(contextKey, payload) {
1037
1155
  OCache.set(contextKey, payload, ECacheContext.WSAPI);
1038
1156
  const onUpdate = this.onUpdateCallback.get(contextKey);
@@ -1054,6 +1172,7 @@ class SmarticoAPI {
1054
1172
  this.messageSender = void 0;
1055
1173
  this.publicUrl = void 0;
1056
1174
  this.wsUrl = void 0;
1175
+ this.inboxCdnUrl = void 0;
1057
1176
  this.partnerUrl = void 0;
1058
1177
  this.avatarDomain = void 0;
1059
1178
  this.logger = void 0;
@@ -1428,6 +1547,77 @@ class SmarticoAPI {
1428
1547
  async getTranslationsT(user_ext_id, lang_code, areas, cacheSec = 60) {
1429
1548
  return await this.coreGetTranslations(user_ext_id, lang_code, areas, 30);
1430
1549
  }
1550
+ async getInboxMessages(user_ext_id, limit = 20, offset = 0, starred_only) {
1551
+ const message = this.buildMessage(user_ext_id, ClassId.GET_INBOX_MESSAGES_REQUEST, {
1552
+ limit,
1553
+ offset,
1554
+ starred_only
1555
+ });
1556
+ return await this.send(message, ClassId.GET_INBOX_MESSAGES_RESPONSE);
1557
+ }
1558
+ async getInboxMessagesT(user_ext_id, from = 0, to = 20, favoriteOnly = false) {
1559
+ const limit = to - from > 20 ? 20 : to - from;
1560
+ const offset = from;
1561
+ return InboxMessagesTransform((await this.getInboxMessages(user_ext_id, limit, offset, favoriteOnly)).log);
1562
+ }
1563
+ async getInboxMessageBody(messageGuid) {
1564
+ var _this3 = this;
1565
+ const getMessageBody = async function getMessageBody(messageGuid) {
1566
+ const inboxCdnUrl = _this3.tracker.getLabelSetting(PublicLabelSettings.INBOX_PUBLIC_CDN);
1567
+ try {
1568
+ const url = `${inboxCdnUrl}${messageGuid}.json`;
1569
+ const response = await fetch(url, {
1570
+ method: 'GET',
1571
+ headers: {
1572
+ 'Accept': 'application/json',
1573
+ 'Content-Type': 'application/json',
1574
+ 'Access-Control-Allow-Origin': '*'
1575
+ }
1576
+ });
1577
+ const data = await response.json();
1578
+ return data || {};
1579
+ } catch (error) {
1580
+ _this3.logger.error('Error fetching inbox message body:', error);
1581
+ return null;
1582
+ }
1583
+ };
1584
+ return await getMessageBody(messageGuid);
1585
+ }
1586
+ async getInboxMessageBodyT(messageGuid) {
1587
+ const message = await this.getInboxMessageBody(messageGuid);
1588
+ return InboxMessageBodyTransform(message);
1589
+ }
1590
+ async markInboxMessageRead(user_ext_id, messageGuid) {
1591
+ const message = this.buildMessage(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
1592
+ engagement_uid: messageGuid
1593
+ });
1594
+ return await this.send(message, ClassId.MARK_INBOX_READ_RESPONSE);
1595
+ }
1596
+ async markAllInboxMessageRead(user_ext_id) {
1597
+ const message = this.buildMessage(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
1598
+ all_read: true
1599
+ });
1600
+ return await this.send(message, ClassId.MARK_INBOX_READ_RESPONSE);
1601
+ }
1602
+ async markUnmarkInboxMessageAsFavorite(user_ext_id, messageGuid, mark) {
1603
+ const message = this.buildMessage(user_ext_id, ClassId.MARK_INBOX_STARRED_REQUEST, {
1604
+ engagement_uid: messageGuid,
1605
+ is_starred: mark
1606
+ });
1607
+ return await this.send(message, ClassId.MARK_INBOX_STARRED_RESPONSE);
1608
+ }
1609
+ async deleteInboxMessage(user_ext_id, messageGuid) {
1610
+ const message = this.buildMessage(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
1611
+ engagement_uid: messageGuid
1612
+ });
1613
+ return await this.send(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
1614
+ }
1615
+ async deleteAllInboxMessages(user_ext_id) {
1616
+ const message = this.buildMessage(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
1617
+ all_deleted: true
1618
+ });
1619
+ return await this.send(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
1620
+ }
1431
1621
  getWSCalls() {
1432
1622
  return new WSAPI(this);
1433
1623
  }
@@ -1444,20 +1634,6 @@ class CookieStore {
1444
1634
  }
1445
1635
  CookieStore.cookieStore = new TSMap();
1446
1636
 
1447
- var InboxMessageType;
1448
- (function (InboxMessageType) {
1449
- InboxMessageType[InboxMessageType["Custom"] = 0] = "Custom";
1450
- InboxMessageType[InboxMessageType["MissionCompleted"] = 1] = "MissionCompleted";
1451
- InboxMessageType[InboxMessageType["MissionUnlocked"] = 2] = "MissionUnlocked";
1452
- InboxMessageType[InboxMessageType["LeaderboardWon"] = 3] = "LeaderboardWon";
1453
- InboxMessageType[InboxMessageType["LevelChanged"] = 4] = "LevelChanged";
1454
- InboxMessageType[InboxMessageType["BonusGiven"] = 5] = "BonusGiven";
1455
- InboxMessageType[InboxMessageType["PointsAdded"] = 6] = "PointsAdded";
1456
- InboxMessageType[InboxMessageType["PointsUsed"] = 7] = "PointsUsed";
1457
- InboxMessageType[InboxMessageType["PersonalMessage"] = 8] = "PersonalMessage";
1458
- })(InboxMessageType || (InboxMessageType = {}));
1459
- // keep in sync with BO enum
1460
-
1461
1637
  var LeaderBoardPeriodType;
1462
1638
  (function (LeaderBoardPeriodType) {
1463
1639
  LeaderBoardPeriodType[LeaderBoardPeriodType["DAILY"] = 1] = "DAILY";
@@ -1465,5 +1641,5 @@ var LeaderBoardPeriodType;
1465
1641
  LeaderBoardPeriodType[LeaderBoardPeriodType["MONTHLY"] = 3] = "MONTHLY";
1466
1642
  })(LeaderBoardPeriodType || (LeaderBoardPeriodType = {}));
1467
1643
 
1468
- export { AchievementStatus, AchievementTaskType, AchievementType, ActivityTypeLimited, BuyStoreItemErrorCode, ClassId, CookieStore, CoreUtils, GetLevelMapResponseTransform, InboxMessageType, 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 };
1644
+ export { 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 };
1469
1645
  //# sourceMappingURL=index.modern.mjs.map