@smartico/public-api 0.0.252 → 0.0.253

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.
Files changed (45) hide show
  1. package/dist/Base/ClassId.d.ts +2 -0
  2. package/dist/Jackpots/GetJackpotWinnersRequest.d.ts +10 -0
  3. package/dist/Jackpots/GetJackpotWinnersResponse.d.ts +20 -0
  4. package/dist/Jackpots/index.d.ts +2 -0
  5. package/dist/Raffle/GetDrawRunResponse.d.ts +2 -0
  6. package/dist/Raffle/GetRaffleDrawRunsHistoryResponse.d.ts +2 -0
  7. package/dist/Raffle/GetRafflesResponse.d.ts +10 -0
  8. package/dist/Raffle/RaffleClaimPrizeResponse.d.ts +4 -0
  9. package/dist/Raffle/RaffleDraw.d.ts +2 -2
  10. package/dist/SmarticoAPI.d.ts +17 -5
  11. package/dist/WSAPI/WSAPI.d.ts +94 -8
  12. package/dist/WSAPI/WSAPITypes.d.ts +272 -0
  13. package/dist/index.js +559 -199
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.modern.mjs +322 -14
  16. package/dist/index.modern.mjs.map +1 -1
  17. package/docs/README.md +140 -0
  18. package/docs/classes/WSAPI.md +102 -12
  19. package/docs/enums/RaffleDrawInstanceState.md +25 -0
  20. package/docs/enums/RaffleDrawTypeExecution.md +27 -0
  21. package/docs/interfaces/GetJackpotWinnersRequest.md +91 -0
  22. package/docs/interfaces/GetJackpotWinnersResponse.md +73 -0
  23. package/docs/interfaces/JackpotWinnerHistory.md +25 -0
  24. package/docs/interfaces/RaffleClaimPrizeResponse.md +3 -3
  25. package/docs/interfaces/RaffleDraw.md +2 -2
  26. package/docs/interfaces/TRaffle.md +101 -0
  27. package/docs/interfaces/TRaffleDraw.md +181 -0
  28. package/docs/interfaces/TRaffleDrawRun.md +125 -0
  29. package/docs/interfaces/TRafflePrize.md +159 -0
  30. package/docs/interfaces/TRafflePrizeWinner.md +50 -0
  31. package/docs/interfaces/TRaffleTicket.md +13 -0
  32. package/docs/interfaces/TransformedRaffleClaimPrizeResponse.md +17 -0
  33. package/package.json +1 -1
  34. package/src/Base/ClassId.ts +2 -1
  35. package/src/Jackpots/GetJackpotWinnersRequest.ts +12 -0
  36. package/src/Jackpots/GetJackpotWinnersResponse.ts +33 -0
  37. package/src/Jackpots/index.ts +2 -0
  38. package/src/Raffle/GetDrawRunResponse.ts +30 -0
  39. package/src/Raffle/GetRaffleDrawRunsHistoryResponse.ts +23 -0
  40. package/src/Raffle/GetRafflesResponse.ts +97 -0
  41. package/src/Raffle/RaffleClaimPrizeResponse.ts +16 -1
  42. package/src/Raffle/RaffleDraw.ts +2 -2
  43. package/src/SmarticoAPI.ts +45 -24
  44. package/src/WSAPI/WSAPI.ts +144 -9
  45. package/src/WSAPI/WSAPITypes.ts +307 -0
@@ -1,6 +1,103 @@
1
+ import { TRaffle, TRaffleDraw, TRafflePrize, TRafflePrizeWinner, TRaffleTicket } from 'src/WSAPI/WSAPITypes';
1
2
  import { ProtocolResponse } from '../Base/ProtocolResponse';
2
3
  import { Raffle } from './Raffle';
4
+ import { RaffleDraw } from './RaffleDraw';
5
+ import { RafflePrize } from './RafflePrize';
6
+ import { RafflePrizeWinner } from './RafflePrizeWinner';
7
+ import { CoreUtils } from 'src/Core';
8
+ import { RaffleTicket } from './RaffleTicket';
3
9
 
4
10
  export interface GetRafflesResponse extends ProtocolResponse {
5
11
  items: Raffle[];
6
12
  }
