@smartico/public-api 0.0.162 → 0.0.163

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.
@@ -152,7 +152,10 @@ ___
152
152
 
153
153
  ▸ **getBonuses**(): `Promise`\<[`TBonus`](../interfaces/TBonus.md)[]\>
154
154
 
155
- Returns all the bonuses for the current user
155
+ Returns all the bonuses for the current user.
156
+ The returned bonuss are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
157
+ Note that each time you call getBonuses with a new onUpdate callback, the old one will be overwritten by the new one.
158
+ The onUpdate callback will be called on mission OptIn and the updated missions will be passed to it.
156
159
 
157
160
  **Visitor mode: not supported**
158
161
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.162",
3
+ "version": "0.0.163",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -80,14 +80,16 @@ export class WSAPI {
80
80
  on(ClassId.SAW_DO_SPIN_RESPONSE, (data: SAWDoSpinResponse) =>
81
81
  on(ClassId.SAW_AKNOWLEDGE_RESPONSE, () => this.updateOnPrizeWin(data)),
82
82
  );
83
- on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissionsOnOptIn());
84
- on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournamentsOnRegistration());
83
+ on(ClassId.MISSION_OPTIN_RESPONSE, () => this.updateMissions());
84
+ on(ClassId.ACHIEVEMENT_CLAIM_PRIZE_RESPONSE, () => this.updateMissions());
85
+ on(ClassId.RELOAD_ACHIEVEMENTS_EVENT, () => this.updateMissions());
86
+ on(ClassId.TOURNAMENT_REGISTER_RESPONSE, () => this.updateTournaments());
85
87
  on(ClassId.CLIENT_ENGAGEMENT_EVENT_NEW, () => this.updateInboxMessages());
86
88
  on(ClassId.LOGOUT_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
87
89
  on(ClassId.IDENTIFY_RESPONSE, () => OCache.clearContext(ECacheContext.WSAPI));
88
90
  on(ClassId.JP_WIN_PUSH, (data: JackpotWinPush) => this.jackpotClearCache());
89
91
  on(ClassId.JP_OPTOUT_RESPONSE, (data: JackpotsOptoutRequest) => this.jackpotClearCache());
90
- on(ClassId.JP_OPTIN_RESPONSE, (data: JackpotsOptinResponse) => this.jackpotClearCache());
92
+ on(ClassId.CLAIM_BONUS_RESPONSE, () => this.updateBonuses());
91
93
  }
92
94
  }
93
95
 
@@ -186,12 +188,7 @@ export class WSAPI {
186
188
  this.onUpdateCallback.set(onUpdateContextKey.Missions, onUpdate);
187
189
  }
188
190
 
189
- return OCache.use(
190
- onUpdateContextKey.Missions,
191
- ECacheContext.WSAPI,
192
- () => this.api.missionsGetItemsT(null),
193
- CACHE_DATA_SEC,
194
- );
191
+ return OCache.use(onUpdateContextKey.Missions, ECacheContext.WSAPI, () => this.api.missionsGetItemsT(null), CACHE_DATA_SEC);
195
192
  }
196
193
 
197
194
  /**
@@ -208,11 +205,15 @@ export class WSAPI {
208
205
  *
209
206
  * **Visitor mode: not supported**
210
207
  */
211
- public async getBonuses(): Promise<TBonus[]> {
208
+ public async getBonuses({ onUpdate }: { onUpdate?: (data: TBonus[]) => void } = {}): Promise<TBonus[]> {
209
+ if (onUpdate) {
210
+ this.onUpdateCallback.set(onUpdateContextKey.Bonuses, onUpdate);
211
+ }
212
+
212
213
  return OCache.use(onUpdateContextKey.Bonuses, ECacheContext.WSAPI, () => this.api.bonusesGetItemsT(null), CACHE_DATA_SEC);
213
214
  }
214
215
 
215
- /**
216
+ /**
216
217
  * Claim the bonus by bonus_id. Returns the err_code in case of success or error.
217
218
  * Note that this method can be used only on integrations where originally failed bonus can be claimed again.
218
219
  * For example, user won a bonus in the mini-game, but Operator rejected this bonus.
@@ -738,33 +739,23 @@ export class WSAPI {
738
739
 
739
740
  private async updateOnPrizeWin(data: SAWDoSpinResponse) {
740
741
  if (data.errCode === SAWSpinErrorCode.SAW_OK) {
741
- const templates: TMiniGameTemplate[] = await OCache.use(
742
- onUpdateContextKey.Saw,
743
- ECacheContext.WSAPI,
744
- () => this.api.sawGetTemplatesT(null),
745
- CACHE_DATA_SEC,
746
- );
747
- const template: TMiniGameTemplate = templates.find((t) => t.prizes.find((p) => p.id === data.saw_prize_id));
748
- const prizeType = template.prizes.find((p) => p.id === data.saw_prize_id)?.prize_type;
749
-
750
- if (
751
- template.jackpot_add_on_attempt ||
752
- template.spin_count === 1 ||
753
- prizeType === MiniGamePrizeTypeName.JACKPOT ||
754
- prizeType === MiniGamePrizeTypeName.SPIN
755
- ) {
742
+
756
743
  const updatedTemplates = await this.api.sawGetTemplatesT(null);
757
744
  this.updateEntity(onUpdateContextKey.Saw, updatedTemplates);
758
- }
759
745
  }
760
746
  }
761
747
 
762
- private async updateMissionsOnOptIn() {
748
+ private async updateMissions() {
763
749
  const payload = await this.api.missionsGetItemsT(null);
764
750
  this.updateEntity(onUpdateContextKey.Missions, payload);
765
751
  }
766
752
 
767
- private async updateTournamentsOnRegistration() {
753
+ private async updateBonuses() {
754
+ const payload = await this.api.bonusesGetItemsT(null);
755
+ this.updateEntity(onUpdateContextKey.Bonuses, payload);
756
+ }
757
+
758
+ private async updateTournaments() {
768
759
  const payload = await this.api.tournamentsGetLobbyT(null);
769
760
  this.updateEntity(onUpdateContextKey.TournamentList, payload);
770
761
  }