@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.
@@ -7,17 +7,17 @@ import { IntUtils } from './IntUtils';
7
7
  import { ILogger } from './ILogger';
8
8
  import { SAWDoAknowledgeRequest, SAWDoAknowledgeResponse, SAWDoSpinRequest, SAWDoSpinResponse, SAWSpinErrorCode, SAWTemplatesTransform } from './MiniGames';
9
9
  import { ECacheContext, OCache } from './OCache';
10
- import { CoreUtils, GetTranslationsRequest, GetTranslationsResponse, ResponseIdentify, TranslationArea } from './Core';
10
+ import { CoreUtils, GetTranslationsRequest, GetTranslationsResponse, PublicLabelSettings, ResponseIdentify, TranslationArea } from './Core';
11
11
  import { GetLabelInfoResponse } from './Core/GetLabelInfoResponse';
12
12
  import { GetLabelInfoRequest } from './Core/GetLabelInfoRequest';
13
- import { GetInboxMessagesRequest, GetInboxMessagesResponse } from './Inbox';
13
+ import { GetInboxMessagesRequest, GetInboxMessagesResponse, InboxMessageBody, InboxMessageBodyTransform, InboxMessagesTransform, MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse, MarkInboxMessageReadRequest, MarkInboxMessageReadResponse, MarkInboxMessageStarredRequest, MarkInboxMessageStarredResponse } from './Inbox';
14
14
  import { BuyStoreItemRequest, BuyStoreItemResponse, GetCategoriesStoreResponse, GetStoreItemsResponse, StoreCategoryTransform, StoreItemTransform } from './Store';
15
15
  import { AchievementOptinRequest, AchievementOptinResponse, AchievementType, GetAchievementMapRequest, GetAchievementMapResponse, UserAchievementTransform } from './Missions';
16
16
  import { GetTournamentInfoRequest, GetTournamentInfoResponse, GetTournamentsRequest, GetTournamentsResponse, TournamentItemsTransform, TournamentRegisterRequest, TournamentRegisterResponse, tournamentInfoItemTransform } from './Tournaments';
17
17
  import { GetLeaderBoardsRequest, GetLeaderBoardsResponse, LeaderBoardDetails, LeaderBoardPeriodType } from "./Leaderboard";
18
18
  import { GetLevelMapResponse, GetLevelMapResponseTransform } from "./Level";
19
19
  import { WSAPI } from "./WSAPI/WSAPI";
20
- import { TLevel, TMiniGameTemplate, TMissionOrBadge, TStoreCategory, TStoreItem, TTournament, TTournamentDetailed } from "./WSAPI/WSAPITypes";
20
+ import { TInboxMessage, TInboxMessageBody, TLevel, TMiniGameTemplate, TMissionOrBadge, TStoreCategory, TStoreItem, TTournament, TTournamentDetailed } from "./WSAPI/WSAPITypes";
21
21
 
22
22
  const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
23
23
  const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
@@ -28,6 +28,7 @@ interface Tracker {
28
28
  label_api_key: string;
29
29
  userPublicProps: any;
30
30
  on: (callBackKey: ClassId, func: (data: any) => void) => void;
31
+ getLabelSetting: (key: PublicLabelSettings) => any;
31
32
  }