13
+
14
+ export const ticketsTransform = (items: RaffleTicket[]): TRaffleTicket[] => {
15
+ return items.map((item) => {
16
+ return {
17
+ ticekt_id: item.id,
18
+ ticket_id_string: item.s,
19
+ };
20
+ });
21
+ };
22
+
23
+ export const winnersTransform = (items: RafflePrizeWinner[]): TRafflePrizeWinner[] => {
24
+ return items.map((item) => {
25
+ return {
26
+ id: item.user_id,
27
+ username: item.public_username,
28
+ avatar_url: item.avatar_url,
29
+ ticket: { ticekt_id: item.ticket.id, ticket_id_string: item.ticket.s },
30
+ raf_won_id: item.raf_won_id,
31
+ claimed_date: item.claimed_date,
32
+ };
33
+ });
34
+ };
35
+
36
+ export const prizeTransform = (items: RafflePrize[]): TRafflePrize[] => {
37
+ return items.map((item) => {
38
+ return {
39
+ id: item.prize_id,
40
+ name: item.public_meta.name,
41
+ description: item.public_meta.description,
42
+ image_url: item.public_meta.image_url,
43
+ prizes_per_run: item.prizes_per_run,
44
+ prizes_per_run_actual: item.prizes_per_run_actual,
45
+ chances_to_win_perc: item.chances_to_win_perc,
46
+ min_required_total_tickets: item.min_required_total_tickets,
47
+ cap_prizes_per_run: item.cap_prizes_per_run,
48
+ priority: item.priority,
49
+ stock_items_per_draw: item.stock_items_per_draw,
50
+ should_claim: item.should_claim,
51
+ winners: winnersTransform(item.winners),
52
+ requires_claim: item.requires_claim,
53
+ min_required_tickets_for_user: item.min_required_tickets_for_user,
54
+ };
55
+ });
56
+ };
57
+
58
+ export const drawTransform = (items: RaffleDraw[]): TRaffleDraw[] => {
59
+ return items.map((item) => {
60
+ return {
61
+ id: item.draw_id,
62
+ name: item.public_meta.name,
63
+ description: item.public_meta.description,
64
+ image_url: item.public_meta.image_url,
65
+ image_url_mobile: item.public_meta.image_url_mobile,
66
+ icon_url: item.public_meta.icon_url,
67
+ background_image_url: item.public_meta.background_image_url,
68
+ background_image_url_mobile: item.public_meta.background_image_url_mobile,
69
+ is_grand: item.public_meta.is_grand,
70
+ prizes: prizeTransform(item.prizes),
71
+ current_state: item.current_state,
72
+ run_id: item.run_id,
73
+ execution_type: item.execution_type,
74
+ execution_ts: item.execution_ts,
75
+ previous_run_ts: item.previous_run_ts,
76
+ previous_run_id: item.previous_run_id,
77
+ ticket_start_ts: item.ticket_start_ts,
78
+ allow_multi_prize_per_ticket: item.allow_multi_prize_per_ticket,
79
+ total_tickets_count: item.total_tickets_count,
80
+ my_tickets_count: item.my_tickets_count,
81
+ my_last_tickets: ticketsTransform(item.my_last_tickets),
82
+ };
83
+ });
84
+ };
85
+
86
+ export const raffleTransform = (items: Raffle[]): TRaffle[] => {
87
+ return items.map((item) => {
88
+ return {
89
+ id: item.raffle_id,
90
+ name: item.public_meta.name,
91
+ description: item.public_meta.description,
92
+ custom_section_id: item.public_meta.custom_section_id,
93
+ image_url: item.public_meta.image_url,
94
+ image_url_mobile: item.public_meta.image_url_mobile,
95
+ custom_data: item.public_meta.custom_data,
96
+ start_date: item.start_date_ts,
97
+ end_date: item.end_date_ts,
98
+ max_tickets_count: item.max_tickets_count,
99
+ current_tickets_count: item.current_tickets_count,
100
+ draws: drawTransform(item.draws),
101
+ };
102
+ });
103
+ };
@@ -1,3 +1,18 @@
1
+ import { TransformedRaffleClaimPrizeResponse } from "src/WSAPI/WSAPITypes";
1
2
  import { ProtocolResponse } from "../Base/ProtocolResponse";
