@smartico/public-api 0.0.352 → 0.0.353

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.
@@ -143,22 +143,25 @@ import {
143
143
 
144
144
  const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
145
145
  const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
146
- const GAMES_API_URL = 'https://r-games-api{ENV_ID}.smr.vc';
146
+ const GAMES_API_URL = 'https://r-games-api.smr.vc';
147
147
  const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
148
148
  const DEFAULT_LANG_EN = 'EN';
149
149
 
150
150
  interface Tracker {
151
151
  label_api_key: string;
152
152
  userPublicProps: any;
153
+ params: { brand_key?: string };
153
154
  on: (callBackKey: ClassId, func: (data: any) => void) => void;
154
155
  getLabelSetting: (key: PublicLabelSettings) => any;
155
156
  triggerExternalCallBack: (callBackKey: string, payload: any) => void;
157
+ getExtUserId: () => string;
156
158
  }
157
159
  interface IOptions {
158
160
  logger?: ILogger;
159
161
  logCIDs?: ClassId[];
160
162
  logHTTPTiming?: boolean;
161
163
  tracker?: Tracker;
164
+ brand_api_key?: string;
162
165
  }
163
166
 
164
167
  type MessageSender = (message: any, publicApuUrl?: string, expectCID?: ClassId) => Promise<any>;
@@ -168,7 +171,8 @@ class SmarticoAPI {
168
171
  private wsUrl: string;
169
172
  private inboxCdnUrl: string;
170
173
  private partnerUrl: string;
171
- public gamesApiUrl: string;
174
+ private gamesApiUrl: string;
175
+ private baseRgApiParams: Record<string, string>;
172
176
  public avatarDomain: string;
173
177
  private envId: number;
174
178
 
@@ -195,7 +199,13 @@ class SmarticoAPI {
195
199
 
196
200
  this.publicUrl = SmarticoAPI.getPublicUrl(label_api_key);
197
201
  this.wsUrl = SmarticoAPI.getPublicWsUrl(label_api_key);
198
- this.gamesApiUrl = SmarticoAPI.getGamesApiUrl(label_api_key);
202
+
203
+ this.baseRgApiParams = {
204
+ env_id: String(SmarticoAPI.getEnvId(label_api_key)),
205
+ label_api_key: label_api_key,
206
+ brand_key: options.brand_api_key || this.tracker.params.brand_key,
207
+ hash: IntUtils.uuid(),
208
+ }
199
209
 
200
210
  this.avatarDomain = SmarticoAPI.getAvatarUrl(label_api_key || options.tracker?.label_api_key);
201
211
 
@@ -211,7 +221,7 @@ class SmarticoAPI {
211
221
  return ENV_ID;
212
222
  }
213
223
 
214
- public static replaceSmrDomainsWithCloudfront<T>(value: string | {[key: string]: any}): T {
224
+ public static replaceSmrDomainsWithCloudfront<T>(value: string | { [key: string]: any }): T {
215
225
  if (!value) {
216
226
  return value as T;
217
227
  }
@@ -265,10 +275,6 @@ class SmarticoAPI {
265
275
  return C_SOCKET_PROD.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key));
266
276
  }
267
277
 
268
- public static getGamesApiUrl(label_api_key: string): string {
269
- return GAMES_API_URL.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key));
270
- }
271
-
272
278
  public static getAvatarUrl(label_api_key: string): string {
273
279
  const avatarUrl = AVATAR_DOMAIN.replace('{ENV_ID}', SmarticoAPI.getEnvDnsSuffix(label_api_key));
274
280
  return SmarticoAPI.replaceSmrDomainsWithCloudfront(avatarUrl);
@@ -491,7 +497,7 @@ class SmarticoAPI {
491
497
  activityType,
492
498
  });
493
499
 
494
- this.send(message).catch(() => {});
500
+ this.send(message).catch(() => { });
495
501
  }
496
502
 