32
33
  interface IOptions {
33
34
  logger?: ILogger;
@@ -43,6 +44,7 @@ class SmarticoAPI {
43
44
 
44
45
  private publicUrl: string;
45
46
  private wsUrl: string;
47
+ private inboxCdnUrl: string;
46
48
  private partnerUrl: string;
47
49
  public avatarDomain: string;
48
50
 
@@ -525,6 +527,95 @@ class SmarticoAPI {
525
527
  return await this.coreGetTranslations(user_ext_id, lang_code, areas, 30);
526
528
  }
527
529
 
530
+ public async getInboxMessages(user_ext_id: string, limit: number = 20, offset: number = 0, starred_only: boolean): Promise<GetInboxMessagesResponse> {
531
+ const message = this.buildMessage<GetInboxMessagesRequest, GetInboxMessagesResponse>(user_ext_id, ClassId.GET_INBOX_MESSAGES_REQUEST, {
532
+ limit,
533
+ offset,
534
+ starred_only
535
+ });
536
+ return await this.send<GetInboxMessagesResponse>(message, ClassId.GET_INBOX_MESSAGES_RESPONSE);
537
+ }
538
+
539
+ public async getInboxMessagesT(user_ext_id: string, from: number = 0, to: number = 20, favoriteOnly: boolean = false): Promise<TInboxMessage[]> {
540
+ const limit = (to - from) > 20 ? 20 : to - from;
541
+ const offset = from;
542
+
543
+ return InboxMessagesTransform((await this.getInboxMessages(user_ext_id, limit, offset, favoriteOnly)).log);
544
+ }
545
+
546
+ public async getInboxMessageBody(messageGuid: string): Promise<InboxMessageBody> {
547
+
548
+ const getMessageBody = async (messageGuid: string): Promise<InboxMessageBody>=> {
549
+ const inboxCdnUrl = this.tracker.getLabelSetting(PublicLabelSettings.INBOX_PUBLIC_CDN);
550
+
551
+ try {
552
+ const url = `${inboxCdnUrl}${messageGuid}.json`;
553
+
554
+ const response = await fetch(url, {
555
+ method: 'GET',
556
+ headers: {
557
+ 'Accept': 'application/json',
558
+ 'Content-Type': 'application/json',
559
+ 'Access-Control-Allow-Origin': '*'
560
+ }
561
+ });
562
+ const data = await response.json();
563
+ return data || {};
564
+ } catch (error) {
565
+ this.logger.error('Error fetching inbox message body:', error);
566
+ return null;
567
+ }
568
+ };
569
+
570
+ return await getMessageBody(messageGuid)
571
+ }
572
+
573
+ public async getInboxMessageBodyT(messageGuid: string): Promise<TInboxMessageBody> {
574
+ const message = await this.getInboxMessageBody(messageGuid);
575
+ return InboxMessageBodyTransform(message);
576
+ }
577
+
578
+ public async markInboxMessageRead(user_ext_id: string, messageGuid: string): Promise<MarkInboxMessageReadResponse> {
579
+ const message = this.buildMessage<MarkInboxMessageReadRequest, MarkInboxMessageReadResponse>(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
580
+ engagement_uid: messageGuid
581
+ });
582
+
583
+ return await this.send<MarkInboxMessageReadResponse>(message, ClassId.MARK_INBOX_READ_RESPONSE);
584
+ }
585
+
586
+ public async markAllInboxMessageRead(user_ext_id: string): Promise<MarkInboxMessageReadResponse> {
587
+ const message = this.buildMessage<MarkInboxMessageReadRequest, MarkInboxMessageReadResponse>(user_ext_id, ClassId.MARK_INBOX_READ_REQUEST, {
588
+ all_read: true
589
+ });
590
+
591
+ return await this.send<MarkInboxMessageReadResponse>(message, ClassId.MARK_INBOX_READ_RESPONSE);
592
+ }
593
+
594
+ public async markUnmarkInboxMessageAsFavorite(user_ext_id: string, messageGuid: string, mark: boolean): Promise<MarkInboxMessageStarredResponse> {
595
+ const message = this.buildMessage<MarkInboxMessageStarredRequest, MarkInboxMessageStarredResponse>(user_ext_id, ClassId.MARK_INBOX_STARRED_REQUEST, {
596
+ engagement_uid: messageGuid,
597
+ is_starred: mark
598
+ });
599
+
600
+ return await this.send<MarkInboxMessageStarredResponse>(message, ClassId.MARK_INBOX_STARRED_RESPONSE);
601
+ }
602
+
603
+ public async deleteInboxMessage(user_ext_id: string, messageGuid: string): Promise<MarkInboxMessageDeletedResponse> {
604
+ const message = this.buildMessage<MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse>(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
605
+ engagement_uid: messageGuid,
606
+ });
607
+
608
+ return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
609
+ }
610
+
611
+ public async deleteAllInboxMessages(user_ext_id: string): Promise<MarkInboxMessageDeletedResponse> {
612
+ const message = this.buildMessage<MarkInboxMessageDeletedRequest, MarkInboxMessageDeletedResponse>(user_ext_id, ClassId.MARK_INBOX_DELETED_REQUEST, {
613
+ all_deleted: true
614
+ });
615
+
616
+ return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
617
+ }
618
+
528
619
 