2
3
 
3
- export interface RaffleClaimPrizeResponse extends ProtocolResponse { }
4
+ export interface RaffleClaimPrizeResponse extends ProtocolResponse {
5
+ errCode: number
6
+ errMsg?: string
7
+ }
8
+
9
+
10
+ export const raffleClaimPrizeResponseTransform = (info: RaffleClaimPrizeResponse): TransformedRaffleClaimPrizeResponse => {
11
+ return {
12
+ errorCode: info.errCode,
13
+ errorMessage: info.errMsg
14
+ }
15
+ }
16
+
17
+
18
+
@@ -2,7 +2,7 @@ import { RaffleDrawPublicMeta } from "./RaffleDrawPublicMeta";
2
2
  import { RafflePrize } from "./RafflePrize";
3
3
  import { RaffleTicket } from "./RaffleTicket";
4
4
 
5
- enum RaffleDrawInstanceState {
5
+ export enum RaffleDrawInstanceState {
6
6
  /** Draw is open for the tickets collection */
7
7
  Open = 1,
8
8
  /** Winner selection is in progress */
@@ -11,7 +11,7 @@ enum RaffleDrawInstanceState {
11
11
  Executed = 3,
12
12
  }
13
13
 
14
- enum RaffleDrawTypeExecution {
14
+ export enum RaffleDrawTypeExecution {
15
15
  /** Draw is executed only once */
16
16
  ExecDate = 0,
17
17
  /** Draw is executed on a recurring basis */
@@ -95,6 +95,7 @@ import {
95
95
  TUICustomSection,
96
96
  TBonus,
97
97
  TSawHistory,
98
+ TRaffle,
98
99
  } from './WSAPI/WSAPITypes';
99
100
  import { getLeaderBoardTransform } from './Leaderboard/LeaderBoards';
100
101
  import { GetAchievementsUserInfoResponse } from './Core/GetAchievementsUserInfoResponse';
@@ -105,8 +106,6 @@ import {
105
106
  GetJackpotsPotsResponse,
106
107
  GetJackpotsRequest,
107
108
  GetJackpotsResponse,
108
- JackpotDetails,
109
- JackpotPot,
110
109
  JackpotsOptinRequest,
111
110
  JackpotsOptinResponse,
112
111
  JackpotsOptoutRequest,
@@ -121,10 +120,12 @@ import { SAWDoAcknowledgeBatchRequest } from './MiniGames/SAWDoAcknowledgeBatchR
121
120
  import { SAWDoAcknowledgeBatchResponse } from './MiniGames/SAWDoAcknowledgeBatchResponse';
122
121
  import { GetRelatedAchTourRequest } from './Missions/GetRelatedAchTourRequest';
123
122
  import { GetRelatedAchTourResponse } from './Missions/GetRelatedAchTourResponse';
124
- import { GetRafflesResponse } from './Raffle/GetRafflesResponse';
123
+ import { GetRafflesResponse, raffleTransform } from './Raffle/GetRafflesResponse';
125
124
  import { GetRafflesRequest } from './Raffle/GetRafflesRequest';
126
125
  import { InboxCategories } from './Inbox/InboxCategories';
127
126
  import { GetDrawRunRequest, GetDrawRunResponse, GetRaffleDrawRunsHistoryRequest, GetRaffleDrawRunsHistoryResponse, RaffleClaimPrizeRequest, RaffleClaimPrizeResponse } from './Raffle';
127
+ import { GetJackpotWinnersResponse, GetJackpotWinnersResponseTransform, JackpotWinnerHistory } from './Jackpots/GetJackpotWinnersResponse';
128
+ import { GetJackpotWinnersRequest } from './Jackpots/GetJackpotWinnersRequest';
128
129
 
129
130
  const PUBLIC_API_URL = 'https://papi{ENV_ID}.smartico.ai/services/public';
130
131
  const C_SOCKET_PROD = 'wss://api{ENV_ID}.smartico.ai/websocket/services';
@@ -487,6 +488,23 @@ class SmarticoAPI {
487
488
  return await this.send<JackpotsOptoutResponse>(message, ClassId.JP_OPTOUT_RESPONSE);
488
489
  }
489
490
 
491
+ public async getJackpotWinners(user_ext_id: string, limit: number = 20, offset: number = 0, jp_template_id: number ): Promise<GetJackpotWinnersResponse> {
492
+ const message = this.buildMessage<GetJackpotWinnersRequest, GetJackpotWinnersResponse>(
493
+ user_ext_id,
494
+ ClassId.JP_GET_WINNERS_REQUEST,
495
+ {
496
+ limit,
497
+ offset,
498
+ jp_template_id,
499
+ },
500
+ );
501
+ return await this.send<GetJackpotWinnersResponse>(message, ClassId.JP_GET_WINNERS_RESPONSE);
502
+ }
503
+
504
+ public async getJackpotWinnersT(user_ext_id: string, limit: number = 20, offset: number = 0, jp_template_id: number ): Promise<JackpotWinnerHistory[]> {
505
+ return GetJackpotWinnersResponseTransform((await this.getJackpotWinners(user_ext_id, limit, offset, jp_template_id)).winners);
506
+ }
507
+
490
508
  public async sawGetTemplates(
491
509
  user_ext_id: string,
492
510
  force_language?: string,
@@ -1149,47 +1167,50 @@ class SmarticoAPI {
1149
1167
  );
1150
1168
 
1151
1169
  return await this.send<GetRelatedAchTourResponse>(message, ClassId.GET_RELATED_ACH_N_TOURNAMENTS_RESPONSE);
1170
+ }
1152
1171
 
1172
+ public async getRafflesT(user_ext_id: string): Promise<TRaffle[]> {
1173
+ return raffleTransform((await this.getRaffles(user_ext_id)).items);
1153
1174
  }
1154
1175
 
1155
1176
  public async getRaffles(user_ext_id: string): Promise<GetRafflesResponse> {
1156
- const message = this.buildMessage< GetRafflesRequest, GetRafflesResponse>(
1157
- user_ext_id,
1158
- ClassId.RAF_GET_RAFFLES_REQUEST
1159
- );
1160
-
1161
- return await this.send<GetRafflesResponse>(message, ClassId.RAF_GET_RAFFLES_RESPONSE);
1162
- }
1177
+ const message = this.buildMessage<GetRafflesRequest, GetRafflesResponse>(user_ext_id, ClassId.RAF_GET_RAFFLES_REQUEST);
1163
1178
 
1179
+ return await this.send<GetRafflesResponse>(message, ClassId.RAF_GET_RAFFLES_RESPONSE);
1180
+ }
1164
1181
 
1165
- public async getDrawRun(user_ext_id: string, payload: GetDrawRunRequest): Promise<GetDrawRunResponse> {
1182
+ public async getRaffleDrawRun(user_ext_id: string, payload: { raffle_id: number; run_id: number }): Promise<GetDrawRunResponse> {
1166
1183
  const message = this.buildMessage<GetDrawRunRequest, GetDrawRunResponse>(
1167
1184
  user_ext_id,
1168
- ClassId.RAF_GET_DRAW_RUN_REQUEST ,
1185
+ ClassId.RAF_GET_DRAW_RUN_REQUEST,
1169
1186
  payload,
1170
1187
  );
1171
-
1188
+
1172
1189
  return await this.send<GetDrawRunResponse>(message, ClassId.RAF_GET_DRAW_RUN_RESPONSE);
1173
- }
1190
+ }
1174
1191
 
1175
- public async getRaffleDrawRunsHistory(user_ext_id: string, payload: GetRaffleDrawRunsHistoryRequest): Promise<GetRaffleDrawRunsHistoryResponse> {
1192
+ public async getRaffleDrawRunsHistory(
1193
+ user_ext_id: string,
1194
+ props: { raffle_id: number; draw_id?: number },
1195
+ ): Promise<GetRaffleDrawRunsHistoryResponse> {
1176
1196
  const message = this.buildMessage<GetRaffleDrawRunsHistoryRequest, GetRaffleDrawRunsHistoryResponse>(
1177
1197
  user_ext_id,
1178
- ClassId.RAF_GET_DRAW_HISTORY_REQUEST ,
1179
- payload,
1198
+ ClassId.RAF_GET_DRAW_HISTORY_REQUEST,
1199
+ props,
1180
1200
  );
1181
-
1201
+
1182
1202
  return await this.send<GetRaffleDrawRunsHistoryResponse>(message, ClassId.RAF_GET_DRAW_HISTORY_RESPONSE);
1183
- }
1203
+ }
1184
1204
 
1185
- public async claimRafflePrize (user_ext_id:string, payload: RaffleClaimPrizeRequest):Promise <RaffleClaimPrizeResponse>{
1186
- const message = this.buildMessage<RaffleClaimPrizeRequest,RaffleClaimPrizeResponse>(
1205
+ public async claimRafflePrize(user_ext_id: string, props: { won_id: number }): Promise<RaffleClaimPrizeResponse> {
1206
+ const message = this.buildMessage<RaffleClaimPrizeRequest, RaffleClaimPrizeResponse>(
1187
1207
  user_ext_id,
1188
- ClassId.RAF_CLAIM_PRIZE_REQUEST ,
1189
- payload
1208
+ ClassId.RAF_CLAIM_PRIZE_REQUEST,
1209
+ props,
1190
1210
  );
1191
1211
 
1192
- return await this.send<RaffleClaimPrizeResponse>(message,ClassId.RAF_CLAIM_PRIZE_RESPONSE);
1212
+ return await this.send<RaffleClaimPrizeResponse>(message, ClassId.RAF_CLAIM_PRIZE_RESPONSE);
1213
+
1193
1214
  }
1194
1215
  }
1195
1216
 
@@ -38,12 +38,17 @@ import {
38
38
  TClaimBonusResult,
39
39
  TMiniGamePlayBatchResult,
40
40
  TSawHistory,
41
+ TRaffle,
42
+ TRaffleDraw,
43
+ TRaffleDrawRun,
44
+ TransformedRaffleClaimPrizeResponse,
41
45
  } from './WSAPITypes';
42
46
  import { LeaderBoardPeriodType } from '../Leaderboard';
43
47
  import {
44
48
  JackpotDetails,
45
49
  JackpotPot,
46
50
  JackpotWinPush,
51
+ JackpotWinnerHistory,
47
52
  JackpotsOptinResponse,
48
53
  JackpotsOptoutRequest,
49
54
  JackpotsOptoutResponse,
@@ -51,15 +56,18 @@ import {
51
56
  import { GetTournamentsResponse } from '../Tournaments';
52
57
  import { GetAchievementMapResponse } from '../Missions';
53
58
  import { GetRelatedAchTourResponse } from '../Missions/GetRelatedAchTourResponse';
54
- import { GetRafflesResponse } from '../Raffle/GetRafflesResponse';
59
+ import { drawTransform, GetRafflesResponse, prizeTransform, ticketsTransform } from '../Raffle/GetRafflesResponse';
55
60
  import { InboxCategories } from '../Inbox/InboxCategories';
56
61
  import {
62
+ drawRunHistoryTransform,
63
+ drawRunTransform,
57
64
  GetDrawRunRequest,
58
65
  GetDrawRunResponse,
59
66
  GetRaffleDrawRunsHistoryRequest,
60
67
  GetRaffleDrawRunsHistoryResponse,
61
68
  RaffleClaimPrizeRequest,
62
69
  RaffleClaimPrizeResponse,
70
+ raffleClaimPrizeResponseTransform,
63
71
  } from '../Raffle';
64
72
  import { IntUtils } from '../IntUtils';
65
73
 
@@ -68,6 +76,7 @@ const CACHE_DATA_SEC = 30;
68
76
 
69
77
  const JACKPOT_TEMPLATE_CACHE_SEC = 30;
70
78
  const JACKPOT_POT_CACHE_SEC = 1;
79
+ const JACKPOT_WINNERS_CACHE_SEC = 30;
71
80
 
72
81
  /** @hidden */
73
82
  enum onUpdateContextKey {
@@ -89,6 +98,8 @@ enum onUpdateContextKey {
89
98
  CustomSections = 'customSections',
90
99
  Bonuses = 'bonuses',
91
100
  SAWHistory = 'sawHistory',
101
+ JackpotWinners = 'jackpotWinners',
102
+ Raffles = 'raffles',
92
103
  }
93
104
 
94
105
  /** @group General API */
@@ -126,6 +137,10 @@ export class WSAPI {
126
137
  this.reloadMiniGameTemplate();
127
138
  OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.SAWHistory);
128
139
  });
140
+ on(ClassId.RAF_CLAIM_PRIZE_RESPONSE, () => {
141
+ this.updateRaffles();
142
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Raffles);
143
+ });
129
144
  }
130
145
  }
131
146
 
@@ -911,6 +926,11 @@ export class WSAPI {
911
926
  this.updateEntity(onUpdateContextKey.InboxMessages, payload);
912
927
  }
913
928
 
929
+ private async updateRaffles() {
930
+ const payload = await this.api.getRafflesT(null);
931
+ this.updateEntity(onUpdateContextKey.Raffles, payload);
932
+ }
933
+
914
934
  private async updateEntity(contextKey: onUpdateContextKey, payload: any) {
915
935
  OCache.set(contextKey, payload, ECacheContext.WSAPI);
916
936
 
@@ -923,6 +943,7 @@ export class WSAPI {
923
943
  private async jackpotClearCache() {
924
944
  OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Jackpots);
925
945
  OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.Pots);
946
+ OCache.clear(ECacheContext.WSAPI, onUpdateContextKey.JackpotWinners);
926
947
  }
927
948
 
928
949
  /** Returns list of Jackpots that are active in the systen and matching to the filter definition.
@@ -1040,6 +1061,40 @@ export class WSAPI {
1040
1061
 
1041
1062
  return result;
1042
1063
  }
1064
+
1065
+ /**
1066
+ * Returns the winners of the jackpot with the specified jp_template_id.
1067
+ *
1068
+ * **Example**:
1069
+ * ```
1070
+ * _smartico.api.getJackpotWinners({
1071
+ * jp_template_id: 123,
1072
+ * }).then((result) => {
1073
+ * console.log(result);
1074
+ * });
1075
+ * ```
1076
+ *
1077
+ * **Visitor mode: not supported**
1078
+ *
1079
+ */
1080
+
1081
+ public async getJackpotWinners({
1082
+ limit,
1083
+ offset,
1084
+ jp_template_id,
1085
+ } : {
1086
+ limit?: number;
1087
+ offset?: number;
1088
+ jp_template_id?: number;
1089
+ }): Promise<JackpotWinnerHistory[]> {
1090
+ return OCache.use(
1091
+ onUpdateContextKey.JackpotWinners,
1092
+ ECacheContext.WSAPI,
1093
+ () => this.api.getJackpotWinnersT(null, limit, offset, jp_template_id),
1094
+ JACKPOT_WINNERS_CACHE_SEC,
1095
+ );
1096
+ }
1097
+
1043
1098
  /**
1044
1099
  * Returns all the related tournaments and missions for the provided game id for the current user
1045
1100
  * The provided Game ID should correspond to the ID from the Games Catalog - https://help.smartico.ai/welcome/technical-guides/games-catalog-api
@@ -1063,19 +1118,99 @@ export class WSAPI {
1063
1118
  return result;
1064
1119
  }
1065
1120
 
1066
- public async getRaffles(): Promise<GetRafflesResponse> {
1067
- return await this.api.getRaffles(null);
1121
+ /**
1122
+ * Returns the list of Raffles available for user
1123
+ * The returned list of Raffles is cached for 30 seconds. But you can pass the onUpdate callback as a parameter. Note that each time you call getRaffles with a new onUpdate callback, the old one will be overwritten by the new one.
1124
+ * The onUpdate callback will be called on claiming prize. Updated Raffles will be passed to onUpdate callback.
1125
+ *
1126
+ * **Example**:
1127
+ * ```
1128
+ * _smartico.api.getRaffles().then((result) => {
1129
+ * console.log(result);
1130
+ * });
1131
+ * ```
1132
+ *
1133
+ * **Visitor mode: not supported**
1134
+ *
1135
+ */
1136
+
1137
+ public async getRaffles({ onUpdate }: { onUpdate?: (data: TRaffle[]) => void } = {}): Promise<TRaffle[]> {
1138
+ if (onUpdate) {
1139
+ this.onUpdateCallback.set(onUpdateContextKey.Raffles, onUpdate);
1140
+ }
1141
+
1142
+ return OCache.use(onUpdateContextKey.Raffles, ECacheContext.WSAPI, () => this.api.getRafflesT(null), CACHE_DATA_SEC);
1068
1143
  }
1069
1144
 
1070
- public async getDrawRun(payload: GetDrawRunRequest): Promise<GetDrawRunResponse> {
1071
- return await this.api.getDrawRun(null, payload);
1145
+ /**
1146
+ * Returns draw run for provided raffle_id and run_id
1147
+ *
1148
+ *
1149
+ * **Example**:
1150
+ * ```
1151
+ * _smartico.api.getRaffleDrawRun({raffle_id:156, run_id: 145}).then((result) => {
1152
+ * console.log(result);
1153
+ * });
1154
+ * ```
1155
+ *
1156
+ * **Visitor mode: not supported**
1157
+ *
1158
+ */
1159
+
1160
+ public async getRaffleDrawRun(props: { raffle_id: number; run_id: number }): Promise<TRaffleDraw> {
1161
+ const res = await this.api.getRaffleDrawRun(null, props);
1162
+
1163
+ if (!props.raffle_id || !props.run_id) {
1164
+ throw new Error('both raffle_id and run_id are required');
1165
+ }
1166
+
1167
+ return drawRunTransform(res);
1072
1168
  }
1073
1169
 
1074
- public async getRaffleDrawRunsHistory(payload: GetRaffleDrawRunsHistoryRequest): Promise<GetRaffleDrawRunsHistoryResponse> {
1075
- return await this.api.getRaffleDrawRunsHistory(null, payload);
1170
+ /**
1171
+ * Returns history of draw runs for the provided raffle_id and draw_id, if the draw_id is not provided will return history of all the draws for the provided raffle_id
1172
+ *
1173
+ *
1174
+ * **Example**:
1175
+ * ```
1176
+ * _smartico.api.getRaffleDrawRunHistory({raffle_id:156, draw_id: 432}).then((result) => {
1177
+ * console.log(result);
1178
+ * });
1179
+ * ```
1180
+ *
1181
+ * **Visitor mode: not supported**
1182
+ *
1183
+ */
1184
+
1185
+ public async getRaffleDrawRunsHistory(props: { raffle_id: number; draw_id?: number }): Promise<TRaffleDrawRun[]> {
1186
+ const res = await this.api.getRaffleDrawRunsHistory(null, props);
1187
+
1188
+ if (!props.raffle_id) {
1189
+ throw new Error('raffle_id is required');
1190
+ }
1191
+
1192
+ return drawRunHistoryTransform(res);
1076
1193
  }
1077
1194
 
1078
- public async claimRafflePrize(payload: RaffleClaimPrizeRequest): Promise<RaffleClaimPrizeResponse> {
1079
- return await this.api.claimRafflePrize(null, payload);
1195
+ /**
1196
+ * Returns error code, and error Message after calling the function, error message 0 - means that the request was successful
1197
+ *
1198
+ *
1199
+ * **Example**:
1200
+ * ```
1201
+ * _smartico.api.claimRafflePrize({won_id:251}).then((result) => {
1202
+ * console.log(result);
1203
+ * });
1204
+ * ```
1205
+ *
1206
+ * **Visitor mode: not supported**
1207
+ *
1208
+ */
1209
+ public async claimRafflePrize(props: { won_id: number }): Promise<TransformedRaffleClaimPrizeResponse> {
1210
+ if (!props.won_id) {
1211
+ throw new Error('won_id is required');
1212
+ }
1213
+ const res = await this.api.claimRafflePrize(null, { won_id: props.won_id });
1214
+ return raffleClaimPrizeResponseTransform(res);
1080
1215
  }
1081
1216
  }