@smartico/public-api 0.0.107 → 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.
- package/dist/Inbox/GetInboxMessagesResponse.d.ts +2 -0
- package/dist/Inbox/InboxMessage.d.ts +15 -12
- package/dist/Inbox/MarkInboxMessageDeletedResponse.d.ts +1 -0
- package/dist/Inbox/MarkInboxMessageReadResponse.d.ts +1 -0
- package/dist/Inbox/MarkInboxMessageStarredResponse.d.ts +1 -0
- package/dist/SmarticoAPI.d.ts +14 -3
- package/dist/WSAPI/WSAPI.d.ts +31 -2
- package/dist/WSAPI/WSAPITypes.d.ts +39 -1
- package/dist/index.js +322 -39
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +190 -16
- package/dist/index.modern.mjs.map +1 -1
- package/docs/README.md +3 -0
- package/docs/classes/WSAPI.md +144 -27
- package/docs/interfaces/InboxMarkMessageAction.md +17 -0
- package/docs/interfaces/TInboxMessage.md +33 -0
- package/docs/interfaces/TInboxMessageBody.md +52 -0
- package/docs/interfaces/TMissionOrBadge.md +1 -1
- package/docs/interfaces/TTournament.md +1 -1
- package/docs/interfaces/TTournamentDetailed.md +2 -2
- package/package.json +1 -1
- package/src/Inbox/GetInboxMessagesResponse.ts +14 -0
- package/src/Inbox/InboxMessage.ts +35 -9
- package/src/Inbox/MarkInboxMessageDeletedResponse.ts +1 -0
- package/src/Inbox/MarkInboxMessageReadResponse.ts +1 -0
- package/src/Inbox/MarkInboxMessageStarredResponse.ts +1 -0
- package/src/SmarticoAPI.ts +94 -3
- package/src/WSAPI/WSAPI.ts +82 -2
- package/src/WSAPI/WSAPITypes.ts +42 -1
package/dist/index.modern.mjs
CHANGED
|
@@ -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";
|
|
@@ -872,6 +917,7 @@ var onUpdateContextKey;
|
|
|
872
917
|
onUpdateContextKey["Saw"] = "saw";
|
|
873
918
|
onUpdateContextKey["Missions"] = "missions";
|
|
874
919
|
onUpdateContextKey["TournamentList"] = "tournamentList";
|
|
920
|
+
onUpdateContextKey["InboxMessages"] = "inboxMessages";
|
|
875
921
|
})(onUpdateContextKey || (onUpdateContextKey = {}));
|
|
876
922
|
/** @group General API */
|
|
877
923
|
class WSAPI {
|
|
@@ -886,6 +932,7 @@ class WSAPI {
|
|
|
886
932
|
on(ClassId.SAW_DO_SPIN_RESPONSE, data => on(ClassId.SAW_AKNOWLEDGE_RESPONSE, () => this.updateOnPrizeWin(data)));
|
|
887
933
|
on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissionsOnOptIn());
|
|
888
934
|
on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournamentsOnRegistration());
|
|
935
|
+
on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
|
|
889
936
|
}
|
|
890
937
|
/** Returns information about current user */
|
|
891
938
|
getUserProfile() {
|
|
@@ -985,7 +1032,7 @@ class WSAPI {
|
|
|
985
1032
|
}
|
|
986
1033
|
return OCache.use(onUpdateContextKey.TournamentList, ECacheContext.WSAPI, () => this.api.tournamentsGetLobbyT(null), CACHE_DATA_SEC);
|
|
987
1034
|
}
|
|
988
|
-
/** Returns details information of specific tournament instance, the response will
|
|
1035
|
+
/** Returns details information of specific tournament instance, the response will include tournament info and the leaderboard of players */
|
|
989
1036
|
async getTournamentInstanceInfo(tournamentInstanceId) {
|
|
990
1037
|
return this.api.tournamentsGetInfoT(null, tournamentInstanceId);
|
|
991
1038
|
}
|
|
@@ -998,6 +1045,71 @@ class WSAPI {
|
|
|
998
1045
|
};
|
|
999
1046
|
return o;
|
|
1000
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
|
+
}
|
|
1001
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. */
|
|
1002
1114
|
async getTranslations(lang_code) {
|
|
1003
1115
|
const r = await this.api.getTranslationsT(null, lang_code, []);
|
|
@@ -1035,6 +1147,10 @@ class WSAPI {
|
|
|
1035
1147
|
const payload = await this.api.tournamentsGetLobbyT(null);
|
|
1036
1148
|
this.updateEntity(onUpdateContextKey.TournamentList, payload);
|
|
1037
1149
|
}
|
|
1150
|
+
async updateInboxMessages() {
|
|
1151
|
+
const payload = await this.api.getInboxMessagesT(null);
|
|
1152
|
+
this.updateEntity(onUpdateContextKey.InboxMessages, payload);
|
|
1153
|
+
}
|
|
1038
1154
|
async updateEntity(contextKey, payload) {
|
|
1039
1155
|
OCache.set(contextKey, payload, ECacheContext.WSAPI);
|
|
1040
1156
|
const onUpdate = this.onUpdateCallback.get(contextKey);
|
|
@@ -1056,6 +1172,7 @@ class SmarticoAPI {
|
|
|
1056
1172
|
this.messageSender = void 0;
|
|
1057
1173
|
this.publicUrl = void 0;
|
|
1058
1174
|
this.wsUrl = void 0;
|
|
1175
|
+
this.inboxCdnUrl = void 0;
|
|
1059
1176
|
this.partnerUrl = void 0;
|
|
1060
1177
|
this.avatarDomain = void 0;
|
|
1061
1178
|
this.logger = void 0;
|
|
@@ -1430,6 +1547,77 @@ class SmarticoAPI {
|
|
|
1430
1547
|
async getTranslationsT(user_ext_id, lang_code, areas, cacheSec = 60) {
|
|
1431
1548
|
return await this.coreGetTranslations(user_ext_id, lang_code, areas, 30);
|
|
1432
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
|
+
}
|
|
1433
1621
|
getWSCalls() {
|
|
1434
1622
|
return new WSAPI(this);
|
|
1435
1623
|
}
|
|
@@ -1446,20 +1634,6 @@ class CookieStore {
|
|
|
1446
1634
|
}
|
|
1447
1635
|
CookieStore.cookieStore = new TSMap();
|
|
1448
1636
|
|
|
1449
|
-
var InboxMessageType;
|
|
1450
|
-
(function (InboxMessageType) {
|
|
1451
|
-
InboxMessageType[InboxMessageType["Custom"] = 0] = "Custom";
|
|
1452
|
-
InboxMessageType[InboxMessageType["MissionCompleted"] = 1] = "MissionCompleted";
|
|
1453
|
-
InboxMessageType[InboxMessageType["MissionUnlocked"] = 2] = "MissionUnlocked";
|
|
1454
|
-
InboxMessageType[InboxMessageType["LeaderboardWon"] = 3] = "LeaderboardWon";
|
|
1455
|
-
InboxMessageType[InboxMessageType["LevelChanged"] = 4] = "LevelChanged";
|
|
1456
|
-
InboxMessageType[InboxMessageType["BonusGiven"] = 5] = "BonusGiven";
|
|
1457
|
-
InboxMessageType[InboxMessageType["PointsAdded"] = 6] = "PointsAdded";
|
|
1458
|
-
InboxMessageType[InboxMessageType["PointsUsed"] = 7] = "PointsUsed";
|
|
1459
|
-
InboxMessageType[InboxMessageType["PersonalMessage"] = 8] = "PersonalMessage";
|
|
1460
|
-
})(InboxMessageType || (InboxMessageType = {}));
|
|
1461
|
-
// keep in sync with BO enum
|
|
1462
|
-
|
|
1463
1637
|
var LeaderBoardPeriodType;
|
|
1464
1638
|
(function (LeaderBoardPeriodType) {
|
|
1465
1639
|
LeaderBoardPeriodType[LeaderBoardPeriodType["DAILY"] = 1] = "DAILY";
|
|
@@ -1467,5 +1641,5 @@ var LeaderBoardPeriodType;
|
|
|
1467
1641
|
LeaderBoardPeriodType[LeaderBoardPeriodType["MONTHLY"] = 3] = "MONTHLY";
|
|
1468
1642
|
})(LeaderBoardPeriodType || (LeaderBoardPeriodType = {}));
|
|
1469
1643
|
|
|
1470
|
-
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 };
|
|
1471
1645
|
//# sourceMappingURL=index.modern.mjs.map
|