529
620
  public getWSCalls(): WSAPI {
530
621
  return new WSAPI(this);
@@ -3,7 +3,7 @@ import { CoreUtils } from "../Core";
3
3
  import { MiniGamePrizeTypeName, SAWDoSpinResponse, SAWSpinErrorCode, SAWSpinsCountPush } from "../MiniGames";
4
4
  import { ECacheContext, OCache } from "../OCache";
5
5
  import { SmarticoAPI } from "../SmarticoAPI";
6
- import { TBuyStoreItemResult, TGetTranslations, TLevel, TMiniGamePlayResult, TMiniGamePrize, TMiniGameTemplate, TMissionOptInResult, TMissionOrBadge, TStoreItem, TTournament, TTournamentDetailed, TTournamentRegistrationResult, TUserProfile } from "./WSAPITypes";
6
+ import { InboxMarkMessageAction, TBuyStoreItemResult, TGetTranslations, TInboxMessage, TInboxMessageBody, TLevel, TMiniGamePlayResult, TMiniGameTemplate, TMissionOptInResult, TMissionOrBadge, TStoreItem, TTournament, TTournamentDetailed, TTournamentRegistrationResult, TUserProfile } from "./WSAPITypes";
7
7
 
8
8
  /** @hidden */
9
9
  const CACHE_DATA_SEC = 30;
@@ -12,6 +12,7 @@ enum onUpdateContextKey {
12
12
  Saw = 'saw',
13
13
  Missions = 'missions',
14
14
  TournamentList = 'tournamentList',
15
+ InboxMessages = 'inboxMessages',
15
16
  }
16
17
 
17
18
 
@@ -28,6 +29,7 @@ export class WSAPI {
28
29
  on(ClassId.SAW_DO_SPIN_RESPONSE, (data: SAWDoSpinResponse) => on(ClassId.SAW_AKNOWLEDGE_RESPONSE, () => this.updateOnPrizeWin(data)));
29
30
  on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissionsOnOptIn());
30
31
  on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournamentsOnRegistration());
32
+ on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
31
33
  }
32
34
 
33
35
  /** Returns information about current user */
@@ -142,7 +144,7 @@ export class WSAPI {
142
144
  return OCache.use(onUpdateContextKey.TournamentList, ECacheContext.WSAPI, () => this.api.tournamentsGetLobbyT(null), CACHE_DATA_SEC);
143
145
  }
144
146
 
145
- /** Returns details information of specific tournament instance, the response will includ tournamnet info and the leaderboard of players */
147
+ /** Returns details information of specific tournament instance, the response will include tournament info and the leaderboard of players */
146
148
  public async getTournamentInstanceInfo(tournamentInstanceId: number): Promise<TTournamentDetailed> {
147
149
  return this.api.tournamentsGetInfoT(null, tournamentInstanceId);
148
150
  }
@@ -159,6 +161,79 @@ export class WSAPI {
159
161
  return o;
160
162
  }
161
163
 
164
+ /** Returns inbox messages based on the provided parameters. "From" and "to" indicate the range of messages to be fetched.
165
+ * The maximum number of messages per request is limited to 20. An indicator "onlyFavorite" can be passed to get only messages marked as favorites.
166
+ * You can leave this params empty and by default it will return list of messages ranging from 0 to 20.
167
+ * This functions return list of messages without the body of the message.
168
+ * 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.
169
+ * All other action like mark as read, favorite, delete, etc. can be done using this message GUID.
170
+ * 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. */
171
+ /**
172
+ * @param params
173
+ */
174
+ public async getInboxMessages({ from, to, onlyFavorite, onUpdate }: { from?: number, to?: number, onlyFavorite?: boolean, onUpdate?: (data: TInboxMessage[]) => void } = {}): Promise<TInboxMessage[]> {
175
+ if (onUpdate) {
176
+ this.onUpdateCallback.set(onUpdateContextKey.InboxMessages, onUpdate);
177
+ }
178
+
179
+ return await this.api.getInboxMessagesT(null, from, to, onlyFavorite);
180
+ }
181
+
182
+ /** Returns the message body of the specified message guid. */
183
+ public async getInboxMessageBody(messageGuid: string): Promise<TInboxMessageBody> {
184
+ return await this.api.getInboxMessageBodyT(messageGuid);
185
+ }
186
+
187
+ /** Requests to mark inbox message with specified guid as read */
188
+ public async markInboxMessageAsRead(messageGuid: string): Promise<InboxMarkMessageAction> {
189
+ const r = await this.api.markInboxMessageRead(null, messageGuid);
190
+
191
+ return {
192
+ err_code: r.errCode,
193
+ err_message: r.errMsg,
194
+ }
195
+ }
196
+
197
+ /** Requests to mark all inbox messages as read */
198
+ public async markAllInboxMessagesAsRead(): Promise<InboxMarkMessageAction> {
199
+ const r = await this.api.markAllInboxMessageRead(null);
200
+
201
+ return {
202
+ err_code: r.errCode,
203
+ err_message: r.errMsg,
204
+ }
205
+ }
206
+
207
+ /** Requests to mark inbox message with specified guid as favorite. Pass mark true to add message to favorite and false to remove. */
208
+ public async markUnmarkInboxMessageAsFavorite(messageGuid: string, mark: boolean): Promise<InboxMarkMessageAction> {
209
+ const r = await this.api.markUnmarkInboxMessageAsFavorite(null, messageGuid, mark);
210
+
211
+ return {
212
+ err_code: r.errCode,
213
+ err_message: r.errMsg,
214
+ }
215
+ }
216
+
217
+ /** Requests to delete inbox message */
218
+ public async deleteInboxMessage(messageGuid: string): Promise<InboxMarkMessageAction> {
219
+ const r = await this.api.deleteInboxMessage(null, messageGuid);
220
+
221
+ return {
222
+ err_code: r.errCode,
223
+ err_message: r.errMsg,
224
+ }
225
+ }
226
+
227
+ /** Requests to delete all inbox messages */
228
+ public async deleteAllInboxMessages(): Promise<InboxMarkMessageAction> {
229
+ const r = await this.api.deleteAllInboxMessages(null);
230
+
231
+ return {
232
+ err_code: r.errCode,
233
+ err_message: r.errMsg,
234
+ }
235
+ }
236
+
162
237
  /** Requests translations for the given language. Returns the object including translation key/translation value pairs. All possible translation keys defined in the back office. */