497
503
  /**
@@ -509,7 +515,7 @@ class SmarticoAPI {
509
515
  ...(action && { action }),
510
516
  });
511
517
 
512
- this.send(message).catch(() => {});
518
+ this.send(message).catch(() => { });
513
519
  }
514
520
 
515
521
  public async jackpotGet(
@@ -552,7 +558,7 @@ class SmarticoAPI {
552
558
  return await this.send<JackpotsOptoutResponse>(message, ClassId.JP_OPTOUT_RESPONSE);
553
559
  }
554
560
 
555
- public async getJackpotWinners(user_ext_id: string, limit: number = 20, offset: number = 0, jp_template_id: number ): Promise<GetJackpotWinnersResponse> {
561
+ public async getJackpotWinners(user_ext_id: string, limit: number = 20, offset: number = 0, jp_template_id: number): Promise<GetJackpotWinnersResponse> {
556
562
  const message = this.buildMessage<GetJackpotWinnersRequest, GetJackpotWinnersResponse>(
557
563
  user_ext_id,
558
564
  ClassId.JP_GET_WINNERS_REQUEST,
@@ -565,11 +571,11 @@ class SmarticoAPI {
565
571
  return await this.send<GetJackpotWinnersResponse>(message, ClassId.JP_GET_WINNERS_RESPONSE);
566
572
  }
567
573
 
568
- public async getJackpotWinnersT(user_ext_id: string, limit: number = 20, offset: number = 0, jp_template_id: number ): Promise<JackpotWinnerHistory[]> {
574
+ public async getJackpotWinnersT(user_ext_id: string, limit: number = 20, offset: number = 0, jp_template_id: number): Promise<JackpotWinnerHistory[]> {
569
575
  return GetJackpotWinnersResponseTransform((await this.getJackpotWinners(user_ext_id, limit, offset, jp_template_id)).winners);
570
576
  }
571
577
 
572
- public async getJackpotEligibleGames(user_ext_id: string, { jp_template_id } : { jp_template_id: number }): Promise<GetJackpotEligibleGamesResponse> {
578
+ public async getJackpotEligibleGames(user_ext_id: string, { jp_template_id }: { jp_template_id: number }): Promise<GetJackpotEligibleGamesResponse> {
573
579
  const message = this.buildMessage<GetJackpotEligibleGamesRequest, GetJackpotEligibleGamesResponse>(
574
580
  user_ext_id,
575
581
  ClassId.JP_GET_ELIGIBLE_GAMES_REQUEST,
@@ -579,7 +585,7 @@ class SmarticoAPI {
579
585
  return await this.send<GetJackpotEligibleGamesResponse>(message, ClassId.JP_GET_ELIGIBLE_GAMES_RESPONSE);;
580
586
  }
581
587
 
582
- public async getJackpotEligibleGamesT(user_ext_id: string, { jp_template_id } : { jp_template_id: number }): Promise<TGetJackpotEligibleGamesResponse> {
588
+ public async getJackpotEligibleGamesT(user_ext_id: string, { jp_template_id }: { jp_template_id: number }): Promise<TGetJackpotEligibleGamesResponse> {
583
589
  return GetJackpotEligibleGamesResponseTransform(await this.getJackpotEligibleGames(user_ext_id, { jp_template_id }));
584
590
  }
585
591
 
@@ -743,7 +749,7 @@ class SmarticoAPI {
743
749
  public async getSawWinningHistoryT(user_ext_id: string, limit?: number, offset?: number, saw_template_id?: number): Promise<SAWPrizesHistory[]> {
744
750
  return SAWHistoryTransform((await this.getSawWinningHistory(user_ext_id, limit, offset, saw_template_id)).prizes);
745
751
  }
746
-
752
+
747
753
  public async missionOptIn(user_ext_id: string, mission_id: number) {
748
754
  if (!mission_id) {
749
755
  throw new Error('Missing mission id');
@@ -946,7 +952,7 @@ class SmarticoAPI {
946
952
  ClassId.GET_BONUSES_RESPONSE,
947
953
  force_language,
948
954
  );
949
-
955
+
950
956
  const responseClone = { ...response };
951
957
 
952
958
  return responseClone;
@@ -963,7 +969,7 @@ class SmarticoAPI {
963
969
  ClassId.CLAIM_BONUS_RESPONSE,
964
970
 
965
971
  );
966
-
972
+
967
973
  const responseClone = { ...response };
968
974
 
969
975
  return responseClone;
@@ -1280,45 +1286,37 @@ class SmarticoAPI {
1280
1286
  return await this.send<MarkInboxMessageDeletedResponse>(message, ClassId.MARK_INBOX_DELETED_RESPONSE);
1281
1287
  }
1282
1288
 
1283
- private buildGamesApiParams(ext_user_id: string, smartico_ext_user_id: string, ext_game_id: number, lang: string): Record<string, string> {
1284
- const params: Record<string, string> = {
1285
- ext_user_id,
1286
- smartico_ext_user_id,
1287
- ext_game_id: String(ext_game_id),
1288
- lang,
1289
- env_id: String(SmarticoAPI.getEnvId(this.label_api_key)),
1290
- label_api_key: this.label_api_key,
1291
- hash: '',
1292
- };
1293
-
1294
- if (this.brand_api_key) {
1295
- params.brand_key = this.brand_api_key;
1296
- }
1289
+ private buildGamesApiParams(): Record<string, string> {
1290
+ const params: Record<string, string> = Object.assign({}, this.baseRgApiParams, {
1291
+ ext_user_id: this.tracker.userPublicProps?.user_id,
1292
+ smartico_ext_user_id: this.tracker.getExtUserId(),
1293
+ lang: this.tracker.userPublicProps?.core_user_language,
1294
+ });
1297
1295
 
1298
1296
  return params;
1299
1297
  }
1300
1298
 
1301
- private async sendGamesApi<T>(method: string, ext_user_id: string, smartico_ext_user_id: string, ext_game_id: number, lang: string, extraParams?: Record<string, any>, usePost: boolean = false): Promise<GamesApiResponse<T>> {
1302
- const baseParams = this.buildGamesApiParams(ext_user_id, smartico_ext_user_id, ext_game_id, lang);
1299
+ private async sendGamesApi<T>({ method, params, usePost = false }: { method: string, params: Record<string, any>, usePost?: boolean }): Promise<GamesApiResponse<T>> {
1300
+ const baseParams = this.buildGamesApiParams();
1303
1301
  const queryString = Object.entries(baseParams).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
1304
- let url = `${this.gamesApiUrl}/${method}?${queryString}`;
1302
+ let url = `${GAMES_API_URL}/${method}?${queryString}`;
1305
1303
 
1306
1304
  let fetchOptions: RequestInit = {
1307
1305
  method: 'GET',
1308
1306
  headers: { 'Accept': 'application/json' },
1309
1307
  };
1310
1308
 
1311
- if (usePost && extraParams) {
1309
+ if (usePost && params) {
1312
1310
  fetchOptions = {
1313
1311
  method: 'POST',
1314
1312
  headers: {
1315
1313
  'Accept': 'application/json',
1316
1314
  'Content-Type': 'application/json',
1317
1315
  },
1318
- body: JSON.stringify(extraParams),
1316
+ body: JSON.stringify(params),
1319
1317
  };
1320
- } else if (extraParams) {
1321
- const extraQuery = Object.entries(extraParams)
1318
+ } else if (params) {
1319
+ const extraQuery = Object.entries(params)
1322
1320
  .map(([k, v]) => `${k}=${encodeURIComponent(JSON.stringify(v))}`)
1323
1321
  .join('&');
1324
1322
  url += `&${extraQuery}`;
@@ -1326,6 +1324,7 @@ class SmarticoAPI {
1326
1324
 
1327
1325
  try {
1328
1326
  const response = await fetch(url, fetchOptions);
1327
+
1329
1328
  const data = await response.json();
1330
1329
  return SmarticoAPI.replaceSmrDomainsWithCloudfront<GamesApiResponse<T>>(data);
1331
1330
  } catch (e) {
@@ -1334,45 +1333,82 @@ class SmarticoAPI {
1334
1333
  }
1335
1334
  }
1336
1335
 
1337
- public async gpGetActiveRounds(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickRound[]>> {
1338
- return this.sendGamesApi<GamePickRound[]>('active-rounds', ext_user_id, smartico_ext_user_id, saw_template_id, lang);
1336
+ public async gpGetActiveRounds(saw_template_id: number): Promise<GamesApiResponse<GamePickRound[]>> {
1337
+ const params = {
1338
+ ext_game_id: saw_template_id,
1339
+ };
1340
+
1341
+ return this.sendGamesApi<GamePickRound[]>({ method: 'active-rounds', params });
1339
1342
  }
1340
1343
 
1341
- public async gpGetActiveRound(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, lang: string = DEFAULT_LANG_EN, round_id?: number): Promise<GamesApiResponse<GamePickRound>> {
1342
- const extraParams: Record<string, any> = {};
1343
- if (round_id !== undefined) {
1344
- extraParams.round_id = round_id;
1345
- }
1346
- return this.sendGamesApi<GamePickRound>('active-round', ext_user_id, smartico_ext_user_id, saw_template_id, lang, Object.keys(extraParams).length > 0 ? extraParams : undefined);
1344
+ public async gpGetActiveRound(saw_template_id: number, round_id?: number): Promise<GamesApiResponse<GamePickRound>> {
1345
+ const params = {
1346
+ ext_game_id: saw_template_id,
1347
+ round_id: round_id,
1348
+ };
1349
+
1350
+ return this.sendGamesApi<GamePickRound>({ method: 'active-round', params });
1347
1351
  }
1348
1352
 
1349
- public async gpGetGamesHistory(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickRound[]>> {
1350
- return this.sendGamesApi<GamePickRound[]>('games-history', ext_user_id, smartico_ext_user_id, saw_template_id, lang);
1353
+ public async gpGetGamesHistory(saw_template_id: number): Promise<GamesApiResponse<GamePickRound[]>> {
1354
+ const params = {
1355
+ ext_game_id: saw_template_id,
1356
+ };
1357
+
1358
+ return this.sendGamesApi<GamePickRound[]>({ method: 'games-history', params });
1351
1359
  }
1352
1360
 
1353
- public async gpGetGameBoard(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, round_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickRoundBoard>> {
1354
- return this.sendGamesApi<GamePickRoundBoard>('game-board', ext_user_id, smartico_ext_user_id, saw_template_id, lang, { round_id });
1361
+ public async gpGetGameBoard(saw_template_id: number, round_id: number): Promise<GamesApiResponse<GamePickRoundBoard>> {
1362
+ const params = {
1363
+ ext_game_id: saw_template_id,
1364
+ round_id: round_id,
1365
+ };
1366
+
1367
+ return this.sendGamesApi<GamePickRoundBoard>({ method: 'game-board', params });
1355
1368
  }
1356
1369
 
1357
- public async gpSubmitSelection(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, round: any, isQuiz: boolean, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickRound>> {
1370
+ public async gpSubmitSelection(saw_template_id: number, round: any, isQuiz: boolean): Promise<GamesApiResponse<GamePickRound>> {
1358
1371
  const method = isQuiz ? 'submit-selection-quiz' : 'submit-selection';
1359
- return this.sendGamesApi<GamePickRound>(method, ext_user_id, smartico_ext_user_id, saw_template_id, lang, { round }, true);
1372
+ const params = {
1373
+ ext_game_id: saw_template_id,
1374
+ round: round,
1375
+ };
1376
+
1377
+ return this.sendGamesApi<GamePickRound>({ method, params, usePost: true });
1360
1378
  }
1361
1379
 
1362
- public async gpGetUserInfo(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickUserInfo>> {
1363
- return this.sendGamesApi<GamePickUserInfo>('user-info', ext_user_id, smartico_ext_user_id, saw_template_id, lang);
1380
+ public async gpGetUserInfo(saw_template_id: number): Promise<GamesApiResponse<GamePickUserInfo>> {
1381
+ const params = {
1382
+ ext_game_id: saw_template_id,
1383
+ };
1384
+
1385
+ return this.sendGamesApi<GamePickUserInfo>({ method: 'user-info', params });
1364
1386
  }
1365
1387
 
1366
- public async gpGetGameInfo(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickGameInfo>> {
1367
- return this.sendGamesApi<GamePickGameInfo>('game-info', ext_user_id, smartico_ext_user_id, saw_template_id, lang);
1388
+ public async gpGetGameInfo(saw_template_id: number): Promise<GamesApiResponse<GamePickGameInfo>> {
1389
+ const params = {
1390
+ ext_game_id: saw_template_id,
1391
+ };
1392
+
1393
+ return this.sendGamesApi<GamePickGameInfo>({ method: 'game-info', params });
1368
1394
  }
1369
1395
 
1370
- public async gpGetTranslations(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<any>> {
1371
- return this.sendGamesApi<any>('translations', ext_user_id, smartico_ext_user_id, saw_template_id, lang);
1396
+ public async gpGetTranslations(saw_template_id: number): Promise<GamesApiResponse<any>> {
1397
+ const params = {
1398
+ ext_game_id: saw_template_id,
1399
+ };
1400
+
1401
+ return this.sendGamesApi<any>({ method: 'translations', params });
1372
1402
  }
1373
1403
 
1374
- public async gpGetRoundInfoForUser(ext_user_id: string, smartico_ext_user_id: string, saw_template_id: number, round_id: number, int_user_id: number, lang: string = DEFAULT_LANG_EN): Promise<GamesApiResponse<GamePickRound>> {
1375
- return this.sendGamesApi<GamePickRound>('game-round-info-for-user', ext_user_id, smartico_ext_user_id, saw_template_id, lang, { round_id, int_user_id });
1404
+ public async gpGetRoundInfoForUser(saw_template_id: number, round_id: number, int_user_id: number): Promise<GamesApiResponse<GamePickRound>> {
1405
+ const params = {
1406
+ ext_game_id: saw_template_id,
1407
+ round_id: round_id,
1408
+ int_user_id: int_user_id,
1409
+ };
1410
+
1411
+ return this.sendGamesApi<GamePickRound>({ method: 'game-round-info-for-user', params });
1376
1412
  }
1377
1413
 
1378
1414
  public getWSCalls(): WSAPI {
@@ -1380,14 +1416,14 @@ class SmarticoAPI {
1380
1416
  }
1381
1417
 
1382
1418
  public async getRelatedItemsForGame(user_ext_id: string, related_game_id: string,): Promise<GetRelatedAchTourResponse> {
1383
- const message = this.buildMessage< GetRelatedAchTourRequest, GetRelatedAchTourResponse>(
1419
+ const message = this.buildMessage<GetRelatedAchTourRequest, GetRelatedAchTourResponse>(
1384
1420
  user_ext_id,
1385
1421
  ClassId.GET_RELATED_ACH_N_TOURNAMENTS_REQUEST,
1386
1422
  {
1387
1423
  related_game_id: related_game_id
1388
1424
  }
1389
1425
  );
1390
-
1426
+
1391
1427
  return await this.send<GetRelatedAchTourResponse>(message, ClassId.GET_RELATED_ACH_N_TOURNAMENTS_RESPONSE);
1392
1428
  }
1393
1429