@smartico/public-api 0.0.126 → 0.0.128
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/Jackpots/GetJackpotsRequest.d.ts +1 -0
- package/dist/Jackpots/GetJackpotsResponse.d.ts +1 -1
- package/dist/Jackpots/JackpotHtmlTemplate.d.ts +5 -0
- package/dist/Jackpots/JackpotPublicMeta.d.ts +3 -0
- package/dist/Jackpots/index.d.ts +1 -0
- package/dist/NodeCache.d.ts +1 -0
- package/dist/OCache.d.ts +2 -1
- package/dist/SmarticoAPI.d.ts +14 -0
- package/dist/SmarticoLib/index.d.ts +2013 -0
- package/dist/WSAPI/WSAPI.d.ts +13 -0
- package/dist/index.js +288 -126
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +88 -3
- package/dist/index.modern.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Jackpots/GetJackpotsRequest.ts +1 -0
- package/src/Jackpots/GetJackpotsResponse.ts +1 -1
- package/src/Jackpots/JackpotHtmlTemplate.ts +6 -0
- package/src/Jackpots/JackpotPot.ts +0 -1
- package/src/Jackpots/JackpotPublicMeta.ts +3 -0
- package/src/Jackpots/index.ts +2 -1
- package/src/NodeCache.ts +7 -0
- package/src/OCache.ts +9 -1
- package/src/SmarticoAPI.ts +24 -1
- package/src/SmarticoLib/index.ts +2019 -0
- package/src/WSAPI/WSAPI.ts +88 -4
package/src/WSAPI/WSAPI.ts
CHANGED
|
@@ -5,9 +5,15 @@ import { ECacheContext, OCache } from "../OCache";
|
|
|
5
5
|
import { SmarticoAPI } from "../SmarticoAPI";
|
|
6
6
|
import { InboxMarkMessageAction, LeaderBoardDetailsT, TAchCategory, TBuyStoreItemResult, TGetTranslations, TInboxMessage, TInboxMessageBody, TLevel, TMiniGamePlayResult, TMiniGameTemplate, TMissionClaimRewardResult, TMissionOptInResult, TMissionOrBadge, TSegmentCheckResult, TStoreCategory, TStoreItem, TTournament, TTournamentDetailed, TTournamentRegistrationResult, TUserProfile, UserLevelExtraCountersT } from "./WSAPITypes";
|
|
7
7
|
import { LeaderBoardPeriodType } from "../Leaderboard";
|
|
8
|
+
import { JackpotDetails, JackpotPot, JackpotWinPush, JackpotsOptinResponse, JackpotsOptoutResponse } from "src/Jackpots";
|
|
9
|
+
import { AchRelatedGame } from "src/Base/AchRelatedGame";
|
|
8
10
|
|
|
9
11
|
/** @hidden */
|
|
10
12
|
const CACHE_DATA_SEC = 30;
|
|
13
|
+
|
|
14
|
+
const JACKPOT_TEMPLATE_CACHE_SEC = 30;
|
|
15
|
+
const JACKPOT_POT_CACHE_SEC = 1;
|
|
16
|
+
|
|
11
17
|
/** @hidden */
|
|
12
18
|
enum onUpdateContextKey {
|
|
13
19
|
Saw = 'saw',
|
|
@@ -22,7 +28,9 @@ enum onUpdateContextKey {
|
|
|
22
28
|
LeaderBoards = 'leaderBoards',
|
|
23
29
|
LevelExtraCounters = 'levelExtraCounters',
|
|
24
30
|
Segments = 'segments',
|
|
25
|
-
StoreHistory = 'storeHistory'
|
|
31
|
+
StoreHistory = 'storeHistory',
|
|
32
|
+
Jackpots = 'jackpots',
|
|
33
|
+
Pots = 'Pots',
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
|
|
@@ -30,6 +38,7 @@ enum onUpdateContextKey {
|
|
|
30
38
|
export class WSAPI {
|
|
31
39
|
|
|
32
40
|
private onUpdateCallback: Map<onUpdateContextKey, (data: any) => void> = new Map();
|
|
41
|
+
private jackpotGetSignature: string = '';
|
|
33
42
|
|
|
34
43
|
/** @private */
|
|
35
44
|
constructor(private api: SmarticoAPI) {
|
|
@@ -40,8 +49,9 @@ export class WSAPI {
|
|
|
40
49
|
on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissionsOnOptIn());
|
|
41
50
|
on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournamentsOnRegistration());
|
|
42
51
|
on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
|
|
43
|
-
on(ClassId.LOGOUT_RESPONSE, () => OCache.
|
|
44
|
-
on(ClassId.IDENTIFY_RESPONSE, () => OCache.
|
|
52
|
+
on(ClassId.LOGOUT_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
|
|
53
|
+
on(ClassId.IDENTIFY_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
|
|
54
|
+
on(ClassId.JP_WIN_PUSH, (data: JackpotWinPush) => this.jackpotClearCache())
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
/** Returns information about current user
|
|
@@ -426,4 +436,78 @@ export class WSAPI {
|
|
|
426
436
|
onUpdate(payload);
|
|
427
437
|
}
|
|
428
438
|
}
|
|
429
|
-
|
|
439
|
+
|
|
440
|
+
private async jackpotClearCache() {
|
|
441
|
+
OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Jackpots);
|
|
442
|
+
OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Pots);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
public async jackpotGet(filter?: { related_game_id?: string, jp_template_id?: number }): Promise<JackpotDetails[]> {
|
|
447
|
+
|
|
448
|
+
const signature: string = `${filter.jp_template_id}:${filter.related_game_id}`;
|
|
449
|
+
|
|
450
|
+
if (signature !== this.jackpotGetSignature) {
|
|
451
|
+
this.jackpotGetSignature = signature;
|
|
452
|
+
this.jackpotClearCache();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
let jackpots: JackpotDetails[] = [];
|
|
456
|
+
let pots: JackpotPot[] = [];
|
|
457
|
+
|
|
458
|
+
jackpots = await OCache.use<JackpotDetails[]>(onUpdateContextKey.Jackpots, ECacheContext.WSAPI, async () => {
|
|
459
|
+
|
|
460
|
+
const _jackpots = await this.api.jackpotGet(null, filter);
|
|
461
|
+
const _pots = _jackpots.map( jp => jp.pot);
|
|
462
|
+
|
|
463
|
+
OCache.set(onUpdateContextKey.Pots, _pots, ECacheContext.WSAPI, JACKPOT_POT_CACHE_SEC);
|
|
464
|
+
return _jackpots;
|
|
465
|
+
|
|
466
|
+
}, JACKPOT_TEMPLATE_CACHE_SEC);
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
if (jackpots.length > 0) {
|
|
470
|
+
pots = await OCache.use<JackpotPot[]>(onUpdateContextKey.Pots, ECacheContext.WSAPI, async () => {
|
|
471
|
+
|
|
472
|
+
const jp_template_ids = jackpots.map(jp => jp.jp_template_id);
|
|
473
|
+
return this.api.potGet(null, { jp_template_ids })
|
|
474
|
+
|
|
475
|
+
}, JACKPOT_POT_CACHE_SEC);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return jackpots.map( jp => {
|
|
479
|
+
let _jp: JackpotDetails = {
|
|
480
|
+
...jp,
|
|
481
|
+
pot: pots.find( p => p.jp_template_id === jp.jp_template_id),
|
|
482
|
+
};
|
|
483
|
+
return _jp;
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
public async jackpotOptIn(filter: { jp_template_id: number }): Promise<JackpotsOptinResponse> {
|
|
489
|
+
|
|
490
|
+
if (!filter.jp_template_id) {
|
|
491
|
+
throw new Error('jp_template_id is required in jackpotOptIn');
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const result = await this.api.jackpotOptIn(null, filter);
|
|
495
|
+
|
|
496
|
+
this.jackpotClearCache();
|
|
497
|
+
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
public async jackpotOptOut(filter: { jp_template_id: number }): Promise<JackpotsOptoutResponse> {
|
|
502
|
+
|
|
503
|
+
if (!filter.jp_template_id) {
|
|
504
|
+
throw new Error('jp_template_id is required in jackpotOptOut');
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const result = await this.api.jackpotOptOut(null, filter);
|
|
508
|
+
|
|
509
|
+
this.jackpotClearCache();
|
|
510
|
+
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
}
|