163
238
  public async getTranslations(lang_code: string): Promise<TGetTranslations> {
164
239
  const r = await this.api.getTranslationsT(null, lang_code, []);
@@ -208,6 +283,11 @@ export class WSAPI {
208
283
  this.updateEntity(onUpdateContextKey.TournamentList, payload)
209
284
  }
210
285
 
286
+ private async updateInboxMessages() {
287
+ const payload = await this.api.getInboxMessagesT(null);
288
+ this.updateEntity(onUpdateContextKey.InboxMessages, payload)
289
+ }
290
+
211
291
  private async updateEntity(contextKey: onUpdateContextKey, payload: any) {
212
292
  OCache.set(contextKey, payload, ECacheContext.WSAPI);
213
293
 
@@ -406,7 +406,7 @@ export interface TMissionOrBadge {
406
406
  progress: number;
407
407
  /**
408
408
  * The action that should be performed when user clicks on the mission or badge
409
- * Can be URL or deep link, e.g. 'dp:deposit'. The most safe to execute CTA is to pass it to _smartico.do(cta_action);
409
+ * Can be URL or deep link, e.g. 'dp:deposit'. The most safe to execute CTA is to pass it to _smartico.dp(cta_action);
410
410
  * The 'dp' function will handle the CTA and will execute it in the most safe way
411
411
  */
412
412
  cta_action: string,
@@ -491,4 +491,45 @@ export interface TBuyStoreItemResult {
491
491
 
492
492
  export interface TGetTranslations {
493
493
  translations: {[key: string]: string};
494
+ }
495
+
496
+ export interface TInboxMessage {
497
+ /** Uniq identifier of the message. It is needed to request the message body, mark the message as read/deleted/favorite. */
498
+ message_guid: string;
499
+ /** Date when the message was sent */
500
+ sent_date: string;
501
+ /** Indicator if a message is read */
502
+ read: boolean;
503
+ /** Indicator if a message is added to favorites */
504
+ favorite: boolean;
505
+ }
506
+
507
+ export interface TInboxMessageBody {
508
+ /** Message title */
509
+ title: string
510
+ /** Short preview body of the message */
511
+ preview_body: string,
512
+ /** Message icon */
513
+ icon: string,
514
+ /** The action that should be performed when user clicks on the message.
515
+ * Can be URL or deep link, e.g. 'dp:deposit'. The most safe to execute CTA is to pass it to _smartico.dp(cta_action);
516
+ * The 'dp' function will handle the CTA and will execute it in the most safe way.
517
+ * If the message has a rich html body - the action will always be 'dp:inbox' which will open the inbox widget when triggered. */
518
+ action: string,
519
+ /** Rich HTML body of the message. */
520
+ html_body?: string,
521
+ /** Optional additional buttons to show in the message, available only if message has rich HTML body. Max count - 2. */
522
+ buttons?: {
523
+ /** The action that should be performed when user clicks on the button. The logic is the same as for message actions */
524
+ action: string,
525
+ /** Button text */
526
+ text: string
527
+ }[];
528
+ }
529
+
530
+ export interface InboxMarkMessageAction {
531
+ /** An error code representing the result of marking a message as deleted, favorite or read. Successful marking action if err_code is 0 */
532
+ err_code: number;
533
+ /** Optional error message */
534
+ err_message: string;
494
535
  }