@smartico/public-api 0.0.166 → 0.0.168

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/docs/README.md CHANGED
@@ -32,6 +32,7 @@
32
32
  - [JackpotsOptoutResponse](interfaces/JackpotsOptoutResponse.md)
33
33
  - [TMiniGamePrize](interfaces/TMiniGamePrize.md)
34
34
  - [TMiniGamePlayResult](interfaces/TMiniGamePlayResult.md)
35
+ - [TMiniGamePlayBatchResult](interfaces/TMiniGamePlayBatchResult.md)
35
36
  - [TMiniGameTemplate](interfaces/TMiniGameTemplate.md)
36
37
  - [TUserProfile](interfaces/TUserProfile.md)
37
38
  - [TLevel](interfaces/TLevel.md)
@@ -150,15 +150,22 @@ ___
150
150
 
151
151
  ### getBonuses
152
152
 
153
- ▸ **getBonuses**(): `Promise`\<[`TBonus`](../interfaces/TBonus.md)[]\>
153
+ ▸ **getBonuses**(`«destructured»?`): `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
156
  The returned bonuss are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
157
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.
158
+ The onUpdate callback will be called on bonus claimed and the updated bonuses will be passed to it.
159
159
 
160
160
  **Visitor mode: not supported**
161
161
 
162
+ #### Parameters
163
+
164
+ | Name | Type |
165
+ | :------ | :------ |
166
+ | `«destructured»` | `Object` |
167
+ | › `onUpdate?` | (`data`: [`TBonus`](../interfaces/TBonus.md)[]) => `void` |
168
+
162
169
  #### Returns
163
170
 
164
171
  `Promise`\<[`TBonus`](../interfaces/TBonus.md)[]\>
@@ -428,6 +435,27 @@ Plays the specified by template_id mini-game on behalf of user and returns prize
428
435
 
429
436
  ___
430
437
 
438
+ ### playMiniGameBatch
439
+
440
+ ▸ **playMiniGameBatch**(`template_id`, `spin_count`): `Promise`\<[`TMiniGamePlayBatchResult`](../interfaces/TMiniGamePlayBatchResult.md)[]\>
441
+
442
+ Plays the specified by template_id mini-game on behalf of user {count} times and returns prizes or err_code
443
+
444
+ **Visitor mode: not supported**
445
+
446
+ #### Parameters
447
+
448
+ | Name | Type |
449
+ | :------ | :------ |
450
+ | `template_id` | `number` |
451
+ | `spin_count` | `number` |
452
+
453
+ #### Returns
454
+
455
+ `Promise`\<[`TMiniGamePlayBatchResult`](../interfaces/TMiniGamePlayBatchResult.md)[]\>
456
+
457
+ ___
458
+
431
459
  ### requestMissionOptIn
432
460
 
433
461
  ▸ **requestMissionOptIn**(`mission_id`): `Promise`\<[`TMissionOptInResult`](../interfaces/TMissionOptInResult.md)\>
@@ -847,3 +875,36 @@ _smartico.api.jackpotOptOut({ jp_template_id: 123 }).then((result) => {
847
875
  #### Returns
848
876
 
849
877
  `Promise`\<[`JackpotsOptoutResponse`](../interfaces/JackpotsOptoutResponse.md)\>
878
+
879
+ ___
880
+
881
+ ### getRelatedItemsForGame
882
+
883
+ ▸ **getRelatedItemsForGame**(`related_game_id`): `Promise`\<`GetAchievementMapResponse`\>
884
+
885
+ Returns all the related tournaments and missions for the provided game id for the current user
886
+ The provided Game ID should correspond to the ID from the Games Catalog - https://help.smartico.ai/welcome/technical-guides/games-catalog-api
887
+
888
+ **Example**:
889
+ ```
890
+ _smartico.api.getRelatedItemsForGame('gold-slot2').then((result) => {
891
+ console.log(result);
892
+ });
893
+ ```
894
+
895
+ **Example in the Visitor mode**:
896
+ ```
897
+ _smartico.vapi('EN').getRelatedItemsForGame('gold-slot2').then((result) => {
898
+ console.log(result);
899
+ });
900
+ ```
901
+
902
+ #### Parameters
903
+
904
+ | Name | Type |
905
+ | :------ | :------ |
906
+ | `related_game_id` | `string` |
907
+
908
+ #### Returns
909
+
910
+ `Promise`\<`GetAchievementMapResponse`\>
@@ -0,0 +1,43 @@
1
+ # Interface: TMiniGamePlayBatchResult
2
+
3
+ TMiniGamePlayBatchResult describes the response of call to _smartico.api.playMiniGameBatch(template_id, spin_count) method
4
+
5
+ ## Properties
6
+
7
+ ### saw\_prize\_id
8
+
9
+ • **saw\_prize\_id**: `number`
10
+
11
+ The saw_prize_id that user won, details of the prize can be found in the mini-game definition
12
+
13
+ ___
14
+
15
+ ### errCode
16
+
17
+ • **errCode**: [`SAWSpinErrorCode`](../enums/SAWSpinErrorCode.md)
18
+
19
+ Error code that represents outcome of the game play attempt. Game succeed to be played in case err_code is 0
20
+
21
+ ___
22
+
23
+ ### errMessage
24
+
25
+ • `Optional` **errMessage**: `string`
26
+
27
+ Optional error message
28
+
29
+ ___
30
+
31
+ ### jackpot\_amount
32
+
33
+ • `Optional` **jackpot\_amount**: `number`
34
+
35
+ Jackpot amount what user won
36
+
37
+ ___
38
+
39
+ ### first\_spin\_in\_period
40
+
41
+ • `Optional` **first\_spin\_in\_period**: `number`
42
+
43
+ Period in miliseconds from last spin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.166",
3
+ "version": "0.0.168",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -121,6 +121,10 @@ export enum ClassId {
121
121
  SAW_PRIZE_DROP_WIN_AKNOWLEDGE_REQUEST = 709,
122
122
  SAW_PRIZE_DROP_WIN_AKNOWLEDGE_RESPONSE = 710,
123
123
  SAW_AKNOWLEDGE_SPIN_PUSH = 711,
124
+ SAW_DO_SPIN_BATCH_REQUEST = 712,
125
+ SAW_DO_SPIN_BATCH_RESPONSE = 713,
126
+ SAW_AKNOWLEDGE_BATCH_REQUEST = 714,
127
+ SAW_AKNOWLEDGE_BATCH_RESPONSE = 715,
124
128
 
125
129
  /*
126
130
  !Important, if adding new messages that are 'acting' on behalf of the client,
@@ -0,0 +1,5 @@
1
+ import { ProtocolRequest } from '../Base/ProtocolRequest';
2
+
3
+ export interface SAWDoAcknowledgeBatchRequest extends ProtocolRequest {
4
+ request_ids: string[];
5
+ }
@@ -0,0 +1,5 @@
1
+ import { ProtocolRequest } from '../Base/ProtocolRequest';
2
+
3
+ export interface SAWDoAcknowledgeBatchResponse extends ProtocolRequest {
4
+ results: Array<{ request_id: string, errCode: number, errMessage?: string }>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { ProtocolMessage } from 'src/SmarticoLib';
2
+
3
+ export interface SAWDoSpinBatchRequest extends ProtocolMessage {
4
+ spins: Array<{ request_id: string, saw_template_id: number }>;
5
+ }
@@ -0,0 +1,8 @@
1
+ import { ProtocolResponse } from '../Base/ProtocolResponse';
2
+ import { SAWDoSpinResponse } from './SAWDoSpinResponse';
3
+ import { SAWSpinErrorCode } from './SAWSpinErrorCode';
4
+
5
+ export interface SAWDoSpinBatchResponse extends ProtocolResponse {
6
+ results: SAWDoSpinResponse[];
7
+ errCode: SAWSpinErrorCode,
8
+ }
@@ -2,7 +2,7 @@ import { ProtocolResponse } from '../Base/ProtocolResponse';
2
2
  import { Tournament } from '../Tournaments';
3
3
  import { UserAchievement } from './UserAchievement';
4
4
 
5
- export interface GetAchievementMapResponse extends ProtocolResponse {
5
+ export interface GetRelatedAchTourResponse extends ProtocolResponse {
6
6
  achievements: UserAchievement[];
7
7
  tournaments?: Tournament[];
8
8
  }
@@ -109,6 +109,12 @@ import {
109
109
  import { GetCustomSectionsRequest, GetCustomSectionsResponse, UICustomSectionTransform } from './CustomSections';
110
110
  import { BonusItemsTransform, ClaimBonusRequest, ClaimBonusResponse, GetBonusesResponse } from './Bonuses';
111
111
  import { GetBonusesRequest } from './Bonuses/GetBonusesRequest';
112
+ import { SAWDoSpinBatchResponse } from './MiniGames/SAWDoSpinBatchResponse';
113
+ import { SAWDoSpinBatchRequest } from './MiniGames/SAWDoSpinBatchRequest';
114
+ import { SAWDoAcknowledgeBatchRequest } from './MiniGames/SAWDoAcknowledgeBatchRequest';
115
+ import { SAWDoAcknowledgeBatchResponse } from './MiniGames/SAWDoAcknowledgeBatchResponse';
116
+ import { GetRelatedAchTourRequest } from './Missions/GetRelatedAchTourRequest';
117
+ import { GetRelatedAchTourResponse } from './Missions/GetRelatedAchTourResponse';
112
118
 
113
119
  const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
114
120
  const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
@@ -537,6 +543,47 @@ class SmarticoAPI {
537
543
  return { ...spinAttemptResponse, request_id };
538
544
  }
539
545
 
546
+
547
+ public async doAcknowledgeBatchRequest(user_ext_id: string, request_ids: string[]): Promise<SAWDoAcknowledgeBatchResponse> {
548
+ const message = this.buildMessage<SAWDoAcknowledgeBatchRequest, SAWDoAcknowledgeBatchResponse>(
549
+ user_ext_id,
550
+ ClassId.SAW_AKNOWLEDGE_REQUEST,
551
+ {
552
+ request_ids,
553
+ },
554
+ );
555
+
556
+ return await this.send<SAWDoAcknowledgeBatchResponse>(message, ClassId.SAW_AKNOWLEDGE_BATCH_RESPONSE);
557
+ }
558
+
559
+ public async sawSpinBatchRequest(user_ext_id: string, saw_template_id: number, spins_count: number): Promise<SAWDoSpinBatchResponse> {
560
+
561
+ const spins = [];
562
+ for (let i = 0; i < spins_count; i++) {
563
+ const request_id = IntUtils.uuid();
564
+ spins.push({ request_id, saw_template_id })
565
+ }
566
+
567
+ const message = this.buildMessage<SAWDoSpinBatchRequest, SAWDoSpinBatchResponse>(user_ext_id, ClassId.SAW_DO_SPIN_BATCH_REQUEST, { spins });
568
+ const spinAttemptResponse = await this.send<SAWDoSpinBatchResponse>(message, ClassId.SAW_DO_SPIN_BATCH_RESPONSE);
569
+
570
+ // If one response is 'OK' we consider that whole result is 'OK'
571
+ const result = spinAttemptResponse.results.find((res) => res.errCode === 0);
572
+
573
+ let status = 'OK';
574
+ if (!result) {
575
+ status = 'BATCH FAIL';
576
+ }
577
+
578
+ await this.coreReportCustomEvent(user_ext_id, 'minigame_attempt', {
579
+ saw_template_id,
580
+ status,
581
+ spins_count,
582
+ });
583
+
584
+ return { ...spinAttemptResponse };
585
+ }
586
+
540
587
  public async missionOptIn(user_ext_id: string, mission_id: number) {
541
588
  if (!mission_id) {
542
589
  throw new Error('Missing mission id');
@@ -1027,6 +1074,19 @@ class SmarticoAPI {
1027
1074
  public getWSCalls(): WSAPI {
1028
1075
  return new WSAPI(this);
1029
1076
  }
1077
+
1078
+ public async getRelatedItemsForGame(user_ext_id: string, related_game_id: string,): Promise<GetRelatedAchTourResponse> {
1079
+ const message = this.buildMessage< GetRelatedAchTourRequest, GetRelatedAchTourResponse>(
1080
+ user_ext_id,
1081
+ ClassId.GET_RELATED_ACH_N_TOURNAMENTS_REQUEST,
1082
+ {
1083
+ related_game_id: related_game_id
1084
+ }
1085
+ );
1086
+
1087
+ return await this.send<GetRelatedAchTourResponse>(message, ClassId.GET_RELATED_ACH_N_TOURNAMENTS_RESPONSE);
1088
+
1089
+ }
1030
1090
  }
1031
1091
 
1032
1092
  export { SmarticoAPI, MessageSender };
@@ -1,6 +1,6 @@
1
1
  import { ClassId } from '../Base/ClassId';
2
2
  import { CoreUtils } from '../Core';
3
- import { MiniGamePrizeTypeName, SAWDoSpinResponse, SAWSpinErrorCode, SAWSpinsCountPush } from '../MiniGames';
3
+ import { MiniGamePrizeTypeName, SAWDoSpinResponse, SAWGetTemplatesResponse, SAWSpinErrorCode, SAWSpinsCountPush } from '../MiniGames';
4
4
  import { ECacheContext, OCache } from '../OCache';
5
5
  import { SmarticoAPI } from '../SmarticoAPI';
6
6
  import {
@@ -26,7 +26,8 @@ import {
26
26
  TUICustomSection,
27
27
  TUserProfile,
28
28
  UserLevelExtraCountersT,TBonus,
29
- TClaimBonusResult
29
+ TClaimBonusResult,
30
+ TMiniGamePlayBatchResult
30
31
  } from './WSAPITypes';
31
32
  import { LeaderBoardPeriodType } from '../Leaderboard';
32
33
  import {
@@ -37,6 +38,8 @@ import {
37
38
  JackpotsOptoutRequest,
38
39
  JackpotsOptoutResponse,
39
40
  } from '../Jackpots';
41
+ import { GetTournamentsResponse } from 'src/Tournaments';
42
+ import { GetAchievementMapResponse } from 'src/Missions';
40
43
 
41
44
  /** @hidden */
42
45
  const CACHE_DATA_SEC = 30;
@@ -202,6 +205,9 @@ export class WSAPI {
202
205
 
203
206
  /**
204
207
  * Returns all the bonuses for the current user
208
+ * The returned bonuss are cached for 30 seconds. But you can pass the onUpdate callback as a parameter.
209
+ * Note that each time you call getBonuses with a new onUpdate callback, the old one will be overwritten by the new one.
210
+ * The onUpdate callback will be called on bonus claimed and the updated bonuses will be passed to it.
205
211
  *
206
212
  * **Visitor mode: not supported**
207
213
  */
@@ -466,6 +472,28 @@ export class WSAPI {
466
472
  return o;
467
473
  }
468
474
 
475
+ /**
476
+ * Plays the specified by template_id mini-game on behalf of user {count} times and returns prizes or err_code
477
+ *
478
+ * **Visitor mode: not supported**
479
+ */
480
+ public async playMiniGameBatch(template_id: number, spin_count: number): Promise<TMiniGamePlayBatchResult[]> {
481
+ const response = await this.api.sawSpinBatchRequest(null, template_id, spin_count);
482
+
483
+ const request_ids = response.results.map((result) => result.request_id);
484
+ this.api.doAcknowledgeBatchRequest(null, request_ids);
485
+
486
+ const o: TMiniGamePlayBatchResult[] = response.results.map((result) => ({
487
+ errCode: result.errCode,
488
+ errMessage: result.errMsg,
489
+ saw_prize_id: result.saw_prize_id,
490
+ jackpot_amount: result.jackpot_amount,
491
+ first_spin_in_period: result.first_spin_in_period,
492
+ }));
493
+
494
+ return o;
495
+ }
496
+
469
497
  /**
470
498
  * Requests an opt-in for the specified mission_id. Returns the err_code.
471
499
  *
@@ -890,4 +918,28 @@ export class WSAPI {
890
918
 
891
919
  return result;
892
920
  }
921
+ /**
922
+ * Returns all the related tournaments and missions for the provided game id for the current user
923
+ * The provided Game ID should correspond to the ID from the Games Catalog - https://help.smartico.ai/welcome/technical-guides/games-catalog-api
924
+ *
925
+ * **Example**:
926
+ * ```
927
+ * _smartico.api.getRelatedItemsForGame('gold-slot2').then((result) => {
928
+ * console.log(result);
929
+ * });
930
+ * ```
931
+ *
932
+ * **Example in the Visitor mode**:
933
+ * ```
934
+ * _smartico.vapi('EN').getRelatedItemsForGame('gold-slot2').then((result) => {
935
+ * console.log(result);
936
+ * });
937
+ * ```
938
+ */
939
+ public async getRelatedItemsForGame(related_game_id: string): Promise<GetAchievementMapResponse> {
940
+
941
+ const result = await this.api.getRelatedItemsForGame(null, related_game_id);
942
+ return result;
943
+
944
+ }
893
945
  }
@@ -55,6 +55,22 @@ export interface TMiniGamePlayResult {
55
55
  prize_id: number;
56
56
  }
57
57
 
58
+ /**
59
+ * TMiniGamePlayBatchResult describes the response of call to _smartico.api.playMiniGameBatch(template_id, spin_count) method
60
+ */
61
+ export interface TMiniGamePlayBatchResult {
62
+ /** The saw_prize_id that user won, details of the prize can be found in the mini-game definition */
63
+ saw_prize_id: number;
64
+ /** Error code that represents outcome of the game play attempt. Game succeed to be played in case err_code is 0 */
65
+ errCode: SAWSpinErrorCode;
66
+ /** Optional error message */
67
+ errMessage?: string;
68
+ /** Jackpot amount what user won */
69
+ jackpot_amount?: number;
70
+ /** Period in miliseconds from last spin */
71
+ first_spin_in_period?: number,
72
+ }
73
+
58
74
  /**
59
75
  * TMiniGameTemplate describes the information of mini-games available for the user
60
76
  */